Add initial cloud commands + refactors to common
This commit is contained in:
parent
f21306021d
commit
6545d7ffac
89 changed files with 1959 additions and 1893 deletions
|
|
@ -1,40 +1,25 @@
|
|||
package net.frankheijden.serverutils.bukkit;
|
||||
|
||||
import co.aikar.commands.BukkitCommandCompletionContext;
|
||||
import co.aikar.commands.CommandCompletions;
|
||||
import co.aikar.commands.PaperCommandManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.frankheijden.serverutils.bukkit.commands.CommandPlugins;
|
||||
import net.frankheijden.serverutils.bukkit.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitPlugin;
|
||||
import net.frankheijden.serverutils.bukkit.listeners.BukkitListener;
|
||||
import net.frankheijden.serverutils.bukkit.managers.BukkitPluginManager;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCommandMap;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCraftServer;
|
||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||
import net.frankheijden.serverutils.common.config.Config;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.frankheijden.serverutils.common.utils.StringUtils;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.defaults.PluginsCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
||||
public class ServerUtils extends JavaPlugin {
|
||||
|
||||
private static ServerUtils instance;
|
||||
private static final String CONFIG_RESOURCE = "bukkit-config.yml";
|
||||
private static final String MESSAGES_RESOURCE = "bukkit-messages.yml";
|
||||
|
||||
private BukkitPlugin plugin;
|
||||
private PaperCommandManager commandManager;
|
||||
private CommandPlugins commandPlugins;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
|
@ -45,23 +30,7 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
ServerUtilsApp.init(this, plugin);
|
||||
|
||||
new Metrics(this, ServerUtilsApp.BSTATS_METRICS_ID);
|
||||
|
||||
this.commandManager = new PaperCommandManager(this);
|
||||
commandManager.registerCommand(new CommandServerUtils(), true);
|
||||
this.commandPlugins = null;
|
||||
|
||||
BukkitPluginManager manager = plugin.getPluginManager();
|
||||
CommandCompletions<BukkitCommandCompletionContext> completions = commandManager.getCommandCompletions();
|
||||
completions.registerAsyncCompletion("plugins", context -> manager.getPluginNames());
|
||||
completions.registerAsyncCompletion("pluginJars", context -> manager.getPluginFileNames());
|
||||
completions.registerAsyncCompletion("supportedConfigs", context -> CommandServerUtils.getSupportedConfigs());
|
||||
completions.registerAsyncCompletion("commands", context -> manager.getCommands());
|
||||
reload();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new BukkitListener(), this);
|
||||
plugin.enable();
|
||||
|
||||
ServerUtilsApp.tryCheckForUpdates();
|
||||
}
|
||||
|
||||
public static ServerUtils getInstance() {
|
||||
|
|
@ -75,54 +44,20 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
commandManager.unregisterCommands();
|
||||
restoreBukkitPluginCommand();
|
||||
plugin.disable();
|
||||
}
|
||||
|
||||
private void removeCommands(String... commands) {
|
||||
Map<String, Command> map;
|
||||
try {
|
||||
map = RCommandMap.getKnownCommands(RCraftServer.getCommandMap());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
for (String command : commands) {
|
||||
map.remove(command);
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreBukkitPluginCommand() {
|
||||
RCraftServer.getCommandMap().register("bukkit", new PluginsCommand("plugins"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the configurations of the plugin.
|
||||
* Also makes sure the bukkit /pl command gets restored.
|
||||
* Retrieves the disabled commands from the configuration.
|
||||
*/
|
||||
public void reload() {
|
||||
if (commandPlugins != null) {
|
||||
commandManager.unregisterCommand(commandPlugins);
|
||||
restoreBukkitPluginCommand();
|
||||
}
|
||||
|
||||
new Config("config.yml", CONFIG_RESOURCE);
|
||||
new Messenger("messages.yml", MESSAGES_RESOURCE);
|
||||
|
||||
if (!Config.getInstance().getConfig().getBoolean("settings.disable-plugins-command")) {
|
||||
this.removeCommands("pl", "plugins");
|
||||
this.commandPlugins = new CommandPlugins();
|
||||
commandManager.registerCommand(commandPlugins, true);
|
||||
}
|
||||
|
||||
getPlugin().getTaskManager().runTask(() -> BukkitPluginManager.unregisterExactCommands(getDisabledCommands()));
|
||||
}
|
||||
|
||||
private List<Command> getDisabledCommands() {
|
||||
public List<Command> getDisabledCommands() {
|
||||
List<Command> commands = new ArrayList<>();
|
||||
for (String cmd : Config.getInstance().getConfig().getStringList("disabled-commands")) {
|
||||
for (String cmd : plugin.getConfigResource().getConfig().getStringList("disabled-commands")) {
|
||||
String[] split = cmd.split(":");
|
||||
|
||||
Command command;
|
||||
|
|
@ -153,8 +88,4 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
public PaperCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package net.frankheijden.serverutils.bukkit.commands;
|
||||
|
||||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitCommandSender;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitPlugin;
|
||||
import net.frankheijden.serverutils.common.commands.CommandPlugins;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class BukkitCommandPlugins extends CommandPlugins<
|
||||
BukkitPlugin,
|
||||
Plugin,
|
||||
BukkitTask,
|
||||
BukkitCommandSender,
|
||||
CommandSender
|
||||
> {
|
||||
|
||||
public BukkitCommandPlugins(BukkitPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void register(
|
||||
CommandManager<BukkitCommandSender> manager,
|
||||
Command.Builder<BukkitCommandSender> builder
|
||||
) {
|
||||
manager.command(builder
|
||||
.flag(parseFlag("version"))
|
||||
.handler(this::handlePlugins));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlugins(CommandContext<BukkitCommandSender> context) {
|
||||
BukkitCommandSender sender = context.getSender();
|
||||
boolean hasVersionFlag = context.flags().contains("version");
|
||||
|
||||
handlePlugins(sender, plugin.getPluginManager().getPluginsSorted(), bukkitPlugin -> {
|
||||
PluginDescriptionFile description = bukkitPlugin.getDescription();
|
||||
|
||||
String message = plugin.getMessagesResource().getMessage(
|
||||
"serverutils.plugins.format",
|
||||
"%plugin%", description.getName()
|
||||
);
|
||||
|
||||
if (hasVersionFlag) {
|
||||
message += plugin.getMessagesResource().getMessage(
|
||||
"serverutils.plugins.version",
|
||||
"%version%", description.getVersion()
|
||||
);
|
||||
}
|
||||
|
||||
return message;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,208 @@
|
|||
package net.frankheijden.serverutils.bukkit.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import dev.frankheijden.minecraftreflection.MinecraftReflectionVersion;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitCommandSender;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitPlugin;
|
||||
import net.frankheijden.serverutils.bukkit.managers.BukkitPluginManager;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCraftServer;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RDedicatedServer;
|
||||
import net.frankheijden.serverutils.bukkit.utils.ReloadHandler;
|
||||
import net.frankheijden.serverutils.bukkit.utils.VersionReloadHandler;
|
||||
import net.frankheijden.serverutils.common.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.common.entities.Result;
|
||||
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ForwardFilter;
|
||||
import net.frankheijden.serverutils.common.utils.ListBuilder;
|
||||
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;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class BukkitCommandServerUtils extends CommandServerUtils<
|
||||
BukkitPlugin,
|
||||
Plugin,
|
||||
BukkitTask,
|
||||
BukkitCommandSender,
|
||||
CommandSender
|
||||
> {
|
||||
|
||||
private static final Map<String, ReloadHandler> supportedConfigs;
|
||||
|
||||
static {
|
||||
supportedConfigs = new HashMap<>();
|
||||
supportedConfigs.put("bukkit", new VersionReloadHandler(16, RCraftServer::reloadBukkitConfiguration));
|
||||
supportedConfigs.put("commands.yml", RCraftServer::reloadCommandsConfiguration);
|
||||
supportedConfigs.put("server-icon.png", new VersionReloadHandler(16, RCraftServer::loadIcon));
|
||||
supportedConfigs.put("banned-ips.json", new VersionReloadHandler(16, RCraftServer::reloadIpBans));
|
||||
supportedConfigs.put("banned-players.json", new VersionReloadHandler(16, RCraftServer::reloadProfileBans));
|
||||
supportedConfigs.put("server.properties", new VersionReloadHandler(
|
||||
16,
|
||||
RDedicatedServer::reloadServerProperties
|
||||
));
|
||||
}
|
||||
|
||||
public BukkitCommandServerUtils(BukkitPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(
|
||||
CommandManager<BukkitCommandSender> manager,
|
||||
cloud.commandframework.Command.Builder<BukkitCommandSender> builder
|
||||
) {
|
||||
super.register(manager, builder);
|
||||
|
||||
final List<String> supportedConfigNames = supportedConfigs.entrySet().stream()
|
||||
.filter(r -> {
|
||||
if (r instanceof VersionReloadHandler) {
|
||||
VersionReloadHandler reloadHandler = ((VersionReloadHandler) r);
|
||||
return MinecraftReflectionVersion.MINOR <= reloadHandler.getMinecraftVersionMaximum();
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
addArgument(CommandArgument.<BukkitCommandSender, String>ofType(String.class, "config")
|
||||
.manager(manager)
|
||||
.withSuggestionsProvider((context, s) -> supportedConfigNames)
|
||||
.build());
|
||||
|
||||
manager.command(parseSubcommand(builder, "enableplugin")
|
||||
.argument(getArgument("plugin"))
|
||||
.handler(this::handleEnablePlugin));
|
||||
manager.command(parseSubcommand(builder, "disableplugin")
|
||||
.argument(getArgument("plugin"))
|
||||
.handler(this::handleDisablePlugin));
|
||||
manager.command(parseSubcommand(builder, "reloadconfig")
|
||||
.argument(getArgument("config"))
|
||||
.handler(this::handleReloadConfig));
|
||||
}
|
||||
|
||||
private void handleEnablePlugin(CommandContext<BukkitCommandSender> context) {
|
||||
BukkitCommandSender sender = context.getSender();
|
||||
String pluginName = context.get("pluginName");
|
||||
|
||||
Result result = plugin.getPluginManager().enablePlugin(pluginName);
|
||||
result.sendTo(sender, "enabl", pluginName);
|
||||
}
|
||||
|
||||
private void handleDisablePlugin(CommandContext<BukkitCommandSender> context) {
|
||||
BukkitCommandSender sender = context.getSender();
|
||||
String pluginName = context.get("pluginName");
|
||||
|
||||
Result result = plugin.getPluginManager().disablePlugin(pluginName);
|
||||
result.sendTo(sender, "disabl", pluginName);
|
||||
}
|
||||
|
||||
private void handleReloadConfig(CommandContext<BukkitCommandSender> context) {
|
||||
BukkitCommandSender sender = context.getSender();
|
||||
String config = context.get("config");
|
||||
|
||||
ReloadHandler handler = supportedConfigs.get(config);
|
||||
if (handler == null) {
|
||||
plugin.getMessagesResource().sendMessage(
|
||||
sender,
|
||||
"serverutils.reloadconfig.not_exists",
|
||||
"%what%", config
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (handler instanceof VersionReloadHandler) {
|
||||
VersionReloadHandler versionReloadHandler = (VersionReloadHandler) handler;
|
||||
int max = versionReloadHandler.getMinecraftVersionMaximum();
|
||||
|
||||
if (MinecraftReflectionVersion.MINOR > max) {
|
||||
plugin.getMessagesResource().sendMessage(
|
||||
sender,
|
||||
"serverutils.reloadconfig.not_supported",
|
||||
"%what%", config
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String[] replacements = new String[]{ "%action%", "reload", "%what%", config };
|
||||
|
||||
ForwardFilter filter = new ForwardFilter(plugin.getChatProvider(), sender);
|
||||
filter.start(Bukkit.getLogger());
|
||||
try {
|
||||
handler.handle();
|
||||
filter.stop(Bukkit.getLogger());
|
||||
|
||||
String path = "serverutils." + (filter.hasWarnings() ? "warning" : "success");
|
||||
plugin.getMessagesResource().sendMessage(sender, path, replacements);
|
||||
} catch (Exception ex) {
|
||||
filter.stop(Bukkit.getLogger());
|
||||
|
||||
ex.printStackTrace();
|
||||
plugin.getMessagesResource().sendMessage(sender, "serverutils.error", replacements);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FormatBuilder createPluginInfo(
|
||||
FormatBuilder builder,
|
||||
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
|
||||
String pluginName
|
||||
) {
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
|
||||
builder.add("Name", plugin.getName())
|
||||
.add("Full Name", description.getFullName())
|
||||
.add("Version", description.getVersion())
|
||||
.add("Website", description.getWebsite())
|
||||
.add("Authors", listBuilderFunction.apply(b -> b.addAll(description.getAuthors())))
|
||||
.add("Description", description.getDescription())
|
||||
.add("Main", description.getMain())
|
||||
.add("Prefix", description.getPrefix())
|
||||
.add("Load Order", description.getLoad().name())
|
||||
.add("Load Before", listBuilderFunction.apply(b -> b.addAll(description.getLoadBefore())))
|
||||
.add("Depend", listBuilderFunction.apply(b -> b.addAll(description.getDepend())))
|
||||
.add("Soft Depend", listBuilderFunction.apply(b -> b.addAll(description.getSoftDepend())));
|
||||
|
||||
if (MinecraftReflectionVersion.MINOR >= 13) {
|
||||
builder.add("API Version", description.getAPIVersion());
|
||||
}
|
||||
|
||||
if (MinecraftReflectionVersion.MINOR >= 15) {
|
||||
builder.add("Provides", listBuilderFunction.apply(b -> b.addAll(description.getProvides())));
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FormatBuilder createCommandInfo(
|
||||
FormatBuilder builder,
|
||||
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
|
||||
String commandName
|
||||
) {
|
||||
Command cmd = BukkitPluginManager.getCommand(commandName);
|
||||
builder.add("Name", cmd.getName());
|
||||
|
||||
if (cmd instanceof PluginIdentifiableCommand) {
|
||||
builder.add("Plugin", ((PluginIdentifiableCommand) cmd).getPlugin().getName());
|
||||
}
|
||||
|
||||
return builder.add("Aliases", listBuilderFunction.apply(b -> b.addAll(cmd.getAliases())))
|
||||
.add("Usage", cmd.getUsage())
|
||||
.add("Description", cmd.getDescription())
|
||||
.add("Label", cmd.getLabel())
|
||||
.add("Permission", cmd.getPermission())
|
||||
.add("Permission Message", cmd.getPermissionMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package net.frankheijden.serverutils.bukkit.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
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 net.frankheijden.serverutils.bukkit.managers.BukkitPluginManager;
|
||||
import net.frankheijden.serverutils.bukkit.utils.BukkitUtils;
|
||||
import net.frankheijden.serverutils.common.commands.Plugins;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandAlias("pl|plugins")
|
||||
public class CommandPlugins extends BaseCommand {
|
||||
|
||||
private static final BukkitPluginManager manager = BukkitPluginManager.get();
|
||||
|
||||
/**
|
||||
* 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.")
|
||||
public void onPlugins(CommandSender sender) {
|
||||
Plugins.sendPlugins(BukkitUtils.wrap(sender), manager.getPluginsSorted(), pl -> {
|
||||
String format = "serverutils.plugins.format" + (pl.isEnabled() ? "" : "_disabled");
|
||||
return Messenger.getMessage(format, "%plugin%", pl.getName());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
Plugins.sendPlugins(BukkitUtils.wrap(sender), manager.getPluginsSorted(), pl -> {
|
||||
String format = "serverutils.plugins.format" + (pl.isEnabled() ? "" : "_disabled");
|
||||
String version = Messenger.getMessage("serverutils.plugins.version",
|
||||
"%version%", pl.getDescription().getVersion());
|
||||
return Messenger.getMessage(format, "%plugin%", pl.getName()) + version;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,408 +0,0 @@
|
|||
package net.frankheijden.serverutils.bukkit.commands;
|
||||
|
||||
import static net.frankheijden.serverutils.common.config.Messenger.sendMessage;
|
||||
import static net.frankheijden.serverutils.common.config.Messenger.sendRawMessage;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.RegisteredCommand;
|
||||
import co.aikar.commands.RootCommand;
|
||||
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 dev.frankheijden.minecraftreflection.MinecraftReflectionVersion;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.frankheijden.serverutils.bukkit.ServerUtils;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitLoadResult;
|
||||
import net.frankheijden.serverutils.bukkit.managers.BukkitPluginManager;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCraftServer;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RDedicatedServer;
|
||||
import net.frankheijden.serverutils.bukkit.utils.BukkitUtils;
|
||||
import net.frankheijden.serverutils.bukkit.utils.ReloadHandler;
|
||||
import net.frankheijden.serverutils.bukkit.utils.VersionReloadHandler;
|
||||
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;
|
||||
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ForwardFilter;
|
||||
import net.frankheijden.serverutils.common.utils.HexUtils;
|
||||
import net.frankheijden.serverutils.common.utils.ListBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ListFormat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
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("su|serverutils")
|
||||
public class CommandServerUtils extends BaseCommand {
|
||||
|
||||
private static final Map<String, ReloadHandler> supportedConfigs;
|
||||
|
||||
static {
|
||||
supportedConfigs = new HashMap<>();
|
||||
supportedConfigs.put("bukkit", new VersionReloadHandler(16, RCraftServer::reloadBukkitConfiguration));
|
||||
supportedConfigs.put("commands.yml", RCraftServer::reloadCommandsConfiguration);
|
||||
supportedConfigs.put("server-icon.png", new VersionReloadHandler(16, RCraftServer::loadIcon));
|
||||
supportedConfigs.put("banned-ips.json", new VersionReloadHandler(16, RCraftServer::reloadIpBans));
|
||||
supportedConfigs.put("banned-players.json", new VersionReloadHandler(16, RCraftServer::reloadProfileBans));
|
||||
supportedConfigs.put("server.properties", new VersionReloadHandler(
|
||||
16,
|
||||
RDedicatedServer::reloadServerProperties
|
||||
));
|
||||
}
|
||||
|
||||
@Dependency
|
||||
private ServerUtils plugin;
|
||||
|
||||
public static Set<String> getSupportedConfigs() {
|
||||
return supportedConfigs.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the help page to the sender.
|
||||
* @param commandSender The sender of the command.
|
||||
*/
|
||||
@Default
|
||||
@Subcommand("help")
|
||||
@CommandPermission("serverutils.help")
|
||||
@Description("Shows a help page with a few commands.")
|
||||
public void onHelp(CommandSender commandSender) {
|
||||
ServerCommandSender sender = BukkitUtils.wrap(commandSender);
|
||||
Messenger.sendMessage(sender, "serverutils.help.header");
|
||||
|
||||
FormatBuilder builder = FormatBuilder.create(Messenger.getMessage("serverutils.help.format"))
|
||||
.orderedKeys("%command%", "%subcommand%", "%help%");
|
||||
|
||||
Set<String> rootCommands = new HashSet<>();
|
||||
for (RootCommand root : plugin.getCommandManager().getRegisteredRootCommands()) {
|
||||
String rootName = root.getDefCommand().getName();
|
||||
if (!rootCommands.add(rootName)) continue;
|
||||
builder.add(rootName, "", root.getDescription());
|
||||
|
||||
Set<String> subCommands = new HashSet<>();
|
||||
for (RegisteredCommand<?> sub : root.getSubCommands().values()) {
|
||||
String name = sub.getPrefSubCommand().toLowerCase();
|
||||
if (name.isEmpty()) continue;
|
||||
if (!subCommands.add(name)) continue;
|
||||
builder.add(rootName, " " + name, sub.getHelpText());
|
||||
}
|
||||
}
|
||||
builder.sendTo(sender);
|
||||
Messenger.sendMessage(sender, "serverutils.help.footer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the configurations of ServerUtils.
|
||||
* @param sender The sender of the command.
|
||||
*/
|
||||
@Subcommand("reload|r")
|
||||
@CommandPermission("serverutils.reload")
|
||||
@Description("Reloads the ServerUtils plugin.")
|
||||
public void onReload(CommandSender sender) {
|
||||
plugin.reload();
|
||||
sendMessage(BukkitUtils.wrap(sender), "serverutils.success",
|
||||
"%action%", "reload",
|
||||
"%what%", "ServerUtils configurations");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads a config from a set of configurations of the server.
|
||||
* @param commandSender The sender of the command.
|
||||
* @param config The configuration to reload.
|
||||
*/
|
||||
@Subcommand("reloadconfig|rc")
|
||||
@CommandCompletion("@supportedConfigs")
|
||||
@CommandPermission("serverutils.reloadconfig")
|
||||
@Description("Reloads individual Server configurations.")
|
||||
public void onReloadCommands(CommandSender commandSender, String config) {
|
||||
ServerCommandSender sender = BukkitUtils.wrap(commandSender);
|
||||
|
||||
ReloadHandler handler = supportedConfigs.get(config);
|
||||
if (handler == null) {
|
||||
this.doHelp(commandSender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (handler instanceof VersionReloadHandler) {
|
||||
VersionReloadHandler versionReloadHandler = (VersionReloadHandler) handler;
|
||||
int max = versionReloadHandler.getMinecraftVersionMaximum();
|
||||
|
||||
if (MinecraftReflectionVersion.MINOR > max) {
|
||||
sendRawMessage(sender, "&cThis command is not supported on your Minecraft version."
|
||||
+ " This command only support Minecraft versions up to MC1." + max);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String[] replacements = new String[]{ "%action%", "reload", "%what%", config };
|
||||
|
||||
ForwardFilter filter = new ForwardFilter(plugin.getPlugin().getChatProvider(), sender);
|
||||
filter.start(Bukkit.getLogger());
|
||||
try {
|
||||
handler.handle();
|
||||
filter.stop(Bukkit.getLogger());
|
||||
|
||||
String path = "serverutils." + (filter.hasWarnings() ? "warning" : "success");
|
||||
sendMessage(sender, path, replacements);
|
||||
} catch (Exception ex) {
|
||||
filter.stop(Bukkit.getLogger());
|
||||
|
||||
ex.printStackTrace();
|
||||
sendMessage(sender, "serverutils.error", replacements);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the specified plugin on the server.
|
||||
* @param commandSender The sender of the command.
|
||||
* @param jarFile The filename of the plugin in the plugins/ directory.
|
||||
*/
|
||||
@Subcommand("loadplugin|lp")
|
||||
@CommandCompletion("@pluginJars")
|
||||
@CommandPermission("serverutils.loadplugin")
|
||||
@Description("Loads the specified jar file as a plugin.")
|
||||
public void onLoadPlugin(CommandSender commandSender, String jarFile) {
|
||||
ServerCommandSender sender = BukkitUtils.wrap(commandSender);
|
||||
|
||||
BukkitLoadResult loadResult = BukkitPluginManager.get().loadPlugin(jarFile);
|
||||
if (!loadResult.isSuccess()) {
|
||||
loadResult.getResult().sendTo(sender, "load", jarFile);
|
||||
return;
|
||||
}
|
||||
|
||||
Result result = BukkitPluginManager.get().enablePlugin(loadResult.get());
|
||||
result.sendTo(sender, "load", jarFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unloads the specified plugin from the server.
|
||||
* @param commandSender The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("unloadplugin|up")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.unloadplugin")
|
||||
@Description("Disables and unloads the specified plugin.")
|
||||
public void onUnloadPlugin(CommandSender commandSender, String pluginName) {
|
||||
ServerCommandSender sender = BukkitUtils.wrap(commandSender);
|
||||
|
||||
Result disableResult = BukkitPluginManager.get().disablePlugin(pluginName);
|
||||
if (disableResult != Result.SUCCESS && disableResult != Result.ALREADY_DISABLED) {
|
||||
disableResult.sendTo(sender, "disabl", pluginName);
|
||||
return;
|
||||
}
|
||||
|
||||
CloseableResult result = BukkitPluginManager.get().unloadPlugin(pluginName);
|
||||
result.getResult().sendTo(sender, "unload", pluginName);
|
||||
result.tryClose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the specified plugin on the server.
|
||||
* @param sender The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("reloadplugin|rp")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.reloadplugin")
|
||||
@Description("Reloads a specified plugin.")
|
||||
public void onReloadPlugin(CommandSender sender, String pluginName) {
|
||||
// Wacky method to have the resources needed for the reload in memory, in case of a self reload.
|
||||
HexUtils utils = new HexUtils();
|
||||
Map<String, Object> section = Messenger.getInstance().getConfig().getMap("serverutils");
|
||||
String result = BukkitPluginManager.get().reloadPlugin(pluginName).toString();
|
||||
|
||||
String msg = (String) section.get(result.toLowerCase());
|
||||
if (msg != null && !msg.isEmpty()) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', utils.convertHexString(
|
||||
msg.replace("%action%", "reload").replace("%what%", pluginName))));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the specified plugin on the server.
|
||||
* @param sender The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("enableplugin|ep")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.enableplugin")
|
||||
@Description("Enables the loaded plugin.")
|
||||
public void onEnablePlugin(CommandSender sender, String pluginName) {
|
||||
Result result = BukkitPluginManager.get().enablePlugin(pluginName);
|
||||
result.sendTo(BukkitUtils.wrap(sender), "enabl", pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the specified plugin on the server.
|
||||
* @param sender The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("disableplugin|dp")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.disableplugin")
|
||||
@Description("Disables the specified plugin.")
|
||||
public void onDisablePlugin(CommandSender sender, String pluginName) {
|
||||
Result result = BukkitPluginManager.get().disablePlugin(pluginName);
|
||||
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|wp")
|
||||
@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|uwp")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.watchplugin")
|
||||
@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.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("plugininfo|pi")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.plugininfo")
|
||||
@Description("Shows information about the specified plugin.")
|
||||
public void onPluginInfo(CommandSender commandSender, String pluginName) {
|
||||
ServerCommandSender sender = BukkitUtils.wrap(commandSender);
|
||||
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
|
||||
if (plugin == null) {
|
||||
Result.NOT_EXISTS.sendTo(sender, "fetch", pluginName);
|
||||
return;
|
||||
}
|
||||
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
String format = Messenger.getMessage("serverutils.plugininfo.format");
|
||||
String listFormatString = Messenger.getMessage("serverutils.plugininfo.list_format");
|
||||
String seperator = Messenger.getMessage("serverutils.plugininfo.seperator");
|
||||
String lastSeperator = Messenger.getMessage("serverutils.plugininfo.last_seperator");
|
||||
|
||||
ListFormat<String> listFormat = str -> listFormatString.replace("%value%", str);
|
||||
|
||||
Messenger.sendMessage(sender, "serverutils.plugininfo.header");
|
||||
|
||||
FormatBuilder builder = FormatBuilder.create(format)
|
||||
.orderedKeys("%key%", "%value%")
|
||||
.add("Name", plugin.getName())
|
||||
.add("Full Name", description.getFullName())
|
||||
.add("Version", description.getVersion());
|
||||
if (MinecraftReflectionVersion.MINOR >= 13) builder.add("API Version", description.getAPIVersion());
|
||||
builder.add("Website", description.getWebsite())
|
||||
.add("Authors", ListBuilder.create(description.getAuthors())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString())
|
||||
.add("Description", description.getDescription())
|
||||
.add("Main", description.getMain())
|
||||
.add("Prefix", description.getPrefix())
|
||||
.add("Load Order", description.getLoad().name())
|
||||
.add("Load Before", ListBuilder.create(description.getLoadBefore())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString())
|
||||
.add("Depend", ListBuilder.create(description.getDepend())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString())
|
||||
.add("Soft Depend", ListBuilder.create(description.getSoftDepend())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString());
|
||||
if (MinecraftReflectionVersion.MINOR >= 15) {
|
||||
builder.add("Provides", ListBuilder.create(description.getProvides())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString());
|
||||
}
|
||||
|
||||
builder.sendTo(sender);
|
||||
Messenger.sendMessage(sender, "serverutils.plugininfo.footer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows information about a provided command.
|
||||
* @param commandSender The sender of the command.
|
||||
* @param command The command to lookup.
|
||||
*/
|
||||
@Subcommand("commandinfo|ci")
|
||||
@CommandCompletion("@commands")
|
||||
@CommandPermission("serverutils.commandinfo")
|
||||
@Description("Shows information about the specified command.")
|
||||
public void onCommandInfo(CommandSender commandSender, String command) {
|
||||
ServerCommandSender sender = BukkitUtils.wrap(commandSender);
|
||||
|
||||
Command cmd = BukkitPluginManager.getCommand(command);
|
||||
if (cmd == null) {
|
||||
Messenger.sendMessage(sender, "serverutils.commandinfo.not_exists");
|
||||
return;
|
||||
}
|
||||
|
||||
String format = Messenger.getMessage("serverutils.commandinfo.format");
|
||||
String listFormatString = Messenger.getMessage("serverutils.commandinfo.list_format");
|
||||
String seperator = Messenger.getMessage("serverutils.commandinfo.seperator");
|
||||
String lastSeperator = Messenger.getMessage("serverutils.commandinfo.last_seperator");
|
||||
|
||||
ListFormat<String> listFormat = str -> listFormatString.replace("%value%", str);
|
||||
|
||||
Messenger.sendMessage(sender, "serverutils.commandinfo.header");
|
||||
FormatBuilder builder = FormatBuilder.create(format)
|
||||
.orderedKeys("%key%", "%value%")
|
||||
.add("Name", cmd.getName());
|
||||
if (cmd instanceof PluginIdentifiableCommand) {
|
||||
PluginIdentifiableCommand pc = (PluginIdentifiableCommand) cmd;
|
||||
builder.add("Plugin", pc.getPlugin().getName());
|
||||
}
|
||||
builder.add("Usage", cmd.getUsage())
|
||||
.add("Description", cmd.getDescription())
|
||||
.add("Aliases", ListBuilder.create(cmd.getAliases())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString())
|
||||
.add("Label", cmd.getLabel())
|
||||
.add("Permission", cmd.getPermission())
|
||||
.add("Permission Message", cmd.getPermissionMessage());
|
||||
|
||||
builder.sendTo(sender);
|
||||
Messenger.sendMessage(sender, "serverutils.commandinfo.footer");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +1,28 @@
|
|||
package net.frankheijden.serverutils.bukkit.entities;
|
||||
|
||||
import net.frankheijden.serverutils.bukkit.utils.BukkitUtils;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.frankheijden.serverutils.common.providers.ChatProvider;
|
||||
import net.frankheijden.serverutils.common.utils.HexUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Provides basic chat functionality for Bukkit servers.
|
||||
*/
|
||||
public class BukkitChatProvider extends ChatProvider {
|
||||
public class BukkitChatProvider implements ChatProvider<BukkitCommandSender, CommandSender> {
|
||||
|
||||
/**
|
||||
* Retrieves the console sender of a Bukkit instance.
|
||||
* @return The console sender.
|
||||
*/
|
||||
@Override
|
||||
public ServerCommandSender getConsoleSender() {
|
||||
return BukkitUtils.wrap(Bukkit.getConsoleSender());
|
||||
public BukkitCommandSender getConsoleSender() {
|
||||
return new BukkitCommandSender(Bukkit.getConsoleSender());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitCommandSender get(CommandSender source) {
|
||||
return new BukkitCommandSender(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Colorizes the given string.
|
||||
* @param str The string to color.
|
||||
* @return The colored string.
|
||||
*/
|
||||
@Override
|
||||
public String color(String str) {
|
||||
return ChatColor.translateAlternateColorCodes('&', HexUtils.convertHexString(str));
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a message over a Bukkit instance.
|
||||
* @param permission The permission the receivers need to have.
|
||||
* @param message The message to broadcast.
|
||||
*/
|
||||
@Override
|
||||
public void broadcast(String permission, String message) {
|
||||
Bukkit.broadcast(message, permission);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
|
|||
/**
|
||||
* A wrap for a Bukkit CommandSender.
|
||||
*/
|
||||
public class BukkitCommandSender implements ServerCommandSender {
|
||||
public class BukkitCommandSender implements ServerCommandSender<CommandSender> {
|
||||
|
||||
private final CommandSender sender;
|
||||
|
||||
|
|
@ -46,4 +46,9 @@ public class BukkitCommandSender implements ServerCommandSender {
|
|||
public boolean isPlayer() {
|
||||
return sender instanceof Player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSender getSource() {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,34 @@
|
|||
package net.frankheijden.serverutils.bukkit.entities;
|
||||
|
||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||
import cloud.commandframework.paper.PaperCommandManager;
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
import net.frankheijden.serverutils.bukkit.ServerUtils;
|
||||
import net.frankheijden.serverutils.bukkit.commands.BukkitCommandPlugins;
|
||||
import net.frankheijden.serverutils.bukkit.commands.BukkitCommandServerUtils;
|
||||
import net.frankheijden.serverutils.bukkit.listeners.BukkitListener;
|
||||
import net.frankheijden.serverutils.bukkit.managers.BukkitPluginManager;
|
||||
import net.frankheijden.serverutils.bukkit.managers.BukkitTaskManager;
|
||||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class BukkitPlugin extends ServerUtilsPlugin {
|
||||
public class BukkitPlugin extends ServerUtilsPlugin<
|
||||
Plugin,
|
||||
BukkitTask,
|
||||
BukkitCommandSender,
|
||||
CommandSender
|
||||
> {
|
||||
|
||||
private final ServerUtils plugin;
|
||||
private final BukkitPluginManager pluginManager;
|
||||
private final BukkitTaskManager taskManager;
|
||||
private final BukkitResourceProvider resourceProvider;
|
||||
private final BukkitChatProvider chatProvider;
|
||||
private boolean registeredPluginsCommand;
|
||||
|
||||
/**
|
||||
* Creates a new BukkitPlugin instance of ServerUtils.
|
||||
|
|
@ -25,16 +40,34 @@ public class BukkitPlugin extends ServerUtilsPlugin {
|
|||
this.taskManager = new BukkitTaskManager();
|
||||
this.resourceProvider = new BukkitResourceProvider(plugin);
|
||||
this.chatProvider = new BukkitChatProvider();
|
||||
this.registeredPluginsCommand = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PaperCommandManager<BukkitCommandSender> newCommandManager() {
|
||||
try {
|
||||
return new PaperCommandManager<>(
|
||||
plugin,
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
chatProvider::get,
|
||||
BukkitCommandSender::getSource
|
||||
);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform getPlatform() {
|
||||
return Platform.BUKKIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public BukkitPluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public BukkitTaskManager getTaskManager() {
|
||||
return taskManager;
|
||||
}
|
||||
|
|
@ -60,8 +93,23 @@ public class BukkitPlugin extends ServerUtilsPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public File fetchUpdaterData() {
|
||||
return pluginManager.getPluginFile("ServerUtils");
|
||||
protected void enablePlugin() {
|
||||
Bukkit.getPluginManager().registerEvents(new BukkitListener(this), plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reloadPlugin() {
|
||||
if (getConfigResource().getConfig().getBoolean("settings.disable-plugins-command")) {
|
||||
if (registeredPluginsCommand) {
|
||||
plugin.restoreBukkitPluginCommand();
|
||||
this.registeredPluginsCommand = false;
|
||||
}
|
||||
} else {
|
||||
new BukkitCommandPlugins(this).register(commandManager);
|
||||
this.registeredPluginsCommand = true;
|
||||
}
|
||||
new BukkitCommandServerUtils(this).register(commandManager);
|
||||
|
||||
taskManager.runTask(() -> BukkitPluginManager.unregisterExactCommands(plugin.getDisabledCommands()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ public class BukkitResourceProvider implements ResourceProvider {
|
|||
|
||||
@Override
|
||||
public InputStream getResource(String resource) {
|
||||
return getRawResource(resource + getResourceExtension());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getRawResource(String resource) {
|
||||
return plugin.getResource(resource);
|
||||
}
|
||||
|
||||
|
|
@ -28,4 +33,9 @@ public class BukkitResourceProvider implements ResourceProvider {
|
|||
public ServerUtilsConfig load(File file) {
|
||||
return new BukkitYamlConfig(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResourceExtension() {
|
||||
return ".yml";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,35 @@
|
|||
package net.frankheijden.serverutils.bukkit.listeners;
|
||||
|
||||
import net.frankheijden.serverutils.bukkit.utils.BukkitUtils;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitCommandSender;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitPlugin;
|
||||
import net.frankheijden.serverutils.common.listeners.ServerListener;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class BukkitListener implements Listener {
|
||||
public class BukkitListener extends ServerListener<
|
||||
BukkitPlugin,
|
||||
Plugin,
|
||||
BukkitTask,
|
||||
BukkitCommandSender,
|
||||
CommandSender
|
||||
> implements Listener {
|
||||
|
||||
public BukkitListener(BukkitPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
ServerListener.handleUpdate(BukkitUtils.wrap(event.getPlayer()));
|
||||
handleUpdate(plugin.getChatProvider().get(event.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
|||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.UnknownDependencyException;
|
||||
|
||||
public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
||||
public class BukkitPluginManager implements AbstractPluginManager<Plugin> {
|
||||
|
||||
private static BukkitPluginManager instance;
|
||||
|
||||
|
|
@ -306,6 +306,25 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
|||
RCraftServer.syncCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters all the specified commands.
|
||||
*/
|
||||
public static void unregisterCommands(String... commands) {
|
||||
Map<String, Command> map;
|
||||
try {
|
||||
map = RCommandMap.getKnownCommands(RCraftServer.getCommandMap());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
for (String command : commands) {
|
||||
map.remove(command);
|
||||
}
|
||||
|
||||
RCraftServer.syncCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters all specified commands exactly.
|
||||
* @param commands The commands to unregister.
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
package net.frankheijden.serverutils.bukkit.utils;
|
||||
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitCommandSender;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class BukkitUtils {
|
||||
|
||||
public static ServerCommandSender wrap(CommandSender sender) {
|
||||
return new BukkitCommandSender(sender);
|
||||
}
|
||||
}
|
||||
26
Bukkit/src/main/resources/bukkit-commands.json
Normal file
26
Bukkit/src/main/resources/bukkit-commands.json
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"serverutils": {
|
||||
"subcommands": {
|
||||
"enableplugin": {
|
||||
"main": "enableplugin",
|
||||
"aliases": ["ep"],
|
||||
"permission": "serverutils.enableplugin",
|
||||
"description": "Enables the specified plugin.",
|
||||
"display-in-help": true
|
||||
},
|
||||
"disableplugin": {
|
||||
"main": "disableplugin",
|
||||
"aliases": ["dp"],
|
||||
"permission": "serverutils.disableplugin",
|
||||
"description": "Disables the specified plugin.",
|
||||
"display-in-help": true
|
||||
},
|
||||
"reloadconfig": {
|
||||
"main": "reloadconfig",
|
||||
"aliases": ["rc"],
|
||||
"permission": "serverutils.reloadconfig",
|
||||
"description": "Reloads particular server configurations."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
6
Bukkit/src/main/resources/bukkit-config.json
Normal file
6
Bukkit/src/main/resources/bukkit-config.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"settings": {
|
||||
"disable-plugins-command": false
|
||||
},
|
||||
"disabled-commands": []
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
settings:
|
||||
disable-plugins-command: false
|
||||
check-updates-boot: true
|
||||
check-updates-login: false
|
||||
download-updates-boot: false
|
||||
download-updates-login: false
|
||||
install-updates-boot: false
|
||||
install-updates-login: false
|
||||
|
||||
disabled-commands: []
|
||||
8
Bukkit/src/main/resources/bukkit-messages.json
Normal file
8
Bukkit/src/main/resources/bukkit-messages.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"serverutils": {
|
||||
"reloadconfig": {
|
||||
"not_exists": "&cConfig &4%what% &cdoes not exist.",
|
||||
"not_supported": "&cConfig &4%what% &cis not supported on your Minecraft version."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
serverutils:
|
||||
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_deleted: "&cAccessing the jar file while %action%ing &4%what%&c went wrong, plugin has been deleted!"
|
||||
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%"
|
||||
watcher:
|
||||
start: "&3Started watching &b%what%&3!"
|
||||
change: "&3Change detected for plugin &b%what%&3, reloading now..."
|
||||
stopped: "&3Stopped watching &b%what%&3!"
|
||||
not_watching: "&cWe aren't watching that plugin!"
|
||||
update:
|
||||
available: |-
|
||||
&8&m------------=&r&8[ &b&lServerUtils Update&r &8]&m=--------------
|
||||
&3Current version: &b%old%
|
||||
&3New version: &b%new%
|
||||
&3Release info: &b%info%
|
||||
&8&m-------------------------------------------------
|
||||
downloading: |-
|
||||
&8&m------------=&r&8[ &b&lServerUtils Update&r &8]&m=--------------
|
||||
&3A new version of ServerUtils will be downloaded and installed after a restart!
|
||||
&3Current version: &b%old%
|
||||
&3New version: &b%new%
|
||||
&3Release info: &b%info%
|
||||
&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:
|
||||
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:
|
||||
header: "&8&m------------=&r&8[ &b&lServerUtils Plugins&r &8]&m=-------------"
|
||||
prefix: " &3Plugins &8(&a%count%&8)&b: "
|
||||
format: "&3%plugin%"
|
||||
format_disabled: "&c%plugin%"
|
||||
seperator: "&b, "
|
||||
last_seperator: " &band "
|
||||
version: " &8(&a%version%&8)"
|
||||
footer: "&8&m-------------------------------------------------"
|
||||
plugininfo:
|
||||
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:
|
||||
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."
|
||||
|
|
@ -4,10 +4,3 @@ version: ${version}
|
|||
author: FrankHeijden
|
||||
api-version: '1.13'
|
||||
softdepend: [ServerUtilsUpdater]
|
||||
|
||||
commands:
|
||||
serverutils:
|
||||
usage: "/<command>"
|
||||
aliases:
|
||||
- "su"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue