Enables operation on 1.13.2 servers.

Avoids use of AbstractVillager for now. Alternative to PR
https://github.com/BentoBoxWorld/BentoBox/pull/1035
This commit is contained in:
tastybento 2019-11-25 21:17:41 -08:00
parent b3dde9ad3e
commit 5f52b32cd3
4 changed files with 26 additions and 7 deletions

View File

@ -1,11 +1,11 @@
package world.bentobox.bentobox.listeners.flags.protection;
import org.bukkit.Material;
import org.bukkit.entity.AbstractVillager;
import org.bukkit.entity.Animals;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.Villager;
import org.bukkit.entity.minecart.RideableMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -47,7 +47,7 @@ public class EntityInteractListener extends FlagListener {
}
}
// Villager trading
else if (e.getRightClicked() instanceof AbstractVillager) {
else if (e.getRightClicked() instanceof Villager || e.getRightClicked().getType().name().equals("WANDERING_TRADER")) { // TODO: Simplify when 1.13.2 support is dropped
// Check naming and check trading
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.TRADING);
if (e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.NAME_TAG)) {

View File

@ -14,6 +14,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Parrot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -53,7 +54,7 @@ public class HurtingListener extends FlagListener {
// Mobs being hurt
if (Util.isPassiveEntity(e.getEntity())) {
respond(e, e.getDamager(), Flags.HURT_ANIMALS);
} else if (e.getEntity() instanceof AbstractVillager) {
} else if (e.getEntity() instanceof Villager || e.getEntityType().name().equals("WANDERING_TRADER")) { // TODO: Simplify when 1.13.2 support is dropped
respond(e, e.getDamager(), Flags.HURT_VILLAGERS);
} else if (Util.isHostileEntity(e.getEntity())) {
respond(e, e.getDamager(), Flags.HURT_MONSTERS);

View File

@ -22,6 +22,7 @@ import org.bukkit.World;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep;
@ -335,7 +336,7 @@ public class EntityInteractListenerTest {
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.EntityInteractListener#onPlayerInteractEntity(org.bukkit.event.player.PlayerInteractEntityEvent)}.
*/
@ -343,6 +344,7 @@ public class EntityInteractListenerTest {
public void testOnPlayerInteractEntityWanderingTraderNoInteraction() {
clickedEntity = mock(WanderingTrader.class);
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.WANDERING_TRADER);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, times(2)).notify(any(), eq("protection.protected"));
@ -356,6 +358,7 @@ public class EntityInteractListenerTest {
public void testOnPlayerInteractAtEntityWanderingTraderAllowed() {
when(island.isAllowed(any(), any())).thenReturn(true);
clickedEntity = mock(WanderingTrader.class);
when(clickedEntity.getType()).thenReturn(EntityType.WANDERING_TRADER);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
@ -371,6 +374,7 @@ public class EntityInteractListenerTest {
when(island.isAllowed(any(), eq(Flags.TRADING))).thenReturn(false);
when(island.isAllowed(any(), eq(Flags.NAME_TAG))).thenReturn(true);
clickedEntity = mock(WanderingTrader.class);
when(clickedEntity.getType()).thenReturn(EntityType.WANDERING_TRADER);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
@ -386,6 +390,7 @@ public class EntityInteractListenerTest {
when(island.isAllowed(any(), eq(Flags.TRADING))).thenReturn(true);
when(island.isAllowed(any(), eq(Flags.NAME_TAG))).thenReturn(false);
clickedEntity = mock(WanderingTrader.class);
when(clickedEntity.getType()).thenReturn(EntityType.WANDERING_TRADER);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
@ -400,6 +405,7 @@ public class EntityInteractListenerTest {
public void testOnPlayerInteractEntitySheepAllowed() {
clickedEntity = mock(Sheep.class);
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.SHEEP);
when(inv.getItemInMainHand()).thenReturn(new ItemStack(Material.AIR));
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
@ -414,6 +420,7 @@ public class EntityInteractListenerTest {
public void testOnPlayerInteractEntitySheepNameTagNoInteraction() {
clickedEntity = mock(Sheep.class);
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.SHEEP);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));

View File

@ -22,6 +22,7 @@ import org.bukkit.World;
import org.bukkit.entity.Animals;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
@ -36,6 +37,7 @@ import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@ -132,6 +134,7 @@ public class HurtingListenerTest {
// Monsters and animals
when(enderman.getLocation()).thenReturn(location);
when(enderman.getWorld()).thenReturn(world);
when(enderman.getType()).thenReturn(EntityType.ENDERMAN);
Slime slime = mock(Slime.class);
when(slime.getLocation()).thenReturn(location);
@ -324,6 +327,7 @@ public class HurtingListenerTest {
public void testOnFishingDisallowVillagerCatching() {
Villager entity = mock(Villager.class);
when(entity.getLocation()).thenReturn(location);
when(entity.getType()).thenReturn(EntityType.VILLAGER);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
@ -331,13 +335,14 @@ public class HurtingListenerTest {
// Verify
verify(notifier).notify(eq(user), eq("protection.protected"));
}
/**
* Test method for {@link HurtingListener#onFishing(org.bukkit.event.player.PlayerFishEvent)}.
*/
@Test
public void testOnFishingDisallowWanderingTraderCatching() {
WanderingTrader entity = mock(WanderingTrader.class);
when(entity.getType()).thenReturn(EntityType.WANDERING_TRADER);
when(entity.getLocation()).thenReturn(location);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
@ -355,6 +360,7 @@ public class HurtingListenerTest {
public void testOnFishingAllowVillagerCatching() {
Villager entity = mock(Villager.class);
when(entity.getLocation()).thenReturn(location);
when(entity.getType()).thenReturn(EntityType.VILLAGER);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
@ -364,7 +370,7 @@ public class HurtingListenerTest {
// Verify
verify(notifier, never()).notify(eq(user), eq("protection.protected"));
}
/**
* Test method for {@link HurtingListener#onFishing(org.bukkit.event.player.PlayerFishEvent)}.
*/
@ -372,6 +378,7 @@ public class HurtingListenerTest {
public void testOnFishingAllowWanderingTraderCatching() {
WanderingTrader entity = mock(WanderingTrader.class);
when(entity.getLocation()).thenReturn(location);
when(entity.getType()).thenReturn(EntityType.WANDERING_TRADER);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
@ -381,10 +388,11 @@ public class HurtingListenerTest {
// Verify
verify(notifier, never()).notify(eq(user), eq("protection.protected"));
}
/**
* Test method for {@link HurtingListener#onPlayerFeedParrots(org.bukkit.event.player.PlayerInteractEntityEvent)}.
*/
@Ignore("Not yet implemented")
@Test
public void testOnPlayerFeedParrots() {
//fail("Not yet implemented"); // TODO
@ -393,6 +401,7 @@ public class HurtingListenerTest {
/**
* Test method for {@link HurtingListener#onSplashPotionSplash(org.bukkit.event.entity.PotionSplashEvent)}.
*/
@Ignore("Not yet implemented")
@Test
public void testOnSplashPotionSplash() {
//fail("Not yet implemented"); // TODO
@ -401,6 +410,7 @@ public class HurtingListenerTest {
/**
* Test method for {@link HurtingListener#onLingeringPotionSplash(org.bukkit.event.entity.LingeringPotionSplashEvent)}.
*/
@Ignore("Not yet implemented")
@Test
public void testOnLingeringPotionSplash() {
//fail("Not yet implemented"); // TODO
@ -409,6 +419,7 @@ public class HurtingListenerTest {
/**
* Test method for {@link HurtingListener#onLingeringPotionDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
*/
@Ignore("Not yet implemented")
@Test
public void testOnLingeringPotionDamage() {
//fail("Not yet implemented"); // TODO