Update gc and add scheduler subcommand

This commit is contained in:
JeremyStar™ 2024-04-30 21:46:34 +02:00
parent 5d51ae33b0
commit 407a123566
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
4 changed files with 41 additions and 9 deletions

View file

@ -53,6 +53,9 @@ public class Translation {
public static String PLUGINCOMMAND_RELOAD_DATA_SUCCESS = "Alle Spielerdaten wurden erfolgreich neugeladen.";
public static String PLUGINCOMMAND_RELOAD_DATA_FAIL = "Nicht alle Spielerdaten konnten erfolgreich neugeladen werden, folgende UUIDs sind betroffen:\n%uuids%";
public static String PLUGINCOMMAND_GARBAGECOLLECT = "Starte Garbage Collector, der Server könnte für ein paar Millisekunden einfrieren.";
public static String PLUGINCOMMAND_GARBAGECOLLECT_FINISHED = "Der Garbage Collector wurde gestartet und hat erfolgreich den Arbeitsspeicher entleert.";
public static String PLUGINCOMMAND_SCHEDULER = "Der Scheduler \"%timeframe%\" wurde gestartet und führt seine Hintergrundaufgaben aus, bitte warten.";
public static String PLUGINCOMMAND_SCHEDULER_DONE = "Der Scheduler \"%timeframe%\" wurde ausgeführt. Für eventuelle Fehler gucken sie sich bitte die Serverkonsole an.";
public static String PLUGINCOMMAND_PLAYERINFO = "Deine Spielerinformationen:\n%playerdata%";
// Command: /sysinfo

View file

@ -47,6 +47,7 @@ public class PluginCommand extends CommandBase {
sender.sendMessage(Miscellaneous.format(Translation.PLUGINCOMMAND_INFO));
return true;
}
switch (args[0]) {
case "reloadconfig":
sender.sendMessage(Miscellaneous.format(Translation.PLUGINCOMMAND_RELOAD_CONFIG));
@ -68,19 +69,45 @@ public class PluginCommand extends CommandBase {
}
break;
case "gc":
Thread gcThread = new Thread(() -> {
sender.sendMessage(Miscellaneous.format(Translation.PLUGINCOMMAND_GARBAGECOLLECT));
Miscellaneous.gc();
sender.sendMessage(Miscellaneous.format(Translation.PLUGINCOMMAND_GARBAGECOLLECT_FINISHED));
});
gcThread.start();
break;
case "playerinfo":
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage(Miscellaneous.format(Translation.GLOBAL_NOT_A_PLAYER, Types.FormatType.ERROR));
break;
}
Player player = (Player) sender;
sender.sendMessage(Miscellaneous.format(Translation.PLUGINCOMMAND_PLAYERINFO.replace("%playerdata%", ObjHolder.playerDataLoader.getPlayerData(player.getUniqueId()).convertToString())));
break;
default:
sender.sendMessage(Miscellaneous.format(Translation.GLOBAL_INVALID_ARGUMENT.replace("%usage%", command.getUsage()), Types.FormatType.ERROR));
case "scheduler":
if (args.length < 2) {
sender.sendMessage(Miscellaneous.format(Translation.GLOBAL_NOT_ENOUGH_ARGUMENTS.replace("%usage%", command.getUsage()), Types.FormatType.ERROR));
return true;
}
switch (args[1]) {
case "minutely":
case "minute":
sender.sendMessage(Miscellaneous.format(Translation.PLUGINCOMMAND_SCHEDULER.replace("%timeframe%", "minutely")));
ObjHolder.scheduler.runMinuteTasks(ObjHolder.scheduler.execsMinutely);
sender.sendMessage(Miscellaneous.format(Translation.PLUGINCOMMAND_SCHEDULER_DONE.replace("%timeframe%", "minutely")));
break;
case "hourly":
case "hour":
sender.sendMessage(Miscellaneous.format(Translation.PLUGINCOMMAND_SCHEDULER.replace("%timeframe%", "hourly")));
ObjHolder.scheduler.runHourTasks(ObjHolder.scheduler.execsHourly);
sender.sendMessage(Miscellaneous.format(Translation.PLUGINCOMMAND_SCHEDULER_DONE.replace("%timeframe%", "hourly")));
break;
default: sender.sendMessage(Miscellaneous.format(Translation.GLOBAL_INVALID_ARGUMENT.replace("%usage%", command.getUsage()), Types.FormatType.ERROR));
}
break;
default: sender.sendMessage(Miscellaneous.format(Translation.GLOBAL_INVALID_ARGUMENT.replace("%usage%", command.getUsage()), Types.FormatType.ERROR));
}
return true;
}
@ -89,7 +116,12 @@ public class PluginCommand extends CommandBase {
return (commandSender, command, name, args) -> {
if (commandSender.hasPermission("atc.commands.pickshadow")) {
ArrayList<String[]> completion = new ArrayList<>();
completion.add(new String[]{ "reloadconfig", "reloaddata", "gc", "playerinfo" });
completion.add(new String[]{ "reloadconfig", "reloaddata", "gc", "scheduler", "playerinfo" });
if (args.length > 2) {
if (args[0].equals("scheduler")) {
completion.add(new String[]{"minutely", "hourly"});
}
}
return TabCompletionHelper.processDynamicCompletion(completion, args);
} else {
return TabCompletionHelper.processEmptyCompletion(args);

View file

@ -18,13 +18,10 @@
*/
package de.pickshadow.plugin.loaders;
import de.pickshadow.plugin.Main;
import de.pickshadow.plugin.ObjHolder;
import de.pickshadow.plugin.classes.Configuration;
import de.pickshadow.plugin.classes.logger.LoggerImpl;
import de.pickshadow.plugin.classes.logger.LoggerInstanceImpl;
import de.pickshadow.plugin.utils.FileOperations;
import org.jetbrains.annotations.NotNull;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.composer.ComposerException;

View file

@ -35,7 +35,7 @@ commands:
permission: pickshadow.commands.home
pssp:
description: Verwaltet das PickShadow Server Plugin.
usage: /pssp <reloadconfig|reloaddata|gc|playerinfo>
usage: /pssp <reloadconfig|reloaddata|gc <minutely|hourly>|playerinfo>
aliases: [ "pickshadow" ]
sysinfo:
description: Zeigt Informationen zum Server an.