Merge remote-tracking branch 'origin/develop' into async-paste2

This commit is contained in:
tastybento 2019-01-01 12:47:57 -08:00
commit d039bf0c10
6 changed files with 185 additions and 24 deletions

View File

@ -32,6 +32,7 @@ import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.managers.SchemsManager; import world.bentobox.bentobox.managers.SchemsManager;
import world.bentobox.bentobox.util.heads.HeadGetter; import world.bentobox.bentobox.util.heads.HeadGetter;
import world.bentobox.bentobox.versions.ServerCompatibility;
/** /**
* Main BentoBox class * Main BentoBox class
@ -67,6 +68,18 @@ public class BentoBox extends JavaPlugin {
@Override @Override
public void onEnable(){ public void onEnable(){
if (!ServerCompatibility.getInstance().checkCompatibility(this).isCanLaunch()) {
// The server's most likely incompatible.
// For safety reasons, we must stop BentoBox from loading.
getServer().getLogger().severe("Aborting BentoBox enabling.");
getServer().getLogger().severe("BentoBox cannot be loaded on this server.");
getServer().getLogger().severe("You must be using a compatible server software and run on a version supported by BentoBox.");
getServer().getPluginManager().disablePlugin(this);
return;
}
// Not loaded // Not loaded
isLoaded = false; isLoaded = false;
// Store the current millis time so we can tell how many ms it took for BSB to fully load. // Store the current millis time so we can tell how many ms it took for BSB to fully load.
@ -163,7 +176,7 @@ public class BentoBox extends JavaPlugin {
instance.log(instance.getDescription().getFullName() + " has been fully enabled."); instance.log(instance.getDescription().getFullName() + " has been fully enabled.");
instance.log("It took: " + (System.currentTimeMillis() - startMillis + "ms")); instance.log("It took: " + (System.currentTimeMillis() - startMillis + "ms"));
instance.log("Thanks for using our plugin !"); instance.log("Thanks for using our plugin !");
instance.log("- Tastybento and Poslovitch, 2017-2018"); instance.log("- Tastybento and Poslovitch, 2017-2019");
instance.log("#############################################"); instance.log("#############################################");
}); });
} }

View File

@ -14,7 +14,7 @@ import world.bentobox.bentobox.managers.RanksManager;
/** /**
* All the plugin settings are here * All the plugin settings are here
* @author Tastybento * @author tastybento
*/ */
@StoreAt(filename="config.yml") // Explicitly call out what name this should have. @StoreAt(filename="config.yml") // Explicitly call out what name this should have.
@ConfigComment("BentoBox Configuration [version]") @ConfigComment("BentoBox Configuration [version]")
@ -43,15 +43,10 @@ public class Settings implements DataObject {
@ConfigEntry(path = "general.use-economy") @ConfigEntry(path = "general.use-economy")
private boolean useEconomy = true; private boolean useEconomy = true;
@ConfigComment("Starting money - this is how much money new players will have as their")
@ConfigComment("balance at the start of an island.")
@ConfigEntry(path = "general.starting-money")
private double startingMoney = 10.0;
// Database // Database
@ConfigComment("YAML, JSON, MYSQL, MONGODB.") @ConfigComment("YAML, JSON, MYSQL, MONGODB.")
@ConfigComment("YAML and JSON are both file-based databases.") @ConfigComment("YAML and JSON are both file-based databases.")
@ConfigComment("if you use MONGODB, you must also run the BSBMongo plugin (not addon).") @ConfigComment("If you use MONGODB, you must also run the BSBMongo plugin (not addon).")
@ConfigComment("See https://github.com/tastybento/bsbMongo/releases/.") @ConfigComment("See https://github.com/tastybento/bsbMongo/releases/.")
@ConfigEntry(path = "general.database.type") @ConfigEntry(path = "general.database.type")
private DatabaseType databaseType = DatabaseType.YAML; private DatabaseType databaseType = DatabaseType.YAML;
@ -186,14 +181,6 @@ public class Settings implements DataObject {
this.useEconomy = useEconomy; this.useEconomy = useEconomy;
} }
public double getStartingMoney() {
return startingMoney;
}
public void setStartingMoney(double startingMoney) {
this.startingMoney = startingMoney;
}
public DatabaseType getDatabaseType() { public DatabaseType getDatabaseType() {
return databaseType; return databaseType;
} }

View File

@ -28,7 +28,7 @@ public class BentoBoxAboutCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
user.sendRawMessage("About " + BentoBox.getInstance().getDescription().getName() + " v" + BentoBox.getInstance().getDescription().getVersion() + ":"); user.sendRawMessage("About " + BentoBox.getInstance().getDescription().getName() + " v" + BentoBox.getInstance().getDescription().getVersion() + ":");
user.sendRawMessage("Copyright (c) 2017 - 2018 Tastybento, Poslovitch"); user.sendRawMessage("Copyright (c) 2017 - 2019 Tastybento, Poslovitch");
user.sendRawMessage("See https://www.eclipse.org/legal/epl-2.0/ for license information."); user.sendRawMessage("See https://www.eclipse.org/legal/epl-2.0/ for license information.");
return true; return true;
} }

View File

@ -0,0 +1,164 @@
package world.bentobox.bentobox.versions;
import world.bentobox.bentobox.BentoBox;
/**
* Checks and ensures the current server software is compatible with BentoBox.
* @author Poslovitch
*/
public class ServerCompatibility {
// ---- SINGLETON ----
private static ServerCompatibility instance = new ServerCompatibility();
public static ServerCompatibility getInstance() {
return instance;
}
private ServerCompatibility() { }
// ---- CONTENT ----
private Compatibility result;
public enum Compatibility {
/**
* The server software is compatible with the current version of BentoBox.
* There shouldn't be any issues.
*/
COMPATIBLE(true),
/**
* The server software might not be compatible but is supported.
* Issues might occur.
*/
SUPPORTED(true),
/**
* The server software is not supported, even though BentoBox may work fine.
* Issues are likely and won't receive any support.
*/
NOT_SUPPORTED(true),
/**
* The server software is explicitly not supported and incompatible.
* BentoBox won't run on it: that's pointless to try to run it.
*/
INCOMPATIBLE(false);
private boolean canLaunch;
Compatibility(boolean canLaunch) {
this.canLaunch = canLaunch;
}
public boolean isCanLaunch() {
return canLaunch;
}
}
/**
* Provides a list of server software.
* Any software that is not listed here is implicitly considered as "INCOMPATIBLE".
*/
public enum ServerSoftware {
CRAFTBUKKIT(Compatibility.INCOMPATIBLE),
BUKKIT(Compatibility.INCOMPATIBLE),
SPIGOT(Compatibility.COMPATIBLE),
PAPER(Compatibility.NOT_SUPPORTED),
TACOSPIGOT(Compatibility.NOT_SUPPORTED);
private Compatibility compatibility;
ServerSoftware(Compatibility compatibility) {
this.compatibility = compatibility;
}
public Compatibility getCompatibility() {
return compatibility;
}
}
/**
* Provides a list of server versions.
* Any version that is not listed here is implicitly considered as "INCOMPATIBLE".
*/
public enum ServerVersion {
V1_13(Compatibility.NOT_SUPPORTED),
V1_13_1(Compatibility.NOT_SUPPORTED),
V1_13_2(Compatibility.COMPATIBLE);
private Compatibility compatibility;
ServerVersion(Compatibility compatibility) {
this.compatibility = compatibility;
}
public Compatibility getCompatibility() {
return compatibility;
}
@Override
public String toString() {
return super.toString().substring(1).replace("_", ".");
}
}
/**
* 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.
* @param plugin BentoBox instance to provide.
* @return the {@link Compatibility}.
*/
public Compatibility checkCompatibility(BentoBox plugin) {
if (result == null) {
// Check the server version first
ServerVersion version = getServerVersion(plugin.getServer().getBukkitVersion());
if (version == null || version.getCompatibility().equals(Compatibility.INCOMPATIBLE)) {
// 'Version = null' means that it's not listed. And therefore, it's implicitly incompatible.
return result = Compatibility.INCOMPATIBLE;
}
// Now, check the server software
ServerSoftware software = getServerSoftware(plugin.getServer().getVersion());
if (software == null || software.getCompatibility().equals(Compatibility.INCOMPATIBLE)) {
// 'software = null' means that it's not listed. And therefore, it's implicitly incompatible.
return result = Compatibility.INCOMPATIBLE;
}
if (software.getCompatibility().equals(Compatibility.NOT_SUPPORTED) || version.getCompatibility().equals(Compatibility.NOT_SUPPORTED)) {
return result = Compatibility.NOT_SUPPORTED;
}
if (software.getCompatibility().equals(Compatibility.SUPPORTED) || version.getCompatibility().equals(Compatibility.SUPPORTED)) {
return result = Compatibility.SUPPORTED;
}
// Nothing's wrong, the server is compatible.
return result = Compatibility.COMPATIBLE;
}
return result;
}
private ServerSoftware getServerSoftware(String server) {
try {
String serverSoftware = server.substring(4).split("-")[0];
return ServerSoftware.valueOf(serverSoftware.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
}
private ServerVersion getServerVersion(String bukkitVersion) {
try {
String serverVersion = bukkitVersion.split("-")[0].replace(".", "_");
return ServerVersion.valueOf("V" + serverVersion.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
}
}

View File

@ -1,4 +1,4 @@
# BentoBox Configuration 0.12.0-SNAPSHOT # BentoBox Configuration 1.0-SNAPSHOT
# This config file is dynamic and saved when the server is shutdown. # This config file is dynamic and saved when the server is shutdown.
# You cannot edit it while the server is running because changes will # You cannot edit it while the server is running because changes will
# be lost! Use in-game settings GUI or edit when server is offline. # be lost! Use in-game settings GUI or edit when server is offline.
@ -14,13 +14,10 @@ general:
# Use economy or not. If true, an economy plugin is required. If false, no money is used or give. # Use economy or not. If true, an economy plugin is required. If false, no money is used or give.
# If there is no economy plugin present anyway, money will be automatically disabled. # If there is no economy plugin present anyway, money will be automatically disabled.
use-economy: true use-economy: true
# Starting money - this is how much money new players will have as their
# balance at the start of an island.
starting-money: 10.0
database: database:
# YAML, JSON, MYSQL, MONGODB. # YAML, JSON, MYSQL, MONGODB.
# YAML and JSON are both file-based databases. # YAML and JSON are both file-based databases.
# if you use MONGODB, you must also run the BSBMongo plugin (not addon). # If you use MONGODB, you must also run the BSBMongo plugin (not addon).
# See https://github.com/tastybento/bsbMongo/releases/. # See https://github.com/tastybento/bsbMongo/releases/.
type: YAML type: YAML
host: localhost host: localhost
@ -37,7 +34,7 @@ general:
# Add other fake player names here if required # Add other fake player names here if required
# /!\ This feature is experimental and might not work as expected or might not work at all. # /!\ This feature is experimental and might not work as expected or might not work at all.
fakeplayers: fakeplayers:
- '[CoFH]' - '[CoFH]'
# Allow obsidian to be scooped up with an empty bucket back into lava # Allow obsidian to be scooped up with an empty bucket back into lava
# This only works if there is a single block of obsidian (no obsidian within 10 blocks) # This only works if there is a single block of obsidian (no obsidian within 10 blocks)
# Recommendation is to keep this true so that newbies don't bother you or reset their # Recommendation is to keep this true so that newbies don't bother you or reset their