From 2eee3b5fb45cf82ce50956804e16ce9d6085bb5b Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Thu, 7 May 2020 23:34:18 +0200 Subject: [PATCH] Add option to prevent backpack from being moved --- Minepacks/resources/config.yml | 4 +++- .../pcgamingfreaks/Minepacks/Bukkit/Database/Config.java | 7 ++++++- .../Minepacks/Bukkit/Listener/ItemShortcut.java | 4 +++- pom.xml | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Minepacks/resources/config.yml b/Minepacks/resources/config.yml index 07a3b63..dc3b3c2 100644 --- a/Minepacks/resources/config.yml +++ b/Minepacks/resources/config.yml @@ -180,6 +180,8 @@ ItemShortcut: OpenContainerOnRightClick: false # The id of the slot that should be preferred when giving a player the shortcut item PreferredSlotId: -1 + # If this option is enabled the player will not be able to move the backpack item within their inventory + BlockItemFromMoving: false Sound: # Enables all sound effects @@ -208,4 +210,4 @@ Misc: UseBungeeCord: false # Config file version. Don't touch it! -Version: 29 \ No newline at end of file +Version: 30 \ No newline at end of file diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java index eff9cd6..0eeee53 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java @@ -38,7 +38,7 @@ public class Config extends Configuration implements DatabaseConnectionConfiguration { - private static final int CONFIG_VERSION = 29, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20; + private static final int CONFIG_VERSION = 30, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20; public Config(JavaPlugin plugin) { @@ -420,6 +420,11 @@ public int getItemShortcutPreferredSlotId() { return getConfigE().getInt("ItemShortcut.PreferredSlotId", -1); } + + public boolean getItemShortcutBlockItemFromMoving() + { + return getConfigE().getBoolean("ItemShortcut.BlockItemFromMoving", false); + } //endregion //region Sound settings diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java index ab24224..0b65d2a 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java @@ -52,7 +52,7 @@ public class ItemShortcut implements Listener private final Minepacks plugin; private final String itemName, value, openCommand; private final Message messageDoNotRemoveItem; - private final boolean improveDeathChestCompatibility, blockAsHat, allowRightClickOnContainers; + private final boolean improveDeathChestCompatibility, blockAsHat, allowRightClickOnContainers, blockItemFromMoving; private final int preferredSlotId; private final Set containerMaterials = new HashSet<>(); @@ -65,6 +65,7 @@ public ItemShortcut(Minepacks plugin) blockAsHat = plugin.getConfiguration().isItemShortcutBlockAsHatEnabled(); allowRightClickOnContainers = plugin.getConfiguration().isItemShortcutRightClickOnContainerAllowed(); preferredSlotId = plugin.getConfiguration().getItemShortcutPreferredSlotId(); + blockItemFromMoving = plugin.getConfiguration().getItemShortcutBlockItemFromMoving(); openCommand = plugin.getLanguage().getCommandAliases("Backpack", "backpack")[0] + ' ' + plugin.getLanguage().getCommandAliases("Open", "open")[0]; messageDoNotRemoveItem = plugin.getLanguage().getMessage("Ingame.DontRemoveShortcut"); @@ -247,6 +248,7 @@ else if(event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) event.setCancelled(true); messageDoNotRemoveItem.send(player); } + if(blockItemFromMoving) event.setCancelled(true); } else if((event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD || event.getAction() == InventoryAction.HOTBAR_SWAP) && event.getHotbarButton() != -1) { diff --git a/pom.xml b/pom.xml index b3b8ac1..b6a0bf2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ pom - 2.3.7 + 2.3.8-RC1 UTF-8 UTF-8