Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>3.9.1</build.version>
<build.version>3.9.2</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData;
import net.minecraft.world.level.block.entity.TileEntity;
import world.bentobox.bentobox.BentoBox;

public abstract class AbstractMetaData {

Expand All @@ -33,7 +34,7 @@ protected String getData(TileEntity te, String method, String field) {
// object.getClass().getCanonicalName() + " is not a PacketPlayOutTileEntityData");
//}
} catch (Exception e) {
System.out.println("The method '" + method + "' does not exist in the TileEntity class.");
BentoBox.getInstance().logError("The method '" + method + "' does not exist in the TileEntity class.");
e.printStackTrace();
}
return "";
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/world/bentobox/bentobox/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.bukkit.entity.CopperGolem;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Flying;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Monster;
Expand Down Expand Up @@ -361,19 +362,25 @@ public static boolean isHostileEntity(Entity entity) {
* @since 1.4.0
*/
public static boolean isPassiveEntity(Entity entity) {
// IronGolem and Snowman extends Golem, but Shulker also extends Golem
// Fishes, Dolphin and Squid extends WaterMob | Excludes PufferFish
// Bat extends Mob
// Most of passive mobs extends Animals
boolean copperGolem = false;
try {
copperGolem = entity instanceof CopperGolem;
} catch (Exception ex) {
copperGolem = false;
if (entity == null || entity.getType() == null) {
return true;
}
return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat ||
entity instanceof Allay || copperGolem;
// Check built-in class hierarchy for common passive mobs
boolean isPassiveByClass = entity instanceof Animals
|| entity instanceof IronGolem
|| entity instanceof Snowman
|| entity instanceof Bat
|| entity instanceof Allay;

// Check WaterMob hierarchy, excluding PufferFish (hostile)
boolean isPassiveWaterMob = entity instanceof WaterMob && !(entity instanceof PufferFish);

// Check for newer entity types by their enum name (String comparison is safe across versions)
boolean isCopperGolem = entity.getType().name().equals("COPPER_GOLEM");
// And the sniffer
boolean isSniffer = entity.getType().name().equals("SNIFFER");

return isPassiveByClass || isPassiveWaterMob || isCopperGolem || isSniffer;
}

public static boolean isTamableEntity(Entity entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

Expand Down Expand Up @@ -68,6 +69,7 @@ public void setUp() throws Exception {
// Utils
when(Util.isPassiveEntity(any())).thenCallRealMethod();
when(Util.isHostileEntity(any())).thenCallRealMethod();
when(Util.isTamableEntity(any())).thenCallRealMethod();

// User & player
user = User.getInstance(mockPlayer);
Expand All @@ -93,6 +95,7 @@ public void testOnEntityDamagePlayeronMonster() {
HurtingListener hl = new HurtingListener();
hl.onEntityDamage(e);
assertTrue(e.isCancelled());

verify(notifier).notify(user, "protection.protected");
}

Expand Down Expand Up @@ -121,7 +124,7 @@ public void testOnFishingDisallowArmorStandCatching() {
HurtingListener hl = new HurtingListener();
hl.onFishing(e);
// Verify
verify(notifier).notify(user, "protection.protected");
verify(notifier, Mockito.atLeastOnce()).notify(user, "protection.protected");
}

/**
Expand Down Expand Up @@ -185,7 +188,7 @@ public void testOnFishingDisallowMonsterCatching() {
HurtingListener hl = new HurtingListener();
hl.onFishing(e);
// Verify
verify(notifier).notify(user, "protection.protected");
verify(notifier, Mockito.atLeastOnce()).notify(user, "protection.protected");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,6 @@ public void tearDown() {
Mockito.framework().clearInlineMocks();
}

@Test
public void testNotLoaded() {
when(plugin.isLoaded()).thenReturn(false);
CreatureSpawnEvent e = new CreatureSpawnEvent(livingEntity, SpawnReason.NATURAL);
MobSpawnListener l = new MobSpawnListener();
l.onMobSpawn(e);
assertFalse(e.isCancelled());
}

@Test
public void testNotInWorld() {
when(iwm.inWorld(any(Location.class))).thenReturn(false);
Expand Down