Skip to content

Commit

Permalink
Melhoria de métodos relacionados ao ShareMode
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Feb 21, 2024
1 parent 228ee2d commit 3e6e7d7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<nenhum | igual | aleatorio>"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
80 changes: 25 additions & 55 deletions src/main/java/com/gmail/nossr50/datatypes/party/Party.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -86,13 +85,11 @@ public List<Player> getOnlineMembers() {
return onlineMembers;
}

public List<Player> getVisibleMembers(Player player)
{
public List<Player> getVisibleMembers(Player player) {
ArrayList<Player> visibleMembers = new ArrayList<>();

for(Player p : onlineMembers)
{
if(player.canSee(p))
for (Player p : onlineMembers) {
if (player.canSee(p))
visibleMembers.add(p);
}

Expand Down Expand Up @@ -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;
}
}

Expand All @@ -338,17 +307,18 @@ 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
*/
public String createMembersList(Player player) {
StringBuilder memberList = new StringBuilder();
List<String> 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 {
Expand All @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/gmail/nossr50/datatypes/party/ShareMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/gmail/nossr50/party/ShareHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 3e6e7d7

Please sign in to comment.