From 32a6d572ee303034f32e28d526b28ccea8947c40 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sat, 5 Dec 2015 22:56:15 -0500 Subject: [PATCH] Disable gadgets in arcade for player count > 40 --- .../mineplex/core/gadget/GadgetManager.java | 39 +++++++++++++++++++ .../src/mineplex/hub/HubManager.java | 38 +++--------------- .../nautilus/game/arcade/ArcadeManager.java | 20 ++++++++++ 3 files changed, 65 insertions(+), 32 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index 7494e9fa6..bb17d1e2f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -14,6 +14,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; +import mineplex.core.gadget.event.GadgetActivateEvent; import mineplex.core.gadget.event.GadgetCollideEntityEvent; import mineplex.core.gadget.gadgets.ItemBatGun; import mineplex.core.gadget.gadgets.ItemCoinBomb; @@ -63,6 +64,7 @@ import mineplex.core.gadget.types.OutfitGadget.ArmorSlot; import mineplex.core.gadget.types.ParticleGadget; import mineplex.core.inventory.InventoryManager; import mineplex.core.mount.MountManager; +import mineplex.core.mount.event.MountActivateEvent; import mineplex.core.pet.PetManager; import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; @@ -91,6 +93,7 @@ public class GadgetManager extends MiniPlugin private BlockRestore _blockRestore; private ProjectileManager _projectileManager; private AchievementManager _achievementManager; + private MountManager _mountManager; private NautHashMap> _gadgets; @@ -99,6 +102,7 @@ public class GadgetManager extends MiniPlugin private boolean _hideParticles = false; private int _activeItemSlot = 3; + private boolean _gadgetsEnabled = true; public GadgetManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, MountManager mountManager, PetManager petManager, PreferencesManager preferencesManager, @@ -115,6 +119,7 @@ public class GadgetManager extends MiniPlugin _blockRestore = blockRestore; _projectileManager = projectileManager; _achievementManager = achievementManager; + _mountManager = mountManager; CreateGadgets(); } @@ -491,6 +496,40 @@ public class GadgetManager extends MiniPlugin return true; } + + public boolean isGadgetEnabled() + { + return _gadgetsEnabled; + } + + public void toggleGadgetEnabled() + { + setGadgetEnabled(!_gadgetsEnabled); + } + + public void setGadgetEnabled(boolean enabled) + { + if (_gadgetsEnabled != enabled) + { + _gadgetsEnabled = enabled; + DisableAll(); + _mountManager.DisableAll(); + } + } + + @EventHandler + public void GadgetActivate(GadgetActivateEvent event) + { + if (!_gadgetsEnabled) + event.setCancelled(true); + } + + @EventHandler + public void MountActivate(MountActivateEvent event) + { + if (!_gadgetsEnabled) + event.setCancelled(true); + } @EventHandler public void chissMeow(PlayerToggleSneakEvent event) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 4ae6eea74..7a23e98a9 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -28,14 +28,12 @@ import mineplex.core.disguise.DisguiseManager; import mineplex.core.disguise.disguises.DisguiseSlime; import mineplex.core.donation.DonationManager; import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.event.GadgetActivateEvent; import mineplex.core.gadget.event.GadgetCollideEntityEvent; import mineplex.core.giveaway.GiveawayManager; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.message.PrivateMessageEvent; import mineplex.core.mount.MountManager; -import mineplex.core.mount.event.MountActivateEvent; import mineplex.core.notifier.NotificationManager; import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; @@ -161,9 +159,6 @@ public class HubManager extends MiniClientPlugin private HashMap> _creativeAdmin = new HashMap>(); - //Admin - private boolean _gadgetsEnabled = true; - public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, GiveawayManager giveawayManager) { super("Hub Manager", plugin); @@ -913,12 +908,6 @@ public class HubManager extends MiniClientPlugin event.SetCancelled(true); } - public boolean IsGadgetEnabled() - { - return _gadgetsEnabled; - } - - public NewsManager GetNewsManager() { return _news; @@ -935,30 +924,15 @@ public class HubManager extends MiniClientPlugin public void ToggleGadget(Player caller) { - _gadgetsEnabled = !_gadgetsEnabled; + toggleGadget(); + } - if (!_gadgetsEnabled) - { - GetMount().DisableAll(); - GetGadget().DisableAll(); - } + public void toggleGadget() + { + GetGadget().toggleGadgetEnabled(); for (Player player : UtilServer.getPlayers()) - player.sendMessage(C.cWhite + C.Bold + "Gadgets/Mounts are now " + F.elem(_gadgetsEnabled ? C.cGreen + C.Bold + "Enabled" : C.cRed + C.Bold + "Disabled")); - } - - @EventHandler - public void GadgetActivate(GadgetActivateEvent event) - { - if (!_gadgetsEnabled) - event.setCancelled(true); - } - - @EventHandler - public void MountActivate(MountActivateEvent event) - { - if (!_gadgetsEnabled) - event.setCancelled(true); + player.sendMessage(C.cWhite + C.Bold + "Gadgets/Mounts are now " + F.elem(GetGadget().isGadgetEnabled() ? C.cGreen + C.Bold + "Enabled" : C.cRed + C.Bold + "Disabled")); } public void addGameMode(Player caller, Player target) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 531df19d4..a29c226fe 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -24,6 +24,7 @@ import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.creature.Creature; @@ -1236,6 +1237,25 @@ public class ArcadeManager extends MiniPlugin implements IRelation } } + @EventHandler + public void disableGadget(PlayerJoinEvent event) + { + updateGadgetEnabled(); + } + + @EventHandler + public void disableGadget(PlayerQuitEvent event) + { + updateGadgetEnabled(); + } + + private void updateGadgetEnabled() + { + // Disables gadgets if player count is greater than 40 + int playerCount = UtilServer.getPlayers().length; + getCosmeticManager().getGadgetManager().setGadgetEnabled(playerCount <= 40); + } + /*public void saveBasicStats(final Game game) { if (!IsTournamentServer())