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:
Andreas Troelsen 2019-08-07 23:41:02 +02:00
parent b44b808d38
commit 127d273fd6
2 changed files with 47 additions and 13 deletions

View File

@ -24,6 +24,7 @@ These changes will (most likely) be included in the next version.
- Mobs now correctly take damage from player-made iron golems.
- Cat and parrot pets now also sit when their owner joins an arena (although parrots perching on players' shoulders will still follow them into the arena).
- Pig zombies are now angry immediately after they spawn as they should be.
- Vexes summoned by evokers are now kept track of, so they count towards `clear-wave-before-next`, and they are properly removed at arena end.
- Support for denoting potion effects by magic number IDs has been dropped. This means that if your config-file has any such magic numbers in it, MobArena will no longer successfully parse them and will throw an error on startup.
- Support for auto-respawning has been dropped. The hacky way it was implemented is not officially supported by the Bukkit API and is highly discouraged because it is very buggy.

View File

@ -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) {