Skip to content

Commit

Permalink
Fix for "misc:" data conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
weaves7 committed Mar 8, 2020
1 parent 7439c2b commit 24c55df
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 71 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.makershaven</groupId>
<artifactId>SignShop</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,50 @@
import java.util.*;

public class SignShopArguments implements IMessagePartContainer {
public static String seperator = "~";
public Map<String, String> miscSettings = new HashMap<>();
public Map<String, String> forceMessageKeys = new HashMap<>();
public boolean bDoNotClearClickmap = false;
public boolean bPriceModApplied = false;
public boolean bRunCommandAsUser = false;
private SignShopArgument<Double> fPrice = new SignShopArgument<>(this);
private SignShopArgument<List<Block>> containables = new SignShopArgument<>(this);
private SignShopArgument<List<Block>> activatables = new SignShopArgument<>(this);
private SignShopArgument<SignShopPlayer> ssPlayer = new SignShopArgument<>(this);
private SignShopArgument<SignShopPlayer> ssOwner = new SignShopArgument<>(this);
private SignShopArgument<Block> bSign = new SignShopArgument<>(this);
private SignShopArgument<String> sOperation = new SignShopArgument<>(this);
private SignShopArgument<String> sEnchantments = new SignShopArgument<>(this);
private SignShopArgument<BlockFace> bfBlockFace = new SignShopArgument<>(this);
private SignShopArgument<Action> aAction = new SignShopArgument<>(this);
private List<String> operationParameters = new LinkedList<>();
private SignShopArgumentsType argumentType;
private SignShopArgument<ItemStack[]> isItems = new SignShopArgument<ItemStack[]>(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<String, String> messageParts = new LinkedHashMap<>();

public SignShopArguments(double pfPrice, ItemStack[] pisItems, List<Block> pContainables, List<Block> 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);
Expand All @@ -44,16 +74,16 @@ public SignShopArguments(double pfPrice, ItemStack[] pisItems, List<Block> 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());
Expand All @@ -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);
Expand All @@ -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()));
}
}
Expand All @@ -141,97 +171,85 @@ public void resetPriceMod() {
bPriceModApplied = false;
}

public static String seperator = "~";

public Map<String, String> miscSettings = new HashMap<>();
public SignShopArgument<Double> getPrice() {
return fPrice;
}

private SignShopArgument<ItemStack[]> isItems = new SignShopArgument<ItemStack[]>(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<ItemStack[]> getItems() {
return isItems;
}

public Map<String, String> forceMessageKeys = new HashMap<>();
public SignShopArgument<List<Block>> getContainables() {
return containables;
}

private SignShopArgument<Double> fPrice = new SignShopArgument<>(this);
public SignShopArgument<List<Block>> getActivatables() {
return activatables;
}

private SignShopArgument<List<Block>> containables = new SignShopArgument<>(this);
public SignShopArgument<SignShopPlayer> getPlayer() {
return ssPlayer;
}

private SignShopArgument<List<Block>> activatables = new SignShopArgument<>(this);
public SignShopArgument<SignShopPlayer> getOwner() {
return ssOwner;
}

private SignShopArgument<SignShopPlayer> ssPlayer = new SignShopArgument<>(this);
public SignShopArgument<Block> getSign() {
return bSign;
}

private SignShopArgument<SignShopPlayer> ssOwner = new SignShopArgument<>(this);
public SignShopArgument<String> getOperation() {
return sOperation;
}

private SignShopArgument<Block> bSign = new SignShopArgument<>(this);
public SignShopArgument<String> getEnchantments() {
return sEnchantments;
}

private SignShopArgument<String> sOperation = new SignShopArgument<>(this);
public SignShopArgument<BlockFace> getBlockFace() {
return bfBlockFace;
}

private SignShopArgument<String> sEnchantments = new SignShopArgument<>(this);
public SignShopArgument<Action> getAction() {
return aAction;
}

private SignShopArgument<BlockFace> bfBlockFace = new SignShopArgument<>(this);
public void setOperationParameters(List<String> 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<String> pOperationParameters) {
operationParameters.clear();
operationParameters.addAll(pOperationParameters);
}

private SignShopArgument<Action> 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<String> 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");
}

Expand All @@ -240,7 +258,7 @@ public boolean isLeftClicking() {
}

public void sendFailedRequirementsMessage(String messageName) {
if(!isLeftClicking())
if (!isLeftClicking())
getPlayer().get().sendMessage(SignShopConfig.getError(messageName, getMessageParts()));
}

Expand All @@ -249,16 +267,14 @@ public boolean isPlayerOnline() {
}

public boolean tryToApplyPriceMod() {
if(bPriceModApplied)
if (bPriceModApplied)
return false;
return (bPriceModApplied = true);
}

private Map<String, String> 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);
}
Expand All @@ -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 "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/org/wargamer2010/signshop/util/DataConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,30 @@ private static void convertData(FileConfiguration sellers) {
ConfigurationSection section = sellers.getConfigurationSection("sellers");
Set<String> shops = section.getKeys(false);
for (String shop : shops) {
StringBuilder path = new StringBuilder();
path.append("sellers.").append(shop).append(".items");
List<String> 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<String> 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<String> misc = sellers.getStringList(miscPath.toString());
if (!misc.isEmpty()){
List<String> 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);
Expand Down

0 comments on commit 24c55df

Please sign in to comment.