Skip to content

Commit

Permalink
Uses Bukkit version method instead of class names (#2370)
Browse files Browse the repository at this point in the history
* Uses Bukkit version method instead of class names

See https://forums.papermc.io/threads/important-dev-psa-future-removal-of-cb-package-relocation.1106/

* Fix tests

* Fix server compatibility reporting issue with Paper

* Remove unused import
  • Loading branch information
tastybento committed May 19, 2024
1 parent 2fc3396 commit d701b7e
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public class BentoBox extends JavaPlugin implements Listener {

@Override
public void onEnable(){
setInstance(this);

if (!ServerCompatibility.getInstance().checkCompatibility().isCanLaunch()) {
// The server's most likely incompatible.
// Show a warning
Expand All @@ -125,7 +127,6 @@ public void onEnable(){

// Save the default config from config.yml
saveDefaultConfig();
setInstance(this);
// Load Flags
flagsManager = new FlagsManager(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public boolean addIsland(@NonNull Island island) {
* associated per world.
*/
public void addPlayer(@NonNull UUID uuid, @NonNull Island island) {
islandsByUUID.computeIfAbsent(uuid, k -> new HashSet<>()).add(island.getUniqueId());
this.islandsById.put(island.getUniqueId(), island);
this.islandsByUUID.computeIfAbsent(uuid, k -> new HashSet<>()).add(island.getUniqueId());
}

/**
Expand Down Expand Up @@ -181,6 +182,7 @@ public void deleteIslandFromCache(@NonNull String uniqueId) {
public Island get(@NonNull World world, @NonNull UUID uuid) {
List<Island> islands = getIslands(world, uuid);
if (islands.isEmpty()) {
System.out.println("empty");
return null;
}
for (Island island : islands) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package world.bentobox.bentobox.nms.v1_20_R1;
package world.bentobox.bentobox.nms.v1_20_0_R0_1_SNAPSHOT;

import java.util.concurrent.CompletableFuture;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package world.bentobox.bentobox.nms.v1_20_R1;
package world.bentobox.bentobox.nms.v1_20_0_R0_1_SNAPSHOT;

import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package world.bentobox.bentobox.nms.v1_20_R2;
package world.bentobox.bentobox.nms.v1_20_1_R0_1_SNAPSHOT;

import java.util.concurrent.CompletableFuture;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package world.bentobox.bentobox.nms.v1_20_R2;
package world.bentobox.bentobox.nms.v1_20_1_R0_1_SNAPSHOT;

import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package world.bentobox.bentobox.nms.v1_20_R3;
package world.bentobox.bentobox.nms.v1_20_4_R0_1_SNAPSHOT;

import java.util.concurrent.CompletableFuture;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package world.bentobox.bentobox.nms.v1_20_R3;
package world.bentobox.bentobox.nms.v1_20_4_R0_1_SNAPSHOT;

import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package world.bentobox.bentobox.nms.v1_20_R4;
package world.bentobox.bentobox.nms.v1_20_6_R0_1_SNAPSHOT;

import java.util.concurrent.CompletableFuture;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package world.bentobox.bentobox.nms.v1_20_R4;
package world.bentobox.bentobox.nms.v1_20_6_R0_1_SNAPSHOT;

import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_20_R4.CraftWorld;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/world/bentobox/bentobox/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -719,19 +719,21 @@ public static void setRegenerator(WorldRegenerator regenerator) {
*/
public static WorldRegenerator getRegenerator() {
if (regenerator == null) {
String serverPackageName = Bukkit.getServer().getClass().getPackage().getName();

// Bukkit method that was added in 2011
// Example value: 1.20.4-R0.1-SNAPSHOT
String bukkitVersion = "v" + Bukkit.getServer().getBukkitVersion().replace('.', '_').replace('-', '_');
String pluginPackageName = plugin.getClass().getPackage().getName();
String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1);
WorldRegenerator handler;
try {
Class<?> clazz = Class.forName(pluginPackageName + ".nms." + version + ".WorldRegeneratorImpl");
Class<?> clazz = Class.forName(pluginPackageName + ".nms." + bukkitVersion + ".WorldRegeneratorImpl");
if (WorldRegenerator.class.isAssignableFrom(clazz)) {
handler = (WorldRegenerator) clazz.getConstructor().newInstance();
} else {
throw new IllegalStateException("Class " + clazz.getName() + " does not implement WorldRegenerator");
}
} catch (Exception e) {
plugin.logWarning("No Regenerator found for " + version + ", falling back to Bukkit API.");
plugin.logWarning("No Regenerator found for " + bukkitVersion + ", falling back to Bukkit API.");
handler = new world.bentobox.bentobox.nms.fallback.WorldRegeneratorImpl();
}
setRegenerator(handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.bentobox.util.Util;

/**
* Checks and ensures the current server software is compatible with BentoBox.
* @author Poslovitch
Expand Down Expand Up @@ -281,7 +283,6 @@ public Compatibility checkCompatibility() {
if (result == null) {
// Check the server version first
ServerVersion version = getServerVersion();

if (version == null || version.getCompatibility().equals(Compatibility.INCOMPATIBLE)) {
// 'Version = null' means that it's not listed. And therefore, it's implicitly incompatible.
result = Compatibility.INCOMPATIBLE;
Expand Down Expand Up @@ -323,9 +324,12 @@ public Compatibility checkCompatibility() {
*/
@NonNull
public ServerSoftware getServerSoftware() {
String[] parts = Bukkit.getServer().getVersion().split("-");
if (Util.isPaper()) {
return ServerSoftware.PAPER;
}
String[] parts = Bukkit.getServer().getBukkitVersion().split("-");
if (parts.length < 2) {
return ServerSoftware.UNKNOWN.setName(Bukkit.getServer().getVersion().toUpperCase(Locale.ENGLISH));
return ServerSoftware.UNKNOWN.setName(Bukkit.getServer().getBukkitVersion().toUpperCase(Locale.ENGLISH));
}
String serverSoftware = Bukkit.getServer().getVersion().split("-")[1];
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void setUp() throws Exception {
when(Bukkit.getPluginManager()).thenReturn(pim);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getScheduler()).thenReturn(scheduler);
when(server.getBukkitVersion()).thenReturn("1.20.6-R0.2-SNAPSHOT");

// Clear any remaining database
deleteAll(new File("database"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void setUp() throws Exception {

// Island
when(island.getWorld()).thenReturn(world);
when(island.getUniqueId()).thenReturn("uniqueId");
@NonNull
String uniqueId = UUID.randomUUID().toString();
when(island.getUniqueId()).thenReturn(uniqueId);
Expand Down

0 comments on commit d701b7e

Please sign in to comment.