Merge branch '1.12' into 1.13

This commit is contained in:
Phoenix616 2018-09-05 23:07:49 +01:00
commit f1ce97dbce
2 changed files with 11 additions and 1 deletions

View File

@ -68,6 +68,9 @@ public class Properties {
@ConfigurationComment("How much money do you get back when destroying a sign?")
public static double SHOP_REFUND_PRICE = 0;
@ConfigurationComment("How many decimal places are allowed at a maximum for prices?")
public static int PRICE_PRECISION = 2;
@PrecededBySpace
@ConfigurationComment("Should we block shops that sell things for more than they buy? (This prevents newbies from creating shops that would be exploited)")
public static boolean BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE = true;

View File

@ -1,6 +1,7 @@
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
import com.Acrobot.Breeze.Utils.PriceUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -18,7 +19,13 @@ public class PriceChecker implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public static void onPreShopCreation(PreShopCreationEvent event) {
String line = event.getSignLine(PRICE_LINE).toUpperCase();
line = line.replaceAll("(\\.\\d*?[1-9])0+", "$1"); //remove trailing zeroes
if (Properties.PRICE_PRECISION <= 0) {
line = line.replaceAll("\\.\\d*", ""); //remove too many decimal places
} else {
line = line.replaceAll("(\\.\\d{0," + Properties.PRICE_PRECISION + "})\\d*", "$1"); //remove too many decimal places
}
line = line.replaceAll("(\\.\\d*[1-9])0+", "$1"); //remove trailing zeroes
line = line.replaceAll("(\\d)\\.0+(\\D|$)", "$1$2"); //remove point and zeroes from strings that only have trailing zeros
String[] part = line.split(":");