Fix NPE, actually call PetSpawnEvent when spawning a pet

This commit is contained in:
LCastr0 2017-05-01 22:19:50 -03:00
parent fc5c420176
commit b8d2f784c7
3 changed files with 24 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -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<PetClient>
private DonationManager _donationManager;
private CoreClientManager _clientManager;
private InventoryManager _inventoryManager;
private CastleManager _castleManager;
private Map<Entity, FlyingPetManager> _flyingPets = new HashMap<>();
private Map<Entity, TrueLoveData> _trueLovePets = new HashMap<>();
@ -110,8 +109,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
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<PetClient>
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();

View File

@ -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;
}