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).
This commit is contained in:
Andreas Troelsen 2019-07-26 23:13:34 +02:00
parent 81dfb71fe1
commit 7f1c4b1b87
2 changed files with 11 additions and 18 deletions

View File

@ -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. - Food levels no longer deplete for players in the lobby and spectator area.
- Wither skeletons now correctly spawn with stone swords. - Wither skeletons now correctly spawn with stone swords.
- Mobs now correctly take damage from player-made iron golems. - 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. - 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 ## [0.103.2] - 2019-04-23

View File

@ -1,10 +1,9 @@
package com.garbagemule.MobArena.steps; package com.garbagemule.MobArena.steps;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Sittable;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wolf;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -45,34 +44,27 @@ class SitPets extends PlayerStep {
private static Predicate<Entity> isPetOwnedBy(Player player) { private static Predicate<Entity> isPetOwnedBy(Player player) {
return entity -> { return entity -> {
switch (entity.getType()) { if (entity instanceof Tameable) {
case WOLF: Tameable tameable = (Tameable) entity;
case OCELOT: return player.equals(tameable.getOwner());
return player.equals(((Tameable) entity).getOwner());
} }
return false; return false;
}; };
} }
private static boolean isFollowing(Entity entity) { private static boolean isFollowing(Entity entity) {
switch (entity.getType()) { if (entity instanceof Sittable) {
case WOLF: Sittable sittable = (Sittable) entity;
return !((Wolf) entity).isSitting(); return !sittable.isSitting();
case OCELOT:
return !((Ocelot) entity).isSitting();
} }
return false; return false;
} }
private static Consumer<Entity> setSitting(boolean sitting) { private static Consumer<Entity> setSitting(boolean sitting) {
return entity -> { return entity -> {
switch (entity.getType()) { if (entity instanceof Sittable) {
case WOLF: Sittable sittable = (Sittable) entity;
((Wolf) entity).setSitting(sitting); sittable.setSitting(sitting);
break;
case OCELOT:
((Ocelot) entity).setSitting(sitting);
break;
} }
}; };
} }