From 4232a5675f58c57f63a4cad6c9d3610715486810 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 9 Nov 2015 08:45:34 +0000 Subject: [PATCH] fixed bug with part 5 of the getting started tutorial (has to do with claiming events) --- .../mineplex/game/clans/clans/ClansAdmin.java | 2 +- .../clans/clans/commands/ClansCommand.java | 36 ++++++++++++++++--- .../event/ClansCommandExecutedEvent.java | 12 +++++++ .../types/TutorialGettingStarted.java | 24 +++++-------- 4 files changed, 53 insertions(+), 21 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansAdmin.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansAdmin.java index f44971efb..7d6418651 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansAdmin.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansAdmin.java @@ -615,7 +615,7 @@ public class ClansAdmin clientClan.inform(caller.getName() + " claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".", caller.getName()); } - public void unclaim(Player caller, String args[]) + public void unclaim(Player caller, String[] args) { if (args.length > 2) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index 877d69dda..43e947bea 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -168,7 +168,13 @@ public class ClansCommand extends CommandBase private void help(Player caller) { - UtilServer.getServer().getPluginManager().callEvent(new ClansCommandExecutedEvent(caller, "help", null)); + ClansCommandExecutedEvent event = new ClansCommandExecutedEvent(caller, "help"); + UtilServer.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) + { + return; + } UtilPlayer.message(caller, F.main("Clans", "Commands List;")); UtilPlayer.message(caller, F.help("/c create ", "Create new Clan", Rank.ALL)); @@ -825,10 +831,18 @@ public class ClansCommand extends CommandBase } } - public void claim(Player caller, String args[]) + public void claim(Player caller, String[] args) { ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller); + ClansCommandExecutedEvent event = new ClansCommandExecutedEvent(caller, "claim", args); + UtilServer.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) + { + return; + } + if (clan == null) { UtilPlayer.message(caller, F.main("Clans", "You are not in a Clan.")); @@ -952,7 +966,13 @@ public class ClansCommand extends CommandBase if (!Recharge.Instance.use(caller, "Territory Claim", 60000, true, false)) return; // Event - PlayerClaimTerritoryEvent event = new PlayerClaimTerritoryEvent(caller, caller.getLocation().getChunk()); + PlayerClaimTerritoryEvent claimEvent = new PlayerClaimTerritoryEvent(caller, caller.getLocation().getChunk()); + UtilServer.getServer().getPluginManager().callEvent(claimEvent); + + if (claimEvent.isCancelled()) + { + return; + } // Task Plugin.getClanDataAccess().claim(clan.getName(), chunk, caller.getName(), false); @@ -982,7 +1002,7 @@ public class ClansCommand extends CommandBase return (boxed >= req); } - public void unclaim(Player caller, String args[]) + public void unclaim(Player caller, String[] args) { if (args.length > 1) { @@ -1189,7 +1209,13 @@ public class ClansCommand extends CommandBase return; } - UtilServer.getServer().getPluginManager().callEvent(new ClansCommandExecutedEvent(caller, "info", search)); + ClansCommandExecutedEvent event = new ClansCommandExecutedEvent(caller, "info", search); + UtilServer.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) + { + return; + } ClanInfo clan = Plugin.getClanUtility().searchClanPlayer(caller, search, true); if (clan == null) return; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansCommandExecutedEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansCommandExecutedEvent.java index 0697007fd..277df4f91 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansCommandExecutedEvent.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansCommandExecutedEvent.java @@ -12,6 +12,8 @@ public class ClansCommandExecutedEvent extends Event private String _command; private String[] _args; + private boolean _cancelled; + public ClansCommandExecutedEvent(Player player, String command, String... args) { _player = player; @@ -47,6 +49,11 @@ public class ClansCommandExecutedEvent extends Event return _command; } + public boolean isCancelled() + { + return _cancelled; + } + public String[] getArguments() { return _args; @@ -61,4 +68,9 @@ public class ClansCommandExecutedEvent extends Event { return handlers; } + + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java index a4676267b..28705a3b5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java @@ -80,7 +80,6 @@ public class TutorialGettingStarted extends Tutorial }, 40L); } - @EventHandler(priority = EventPriority.MONITOR) public void onClansShopButtonAdded(ClansShopAddButtonEvent event) { @@ -202,6 +201,14 @@ public class TutorialGettingStarted extends Tutorial finishTask(event.getPlayer(), "Viewing Clan Info"); } } + else if (event.getCommand().equals("claim")) + { + if (isInTutorial(event.getPlayer()) && get(event.getPlayer()).hasFinishedTask(getTask("Go To The Wilderness")) && !get(event.getPlayer()).hasFinishedTask(getTask("Claiming Territory"))) + { + finishTask(event.getPlayer(), "Claiming Territory"); + event.setCancelled(true); + } + } } @EventHandler(priority = EventPriority.MONITOR) @@ -224,19 +231,6 @@ public class TutorialGettingStarted extends Tutorial } } - @EventHandler(priority = EventPriority.MONITOR) - public boolean onClaim(final PlayerClaimTerritoryEvent event) - { - if (isInTutorial(event.getClaimer()) && get(event.getClaimer()).hasFinishedTask(getTask("Go To The Wilderness")) && !get(event.getClaimer()).hasFinishedTask(getTask("Claiming Territory"))) - { - finishTask(event.getClaimer(), "Claiming Territory"); - - return false; - } - - return true; - } - @EventHandler(priority = EventPriority.MONITOR) public void onSkillTriggered(final SkillTriggerEvent event) { @@ -294,5 +288,5 @@ public class TutorialGettingStarted extends Tutorial { UtilPlayer.message(player, F.main("Tutorials", "Welcome to the " + F.elem("Getting Started Tutorial!"))); } - + }