Merge remote-tracking branch 'origin/master'

Former-commit-id: f35955a789854933a46bfc865c7e5a1c45dcb89c
This commit is contained in:
Ghost_chu committed 2020-04-12 12:19:22 +08:00
commit 9def06335e
8 files changed
+83 -33

No files matched your search

@@ -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;
}
@@ -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()) + "##########");
}
@@ -0,0 +1,47 @@
/*
* This file is a part of project QuickShop, the name is CalculateUtil.java
* Copyright (C) sandtechnology <https://github.com/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 <http://www.gnu.org/licenses/>.
*/
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();
}
}
@@ -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;
@@ -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());
}));
}
}
}