From 63dd2d95b2e7534e03665b488ab54f076da0090f Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Mon, 11 Jun 2018 12:19:14 +0200 Subject: [PATCH 1/2] Added option to close panel on click outside of it This is related to commit #8d596c5f1d24ea2e319e5172b2c954a8caa46f67 --- src/main/java/us/tastybento/bskyblock/Settings.java | 11 +++++++++++ .../bskyblock/listeners/PanelListenerManager.java | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/Settings.java b/src/main/java/us/tastybento/bskyblock/Settings.java index 7ee5ee9f2..b7195df94 100644 --- a/src/main/java/us/tastybento/bskyblock/Settings.java +++ b/src/main/java/us/tastybento/bskyblock/Settings.java @@ -412,6 +412,9 @@ public class Settings implements DataObject, WorldSettings { @ConfigEntry(path = "island.require-confirmation.leave-wait") private long leaveWait = 10L; + @ConfigEntry(path = "panel.close-on-click-outside") + private boolean closePanelOnClickOutside = true; + private String uniqueId = "config"; // Getters and setters @@ -1482,4 +1485,12 @@ public class Settings implements DataObject, WorldSettings { this.worldFlags = worldFlags; } + public boolean getClosePanelOnClickOutside() { + return closePanelOnClickOutside; + } + + public void setClosePanelOnClickOutside(boolean closePanelOnClickOutside) { + this.closePanelOnClickOutside = closePanelOnClickOutside; + } + } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java b/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java index eb8f485cc..d88df3f3b 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java @@ -13,6 +13,7 @@ import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; +import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.panels.Panel; import us.tastybento.bskyblock.api.panels.PanelItem; import us.tastybento.bskyblock.api.user.User; @@ -23,13 +24,12 @@ public class PanelListenerManager implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onInventoryClick(InventoryClickEvent event) { - // Close inventory if clicked outside - if (event.getSlotType().equals(SlotType.OUTSIDE)) { + // Close inventory if clicked outside and if setting is true + if (BSkyBlock.getInstance().getSettings().getClosePanelOnClickOutside() && event.getSlotType().equals(SlotType.OUTSIDE)) { event.getWhoClicked().closeInventory(); return; } - User user = User.getInstance(event.getWhoClicked()); // The player that - // clicked the item + User user = User.getInstance(event.getWhoClicked()); // The player that clicked the item Inventory inventory = event.getInventory(); // The inventory that was // Open the inventory panel that this player has open (they can only ever have one) if (openPanels.containsKey(user.getUniqueId())) { From d2697e15254056af45d16eb354596ac40bdbdfc0 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Mon, 11 Jun 2018 15:55:01 +0200 Subject: [PATCH 2/2] Added a description variable to the "Island protected" message Added "[description]" in TextVariables added getName- and getDescriptionReference() in Flag --- locales/en-US.yml | 2 +- .../tastybento/bskyblock/api/flags/Flag.java | 24 +++++++++++-------- .../api/localization/TextVariables.java | 1 + .../listeners/flags/AbstractFlagListener.java | 15 +++++++----- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index 11a454f70..0eb91fbc2 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -455,7 +455,7 @@ protection: description: "Toggle access" name: "Trap doors" locked: "&cThis island is locked!" - protected: "&cIsland protected!" + protected: "&cIsland protected: [description]" panel: title: "Island flags" diff --git a/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java b/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java index a000d179b..f52b2a354 100644 --- a/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java +++ b/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java @@ -25,10 +25,6 @@ public class Flag implements Comparable { WORLD_SETTING } - private static final String PRO_FLAGS = "protection.flags."; - private static final String DOT_DESC = ".description"; - private static final String DESC_PLACEHOLDER = "[description]"; - private final String id; private final Material icon; private final Listener listener; @@ -141,6 +137,14 @@ public class Flag implements Comparable { return type == other.type; } + public String getNameReference() { + return "protection.flags." + this.id + ".name"; + } + + public String getDescriptionReference() { + return "protection.flags." + this.id + ".description"; + } + /** * Converts a flag to a panel item. The content of the flag will change depending on who the user is and where they are. * @param plugin - plugin @@ -151,17 +155,17 @@ public class Flag implements Comparable { // Start the flag conversion PanelItemBuilder pib = new PanelItemBuilder() .icon(new ItemStack(icon)) - .name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME, user.getTranslation(PRO_FLAGS + id + ".name"))) + .name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME, user.getTranslation(getNameReference()))) .clickHandler(clickHandler); if (getType().equals(Type.MENU)) { - pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", DESC_PLACEHOLDER, user.getTranslation(PRO_FLAGS + id + DOT_DESC))); + pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference()))); return pib.build(); } // Check if this is a setting or world setting if (getType().equals(Type.WORLD_SETTING)) { String worldDetting = this.isSetForWorld(user.getWorld()) ? user.getTranslation("protection.panel.flag-item.setting-active") : user.getTranslation("protection.panel.flag-item.setting-disabled"); - pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", DESC_PLACEHOLDER, user.getTranslation(PRO_FLAGS + id + DOT_DESC) + pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference()) , "[setting]", worldDetting)); return pib.build(); } @@ -172,7 +176,7 @@ public class Flag implements Comparable { if (getType().equals(Type.SETTING)) { String islandSetting = island.isAllowed(this) ? user.getTranslation("protection.panel.flag-item.setting-active") : user.getTranslation("protection.panel.flag-item.setting-disabled"); - pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", DESC_PLACEHOLDER, user.getTranslation(PRO_FLAGS + id + DOT_DESC) + pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference()) , "[setting]", islandSetting)); return pib.build(); } @@ -180,8 +184,8 @@ public class Flag implements Comparable { // Dynamic rank list if (getType().equals(Type.PROTECTION)) { // Protection flag - String d = user.getTranslation(PRO_FLAGS + id + DOT_DESC); - d = user.getTranslation("protection.panel.flag-item.description-layout", DESC_PLACEHOLDER, d); + String d = user.getTranslation(getDescriptionReference()); + d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, d); pib.description(d); plugin.getRanksManager().getRanks().forEach((reference, score) -> { if (score > RanksManager.BANNED_RANK && score < island.getFlag(this)) { diff --git a/src/main/java/us/tastybento/bskyblock/api/localization/TextVariables.java b/src/main/java/us/tastybento/bskyblock/api/localization/TextVariables.java index a96939c5d..d915e09e3 100644 --- a/src/main/java/us/tastybento/bskyblock/api/localization/TextVariables.java +++ b/src/main/java/us/tastybento/bskyblock/api/localization/TextVariables.java @@ -7,6 +7,7 @@ package us.tastybento.bskyblock.api.localization; public class TextVariables { public static final String NAME = "[name]"; + public static final String DESCRIPTION = "[description]"; public static final String NUMBER = "[number]"; public static final String RANK = "[rank]"; public static final String LABEL = "[label]"; diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/AbstractFlagListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/AbstractFlagListener.java index 4acbbb687..245b976f3 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/AbstractFlagListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/AbstractFlagListener.java @@ -12,6 +12,7 @@ import org.bukkit.event.Listener; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.flags.Flag; import us.tastybento.bskyblock.api.flags.Flag.Type; +import us.tastybento.bskyblock.api.localization.TextVariables; import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.managers.IslandWorldManager; @@ -79,23 +80,25 @@ public abstract class AbstractFlagListener implements Listener { /** * Cancels the event and sends the island public message to user * @param e - event + * @param flag - the flag that has been checked */ - public void noGo(Event e) { - noGo(e, false); + public void noGo(Event e, Flag flag) { + noGo(e, flag,false); } /** * Cancels the event and sends the island protected message to user unless silent is true * @param e - event + * @param flag - the flag that has been checked * @param silent - if true, message is not sent */ - public void noGo(Event e, boolean silent) { + public void noGo(Event e, Flag flag, boolean silent) { if (e instanceof Cancellable) { ((Cancellable)e).setCancelled(true); } if (user != null) { if (!silent) { - user.notify("protection.protected"); + user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(flag.getDescriptionReference())); } user.updateInventory(); } @@ -148,7 +151,7 @@ public abstract class AbstractFlagListener implements Listener { if (island.isPresent()) { if (!island.get().isAllowed(user, flag)) { - noGo(e, silent); + noGo(e, flag, silent); // Clear the user for the next time user = null; return false; @@ -159,7 +162,7 @@ public abstract class AbstractFlagListener implements Listener { } // The player is in the world, but not on an island, so general world settings apply if (!flag.isSetForWorld(loc.getWorld())) { - noGo(e, silent); + noGo(e, flag, silent); user = null; return false; } else {