use of me.wiefferink.areashop.interfaces.WorldGuardInterface in project AreaShop by NLthijs48.
the class AreaShop method onEnable.
/**
* Called on start or reload of the server.
*/
public void onEnable() {
AreaShop.instance = this;
Do.init(this);
managers = new HashSet<>();
boolean error = false;
// Check if WorldGuard is present
String wgVersion = null;
String rawVersion = null;
int major = 0;
int minor = 0;
int fixes = 0;
Integer build = null;
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin == null || !(plugin instanceof WorldGuardPlugin) || !plugin.isEnabled()) {
error("WorldGuard plugin is not present or has not loaded correctly");
error = true;
} else {
worldGuard = (WorldGuardPlugin) plugin;
// Get correct WorldGuardInterface (handles things that changed version to version)
try {
rawVersion = worldGuard.getDescription().getVersion();
if (rawVersion.contains("-SNAPSHOT;")) {
String buildNumber = rawVersion.substring(rawVersion.indexOf("-SNAPSHOT;") + 10, rawVersion.length());
if (buildNumber.contains("-")) {
buildNumber = buildNumber.substring(0, buildNumber.indexOf("-"));
try {
build = Integer.parseInt(buildNumber);
} catch (NumberFormatException e) {
warn("Could not correctly parse the build of WorldGuard, raw version: " + rawVersion + ", buildNumber: " + buildNumber);
}
}
}
// Clear stuff from the version string that is not a number
String[] versionParts = rawVersion.split("\\.");
for (int i = 0; i < versionParts.length; i++) {
Pattern pattern = Pattern.compile("^\\d+");
Matcher matcher = pattern.matcher(versionParts[i]);
if (matcher.find()) {
versionParts[i] = matcher.group();
}
}
// Find major, minor and fix numbers
try {
if (versionParts.length > 0) {
major = Integer.parseInt(versionParts[0]);
}
if (versionParts.length > 1) {
minor = Integer.parseInt(versionParts[1]);
}
if (versionParts.length > 2) {
fixes = Integer.parseInt(versionParts[2]);
}
} catch (NumberFormatException e) {
warn("Something went wrong while parsing WorldGuard version number: " + rawVersion);
}
// Determine correct implementation to use
if (worldGuard.getDescription().getVersion().startsWith("5.")) {
wgVersion = "5";
} else if (major == 6 && minor == 1 && fixes < 3) {
wgVersion = "6";
} else {
if (build != null && build == 1672) {
error = true;
error("Build 1672 of WorldGuard is broken, update to a later build or a stable version!");
} else if (build != null && build < 1672) {
wgVersion = "6";
} else {
wgVersion = "6_1_3";
}
}
} catch (Exception e) {
// If version detection fails, at least try to load the latest version
wgVersion = "6_1_3";
}
// Load chosen implementation
try {
final Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers.WorldGuardHandler" + wgVersion);
// Check if we have a NMSHandler class at that location.
if (WorldGuardInterface.class.isAssignableFrom(clazz)) {
// Make sure it actually implements WorldGuardInterface
// Set our handler
worldGuardInterface = (WorldGuardInterface) clazz.getConstructor(AreaShopInterface.class).newInstance(this);
}
} catch (final Exception e) {
error("Could not load the handler for WorldGuard (tried to load " + wgVersion + "), report this problem to the author:" + ExceptionUtils.getStackTrace(e));
error = true;
wgVersion = null;
}
}
// Check if WorldEdit is present
String weVersion = null;
plugin = getServer().getPluginManager().getPlugin("WorldEdit");
if (plugin == null || !(plugin instanceof WorldEditPlugin) || !plugin.isEnabled()) {
error("WorldEdit plugin is not present or has not loaded correctly");
error = true;
} else {
worldEdit = (WorldEditPlugin) plugin;
// Get correct WorldEditInterface (handles things that changed version to version)
if (worldEdit.getDescription().getVersion().startsWith("5.")) {
weVersion = "5";
} else {
weVersion = "6";
}
try {
final Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers.WorldEditHandler" + weVersion);
// Check if we have a NMSHandler class at that location.
if (WorldEditInterface.class.isAssignableFrom(clazz)) {
// Make sure it actually implements WorldEditInterface
// Set our handler
worldEditInterface = (WorldEditInterface) clazz.getConstructor(AreaShopInterface.class).newInstance(this);
}
} catch (final Exception e) {
error("Could not load the handler for WorldEdit (tried to load " + weVersion + "), report this problem to the author: " + ExceptionUtils.getStackTrace(e));
error = true;
weVersion = null;
}
}
// Check if Vault is present
if (getServer().getPluginManager().getPlugin("Vault") == null) {
error("Vault plugin is not present or has not loaded correctly");
error = true;
}
// Load all data from files and check versions
fileManager = new FileManager();
managers.add(fileManager);
error = error | !fileManager.loadFiles(false);
// Print loaded version of WG and WE in debug
if (wgVersion != null) {
AreaShop.debug("Loaded WorldGuardHandler" + wgVersion + " (raw version: " + rawVersion + ", major:" + major + ", minor:" + minor + ", fixes:" + fixes + ", build:" + build + ")");
}
if (weVersion != null) {
AreaShop.debug("Loaded WorldEditHandler" + weVersion);
}
setupLanguageManager();
if (error) {
error("The plugin has not started, fix the errors listed above");
} else {
featureManager = new FeatureManager();
managers.add(featureManager);
// Register the event listeners
getServer().getPluginManager().registerEvents(new PlayerLoginLogoutListener(this), this);
setupTasks();
// Startup the CommandManager (registers itself for the command)
commandManager = new CommandManager();
managers.add(commandManager);
// Create a signLinkerManager
signLinkerManager = new SignLinkerManager();
managers.add(signLinkerManager);
// Enable Metrics if config allows it
if (getConfig().getBoolean("sendStats")) {
Analytics.start();
}
// Register dynamic permission (things declared in config)
registerDynamicPermissions();
// Don't initialize the updatechecker if disabled in the config
if (getConfig().getBoolean("checkForUpdates")) {
githubUpdateCheck = new GithubUpdateCheck(AreaShop.getInstance(), "NLThijs48", "AreaShop").withVersionComparator((latestVersion, currentVersion) -> !cleanVersion(latestVersion).equals(cleanVersion(currentVersion))).checkUpdate((result) -> {
AreaShop.debug("Update check result:", result);
if (!result.hasUpdate()) {
return;
}
AreaShop.info("Update from AreaShop V" + cleanVersion(result.getCurrentVersion()) + " to AreaShop V" + cleanVersion(result.getLatestVersion()) + " available, get the latest version at https://www.spigotmc.org/resources/areashop.2991/");
for (Player player : Utils.getOnlinePlayers()) {
notifyUpdate(player);
}
});
}
}
}
Aggregations