mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-07 12:58:02 +02:00
Added a few methods in ServerCompatibility
This commit is contained in:
parent
bf08475a4f
commit
cfdd0c728a
@ -31,8 +31,8 @@ public class BentoBoxVersionCommand extends CompositeCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
ServerCompatibility.ServerSoftware serverSoftware = ServerCompatibility.getInstance().getServerSoftware(getPlugin().getServer());
|
ServerCompatibility.ServerSoftware serverSoftware = ServerCompatibility.getInstance().getServerSoftware();
|
||||||
ServerCompatibility.ServerVersion serverVersion = ServerCompatibility.getInstance().getServerVersion(getPlugin().getServer());
|
ServerCompatibility.ServerVersion serverVersion = ServerCompatibility.getInstance().getServerVersion();
|
||||||
|
|
||||||
user.sendMessage("commands.bentobox.version.server",
|
user.sendMessage("commands.bentobox.version.server",
|
||||||
TextVariables.NAME, serverSoftware != null ? serverSoftware.toString() : user.getTranslation("general.invalid"),
|
TextVariables.NAME, serverSoftware != null ? serverSoftware.toString() : user.getTranslation("general.invalid"),
|
||||||
|
@ -205,9 +205,9 @@ public class ManagementPanel {
|
|||||||
builder.item(6, reloadItem);
|
builder.item(6, reloadItem);
|
||||||
|
|
||||||
// BentoBox state icon
|
// BentoBox state icon
|
||||||
ServerCompatibility.Compatibility compatibility = ServerCompatibility.getInstance().checkCompatibility(BentoBox.getInstance());
|
ServerCompatibility.Compatibility compatibility = ServerCompatibility.getInstance().checkCompatibility();
|
||||||
ServerCompatibility.ServerSoftware serverSoftware = ServerCompatibility.getInstance().getServerSoftware(BentoBox.getInstance().getServer());
|
ServerCompatibility.ServerSoftware serverSoftware = ServerCompatibility.getInstance().getServerSoftware();
|
||||||
ServerCompatibility.ServerVersion serverVersion = ServerCompatibility.getInstance().getServerVersion(BentoBox.getInstance().getServer());
|
ServerCompatibility.ServerVersion serverVersion = ServerCompatibility.getInstance().getServerVersion();
|
||||||
|
|
||||||
PanelItemBuilder compatibilityItemBuilder = new PanelItemBuilder()
|
PanelItemBuilder compatibilityItemBuilder = new PanelItemBuilder()
|
||||||
.name(user.getTranslation(LOCALE_REF + "information.state.name"))
|
.name(user.getTranslation(LOCALE_REF + "information.state.name"))
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package world.bentobox.bentobox.versions;
|
package world.bentobox.bentobox.versions;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks and ensures the current server software is compatible with BentoBox.
|
* Checks and ensures the current server software is compatible with BentoBox.
|
||||||
* @author Poslovitch
|
* @author Poslovitch
|
||||||
@ -120,13 +117,12 @@ public class ServerCompatibility {
|
|||||||
/**
|
/**
|
||||||
* Checks the compatibility with the current server software and returns the {@link Compatibility}.
|
* Checks the compatibility with the current server software and returns the {@link Compatibility}.
|
||||||
* Note this is a one-time calculation: further calls won't change the result.
|
* Note this is a one-time calculation: further calls won't change the result.
|
||||||
* @param plugin BentoBox instance to provide.
|
|
||||||
* @return the {@link Compatibility}.
|
* @return the {@link Compatibility}.
|
||||||
*/
|
*/
|
||||||
public Compatibility checkCompatibility(BentoBox plugin) {
|
public Compatibility checkCompatibility() {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
// Check the server version first
|
// Check the server version first
|
||||||
ServerVersion version = getServerVersion(Bukkit.getServer());
|
ServerVersion version = getServerVersion();
|
||||||
|
|
||||||
if (version == null || version.getCompatibility().equals(Compatibility.INCOMPATIBLE)) {
|
if (version == null || version.getCompatibility().equals(Compatibility.INCOMPATIBLE)) {
|
||||||
// 'Version = null' means that it's not listed. And therefore, it's implicitly incompatible.
|
// 'Version = null' means that it's not listed. And therefore, it's implicitly incompatible.
|
||||||
@ -135,7 +131,7 @@ public class ServerCompatibility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now, check the server software
|
// Now, check the server software
|
||||||
ServerSoftware software = getServerSoftware(Bukkit.getServer());
|
ServerSoftware software = getServerSoftware();
|
||||||
|
|
||||||
if (software == null || software.getCompatibility().equals(Compatibility.INCOMPATIBLE)) {
|
if (software == null || software.getCompatibility().equals(Compatibility.INCOMPATIBLE)) {
|
||||||
// 'software = null' means that it's not listed. And therefore, it's implicitly incompatible.
|
// 'software = null' means that it's not listed. And therefore, it's implicitly incompatible.
|
||||||
@ -163,13 +159,12 @@ public class ServerCompatibility {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link ServerSoftware} entry corresponding to the current server software, may be null.
|
* Returns the {@link ServerSoftware} entry corresponding to the current server software, may be null.
|
||||||
* @param server the {@link Server} instance, must not be null.
|
|
||||||
* @return the {@link ServerSoftware} run by this server or null.
|
* @return the {@link ServerSoftware} run by this server or null.
|
||||||
* @since 1.3.0
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public ServerSoftware getServerSoftware(@NonNull Server server) {
|
public ServerSoftware getServerSoftware() {
|
||||||
String serverSoftware = server.getVersion().substring(4).split("-")[0];
|
String serverSoftware = Bukkit.getServer().getVersion().substring(4).split("-")[0];
|
||||||
try {
|
try {
|
||||||
return ServerSoftware.valueOf(serverSoftware.toUpperCase());
|
return ServerSoftware.valueOf(serverSoftware.toUpperCase());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -179,17 +174,36 @@ public class ServerCompatibility {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link ServerVersion} entry corresponding to the current server software, may be null.
|
* Returns the {@link ServerVersion} entry corresponding to the current server software, may be null.
|
||||||
* @param server the {@link Server} instance, must not be null.
|
|
||||||
* @return the {@link ServerVersion} run by this server or null.
|
* @return the {@link ServerVersion} run by this server or null.
|
||||||
* @since 1.3.0
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public ServerVersion getServerVersion(@NonNull Server server) {
|
public ServerVersion getServerVersion() {
|
||||||
String serverVersion = server.getBukkitVersion().split("-")[0].replace(".", "_");
|
String serverVersion = Bukkit.getServer().getBukkitVersion().split("-")[0].replace(".", "_");
|
||||||
try {
|
try {
|
||||||
return ServerVersion.valueOf("V" + serverVersion.toUpperCase());
|
return ServerVersion.valueOf("V" + serverVersion.toUpperCase());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the server runs on the specified version.
|
||||||
|
* @param version the {@link ServerVersion} to check.
|
||||||
|
* @return {@code true} if the server runs on this version, {@code false} otherwise.
|
||||||
|
* @since 1.5.0
|
||||||
|
*/
|
||||||
|
public boolean isVersion(@NonNull ServerVersion version) {
|
||||||
|
return version.equals(getServerVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the server runs on the specified software.
|
||||||
|
* @param software the {@link ServerSoftware} to check.
|
||||||
|
* @return {@code true} if the server runs on this software, {@code false} otherwise.
|
||||||
|
* @since 1.5.0
|
||||||
|
*/
|
||||||
|
public boolean isSoftware(@NonNull ServerSoftware software) {
|
||||||
|
return software.equals(getServerSoftware());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user