Initial BungeeCord edition
This commit is contained in:
parent
4416d55173
commit
23e8e80191
75 changed files with 1931 additions and 396 deletions
|
|
@ -1,56 +0,0 @@
|
|||
package net.frankheijden.serverutils.bukkit.managers;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CloseableResult implements Closeable {
|
||||
|
||||
private Result result;
|
||||
private final Closeable closeable;
|
||||
|
||||
/**
|
||||
* Constructs a new closable result.
|
||||
* Used for unloading / reloading a plugin.
|
||||
* NB: The closable needs to be closed to fully ensure that the old plugin doesn't work anymore!
|
||||
* @param result The result of the procedure
|
||||
* @param closeable The closable of the procedure.
|
||||
*/
|
||||
public CloseableResult(Result result, Closeable closeable) {
|
||||
this.result = result;
|
||||
this.closeable = closeable;
|
||||
}
|
||||
|
||||
public CloseableResult(Result result) {
|
||||
this(result, null);
|
||||
}
|
||||
|
||||
public CloseableResult(Closeable closeable) {
|
||||
this(Result.SUCCESS, closeable);
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public CloseableResult set(Result result) {
|
||||
this.result = result;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to close the closable, essentially wrapping it with try-catch.
|
||||
*/
|
||||
public void tryClose() {
|
||||
if (closeable == null) return;
|
||||
try {
|
||||
close();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
closeable.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package net.frankheijden.serverutils.bukkit.managers;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class LoadResult {
|
||||
private final Plugin plugin;
|
||||
private final Result result;
|
||||
|
||||
private LoadResult(Plugin plugin, Result result) {
|
||||
this.plugin = plugin;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public LoadResult(Plugin plugin) {
|
||||
this(plugin, Result.SUCCESS);
|
||||
}
|
||||
|
||||
public LoadResult(Result result) {
|
||||
this(null, result);
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Plugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return plugin != null && result == Result.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,12 +7,15 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import net.frankheijden.serverutils.bukkit.ServerUtils;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitLoadResult;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCommandMap;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCraftServer;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCraftingManager;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RJavaPlugin;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RPluginClassLoader;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RSimplePluginManager;
|
||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||
import net.frankheijden.serverutils.common.entities.Result;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
|
|
@ -30,7 +33,7 @@ public class PluginManager {
|
|||
* @param jarFile The name of the file in the plugins/ folder.
|
||||
* @return The result of the loading procedure.
|
||||
*/
|
||||
public static LoadResult loadPlugin(String jarFile) {
|
||||
public static BukkitLoadResult loadPlugin(String jarFile) {
|
||||
return loadPlugin(new File(ServerUtils.getInstance().getDataFolder().getParent(), jarFile));
|
||||
}
|
||||
|
||||
|
|
@ -39,33 +42,33 @@ public class PluginManager {
|
|||
* @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);
|
||||
public static BukkitLoadResult loadPlugin(File file) {
|
||||
if (!file.exists()) return new BukkitLoadResult(Result.NOT_EXISTS);
|
||||
|
||||
Plugin loadedPlugin = getLoadedPlugin(file);
|
||||
if (loadedPlugin != null) return new LoadResult(Result.ALREADY_LOADED);
|
||||
if (loadedPlugin != null) return new BukkitLoadResult(Result.ALREADY_LOADED);
|
||||
|
||||
Plugin plugin;
|
||||
try {
|
||||
plugin = Bukkit.getPluginManager().loadPlugin(file);
|
||||
} catch (InvalidDescriptionException ex) {
|
||||
return new LoadResult(Result.INVALID_DESCRIPTION);
|
||||
return new BukkitLoadResult(Result.INVALID_DESCRIPTION);
|
||||
} catch (UnknownDependencyException ex) {
|
||||
return new LoadResult(Result.UNKNOWN_DEPENDENCY.arg(ex.getMessage()));
|
||||
return new BukkitLoadResult(Result.UNKNOWN_DEPENDENCY.arg(ex.getMessage()));
|
||||
} catch (InvalidPluginException ex) {
|
||||
if (ex.getCause() instanceof IllegalArgumentException) {
|
||||
IllegalArgumentException e = (IllegalArgumentException) ex.getCause();
|
||||
if (e.getMessage().equalsIgnoreCase("Plugin already initialized!")) {
|
||||
return new LoadResult(Result.ALREADY_ENABLED);
|
||||
return new BukkitLoadResult(Result.ALREADY_ENABLED);
|
||||
}
|
||||
}
|
||||
ex.printStackTrace();
|
||||
return new LoadResult(Result.ERROR);
|
||||
return new BukkitLoadResult(Result.ERROR);
|
||||
}
|
||||
|
||||
if (plugin == null) return new LoadResult(Result.INVALID_PLUGIN);
|
||||
if (plugin == null) return new BukkitLoadResult(Result.INVALID_PLUGIN);
|
||||
plugin.onLoad();
|
||||
return new LoadResult(plugin);
|
||||
return new BukkitLoadResult(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -176,9 +179,9 @@ public class PluginManager {
|
|||
File pluginFile = getPluginFile(plugin.getName());
|
||||
if (pluginFile == null) return result.set(Result.FILE_DELETED);
|
||||
|
||||
LoadResult loadResult = loadPlugin(pluginFile);
|
||||
BukkitLoadResult loadResult = loadPlugin(pluginFile);
|
||||
if (!loadResult.isSuccess()) return result.set(loadResult.getResult());
|
||||
return result.set(enablePlugin(loadResult.getPlugin()));
|
||||
return result.set(enablePlugin(loadResult.get()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -291,7 +294,7 @@ public class PluginManager {
|
|||
* @return The file, or null if invalid or not found.
|
||||
*/
|
||||
public static File getPluginFile(String pluginName) {
|
||||
for (File file : ServerUtils.getInstance().getJars()) {
|
||||
for (File file : ServerUtils.getInstance().getPlugin().getPluginProvider().getPluginJars()) {
|
||||
PluginDescriptionFile descriptionFile;
|
||||
try {
|
||||
descriptionFile = getPluginDescription(file);
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
package net.frankheijden.serverutils.bukkit.managers;
|
||||
|
||||
import net.frankheijden.serverutils.bukkit.config.Messenger;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public enum Result {
|
||||
NOT_EXISTS,
|
||||
NOT_ENABLED,
|
||||
ALREADY_LOADED,
|
||||
ALREADY_ENABLED,
|
||||
ALREADY_DISABLED,
|
||||
FILE_DELETED,
|
||||
INVALID_DESCRIPTION,
|
||||
INVALID_PLUGIN,
|
||||
UNKNOWN_DEPENDENCY,
|
||||
ERROR,
|
||||
SUCCESS;
|
||||
|
||||
private String arg;
|
||||
|
||||
Result() {
|
||||
this.arg = "";
|
||||
}
|
||||
|
||||
public Result arg(String arg) {
|
||||
this.arg = arg;
|
||||
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,
|
||||
"%what%", what,
|
||||
"%arg%", arg);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue