From 90ed038e4c71c38044f9cbe08ade96f956208c07 Mon Sep 17 00:00:00 2001 From: mfnalex <1122571+mfnalex@users.noreply.github.com> Date: Thu, 24 Jun 2021 15:53:58 +0200 Subject: [PATCH] 10.3.1 release --- CHANGELOG.md | 3 + pom.xml | 2 +- .../chestsort/commands/ChestSortCommand.java | 14 +- .../de/jeff_media/chestsort/enums/Hotkey.java | 6 +- .../jeff_media/chestsort/gui/SettingsGUI.java | 282 +++++++++--------- .../chestsort/listeners/Listener.java | 5 +- src/main/resources/config.yml | 13 +- src/main/resources/plugin.yml | 6 +- 8 files changed, 175 insertions(+), 156 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ae4060..c22a2ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 10.3.1 +- Fixed hotkeys not working since 10.3.0 + ## 10.3.0 - Added permissions for each hotkey. - Given to all players by default diff --git a/pom.xml b/pom.xml index d0b190d..1e24c81 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ ChestSort https://www.chestsort.de Allows automatic chest sorting! - 10.3.0 + 10.3.1 jar diff --git a/src/main/java/de/jeff_media/chestsort/commands/ChestSortCommand.java b/src/main/java/de/jeff_media/chestsort/commands/ChestSortCommand.java index aab4285..884aff3 100644 --- a/src/main/java/de/jeff_media/chestsort/commands/ChestSortCommand.java +++ b/src/main/java/de/jeff_media/chestsort/commands/ChestSortCommand.java @@ -15,9 +15,17 @@ import org.jetbrains.annotations.NotNull; public class ChestSortCommand implements CommandExecutor { private final ChestSortPlugin plugin; + final String noPermission; public ChestSortCommand(ChestSortPlugin plugin) { this.plugin = plugin; + noPermission = plugin.getCommand("sort").getPermissionMessage(); + } + + private void sendNoPermissionMessage(CommandSender sender) { + if(noPermission != null && noPermission.length()>0) { + sender.sendMessage(noPermission); + } } @Override @@ -29,14 +37,14 @@ public class ChestSortCommand implements CommandExecutor { } if(!plugin.getConfig().getBoolean("allow-commands") && !sender.isOp()) { - sender.sendMessage(command.getPermissionMessage()); + sendNoPermissionMessage(sender); return true; } // Reload command if(args.length>0 && args[0].equalsIgnoreCase("reload")) { if(!sender.hasPermission("chestsort.reload")) { - sender.sendMessage(plugin.getCommand("chestsort").getPermissionMessage()); + sendNoPermissionMessage(sender); return true; } sender.sendMessage(ChatColor.GRAY + "Reloading ChestSort..."); @@ -48,7 +56,7 @@ public class ChestSortCommand implements CommandExecutor { // Debug command if(args.length>0 && args[0].equalsIgnoreCase("debug")) { if(!sender.hasPermission("chestsort.debug")) { - sender.sendMessage(plugin.getCommand("chestsort").getPermissionMessage()); + sendNoPermissionMessage(sender); } sender.sendMessage(ChatColor.RED+"ChestSort Debug mode enabled - I hope you know what you are doing!"); plugin.setDebug(true); diff --git a/src/main/java/de/jeff_media/chestsort/enums/Hotkey.java b/src/main/java/de/jeff_media/chestsort/enums/Hotkey.java index 991400f..68d7401 100644 --- a/src/main/java/de/jeff_media/chestsort/enums/Hotkey.java +++ b/src/main/java/de/jeff_media/chestsort/enums/Hotkey.java @@ -6,9 +6,11 @@ public enum Hotkey { SHIFT_CLICK, MIDDLE_CLICK, DOUBLE_CLICK, SHIFT_RIGHT_CLICK, - LEFT_CLICK_OUTSIDE, RIGHT_CLICK_OUTSIDE; + OUTSIDE, LEFT_CLICK, RIGHT_CLICK; public static String getPermission(Hotkey hotkey) { - return hotkey.name().toLowerCase(Locale.ROOT).replace("_", ""); + String permission = "chestsort.hotkey." + hotkey.name().toLowerCase(Locale.ROOT).replace("_", ""); + //System.out.println("Permission for " + hotkey.name()+ ": " + permission); + return permission; } } diff --git a/src/main/java/de/jeff_media/chestsort/gui/SettingsGUI.java b/src/main/java/de/jeff_media/chestsort/gui/SettingsGUI.java index 9f1e051..ebed39f 100644 --- a/src/main/java/de/jeff_media/chestsort/gui/SettingsGUI.java +++ b/src/main/java/de/jeff_media/chestsort/gui/SettingsGUI.java @@ -3,6 +3,7 @@ package de.jeff_media.chestsort.gui; import de.jeff_media.chestsort.ChestSortPlugin; import de.jeff_media.chestsort.config.Messages; import de.jeff_media.chestsort.data.PlayerSetting; +import de.jeff_media.chestsort.enums.Hotkey; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -17,158 +18,157 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; public class SettingsGUI implements Listener { - - final ChestSortPlugin plugin; - - public static final int slotMiddleClick = 1; - public static final int slotShiftClick = 3 ; - public static final int slotDoubleClick = 5 ; - public static final int slotShiftRightClick = 7 ; - public static final int slotLeftClickFromOutside = 4 + 9; - public static final int slotLeftClick = 2+18; - public static final int slotRightClick = 6+18; - - final static Material red = Material.REDSTONE_BLOCK; - final static Material green = Material.EMERALD_BLOCK; - - enum Hotkey { - MiddleClick, ShiftClick, DoubleClick, ShiftRightClick, LeftClick, RightClick, LeftClickOutside - } - - public SettingsGUI(ChestSortPlugin plugin) { - this.plugin=plugin; - } - - ItemStack getItem(boolean active, Hotkey hotkey) { - ItemStack is; - String suffix; - - if(active) { - is = new ItemStack(green); - suffix = Messages.MSG_GUI_ENABLED; - } - else { - is = new ItemStack(red); - suffix = Messages.MSG_GUI_DISABLED; - } - - ItemMeta meta = is.getItemMeta(); - - switch(hotkey) { - case MiddleClick: - meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_MIDDLECLICK + ": " + suffix); - break; - case ShiftClick: - meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_SHIFTCLICK + ": " + suffix); - break; - case DoubleClick: - meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_DOUBLECLICK + ": " + suffix); - break; - case ShiftRightClick: - meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_SHIFTRIGHTCLICK + ": " + suffix); - break; - case LeftClickOutside: - meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_LEFTCLICKOUTSIDE + ": " + suffix); - break; - case LeftClick: - meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_LEFTCLICK + ": "+ suffix); - break; - case RightClick: - meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_RIGHTCLICK + ": "+ suffix); - break; - default: - break; - } - - is.setItemMeta(meta); - - return is; - } - + + public static final int slotMiddleClick = 1; + public static final int slotShiftClick = 3; + public static final int slotDoubleClick = 5; + public static final int slotShiftRightClick = 7; + public static final int slotLeftClickFromOutside = 4 + 9; + public static final int slotLeftClick = 2 + 18; + public static final int slotRightClick = 6 + 18; + final static Material red = Material.REDSTONE_BLOCK; + final static Material green = Material.EMERALD_BLOCK; + final ChestSortPlugin plugin; + + public SettingsGUI(ChestSortPlugin plugin) { + this.plugin = plugin; + } + + ItemStack getItem(boolean active, Hotkey hotkey, Player player) { + + //System.out.println("Getting Item for hotkey " + hotkey); + + ItemStack is; + String suffix; + + if(!player.hasPermission(Hotkey.getPermission(hotkey))) { + //System.out.println(" Player does NOT have permission " + hotkey.name()); + return null; + } + + if (active) { + is = new ItemStack(green); + suffix = Messages.MSG_GUI_ENABLED; + } else { + is = new ItemStack(red); + suffix = Messages.MSG_GUI_DISABLED; + } + + ItemMeta meta = is.getItemMeta(); + + switch (hotkey) { + case MIDDLE_CLICK: + meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_MIDDLECLICK + ": " + suffix); + break; + case SHIFT_CLICK: + meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_SHIFTCLICK + ": " + suffix); + break; + case DOUBLE_CLICK: + meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_DOUBLECLICK + ": " + suffix); + break; + case SHIFT_RIGHT_CLICK: + meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_SHIFTRIGHTCLICK + ": " + suffix); + break; + case OUTSIDE: + meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_LEFTCLICKOUTSIDE + ": " + suffix); + break; + case LEFT_CLICK: + meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_LEFTCLICK + ": " + suffix); + break; + case RIGHT_CLICK: + meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_RIGHTCLICK + ": " + suffix); + break; + default: + break; + } + + is.setItemMeta(meta); + + return is; + } + public void openGUI(Player player) { Inventory inventory = createGUI("ChestSort", player); - + PlayerSetting setting = plugin.getPerPlayerSettings().get(player.getUniqueId().toString()); - if(plugin.getConfig().getBoolean("allow-sorting-hotkeys")) { - inventory.setItem(slotMiddleClick, getItem(setting.middleClick, Hotkey.MiddleClick)); - inventory.setItem(slotShiftClick, getItem(setting.shiftClick, Hotkey.ShiftClick)); - inventory.setItem(slotDoubleClick, getItem(setting.doubleClick, Hotkey.DoubleClick)); - inventory.setItem(slotShiftRightClick, getItem(setting.shiftRightClick, Hotkey.ShiftRightClick)); - } - if(plugin.getConfig().getBoolean("allow-left-click-to-sort")) { - inventory.setItem(slotLeftClickFromOutside, getItem(setting.leftClickOutside, Hotkey.LeftClickOutside)); - } - if(plugin.getConfig().getBoolean("allow-additional-hotkeys")) { - inventory.setItem(slotLeftClick, getItem(setting.leftClick,Hotkey.LeftClick)); - inventory.setItem(slotRightClick, getItem(setting.rightClick,Hotkey.RightClick)); - } - + if (plugin.getConfig().getBoolean("allow-sorting-hotkeys")) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.MIDDLE_CLICK))) inventory.setItem(slotMiddleClick, getItem(setting.middleClick, Hotkey.MIDDLE_CLICK, player)); + if(player.hasPermission(Hotkey.getPermission(Hotkey.SHIFT_CLICK))) inventory.setItem(slotShiftClick, getItem(setting.shiftClick, Hotkey.SHIFT_CLICK, player)); + if(player.hasPermission(Hotkey.getPermission(Hotkey.DOUBLE_CLICK))) inventory.setItem(slotDoubleClick, getItem(setting.doubleClick, Hotkey.DOUBLE_CLICK, player)); + if(player.hasPermission(Hotkey.getPermission(Hotkey.SHIFT_RIGHT_CLICK))) inventory.setItem(slotShiftRightClick, getItem(setting.shiftRightClick, Hotkey.SHIFT_RIGHT_CLICK, player)); + } + if (plugin.getConfig().getBoolean("allow-left-click-to-sort")) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.OUTSIDE))) inventory.setItem(slotLeftClickFromOutside, getItem(setting.leftClickOutside, Hotkey.OUTSIDE, player)); + } + if (plugin.getConfig().getBoolean("allow-additional-hotkeys")) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.LEFT_CLICK))) inventory.setItem(slotLeftClick, getItem(setting.leftClick, Hotkey.LEFT_CLICK, player)); + if(player.hasPermission(Hotkey.getPermission(Hotkey.RIGHT_CLICK))) inventory.setItem(slotRightClick, getItem(setting.rightClick, Hotkey.RIGHT_CLICK, player)); + } + setting.guiInventory = inventory; player.openInventory(inventory); } - + Inventory createGUI(String name, Player inventoryHolder) { - return Bukkit.createInventory(inventoryHolder, InventoryType.CHEST, name); + return Bukkit.createInventory(inventoryHolder, InventoryType.CHEST, name); } - + @EventHandler - void onGUIInteract(InventoryClickEvent event) { - if(!plugin.isHotkeyGUI()) { - return; - } - if(!(event.getWhoClicked() instanceof Player)) { - return; - } - Player p = (Player) event.getWhoClicked(); - plugin.registerPlayerIfNeeded(p); - PlayerSetting setting = plugin.getPerPlayerSettings().get(p.getUniqueId().toString()); - - if(setting.guiInventory==null) { - return; - } - - if(event.getClickedInventory()==null) { - return; - } - if(!event.getClickedInventory().equals(setting.guiInventory)) { - return; - } - - // We only get this far if the player has clicked inside his GUI inventory - event.setCancelled(true); - if(event.getClick() != ClickType.LEFT) { - return; - } + void onGUIInteract(InventoryClickEvent event) { + if (!plugin.isHotkeyGUI()) { + return; + } + if (!(event.getWhoClicked() instanceof Player)) { + return; + } + Player player = (Player) event.getWhoClicked(); + plugin.registerPlayerIfNeeded(player); + PlayerSetting setting = plugin.getPerPlayerSettings().get(player.getUniqueId().toString()); - if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR) { - return; - } + if (setting.guiInventory == null) { + return; + } + if (event.getClickedInventory() == null) { + return; + } + if (!event.getClickedInventory().equals(setting.guiInventory)) { + return; + } - if(event.getSlot() == SettingsGUI.slotMiddleClick) { - setting.toggleMiddleClick(); - plugin.getSettingsGUI().openGUI(p); - } - else if(event.getSlot() == SettingsGUI.slotShiftClick) { - setting.toggleShiftClick(); - plugin.getSettingsGUI().openGUI(p); - } else if(event.getSlot() == SettingsGUI.slotDoubleClick) { - setting.toggleDoubleClick(); - plugin.getSettingsGUI().openGUI(p); - } else if(event.getSlot() == SettingsGUI.slotLeftClickFromOutside) { - setting.toggleLeftClickOutside(); - plugin.getSettingsGUI().openGUI(p); - } else if(event.getSlot() == SettingsGUI.slotShiftRightClick) { - setting.toggleShiftRightClick(); - plugin.getSettingsGUI().openGUI(p); - } else if(event.getSlot() == SettingsGUI.slotLeftClick) { - setting.toggleLeftClick(); - plugin.getSettingsGUI().openGUI(p); - } else if(event.getSlot() == SettingsGUI.slotRightClick) { - setting.toggleRightClick(); - plugin.getSettingsGUI().openGUI(p); - } - - } + // We only get this far if the player has clicked inside his GUI inventory + event.setCancelled(true); + if (event.getClick() != ClickType.LEFT) { + return; + } + + if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR) { + return; + } + + if (event.getSlot() == SettingsGUI.slotMiddleClick) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.MIDDLE_CLICK))) setting.toggleMiddleClick(); + plugin.getSettingsGUI().openGUI(player); + } else if (event.getSlot() == SettingsGUI.slotShiftClick) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.SHIFT_CLICK))) setting.toggleShiftClick(); + plugin.getSettingsGUI().openGUI(player); + } else if (event.getSlot() == SettingsGUI.slotDoubleClick) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.DOUBLE_CLICK))) setting.toggleDoubleClick(); + plugin.getSettingsGUI().openGUI(player); + } else if (event.getSlot() == SettingsGUI.slotLeftClickFromOutside) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.OUTSIDE))) setting.toggleLeftClickOutside(); + plugin.getSettingsGUI().openGUI(player); + } else if (event.getSlot() == SettingsGUI.slotShiftRightClick) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.SHIFT_RIGHT_CLICK))) setting.toggleShiftRightClick(); + plugin.getSettingsGUI().openGUI(player); + } else if (event.getSlot() == SettingsGUI.slotLeftClick) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.LEFT_CLICK))) setting.toggleLeftClick(); + plugin.getSettingsGUI().openGUI(player); + } else if (event.getSlot() == SettingsGUI.slotRightClick) { + if(player.hasPermission(Hotkey.getPermission(Hotkey.RIGHT_CLICK))) setting.toggleRightClick(); + plugin.getSettingsGUI().openGUI(player); + } + + } } diff --git a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java b/src/main/java/de/jeff_media/chestsort/listeners/Listener.java index c05161b..e6b9563 100644 --- a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java +++ b/src/main/java/de/jeff_media/chestsort/listeners/Listener.java @@ -54,6 +54,7 @@ public class Listener implements org.bukkit.event.Listener { @EventHandler public void onLeftClickChest(PlayerInteractEvent event) { if(!event.getPlayer().hasPermission("chestsort.use")) return; + if(!event.getPlayer().hasPermission(Hotkey.getPermission(Hotkey.OUTSIDE))) return; if(event.getHand() != EquipmentSlot.HAND) return; if(event.getAction() != Action.LEFT_CLICK_BLOCK) return; if(!plugin.getConfig().getBoolean("allow-left-click-to-sort")) return; @@ -649,7 +650,7 @@ public class Listener implements org.bukkit.event.Listener { return; } - if (e.isLeftClick() && setting.leftClick && p.hasPermission(Hotkey.getPermission(Hotkey.LEFT_CLICK_OUTSIDE))) { + if (e.isLeftClick() && setting.leftClick && p.hasPermission(Hotkey.getPermission(Hotkey.LEFT_CLICK))) { plugin.getLgr().logSort(p, Logger.SortCause.H_LEFT); if (setting.getCurrentDoubleClick(plugin, PlayerSetting.DoubleClickType.LEFT_CLICK) == PlayerSetting.DoubleClickType.LEFT_CLICK) { @@ -661,7 +662,7 @@ public class Listener implements org.bukkit.event.Listener { plugin.getOrganizer().stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), true, chestSortEvent); } - } else if (e.isRightClick() && setting.rightClick && p.hasPermission(Hotkey.getPermission(Hotkey.RIGHT_CLICK_OUTSIDE))) { + } else if (e.isRightClick() && setting.rightClick && p.hasPermission(Hotkey.getPermission(Hotkey.RIGHT_CLICK))) { plugin.getLgr().logSort(p, Logger.SortCause.H_RIGHT); if (setting.getCurrentDoubleClick(plugin, PlayerSetting.DoubleClickType.RIGHT_CLICK) == PlayerSetting.DoubleClickType.RIGHT_CLICK) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f9cbfb9..c152424 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -39,7 +39,7 @@ # chestsort.hotkey. Allows to use a specific hotkey. Given to all players by default. Players still need # to have the chestsort.use permission. # Available hotkeys are: shiftclick, middleclick, doubleclick, shiftrightclick, -# leftclickoutside, rightclickoutside +# leftclick, rightlick, outside ############################### @@ -151,13 +151,13 @@ allow-sorting-hotkeys: true # /chestsort hotkeys # sorting-hotkeys: - # Use middle click (mousewheel) on ANY inventory slot as hotkey + # Use middle click (mousewheel) on ANY inventory slot as hotkey. Permission: chestsort.hotkey.middleclick middle-click: true - # Use shift + left-click on any EMPTY inventory slot as hotkey + # Use shift + left-click on any EMPTY inventory slot as hotkey. Permission: chestsort.hotkey.shiftclick shift-click: true - # Use double left-click on any EMPTY inventory slot as hotkey + # Use double left-click on any EMPTY inventory slot as hotkey. Permission: chestsort.hotkey.doubleclick double-click: true - # Use shift + right-click on any EMPTY inventory slot as hotkey + # Use shift + right-click on any EMPTY inventory slot as hotkey. Permission: chestsort.hotkey.shiftrightclick shift-right-click: true # Amount in seconds that players have to wait between using hotkeys to prevent them from spamming the @@ -166,6 +166,7 @@ hotkey-cooldown: 0.2 # When enabled, players can leftclick on chests, barrels etc. # to sort them without having to open them. +# Permission: chestsort.hotkey.outside allow-left-click-to-sort: true # When set to true, sorting a chest by left-clicking it is enabled by default @@ -182,9 +183,11 @@ allow-additional-hotkeys: true additional-hotkeys: # Use left-click outside inventory to quickly put matching items from your inventory (except hotbar) # into the chest. Use left-double-click to put everything except your hotbar into the chest. + # Permission: chestsort.hotkey.leftclick left-click: false # Use right-click outside inventory to quickly take all matching items from the chest into your # inventory. Use right-double-click to take all items out of the chest. + # Permission: chestsort.hotkey.leftclick right-click: false ########################## diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9ae2024..3d7a9ad 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -55,7 +55,9 @@ permissions: default: true chestsort.hotkey.shiftrightclick: default: true - chestsort.hotkey.leftclickoutside: + chestsort.hotkey.leftclick: default: true - chestsort.hotkey.rightclickoutside: + chestsort.hotkey.rightclick: + default: true + chestsort.hotkey.outside: default: true \ No newline at end of file