Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operators reloading info #6780

Merged
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
60d3682
Commit
Asleeepp May 29, 2024
ca7df36
Commit x2
Asleeepp Jun 11, 2024
e522450
whoops
Asleeepp Jun 11, 2024
d91cb9a
Merge branch 'dev/feature' into addition-operators-reloading-info
Asleeepp Jun 11, 2024
299355d
Suggested
Asleeepp Jun 11, 2024
b14b938
Merge remote-tracking branch 'origin/addition-operators-reloading-inf…
Asleeepp Jun 11, 2024
aa33f20
One last change
Asleeepp Jun 28, 2024
52a957f
Commit
Asleeepp May 29, 2024
705235c
Commit x2
Asleeepp Jun 11, 2024
4c0384d
whoops
Asleeepp Jun 11, 2024
b4d9ffa
Suggested
Asleeepp Jun 11, 2024
96edf65
One last change
Asleeepp Jun 28, 2024
186f43d
change
Asleeepp Jul 1, 2024
c1ecc9e
Merge remote-tracking branch 'origin/addition-operators-reloading-inf…
Asleeepp Jul 1, 2024
f64cfd0
yes?!
Asleeepp Jul 1, 2024
573660a
moved config
Asleeepp Jul 1, 2024
1eb07ff
e
Asleeepp Jul 1, 2024
a981ed1
simplification
Asleeepp Jul 1, 2024
52e29b3
e
Asleeepp Jul 1, 2024
f12b61e
pickle please :pray:
Asleeepp Jul 2, 2024
2b58032
stupid IDE
Asleeepp Jul 2, 2024
ffee17d
aaaaaaaaaaaaaaaaaa
Asleeepp Jul 2, 2024
91226fb
Changes, once again
Asleeepp Jul 3, 2024
4115dd0
chagne
Asleeepp Jul 12, 2024
3061e2e
deleted left other thing from a pr that i didnt make
Asleeepp Jul 12, 2024
3f35534
e
Asleeepp Jul 12, 2024
b15f09d
Merge remote-tracking branch 'origin/addition-operators-reloading-inf…
Asleeepp Jul 12, 2024
f501eef
done
Asleeepp Jul 14, 2024
3673f27
Merge branch 'dev/feature' into addition-operators-reloading-info
sovdeeth Jul 18, 2024
bffc5ad
Merge branch 'dev/feature' into addition-operators-reloading-info
sovdeeth Aug 15, 2024
57cc472
Cleanup + Remove config
Asleeepp Aug 15, 2024
405577d
Merge branch 'dev/feature' into addition-operators-reloading-info
Moderocky Aug 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 67 additions & 66 deletions src/main/java/ch/njol/skript/SkriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import ch.njol.skript.localization.ArgsMessage;
import ch.njol.skript.localization.Language;
import ch.njol.skript.localization.PluralizingArgsMessage;
import ch.njol.skript.log.LogEntry;
import ch.njol.skript.log.RedirectingLogHandler;
import ch.njol.skript.log.SkriptLogger;
import ch.njol.skript.log.TimingLogHandler;
import ch.njol.skript.test.runner.SkriptTestEvent;
import ch.njol.skript.test.runner.TestMode;
Expand All @@ -52,10 +54,13 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.stream.Collectors;


public class SkriptCommand implements CommandExecutor {

private static final String CONFIG_NODE = "skript command";
private static final ArgsMessage m_reloading = new ArgsMessage(CONFIG_NODE + ".reload.reloading");

Expand Down Expand Up @@ -90,30 +95,43 @@ public class SkriptCommand implements CommandExecutor {
if (TestMode.DEV_MODE)
SKRIPT_COMMAND_HELP.add("test");
}
private static void reloading(CommandSender sender, String what, Object... args) {

private static void reloading(CommandSender sender, String what, RedirectingLogHandler logHandler, Object... args) {
what = args.length == 0 ? Language.get(CONFIG_NODE + ".reload." + what) : Language.format(CONFIG_NODE + ".reload." + what, args);
Skript.info(sender, StringUtils.fixCapitalization(m_reloading.toString(what)));
String message = StringUtils.fixCapitalization(m_reloading.toString(what));
Skript.info(sender, message);

// Log reloading message
if (SkriptConfig.sendReloadingInfoToOps.value())
logHandler.log(new LogEntry(Level.INFO, Language.format(CONFIG_NODE + ".reload." + "player reload", sender.getName(), what)));
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}




Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
private static final ArgsMessage m_reloaded = new ArgsMessage(CONFIG_NODE + ".reload.reloaded");
private static final ArgsMessage m_reload_error = new ArgsMessage(CONFIG_NODE + ".reload.error");

private static void reloaded(CommandSender sender, RedirectingLogHandler r, TimingLogHandler timingLogHandler, String what, Object... args) {
what = args.length == 0 ? Language.get(CONFIG_NODE + ".reload." + what) : PluralizingArgsMessage.format(Language.format(CONFIG_NODE + ".reload." + what, args));
String timeTaken = String.valueOf(timingLogHandler.getTimeTaken());

if (r.numErrors() == 0)
Skript.info(sender, StringUtils.fixCapitalization(PluralizingArgsMessage.format(m_reloaded.toString(what, timeTaken))));
else
Skript.error(sender, StringUtils.fixCapitalization(PluralizingArgsMessage.format(m_reload_error.toString(what, r.numErrors(), timeTaken))));
private static void reloaded(CommandSender sender, RedirectingLogHandler logHandler, TimingLogHandler timingLogHandler, String what, Object... args) {
what = args.length == 0 ? Language.get(CONFIG_NODE + ".reload." + what) : PluralizingArgsMessage.format(Language.format(CONFIG_NODE + ".reload." + what, args));
String timeTaken = String.valueOf(timingLogHandler.getTimeTaken());

String message;
if (logHandler.numErrors() == 0) {
message = StringUtils.fixCapitalization(PluralizingArgsMessage.format(m_reloaded.toString(what, timeTaken)));
logHandler.log(new LogEntry(Level.INFO, message));
} else {
message = StringUtils.fixCapitalization(PluralizingArgsMessage.format(m_reload_error.toString(what, logHandler.numErrors(), timeTaken)));
logHandler.log(new LogEntry(Level.SEVERE, message));
}
}




Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
private static void info(CommandSender sender, String what, Object... args) {
what = args.length == 0 ? Language.get(CONFIG_NODE + "." + what) : PluralizingArgsMessage.format(Language.format(CONFIG_NODE + "." + what, args));
Skript.info(sender, StringUtils.fixCapitalization(what));
}

private static void error(CommandSender sender, String what, Object... args) {
what = args.length == 0 ? Language.get(CONFIG_NODE + "." + what) : PluralizingArgsMessage.format(Language.format(CONFIG_NODE + "." + what, args));
Skript.error(sender, StringUtils.fixCapitalization(what));
Expand All @@ -124,15 +142,24 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (!SKRIPT_COMMAND_HELP.test(sender, args))
return true;

List<CommandSender> recipients = new ArrayList<>();
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
recipients.add(sender);

if (args[0].equalsIgnoreCase("reload") && SkriptConfig.sendReloadingInfoToOps.value()) {
recipients.addAll(Bukkit.getOnlinePlayers().stream()
.filter(player -> player.hasPermission("skript.reloadnotify") && !player.equals(sender))
.collect(Collectors.toList()));
}

try (
RedirectingLogHandler logHandler = new RedirectingLogHandler(sender, "").start();
RedirectingLogHandler logHandler = new RedirectingLogHandler(recipients, "").start();
TimingLogHandler timingLogHandler = new TimingLogHandler().start()
) {

if (args[0].equalsIgnoreCase("reload")) {

if (args[1].equalsIgnoreCase("all")) {
reloading(sender, "config, aliases and scripts");
reloading(sender, "config, aliases and scripts", logHandler);
SkriptConfig.load();
Aliases.clear();
Aliases.load();
Expand All @@ -144,10 +171,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Skript.warning(Skript.m_no_scripts.toString());
reloaded(sender, logHandler, timingLogHandler, "config, aliases and scripts");
});
}

else if (args[1].equalsIgnoreCase("scripts")) {
reloading(sender, "scripts");
} else if (args[1].equalsIgnoreCase("scripts")) {
reloading(sender, "scripts", logHandler);

ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts());
ScriptLoader.loadScripts(Skript.getInstance().getScriptsFolder(), OpenCloseable.combine(logHandler, timingLogHandler))
Expand All @@ -156,22 +181,16 @@ else if (args[1].equalsIgnoreCase("scripts")) {
Skript.warning(Skript.m_no_scripts.toString());
reloaded(sender, logHandler, timingLogHandler, "scripts");
});
}

else if (args[1].equalsIgnoreCase("config")) {
reloading(sender, "main config");
} else if (args[1].equalsIgnoreCase("config")) {
reloading(sender, "main config", logHandler);
SkriptConfig.load();
reloaded(sender, logHandler, timingLogHandler, "main config");
}

else if (args[1].equalsIgnoreCase("aliases")) {
reloading(sender, "aliases");
} else if (args[1].equalsIgnoreCase("aliases")) {
reloading(sender, "aliases", logHandler);
Aliases.clear();
Aliases.load();
reloaded(sender, logHandler, timingLogHandler, "aliases");
}

else { // Reloading an individual Script or folder
} else { // Reloading an individual Script or folder
File scriptFile = getScriptFromArgs(sender, args);
if (scriptFile == null)
return true;
Expand All @@ -182,7 +201,7 @@ else if (args[1].equalsIgnoreCase("aliases")) {
return true;
}

reloading(sender, "script", scriptFile.getName());
reloading(sender, "script", logHandler, scriptFile.getName());

Script script = ScriptLoader.getScript(scriptFile);
if (script != null)
Expand All @@ -193,7 +212,7 @@ else if (args[1].equalsIgnoreCase("aliases")) {
);
} else {
final String fileName = scriptFile.getName();
reloading(sender, "scripts in folder", fileName);
reloading(sender, "scripts in folder", logHandler, fileName);
ScriptLoader.unloadScripts(ScriptLoader.getScripts(scriptFile));
ScriptLoader.loadScripts(scriptFile, OpenCloseable.combine(logHandler, timingLogHandler))
.thenAccept(scriptInfo -> {
Expand All @@ -206,9 +225,7 @@ else if (args[1].equalsIgnoreCase("aliases")) {
}
}

}

else if (args[0].equalsIgnoreCase("enable")) {
} else if (args[0].equalsIgnoreCase("enable")) {

if (args[1].equalsIgnoreCase("all")) {
try {
Expand All @@ -224,9 +241,7 @@ else if (args[0].equalsIgnoreCase("enable")) {
} catch (IOException e) {
error(sender, "enable.all.io error", ExceptionUtils.toString(e));
}
}

else {
} else {
File scriptFile = getScriptFromArgs(sender, args);
if (scriptFile == null)
return true;
Expand Down Expand Up @@ -281,9 +296,7 @@ else if (args[0].equalsIgnoreCase("enable")) {
}
}

}

else if (args[0].equalsIgnoreCase("disable")) {
} else if (args[0].equalsIgnoreCase("disable")) {

if (args[1].equalsIgnoreCase("all")) {
ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts());
Expand All @@ -293,9 +306,7 @@ else if (args[0].equalsIgnoreCase("disable")) {
} catch (IOException e) {
error(sender, "disable.all.io error", ExceptionUtils.toString(e));
}
}

else {
} else {
File scriptFile = getScriptFromArgs(sender, args);
if (scriptFile == null) // TODO allow disabling deleted/renamed scripts
return true;
Expand Down Expand Up @@ -339,9 +350,7 @@ else if (args[0].equalsIgnoreCase("disable")) {
}
}

}

else if (args[0].equalsIgnoreCase("update")) {
} else if (args[0].equalsIgnoreCase("update")) {
SkriptUpdater updater = Skript.getInstance().getUpdater();
if (updater == null) { // Oh. That is bad
Skript.info(sender, "" + SkriptUpdater.m_internal_error);
Expand All @@ -354,9 +363,7 @@ else if (args[0].equalsIgnoreCase("update")) {
} else if (args[1].equalsIgnoreCase("download")) {
updater.updateCheck(sender);
}
}

else if (args[0].equalsIgnoreCase("info")) {
} else if (args[0].equalsIgnoreCase("info")) {
info(sender, "info.aliases");
info(sender, "info.documentation");
info(sender, "info.tutorials");
Expand Down Expand Up @@ -393,9 +400,7 @@ else if (args[0].equalsIgnoreCase("info")) {
if (!dependenciesFound)
info(sender, "info.dependencies", "None");

}

else if (args[0].equalsIgnoreCase("gen-docs")) {
} else if (args[0].equalsIgnoreCase("gen-docs")) {
File templateDir = Documentation.getDocsTemplateDirectory();
if (!templateDir.exists()) {
Skript.error(sender, "Cannot generate docs! Documentation templates not found at '" + Documentation.getDocsTemplateDirectory().getPath() + "'");
Expand All @@ -408,9 +413,7 @@ else if (args[0].equalsIgnoreCase("gen-docs")) {
Skript.info(sender, "Generating docs...");
generator.generate(); // Try to generate docs... hopefully
Skript.info(sender, "Documentation generated!");
}

else if (args[0].equalsIgnoreCase("test") && TestMode.DEV_MODE) {
} else if (args[0].equalsIgnoreCase("test") && TestMode.DEV_MODE) {
File scriptFile;
if (args.length == 1) {
scriptFile = TestMode.lastTestFile;
Expand Down Expand Up @@ -444,9 +447,7 @@ else if (args[0].equalsIgnoreCase("test") && TestMode.DEV_MODE) {
}
})
);
}

else if (args[0].equalsIgnoreCase("help")) {
} else if (args[0].equalsIgnoreCase("help")) {
SKRIPT_COMMAND_HELP.showHelp(sender);
}

Expand All @@ -457,10 +458,10 @@ else if (args[0].equalsIgnoreCase("help")) {

return true;
}

private static final ArgsMessage m_invalid_script = new ArgsMessage(CONFIG_NODE + ".invalid script");
private static final ArgsMessage m_invalid_folder = new ArgsMessage(CONFIG_NODE + ".invalid folder");

@Nullable
private static File getScriptFromArgs(CommandSender sender, String[] args) {
String script = StringUtils.join(args, " ", 1, args.length);
Expand All @@ -473,7 +474,7 @@ private static File getScriptFromArgs(CommandSender sender, String[] args) {
}
return f;
}

@Nullable
public static File getScriptFromName(String script) {
if (script.endsWith("/") || script.endsWith("\\")) { // Always allow '/' and '\' regardless of OS
Expand Down Expand Up @@ -515,7 +516,7 @@ private static File toggleFile(File file, boolean enable) throws IOException {
false
);
}

private static Set<File> toggleFiles(File folder, boolean enable) throws IOException {
FileFilter filter = enable ? ScriptLoader.getDisabledScriptsFilter() : ScriptLoader.getLoadedScriptsFilter();

Expand All @@ -537,5 +538,5 @@ private static Set<File> toggleFiles(File folder, boolean enable) throws IOExcep

return changed;
}

}
2 changes: 2 additions & 0 deletions src/main/java/ch/njol/skript/SkriptConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public class SkriptConfig {
public static final Option<String> effectCommandToken = new Option<>("effect command token", "!");
public static final Option<Boolean> allowOpsToUseEffectCommands = new Option<>("allow ops to use effect commands", false);

public static final Option<Boolean> sendReloadingInfoToOps = new Option<>("send reloading info to ops", false);

/*
* @deprecated Will be removed in 2.8.0. Use {@link #logEffectCommands} instead.
*/
Expand Down
36 changes: 23 additions & 13 deletions src/main/java/ch/njol/skript/log/RedirectingLogHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,53 @@
*/
package ch.njol.skript.log;

import ch.njol.skript.SkriptConfig;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.eclipse.jdt.annotation.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;

/**
* Redirects the log to a {@link CommandSender}.
* Redirects the log to one or more {@link CommandSender}s.
*/
public class RedirectingLogHandler extends LogHandler {

private final CommandSender recipient;

private final String prefix;

private final List<CommandSender> recipients;
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
private int numErrors = 0;

private final String prefix;

public RedirectingLogHandler(CommandSender recipient, @Nullable String prefix) {
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
this.recipient = recipient;
this(Collections.singletonList(recipient), prefix);
}

public RedirectingLogHandler(List<CommandSender> recipients, @Nullable String prefix) {
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
this.recipients = new ArrayList<>(recipients);
this.prefix = prefix == null ? "" : prefix;
}

@Override
public LogResult log(LogEntry entry) {
SkriptLogger.sendFormatted(recipient, prefix + entry.toFormattedString());
if (entry.level == Level.SEVERE)
String formattedMessage = prefix + entry.toFormattedString();
for (CommandSender recipient : recipients) {
SkriptLogger.sendFormatted(recipient, formattedMessage);
}
if (entry.level == Level.SEVERE) {
numErrors++;
}
return LogResult.DO_NOT_LOG;
}

@Override
public RedirectingLogHandler start() {
return SkriptLogger.startLogHandler(this);
}

public int numErrors() {
return numErrors;
}

}

4 changes: 4 additions & 0 deletions src/main/resources/config.sk
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ release channel: @release-channel@
# 'prerelease' means that development releases will also be checked for.
# Initial value of this depends on the Skript version you first installed; it was '@release-channel@'.

send reloading info to ops: false
# Whether Skript should alert operators when someone reloads a script file.
# This will look like the normal message you receive when reloading a script, containing reload time, errors and/or warnings.
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved

enable effect commands: false
effect command token: !
# If 'enable effect commands' is set to true, chat messages starting with the 'effect command token' will be interpreted as effects and executed.
Expand Down
Loading