From 22f60f8ba5a39335abcf914ba42c3089f69e5407 Mon Sep 17 00:00:00 2001 From: KillerOfPie Date: Mon, 26 Oct 2020 13:19:14 -0700 Subject: [PATCH] Internal Permissions and shulker over trade fix - Added support for internal permissions, disabled by default. - Fixed bug where shops were trading all matching shulkers in their inventory instead of the proper amount. --- .../java/org/shanerx/tradeshop/TradeShop.java | 32 ++++++++----- .../tradeshop/commands/CommandCaller.java | 36 +++++---------- .../tradeshop/commands/CommandRunner.java | 45 +++++++++++++++---- .../tradeshop/commands/CommandTabCaller.java | 34 ++++---------- .../shanerx/tradeshop/enumys/Commands.java | 31 ++++++++----- .../org/shanerx/tradeshop/enumys/Message.java | 16 ++++--- .../shanerx/tradeshop/enumys/PermStatus.java | 32 +++++++++++++ .../shanerx/tradeshop/enumys/Permissions.java | 37 ++++++++++----- .../org/shanerx/tradeshop/enumys/Setting.java | 40 ++++++++++------- .../shanerx/tradeshop/enumys/ShopType.java | 8 ++-- .../listeners/JoinEventListener.java | 4 +- .../listeners/ShopProtectionListener.java | 6 +-- .../org/shanerx/tradeshop/utils/Utils.java | 6 +++ 13 files changed, 208 insertions(+), 119 deletions(-) create mode 100644 src/main/java/org/shanerx/tradeshop/enumys/PermStatus.java diff --git a/src/main/java/org/shanerx/tradeshop/TradeShop.java b/src/main/java/org/shanerx/tradeshop/TradeShop.java index 993ffec6..bf32158c 100644 --- a/src/main/java/org/shanerx/tradeshop/TradeShop.java +++ b/src/main/java/org/shanerx/tradeshop/TradeShop.java @@ -43,18 +43,20 @@ public class TradeShop extends JavaPlugin { - private final NamespacedKey storageKey = new NamespacedKey(this, "tradeshop-storage-data"); - private final NamespacedKey signKey = new NamespacedKey(this, "tradeshop-sign-data"); + private final NamespacedKey storageKey = new NamespacedKey(this, "tradeshop-storage-data"); + private final NamespacedKey signKey = new NamespacedKey(this, "tradeshop-sign-data"); - private final int bStatsPluginID = 1690; + private final int bStatsPluginID = 1690; private Metrics metrics; + private boolean useInternalPerms = false; + private ListManager lists; private DataStorage dataStorage; private BukkitVersion version; private ShopSign signs; - private ShopStorage storages; + private ShopStorage storages; private Debug debugger; @@ -123,15 +125,23 @@ public void onDisable() { getListManager().clearManager(); } - public NamespacedKey getStorageKey() { - return storageKey; - } + public boolean useInternalPerms() { + return useInternalPerms; + } - public NamespacedKey getSignKey() { - return signKey; - } + public void setUseInternalPerms(boolean useInternalPerms) { + this.useInternalPerms = useInternalPerms; + } + + public NamespacedKey getStorageKey() { + return storageKey; + } + + public NamespacedKey getSignKey() { + return signKey; + } - public ListManager getListManager() { + public ListManager getListManager() { return lists; } diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java b/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java index 239eeb2a..9522819f 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java +++ b/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java @@ -28,7 +28,6 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.enumys.Commands; import org.shanerx.tradeshop.enumys.Message; @@ -40,7 +39,7 @@ **/ public class CommandCaller implements CommandExecutor { - private TradeShop plugin; + private final TradeShop plugin; private CommandPass cmdPass; private Commands command; private CommandRunner cmdRnnr; @@ -54,15 +53,19 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String cmdPass = new CommandPass(sender, cmd, label, args); command = Commands.getType(cmdPass.getArgAt(0)); - if (!cmdPass.hasArgs() || command == null) { sender.sendMessage(Message.INVALID_ARGUMENTS.getPrefixed()); return true; } - if (!checkPerm()) { - return true; + switch (command.checkPerm(sender)) { + case NO_PERM: + sender.sendMessage(Message.NO_COMMAND_PERMISSION.getPrefixed()); + return true; + case PLAYER_ONLY: + sender.sendMessage(Message.PLAYER_ONLY_COMMAND.getPrefixed()); + return true; } if (command.getMinArgs() > args.length || command.getMaxArgs() < args.length) { @@ -70,11 +73,6 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String return true; } - if (command.needsPlayer() && !(sender instanceof Player)) { - sender.sendMessage(Message.PLAYER_ONLY_COMMAND.getPrefixed()); - return true; - } - cmdRnnr = new CommandRunner(plugin, cmdPass); switch (command) { @@ -141,21 +139,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String case REMOVE_COST: cmdRnnr.removeCost(); break; - } - - return true; - } - - - /** - * Checks if the sender has the required permission - * - * @return true if permission is NONE or sender has permission - */ - public boolean checkPerm() { - if (!command.checkPerm(cmdPass.getSender())) { - cmdPass.getSender().sendMessage(Message.NO_COMMAND_PERMISSION.getPrefixed()); - return false; + case PLAYER_LEVEL: + cmdRnnr.playerLevel(); + break; } return true; diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java b/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java index e86e2220..e829e3d2 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java +++ b/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java @@ -50,8 +50,8 @@ public class CommandRunner extends Utils { - private TradeShop plugin; - private CommandPass command; + private final TradeShop plugin; + private final CommandPass command; private Player pSender; public CommandRunner(TradeShop instance, CommandPass command) { @@ -91,7 +91,7 @@ public void help() { .append("\n\n&b/tradeshop &f &f Display help message\n"); for (Commands c : Commands.values()) { - if (c.checkPerm(command.getSender())) { + if (c.checkPerm(command.getSender()) == PermStatus.GOOD) { sb.append(Message.colour(String.format("&b/ts %s &f %s\n", c.getFirstName(), c.getDescription()))); } } @@ -539,7 +539,7 @@ public void open() { if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()) || - pSender.hasPermission(Permissions.ADMIN.getPerm()))) { + Permissions.hasPermission(pSender, Permissions.ADMIN))) { sendMessage(Message.NO_EDIT.getPrefixed()); return; } @@ -576,7 +576,7 @@ public void close() { if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()) || - pSender.hasPermission(Permissions.ADMIN.getPerm()))) { + Permissions.hasPermission(pSender, Permissions.ADMIN))) { sendMessage(Message.NO_EDIT.getPrefixed()); return; } @@ -842,16 +842,45 @@ public void multi() { if (amount < 2) amount = 2; - else if (amount > Setting.MULTI_TRADE_MAX.getInt()) - amount = Setting.MULTI_TRADE_MAX.getInt(); + else if (amount > Setting.MULTI_TRADE_MAX.getInt()) + amount = Setting.MULTI_TRADE_MAX.getInt(); playerSetting.setMulti(amount); - plugin.getDataStorage().savePlayer(playerSetting); + plugin.getDataStorage().savePlayer(playerSetting); sendMessage(Message.MULTI_UPDATE.getPrefixed().replaceAll("%amount%", String.valueOf(amount))); } } + /* + * Changes/Sets the players permission level if internal permissions is enabled + */ + public void playerLevel() { + if (Bukkit.getOfflinePlayer(command.getArgAt(1)).hasPlayedBefore()) { + PlayerSetting playerSetting = plugin.getDataStorage().loadPlayer(Bukkit.getOfflinePlayer(command.getArgAt(1)).getUniqueId()); + if (command.argsSize() == 2) { + sendMessage(Message.VIEW_PLAYER_LEVEL.getMessage() + .replace("%player%", Bukkit.getOfflinePlayer(command.getArgAt(1)).getName()) + .replace("%level%", playerSetting.getType() + "")); + } else { + if (isInt(command.getArgAt(2))) { + int newLevel = Integer.parseInt(command.getArgAt(2)); + + playerSetting.setType(newLevel); + plugin.getDataStorage().savePlayer(playerSetting); + + sendMessage(Message.SET_PLAYER_LEVEL.getMessage() + .replace("%player%", Bukkit.getOfflinePlayer(command.getArgAt(1)).getName()) + .replace("%level%", playerSetting.getType() + "")); + } else { + sendMessage(Message.INVALID_ARGUMENTS.getMessage()); + } + } + } else { + sendMessage(Message.PLAYER_NOT_FOUND.getMessage()); + } + } + /** * Returns the Shop the player is looking at * diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandTabCaller.java b/src/main/java/org/shanerx/tradeshop/commands/CommandTabCaller.java index ffe62e22..09e1e0a5 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/CommandTabCaller.java +++ b/src/main/java/org/shanerx/tradeshop/commands/CommandTabCaller.java @@ -28,11 +28,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.enumys.Commands; import org.shanerx.tradeshop.enumys.Message; -import org.shanerx.tradeshop.enumys.Permissions; import java.util.ArrayList; import java.util.Collections; @@ -40,7 +38,7 @@ public class CommandTabCaller implements TabCompleter { - private TradeShop plugin; + private final TradeShop plugin; private CommandPass cmdPass; private Commands command; private CommandTabCompleter tabCompleter; @@ -56,13 +54,12 @@ public List onTabComplete(CommandSender sender, Command cmd, String labe if (command != null) { - if (!checkPerm()) { - return Collections.EMPTY_LIST; - } - - if (command.needsPlayer() && !(sender instanceof Player)) { - sender.sendMessage(Message.PLAYER_ONLY_COMMAND.getPrefixed()); - return Collections.EMPTY_LIST; + switch (command.checkPerm(sender)) { + case NO_PERM: + return Collections.EMPTY_LIST; + case PLAYER_ONLY: + sender.sendMessage(Message.PLAYER_ONLY_COMMAND.getPrefixed()); + return Collections.EMPTY_LIST; } tabCompleter = new CommandTabCompleter(plugin, cmdPass); @@ -71,18 +68,15 @@ public List onTabComplete(CommandSender sender, Command cmd, String labe case HELP: return tabCompleter.help(); case ADD_PRODUCT: - return tabCompleter.addSet(); case ADD_COST: - return tabCompleter.addSet(); case SET_COST: - return tabCompleter.addSet(); case SET_PRODUCT: return tabCompleter.addSet(); - case ADD_MANAGER: - return tabCompleter.fillServerPlayer(); case REMOVE_USER: return tabCompleter.fillShopPlayer(); + case ADD_MANAGER: case ADD_MEMBER: + case PLAYER_LEVEL: return tabCompleter.fillServerPlayer(); default: return Collections.EMPTY_LIST; @@ -101,14 +95,4 @@ public List onTabComplete(CommandSender sender, Command cmd, String labe return Collections.EMPTY_LIST; } } - - - /** - * Checks if the sender has the required permission - * - * @return true if permission is NONE or sender has permission - */ - public boolean checkPerm() { - return cmdPass.getSender().hasPermission(command.getPerm().getPerm()) || command.getPerm().equals(Permissions.NONE); - } } diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Commands.java b/src/main/java/org/shanerx/tradeshop/enumys/Commands.java index feadccb2..178dba69 100644 --- a/src/main/java/org/shanerx/tradeshop/enumys/Commands.java +++ b/src/main/java/org/shanerx/tradeshop/enumys/Commands.java @@ -27,6 +27,7 @@ import com.google.common.collect.Lists; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.util.List; @@ -42,6 +43,7 @@ public enum Commands { HELP(Lists.newArrayList("help", "?"), Permissions.HELP, 1, 2, false, "Display help message", "/tradeshop $cmd$ [command]"), SETUP(Lists.newArrayList("setup", "start", "create", "make"), Permissions.HELP, 1, 1, false, "Display shop setup tutorial", "/tradeshop $cmd$"), BUGS(Lists.newArrayList("bugs", "bug"), Permissions.NONE, 1, 1, false, "Report bugs to the developers", "/tradeshop $cmd$"), + PLAYER_LEVEL(Lists.newArrayList("playerlevel", "pl"), Permissions.MANAGE_PLUGIN, 2, 3, false, "If Internal Permissions is enable this allows the getting and setting of player permission levels.", "/tradeshop $cmd$ "), ADD_MANAGER(Lists.newArrayList("addManager"), Permissions.NONE, 2, 2, true, "Add manager to shop", "/tradeshop $cmd$ "), REMOVE_USER(Lists.newArrayList("removeUser", "removeManager", "removeMember"), Permissions.NONE, 2, 2, true, "Remove user from shop", "/tradeshop $cmd$ "), ADD_MEMBER(Lists.newArrayList("addMember"), Permissions.NONE, 2, 2, true, "Add member to shop", "/tradeshop $cmd$ "), @@ -64,37 +66,38 @@ public enum Commands { /** * Name of the permission **/ - private String name; + private final String name; /** * All names that can be used to call the command **/ - private List names; + private final List names; /** * Minimum and Maximum arguments required for the command **/ - private int minArgs, maxArgs; + private final int minArgs; + private final int maxArgs; /** * Permission required for the command **/ - private Permissions perm; + private final Permissions perm; /** * Whether the command requires a player to run **/ - private boolean needsPlayer; + private final boolean needsPlayer; /** * Description for command */ - private String description; + private final String description; /** * Command usage */ - private String usage; + private final String usage; Commands(List names, Permissions perm, int minArgs, int maxArgs, boolean needsPlayer, String description, String usage) { this.names = names; @@ -257,7 +260,15 @@ public String getAliases() { * @param sender sender to check perm for * @return true is player has perm */ - public boolean checkPerm(CommandSender sender) { - return getPerm().equals(Permissions.NONE) || sender.hasPermission(getPerm().getPerm()); + public PermStatus checkPerm(CommandSender sender) { + if (sender instanceof Player) { + if (!Permissions.hasPermission((Player) sender, getPerm())) + return PermStatus.NO_PERM; + } else { + if (needsPlayer()) + return PermStatus.PLAYER_ONLY; + } + + return PermStatus.GOOD; } -} +} \ No newline at end of file diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Message.java b/src/main/java/org/shanerx/tradeshop/enumys/Message.java index 8f891e8c..864a9174 100644 --- a/src/main/java/org/shanerx/tradeshop/enumys/Message.java +++ b/src/main/java/org/shanerx/tradeshop/enumys/Message.java @@ -101,16 +101,20 @@ public enum Message { UNSUCCESSFUL_SHOP_MEMBERS(MessageSectionKeys.NONE, "&aThat player is either already on the shop, or you have reached the maximum number of users!", "Text to display when shop users could not be updated"), UPDATED_SHOP_MEMBERS(MessageSectionKeys.NONE, "&aShop owners and members have been updated!", "Text to display when shop users have been updated successfully"), WHO_MESSAGE(MessageSectionKeys.NONE, "&6Shop users are:\n&2Owner: &e{OWNER}\n&2Managers: &e{MANAGERS}\n&2Members: &e{MEMBERS}", "Text to display when players use the who command"), + VIEW_PLAYER_LEVEL(MessageSectionKeys.NONE, "&e%player% has a level of %level%.", "Text to display when viewing a players level with /ts PlayerLevel"), + SET_PLAYER_LEVEL(MessageSectionKeys.NONE, "&aYou have set the level of %player% to %level%!", "Text to display after setting a players level"), VARIOUS_ITEM_TYPE(MessageSectionKeys.NONE, "Various", "Text to display when a message uses an Item Type and the Type varies"); private static final char COLOUR_CHAR = '&'; - private static TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop"); - private static File file = new File(plugin.getDataFolder(), "messages.yml"); + private static final TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop"); + private static final File file = new File(plugin.getDataFolder(), "messages.yml"); private static FileConfiguration config = YamlConfiguration.loadConfiguration(file); private static String PREFIX = Setting.MESSAGE_PREFIX.getString() + " "; - private String defaultValue, preComment = "", postComment = ""; - private MessageSectionKeys sectionKey; + private final String defaultValue; + private final MessageSectionKeys sectionKey; + private String preComment = ""; + private String postComment = ""; Message(MessageSectionKeys sectionKey, String defaultValue) { @@ -235,7 +239,9 @@ enum MessageSectionKeys { NONE("", ""), UNUSED("", ""); - private String key, sectionHeader, value_lead = ""; + private final String key; + private final String sectionHeader; + private String value_lead = ""; private MessageSectionKeys parent; MessageSectionKeys(String key, String sectionHeader) { diff --git a/src/main/java/org/shanerx/tradeshop/enumys/PermStatus.java b/src/main/java/org/shanerx/tradeshop/enumys/PermStatus.java new file mode 100644 index 00000000..af4aff7d --- /dev/null +++ b/src/main/java/org/shanerx/tradeshop/enumys/PermStatus.java @@ -0,0 +1,32 @@ +/* + * + * Copyright (c) 2016-2019 + * SparklingComet @ http://shanerx.org + * KillerOfPie @ http://killerofpie.github.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * NOTICE: All modifications made by others to the source code belong + * to the respective contributor. No contributor should be held liable for + * any damages of any kind, whether be material or moral, which were + * caused by their contribution(s) to the project. See the full License for more information. + * + */ + +package org.shanerx.tradeshop.enumys; + +public enum PermStatus { + GOOD, + NO_PERM, + PLAYER_ONLY +} \ No newline at end of file diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Permissions.java b/src/main/java/org/shanerx/tradeshop/enumys/Permissions.java index 7a7432f1..ee9c59b3 100644 --- a/src/main/java/org/shanerx/tradeshop/enumys/Permissions.java +++ b/src/main/java/org/shanerx/tradeshop/enumys/Permissions.java @@ -26,32 +26,37 @@ package org.shanerx.tradeshop.enumys; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.shanerx.tradeshop.TradeShop; public enum Permissions { - HELP("help"), + HELP("help", 0), - CREATE("create"), + CREATE("create", 0), - CREATEI("create.infinite"), + CREATEI("create.infinite", 1), - CREATEBI("create.bi"), + CREATEBI("create.bi", 0), - ADMIN("admin"), + ADMIN("admin", 1), - EDIT("edit"), // non admin perm + EDIT("edit", 0), // non admin perm - INFO("info"), + INFO("info", 0), - NONE(""); + MANAGE_PLUGIN("manage-plugin", 2), + + NONE("", 0); private final static TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop"); - private String key; + private final String key; + private final int level; - Permissions(String key) { + Permissions(String key, int level) { this.key = key; + this.level = level; } @Override @@ -66,4 +71,16 @@ public String getValue() { public Permission getPerm() { return new Permission(toString()); } + + public static boolean hasPermission(Player player, Permissions permission) { + if (plugin.useInternalPerms()) { + return plugin.getDataStorage().loadPlayer(player.getUniqueId()).getType() >= permission.getLevel(); + } else { + return permission.equals(Permissions.NONE) || player.hasPermission(permission.getPerm()); + } + } + + public int getLevel() { + return level; + } } \ No newline at end of file diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Setting.java b/src/main/java/org/shanerx/tradeshop/enumys/Setting.java index d512be64..02f11cf5 100644 --- a/src/main/java/org/shanerx/tradeshop/enumys/Setting.java +++ b/src/main/java/org/shanerx/tradeshop/enumys/Setting.java @@ -49,7 +49,8 @@ public enum Setting { DATA_STORAGE_TYPE(SettingSectionKeys.SYSTEM_OPTIONS, "data-storage-type", "FLATFILE", "How would you like your servers data stored? (FLATFILE, SQLITE)"), ENABLE_DEBUG(SettingSectionKeys.SYSTEM_OPTIONS, "enable-debug", 0, "What debug code should be run. this will add significant amounts of spam to the console/log, generally not used unless requested by Devs (must be a whole number)"), CHECK_UPDATES(SettingSectionKeys.SYSTEM_OPTIONS, "check-updates", true, "Should we check for updates when the server starts"), - ALLOW_METRICS(SettingSectionKeys.SYSTEM_OPTIONS, "allow-metrics", true, "Allow us to connect anonymous metrics so we can see how our plugin is being used to better develop it", "\n"), + ALLOW_METRICS(SettingSectionKeys.SYSTEM_OPTIONS, "allow-metrics", true, "Allow us to connect anonymous metrics so we can see how our plugin is being used to better develop it"), + USE_INTERNAL_PERMISSIONS(SettingSectionKeys.SYSTEM_OPTIONS, "use-internal-permissions", false, "Should our internal permission system be used? (Only enable if you aren't using a permission plugin)", "\n"), // Language Options MESSAGE_PREFIX(SettingSectionKeys.LANGUAGE_OPTIONS, "message-prefix", "&a[&eTradeShop&a] ", "The prefix the displays before all plugin messages", "\n"), @@ -100,12 +101,15 @@ public enum Setting { BITRADESHOP_HOPPER_EXPORT(SettingSectionKeys.BITRADE_SHOP_OPTIONS, "allow-hopper-export", false, "Can hoppers pull items from the shop storage (true/false)"); - private static TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop"); - private static File file = new File(plugin.getDataFolder(), "config.yml"); - private static FileConfiguration config = YamlConfiguration.loadConfiguration(file); - private String key, path, preComment = "", postComment = ""; - private Object defaultValue; - private SettingSectionKeys sectionKey; + private static final TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop"); + private static final File file = new File(plugin.getDataFolder(), "config.yml"); + private static FileConfiguration config = YamlConfiguration.loadConfiguration(file); + private final String key; + private final String path; + private final Object defaultValue; + private final SettingSectionKeys sectionKey; + private String preComment = ""; + private String postComment = ""; Setting(SettingSectionKeys sectionKey, String path, Object defaultValue) { this.sectionKey = sectionKey; @@ -209,17 +213,19 @@ public static void reload() { } if (!file.exists()) { file.createNewFile(); - } - } catch (IOException e) { - plugin.getLogger().log(Level.SEVERE, "Could not create Config file! Disabling plugin!", e); - plugin.getServer().getPluginManager().disablePlugin(plugin); - } + } + } catch (IOException e) { + plugin.getLogger().log(Level.SEVERE, "Could not create Config file! Disabling plugin!", e); + plugin.getServer().getPluginManager().disablePlugin(plugin); + } fixUp(); - setDefaults(); - config = YamlConfiguration.loadConfiguration(file); - } + setDefaults(); + config = YamlConfiguration.loadConfiguration(file); + + plugin.setUseInternalPerms(USE_INTERNAL_PERMISSIONS.getBoolean()); + } // Method to fix any values that have changed with updates private static void fixUp() { @@ -354,7 +360,9 @@ enum SettingSectionKeys { ITRADE_SHOP_OPTIONS("itrade-shop-options", "ITrade Shop Options"), BITRADE_SHOP_OPTIONS("bitrade-shop-options", "BiTrade Shop Options"); - private String key, sectionHeader, value_lead = ""; + private final String key; + private final String sectionHeader; + private String value_lead = ""; private SettingSectionKeys parent; SettingSectionKeys(String key, String sectionHeader) { diff --git a/src/main/java/org/shanerx/tradeshop/enumys/ShopType.java b/src/main/java/org/shanerx/tradeshop/enumys/ShopType.java index 70aefcb2..a7286048 100644 --- a/src/main/java/org/shanerx/tradeshop/enumys/ShopType.java +++ b/src/main/java/org/shanerx/tradeshop/enumys/ShopType.java @@ -44,9 +44,9 @@ public enum ShopType implements Serializable { BITRADE(Setting.BITRADESHOP_HEADER.getString(), Permissions.CREATEBI); - private transient static TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop"); - private String key; - private transient Permissions perm; + private final transient static TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop"); + private final String key; + private final transient Permissions perm; ShopType(String key, Permissions perm) { this.key = key; @@ -96,7 +96,7 @@ public String toHeader() { } public boolean checkPerm(Player pl) { - return pl.hasPermission(perm.getPerm()); + return Permissions.hasPermission(pl, perm); } public String serialize() { diff --git a/src/main/java/org/shanerx/tradeshop/listeners/JoinEventListener.java b/src/main/java/org/shanerx/tradeshop/listeners/JoinEventListener.java index ffb7c390..5770b0a7 100644 --- a/src/main/java/org/shanerx/tradeshop/listeners/JoinEventListener.java +++ b/src/main/java/org/shanerx/tradeshop/listeners/JoinEventListener.java @@ -40,7 +40,7 @@ public class JoinEventListener extends Utils implements Listener { - private TradeShop plugin; + private final TradeShop plugin; public JoinEventListener(TradeShop instance) { plugin = instance; @@ -53,7 +53,7 @@ public void onJoin(PlayerJoinEvent event) { PlayerSetting playerSetting = plugin.getDataStorage().loadPlayer(player.getUniqueId()); plugin.getDataStorage().savePlayer(playerSetting != null ? playerSetting : new PlayerSetting(player.getUniqueId())); - if (player.hasPermission(Permissions.ADMIN.getPerm())) { + if (Permissions.hasPermission(player, Permissions.ADMIN)) { BukkitVersion ver = new BukkitVersion(); if (plugin.getUpdater().compareVersions((short) ver.getMajor(), (short) ver.getMinor(), (short) ver.getPatch()).equals(Updater.RelationalStatus.BEHIND)) player.sendMessage(Message.PLUGIN_BEHIND.getPrefixed()); diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java index b1cb02fc..ce850de1 100644 --- a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java +++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java @@ -168,7 +168,7 @@ public void onBlockBreak(BlockBreakEvent event) { shop = Shop.loadShop((Sign) block.getState()); if (shop == null) return; - if (player.hasPermission(Permissions.ADMIN.getPerm()) || player.getUniqueId().equals(shop.getOwner().getUUID())) { + if (Permissions.hasPermission(player, Permissions.ADMIN) || player.getUniqueId().equals(shop.getOwner().getUUID())) { PlayerShopDestroyEvent destroyEvent = new PlayerShopDestroyEvent(player, shop); Bukkit.getPluginManager().callEvent(destroyEvent); if (destroyEvent.isCancelled()) { @@ -188,7 +188,7 @@ public void onBlockBreak(BlockBreakEvent event) { shop = new ShopChest(block.getLocation()).getShop(); if (shop == null) return; - if (player.hasPermission(Permissions.ADMIN.getPerm()) || player.getUniqueId().equals(shop.getOwner().getUUID())) { + if (Permissions.hasPermission(player, Permissions.ADMIN) || player.getUniqueId().equals(shop.getOwner().getUUID())) { PlayerShopDestroyEvent destroyEvent = new PlayerShopDestroyEvent(player, shop); Bukkit.getPluginManager().callEvent(destroyEvent); if (destroyEvent.isCancelled()) { @@ -232,7 +232,7 @@ public void onChestOpen(PlayerInteractEvent e) { Shop shop = new ShopChest(block.getLocation()).getShop(); PlayerShopInventoryOpenEvent openEvent = new PlayerShopInventoryOpenEvent(e.getPlayer(), shop, e.getAction(), e.getItem(), e.getClickedBlock(), e.getBlockFace()); - if (!e.getPlayer().hasPermission(Permissions.ADMIN.getPerm()) && !shop.getUsersUUID().contains(e.getPlayer().getUniqueId())) { + if (!Permissions.hasPermission(e.getPlayer(), Permissions.ADMIN) && !shop.getUsersUUID().contains(e.getPlayer().getUniqueId())) { openEvent.setCancelled(true); } diff --git a/src/main/java/org/shanerx/tradeshop/utils/Utils.java b/src/main/java/org/shanerx/tradeshop/utils/Utils.java index 975c079c..e33848cf 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/Utils.java +++ b/src/main/java/org/shanerx/tradeshop/utils/Utils.java @@ -491,6 +491,8 @@ public ArrayList getItems(Inventory inventory, List it if (item.getItemStack().getType().name().endsWith("SHULKER_BOX")) { for (ItemStack itm : clone.getStorageContents()) { if (itm != null && itm.getType().name().endsWith("SHULKER_BOX")) { + debugger.log("ShopTradeListener > Type of Item: " + itm.getType(), DebugLevels.TRADE); + debugger.log("ShopTradeListener > Amount of Item: " + itm.getAmount(), DebugLevels.TRADE); StringBuilder contents = new StringBuilder(); Arrays.stream(clone.getContents()).forEach(a -> contents.append(a != null ? a.getType().toString() : "Empty").append("|")); @@ -500,7 +502,11 @@ public ArrayList getItems(Inventory inventory, List it ret.add(itm); currentCount++; } + + debugger.log("ShopTradeListener > CurrentCount: " + currentCount, DebugLevels.TRADE); } + + if (currentCount >= totalCount) break; } } else { int count = item.getItemStack().getAmount() * multiplier, traded;