Skip to content

Commit 0f659a0

Browse files
authored
Merge pull request #2755 from BentoBoxWorld/develop
Version 3.7.2
2 parents 5da0b5c + 424ee01 commit 0f659a0

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<!-- Do not change unless you want different name for local builds. -->
7676
<build.number>-LOCAL</build.number>
7777
<!-- This allows to change between versions. -->
78-
<build.version>3.9.1</build.version>
78+
<build.version>3.9.2</build.version>
7979
<sonar.organization>bentobox-world</sonar.organization>
8080
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
8181
<server.jars>${project.basedir}/lib</server.jars>

src/main/java/world/bentobox/bentobox/nms/AbstractMetaData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraft.nbt.NBTTagCompound;
99
import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData;
1010
import net.minecraft.world.level.block.entity.TileEntity;
11+
import world.bentobox.bentobox.BentoBox;
1112

1213
public abstract class AbstractMetaData {
1314

@@ -33,7 +34,7 @@ protected String getData(TileEntity te, String method, String field) {
3334
// object.getClass().getCanonicalName() + " is not a PacketPlayOutTileEntityData");
3435
//}
3536
} catch (Exception e) {
36-
System.out.println("The method '" + method + "' does not exist in the TileEntity class.");
37+
BentoBox.getInstance().logError("The method '" + method + "' does not exist in the TileEntity class.");
3738
e.printStackTrace();
3839
}
3940
return "";

src/main/java/world/bentobox/bentobox/util/Util.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.bukkit.entity.CopperGolem;
3535
import org.bukkit.entity.EnderDragon;
3636
import org.bukkit.entity.Entity;
37+
import org.bukkit.entity.EntityType;
3738
import org.bukkit.entity.Flying;
3839
import org.bukkit.entity.IronGolem;
3940
import org.bukkit.entity.Monster;
@@ -361,19 +362,25 @@ public static boolean isHostileEntity(Entity entity) {
361362
* @since 1.4.0
362363
*/
363364
public static boolean isPassiveEntity(Entity entity) {
364-
// IronGolem and Snowman extends Golem, but Shulker also extends Golem
365-
// Fishes, Dolphin and Squid extends WaterMob | Excludes PufferFish
366-
// Bat extends Mob
367-
// Most of passive mobs extends Animals
368-
boolean copperGolem = false;
369-
try {
370-
copperGolem = entity instanceof CopperGolem;
371-
} catch (Exception ex) {
372-
copperGolem = false;
365+
if (entity == null || entity.getType() == null) {
366+
return true;
373367
}
374-
return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
375-
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat ||
376-
entity instanceof Allay || copperGolem;
368+
// Check built-in class hierarchy for common passive mobs
369+
boolean isPassiveByClass = entity instanceof Animals
370+
|| entity instanceof IronGolem
371+
|| entity instanceof Snowman
372+
|| entity instanceof Bat
373+
|| entity instanceof Allay;
374+
375+
// Check WaterMob hierarchy, excluding PufferFish (hostile)
376+
boolean isPassiveWaterMob = entity instanceof WaterMob && !(entity instanceof PufferFish);
377+
378+
// Check for newer entity types by their enum name (String comparison is safe across versions)
379+
boolean isCopperGolem = entity.getType().name().equals("COPPER_GOLEM");
380+
// And the sniffer
381+
boolean isSniffer = entity.getType().name().equals("SNIFFER");
382+
383+
return isPassiveByClass || isPassiveWaterMob || isCopperGolem || isSniffer;
377384
}
378385

379386
public static boolean isTamableEntity(Entity entity) {

src/test/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListenerTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.junit.Test;
2727
import org.junit.runner.RunWith;
2828
import org.mockito.Mock;
29+
import org.mockito.Mockito;
2930
import org.powermock.core.classloader.annotations.PrepareForTest;
3031
import org.powermock.modules.junit4.PowerMockRunner;
3132

@@ -68,6 +69,7 @@ public void setUp() throws Exception {
6869
// Utils
6970
when(Util.isPassiveEntity(any())).thenCallRealMethod();
7071
when(Util.isHostileEntity(any())).thenCallRealMethod();
72+
when(Util.isTamableEntity(any())).thenCallRealMethod();
7173

7274
// User & player
7375
user = User.getInstance(mockPlayer);
@@ -93,6 +95,7 @@ public void testOnEntityDamagePlayeronMonster() {
9395
HurtingListener hl = new HurtingListener();
9496
hl.onEntityDamage(e);
9597
assertTrue(e.isCancelled());
98+
9699
verify(notifier).notify(user, "protection.protected");
97100
}
98101

@@ -121,7 +124,7 @@ public void testOnFishingDisallowArmorStandCatching() {
121124
HurtingListener hl = new HurtingListener();
122125
hl.onFishing(e);
123126
// Verify
124-
verify(notifier).notify(user, "protection.protected");
127+
verify(notifier, Mockito.atLeastOnce()).notify(user, "protection.protected");
125128
}
126129

127130
/**
@@ -185,7 +188,7 @@ public void testOnFishingDisallowMonsterCatching() {
185188
HurtingListener hl = new HurtingListener();
186189
hl.onFishing(e);
187190
// Verify
188-
verify(notifier).notify(user, "protection.protected");
191+
verify(notifier, Mockito.atLeastOnce()).notify(user, "protection.protected");
189192
}
190193

191194
/**

src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobSpawnListenerTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,6 @@ public void tearDown() {
149149
Mockito.framework().clearInlineMocks();
150150
}
151151

152-
@Test
153-
public void testNotLoaded() {
154-
when(plugin.isLoaded()).thenReturn(false);
155-
CreatureSpawnEvent e = new CreatureSpawnEvent(livingEntity, SpawnReason.NATURAL);
156-
MobSpawnListener l = new MobSpawnListener();
157-
l.onMobSpawn(e);
158-
assertFalse(e.isCancelled());
159-
}
160-
161152
@Test
162153
public void testNotInWorld() {
163154
when(iwm.inWorld(any(Location.class))).thenReturn(false);

0 commit comments

Comments
 (0)