From 3cba8762e994258424e17cececed693f0ad027f5 Mon Sep 17 00:00:00 2001 From: sandtechnology Date: Sun, 12 Apr 2020 10:34:32 +0800 Subject: [PATCH 1/3] Addition no def class found fix on 1.14 Former-commit-id: d351bf76db2603c9cbe626d01b99803c0472a466 --- .../item/QuickShopItemMatcherImpl.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/util/matcher/item/QuickShopItemMatcherImpl.java b/src/main/java/org/maxgamer/quickshop/util/matcher/item/QuickShopItemMatcherImpl.java index af13e7080..66d70f88b 100644 --- a/src/main/java/org/maxgamer/quickshop/util/matcher/item/QuickShopItemMatcherImpl.java +++ b/src/main/java/org/maxgamer/quickshop/util/matcher/item/QuickShopItemMatcherImpl.java @@ -490,7 +490,7 @@ public class QuickShopItemMatcherImpl implements ItemMatcher { return itemMatcher.matches(((ShulkerBox) ((BlockStateMeta) meta1).getBlockState()).getInventory().getContents(), ((ShulkerBox) ((BlockStateMeta) meta2).getBlockState()).getInventory().getContents()); })); if(!Util.getNMSVersion().equals("v1_13_R1")&&!Util.getNMSVersion().equals("v1_13_R2")){ - addIfEnable(itemMatcherConfig,"custommodeldata",((meta1, meta2) -> { + addIfEnable(itemMatcherConfig, "custommodeldata", ((meta1, meta2) -> { if (!meta1.hasCustomModelData()) { return true; } else { @@ -500,20 +500,22 @@ public class QuickShopItemMatcherImpl implements ItemMatcher { return meta1.getCustomModelData() == meta2.getCustomModelData(); } })); - addIfEnable(itemMatcherConfig,"suspiciousStew",((meta1, meta2) -> { - if ((meta1 instanceof SuspiciousStewMeta) != (meta2 instanceof SuspiciousStewMeta)) { - return false; - } - if (!(meta1 instanceof SuspiciousStewMeta)) { - return true; - } - SuspiciousStewMeta stewMeta1= ((SuspiciousStewMeta) meta1); - SuspiciousStewMeta stewMeta2= ((SuspiciousStewMeta) meta2); - if(!stewMeta1.hasCustomEffects()){ - return true; - } - return stewMeta1.getCustomEffects().equals(stewMeta2.getCustomEffects()); - })); + if (!Util.getNMSVersion().equals("v1_14_R1")) { + addIfEnable(itemMatcherConfig, "suspiciousStew", ((meta1, meta2) -> { + if ((meta1 instanceof SuspiciousStewMeta) != (meta2 instanceof SuspiciousStewMeta)) { + return false; + } + if (!(meta1 instanceof SuspiciousStewMeta)) { + return true; + } + SuspiciousStewMeta stewMeta1 = ((SuspiciousStewMeta) meta1); + SuspiciousStewMeta stewMeta2 = ((SuspiciousStewMeta) meta2); + if (!stewMeta1.hasCustomEffects()) { + return true; + } + return stewMeta1.getCustomEffects().equals(stewMeta2.getCustomEffects()); + })); + } } } From e48c9dc90663db74b2d711fb04bab9ace3b199d7 Mon Sep 17 00:00:00 2001 From: sandtechnology Date: Sun, 12 Apr 2020 11:05:15 +0800 Subject: [PATCH 2/3] Fix counting issue, close #414 Former-commit-id: 255e7395d8ce7cd0c68d7f4fb11f6ebd6dc10184 --- .../maxgamer/quickshop/shop/ShopManager.java | 15 +++--- .../quickshop/util/CalculateUtil.java | 47 +++++++++++++++++++ .../game}/BukkitGameLanguageImpl.java | 0 .../Game => language/game}/GameLanguage.java | 0 .../game}/InternalGameLanguageImpl.java | 0 .../game}/MojangGameLanguageImpl.java | 4 +- 6 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/maxgamer/quickshop/util/CalculateUtil.java rename src/main/java/org/maxgamer/quickshop/util/{Language/Game => language/game}/BukkitGameLanguageImpl.java (100%) rename src/main/java/org/maxgamer/quickshop/util/{Language/Game => language/game}/GameLanguage.java (100%) rename src/main/java/org/maxgamer/quickshop/util/{Language/Game => language/game}/InternalGameLanguageImpl.java (100%) rename src/main/java/org/maxgamer/quickshop/util/{Language/Game => language/game}/MojangGameLanguageImpl.java (100%) diff --git a/src/main/java/org/maxgamer/quickshop/shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/shop/ShopManager.java index 7c4a59153..8d3312f1b 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ShopManager.java @@ -40,6 +40,7 @@ import org.maxgamer.quickshop.event.ShopCreateEvent; import org.maxgamer.quickshop.event.ShopPreCreateEvent; import org.maxgamer.quickshop.event.ShopPurchaseEvent; import org.maxgamer.quickshop.event.ShopSuccessPurchaseEvent; +import org.maxgamer.quickshop.util.CalculateUtil; import org.maxgamer.quickshop.util.MsgUtil; import org.maxgamer.quickshop.util.Util; @@ -564,8 +565,8 @@ public class ShopManager { return; // Cancelled } // Money handling - double tax = getTax(shop,p); - double total = amount * shop.getPrice(); + double tax = getTax(shop, p); + double total = CalculateUtil.multiply(amount, shop.getPrice()); boolean shouldPayOwner = !shop.isUnlimited() || (plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners") && shop.isUnlimited()); if (shouldPayOwner) { @@ -575,7 +576,7 @@ public class ShopManager { return; } } - double depositMoney = total * (1 - tax); + double depositMoney = CalculateUtil.multiply(total, CalculateUtil.subtract(1, tax)); boolean successB = eco.deposit(p.getUniqueId(), depositMoney); // Deposit player's money if (!successB) { plugin.getLogger().warning("Failed to deposit the money " + depositMoney + " to player " + e.getPlayer().getName()); @@ -590,7 +591,7 @@ public class ShopManager { } // Purchase successfully if (tax != 0 && cacheTaxAccount != null) { - eco.deposit(cacheTaxAccount, total * tax); + eco.deposit(cacheTaxAccount, CalculateUtil.multiply(total, tax)); } // Notify the owner of the purchase. String msg = MsgUtil.getMessage("player-sold-to-your-store", p, p.getName(), String.valueOf(amount), "##########" + Util.serialize(shop.getItem()) + "##########"); @@ -831,7 +832,7 @@ public class ShopManager { } double tax = getTax(shop,p); // Money handling - double total = amount * shop.getPrice(); + double total = CalculateUtil.multiply(amount, shop.getPrice()); boolean successA = eco.withdraw(p.getUniqueId(), total); // Withdraw owner's money @@ -841,7 +842,7 @@ public class ShopManager { } boolean shouldPayOwner = !shop.isUnlimited() || (plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners") && shop.isUnlimited()); if (shouldPayOwner) { - double depositMoney = total * (1 - tax); + double depositMoney = CalculateUtil.multiply(total, CalculateUtil.subtract(1, tax)); boolean successB = eco.deposit(shop.getOwner(), depositMoney); if (!successB) { plugin.getLogger().warning("Failed to deposit the money for player " + Bukkit.getOfflinePlayer(shop.getOwner())); @@ -857,7 +858,7 @@ public class ShopManager { String msg; // Notify the shop owner if (plugin.getConfig().getBoolean("show-tax")) { - msg = MsgUtil.getMessage("player-bought-from-your-store-tax", p, p.getName(), "" + amount, "##########" + Util.serialize(shop.getItem()) + "##########", Util.format((tax * total))); + msg = MsgUtil.getMessage("player-bought-from-your-store-tax", p, p.getName(), "" + amount, "##########" + Util.serialize(shop.getItem()) + "##########", Util.format((CalculateUtil.multiply(tax, total)))); } else { msg = MsgUtil.getMessage("player-bought-from-your-store", p, p.getName(), "" + amount, "##########" + Util.serialize(shop.getItem()) + "##########"); } diff --git a/src/main/java/org/maxgamer/quickshop/util/CalculateUtil.java b/src/main/java/org/maxgamer/quickshop/util/CalculateUtil.java new file mode 100644 index 000000000..1d241899a --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/util/CalculateUtil.java @@ -0,0 +1,47 @@ +/* + * This file is a part of project QuickShop, the name is CalculateUtil.java + * Copyright (C) sandtechnology + * Copyright (C) Bukkit Commons Studio and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +package org.maxgamer.quickshop.util; + +import java.math.BigDecimal; +import java.math.MathContext; + +public class CalculateUtil { + private static final MathContext mathContext = MathContext.DECIMAL32; + + private CalculateUtil() { + } + + public static double divide(double number1, double number2) { + return (BigDecimal.valueOf(number1).divide(BigDecimal.valueOf(number2), mathContext)).doubleValue(); + } + + public static double subtract(double number1, double number2) { + return (BigDecimal.valueOf(number1).subtract(BigDecimal.valueOf(number2), mathContext)).doubleValue(); + } + + public static double multiply(double number1, double number2) { + return (BigDecimal.valueOf(number1).multiply(BigDecimal.valueOf(number2), mathContext)).doubleValue(); + } + + public static double add(double number1, double number2) { + return (BigDecimal.valueOf(number1).add(BigDecimal.valueOf(number2), mathContext)).doubleValue(); + } + + +} diff --git a/src/main/java/org/maxgamer/quickshop/util/Language/Game/BukkitGameLanguageImpl.java b/src/main/java/org/maxgamer/quickshop/util/language/game/BukkitGameLanguageImpl.java similarity index 100% rename from src/main/java/org/maxgamer/quickshop/util/Language/Game/BukkitGameLanguageImpl.java rename to src/main/java/org/maxgamer/quickshop/util/language/game/BukkitGameLanguageImpl.java diff --git a/src/main/java/org/maxgamer/quickshop/util/Language/Game/GameLanguage.java b/src/main/java/org/maxgamer/quickshop/util/language/game/GameLanguage.java similarity index 100% rename from src/main/java/org/maxgamer/quickshop/util/Language/Game/GameLanguage.java rename to src/main/java/org/maxgamer/quickshop/util/language/game/GameLanguage.java diff --git a/src/main/java/org/maxgamer/quickshop/util/Language/Game/InternalGameLanguageImpl.java b/src/main/java/org/maxgamer/quickshop/util/language/game/InternalGameLanguageImpl.java similarity index 100% rename from src/main/java/org/maxgamer/quickshop/util/Language/Game/InternalGameLanguageImpl.java rename to src/main/java/org/maxgamer/quickshop/util/language/game/InternalGameLanguageImpl.java diff --git a/src/main/java/org/maxgamer/quickshop/util/Language/Game/MojangGameLanguageImpl.java b/src/main/java/org/maxgamer/quickshop/util/language/game/MojangGameLanguageImpl.java similarity index 100% rename from src/main/java/org/maxgamer/quickshop/util/Language/Game/MojangGameLanguageImpl.java rename to src/main/java/org/maxgamer/quickshop/util/language/game/MojangGameLanguageImpl.java index 18eab5570..7b638b152 100644 --- a/src/main/java/org/maxgamer/quickshop/util/Language/Game/MojangGameLanguageImpl.java +++ b/src/main/java/org/maxgamer/quickshop/util/language/game/MojangGameLanguageImpl.java @@ -17,10 +17,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.util.Copied; -import org.maxgamer.quickshop.util.mojangapi.AssetJson; -import org.maxgamer.quickshop.util.mojangapi.MojangAPI; import org.maxgamer.quickshop.util.ReflectFactory; import org.maxgamer.quickshop.util.Util; +import org.maxgamer.quickshop.util.mojangapi.AssetJson; +import org.maxgamer.quickshop.util.mojangapi.MojangAPI; import java.io.ByteArrayInputStream; import java.io.File; From 1429cc0a48526d2603f3b6bdf600ff6eb9d027c3 Mon Sep 17 00:00:00 2001 From: sandtechnology Date: Sun, 12 Apr 2020 12:09:13 +0800 Subject: [PATCH 3/3] Fix change shop owner command showed previous owner issue Former-commit-id: ef9627eeb576063665b4248c711c99be7d8588dc --- .../subcommand/SubCommand_SetOwner.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_SetOwner.java b/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_SetOwner.java index 27ea96c47..319ee73a5 100644 --- a/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_SetOwner.java +++ b/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_SetOwner.java @@ -19,19 +19,20 @@ package org.maxgamer.quickshop.command.subcommand; -import java.util.ArrayList; -import java.util.List; import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.BlockIterator; import org.jetbrains.annotations.NotNull; -import org.maxgamer.quickshop.command.CommandProcesser; import org.maxgamer.quickshop.QuickShop; +import org.maxgamer.quickshop.command.CommandProcesser; import org.maxgamer.quickshop.shop.Shop; import org.maxgamer.quickshop.util.MsgUtil; +import java.util.ArrayList; +import java.util.List; + public class SubCommand_SetOwner implements CommandProcesser { private final QuickShop plugin = QuickShop.instance; @@ -64,16 +65,15 @@ public class SubCommand_SetOwner implements CommandProcesser { continue; } - @SuppressWarnings("deprecation") final OfflinePlayer p = plugin.getServer().getOfflinePlayer(cmdArg[0]); - final String shopOwner = plugin.getServer().getOfflinePlayer(shop.getOwner()).getName(); - if (shopOwner == null) { - MsgUtil.sendMessage(sender,MsgUtil.getMessage("unknown-player", null)); + @SuppressWarnings("deprecation") final OfflinePlayer newShopOwner = plugin.getServer().getOfflinePlayer(cmdArg[0]); + if (newShopOwner.getName() == null) { + MsgUtil.sendMessage(sender, MsgUtil.getMessage("unknown-player", null)); return; } - shop.setOwner(p.getUniqueId()); + shop.setOwner(newShopOwner.getUniqueId()); // shop.setSignText(); shop.update(); - MsgUtil.sendMessage(sender,MsgUtil.getMessage("command.new-owner", sender, shopOwner)); + MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.new-owner", sender, newShopOwner.getName())); return; }