Skip to content

Commit

Permalink
1.1.5
Browse files Browse the repository at this point in the history
- Bug fixes and improvements
  • Loading branch information
Foulest committed Jan 4, 2025
1 parent cba52a5 commit 9612804
Show file tree
Hide file tree
Showing 20 changed files with 426 additions and 265 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'net.foulest'
version = '1.1.4'
version = '1.1.5'
description = 'PixelAddons'

// Set the project's language level
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/foulest/pixeladdons/cmds/EndBattleCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public void onCommand(@NotNull CommandArgs args) throws CommandException {
return;
}

EntityPlayerMP playerMP = PixelmonCommand.requireEntityPlayer(player.getName());
String playerName = player.getName();
EntityPlayerMP playerMP = PixelmonCommand.requireEntityPlayer(playerName);
BattleControllerBase battleController = BattleRegistry.getBattle(playerMP);

// Checks if the player is in a battle.
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/net/foulest/pixeladdons/cmds/HatchCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.pixelmonmod.pixelmon.Pixelmon;
import com.pixelmonmod.pixelmon.api.economy.IPixelmonBankAccount;
import com.pixelmonmod.pixelmon.api.pokemon.Pokemon;
import com.pixelmonmod.pixelmon.enums.EnumSpecies;
import com.pixelmonmod.pixelmon.storage.PlayerPartyStorage;
import net.foulest.pixeladdons.PixelAddons;
import net.foulest.pixeladdons.data.PlayerData;
Expand All @@ -34,6 +35,7 @@

import java.text.DecimalFormat;
import java.util.Optional;
import java.util.UUID;

/**
* Command for hatching a Pokemon egg.
Expand Down Expand Up @@ -71,24 +73,27 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

PlayerPartyStorage party = Pixelmon.storageManager.getParty(player.getUniqueId());
UUID uniqueId = player.getUniqueId();
PlayerPartyStorage party = Pixelmon.storageManager.getParty(uniqueId);

// Checks if the player has a starter Pokemon.
if (!party.starterPicked) {
MessageUtil.messagePlayer(player, Settings.starterNotFoundMessage);
return;
}

String firstArgs = args.getArgs(0);

// Checks if the slot is a number.
try {
Integer.parseInt(args.getArgs(0));
Integer.parseInt(firstArgs);
} catch (NumberFormatException ex) {
MessageUtil.messagePlayer(player, Settings.commandInvalidUsageMessage
.replace("%reason%", "Number is invalid"));
return;
}

int slot = Integer.parseInt(args.getArgs(0));
int slot = Integer.parseInt(firstArgs);

// Checks if the slot is valid.
if (slot <= 0 || slot > 6) {
Expand Down Expand Up @@ -122,7 +127,8 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

Player owner = Bukkit.getPlayer(pokemon.getOwnerPlayerUUID());
UUID ownerPlayerUUID = pokemon.getOwnerPlayerUUID();
Player owner = Bukkit.getPlayer(ownerPlayerUUID);

// Checks if the owner is valid.
if (owner == null) {
Expand All @@ -132,33 +138,41 @@ public void onCommand(@NotNull CommandArgs args) {
}

Optional<? extends IPixelmonBankAccount> bankAccount
= Pixelmon.moneyManager.getBankAccount(player.getUniqueId());
= Pixelmon.moneyManager.getBankAccount(uniqueId);

// Checks if the player has a bank account.
if (!bankAccount.isPresent()) {
MessageUtil.messagePlayer(player, Settings.bankAccountNotFoundMessage);
return;
}

IPixelmonBankAccount account = bankAccount.get();
int currentBalance = account.getMoney();

// Checks if the player has enough money.
if (bankAccount.get().getMoney() < Settings.hatchCommandCost) {
if (currentBalance < Settings.hatchCommandCost) {
MessageUtil.messagePlayer(player, Settings.notEnoughMoneyMessage
.replace("%amount%", formattedCost));
return;
}

// Handles hatching the egg.
if (playerData.isConfirmHatch()) {
bankAccount.get().setMoney(bankAccount.get().getMoney() - Settings.hatchCommandCost);
account.setMoney(currentBalance - Settings.hatchCommandCost);
pokemon.hatchEgg();

playerData.setConfirmHatch(false);

EnumSpecies species = pokemon.getSpecies();
String pokemonName = species.getPokemonName();

MessageUtil.messagePlayer(player, Settings.pokemonHatchedMessage
.replace("%pokemon%", pokemon.getSpecies().getPokemonName())
.replace("%pokemon%", pokemonName)
.replace("%amount%", formattedCost));

} else {
playerData.setConfirmHatch(true);

MessageUtil.messagePlayer(player, Settings.confirmHatchMessage
.replace("%amount%", formattedCost));

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/net/foulest/pixeladdons/cmds/PixelAddonsCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ private static void handleHelp(@NotNull CommandSender sender, CommandArgs args)
);

int itemsPerPage = 4;
int maxPages = (int) Math.ceil((double) commands.size() / itemsPerPage);
int size = commands.size();
int maxPages = (int) Math.ceil((double) size / itemsPerPage);
int page = 1;

if (args.length() > 1) {
try {
page = Integer.parseInt(args.getArgs(1));
String args1 = args.getArgs(1);
page = Integer.parseInt(args1);
} catch (NumberFormatException ignored) {
}
}
Expand All @@ -112,13 +114,14 @@ private static void handleHelp(@NotNull CommandSender sender, CommandArgs args)
}

int startIndex = (page - 1) * itemsPerPage;
int endIndex = Math.min(commands.size(), startIndex + itemsPerPage);
int endIndex = Math.min(size, startIndex + itemsPerPage);

MessageUtil.messagePlayer(sender, "");
MessageUtil.messagePlayer(sender, "&ePixelAddons Help &7(Page " + page + "/" + maxPages + ")");

for (int i = startIndex; i < endIndex; i++) {
MessageUtil.messagePlayer(sender, commands.get(i));
String line = commands.get(i);
MessageUtil.messagePlayer(sender, line);
}

MessageUtil.messagePlayer(sender, "");
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/net/foulest/pixeladdons/cmds/RerollCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,30 @@ public void onCommand(@NotNull CommandArgs args) {
}
}

String playerName = player.getName();
int votingSize = votingToReroll.size();
int onlineSize = Bukkit.getOnlinePlayers().size();

// Counts the player's vote and broadcasts it.
// If the player has already voted, it removes their vote.
if (votingToReroll.contains(player)) {
votingToReroll.remove(player);

// Broadcasts the cancellation of the vote.
MessageUtil.broadcast(Settings.rerollVoteCancelledMessage
.replace("%player%", player.getName())
.replace("%votes%", String.valueOf(votingToReroll.size()))
.replace("%online%", String.valueOf(Bukkit.getOnlinePlayers().size())));
.replace("%player%", playerName)
.replace("%votes%", String.valueOf(votingSize))
.replace("%online%", String.valueOf(onlineSize)));
} else {
votingToReroll.add(player);

// Only broadcasts the vote if there are other players online.
// Otherwise, it would be pointless to broadcast it.
if (Bukkit.getOnlinePlayers().size() > 1) {
if (onlineSize > 1) {
MessageUtil.broadcast(Settings.rerollVoteSubmittedMessage
.replace("%player%", player.getName())
.replace("%votes%", String.valueOf(votingToReroll.size()))
.replace("%online%", String.valueOf(Bukkit.getOnlinePlayers().size())));
.replace("%player%", playerName)
.replace("%votes%", String.valueOf(votingSize))
.replace("%online%", String.valueOf(onlineSize)));
}
}

Expand Down Expand Up @@ -126,8 +130,9 @@ public static void handleReroll() {

// Broadcasts the re-roll.
if (votingToReroll.size() == 1) {
MessageUtil.broadcast(Settings.rerollHuntMessageWithPlayer
.replace("%player%", votingToReroll.get(0).getName()));
Player player = votingToReroll.get(0);
String playerName = player.getName();
MessageUtil.broadcast(Settings.rerollHuntMessageWithPlayer.replace("%player%", playerName));
} else {
MessageUtil.broadcast(Settings.rerollHuntMessage);
}
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/net/foulest/pixeladdons/cmds/ShowCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

/**
* Command for showing the stats of a selected Pokemon.
*
Expand Down Expand Up @@ -62,24 +64,27 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

PlayerPartyStorage party = Pixelmon.storageManager.getParty(player.getUniqueId());
UUID uniqueId = player.getUniqueId();
PlayerPartyStorage party = Pixelmon.storageManager.getParty(uniqueId);

// Checks if the player has a starter Pokemon.
if (!party.starterPicked) {
MessageUtil.messagePlayer(player, Settings.starterNotFoundMessage);
return;
}

String firstArgs = args.getArgs(0);

// Checks if the slot is a number.
try {
Integer.parseInt(args.getArgs(0));
Integer.parseInt(firstArgs);
} catch (NumberFormatException ex) {
MessageUtil.messagePlayer(player, Settings.commandInvalidUsageMessage
.replace("%reason%", "Not a number"));
return;
}

int slot = Integer.parseInt(args.getArgs(0));
int slot = Integer.parseInt(firstArgs);

// Checks if the slot is valid.
if (slot <= 0 || slot > 6) {
Expand All @@ -106,7 +111,8 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

Player owner = Bukkit.getPlayer(pokemon.getOwnerPlayerUUID());
UUID ownerPlayerUUID = pokemon.getOwnerPlayerUUID();
Player owner = Bukkit.getPlayer(ownerPlayerUUID);

// Checks if the owner is valid.
if (owner == null) {
Expand All @@ -116,10 +122,11 @@ public void onCommand(@NotNull CommandArgs args) {
}

String pokemonName = pokemon.getSpecies().getPokemonName();
String ownerName = owner.getName();

// Handles printing the stats.
String chatMessage = Settings.showMessage
.replace("%player%", owner.getName())
.replace("%player%", ownerName)
.replace("%color%", FormatUtil.getDisplayColor(pokemon))
.replace("%pokemon%", pokemonName);

Expand Down
22 changes: 15 additions & 7 deletions src/main/java/net/foulest/pixeladdons/cmds/StatsCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

/**
* Command for showing the stats of a selected Pokemon.
*
Expand Down Expand Up @@ -62,17 +64,19 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

PlayerPartyStorage party = Pixelmon.storageManager.getParty(player.getUniqueId());
UUID playerUUID = player.getUniqueId();
PlayerPartyStorage party = Pixelmon.storageManager.getParty(playerUUID);
String args1 = args.getArgs(1);

// Handles viewing other players' stats.
if (args.length() == 2 && !args.getArgs(1).isEmpty()) {
if (args.length() == 2 && !args1.isEmpty()) {
// Checks if viewing other players' stats is disabled.
if (!Settings.statsCommandViewOtherPlayers) {
MessageUtil.messagePlayer(player, Settings.commandNoPermissionMessage);
return;
}

Player target = Bukkit.getPlayer(args.getArgs(1));
Player target = Bukkit.getPlayer(args1);

// Checks if the player is invalid.
if (target == null) {
Expand All @@ -88,7 +92,8 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

party = Pixelmon.storageManager.getParty(target.getUniqueId());
UUID targetUUID = target.getUniqueId();
party = Pixelmon.storageManager.getParty(targetUUID);
}

// Checks if the player has a starter Pokemon.
Expand All @@ -97,16 +102,18 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

String args0 = args.getArgs(0);

// Checks if the slot is a number.
try {
Integer.parseInt(args.getArgs(0));
Integer.parseInt(args0);
} catch (NumberFormatException ex) {
MessageUtil.messagePlayer(player, Settings.commandInvalidUsageMessage
.replace("%reason%", "Number is invalid"));
return;
}

int slot = Integer.parseInt(args.getArgs(0));
int slot = Integer.parseInt(args0);

// Checks if the slot is valid.
if (slot <= 0 || slot > 6) {
Expand All @@ -133,7 +140,8 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

Player owner = Bukkit.getPlayer(pokemon.getOwnerPlayerUUID());
UUID ownerPlayerUUID = pokemon.getOwnerPlayerUUID();
Player owner = Bukkit.getPlayer(ownerPlayerUUID);

// Checks if the owner is missing.
if (owner == null) {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/net/foulest/pixeladdons/data/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@
*/
package net.foulest.pixeladdons.data;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.Data;
import org.bukkit.entity.Player;

import java.util.UUID;

@Getter
@Setter
@ToString
public final class PlayerData {
@Data
public class PlayerData {

// Player data
private UUID uniqueId;
Expand Down
Loading

0 comments on commit 9612804

Please sign in to comment.