use of net.citizensnpcs.api.command.CommandContext in project Denizen-For-Bukkit by DenizenScript.
the class ServerTagBase method adjustServer.
// <--[ObjectType]
// @name server
// @prefix None
// @base None
// @format
// N/A
//
// @description
// "server" is an internal pseudo-ObjectType that is used as a mechanism adjust target for some global mechanisms.
//
// -->
public static void adjustServer(Mechanism mechanism) {
// -->
if (mechanism.matches("delete_file") && mechanism.hasValue()) {
if (!Settings.allowDelete()) {
Debug.echoError("File deletion disabled by administrator (refer to mechanism documentation).");
return;
}
File file = new File(Denizen.getInstance().getDataFolder(), mechanism.getValue().asString());
if (!Utilities.canWriteToFile(file)) {
Debug.echoError("Cannot write to that file path due to security settings in Denizen/config.yml.");
return;
}
try {
if (!file.delete()) {
Debug.echoError("Failed to delete file: returned false");
}
} catch (Exception e) {
Debug.echoError("Failed to delete file: " + e.getMessage());
}
}
if (mechanism.matches("redirect_logging") && mechanism.hasValue()) {
Deprecations.serverRedirectLogging.warn(mechanism.context);
if (!Settings.allowConsoleRedirection()) {
Debug.echoError("Console redirection disabled by administrator.");
return;
}
if (mechanism.getValue().asBoolean()) {
DenizenCore.logInterceptor.redirectOutput();
} else {
DenizenCore.logInterceptor.standardOutput();
}
}
// -->
if (mechanism.matches("reset_event_stats")) {
for (ScriptEvent se : ScriptEvent.events) {
se.eventData.stats_fires = 0;
se.eventData.stats_scriptFires = 0;
se.eventData.stats_nanoTimes = 0;
}
}
// -->
if (mechanism.matches("reset_recipes")) {
Bukkit.resetRecipes();
Denizen.getInstance().itemScriptHelper.rebuildRecipes();
}
// -->
if (mechanism.matches("remove_recipes")) {
ListTag list = mechanism.valueAsType(ListTag.class);
for (String str : list) {
NMSHandler.getItemHelper().removeRecipe(Utilities.parseNamespacedKey(str));
}
}
// -->
if (mechanism.matches("idle_timeout") && mechanism.requireObject(DurationTag.class)) {
Bukkit.setIdleTimeout((int) Math.round(mechanism.valueAsType(DurationTag.class).getSeconds() / 60));
}
// -->
if (mechanism.matches("cleanmem")) {
System.gc();
}
// -->
if (mechanism.matches("restart")) {
if (!Settings.allowServerRestart()) {
Debug.echoError("Server restart disabled by administrator (refer to mechanism documentation). Consider using 'shutdown'.");
return;
}
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "+> Server restarted by a Denizen script, see config to prevent this!");
Bukkit.spigot().restart();
}
// -->
if (mechanism.matches("save")) {
DenizenCore.saveAll();
Denizen.getInstance().saveSaves(true);
}
// -->
if (Depends.citizens != null && mechanism.matches("save_citizens")) {
Depends.citizens.storeNPCs(new CommandContext(new String[0]));
}
// -->
if (mechanism.matches("shutdown")) {
if (!Settings.allowServerStop()) {
Debug.echoError("Server stop disabled by administrator (refer to mechanism documentation). Consider using 'restart'.");
return;
}
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "+> Server shutdown by a Denizen script, see config to prevent this!");
Bukkit.shutdown();
}
// -->
if (mechanism.matches("has_whitelist") && mechanism.requireBoolean()) {
Bukkit.setWhitelist(mechanism.getValue().asBoolean());
}
}
Aggregations