diff --git a/src/main/java/com/gmail/nossr50/commands/party/PartyItemShareCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PartyItemShareCommand.java index 42adf51e06..6980cf2770 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyItemShareCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyItemShareCommand.java @@ -45,7 +45,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command switch (args.length) { case 2: - ShareMode mode = ShareMode.getShareMode(args[1].toUpperCase(Locale.ENGLISH)); + ShareMode mode = ShareMode.getShareMode(args[1]); if (mode == null) { sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "")); diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/ItemShareType.java b/src/main/java/com/gmail/nossr50/datatypes/party/ItemShareType.java index 270421f142..edc7c185ec 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/ItemShareType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/ItemShareType.java @@ -16,16 +16,16 @@ public static ItemShareType getShareType(ItemStack itemStack) { if (ItemUtils.isMobDrop(itemStack)) { return LOOT; } - else if (ItemUtils.isMiningDrop(itemStack)) { + if (ItemUtils.isMiningDrop(itemStack)) { return MINING; } - else if (ItemUtils.isHerbalismDrop(itemStack)) { + if (ItemUtils.isHerbalismDrop(itemStack)) { return HERBALISM; } - else if (ItemUtils.isWoodcuttingDrop(itemStack)) { + if (ItemUtils.isWoodcuttingDrop(itemStack)) { return WOODCUTTING; } - else if (ItemUtils.isMiscDrop(itemStack)) { + if (ItemUtils.isMiscDrop(itemStack)) { return MISC; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java index 9b684c7420..99bbe9841f 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java @@ -6,7 +6,6 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.sounds.SoundManager; @@ -38,14 +37,14 @@ public class Party { private int level; private float xp; - private ShareMode xpShareMode = ShareMode.NONE; + private ShareMode xpShareMode = ShareMode.NONE; private ShareMode itemShareMode = ShareMode.NONE; - private boolean shareLootDrops = true; - private boolean shareMiningDrops = true; - private boolean shareHerbalismDrops = true; + private boolean shareLootDrops = true; + private boolean shareMiningDrops = true; + private boolean shareHerbalismDrops = true; private boolean shareWoodcuttingDrops = true; - private boolean shareMiscDrops = true; + private boolean shareMiscDrops = true; public Party(String name) { this.name = name; @@ -86,13 +85,11 @@ public List getOnlineMembers() { return onlineMembers; } - public List getVisibleMembers(Player player) - { + public List getVisibleMembers(Player player) { ArrayList visibleMembers = new ArrayList<>(); - for(Player p : onlineMembers) - { - if(player.canSee(p)) + for (Player p : onlineMembers) { + if (player.canSee(p)) visibleMembers.add(p); } @@ -279,50 +276,22 @@ public ShareMode getItemShareMode() { } public boolean sharingDrops(ItemShareType shareType) { - switch (shareType) { - case HERBALISM: - return shareHerbalismDrops; - - case LOOT: - return shareLootDrops; - - case MINING: - return shareMiningDrops; - - case MISC: - return shareMiscDrops; - - case WOODCUTTING: - return shareWoodcuttingDrops; - - default: - return false; - } + return switch (shareType) { + case HERBALISM -> shareHerbalismDrops; + case LOOT -> shareLootDrops; + case MINING -> shareMiningDrops; + case MISC -> shareMiscDrops; + case WOODCUTTING -> shareWoodcuttingDrops; + }; } public void setSharingDrops(ItemShareType shareType, boolean enabled) { switch (shareType) { - case HERBALISM: - shareHerbalismDrops = enabled; - break; - - case LOOT: - shareLootDrops = enabled; - break; - - case MINING: - shareMiningDrops = enabled; - break; - - case MISC: - shareMiscDrops = enabled; - break; - - case WOODCUTTING: - shareWoodcuttingDrops = enabled; - break; - - default: + case HERBALISM -> shareHerbalismDrops = enabled; + case LOOT -> shareLootDrops = enabled; + case MINING -> shareMiningDrops = enabled; + case MISC -> shareMiscDrops = enabled; + case WOODCUTTING -> shareWoodcuttingDrops = enabled; } } @@ -338,6 +307,7 @@ public boolean hasMember(UUID uuid) { * Makes a formatted list of party members based on the perspective of a target player * Players that are hidden will be shown as offline (formatted in the same way) * Party leader will be formatted a specific way as well + * * @param player target player to use as POV * @return formatted list of party members from the POV of a player */ @@ -345,10 +315,10 @@ public String createMembersList(Player player) { StringBuilder memberList = new StringBuilder(); List coloredNames = new ArrayList<>(); - for(UUID playerUUID : members.keySet()) { + for (UUID playerUUID : members.keySet()) { OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerUUID); - if(offlinePlayer.isOnline() && player.canSee((Player) offlinePlayer)) { + if (offlinePlayer.isOnline() && player.canSee((Player) offlinePlayer)) { ChatColor onlineColor = leader.getUniqueId().equals(playerUUID) ? ChatColor.GOLD : ChatColor.GREEN; coloredNames.add(onlineColor + offlinePlayer.getName()); } else { @@ -361,8 +331,8 @@ public String createMembersList(Player player) { } private void buildChatMessage(@NotNull StringBuilder stringBuilder, String @NotNull [] names) { - for(int i = 0; i < names.length; i++) { - if(i + 1 >= names.length) { + for (int i = 0; i < names.length; i++) { + if (i + 1 >= names.length) { stringBuilder .append(names[i]); } else { diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/ShareMode.java b/src/main/java/com/gmail/nossr50/datatypes/party/ShareMode.java index 28ba6e7231..8d4dcde663 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/ShareMode.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/ShareMode.java @@ -6,15 +6,18 @@ public enum ShareMode { NONE("nenhum"), EQUAL("igual"), RANDOM("aleatorio"); - private final String name; + private final String customName; - ShareMode(String name) { - this.name = name; + ShareMode(String customName) { + this.customName = customName; } public static @Nullable ShareMode getShareMode(String string) { for (ShareMode shareMode : ShareMode.values()) { - if (shareMode.name.equalsIgnoreCase(string)) { + if (shareMode.customName.equalsIgnoreCase(string)) { + return shareMode; + } + if (shareMode.name().equalsIgnoreCase(string)) { return shareMode; } } diff --git a/src/main/java/com/gmail/nossr50/party/ShareHandler.java b/src/main/java/com/gmail/nossr50/party/ShareHandler.java index 38aa0e2c32..65ba214141 100644 --- a/src/main/java/com/gmail/nossr50/party/ShareHandler.java +++ b/src/main/java/com/gmail/nossr50/party/ShareHandler.java @@ -76,6 +76,9 @@ public static boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) { } Party party = mcMMOPlayer.getParty(); + if (party == null) { + return false; + } if (!party.sharingDrops(dropType)) { return false; @@ -113,7 +116,7 @@ public static boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) { McMMOPlayer mcMMOMember = UserManager.getPlayer(member); //Profile not loaded - if(UserManager.getPlayer(member) == null) + if(mcMMOMember == null) { continue; } @@ -130,15 +133,19 @@ public static boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) { if (winningPlayer != null) { McMMOPlayer mcMMOWinning = UserManager.getPlayer(winningPlayer); - mcMMOWinning.setItemShareModifier(mcMMOWinning.getItemShareModifier() + itemWeight); + if (mcMMOWinning != null) { + mcMMOWinning.setItemShareModifier(mcMMOWinning.getItemShareModifier() + itemWeight); + } } winningPlayer = member; } McMMOPlayer mcMMOTarget = UserManager.getPlayer(winningPlayer); - mcMMOTarget.setItemShareModifier(mcMMOTarget.getItemShareModifier() - itemWeight); - awardDrop(winningPlayer, newStack); + if (mcMMOTarget != null && winningPlayer != null) { + mcMMOTarget.setItemShareModifier(mcMMOTarget.getItemShareModifier() - itemWeight); + awardDrop(winningPlayer, newStack); + } } return true;