Skip to content

Commit ec644df

Browse files
committed
Adapt to the new SPELL spawn reason.
This new spawn reason was introduced somewhere between 1.18 and 1.18.1, and unfortunately it is a breaking change, so we have to employ it for MobArena to properly allow and register vexes (again...), but we also have to maintain a variation of the old logic so we don't break support for older server versions. Fixes #719
1 parent 2c0d3e2 commit ec644df

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ These changes will (most likely) be included in the next version.
3131
- Pillagers and vindicators no longer spawn without their much-needed weapons.
3232
- Piglins, piglin brutes, and hoglins no longer zombify. This fixes a bug where the mobs would despawn due to the zombification process.
3333
- Zombies, husks, drowned, zombie villagers, piglins, hoglins, and zoglins without the `baby` prefix are now forced into adulthood to prevent them from occasionally spawning as babies.
34+
- Evokers are once again capable of spawning vexes on 1.18.1+.
3435
- Reward groups with `nothing` in them no longer cause errors when earned/granted.
3536
- The title-based announcer and the title-based boss health bar have been fixed to work with the breaking change to the Title API in Spigot 1.17.
3637
- Arena Signs now correctly update for arenas that don't have `kebab-case` names in the config-file.

src/main/java/com/garbagemule/MobArena/ArenaListener.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,15 +393,23 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
393393
* reason means MobArena didn't trigger the event. However, we
394394
* make an exception for certain mobs that spawn as results of
395395
* other entities spawning them, e.g. when Evokers summon Vexes.
396+
* Note that the "spell" reason was introduced somewhere between
397+
* 1.18 and 1.18.1, so "default" is kept only for compatibility
398+
* with older server versions. Also note the use of `switch` as
399+
* a workaround for the NoSuchFieldError that would occur if we
400+
* used a simple equality check.
396401
*/
397-
if (reason == SpawnReason.DEFAULT) {
398-
if (event.getEntityType() == EntityType.VEX) {
399-
event.setCancelled(false);
400-
monsters.addMonster(event.getEntity());
401-
} else {
402-
event.setCancelled(true);
402+
switch (reason) {
403+
case DEFAULT:
404+
case SPELL: {
405+
if (event.getEntityType() == EntityType.VEX) {
406+
event.setCancelled(false);
407+
monsters.addMonster(event.getEntity());
408+
} else {
409+
event.setCancelled(true);
410+
}
411+
return;
403412
}
404-
return;
405413
}
406414

407415
// If not custom, we probably don't want it, so get rid of it

0 commit comments

Comments
 (0)