From 420b825c3165c3f329af25d13d7b02b77861be7e Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Sun, 29 Jul 2018 16:44:44 +0800 Subject: [PATCH] Fix the tax NullPointer issues in CraftBukkit --- .../org/maxgamer/quickshop/Command/QS.java | 16 ++++++--- .../maxgamer/quickshop/Shop/ShopManager.java | 33 ++++++++++++++----- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Command/QS.java b/src/main/java/org/maxgamer/quickshop/Command/QS.java index cb1e6dcd2..344edd7bf 100644 --- a/src/main/java/org/maxgamer/quickshop/Command/QS.java +++ b/src/main/java/org/maxgamer/quickshop/Command/QS.java @@ -1,8 +1,10 @@ package org.maxgamer.quickshop.Command; import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.Iterator; +import java.util.logging.Level; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -440,12 +442,16 @@ public class QS implements CommandExecutor { return; } sender.sendMessage(MsgUtil.getMessage("fee-charged-for-price-change", plugin.getEcon().format(fee))); - for(OfflinePlayer player : Bukkit.getOfflinePlayers()) { - if(player.getName().equals(plugin.getConfig().getString("tax-account"))) { - plugin.getEcon().deposit(player.getUniqueId(), fee); - } + try { + for(OfflinePlayer player : Bukkit.getOfflinePlayers()) { + if(player.getName().equals(plugin.getConfig().getString("tax-account"))) { + plugin.getEcon().deposit(player.getUniqueId(), fee); + } + } + }catch (IOException ex){ + ex.getMessage(); + plugin.getLogger().log(Level.WARNING, "QuickShop can't pay fee to player `"+plugin.getConfig().getString("tax-account")+"` account,Are you set the default tax account name to your playername?"); } - } // Update the shop shop.setPrice(price); shop.setSignText(); diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index 453c0fd1a..b3247ae97 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -1,8 +1,10 @@ package org.maxgamer.quickshop.Shop; +import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; +import java.util.logging.Level; import java.util.NoSuchElementException; import java.util.UUID; @@ -351,11 +353,15 @@ public class ShopManager { shop.onUnload(); return; } + try { for(OfflinePlayer player : Bukkit.getOfflinePlayers()) { if(player.getName().equals(plugin.getConfig().getString("tax-account"))) { plugin.getEcon().deposit(player.getUniqueId(), tax); } } + }catch (IOException ex){ + ex.getMessage(); + plugin.getLogger().log(Level.WARNING, "QuickShop can't pay tax to player `"+plugin.getConfig().getString("tax-account")+"` account,Are you set the default tax account name to your playername?"); } /* The shop has hereforth been successfully created */ createShop(shop); @@ -495,10 +501,15 @@ public class ShopManager { if (!shop.isUnlimited() || plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners")) { plugin.getEcon().deposit(shop.getOwner(), total * (1 - tax)); if (tax != 0) { - for(OfflinePlayer player : Bukkit.getOfflinePlayers()) { - if(player.getName().equals(plugin.getConfig().getString("tax-account"))) { - plugin.getEcon().deposit(player.getUniqueId(), total * tax); - } + try { + for(OfflinePlayer player : Bukkit.getOfflinePlayers()) { + if(player.getName().equals(plugin.getConfig().getString("tax-account"))) { + plugin.getEcon().deposit(player.getUniqueId(), tax); + } + } + }catch (IOException ex){ + ex.getMessage(); + plugin.getLogger().log(Level.WARNING, "QuickShop can't pay tax to player `"+plugin.getConfig().getString("tax-account")+"` account,Are you set the default tax account name to your playername?"); } } } @@ -564,12 +575,16 @@ public class ShopManager { return; } if (tax != 0) { - for(OfflinePlayer player : Bukkit.getOfflinePlayers()) { - if(player.getName().equals(plugin.getConfig().getString("tax-account"))) { - plugin.getEcon().deposit(player.getUniqueId(), total * tax); - } + try { + for(OfflinePlayer player : Bukkit.getOfflinePlayers()) { + if(player.getName().equals(plugin.getConfig().getString("tax-account"))) { + plugin.getEcon().deposit(player.getUniqueId(), tax); + } + } + }catch (IOException ex){ + ex.getMessage(); + plugin.getLogger().log(Level.WARNING, "QuickShop can't pay tax to player `"+plugin.getConfig().getString("tax-account")+"` account,Are you set the default tax account name to your playername?"); } - } } // Give them the money after we know we succeeded plugin.getEcon().deposit(p.getUniqueId(), total * (1 - tax));