diff --git a/pom.xml b/pom.xml index aa033e91..b2747281 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.makershaven SignShop - 3.3.0 + 3.3.1 1.8 1.8 diff --git a/src/main/java/org/wargamer2010/signshop/operations/SignShopArguments.java b/src/main/java/org/wargamer2010/signshop/operations/SignShopArguments.java index 886307e8..2026354d 100644 --- a/src/main/java/org/wargamer2010/signshop/operations/SignShopArguments.java +++ b/src/main/java/org/wargamer2010/signshop/operations/SignShopArguments.java @@ -20,20 +20,50 @@ import java.util.*; public class SignShopArguments implements IMessagePartContainer { + public static String seperator = "~"; + public Map miscSettings = new HashMap<>(); + public Map forceMessageKeys = new HashMap<>(); + public boolean bDoNotClearClickmap = false; + public boolean bPriceModApplied = false; + public boolean bRunCommandAsUser = false; + private SignShopArgument fPrice = new SignShopArgument<>(this); + private SignShopArgument> containables = new SignShopArgument<>(this); + private SignShopArgument> activatables = new SignShopArgument<>(this); + private SignShopArgument ssPlayer = new SignShopArgument<>(this); + private SignShopArgument ssOwner = new SignShopArgument<>(this); + private SignShopArgument bSign = new SignShopArgument<>(this); + private SignShopArgument sOperation = new SignShopArgument<>(this); + private SignShopArgument sEnchantments = new SignShopArgument<>(this); + private SignShopArgument bfBlockFace = new SignShopArgument<>(this); + private SignShopArgument aAction = new SignShopArgument<>(this); + private List operationParameters = new LinkedList<>(); + private SignShopArgumentsType argumentType; + private SignShopArgument isItems = new SignShopArgument(this) { + @Override + public void set(ItemStack[] pItems) { + if (getCollection().forceMessageKeys.containsKey("!items") && argumentType == SignShopArgumentsType.Setup) + getCollection().miscSettings.put(getCollection().forceMessageKeys.get("!items").replace("!", ""), + signshopUtil.implode(itemUtil.convertItemStacksToString(pItems), seperator)); + super.set(pItems); + } + }; + private SSMoneyEventType moneyEventType = SSMoneyEventType.Unknown; + private Map messageParts = new LinkedHashMap<>(); + public SignShopArguments(double pfPrice, ItemStack[] pisItems, List pContainables, List pActivatables, - SignShopPlayer pssPlayer, SignShopPlayer pssOwner, Block pbSign, String psOperation, BlockFace pbfBlockFace, Action ac, SignShopArgumentsType type) { + SignShopPlayer pssPlayer, SignShopPlayer pssOwner, Block pbSign, String psOperation, BlockFace pbfBlockFace, Action ac, SignShopArgumentsType type) { fPrice.setRoot(pfPrice); isItems.setRoot(pisItems); containables.setRoot(pContainables); activatables.setRoot(pActivatables); - if(pssPlayer != null) + if (pssPlayer != null) ssPlayer.setRoot(pssPlayer); else - ssPlayer.setRoot(new SignShopPlayer((Player)null)); - if(pssOwner != null) + ssPlayer.setRoot(new SignShopPlayer((Player) null)); + if (pssOwner != null) ssOwner.setRoot(pssOwner); else - ssOwner.setRoot(new SignShopPlayer((Player)null)); + ssOwner.setRoot(new SignShopPlayer((Player) null)); bSign.setRoot(pbSign); sOperation.setRoot(psOperation); bfBlockFace.setRoot(pbfBlockFace); @@ -44,16 +74,16 @@ public SignShopArguments(double pfPrice, ItemStack[] pisItems, List pCont } public SignShopArguments(Seller seller, SignShopPlayer player, SignShopArgumentsType type) { - if(seller.getSign().getState() instanceof Sign) - fPrice.setRoot(economyUtil.parsePrice(((Sign)seller.getSign().getState()).getLine(3))); + if (seller.getSign().getState() instanceof Sign) + fPrice.setRoot(economyUtil.parsePrice(((Sign) seller.getSign().getState()).getLine(3))); isItems.setRoot(seller.getItems()); containables.setRoot(seller.getContainables()); activatables.setRoot(seller.getActivatables()); - if(player != null) + if (player != null) ssPlayer.setRoot(player); else - ssPlayer.setRoot(new SignShopPlayer((Player)null)); + ssPlayer.setRoot(new SignShopPlayer((Player) null)); ssOwner.setRoot(seller.getOwner()); bSign.setRoot(seller.getSign()); @@ -65,17 +95,17 @@ public SignShopArguments(Seller seller, SignShopPlayer player, SignShopArguments } private void fixBooks() { - if(isItems.getRoot() != null) { + if (isItems.getRoot() != null) { itemUtil.fixBooks(isItems.getRoot()); } - if(containables.getRoot() != null) { + if (containables.getRoot() != null) { itemUtil.fixBooks(itemUtil.getAllItemStacksForContainables(containables.getRoot())); } SignShopPlayer root = ssPlayer.getRoot(); - if(root != null && root.getPlayer() != null) { - if(root.getItemInHand() != null) { + if (root != null && root.getPlayer() != null) { + if (root.getItemInHand() != null) { ItemStack[] stacks = new ItemStack[1]; stacks[0] = root.getItemInHand(); itemUtil.fixBooks(stacks); @@ -88,38 +118,38 @@ private void fixBooks() { } private void setDefaultMessageParts() { - if(ssPlayer.get() != null) { + if (ssPlayer.get() != null) { setMessagePart("!customer", ssPlayer.get().getName()); setMessagePart("!player", ssPlayer.get().getName()); - if(ssPlayer.get().getPlayer() != null && ssPlayer.get().getPlayer().getWorld() != null) + if (ssPlayer.get().getPlayer() != null && ssPlayer.get().getPlayer().getWorld() != null) setMessagePart("!world", ssPlayer.get().getPlayer().getWorld().getName()); - if(Vault.getPermission() != null && ssPlayer.get() != null && ssPlayer.get().getWorld() != null) { + if (Vault.getPermission() != null && ssPlayer.get() != null && ssPlayer.get().getWorld() != null) { World world = ssPlayer.get().getWorld(); String name = ssPlayer.get().getName(); setMessagePart("!permgroup", Vault.getPermission().getPrimaryGroup(world, name)); } } - if(fPrice.get() != null) + if (fPrice.get() != null) setMessagePart("!price", economyUtil.formatMoney(fPrice.get())); - if(ssOwner.get() != null) + if (ssOwner.get() != null) setMessagePart("!owner", ssOwner.get().getName()); - if(bSign.get() != null) { + if (bSign.get() != null) { setMessagePart("!x", Integer.toString(bSign.get().getX())); setMessagePart("!y", Integer.toString(bSign.get().getY())); setMessagePart("!z", Integer.toString(bSign.get().getZ())); - if(bSign.get().getState() instanceof Sign) { + if (bSign.get().getState() instanceof Sign) { String[] sLines = ((Sign) bSign.get().getState()).getLines(); - for(int i = 0; i < sLines.length; i++) - setMessagePart(("!line" + (i+1)), (sLines[i] == null ? "" : sLines[i])); + for (int i = 0; i < sLines.length; i++) + setMessagePart(("!line" + (i + 1)), (sLines[i] == null ? "" : sLines[i])); } } - if(isItems.get() != null && isItems.get().length > 0) { + if (isItems.get() != null && isItems.get().length > 0) { setMessagePart("!items", itemUtil.itemStackToString(isItems.get())); } } @@ -141,97 +171,85 @@ public void resetPriceMod() { bPriceModApplied = false; } - public static String seperator = "~"; - - public Map miscSettings = new HashMap<>(); public SignShopArgument getPrice() { return fPrice; } - private SignShopArgument isItems = new SignShopArgument(this) { - @Override - public void set(ItemStack[] pItems) { - if(getCollection().forceMessageKeys.containsKey("!items") && argumentType == SignShopArgumentsType.Setup) - getCollection().miscSettings.put(getCollection().forceMessageKeys.get("!items").replace("!", ""), - signshopUtil.implode(itemUtil.convertItemStacksToString(pItems), seperator)); - super.set(pItems); - } - }; public SignShopArgument getItems() { return isItems; } - public Map forceMessageKeys = new HashMap<>(); public SignShopArgument> getContainables() { return containables; } - private SignShopArgument fPrice = new SignShopArgument<>(this); public SignShopArgument> getActivatables() { return activatables; } - private SignShopArgument> containables = new SignShopArgument<>(this); public SignShopArgument getPlayer() { return ssPlayer; } - private SignShopArgument> activatables = new SignShopArgument<>(this); public SignShopArgument getOwner() { return ssOwner; } - private SignShopArgument ssPlayer = new SignShopArgument<>(this); public SignShopArgument getSign() { return bSign; } - private SignShopArgument ssOwner = new SignShopArgument<>(this); public SignShopArgument getOperation() { return sOperation; } - private SignShopArgument bSign = new SignShopArgument<>(this); public SignShopArgument getEnchantments() { return sEnchantments; } - private SignShopArgument sOperation = new SignShopArgument<>(this); public SignShopArgument getBlockFace() { return bfBlockFace; } - private SignShopArgument sEnchantments = new SignShopArgument<>(this); public SignShopArgument getAction() { return aAction; } - private SignShopArgument bfBlockFace = new SignShopArgument<>(this); - public void setOperationParameters(List pOperationParameters) { operationParameters.clear(); operationParameters.addAll(pOperationParameters); } - public boolean isOperationParameter(String sOperationParameter) { return operationParameters.contains(sOperationParameter); } - public boolean hasOperationParameters() { return !operationParameters.isEmpty(); } - public String getFirstOperationParameter() { return hasOperationParameters() ? operationParameters.get(0) : ""; } + public void setOperationParameters(List pOperationParameters) { + operationParameters.clear(); + operationParameters.addAll(pOperationParameters); + } - private SignShopArgument aAction = new SignShopArgument<>(this); - public SignShopArgumentsType getArgumentType() { return argumentType; } - public void setArgumentType(SignShopArgumentsType argumentType) { this.argumentType = argumentType; } + public boolean isOperationParameter(String sOperationParameter) { + return operationParameters.contains(sOperationParameter); + } - private List operationParameters = new LinkedList<>(); - private SignShopArgumentsType argumentType; - public boolean bDoNotClearClickmap = false; - public boolean bPriceModApplied = false; - public boolean bRunCommandAsUser = false; + public boolean hasOperationParameters() { + return !operationParameters.isEmpty(); + } + + public String getFirstOperationParameter() { + return hasOperationParameters() ? operationParameters.get(0) : ""; + } + + public SignShopArgumentsType getArgumentType() { + return argumentType; + } + + public void setArgumentType(SignShopArgumentsType argumentType) { + this.argumentType = argumentType; + } - private SSMoneyEventType moneyEventType = SSMoneyEventType.Unknown; public SSMoneyEventType getMoneyEventType() { return moneyEventType; } + public void setMoneyEventType(SSMoneyEventType type) { moneyEventType = type; } public void ignoreEmptyChest() { - if(!isOperationParameter("allowemptychest")) + if (!isOperationParameter("allowemptychest")) operationParameters.add("allowemptychest"); } @@ -240,7 +258,7 @@ public boolean isLeftClicking() { } public void sendFailedRequirementsMessage(String messageName) { - if(!isLeftClicking()) + if (!isLeftClicking()) getPlayer().get().sendMessage(SignShopConfig.getError(messageName, getMessageParts())); } @@ -249,16 +267,14 @@ public boolean isPlayerOnline() { } public boolean tryToApplyPriceMod() { - if(bPriceModApplied) + if (bPriceModApplied) return false; return (bPriceModApplied = true); } - private Map messageParts = new LinkedHashMap<>(); - public void setMessagePart(String name, String value) { messageParts.put(name, value); - if(forceMessageKeys.containsKey(name)) + if (forceMessageKeys.containsKey(name)) name = forceMessageKeys.get(name); messageParts.put(name, value); } @@ -268,7 +284,7 @@ public boolean hasMessagePart(String name) { } public String getMessagePart(String name) { - if(hasMessagePart(name)) + if (hasMessagePart(name)) return messageParts.get(name); return ""; } diff --git a/src/main/java/org/wargamer2010/signshop/player/SignShopPlayer.java b/src/main/java/org/wargamer2010/signshop/player/SignShopPlayer.java index fab63ef7..2ba8b34e 100644 --- a/src/main/java/org/wargamer2010/signshop/player/SignShopPlayer.java +++ b/src/main/java/org/wargamer2010/signshop/player/SignShopPlayer.java @@ -206,6 +206,7 @@ else if(!SignShop.usePermissions() && !OPOperation) return false; } + @SuppressWarnings("WrapperTypeMayBePrimitive") private boolean isNothing(double amount) { Double doubler = amount; return (doubler == 0.0f || doubler.isInfinite() || doubler.isNaN()); diff --git a/src/main/java/org/wargamer2010/signshop/util/DataConverter.java b/src/main/java/org/wargamer2010/signshop/util/DataConverter.java index 4df65508..41254c44 100644 --- a/src/main/java/org/wargamer2010/signshop/util/DataConverter.java +++ b/src/main/java/org/wargamer2010/signshop/util/DataConverter.java @@ -50,12 +50,30 @@ private static void convertData(FileConfiguration sellers) { ConfigurationSection section = sellers.getConfigurationSection("sellers"); Set shops = section.getKeys(false); for (String shop : shops) { - StringBuilder path = new StringBuilder(); - path.append("sellers.").append(shop).append(".items"); - List items = sellers.getStringList(path.toString()); + StringBuilder itemPath = new StringBuilder().append("sellers.").append(shop).append(".items"); + StringBuilder miscPath = new StringBuilder().append("sellers.").append(shop).append(".misc"); + //Strip old data from items + List items = sellers.getStringList(itemPath.toString()); ItemStack[] itemStacks = convertOldStringsToItemStacks(items); - sellers.set(path.toString(), itemUtil.convertItemStacksToString(itemStacks)); - sellers.set("DataVersion",3); + sellers.set(itemPath.toString(), itemUtil.convertItemStacksToString(itemStacks)); + //Strip old data from misc + List misc = sellers.getStringList(miscPath.toString()); + if (!misc.isEmpty()){ + List newMisc = new ArrayList<>(); + for (String miscString : misc){ + if (miscString.startsWith("sharesigns:")){ + newMisc.add(miscString); + continue; + } + String[] strings = miscString.split("\\|",2); + String[] keyPair = strings[0].split(":",2); + String key = keyPair[0]; + String data = strings[1]; + newMisc.add(key+":"+data); + } + sellers.set(miscPath.toString(),newMisc); + } + sellers.set("DataVersion",SignShop.DATA_VERSION); sellers.save(sellersFile); } SignShop.log("Data conversion of " + shops.size() + " shops has finished.", Level.INFO);