Skip to content

Commit 5da0b5c

Browse files
authored
Merge pull request #2752 from BentoBoxWorld/develop
Release 3.9.1
2 parents 7c60a11 + e7df26c commit 5da0b5c

File tree

8 files changed

+90
-39
lines changed

8 files changed

+90
-39
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.0</build.version>
78+
<build.version>3.9.1</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/listeners/flags/protection/BlockInteractionListener.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import world.bentobox.bentobox.api.flags.FlagListener;
2323
import world.bentobox.bentobox.database.objects.Island;
2424
import world.bentobox.bentobox.lists.Flags;
25+
import world.bentobox.bentobox.util.Util;
2526

2627
/**
2728
* Handle interaction with blocks
@@ -246,18 +247,20 @@ private boolean checkSpecialCases(Event e, Player player, Block block) {
246247
this.checkIsland(e, player, loc, Flags.FLOWER_POT);
247248
return true;
248249
}
249-
// Prevent animation of copper golems. Use break blocks for now. This could potentiall have it's own flag in the future.
250-
if (Tag.COPPER_GOLEM_STATUES.isTagged(type)) {
251-
this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
252-
return true;
250+
if (Util.isVersionAtLeast("1.21.10")) {
251+
// Prevent animation of copper golems. Use break blocks for now. This could potentiall have it's own flag in the future.
252+
if (Tag.COPPER_GOLEM_STATUES.isTagged(type)) {
253+
this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
254+
return true;
255+
}
256+
257+
// There are various types of copper chests
258+
if (Tag.COPPER_CHESTS.isTagged(type)) {
259+
this.checkIsland(e, player, loc, Flags.CHEST);
260+
return true;
261+
}
253262
}
254263

255-
// There are various types of copper chests
256-
if (Tag.COPPER_CHESTS.isTagged(type)) {
257-
this.checkIsland(e, player, loc, Flags.CHEST);
258-
return true;
259-
}
260-
261264
if (block.getState() instanceof BrushableBlock && BlockInteractionListener.holds(player, Material.BRUSH)) {
262265
// Protect this using break blocks flag for now. Maybe in the future it can have its own flag.
263266
this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);

src/main/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.bukkit.event.player.PlayerInteractEntityEvent;
1717
import org.bukkit.event.player.PlayerInteractEvent;
1818

19+
import com.google.common.base.Enums;
20+
1921
import world.bentobox.bentobox.api.flags.FlagListener;
2022
import world.bentobox.bentobox.lists.Flags;
2123

@@ -131,7 +133,7 @@ public void onPlayerInteract(final PlayerInteractEvent e)
131133
e.getMaterial() == Material.ITEM_FRAME ||
132134
e.getMaterial() == Material.GLOW_ITEM_FRAME ||
133135
e.getMaterial() == Material.CHEST ||
134-
e.getMaterial() == Material.COPPER_CHEST ||
136+
e.getMaterial() == Enums.getIfPresent(Material.class, "COPPER_CHEST").or(Material.CHEST) ||
135137
e.getMaterial() == Material.TRAPPED_CHEST)
136138
{
137139
this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.PLACE_BLOCKS);

src/main/java/world/bentobox/bentobox/listeners/flags/settings/MobSpawnListener.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,29 @@ void onMobSpawn(CreatureSpawnEvent e)
104104

105105
switch (e.getSpawnReason())
106106
{
107-
// Natural
108-
case DEFAULT, DROWNED, JOCKEY, LIGHTNING, MOUNT, NATURAL, NETHER_PORTAL, OCELOT_BABY, PATROL,
109-
RAID, REINFORCEMENTS, SILVERFISH_BLOCK, TRAP, VILLAGE_DEFENSE, VILLAGE_INVASION ->
110-
{
111-
boolean cancelNatural = this.shouldCancel(e.getEntity(),
107+
// Natural
108+
case DEFAULT, DROWNED, JOCKEY, LIGHTNING, MOUNT, NATURAL, NETHER_PORTAL, OCELOT_BABY, PATROL,
109+
RAID, REINFORCEMENTS, SILVERFISH_BLOCK, TRAP, VILLAGE_DEFENSE, VILLAGE_INVASION ->
110+
{
111+
boolean cancelNatural = this.shouldCancel(e.getEntity(),
112112
e.getLocation(),
113113
Flags.ANIMAL_NATURAL_SPAWN,
114114
Flags.MONSTER_NATURAL_SPAWN);
115-
e.setCancelled(cancelNatural);
116-
}
117-
// Spawners
118-
case SPAWNER ->
119-
{
120-
boolean cancelSpawners = this.shouldCancel(e.getEntity(),
115+
e.setCancelled(cancelNatural);
116+
}
117+
// Spawners
118+
case SPAWNER, TRIAL_SPAWNER ->
119+
{
120+
boolean cancelSpawners = this.shouldCancel(e.getEntity(),
121121
e.getLocation(),
122122
Flags.ANIMAL_SPAWNERS_SPAWN,
123123
Flags.MONSTER_SPAWNERS_SPAWN);
124-
e.setCancelled(cancelSpawners);
125-
}
126-
default -> {
127-
// Nothing to do
128-
}
124+
e.setCancelled(cancelSpawners);
125+
}
126+
default ->
127+
{
128+
// Nothing to do
129+
}
129130
}
130131
}
131132

src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/ChestDamageListener.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import world.bentobox.bentobox.api.flags.FlagListener;
1010
import world.bentobox.bentobox.lists.Flags;
11+
import world.bentobox.bentobox.util.Util;
1112

1213
/**
1314
* @author tastybento
@@ -24,10 +25,17 @@ public void onExplosion(final EntityExplodeEvent e)
2425
if (getIWM().inWorld(e.getLocation()) && !Flags.CHEST_DAMAGE.isSetForWorld(e.getLocation().getWorld()))
2526
{
2627
e.blockList().removeIf(b -> b.getType().equals(Material.CHEST) ||
27-
Tag.COPPER_CHESTS.isTagged(b.getType()) ||
28-
b.getType().equals(Material.TRAPPED_CHEST) ||
29-
Tag.SHULKER_BOXES.isTagged(b.getType()));
30-
28+
isCopperChest(b.getType()) ||
29+
b.getType().equals(Material.TRAPPED_CHEST) ||
30+
Tag.SHULKER_BOXES.isTagged(b.getType()));
31+
32+
}
33+
}
34+
35+
private boolean isCopperChest(Material m) {
36+
if (Util.isVersionAtLeast("1.21.10")) {
37+
return Tag.COPPER_CHESTS.isTagged(m);
3138
}
39+
return false;
3240
}
3341
}

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public class Util {
7373

7474
private static final String NETHER = "_nether";
7575
private static final String THE_END = "_the_end";
76+
77+
private static final String SERVER_VERSION = Bukkit.getMinecraftVersion();
7678
private static String serverVersion = null;
7779
private static BentoBox plugin = BentoBox.getInstance();
7880
private static PasteHandler pasteHandler = null;
@@ -363,10 +365,15 @@ public static boolean isPassiveEntity(Entity entity) {
363365
// Fishes, Dolphin and Squid extends WaterMob | Excludes PufferFish
364366
// Bat extends Mob
365367
// Most of passive mobs extends Animals
366-
368+
boolean copperGolem = false;
369+
try {
370+
copperGolem = entity instanceof CopperGolem;
371+
} catch (Exception ex) {
372+
copperGolem = false;
373+
}
367374
return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
368375
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat ||
369-
entity instanceof Allay || entity instanceof CopperGolem;
376+
entity instanceof Allay || copperGolem;
370377
}
371378

372379
public static boolean isTamableEntity(Entity entity) {
@@ -744,15 +751,15 @@ public static void resetHealth(Player player) {
744751
public static void setRegenerator(WorldRegenerator regenerator) {
745752
Util.regenerator = regenerator;
746753
}
747-
754+
748755
private static Pair<String, String> getPrefix() {
749756
// Bukkit method that was added in 2011
750757
// Example value: 1.20.4-R0.1-SNAPSHOT
751758
final String bukkitVersion = "v" + Bukkit.getBukkitVersion().replace('.', '_').replace('-', '_');
752759
final String pluginPackageName = plugin.getClass().getPackage().getName();
753760
return new Pair<String, String>(pluginPackageName + ".nms." + bukkitVersion, bukkitVersion);
754761
}
755-
762+
756763
/**
757764
* Generic method to get NMS handlers with fallback options
758765
* @param <T> The type of handler to get
@@ -771,7 +778,7 @@ private static <T> T getNMSHandler(Class<T> handlerClass,
771778
if (existingHandler != null) {
772779
return existingHandler;
773780
}
774-
781+
775782
T handler;
776783
try {
777784
Class<?> clazz = Class.forName(getPrefix().x() + "." + implName);
@@ -786,7 +793,7 @@ private static <T> T getNMSHandler(Class<T> handlerClass,
786793
}
787794
return handler;
788795
}
789-
796+
790797
/**
791798
* Get metadata decoder
792799
* @return an accelerated metadata class for this server
@@ -909,5 +916,30 @@ public static boolean inTest() {
909916
public static String stripColor(String input) {
910917
return input.replaceAll("(?i)§[0-9A-FK-ORX]", ""); // Use regex because it's fast and reliable
911918
}
912-
919+
920+
/**
921+
* Simple utility method to check if the server version is at least the target version.
922+
*/
923+
public static boolean isVersionAtLeast(String targetVersion) {
924+
// Simple string comparison may be sufficient for minor versions,
925+
// but a proper numeric check is safer for major releases.
926+
try {
927+
// Get major, minor, patch versions
928+
String[] currentParts = SERVER_VERSION.split("\\.");
929+
String[] targetParts = targetVersion.split("\\.");
930+
931+
for (int i = 0; i < targetParts.length; i++) {
932+
int current = (i < currentParts.length) ? Integer.parseInt(currentParts[i]) : 0;
933+
int target = Integer.parseInt(targetParts[i]);
934+
935+
if (current > target) return true;
936+
if (current < target) return false;
937+
}
938+
// All parts checked are equal (e.g., 1.21.9 vs 1.21.9)
939+
return true;
940+
} catch (NumberFormatException e) {
941+
// Fallback for non-standard version strings
942+
return SERVER_VERSION.startsWith(targetVersion);
943+
}
944+
}
913945
}

src/test/java/world/bentobox/bentobox/AbstractCommonSetup.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public void setUp() throws Exception {
116116
server = ServerMocks.newServer();
117117
// Bukkit
118118
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
119+
// Version
120+
when(Bukkit.getMinecraftVersion()).thenReturn("1.21.10");
119121
// Set up plugin
120122
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
121123

src/test/java/world/bentobox/bentobox/listeners/PanelListenerManagerTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.junit.runner.RunWith;
3838
import org.mockito.Mock;
3939
import org.mockito.Mockito;
40+
import org.powermock.api.mockito.PowerMockito;
4041
import org.powermock.core.classloader.annotations.PrepareForTest;
4142
import org.powermock.modules.junit4.PowerMockRunner;
4243
import org.powermock.reflect.Whitebox;
@@ -85,6 +86,8 @@ public class PanelListenerManagerTest {
8586
@SuppressWarnings("deprecation")
8687
@Before
8788
public void setUp() throws Exception {
89+
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
90+
when(Bukkit.getMinecraftVersion()).thenReturn("1.21.10");
8891
// Set up plugin
8992
BentoBox plugin = mock(BentoBox.class);
9093
Whitebox.setInternalState(BentoBox.class, "instance", plugin);

0 commit comments

Comments
 (0)