From 7f1c4b1b87f89db918e48e066e341a49d72b0a01 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Fri, 26 Jul 2019 23:13:34 +0200 Subject: [PATCH] Don't assume implemented interfaces by EntityType in SitPets. This commit changes how SitPets determines if a nearby entity is "pet material". Instead of assuming that wolves and ocelots are tameable, we check for the Tameable interface. This means that we get rid of the "concrete" types, Wolf and Ocelot, and also fixes a bug on Minecraft 1.14 servers where ocelots are no longer tameable, but cats are. It also kinda catches parrots, but they will not sit if they are flying or perching on the player's shoulder when joining. Because ocelots are no longer tameable in 1.14, they shouldn't cause trouble here, but because they are tameable in 1.13, we need to rely on the Tameable interface to maintain both backwards and forwards compatibility. Fixes #548 (kind of - no more exceptions thrown, but the pet ocelots from SuperLuckyBlock may misbehave, however that is a different issue). --- changelog.md | 1 + .../garbagemule/MobArena/steps/SitPets.java | 28 +++++++------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index 666d857..4e47c6c 100644 --- a/changelog.md +++ b/changelog.md @@ -20,6 +20,7 @@ These changes will (most likely) be included in the next version. - Food levels no longer deplete for players in the lobby and spectator area. - Wither skeletons now correctly spawn with stone swords. - 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). - 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. ## [0.103.2] - 2019-04-23 diff --git a/src/main/java/com/garbagemule/MobArena/steps/SitPets.java b/src/main/java/com/garbagemule/MobArena/steps/SitPets.java index 950f3d9..c975e7f 100644 --- a/src/main/java/com/garbagemule/MobArena/steps/SitPets.java +++ b/src/main/java/com/garbagemule/MobArena/steps/SitPets.java @@ -1,10 +1,9 @@ package com.garbagemule.MobArena.steps; import org.bukkit.entity.Entity; -import org.bukkit.entity.Ocelot; import org.bukkit.entity.Player; +import org.bukkit.entity.Sittable; import org.bukkit.entity.Tameable; -import org.bukkit.entity.Wolf; import java.util.Collections; import java.util.List; @@ -45,34 +44,27 @@ class SitPets extends PlayerStep { private static Predicate isPetOwnedBy(Player player) { return entity -> { - switch (entity.getType()) { - case WOLF: - case OCELOT: - return player.equals(((Tameable) entity).getOwner()); + if (entity instanceof Tameable) { + Tameable tameable = (Tameable) entity; + return player.equals(tameable.getOwner()); } return false; }; } private static boolean isFollowing(Entity entity) { - switch (entity.getType()) { - case WOLF: - return !((Wolf) entity).isSitting(); - case OCELOT: - return !((Ocelot) entity).isSitting(); + if (entity instanceof Sittable) { + Sittable sittable = (Sittable) entity; + return !sittable.isSitting(); } return false; } private static Consumer setSitting(boolean sitting) { return entity -> { - switch (entity.getType()) { - case WOLF: - ((Wolf) entity).setSitting(sitting); - break; - case OCELOT: - ((Ocelot) entity).setSitting(sitting); - break; + if (entity instanceof Sittable) { + Sittable sittable = (Sittable) entity; + sittable.setSitting(sitting); } }; }