From 86b51df4128c41c3ecccd82394ff6b59d3ce4e46 Mon Sep 17 00:00:00 2001 From: BONNe Date: Mon, 28 Jan 2019 20:21:48 +0200 Subject: [PATCH 1/5] Update to BentoBox 1.2.0 In BentoBox 1.2 hooks are enabled before addons. --- .../bentobox/challenges/ChallengesAddon.java | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index 6f4cc94..f4089c6 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -40,9 +40,8 @@ public class ChallengesAddon extends Addon { /** * VaultHook that process economy. - * todo: because of BentoBox limitations. */ - private Optional vaultHook = null; + private VaultHook vaultHook; /** * Level addon. @@ -132,19 +131,18 @@ public class ChallengesAddon extends Addon { this.levelAddon = (Level) level.get(); } - // BentoBox limitation. Cannot check hooks, as HookManager is created after loading addons. -// Optional vault = this.getPlugin().getVault(); -// -// if (!vault.isPresent() || !vault.get().hook()) -// { -// this.vaultHook = null; -// this.logWarning("Economy plugin not found so money options will not work!"); -// } -// else -// { -// this.economyProvided = true; -// this.vaultHook = vault.get(); -// } + Optional vault = this.getPlugin().getVault(); + + if (!vault.isPresent() || !vault.get().hook()) + { + this.vaultHook = null; + this.logWarning("Economy plugin not found so money options will not work!"); + } + else + { + this.economyProvided = true; + this.vaultHook = vault.get(); + } // Register the reset listener this.registerListener(new ResetListener(this)); @@ -247,12 +245,6 @@ public class ChallengesAddon extends Addon { */ public boolean isEconomyProvided() { - if (!this.economyProvided && this.getPlugin().getVault().isPresent() && this.vaultHook == null) - { - this.vaultHook = this.getPlugin().getVault(); - this.economyProvided = this.vaultHook.get().hook(); - } - return this.economyProvided; } @@ -264,7 +256,7 @@ public class ChallengesAddon extends Addon { */ public VaultHook getEconomyProvider() { - return vaultHook.orElseGet(null); + return vaultHook; } From 7384afa262d8aac4302eb1dd728f58a2a37f8945 Mon Sep 17 00:00:00 2001 From: BONNe Date: Mon, 28 Jan 2019 20:25:28 +0200 Subject: [PATCH 2/5] Disable broadcast message for user. #62 --- .../challenges/panel/TryToComplete.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 3e32318..b25af2e 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -210,10 +210,14 @@ public class TryToComplete if (this.addon.getChallengesSettings().isBroadcastMessages()) { - for (Player p : this.addon.getServer().getOnlinePlayers()) + for (Player player : this.addon.getServer().getOnlinePlayers()) { - User.getInstance(p).sendMessage("challenges.name-has-completed", - "[name]", this.user.getName(), "[challenge]", this.challenge.getFriendlyName()); + // Only other players should see message. + if (!player.getUniqueId().equals(this.user.getUniqueId())) + { + User.getInstance(player).sendMessage("challenges.name-has-completed", + "[name]", this.user.getName(), "[challenge]", this.challenge.getFriendlyName()); + } } } } @@ -275,10 +279,14 @@ public class TryToComplete if (this.addon.getChallengesSettings().isBroadcastMessages()) { - for (Player p : this.addon.getServer().getOnlinePlayers()) + for (Player player : this.addon.getServer().getOnlinePlayers()) { - User.getInstance(p).sendMessage("challenges.name-has-completed-level", - "[name]", this.user.getName(), "[level]", level.getFriendlyName()); + // Only other players should see message. + if (!player.getUniqueId().equals(this.user.getUniqueId())) + { + User.getInstance(player).sendMessage("challenges.name-has-completed-level", + "[name]", this.user.getName(), "[level]", level.getFriendlyName()); + } } } From 99187525894e076b90009e0302980fa7484e7135 Mon Sep 17 00:00:00 2001 From: BONNe Date: Mon, 28 Jan 2019 21:01:26 +0200 Subject: [PATCH 3/5] Fix issue when completing challenge was not displayed in ChallengesGUI. (#60) --- .../challenges/panel/ChallengesPanels2.java | 2 +- .../challenges/panel/TryToComplete.java | 22 ++++++++++++++++++- .../challenges/panel/user/ChallengesGUI.java | 8 +++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java index 2006f46..3c51fd8 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java @@ -152,7 +152,7 @@ public class ChallengesPanels2 { } else { // Player click itemBuilder.clickHandler((panel, player, c, s) -> { - new TryToComplete(addon, player, challenge, world, label, permPrefix); + new TryToComplete(addon, player, challenge, world, label, permPrefix).build(); return true; }); } diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index b25af2e..ceffdba 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -161,8 +161,28 @@ public class TryToComplete this.manager = addon.getChallengesManager(); this.challenge = challenge; this.topLabel = topLabel; + } - this.build(); + + /** + * This static method allows complete challenge and get result about completion. + * @param addon - Challenges Addon. + * @param user - User who performs challenge. + * @param challenge - Challenge that should be completed. + * @param world - World where completion may occur. + * @param topLabel - Label of the top command. + * @param permissionPrefix - Permission prefix for GameMode addon. + * @return true, if challenge is completed, otherwise false. + */ + public static boolean complete(ChallengesAddon addon, + User user, + Challenge challenge, + World world, + String topLabel, + String permissionPrefix) + { + return new TryToComplete(addon, user, challenge, world, topLabel, permissionPrefix). + build().meetsRequirements; } diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index ca88b0f..2cd9aeb 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -325,12 +325,16 @@ public class ChallengesGUI extends CommonGUI name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()). description(GuiUtils.stringSplit(this.createChallengeDescription(challenge))). clickHandler((panel, user1, clickType, slot) -> { - new TryToComplete(this.addon, + if (TryToComplete.complete(this.addon, this.user, challenge, this.world, this.topLabel, - this.permissionPrefix); + this.permissionPrefix)) + { + this.build(); + } + return true; }). glow(this.challengesManager.isChallengeComplete(this.user, challenge)). From 21c57048649a5342dde37b1071b53cd9c7df1332 Mon Sep 17 00:00:00 2001 From: BONNe Date: Mon, 28 Jan 2019 21:32:57 +0200 Subject: [PATCH 4/5] Fix issue when inventory displays message about island challenge and via-versa. --- src/main/resources/locales/en-US.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 261809b..cf257d0 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -148,8 +148,8 @@ challenges: free-challenges: This indicate if free challenges must be at the start (true) or at the end (false) of list. glow: Add enchanted glow to completed challenges in_world: In World - inventory: This type of challenges allows to define blocks and entities on island requirements. - island: This type of challenges allows to define inventory item requirements. + inventory: This type of challenges allows to define inventory item requirements. + island: This type of challenges allows to define blocks and entities on island requirements. nether: Nether normal: Normal online: Online From f1f9072dc092e69a74242823350e902883d877aa Mon Sep 17 00:00:00 2001 From: BONNe Date: Mon, 28 Jan 2019 23:45:05 +0200 Subject: [PATCH 5/5] Add GuiButton that allows to switch MobHeads vs MobEggs... --- .../panel/admin/ManageEntitiesGUI.java | 16 +++++++++++++--- src/main/resources/locales/en-US.yml | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java index d2b4d71..d244984 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java @@ -5,7 +5,6 @@ import org.apache.commons.lang.WordUtils; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.EntityType; -import org.bukkit.inventory.ItemStack; import java.util.*; import world.bentobox.bentobox.api.panels.PanelItem; @@ -61,6 +60,7 @@ public class ManageEntitiesGUI extends CommonGUI panelBuilder.item(3, this.createButton(Button.ADD)); panelBuilder.item(5, this.createButton(Button.REMOVE)); + panelBuilder.item(8, this.createButton(Button.SWITCH)); final int MAX_ELEMENTS = 21; @@ -119,7 +119,7 @@ public class ManageEntitiesGUI extends CommonGUI builder.name(this.user.getTranslation("challenges.gui.button.add")); builder.icon(Material.BUCKET); builder.clickHandler((panel, user1, clickType, slot) -> { - new SelectEntityGUI(this.user, (status, entity) -> { + new SelectEntityGUI(this.user, Collections.emptySet(), this.asEggs, (status, entity) -> { if (status) { if (!this.requiredEntities.containsKey(entity)) @@ -144,6 +144,15 @@ public class ManageEntitiesGUI extends CommonGUI return true; }); break; + case SWITCH: + builder.name(this.user.getTranslation("challenges.gui.button.show-eggs")); + builder.icon(this.asEggs ? Material.EGG : Material.PLAYER_HEAD); + builder.clickHandler((panel, user1, clickType, slot) -> { + this.asEggs = !this.asEggs; + this.build(); + return true; + }); + break; } return builder.build(); @@ -204,7 +213,8 @@ public class ManageEntitiesGUI extends CommonGUI private enum Button { ADD, - REMOVE + REMOVE, + SWITCH } diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index cf257d0..245f3c2 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -177,6 +177,7 @@ challenges: button: add: Add remove-selected: Remove Selected + show-eggs: Toogle Mob View buttons: back: Return next: Next