From 5209cf3d3848638b2959f13b3d9416fde2ac352a Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sun, 15 Nov 2015 20:04:44 +0000 Subject: [PATCH] fixed an annoying IllegalArgument with the World Event start command. fixed limit bukkit runnable not limiting itself. --- .../common/util/LimitedBukkitRunnable.java | 7 +++++- .../clans/worldevent/WorldEventManager.java | 13 +++++++++- .../worldevent/command/StartCommand.java | 24 ++++++++++++++----- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/LimitedBukkitRunnable.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/LimitedBukkitRunnable.java index 6b5c6b068..0a6c71a16 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/LimitedBukkitRunnable.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/LimitedBukkitRunnable.java @@ -15,11 +15,16 @@ public abstract class LimitedBukkitRunnable extends BukkitRunnable @Override public void run() { - if (_timesRun > _maxTimes){ + if (_timesRun > _maxTimes) + { UtilServer.getServer().getScheduler().cancelTask(getTaskId()); + return; } + onRun(_timesRun); + + _timesRun++; } public abstract void onRun(int timesRun); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java index 89330ff6c..c05edd166 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -150,7 +150,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement getPlugin().getServer().getPluginManager().registerEvents(event, getPlugin()); _runningEvents.add(event); } - + public WorldEvent startEventFromName(Location location, String name) { WorldEventType eventType = WorldEventType.valueOf(name); @@ -163,6 +163,17 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement return null; } + public WorldEvent startEventFromType(Location location, WorldEventType eventType) + { + if (eventType != null) + { + WorldEvent event = eventType.createInstance(this, location); + initializeEvent(event); + return event; + } + + return null; + } public void clearEvents() { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java index a0e9eded1..957a39636 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java @@ -7,6 +7,7 @@ import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.worldevent.WorldEventManager; +import mineplex.game.clans.clans.worldevent.WorldEventType; import mineplex.minecraft.game.core.boss.WorldEvent; public class StartCommand extends CommandBase @@ -15,19 +16,30 @@ public class StartCommand extends CommandBase { super(plugin, Rank.DEVELOPER, new Rank[] { Rank.JNR_DEV }, "start", "create"); } - + @Override public void Execute(Player caller, String[] args) { // start specific world event type if (args != null && args.length == 1) { - WorldEvent event = Plugin.startEventFromName(caller.getLocation(), args[0]); - if (event == null) - UtilPlayer.message(caller, F.main("WorldEvent", "Could not find a WorldEvent with the name " + F.elem(args[0]))); - else + try { - UtilPlayer.message(caller, F.main("worldEvent", "Started WorldEvent " + F.elem(args[0]) + " at your current location")); + WorldEventType eventType = WorldEventType.valueOf(args[0]); + WorldEvent event = Plugin.startEventFromType(caller.getLocation(), eventType); + + if (event == null) + { + UtilPlayer.message(caller, F.main("WorldEvent", "Error whilst starting the world event you chose.")); + } + else + { + UtilPlayer.message(caller, F.main("worldEvent", "Started WorldEvent " + F.elem(args[0]) + " at your current location")); + } + } + catch (IllegalArgumentException e) + { + UtilPlayer.message(caller, F.main("WorldEvent", "Could not find a WorldEvent with the name " + F.elem(args[0]))); } } }