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.0</build.version>
<build.version>3.9.1</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 @@ -22,6 +22,7 @@
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.util.Util;

/**
* Handle interaction with blocks
Expand Down Expand Up @@ -246,18 +247,20 @@ private boolean checkSpecialCases(Event e, Player player, Block block) {
this.checkIsland(e, player, loc, Flags.FLOWER_POT);
return true;
}
// Prevent animation of copper golems. Use break blocks for now. This could potentiall have it's own flag in the future.
if (Tag.COPPER_GOLEM_STATUES.isTagged(type)) {
this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
return true;
if (Util.isVersionAtLeast("1.21.10")) {
// Prevent animation of copper golems. Use break blocks for now. This could potentiall have it's own flag in the future.
if (Tag.COPPER_GOLEM_STATUES.isTagged(type)) {
this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
return true;
}

// There are various types of copper chests
if (Tag.COPPER_CHESTS.isTagged(type)) {
this.checkIsland(e, player, loc, Flags.CHEST);
return true;
}
}

// There are various types of copper chests
if (Tag.COPPER_CHESTS.isTagged(type)) {
this.checkIsland(e, player, loc, Flags.CHEST);
return true;
}

if (block.getState() instanceof BrushableBlock && BlockInteractionListener.holds(player, Material.BRUSH)) {
// Protect this using break blocks flag for now. Maybe in the future it can have its own flag.
this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;

import com.google.common.base.Enums;

import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;

Expand Down Expand Up @@ -131,7 +133,7 @@ public void onPlayerInteract(final PlayerInteractEvent e)
e.getMaterial() == Material.ITEM_FRAME ||
e.getMaterial() == Material.GLOW_ITEM_FRAME ||
e.getMaterial() == Material.CHEST ||
e.getMaterial() == Material.COPPER_CHEST ||
e.getMaterial() == Enums.getIfPresent(Material.class, "COPPER_CHEST").or(Material.CHEST) ||
e.getMaterial() == Material.TRAPPED_CHEST)
{
this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.PLACE_BLOCKS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.util.Util;

/**
* @author tastybento
Expand All @@ -24,10 +25,17 @@ public void onExplosion(final EntityExplodeEvent e)
if (getIWM().inWorld(e.getLocation()) && !Flags.CHEST_DAMAGE.isSetForWorld(e.getLocation().getWorld()))
{
e.blockList().removeIf(b -> b.getType().equals(Material.CHEST) ||
Tag.COPPER_CHESTS.isTagged(b.getType()) ||
b.getType().equals(Material.TRAPPED_CHEST) ||
Tag.SHULKER_BOXES.isTagged(b.getType()));

isCopperChest(b.getType()) ||
b.getType().equals(Material.TRAPPED_CHEST) ||
Tag.SHULKER_BOXES.isTagged(b.getType()));

}
}

private boolean isCopperChest(Material m) {
if (Util.isVersionAtLeast("1.21.10")) {
return Tag.COPPER_CHESTS.isTagged(m);
}
return false;
}
}
46 changes: 39 additions & 7 deletions src/main/java/world/bentobox/bentobox/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class Util {

private static final String NETHER = "_nether";
private static final String THE_END = "_the_end";

private static final String SERVER_VERSION = Bukkit.getMinecraftVersion();
private static String serverVersion = null;
private static BentoBox plugin = BentoBox.getInstance();
private static PasteHandler pasteHandler = null;
Expand Down Expand Up @@ -363,10 +365,15 @@ public static boolean isPassiveEntity(Entity entity) {
// 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;
}
return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat ||
entity instanceof Allay || entity instanceof CopperGolem;
entity instanceof Allay || copperGolem;
}

public static boolean isTamableEntity(Entity entity) {
Expand Down Expand Up @@ -744,15 +751,15 @@ public static void resetHealth(Player player) {
public static void setRegenerator(WorldRegenerator regenerator) {
Util.regenerator = regenerator;
}

private static Pair<String, String> getPrefix() {
// Bukkit method that was added in 2011
// Example value: 1.20.4-R0.1-SNAPSHOT
final String bukkitVersion = "v" + Bukkit.getBukkitVersion().replace('.', '_').replace('-', '_');
final String pluginPackageName = plugin.getClass().getPackage().getName();
return new Pair<String, String>(pluginPackageName + ".nms." + bukkitVersion, bukkitVersion);
}

/**
* Generic method to get NMS handlers with fallback options
* @param <T> The type of handler to get
Expand All @@ -771,7 +778,7 @@ private static <T> T getNMSHandler(Class<T> handlerClass,
if (existingHandler != null) {
return existingHandler;
}

T handler;
try {
Class<?> clazz = Class.forName(getPrefix().x() + "." + implName);
Expand All @@ -786,7 +793,7 @@ private static <T> T getNMSHandler(Class<T> handlerClass,
}
return handler;
}

/**
* Get metadata decoder
* @return an accelerated metadata class for this server
Expand Down Expand Up @@ -909,5 +916,30 @@ public static boolean inTest() {
public static String stripColor(String input) {
return input.replaceAll("(?i)§[0-9A-FK-ORX]", ""); // Use regex because it's fast and reliable
}


/**
* Simple utility method to check if the server version is at least the target version.
*/
public static boolean isVersionAtLeast(String targetVersion) {
// Simple string comparison may be sufficient for minor versions,
// but a proper numeric check is safer for major releases.
try {
// Get major, minor, patch versions
String[] currentParts = SERVER_VERSION.split("\\.");
String[] targetParts = targetVersion.split("\\.");

for (int i = 0; i < targetParts.length; i++) {
int current = (i < currentParts.length) ? Integer.parseInt(currentParts[i]) : 0;
int target = Integer.parseInt(targetParts[i]);

if (current > target) return true;
if (current < target) return false;
}
// All parts checked are equal (e.g., 1.21.9 vs 1.21.9)
return true;
} catch (NumberFormatException e) {
// Fallback for non-standard version strings
return SERVER_VERSION.startsWith(targetVersion);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public void setUp() throws Exception {
server = ServerMocks.newServer();
// Bukkit
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Version
when(Bukkit.getMinecraftVersion()).thenReturn("1.21.10");
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
Expand Down Expand Up @@ -85,6 +86,8 @@ public class PanelListenerManagerTest {
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
when(Bukkit.getMinecraftVersion()).thenReturn("1.21.10");
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down