diff --git a/build.gradle b/build.gradle
index 3fe80e8..c65ab46 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,6 @@
plugins {
id 'java'
+ id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
@@ -39,4 +40,13 @@ shadowJar {
relocate 'org.bstats.bukkit', packagePath + '.dependencies.bstats'
}
+checkstyle {
+ toolVersion "8.25"
+ configFile = rootProject.file('config/checkstyle/checkstyle.xml')
+
+ ignoreFailures = false
+ maxErrors = 0
+ maxWarnings = 0
+}
+
build.dependsOn shadowJar
\ No newline at end of file
diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml
new file mode 100644
index 0000000..0395a5d
--- /dev/null
+++ b/config/checkstyle/checkstyle.xml
@@ -0,0 +1,268 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/net/frankheijden/serverutils/ServerUtils.java b/src/main/java/net/frankheijden/serverutils/ServerUtils.java
index c8bbb25..9397661 100644
--- a/src/main/java/net/frankheijden/serverutils/ServerUtils.java
+++ b/src/main/java/net/frankheijden/serverutils/ServerUtils.java
@@ -1,26 +1,32 @@
package net.frankheijden.serverutils;
+import co.aikar.commands.BukkitCommandCompletionContext;
+import co.aikar.commands.CommandCompletions;
import co.aikar.commands.PaperCommandManager;
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
import net.frankheijden.serverutils.commands.CommandPlugins;
import net.frankheijden.serverutils.commands.CommandServerUtils;
import net.frankheijden.serverutils.config.Config;
import net.frankheijden.serverutils.config.Messenger;
import net.frankheijden.serverutils.listeners.MainListener;
import net.frankheijden.serverutils.managers.VersionManager;
-import net.frankheijden.serverutils.reflection.*;
+import net.frankheijden.serverutils.reflection.RCommandMap;
+import net.frankheijden.serverutils.reflection.RCraftServer;
import net.frankheijden.serverutils.tasks.UpdateCheckerTask;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
-import org.bukkit.command.*;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
import org.bukkit.command.defaults.PluginsCommand;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.util.*;
-import java.util.stream.Collectors;
-
public class ServerUtils extends JavaPlugin implements CommandExecutor {
private static final int BSTATS_METRICS_ID = 7790;
@@ -44,14 +50,11 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
commandManager.registerCommand(new CommandServerUtils());
this.commandPlugins = null;
- commandManager.getCommandCompletions().registerAsyncCompletion("plugins", context -> Arrays.stream(Bukkit.getPluginManager().getPlugins())
- .map(Plugin::getName)
- .collect(Collectors.toList()));
- commandManager.getCommandCompletions().registerAsyncCompletion("pluginJars", context -> Arrays.stream(getJars())
- .map(File::getName)
- .collect(Collectors.toList()));
- commandManager.getCommandCompletions().registerAsyncCompletion("supportedConfigs", context -> CommandServerUtils.getSupportedConfigs());
- commandManager.getCommandCompletions().registerAsyncCompletion("commands", context -> {
+ CommandCompletions completions = commandManager.getCommandCompletions();
+ completions.registerAsyncCompletion("plugins", context -> getPluginNames());
+ completions.registerAsyncCompletion("pluginJars", context -> getPluginFileNames());
+ completions.registerAsyncCompletion("supportedConfigs", context -> CommandServerUtils.getSupportedConfigs());
+ completions.registerAsyncCompletion("commands", context -> {
try {
return RCommandMap.getKnownCommands(RCraftServer.getCommandMap()).keySet();
} catch (IllegalAccessException | InvocationTargetException ex) {
@@ -73,6 +76,18 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
restoreBukkitPluginCommand();
}
+ private List getPluginNames() {
+ return Arrays.stream(Bukkit.getPluginManager().getPlugins())
+ .map(Plugin::getName)
+ .collect(Collectors.toList());
+ }
+
+ private List getPluginFileNames() {
+ return Arrays.stream(getJars())
+ .map(File::getName)
+ .collect(Collectors.toList());
+ }
+
private void removeCommands(String... commands) {
Map map;
try {
@@ -91,6 +106,10 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
RCraftServer.getCommandMap().register("bukkit", new PluginsCommand("plugins"));
}
+ /**
+ * Reloads the configurations of the plugin.
+ * Also makes sure the bukkit /pl command gets restored.
+ */
public void reload() {
if (commandPlugins != null) {
commandManager.unregisterCommand(commandPlugins);
diff --git a/src/main/java/net/frankheijden/serverutils/commands/CommandPlugins.java b/src/main/java/net/frankheijden/serverutils/commands/CommandPlugins.java
index b5c9a6c..02e4f16 100644
--- a/src/main/java/net/frankheijden/serverutils/commands/CommandPlugins.java
+++ b/src/main/java/net/frankheijden/serverutils/commands/CommandPlugins.java
@@ -1,7 +1,14 @@
package net.frankheijden.serverutils.commands;
import co.aikar.commands.BaseCommand;
-import co.aikar.commands.annotation.*;
+import co.aikar.commands.annotation.CommandAlias;
+import co.aikar.commands.annotation.CommandPermission;
+import co.aikar.commands.annotation.Default;
+import co.aikar.commands.annotation.Description;
+import co.aikar.commands.annotation.Subcommand;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
import net.frankheijden.serverutils.config.Messenger;
import net.frankheijden.serverutils.utils.ListBuilder;
import net.frankheijden.serverutils.utils.ListFormat;
@@ -9,11 +16,13 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
-import java.util.*;
-
@CommandAlias("plugins|pl")
public class CommandPlugins extends BaseCommand {
+ /**
+ * Sends the plugin list to the sender, without plugin version.
+ * @param sender The sender of the command.
+ */
@Default
@CommandPermission("serverutils.plugins")
@Description("Shows the plugins of this server.")
@@ -24,13 +33,18 @@ public class CommandPlugins extends BaseCommand {
});
}
+ /**
+ * Sends the plugin list to the sender, with plugin version.
+ * @param sender The sender of the command.
+ */
@Subcommand("-v")
@CommandPermission("serverutils.plugins.version")
@Description("Shows the plugins of this server with version.")
public void onPluginsWithVersion(CommandSender sender) {
sendPlugins(sender, pl -> {
String format = "serverutils.plugins.format" + (pl.isEnabled() ? "" : "_disabled");
- String version = Messenger.getMessage("serverutils.plugins.version", "%version%", pl.getDescription().getVersion());
+ String version = Messenger.getMessage("serverutils.plugins.version",
+ "%version%", pl.getDescription().getVersion());
return Messenger.getMessage(format, "%plugin%", pl.getName()) + version;
});
}
diff --git a/src/main/java/net/frankheijden/serverutils/commands/CommandServerUtils.java b/src/main/java/net/frankheijden/serverutils/commands/CommandServerUtils.java
index d6daff7..c460475 100644
--- a/src/main/java/net/frankheijden/serverutils/commands/CommandServerUtils.java
+++ b/src/main/java/net/frankheijden/serverutils/commands/CommandServerUtils.java
@@ -1,27 +1,46 @@
package net.frankheijden.serverutils.commands;
-import co.aikar.commands.BaseCommand;
-import co.aikar.commands.annotation.*;
-import net.frankheijden.serverutils.ServerUtils;
-import net.frankheijden.serverutils.config.Messenger;
-import net.frankheijden.serverutils.managers.*;
-import net.frankheijden.serverutils.reflection.*;
-import net.frankheijden.serverutils.utils.*;
-import org.bukkit.Bukkit;
-import org.bukkit.command.*;
-import org.bukkit.plugin.Plugin;
-import org.bukkit.plugin.PluginDescriptionFile;
-
-import java.util.*;
-
import static net.frankheijden.serverutils.config.Messenger.sendMessage;
import static net.frankheijden.serverutils.reflection.ReflectionUtils.MINOR;
+import co.aikar.commands.BaseCommand;
+import co.aikar.commands.annotation.CommandAlias;
+import co.aikar.commands.annotation.CommandCompletion;
+import co.aikar.commands.annotation.CommandPermission;
+import co.aikar.commands.annotation.Default;
+import co.aikar.commands.annotation.Dependency;
+import co.aikar.commands.annotation.Description;
+import co.aikar.commands.annotation.Subcommand;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import net.frankheijden.serverutils.ServerUtils;
+import net.frankheijden.serverutils.config.Messenger;
+import net.frankheijden.serverutils.managers.LoadResult;
+import net.frankheijden.serverutils.managers.PluginManager;
+import net.frankheijden.serverutils.managers.Result;
+import net.frankheijden.serverutils.reflection.RCraftServer;
+import net.frankheijden.serverutils.utils.FormatBuilder;
+import net.frankheijden.serverutils.utils.ForwardFilter;
+import net.frankheijden.serverutils.utils.ListBuilder;
+import net.frankheijden.serverutils.utils.ListFormat;
+import net.frankheijden.serverutils.utils.ReloadHandler;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.PluginIdentifiableCommand;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginDescriptionFile;
+
@CommandAlias("serverutils|su")
public class CommandServerUtils extends BaseCommand {
private static final Set ALIASES;
private static final Map supportedConfigs;
+
static {
ALIASES = new HashSet<>();
ALIASES.add("serverutils");
@@ -31,7 +50,7 @@ public class CommandServerUtils extends BaseCommand {
supportedConfigs.put("bukkit", RCraftServer::reloadBukkitConfiguration);
supportedConfigs.put("commands.yml", RCraftServer::reloadCommandsConfiguration);
supportedConfigs.put("server-icon.png", RCraftServer::loadIcon);
- supportedConfigs.put("banned-ips.json", RCraftServer::reloadIPBans);
+ supportedConfigs.put("banned-ips.json", RCraftServer::reloadIpBans);
supportedConfigs.put("banned-players.json", RCraftServer::reloadProfileBans);
}
@@ -42,6 +61,10 @@ public class CommandServerUtils extends BaseCommand {
return supportedConfigs.keySet();
}
+ /**
+ * Shows the help page to the sender.
+ * @param sender The sender of the command.
+ */
@Default
@Subcommand("help")
@CommandPermission("serverutils.help")
@@ -59,11 +82,15 @@ public class CommandServerUtils extends BaseCommand {
if (cmd.getPrefSubCommand().isEmpty()) return;
builder.add(rootCommand.getCommandName(), " " + cmd.getPrefSubCommand(), cmd.getHelpText());
});
- });
+ });
builder.sendTo(sender);
Messenger.sendMessage(sender, "serverutils.help.footer");
}
+ /**
+ * Reloads the configurations of ServerUtils.
+ * @param sender The sender of the command.
+ */
@Subcommand("reload")
@CommandPermission("serverutils.reload")
@Description("Reloads the ServerUtils plugin.")
@@ -74,6 +101,11 @@ public class CommandServerUtils extends BaseCommand {
"%what%", "ServerUtils configurations");
}
+ /**
+ * Reloads a config from a set of configurations of the server.
+ * @param sender The sender of the command.
+ * @param config The configuration to reload.
+ */
@Subcommand("reloadconfig")
@CommandCompletion("@supportedConfigs")
@CommandPermission("serverutils.reloadconfig")
@@ -103,6 +135,11 @@ public class CommandServerUtils extends BaseCommand {
}
}
+ /**
+ * Loads the specified plugin on the server.
+ * @param sender The sender of the command.
+ * @param jarFile The filename of the plugin in the plugins/ directory.
+ */
@Subcommand("loadplugin")
@CommandCompletion("@pluginJars")
@CommandPermission("serverutils.loadplugin")
@@ -118,6 +155,11 @@ public class CommandServerUtils extends BaseCommand {
result.sendTo(sender, "load", jarFile);
}
+ /**
+ * Unloads the specified plugin from the server.
+ * @param sender The sender of the command.
+ * @param pluginName The plugin name.
+ */
@Subcommand("unloadplugin")
@CommandCompletion("@plugins")
@CommandPermission("serverutils.unloadplugin")
@@ -133,6 +175,11 @@ public class CommandServerUtils extends BaseCommand {
unloadResult.sendTo(sender, "unload", pluginName);
}
+ /**
+ * Reloads the specified plugin on the server.
+ * @param sender The sender of the command.
+ * @param pluginName The plugin name.
+ */
@Subcommand("reloadplugin")
@CommandCompletion("@plugins")
@CommandPermission("serverutils.reloadplugin")
@@ -142,6 +189,11 @@ public class CommandServerUtils extends BaseCommand {
result.sendTo(sender, "reload", pluginName);
}
+ /**
+ * Enables the specified plugin on the server.
+ * @param sender The sender of the command.
+ * @param pluginName The plugin name.
+ */
@Subcommand("enableplugin")
@CommandCompletion("@plugins")
@CommandPermission("serverutils.enableplugin")
@@ -151,6 +203,11 @@ public class CommandServerUtils extends BaseCommand {
result.sendTo(sender, "enabl", pluginName);
}
+ /**
+ * Disables the specified plugin on the server.
+ * @param sender The sender of the command.
+ * @param pluginName The plugin name.
+ */
@Subcommand("disableplugin")
@CommandCompletion("@plugins")
@CommandPermission("serverutils.disableplugin")
@@ -160,6 +217,11 @@ public class CommandServerUtils extends BaseCommand {
result.sendTo(sender, "disabl", pluginName);
}
+ /**
+ * Shows information about the specified plugin.
+ * @param sender The sender of the command.
+ * @param pluginName The plugin name.
+ */
@Subcommand("plugininfo")
@CommandCompletion("@plugins")
@CommandPermission("serverutils.plugininfo")
@@ -186,7 +248,7 @@ public class CommandServerUtils extends BaseCommand {
.add("Name", plugin.getName())
.add("Full Name", description.getFullName())
.add("Version", description.getVersion());
- if (MINOR >= 13) builder.add( "API Version", description.getAPIVersion());
+ if (MINOR >= 13) builder.add("API Version", description.getAPIVersion());
builder.add("Website", description.getWebsite())
.add("Authors", ListBuilder.create(description.getAuthors())
.format(listFormat)
@@ -222,6 +284,11 @@ public class CommandServerUtils extends BaseCommand {
Messenger.sendMessage(sender, "serverutils.plugininfo.footer");
}
+ /**
+ * Shows information about a provided command.
+ * @param sender The sender of the command.
+ * @param command The command to lookup.
+ */
@Subcommand("commandinfo")
@CommandCompletion("@commands")
@CommandPermission("serverutils.commandinfo")
diff --git a/src/main/java/net/frankheijden/serverutils/config/Config.java b/src/main/java/net/frankheijden/serverutils/config/Config.java
index b4adf84..7af4a81 100644
--- a/src/main/java/net/frankheijden/serverutils/config/Config.java
+++ b/src/main/java/net/frankheijden/serverutils/config/Config.java
@@ -1,39 +1,21 @@
package net.frankheijden.serverutils.config;
-import net.frankheijden.serverutils.ServerUtils;
-import org.bukkit.configuration.file.YamlConfiguration;
-
import java.io.File;
-public class Config {
+public class Config extends YamlResource {
- private static Defaults DEFAULT_CONFIG = Defaults.of(
- "settings", Defaults.of(
- "disable-plugins-command", false,
- "check-updates", true,
- "download-updates", false,
- "download-at-startup-and-update", false
- )
- );
-
- private static final ServerUtils plugin = ServerUtils.getInstance();
private static Config instance;
- private final YamlConfiguration config;
public Config(File file) {
+ super(file, "config.yml");
instance = this;
- config = Defaults.init(file, DEFAULT_CONFIG);
}
public static Config getInstance() {
return instance;
}
- public YamlConfiguration getConfig() {
- return config;
- }
-
public boolean getBoolean(String path) {
- return config.getBoolean(path, (boolean) DEFAULT_CONFIG.get(path));
+ return getConfiguration().getBoolean(path);
}
}
diff --git a/src/main/java/net/frankheijden/serverutils/config/Defaults.java b/src/main/java/net/frankheijden/serverutils/config/Defaults.java
deleted file mode 100644
index b640d67..0000000
--- a/src/main/java/net/frankheijden/serverutils/config/Defaults.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package net.frankheijden.serverutils.config;
-
-import org.bukkit.configuration.file.YamlConfiguration;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public class Defaults {
-
- private final Map rootMap;
-
- private Defaults(Object... objects) {
- this.rootMap = new LinkedHashMap<>();
- for (int i = 0; i < objects.length; i += 2) {
- this.rootMap.put(String.valueOf(objects[i]), objects[i + 1]);
- }
- }
-
- public static Defaults of(Object... objects) {
- return new Defaults(objects);
- }
-
- public static void addDefaults(Defaults defaults, YamlConfiguration yml) {
- addDefaults(defaults, yml, "");
- }
-
- private static void addDefaults(Defaults defaults, YamlConfiguration yml, String root) {
- for (Map.Entry entry : defaults.rootMap.entrySet()) {
- String key = (root.isEmpty() ? "" : root + ".") + entry.getKey();
- Object value = entry.getValue();
- if (value instanceof Defaults) {
- addDefaults((Defaults) value, yml, key);
- } else if (yml.get(key) == null) {
- yml.set(key, value);
- }
- }
- }
-
- public Object get(String path) {
- return get(this, path);
- }
-
- private Object get(Defaults defaults, String path) {
- String[] split = path.split("\\.");
- if (split.length > 1) {
- return get((Defaults) defaults.rootMap.get(split[0]), path.substring(split[0].length() + 1));
- }
- return defaults.rootMap.get(split[0]);
- }
-
- public static YamlConfiguration init(File file, Defaults defaults) {
- YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
- Defaults.addDefaults(defaults, yml);
-
- try {
- // Idk somehow the order messes up
- // of the messages if we don't do this
- file.delete();
- file.createNewFile();
-
- yml.save(file);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- return yml;
- }
-}
diff --git a/src/main/java/net/frankheijden/serverutils/config/Messenger.java b/src/main/java/net/frankheijden/serverutils/config/Messenger.java
index 57fe9a6..ddce16d 100644
--- a/src/main/java/net/frankheijden/serverutils/config/Messenger.java
+++ b/src/main/java/net/frankheijden/serverutils/config/Messenger.java
@@ -1,88 +1,29 @@
package net.frankheijden.serverutils.config;
+import java.io.File;
+
import net.frankheijden.serverutils.ServerUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
-import org.bukkit.configuration.file.YamlConfiguration;
-import java.io.File;
-
-public class Messenger {
-
- private static final Defaults DEFAULT_MESSAGES = Defaults.of(
- "serverutils", Defaults.of(
- "success", "&3Successfully %action%ed &b%what%&3!",
- "warning", "&3Successfully %action%ed &b%what%&3, but with warnings.",
- "error", "&cAn error occurred while %action%ing &4%what%&c, please check the console!",
- "not_exists", "&cAn error occurred while %action%ing &4%what%&c, plugin does not exist!",
- "not_enabled", "&cAn error occurred while %action%ing &4%what%&c, plugin is not enabled!",
- "already_loaded", "&cAn error occurred while %action%ing &4%what%&c, plugin is already loaded!",
- "already_enabled", "&cAn error occurred while %action%ing &4%what%&c, plugin is already enabled!",
- "already_disabled", "&cAn error occurred while %action%ing &4%what%&c, plugin is already disabled!",
- "file_changed", "&cAccessing the jar file while %action%ing &4%what%&c went wrong, please load the plugin manually!",
- "invalid_description", "&cAn error occurred while %action%ing &4%what%&c, plugin doesn't have a valid description!",
- "invalid_plugin", "&cAn error occurred while %action%ing &4%what%&c, plugin is invalid!",
- "unknown_dependency", "&cAn error occurred while %action%ing &4%what%&c, plugin has a dependeny which is not loaded: &4%arg%",
- "update", Defaults.of(
- "available", "&8&m------------=&r&8[ &b&lServerUtils Update&r &8]&m=--------------\n"
- + " &3Current version: &b%old%\n"
- + " &3New version: &b%new%\n"
- + " &3Release info: &b%info%\n"
- + "&8&m-------------------------------------------------",
- "downloading", "&8&m------------=&r&8[ &b&lServerUtils Update&r &8]&m=--------------\n"
- + " &3A new version of ServerUtils will be downloaded and installed after a restart!\n"
- + " &3Current version: &b%old%\n"
- + " &3New version: &b%new%\n"
- + " &3Release info: &b%info%\n"
- + "&8&m-------------------------------------------------",
- "download_failed", "&cFailed to download version %new% of ServerUtils. Please update manually.",
- "download_success", "&3ServerUtils has been downloaded and will be installed on the next restart."
- ),
- "help", Defaults.of(
- "header", "&8&m-------------=&r&8[ &b&lServerUtils Help&r &8]&m=---------------",
- "format", "&8/&3%command%&b%subcommand% &f(&7%help%&f)",
- "footer", "&8&m-------------------------------------------------"
- ),
- "plugins", Defaults.of(
- "header", "&8&m------------=&r&8[ &b&lServerUtils Plugins&r &8]&m=-------------",
- "format", "&3%plugin%",
- "format_disabled", "&c%plugin%",
- "seperator", "&b, ",
- "last_seperator", " &band ",
- "version", " &8(&a%version%&8)",
- "footer", "&8&m-------------------------------------------------"
- ),
- "plugininfo", Defaults.of(
- "header", "&8&m-----------=&r&8[ &b&lServerUtils PluginInfo&r &8]&m=-----------",
- "format", " &3%key%&8: &b%value%",
- "list_format", "&b%value%",
- "seperator", "&8, ",
- "last_seperator", " &8and ",
- "footer", "&8&m-------------------------------------------------"
- ),
- "commandinfo", Defaults.of(
- "header", "&8&m-----------=&r&8[ &b&lServerUtils CommandInfo&r &8]&m=----------",
- "format", " &3%key%&8: &b%value%",
- "list_format", "&b%value%",
- "seperator", "&8, ",
- "last_seperator", " &8and ",
- "footer", "&8&m-------------------------------------------------",
- "not_exists", "&cThat command is not a valid registered command."
- )
- )
- );
+public class Messenger extends YamlResource {
private static final ServerUtils plugin = ServerUtils.getInstance();
private static Messenger instance;
- private final YamlConfiguration messages;
public Messenger(File file) {
+ super(file, "messages.yml");
instance = this;
- messages = Defaults.init(file, DEFAULT_MESSAGES);
}
+ /**
+ * Retrieves a message from the config.
+ * @param path The yml path to the message.
+ * @param replacements The replacements to be taken into account.
+ * @return The config message with translated placeholders.
+ */
public static String getMessage(String path, String... replacements) {
- String message = instance.messages.getString(path);
+ String message = instance.getConfiguration().getString(path);
if (message != null) {
return apply(message, replacements);
} else {
@@ -91,6 +32,13 @@ public class Messenger {
return null;
}
+ /**
+ * Applies placeholders to a message.
+ * @param message The message.
+ * @param replacements The replacements of the message. Expects input to be even and in a key-value like format.
+ * Example: ["%player%", "Player"]
+ * @return The message with translated placeholders.
+ */
public static String apply(String message, String... replacements) {
if (message == null || message.isEmpty()) return null;
for (int i = 0; i < replacements.length; i++, i++) {
@@ -99,6 +47,12 @@ public class Messenger {
return message;
}
+ /**
+ * Sends a message to a player with translated placeholders.
+ * @param sender The receiver.
+ * @param msg The message to be sent.
+ * @param replacements The replacements to be taken into account.
+ */
public static void sendRawMessage(CommandSender sender, String msg, String... replacements) {
String message = apply(msg, replacements);
if (message != null) {
@@ -106,6 +60,12 @@ public class Messenger {
}
}
+ /**
+ * Sends a message from the specified config path to a player with translated placeholders.
+ * @param sender The receiver.
+ * @param path The yml path to the message.
+ * @param replacements The replacements to be taken into account.
+ */
public static void sendMessage(CommandSender sender, String path, String... replacements) {
String message = getMessage(path, replacements);
if (message != null) {
diff --git a/src/main/java/net/frankheijden/serverutils/config/YamlResource.java b/src/main/java/net/frankheijden/serverutils/config/YamlResource.java
new file mode 100644
index 0000000..0716f24
--- /dev/null
+++ b/src/main/java/net/frankheijden/serverutils/config/YamlResource.java
@@ -0,0 +1,32 @@
+package net.frankheijden.serverutils.config;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import net.frankheijden.serverutils.ServerUtils;
+import net.frankheijden.serverutils.utils.YamlUtils;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+public abstract class YamlResource {
+
+ private static final ServerUtils plugin = ServerUtils.getInstance();
+
+ private final YamlConfiguration configuration;
+
+ /**
+ * Creates a new YamlResource instance.
+ * Loads the resource from the jar file.
+ * @param file The destination file.
+ * @param resource The resource from the jar file.
+ */
+ public YamlResource(File file, String resource) {
+ InputStream is = plugin.getResource(resource);
+ YamlConfiguration def = YamlConfiguration.loadConfiguration(new InputStreamReader(is));
+ configuration = YamlUtils.init(file, def);
+ }
+
+ public YamlConfiguration getConfiguration() {
+ return configuration;
+ }
+}
diff --git a/src/main/java/net/frankheijden/serverutils/listeners/MainListener.java b/src/main/java/net/frankheijden/serverutils/listeners/MainListener.java
index 3c4788b..73db05c 100644
--- a/src/main/java/net/frankheijden/serverutils/listeners/MainListener.java
+++ b/src/main/java/net/frankheijden/serverutils/listeners/MainListener.java
@@ -3,13 +3,20 @@ package net.frankheijden.serverutils.listeners;
import net.frankheijden.serverutils.config.Config;
import net.frankheijden.serverutils.tasks.UpdateCheckerTask;
import org.bukkit.entity.Player;
-import org.bukkit.event.*;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class MainListener implements Listener {
private static final Config config = Config.getInstance();
+ /**
+ * Called when a player joins the server.
+ * Used for sending an update message to the player, if enabled and has permission.
+ * @param event The PlayerJoinEvent.
+ */
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) {
if (!config.getBoolean("settings.check-updates")) return;
diff --git a/src/main/java/net/frankheijden/serverutils/managers/PluginManager.java b/src/main/java/net/frankheijden/serverutils/managers/PluginManager.java
index 08d6507..c30f46b 100644
--- a/src/main/java/net/frankheijden/serverutils/managers/PluginManager.java
+++ b/src/main/java/net/frankheijden/serverutils/managers/PluginManager.java
@@ -1,23 +1,45 @@
package net.frankheijden.serverutils.managers;
-import net.frankheijden.serverutils.ServerUtils;
-import net.frankheijden.serverutils.reflection.*;
-import org.bukkit.Bukkit;
-import org.bukkit.command.*;
-import org.bukkit.plugin.*;
-
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import net.frankheijden.serverutils.ServerUtils;
+import net.frankheijden.serverutils.reflection.RCommandMap;
+import net.frankheijden.serverutils.reflection.RCraftServer;
+import net.frankheijden.serverutils.reflection.RCraftingManager;
+import net.frankheijden.serverutils.reflection.RJavaPlugin;
+import net.frankheijden.serverutils.reflection.RPlugin;
+import net.frankheijden.serverutils.reflection.RPluginClassLoader;
+import net.frankheijden.serverutils.reflection.RSimplePluginManager;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.PluginCommand;
+import org.bukkit.plugin.InvalidDescriptionException;
+import org.bukkit.plugin.InvalidPluginException;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.plugin.PluginLoader;
+import org.bukkit.plugin.UnknownDependencyException;
+
public class PluginManager {
+ /**
+ * Loads the specified file as a plugin.
+ * @param jarFile The name of the file in the plugins/ folder.
+ * @return The result of the loading procedure.
+ */
public static LoadResult loadPlugin(String jarFile) {
return loadPlugin(new File(ServerUtils.getInstance().getDataFolder().getParent(), jarFile));
}
+ /**
+ * Loads the specified file as a plugin.
+ * @param file The file to be loaded.
+ * @return The result of the loading procedure.
+ */
public static LoadResult loadPlugin(File file) {
if (!file.exists()) return new LoadResult(Result.NOT_EXISTS);
@@ -47,10 +69,20 @@ public class PluginManager {
return new LoadResult(plugin);
}
+ /**
+ * Disables the specified plugin by name and cleans all commands and recipes of the plugin.
+ * @param pluginName The plugin to disable.
+ * @return The result of the disable call.
+ */
public static Result disablePlugin(String pluginName) {
return disablePlugin(Bukkit.getPluginManager().getPlugin(pluginName));
}
+ /**
+ * Disables the specified plugin and cleans all commands and recipes of the plugin.
+ * @param plugin The plugin to disable.
+ * @return The result of the disable call.
+ */
public static Result disablePlugin(Plugin plugin) {
if (plugin == null) return Result.NOT_ENABLED;
if (!plugin.isEnabled()) return Result.ALREADY_DISABLED;
@@ -65,10 +97,20 @@ public class PluginManager {
return Result.SUCCESS;
}
+ /**
+ * Unloads the specified plugin by name and cleans all traces within bukkit.
+ * @param pluginName The plugin to unload.
+ * @return The result of the unload.
+ */
public static Result unloadPlugin(String pluginName) {
return unloadPlugin(Bukkit.getPluginManager().getPlugin(pluginName));
}
+ /**
+ * Unloads the specified plugin and cleans all traces within bukkit.
+ * @param plugin The plugin to unload.
+ * @return The result of the unload.
+ */
public static Result unloadPlugin(Plugin plugin) {
if (plugin == null) return Result.NOT_EXISTS;
try {
@@ -82,10 +124,20 @@ public class PluginManager {
return Result.SUCCESS;
}
+ /**
+ * Enables the specified plugin by name.
+ * @param pluginName The plugin to enable.
+ * @return The result of the enabling.
+ */
public static Result enablePlugin(String pluginName) {
return enablePlugin(Bukkit.getPluginManager().getPlugin(pluginName));
}
+ /**
+ * Enables the specified plugin.
+ * @param plugin The plugin to enable.
+ * @return The result of the enabling.
+ */
public static Result enablePlugin(Plugin plugin) {
if (plugin == null) return Result.NOT_EXISTS;
if (Bukkit.getPluginManager().isPluginEnabled(plugin.getName())) return Result.ALREADY_ENABLED;
@@ -96,12 +148,22 @@ public class PluginManager {
return Result.ERROR;
}
+ /**
+ * Reloads the specified plugin by name.
+ * @param pluginName The plugin to reload.
+ * @return The result of the reload.
+ */
public static Result reloadPlugin(String pluginName) {
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
if (plugin == null) return Result.NOT_EXISTS;
return reloadPlugin(plugin);
}
+ /**
+ * Reloads the specified plugin.
+ * @param plugin The plugin to reload.
+ * @return The result of the reload.
+ */
public static Result reloadPlugin(Plugin plugin) {
Result disableResult = disablePlugin(plugin);
if (disableResult != Result.SUCCESS && disableResult != Result.ALREADY_DISABLED) return disableResult;
@@ -125,6 +187,10 @@ public class PluginManager {
return enablePlugin(loadResult.getPlugin());
}
+ /**
+ * Retrieves all known commands registered to bukkit.
+ * @return A map with all known commands.
+ */
public static Map getKnownCommands() {
try {
return RCommandMap.getKnownCommands(RCraftServer.getCommandMap());
@@ -134,6 +200,10 @@ public class PluginManager {
}
}
+ /**
+ * Unregisters all commands from the specified plugin.
+ * @param plugin The plugin.
+ */
public static void unregisterCommands(Plugin plugin) {
Map knownCommands = getKnownCommands();
if (knownCommands == null) return;
@@ -151,12 +221,21 @@ public class PluginManager {
});
}
+ /**
+ * Retrieves a command from the command map.
+ * @param command The command string.
+ * @return The command.
+ */
public static Command getCommand(String command) {
Map knownCommands = getKnownCommands();
if (knownCommands == null) return null;
return knownCommands.get(command);
}
+ /**
+ * Retrieves all file associations, i.e. all plugin loaders.
+ * @return A map with all pluginloaders.
+ */
public static Map getFileAssociations() {
try {
return RSimplePluginManager.getFileAssociations(Bukkit.getPluginManager());
@@ -166,6 +245,11 @@ public class PluginManager {
}
}
+ /**
+ * Retrieves the PluginLoader for the input file.
+ * @param file The file.
+ * @return The appropiate PluginLoader.
+ */
public static PluginLoader getPluginLoader(File file) {
Map fileAssociations = getFileAssociations();
if (fileAssociations == null) return null;
@@ -179,6 +263,11 @@ public class PluginManager {
return null;
}
+ /**
+ * Retrieves a loaded plugin associated to a jar file.
+ * @param file The jar file.
+ * @return The already loaded plugin, or null if none.
+ */
public static Plugin getLoadedPlugin(File file) {
PluginDescriptionFile descriptionFile;
try {
@@ -190,6 +279,12 @@ public class PluginManager {
return Bukkit.getPluginManager().getPlugin(descriptionFile.getName());
}
+ /**
+ * Retrieves the PluginDescriptionFile of a jar file.
+ * @param file The jar file.
+ * @return The PluginDescriptionFile.
+ * @throws InvalidDescriptionException Iff the PluginDescriptionFile is invalid.
+ */
public static PluginDescriptionFile getPluginDescription(File file) throws InvalidDescriptionException {
PluginLoader loader = getPluginLoader(file);
if (loader == null) return null;
diff --git a/src/main/java/net/frankheijden/serverutils/managers/Result.java b/src/main/java/net/frankheijden/serverutils/managers/Result.java
index c9b7e15..c8a95a0 100644
--- a/src/main/java/net/frankheijden/serverutils/managers/Result.java
+++ b/src/main/java/net/frankheijden/serverutils/managers/Result.java
@@ -27,6 +27,13 @@ public enum Result {
return this;
}
+ /**
+ * Retrieves the associated message of the result
+ * and sends it to a CommandSender.
+ * @param sender The receiver.
+ * @param action The action which let to the result.
+ * @param what An associated variable.
+ */
public void sendTo(CommandSender sender, String action, String what) {
Messenger.sendMessage(sender, "serverutils." + this.name().toLowerCase(),
"%action%", action,
diff --git a/src/main/java/net/frankheijden/serverutils/managers/VersionManager.java b/src/main/java/net/frankheijden/serverutils/managers/VersionManager.java
index d8d844f..e11d5c2 100644
--- a/src/main/java/net/frankheijden/serverutils/managers/VersionManager.java
+++ b/src/main/java/net/frankheijden/serverutils/managers/VersionManager.java
@@ -9,6 +9,10 @@ public class VersionManager {
private final String currentVersion;
private String downloadedVersion;
+ /**
+ * Creates a new VersionManager instance.
+ * Used for automatic updating.
+ */
public VersionManager() {
instance = this;
this.currentVersion = plugin.getDescription().getVersion();
diff --git a/src/main/java/net/frankheijden/serverutils/reflection/RCommandMap.java b/src/main/java/net/frankheijden/serverutils/reflection/RCommandMap.java
index ebe6188..2f649c6 100644
--- a/src/main/java/net/frankheijden/serverutils/reflection/RCommandMap.java
+++ b/src/main/java/net/frankheijden/serverutils/reflection/RCommandMap.java
@@ -1,17 +1,20 @@
package net.frankheijden.serverutils.reflection;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.getDeclaredField;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;
-import java.lang.reflect.*;
-import java.util.Map;
-
-import static net.frankheijden.serverutils.reflection.ReflectionUtils.getDeclaredField;
-
public class RCommandMap {
private static Field knownCommands = null;
private static Method getKnownCommands = null;
+
static {
try {
try {
@@ -25,7 +28,8 @@ public class RCommandMap {
}
@SuppressWarnings("unchecked")
- public static Map getKnownCommands(SimpleCommandMap map) throws IllegalAccessException, InvocationTargetException {
+ public static Map getKnownCommands(SimpleCommandMap map)
+ throws IllegalAccessException, InvocationTargetException {
return (Map) (knownCommands == null ? getKnownCommands.invoke(map) : knownCommands.get(map));
}
}
diff --git a/src/main/java/net/frankheijden/serverutils/reflection/RCraftServer.java b/src/main/java/net/frankheijden/serverutils/reflection/RCraftServer.java
index 4c66ef7..976ce81 100644
--- a/src/main/java/net/frankheijden/serverutils/reflection/RCraftServer.java
+++ b/src/main/java/net/frankheijden/serverutils/reflection/RCraftServer.java
@@ -1,19 +1,31 @@
package net.frankheijden.serverutils.reflection;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.FieldParam.fieldOf;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.MethodParam.methodOf;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.VersionParam.ALL_VERSIONS;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.VersionParam.max;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.VersionParam.min;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.VersionParam.versionOf;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.get;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.getAllFields;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.getAllMethods;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.getDeclaredField;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.getDeclaredMethod;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.invoke;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.set;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+
import org.bukkit.Bukkit;
import org.bukkit.Warning;
-import org.bukkit.command.*;
+import org.bukkit.command.Command;
+import org.bukkit.command.SimpleCommandMap;
import org.bukkit.configuration.file.YamlConfiguration;
-import java.io.File;
-import java.lang.reflect.*;
-import java.util.Map;
-
-import static net.frankheijden.serverutils.reflection.ReflectionUtils.*;
-import static net.frankheijden.serverutils.reflection.ReflectionUtils.FieldParam.fieldOf;
-import static net.frankheijden.serverutils.reflection.ReflectionUtils.MethodParam.methodOf;
-import static net.frankheijden.serverutils.reflection.ReflectionUtils.VersionParam.*;
-
public class RCraftServer {
private static Class> craftServerClass;
@@ -27,10 +39,12 @@ public class RCraftServer {
static {
try {
- craftServerClass = Class.forName(String.format("org.bukkit.craftbukkit.%s.CraftServer", ReflectionUtils.NMS));
+ craftServerClass = Class.forName(String.format("org.bukkit.craftbukkit.%s.CraftServer",
+ ReflectionUtils.NMS));
craftServer = craftServerClass.cast(Bukkit.getServer());
- commandsConfigFile = (File) getDeclaredMethod(craftServerClass, "getCommandsConfigFile").invoke(craftServer);
+ commandsConfigFile = (File) getDeclaredMethod(craftServerClass,
+ "getCommandsConfigFile").invoke(craftServer);
configFile = (File) getDeclaredMethod(craftServerClass, "getConfigFile").invoke(craftServer);
commandMap = (SimpleCommandMap) getDeclaredField(craftServerClass, "commandMap").get(Bukkit.getServer());
@@ -66,6 +80,13 @@ public class RCraftServer {
return configFile;
}
+ /**
+ * Retrieves the options file from a key.
+ * @param option The option key.
+ * @return The associated file.
+ * @throws InvocationTargetException If the method call produced an exception.
+ * @throws IllegalAccessException When prohibited access to the method.
+ */
public static File getOptionsFile(String option) throws IllegalAccessException, InvocationTargetException {
Object console = get(fields, craftServer, "console");
Object options = get(RDedicatedServer.getFields(), console, "options");
@@ -80,7 +101,11 @@ public class RCraftServer {
return commandMap;
}
- public static void reloadBukkitConfiguration() throws Exception {
+ /**
+ * Reloads the bukkit configuration.
+ * @throws ReflectiveOperationException Iff exception thrown regarding reflection.
+ */
+ public static void reloadBukkitConfiguration() throws ReflectiveOperationException {
YamlConfiguration bukkit = YamlConfiguration.loadConfiguration(getConfigFile());
set(fields, craftServer, "configuration", bukkit);
@@ -91,7 +116,8 @@ public class RCraftServer {
set(fields, craftServer, "animalSpawn", bukkit.getInt("spawn-limits.animals"));
set(fields, craftServer, "waterAnimalSpawn", bukkit.getInt("spawn-limits.water-animals"));
set(fields, craftServer, "ambientSpawn", bukkit.getInt("spawn-limits.ambient"));
- set(fields, craftServer, "warningState", Warning.WarningState.value(bukkit.getString("settings.deprecated-verbose")));
+ set(fields, craftServer, "warningState",
+ Warning.WarningState.value(bukkit.getString("settings.deprecated-verbose")));
set(fields, craftServer, "minimumAPI", bukkit.getString("settings.minimum-api"));
set(fields, craftServer, "printSaveWarning", false);
@@ -105,25 +131,43 @@ public class RCraftServer {
invoke(methods, craftServer, "loadIcon");
}
+ /**
+ * Reloads the commands.yml file.
+ * @throws InvocationTargetException If the method call produced an exception.
+ * @throws IllegalAccessException When prohibited access to the method.
+ */
public static void reloadCommandsConfiguration() throws IllegalAccessException, InvocationTargetException {
Map map = RCommandMap.getKnownCommands(commandMap);
Bukkit.getCommandAliases().keySet().forEach(map::remove);
YamlConfiguration commands = YamlConfiguration.loadConfiguration(getCommandsConfigFile());
set(fields, craftServer, "commandsConfiguration", commands);
- set(fields, craftServer, "overrideAllCommandBlockCommands", commands.getStringList("command-block-overrides").contains("*"));
- set(fields, craftServer, "ignoreVanillaPermissions", commands.getBoolean("ignore-vanilla-permissions"));
- set(fields, craftServer, "unrestrictedAdvancements", commands.getBoolean("unrestricted-advancements"));
+ set(fields, craftServer, "overrideAllCommandBlockCommands",
+ commands.getStringList("command-block-overrides").contains("*"));
+ set(fields, craftServer, "ignoreVanillaPermissions",
+ commands.getBoolean("ignore-vanilla-permissions"));
+ set(fields, craftServer, "unrestrictedAdvancements",
+ commands.getBoolean("unrestricted-advancements"));
commandMap.registerServerAliases();
}
- public static void reloadIPBans() throws IllegalAccessException, InvocationTargetException {
+ /**
+ * Reloads the ip-bans file.
+ * @throws InvocationTargetException If the method call produced an exception.
+ * @throws IllegalAccessException When prohibited access to the method.
+ */
+ public static void reloadIpBans() throws IllegalAccessException, InvocationTargetException {
Object playerList = get(fields, craftServer, "playerList");
Object jsonList = invoke(RPlayerList.getMethods(), playerList, "getIPBans");
RJsonList.load(jsonList);
}
+ /**
+ * Reloads the profile bans file.
+ * @throws InvocationTargetException If the method call produced an exception.
+ * @throws IllegalAccessException When prohibited access to the method.
+ */
public static void reloadProfileBans() throws IllegalAccessException, InvocationTargetException {
Object playerList = get(fields, craftServer, "playerList");
Object jsonList = invoke(RPlayerList.getMethods(), playerList, "getProfileBans");
diff --git a/src/main/java/net/frankheijden/serverutils/reflection/RCraftingManager.java b/src/main/java/net/frankheijden/serverutils/reflection/RCraftingManager.java
index 5ba2bf4..61a7fff 100644
--- a/src/main/java/net/frankheijden/serverutils/reflection/RCraftingManager.java
+++ b/src/main/java/net/frankheijden/serverutils/reflection/RCraftingManager.java
@@ -1,16 +1,21 @@
package net.frankheijden.serverutils.reflection;
-import net.frankheijden.serverutils.utils.MapUtils;
-import org.bukkit.plugin.Plugin;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.FieldParam.fieldOf;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.MINOR;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.VersionParam.min;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.get;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.getAllFields;
+import static net.frankheijden.serverutils.reflection.ReflectionUtils.invoke;
-import java.lang.reflect.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Predicate;
-import static net.frankheijden.serverutils.reflection.ReflectionUtils.*;
-import static net.frankheijden.serverutils.reflection.ReflectionUtils.FieldParam.fieldOf;
-import static net.frankheijden.serverutils.reflection.ReflectionUtils.VersionParam.min;
+import net.frankheijden.serverutils.utils.MapUtils;
+import org.bukkit.plugin.Plugin;
public class RCraftingManager {
@@ -19,7 +24,8 @@ public class RCraftingManager {
static {
try {
- craftingManagerClass = Class.forName(String.format("net.minecraft.server.%s.CraftingManager", ReflectionUtils.NMS));
+ craftingManagerClass = Class.forName(String.format("net.minecraft.server.%s.CraftingManager",
+ ReflectionUtils.NMS));
fields = getAllFields(craftingManagerClass,
fieldOf("recipes", min(12)));
} catch (Exception ex) {
@@ -27,6 +33,12 @@ public class RCraftingManager {
}
}
+ /**
+ * Removes all associated recipes of a plugin.
+ * @param plugin The plugin to remove recipes for.
+ * @throws IllegalAccessException When prohibited access to the method.
+ * @throws InvocationTargetException If the method call produced an exception.
+ */
@SuppressWarnings({"unchecked", "rawtypes"})
public static void removeRecipesFor(Plugin plugin) throws IllegalAccessException, InvocationTargetException {
// Cleaning up recipes before MC 1.12 is not possible,
@@ -43,11 +55,12 @@ public class RCraftingManager {
Object craftingManager = invoke(RMinecraftServer.getMethods(), server, "getCraftingManager");
Map recipes = (Map) recipesField.get(craftingManager);
+ Predicate