From fff6d8e03f0eef64d349bd0943d19f5f64d3224d Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 7 Jan 2016 19:36:52 +0000 Subject: [PATCH] added server shutdown event, along with making the outposts cleanup on server shutdown to prevent debris of currently in-play outposts sticking around. --- .../common/events/ServerShutdownEvent.java | 33 +++++++++++++++++++ .../src/mineplex/game/clans/Clans.java | 3 ++ .../game/clans/clans/outpost/Outpost.java | 12 +++++-- .../clans/clans/outpost/OutpostManager.java | 10 ++++++ .../Mineplex.Hub/src/mineplex/hub/Hub.java | 4 +-- .../src/nautilus/game/arcade/Arcade.java | 16 +++++---- 6 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/events/ServerShutdownEvent.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/events/ServerShutdownEvent.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/events/ServerShutdownEvent.java new file mode 100644 index 000000000..70bf8f99d --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/events/ServerShutdownEvent.java @@ -0,0 +1,33 @@ +package mineplex.core.common.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.plugin.java.JavaPlugin; + +public class ServerShutdownEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private JavaPlugin _plugin; + + public ServerShutdownEvent(JavaPlugin plugin) + { + _plugin = plugin; + } + + public JavaPlugin getPlugin() + { + return _plugin; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 2c0819d99..5d8be3794 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -13,6 +13,7 @@ import mineplex.core.antihack.AntiHack; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.delayedtask.DelayedTask; import mineplex.core.donation.DonationManager; import mineplex.core.explosion.Explosion; @@ -175,5 +176,7 @@ public class Clans extends JavaPlugin // Need to notify WorldEventManager of server shutdown, this seemed like // the only decent way to do it _clansManager.onDisable(); + + getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java index 6288a3947..82d48ff07 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java @@ -109,10 +109,10 @@ public class Outpost implements Listener _blocks = null; if (_preHologram != null) _preHologram.stop(); - if (_preHologram2 != null) _preHologram2.stop(); + if (_preHologram2 != null) _preHologram2.stop(); _preHologram = null; - _preHologram = null; + _preHologram2 = null; _state = OutpostState.DEAD; @@ -147,6 +147,7 @@ public class Outpost implements Listener { if (event.getClickedBlock().getType().equals(Material.NETHERRACK)) { + _origin.getBlock().setType(Material.AIR); beginConstruction(); } } @@ -334,6 +335,13 @@ public class Outpost implements Listener return list; } + + public void instakill() + { + _blocks.values().forEach(OutpostBlock::restore); + + cleanup(); + } public void kill() { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java index d3b81a23b..7f0e5c7ff 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java @@ -14,6 +14,7 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import mineplex.core.MiniPlugin; +import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilItem; @@ -141,6 +142,15 @@ public class OutpostManager extends MiniPlugin } } + @EventHandler + public void onServerShutdown(ServerShutdownEvent event) + { + for (Outpost outpost : _outposts.values()) + { + outpost.instakill(); + } + } + @EventHandler public void onClaim(PlayerClaimTerritoryEvent event) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index bfac5e555..72388bf95 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -13,6 +13,7 @@ import mineplex.core.aprilfools.AprilFoolsManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.creature.Creature; import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; @@ -65,7 +66,6 @@ import mineplex.minecraft.game.classcombat.shop.ClassCombatShop; import mineplex.minecraft.game.classcombat.shop.ClassShopManager; import mineplex.minecraft.game.core.IRelation; import mineplex.minecraft.game.core.combat.CombatManager; -import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.damage.DamageManager; import mineplex.minecraft.game.core.fire.Fire; @@ -188,7 +188,7 @@ public class Hub extends JavaPlugin implements IRelation @Override public void onDisable() { - + getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); } @Override diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index e2ca772b3..cc656c818 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -6,15 +6,9 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import mineplex.core.CustomTagFix; import mineplex.core.FoodDupeFix; import mineplex.core.PacketsInteractionFix; -import mineplex.core.account.CoreClient; -import mineplex.core.customdata.CustomDataManager; -import mineplex.core.giveaway.GiveawayManager; -import mineplex.core.globalpacket.GlobalPacketManager; -import net.minecraft.server.v1_8_R3.BiomeBase; -import net.minecraft.server.v1_8_R3.MinecraftServer; -import mineplex.core.CustomTagFix; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.antihack.AntiHack; @@ -22,15 +16,19 @@ import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blood.Blood; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.common.util.FileUtil; import mineplex.core.common.util.UtilServer; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.creature.Creature; +import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; import mineplex.core.friend.FriendManager; import mineplex.core.gadget.GadgetManager; import mineplex.core.give.Give; +import mineplex.core.giveaway.GiveawayManager; +import mineplex.core.globalpacket.GlobalPacketManager; import mineplex.core.hologram.HologramManager; import mineplex.core.ignore.IgnoreManager; import mineplex.core.inventory.InventoryManager; @@ -61,6 +59,8 @@ import mineplex.core.visibility.VisibilityManager; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; import nautilus.game.arcade.game.GameServerConfig; +import net.minecraft.server.v1_8_R3.BiomeBase; +import net.minecraft.server.v1_8_R3.MinecraftServer; public class Arcade extends JavaPlugin { @@ -186,6 +186,8 @@ public class Arcade extends JavaPlugin if (_gameManager.GetGame() != null) if (_gameManager.GetGame().WorldData != null) _gameManager.GetGame().WorldData.Uninitialize(); + + getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); } public GameServerConfig ReadServerConfig()