Make this a bit more sane.

This commit is contained in:
GJ 2013-04-18 09:09:12 -04:00
parent c3845abd2a
commit 8af425d067
5 changed files with 119 additions and 100 deletions

View File

@ -6,9 +6,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.ItemShareType;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.party.ShareHandler.ShareMode;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils;
@ -27,20 +27,14 @@ public class PartyItemShareCommand implements CommandExecutor {
switch (args.length) {
case 2:
playerParty = UserManager.getPlayer(sender.getName()).getParty();
ShareMode mode = ShareMode.getShareMode(args[1].toUpperCase());
if (args[1].equalsIgnoreCase("none") || CommandUtils.shouldDisableToggle(args[1])) {
handleChangingShareMode(ShareMode.NONE);
}
else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
handleChangingShareMode(ShareMode.EQUAL);
}
else if (args[1].equalsIgnoreCase("random")) {
handleChangingShareMode(ShareMode.RANDOM);
}
else {
if (mode == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
return true;
}
handleChangingShareMode(mode);
return true;
case 3:
@ -58,26 +52,13 @@ public class PartyItemShareCommand implements CommandExecutor {
return true;
}
if (args[1].equalsIgnoreCase("loot")) {
playerParty.setSharingLootDrops(toggle);
try {
handleToggleItemShareCategory(ItemShareType.valueOf(args[1].toUpperCase()), toggle);
}
else if (args[1].equalsIgnoreCase("mining")) {
playerParty.setSharingMiningDrops(toggle);
}
else if (args[1].equalsIgnoreCase("herbalism")) {
playerParty.setSharingHerbalismDrops(toggle);
}
else if (args[1].equalsIgnoreCase("woodcutting")) {
playerParty.setSharingWoodcuttingDrops(toggle);
}
else if (args[1].equalsIgnoreCase("misc")) {
playerParty.setSharingMiscDrops(toggle);
}
else {
catch (IllegalArgumentException ex) {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting | misc> <true | false>"));
}
notifyToggleItemShareCategory(args[1], toggle);
return true;
default:
@ -87,7 +68,7 @@ public class PartyItemShareCommand implements CommandExecutor {
}
}
private void handleChangingShareMode(ShareHandler.ShareMode mode) {
private void handleChangingShareMode(ShareMode mode) {
playerParty.setItemShareMode(mode);
String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())));
@ -97,10 +78,10 @@ public class PartyItemShareCommand implements CommandExecutor {
}
}
private void notifyToggleItemShareCategory(String category, boolean toggle) {
String state = toggle ? "enabled" : "disabled";
private void handleToggleItemShareCategory(ItemShareType type, boolean toggle) {
playerParty.setSharingDrops(type, toggle);
String toggleMessage = LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(category), state);
String toggleMessage = LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(type.toString()), toggle ? "enabled" : "disabled");
for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(toggleMessage);

View File

@ -0,0 +1,33 @@
package com.gmail.nossr50.datatypes.party;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.util.ItemUtils;
public enum ItemShareType {
LOOT,
MINING,
HERBALISM,
WOODCUTTING,
MISC;
public static ItemShareType getShareType(ItemStack itemStack) {
if (ItemUtils.isMobDrop(itemStack)) {
return LOOT;
}
else if (ItemUtils.isMiningDrop(itemStack)) {
return MINING;
}
else if (ItemUtils.isHerbalismDrop(itemStack)) {
return HERBALISM;
}
else if (ItemUtils.isWoodcuttingDrop(itemStack)) {
return WOODCUTTING;
}
else if (ItemUtils.isMiscDrop(itemStack)) {
return MISC;
}
return null;
}
}

View File

@ -8,7 +8,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.party.ShareHandler.ShareMode;
public class Party {
private LinkedHashSet<String> members = new LinkedHashSet<String>();
@ -17,8 +17,8 @@ public class Party {
private String password;
private boolean locked;
private ShareHandler.ShareMode xpShareMode = ShareHandler.ShareMode.NONE;
private ShareHandler.ShareMode itemShareMode = ShareHandler.ShareMode.NONE;
private ShareMode xpShareMode = ShareMode.NONE;
private ShareMode itemShareMode = ShareMode.NONE;
private boolean shareLootDrops = true;
private boolean shareMiningDrops = true;
@ -59,47 +59,27 @@ public class Party {
return locked;
}
public boolean sharingLootDrops() {
return shareLootDrops;
}
public boolean sharingMiningDrops() {
return shareMiningDrops;
}
public boolean sharingHerbalismDrops() {
return shareHerbalismDrops;
}
public boolean sharingWoodcuttingDrops() {
return shareWoodcuttingDrops;
}
public boolean sharingMiscDrops() {
return shareMiscDrops;
}
public List<String> getItemShareCategories() {
List<String> shareCategories = new ArrayList<String>();
// TODO Locale the category names!
if (sharingLootDrops()) {
if (shareLootDrops) {
shareCategories.add("Loot");
}
if (sharingMiningDrops()) {
if (shareMiningDrops) {
shareCategories.add("Mining");
}
if (sharingHerbalismDrops()) {
if (shareHerbalismDrops) {
shareCategories.add("Herbalism");
}
if (sharingWoodcuttingDrops()) {
if (shareWoodcuttingDrops) {
shareCategories.add("Woodcutting");
}
if (sharingMiscDrops()) {
if (shareMiscDrops) {
shareCategories.add("Misc");
}
@ -122,39 +102,68 @@ public class Party {
this.locked = locked;
}
public void setXpShareMode(ShareHandler.ShareMode xpShareMode) {
public void setXpShareMode(ShareMode xpShareMode) {
this.xpShareMode = xpShareMode;
}
public ShareHandler.ShareMode getXpShareMode() {
public ShareMode getXpShareMode() {
return xpShareMode;
}
public void setItemShareMode(ShareHandler.ShareMode itemShareMode) {
public void setItemShareMode(ShareMode itemShareMode) {
this.itemShareMode = itemShareMode;
}
public ShareHandler.ShareMode getItemShareMode() {
public ShareMode getItemShareMode() {
return itemShareMode;
}
public void setSharingLootDrops(boolean enabled) {
shareLootDrops = enabled;
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;
}
}
public void setSharingMiningDrops(boolean enabled) {
shareMiningDrops = enabled;
}
public void setSharingDrops(ItemShareType shareType, boolean enabled) {
switch (shareType) {
case HERBALISM:
shareHerbalismDrops = enabled;
break;
public void setSharingHerbalismDrops(boolean enabled) {
shareHerbalismDrops = enabled;
}
case LOOT:
shareLootDrops = enabled;
break;
public void setSharingWoodcuttingDrops(boolean enabled) {
shareWoodcuttingDrops = enabled;
}
case MINING:
shareMiningDrops = enabled;
break;
public void setSharingMiscDrops(boolean enabled) {
shareMiscDrops = enabled;
case MISC:
shareMiscDrops = enabled;
break;
case WOODCUTTING:
shareWoodcuttingDrops = enabled;
break;
default:
return;
}
}
}

View File

@ -461,8 +461,8 @@ public final class PartyManager {
party.setLeader(partiesFile.getString(partyName + ".Leader"));
party.setPassword(partiesFile.getString(partyName + ".Password"));
party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
party.setXpShareMode(ShareHandler.ShareMode.getFromString(partiesFile.getString(partyName + ".ExpShareMode")));
party.setItemShareMode(ShareHandler.ShareMode.getFromString(partiesFile.getString(partyName + ".ItemShareMode")));
party.setXpShareMode(ShareHandler.ShareMode.getShareMode(partiesFile.getString(partyName + ".ExpShareMode", "NONE")));
party.setItemShareMode(ShareHandler.ShareMode.getShareMode(partiesFile.getString(partyName + ".ItemShareMode", "NONE")));
List<String> memberNames = partiesFile.getStringList(partyName + ".Members");
LinkedHashSet<String> members = party.getMembers();

View File

@ -8,11 +8,12 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.party.ItemWeightConfig;
import com.gmail.nossr50.datatypes.party.ItemShareType;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public final class ShareHandler {
@ -21,15 +22,19 @@ public final class ShareHandler {
EQUAL,
RANDOM;
public static ShareMode getFromString(String string) {
public static ShareMode getShareMode(String string) {
try {
return valueOf(string);
}
catch (IllegalArgumentException exception) {
return NONE;
}
catch (NullPointerException exception) {
return NONE;
catch (IllegalArgumentException ex) {
if (string.equalsIgnoreCase("even")) {
return EQUAL;
}
else if (CommandUtils.shouldDisableToggle(string)) {
return NONE;
}
return null;
}
}
};
@ -76,8 +81,8 @@ public final class ShareHandler {
mcMMOPlayer.beginUnsharedXpGain(skillType, roundedXp);
return true;
case NONE:
// Fallthrough
default:
return false;
}
@ -99,19 +104,9 @@ public final class ShareHandler {
ItemStack newStack = itemStack.clone();
newStack.setAmount(1);
if (ItemUtils.isMobDrop(itemStack) && !party.sharingLootDrops()) {
return false;
}
else if (ItemUtils.isMiningDrop(itemStack) && !party.sharingMiningDrops()) {
return false;
}
else if (ItemUtils.isHerbalismDrop(itemStack) && !party.sharingHerbalismDrops()) {
return false;
}
else if (ItemUtils.isWoodcuttingDrop(itemStack) && !party.sharingWoodcuttingDrops()) {
return false;
}
else if (ItemUtils.isMiscDrop(itemStack) && !party.sharingMiscDrops()) {
ItemShareType dropType = ItemShareType.getShareType(itemStack);
if (dropType == null || !party.sharingDrops(dropType)) {
return false;
}
@ -163,6 +158,7 @@ public final class ShareHandler {
winningPlayer.updateInventory();
}
return true;
case RANDOM:
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
@ -191,8 +187,8 @@ public final class ShareHandler {
winningPlayer.updateInventory();
}
return true;
case NONE:
// Fallthrough
default:
return false;
}