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
@@ -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<Entity> 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<Entity> 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);
}
};
}