Feature - plugin watcher, detect file changes & reload
This commit is contained in:
parent
719163c579
commit
07719cc1cc
24 changed files with 387 additions and 15 deletions
|
|
@ -53,10 +53,18 @@ public class ServerUtils extends Plugin {
|
|||
reload();
|
||||
getProxy().getPluginManager().registerListener(this, new BungeeListener());
|
||||
|
||||
plugin.enable();
|
||||
|
||||
loadClasses();
|
||||
ServerUtilsApp.tryCheckForUpdates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
plugin.disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads some classes in memory so they're available during updating.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import net.frankheijden.serverutils.bungee.managers.BungeePluginManager;
|
|||
import net.frankheijden.serverutils.bungee.reflection.RPluginManager;
|
||||
import net.frankheijden.serverutils.bungee.utils.BungeeUtils;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.frankheijden.serverutils.common.entities.AbstractResult;
|
||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||
import net.frankheijden.serverutils.common.entities.Result;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
|
|
@ -150,6 +151,35 @@ public class CommandServerUtils extends BaseCommand {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Watches the given plugin and reloads it when a change is detected to the file.
|
||||
* @param sender The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("watchplugin")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.watchplugin")
|
||||
@Description("Watches the specified plugin for changes.")
|
||||
public void onWatchPlugin(CommandSender sender, String pluginName) {
|
||||
ServerCommandSender commandSender = BungeeUtils.wrap(sender);
|
||||
AbstractResult result = BungeePluginManager.get().watchPlugin(commandSender, pluginName);
|
||||
result.sendTo(commandSender, "watch", pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops watching the given plugin.
|
||||
* @param sender The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("unwatchplugin")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.unwatchplugin")
|
||||
@Description("Stops watching the specified plugin for changes.")
|
||||
public void onUnwatchPlugin(CommandSender sender, String pluginName) {
|
||||
AbstractResult result = BungeePluginManager.get().unwatchPlugin(pluginName);
|
||||
result.sendTo(BungeeUtils.wrap(sender), "unwatch", pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows information about the specified plugin.
|
||||
* @param commandSender The sender of the command.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package net.frankheijden.serverutils.bungee.entities;
|
|||
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class BungeeCommandSender implements ServerCommandSender {
|
||||
|
||||
|
|
@ -20,4 +21,13 @@ public class BungeeCommandSender implements ServerCommandSender {
|
|||
public boolean hasPermission(String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the given instance is a player.
|
||||
* @return Boolean true or false.
|
||||
*/
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return sender instanceof ProxiedPlayer;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public class BungeePlugin extends ServerUtilsPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public BungeeTaskManager getTaskManager() {
|
||||
return taskManager;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
|||
* @param pluginName The plugin name to search for.
|
||||
* @return The File if the plugin exists with that name.
|
||||
*/
|
||||
@Override
|
||||
public File getPluginFile(String pluginName) {
|
||||
for (File file : getPluginJars()) {
|
||||
PluginDescription desc;
|
||||
|
|
@ -195,6 +196,11 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
|||
return plugin.getFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin getPlugin(String pluginName) {
|
||||
return proxy.getPluginManager().getPlugin(pluginName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCommands() {
|
||||
return proxy.getPluginManager().getCommands().stream()
|
||||
|
|
|
|||
|
|
@ -3,8 +3,13 @@ package net.frankheijden.serverutils.bungee.managers;
|
|||
import net.frankheijden.serverutils.bungee.ServerUtils;
|
||||
import net.frankheijden.serverutils.common.managers.AbstractTaskManager;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
|
||||
public class BungeeTaskManager extends AbstractTaskManager {
|
||||
public class BungeeTaskManager extends AbstractTaskManager<ScheduledTask> {
|
||||
|
||||
public BungeeTaskManager() {
|
||||
super(ScheduledTask::cancel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable runnable) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue