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
|
|
@ -4,8 +4,6 @@ import co.aikar.commands.BukkitCommandCompletionContext;
|
|||
import co.aikar.commands.CommandCompletions;
|
||||
import co.aikar.commands.PaperCommandManager;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import net.frankheijden.serverutils.bukkit.commands.CommandPlugins;
|
||||
|
|
@ -60,6 +58,7 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
reload();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new BukkitListener(), this);
|
||||
plugin.enable();
|
||||
|
||||
ServerUtilsApp.tryCheckForUpdates();
|
||||
}
|
||||
|
|
@ -76,6 +75,7 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
public void onDisable() {
|
||||
super.onDisable();
|
||||
restoreBukkitPluginCommand();
|
||||
plugin.disable();
|
||||
}
|
||||
|
||||
private void removeCommands(String... commands) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import net.frankheijden.serverutils.bukkit.reflection.RCraftServer;
|
|||
import net.frankheijden.serverutils.bukkit.utils.BukkitUtils;
|
||||
import net.frankheijden.serverutils.bukkit.utils.ReloadHandler;
|
||||
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;
|
||||
|
|
@ -237,6 +238,35 @@ public class CommandServerUtils extends BaseCommand {
|
|||
result.sendTo(BukkitUtils.wrap(sender), "disabl", pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = BukkitUtils.wrap(sender);
|
||||
AbstractResult result = BukkitPluginManager.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 = BukkitPluginManager.get().unwatchPlugin(pluginName);
|
||||
result.sendTo(BukkitUtils.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.bukkit.entities;
|
|||
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* A wrap for a Bukkit CommandSender.
|
||||
|
|
@ -36,4 +37,13 @@ public class BukkitCommandSender 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 Player;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public class BukkitPlugin extends ServerUtilsPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public BukkitTaskManager getTaskManager() {
|
||||
return taskManager;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,11 +334,21 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
|||
return loader.getPluginDescription(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getPluginFile(Plugin plugin) {
|
||||
try {
|
||||
return RJavaPlugin.getFile(plugin);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new RuntimeException("Error retrieving current plugin file", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to retrieve the plugin file by plugin name.
|
||||
* @param pluginName The plugin name.
|
||||
* @return The file, or null if invalid or not found.
|
||||
*/
|
||||
@Override
|
||||
public File getPluginFile(String pluginName) {
|
||||
for (File file : getPluginJars()) {
|
||||
PluginDescriptionFile descriptionFile;
|
||||
|
|
@ -354,12 +364,8 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public File getPluginFile(Plugin plugin) {
|
||||
try {
|
||||
return RJavaPlugin.getFile(plugin);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new RuntimeException("Error retrieving current plugin file", ex);
|
||||
}
|
||||
public Plugin getPlugin(String pluginName) {
|
||||
return Bukkit.getPluginManager().getPlugin(pluginName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,16 +3,21 @@ package net.frankheijden.serverutils.bukkit.managers;
|
|||
import net.frankheijden.serverutils.bukkit.ServerUtils;
|
||||
import net.frankheijden.serverutils.common.managers.AbstractTaskManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class BukkitTaskManager extends AbstractTaskManager {
|
||||
public class BukkitTaskManager extends AbstractTaskManager<BukkitTask> {
|
||||
|
||||
public BukkitTaskManager() {
|
||||
super(BukkitTask::cancel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable runnable) {
|
||||
Bukkit.getScheduler().runTask(ServerUtils.getInstance(), runnable);
|
||||
addTask(Bukkit.getScheduler().runTask(ServerUtils.getInstance(), runnable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTaskAsynchronously(Runnable runnable) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(ServerUtils.getInstance(), runnable);
|
||||
addTask(Bukkit.getScheduler().runTaskAsynchronously(ServerUtils.getInstance(), runnable));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue