Skip to content

Commit

Permalink
Melhoria do enum ShareMode
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Feb 21, 2024
1 parent b6e7e42 commit f725217
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 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.getShareModeName(args[1].toUpperCase(Locale.ENGLISH));
ShareMode mode = ShareMode.getShareMode(args[1].toUpperCase(Locale.ENGLISH));

if (mode == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<nenhum | igual | aleatorio>"));
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/com/gmail/nossr50/datatypes/party/ShareMode.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package com.gmail.nossr50.datatypes.party;

import com.gmail.nossr50.util.commands.CommandUtils;
import org.jetbrains.annotations.Nullable;

public enum ShareMode {
NONE,
EQUAL,
RANDOM;
NONE("nenhum"),
EQUAL("igual"),
RANDOM("aleatorio");
private final String name;

public static ShareMode getShareMode(String string) {
try {
return valueOf(string);
}
catch (IllegalArgumentException ex) {
if (string.equalsIgnoreCase("even")) {
return EQUAL;
}
else if (CommandUtils.shouldDisableToggle(string)) {
return NONE;
}
ShareMode(String name) {
this.name = name;
}

return null;
public static @Nullable ShareMode getShareMode(String string) {
for (ShareMode shareMode : ShareMode.values()) {
if (shareMode.name.equalsIgnoreCase(string)) {
return shareMode;
}
}
return null;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/gmail/nossr50/party/PartyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,8 @@ public void loadParties() {
hasAlly.add(party);
}

party.setXpShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ExpShareMode", "NONE")));
party.setItemShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ItemShareMode", "NONE")));
party.setXpShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ExpShareMode", "nenhum")));
party.setItemShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ItemShareMode", "nenhum")));

for (ItemShareType itemShareType : ItemShareType.values()) {
party.setSharingDrops(itemShareType, partiesFile.getBoolean(partyName + ".ItemShareType." + itemShareType.toString(), true));
Expand Down

0 comments on commit f725217

Please sign in to comment.