From b8d2f784c7eedf398e70bfaf67cd068d70d3d20e Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Mon, 1 May 2017 22:19:50 -0300 Subject: [PATCH 1/2] Fix NPE, actually call PetSpawnEvent when spawning a pet --- .../gadgets/particle/king/CastleManager.java | 15 +++++++++++++++ .../src/mineplex/core/pet/PetManager.java | 14 ++++++-------- .../mineplex/core/pet/event/PetSpawnEvent.java | 6 +++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/king/CastleManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/king/CastleManager.java index d874792d5..fb51dbcc2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/king/CastleManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/king/CastleManager.java @@ -36,6 +36,7 @@ import mineplex.core.gadget.gadgets.particle.king.types.Peasant; import mineplex.core.hologram.Hologram; import mineplex.core.hologram.HologramManager; import mineplex.core.mount.event.MountActivateEvent; +import mineplex.core.pet.event.PetSpawnEvent; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -664,6 +665,10 @@ public class CastleManager extends MiniPlugin } } + /** + * Stops players from using mounts inside the castle + * @param event + */ @EventHandler public void onMount(MountActivateEvent event) { @@ -673,4 +678,14 @@ public class CastleManager extends MiniPlugin if (isInsideCastle(event.getPlayer().getLocation())) event.setCancelled(true); } + + @EventHandler + public void onPetSpawn(PetSpawnEvent event) + { + if (!isHub()) + return; + + if (isInsideCastle(event.getLocation())) + event.setCancelled(true); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java index 58b555539..902e5218a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java @@ -70,9 +70,9 @@ import mineplex.core.disguise.disguises.DisguiseVillager; import mineplex.core.disguise.disguises.DisguiseWither; import mineplex.core.disguise.disguises.DisguiseZombie; import mineplex.core.donation.DonationManager; -import mineplex.core.gadget.gadgets.particle.king.CastleManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.pet.event.PetSpawnEvent; import mineplex.core.pet.repository.PetRepository; import mineplex.core.pet.repository.token.ClientPetTokenWrapper; import mineplex.core.updater.UpdateType; @@ -97,7 +97,6 @@ public class PetManager extends MiniClientPlugin private DonationManager _donationManager; private CoreClientManager _clientManager; private InventoryManager _inventoryManager; - private CastleManager _castleManager; private Map _flyingPets = new HashMap<>(); private Map _trueLovePets = new HashMap<>(); @@ -110,8 +109,7 @@ public class PetManager extends MiniClientPlugin private ShapeWings _cupidWingsEdge = new ShapeWings(UtilParticle.ParticleType.RED_DUST.particleName, new Vector(0, 0, 0), 1, 0, true, ShapeWings.DEFAULT_ROTATION, ShapeWings.SMALL_HEART_WING_PATTERN); public PetManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager - , InventoryManager inventoryManager, DisguiseManager disguiseManager, mineplex.core.creature.Creature creatureModule, BlockRestore restore, - CastleManager castleManager) + , InventoryManager inventoryManager, DisguiseManager disguiseManager, mineplex.core.creature.Creature creatureModule, BlockRestore restore) { super("Pet Manager", plugin); @@ -216,11 +214,11 @@ public class PetManager extends MiniClientPlugin return; } - if (_castleManager.isInsideCastle(location)) - { - UtilPlayer.message(player, F.main("Pets", "You cannot spawn a pet inside the castle!")); + PetSpawnEvent petSpawnEvent = new PetSpawnEvent(player, petType.getEntityType(), location); + Bukkit.getPluginManager().callEvent(petSpawnEvent); + + if (petSpawnEvent.isCancelled()) return; - } Entity pet; EntityType entityType = petType.getEntityType(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/pet/event/PetSpawnEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/pet/event/PetSpawnEvent.java index cbd0d2c32..2b7ec73f1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/pet/event/PetSpawnEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/pet/event/PetSpawnEvent.java @@ -23,17 +23,17 @@ public class PetSpawnEvent extends Event implements Cancellable _location = location; } - public Player GetPlayer() + public Player getPlayer() { return _player; } - public EntityType GetEntityType() + public EntityType getEntityType() { return _entityType; } - public Location GetLocation() + public Location getLocation() { return _location; } From 030157fdb5c50d803c91eec03d1c13b0fdbae533 Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Mon, 1 May 2017 23:18:03 -0300 Subject: [PATCH 2/2] Fix constructors --- Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java | 2 +- Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java | 2 +- .../Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java | 2 +- .../mavericks-review-hub/src/mineplex/mavericks/review/Hub.java | 2 +- .../src/mineplex/gemhunters/GemHunters.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java index 01567f155..42a6f3a74 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java @@ -123,7 +123,7 @@ public class ClansHub extends JavaPlugin InventoryManager inventoryManager = new InventoryManager(this, clientManager); HologramManager hologramManager = new HologramManager(this, packetHandler); CastleManager castleManager = new CastleManager(this, clientManager, hologramManager, false); - PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore, castleManager); + PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore); PollManager pollManager = new PollManager(this, clientManager, donationManager); //Main Modules diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index bedf21851..3421cb3d8 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -147,7 +147,7 @@ public class Hub extends JavaPlugin implements IRelation _npcManager = npcManager; InventoryManager inventoryManager = new InventoryManager(this, clientManager); CastleManager castleManager = new CastleManager(this, clientManager, hologramManager, true); - PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore, castleManager); + PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore); PollManager pollManager = new PollManager(this, clientManager, donationManager); //new TournamentManager(this, clientManager, donationManager); 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 d900d8ec3..731d73616 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -202,7 +202,7 @@ public class Arcade extends JavaPlugin //Inventory InventoryManager inventoryManager = new InventoryManager(this, _clientManager); CastleManager castleManager = new CastleManager(this, _clientManager, hologramManager, false); - PetManager petManager = new PetManager(this, _clientManager, _donationManager, inventoryManager, disguiseManager, creature, blockRestore, castleManager); + PetManager petManager = new PetManager(this, _clientManager, _donationManager, inventoryManager, disguiseManager, creature, blockRestore); MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore, disguiseManager); GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager, achievementManager, packetHandler, hologramManager, incognito, castleManager); ThankManager thankManager = new ThankManager(this, _clientManager, _donationManager); diff --git a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java index 1c8d8d76e..ebc01ac9c 100644 --- a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java +++ b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java @@ -129,7 +129,7 @@ public class Hub extends JavaPlugin // Inventory CastleManager castleManager = new CastleManager(this, _clientManager, hologramManager, false); InventoryManager inventoryManager = new InventoryManager(this, _clientManager); - PetManager petManager = new PetManager(this, _clientManager, _donationManager, inventoryManager, disguiseManager, creature, blockRestore, castleManager); + PetManager petManager = new PetManager(this, _clientManager, _donationManager, inventoryManager, disguiseManager, creature, blockRestore); MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore, disguiseManager); GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager, achievementManager, packetHandler, hologramManager, incognito, castleManager); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index f44004315..f89b5f947 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -252,7 +252,7 @@ public class GemHunters extends JavaPlugin // :( CastleManager castleManager = new CastleManager(this, clientManager, hologramManager, false); MountManager mountManager = new MountManager(this, clientManager, donationManager, blockRestore, disguiseManager); - PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore, castleManager); + PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore); ProjectileManager projectileManager = new ProjectileManager(this); GadgetManager gadgetManager = new GadgetManager(this, clientManager, donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager, achievementManager, packetHandler, hologramManager, incognito, castleManager); ThankManager thankManager = new ThankManager(this, clientManager, donationManager);