Keep track of Vexes summoned by Evokers.
This is a bit of an overhaul of how CreatureSpawnEvent is handled: - Events happening outside the arena region are still ignored, as are armor stands placed in edit mode. - Otherwise, if the arena isn't running, we blanket reject all entities. - Player-mode iron golems and snowmen are still allowed. - Anything that isn't spawned by a plugin is rejected, _unless_ it is a Vex spawned with "default" spawn reason, which is what the Evoker summon spell uses. In the end we have a "custom" spawn reason inside the arena region while it's running, which is perfectly "legal". And because of the unfortunate use of Creature (instead of Mob) in MACreature, Slimes and Magma Cubes still need to be handled separately here. Fixes #564
This commit is contained in:
@@ -402,22 +402,55 @@ public class ArenaListener
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getSpawnReason() != SpawnReason.CUSTOM) {
|
||||
if (event.getSpawnReason() == SpawnReason.BUILD_IRONGOLEM || event.getSpawnReason() == SpawnReason.BUILD_SNOWMAN) {
|
||||
monsters.addGolem(event.getEntity());
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!arena.isRunning()) {
|
||||
// Just block everything if we're not running
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity entity = event.getEntity();
|
||||
if (arena.isRunning() && entity instanceof Slime)
|
||||
monsters.addMonster(entity);
|
||||
SpawnReason reason = event.getSpawnReason();
|
||||
|
||||
// If running == true, setCancelled(false), and vice versa.
|
||||
event.setCancelled(!arena.isRunning());
|
||||
// Allow player-made iron golems and snowmen
|
||||
if (reason == SpawnReason.BUILD_IRONGOLEM || reason == SpawnReason.BUILD_SNOWMAN) {
|
||||
event.setCancelled(false);
|
||||
monsters.addGolem(event.getEntity());
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We normally want to block all "default" spawns, because this
|
||||
* reason means MobArena didn't trigger the event. However, we
|
||||
* make an exception for certain mobs that spawn as results of
|
||||
* other entities spawning them, e.g. when Evokers summon Vexes.
|
||||
*/
|
||||
if (reason == SpawnReason.DEFAULT) {
|
||||
if (event.getEntityType() == EntityType.VEX) {
|
||||
event.setCancelled(false);
|
||||
monsters.addMonster(event.getEntity());
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If not custom, we probably don't want it, so get rid of it
|
||||
if (reason != SpawnReason.CUSTOM) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, we probably want it, so uncancel just in case
|
||||
event.setCancelled(false);
|
||||
|
||||
/*
|
||||
* Because MACreature works with the Creature interface rather
|
||||
* than the Mob interface, it doesn't catch Slimes and Magma
|
||||
* Cubes, so we catch them here.
|
||||
*/
|
||||
LivingEntity entity = event.getEntity();
|
||||
if (entity instanceof Slime) {
|
||||
monsters.addMonster(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
|
||||
Reference in New Issue
Block a user