summaryrefslogtreecommitdiff
path: root/src/main/java/com/redstoner/modules/scriptutils
diff options
context:
space:
mode:
authorDavid <david@panic.tk>2018-11-07 23:50:06 +0100
committerDavid <david@panic.tk>2018-11-07 23:50:06 +0100
commit604cf01967ede98bf5024e4926bb0777fc4e8eee (patch)
treee2fa63d7e683769ee3bf3eddc75280648e92eb04 /src/main/java/com/redstoner/modules/scriptutils
parente86c52ef7c0e1e33c6af0e8674b038976bec11cc (diff)
Converted Modules to gradle
Diffstat (limited to 'src/main/java/com/redstoner/modules/scriptutils')
-rw-r--r--src/main/java/com/redstoner/modules/scriptutils/Scriptutils.cmd119
-rw-r--r--src/main/java/com/redstoner/modules/scriptutils/Scriptutils.java177
2 files changed, 296 insertions, 0 deletions
diff --git a/src/main/java/com/redstoner/modules/scriptutils/Scriptutils.cmd b/src/main/java/com/redstoner/modules/scriptutils/Scriptutils.cmd
new file mode 100644
index 0000000..c8498b2
--- /dev/null
+++ b/src/main/java/com/redstoner/modules/scriptutils/Scriptutils.cmd
@@ -0,0 +1,119 @@
+command script_restart {
+ [string:timeout] [string:name] [string:reason] {
+ help Prints bukkit restart message;
+ type console;
+ run script_restart timeout name reason;
+ }
+}
+command script_stop {
+ [string:timeout] [string:name] [string:reason] {
+ help Prints bukkit shut down message;
+ type console;
+ run script_stop timeout name reason;
+ }
+}
+command script_restart_abort {
+ [empty] {
+ help Prints the restart abort message;
+ type console;
+ run script_restart_abort;
+ }
+}
+command script_stop_abort {
+ [empty] {
+ help Prints the shut down abort message;
+ type console;
+ run script_stop_abort;
+ }
+}
+command script_backup_begin {
+ [empty] {
+ help Prints the backup started message, saves all worlds and turns off world saving;
+ type console;
+ run script_backup_begin;
+ }
+}
+command script_backup_end {
+ [empty] {
+ help Prints the backup finished message and turns on world saving;
+ type console;
+ run script_backup_end;
+ }
+}
+command script_backup_error {
+ [empty] {
+ help Prints the backup error message and turns on world saving;
+ type console;
+ run script_backup_error;
+ }
+}
+command script_trim {
+ [empty] {
+ help Prints the world trimming started message and starts trimming;
+ type console;
+ run script_trim;
+ }
+}
+command script_trim_result {
+ [string:size] [string:data...] {
+ help Prints the trimming finished message;
+ type console;
+ run script_trim_result size data;
+ }
+}
+command script_backup_database_begin {
+ [empty] {
+ help Prints the database backup started message and admin-chat warning;
+ type console;
+ run script_backup_database_begin;
+ }
+}
+command script_backup_database_dumps {
+ [empty] {
+ help Prints the database dumps cmpression started message;
+ type console;
+ run script_backup_database_dumps;
+ }
+}
+command script_backup_database_end {
+ [string:size] {
+ help Prints the database finished message and backup size in admin-chat;
+ type console;
+ run script_backup_database_end size;
+ }
+}
+command script_backup_database_error {
+ [empty] {
+ help Prints the database backup error message;
+ type console;
+ run script_backup_database_error;
+ }
+}
+command script_backup_database_abort {
+ [empty] {
+ help Prints the database backup abort message;
+ type console;
+ run script_backup_database_abort;
+ }
+}
+command script_spigot_update {
+ [empty] {
+ help Prints the spigot update message;
+ type console;
+ run script_spigot_update;
+ }
+}
+command script_disk_filled {
+ [string:percentage] {
+ help Prints the admin-chat warning for disk is filled;
+ type console;
+ run script_disk_filled percentage;
+ }
+}
+command script_shutdown {
+ [string:reason] {
+ help Saves all worlds, kicks players and shuts down the server;
+ type console;
+ run script_shutdown reason;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/redstoner/modules/scriptutils/Scriptutils.java b/src/main/java/com/redstoner/modules/scriptutils/Scriptutils.java
new file mode 100644
index 0000000..1d634c0
--- /dev/null
+++ b/src/main/java/com/redstoner/modules/scriptutils/Scriptutils.java
@@ -0,0 +1,177 @@
+package com.redstoner.modules.scriptutils;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+
+import com.nemez.cmdmgr.Command;
+import com.redstoner.annotations.Commands;
+import com.redstoner.annotations.Version;
+import com.redstoner.misc.CommandHolderType;
+import com.redstoner.misc.Utils;
+import com.redstoner.modules.Module;
+
+@Commands(CommandHolderType.File)
+@Version(major = 4, minor = 1, revision = 0, compatible = 4)
+public class Scriptutils implements Module
+{
+ /** Prints Bukkit restart message
+ * arg 0 timeout
+ * arg 1 $(whoami);
+ * arg 2: reason */
+ @Command(hook = "script_restart")
+ public void print_restart(CommandSender sender, String timeout, String name, String reason)
+ {
+ Utils.broadcast("", "§2§l=============================================", null);
+ Utils.broadcast("", "§r", null);
+ Utils.broadcast("", "§r", null);
+ Utils.broadcast("", "§9" + name + " is restarting the server.", null);
+ Utils.broadcast("", "§a§lServer is going to restart in " + timeout + " seconds.", null);
+ Utils.broadcast("", "§6§l" + reason, null);
+ Utils.broadcast("", "§r", null);
+ Utils.broadcast("", "§r", null);
+ Utils.broadcast("", "§2§l=============================================", null);
+ }
+
+ /** Prints the Bukkit shut down message
+ * arg 0 timeout
+ * arg 1 $(whoami);
+ * arg 2: reason */
+ @Command(hook = "script_stop")
+ public void print_stop(CommandSender sender, String timeout, String name, String reason)
+ {
+ Utils.broadcast("", "§2§l=============================================", null);
+ Utils.broadcast("", "§r", null);
+ Utils.broadcast("", "§r", null);
+ Utils.broadcast("", "§9" + name + " is shutting down the server.", null);
+ Utils.broadcast("", "§a§lServer is going to shut down in " + timeout + " seconds.", null);
+ Utils.broadcast("", "§6§l" + reason, null);
+ Utils.broadcast("", "§r", null);
+ Utils.broadcast("", "§r", null);
+ Utils.broadcast("", "§2§l=============================================", null);
+ }
+
+ /** Prints the shut down abort message */
+ @Command(hook = "script_stop_abort")
+ public void abort_stop(CommandSender sender)
+ {
+ Utils.broadcast("", "§4§oShut down has been aborted.", null);
+ }
+
+ /** Prints the restart abort message */
+ @Command(hook = "script_restart_abort")
+ public void abort_restart(CommandSender sender)
+ {
+ Utils.broadcast("", "§4§oRestart has been aborted.", null);
+ }
+
+ /** Prints the backup started message, saves all worlds and turns off world saving */
+ @Command(hook = "script_backup_begin")
+ public void print_backup_begin(CommandSender sender)
+ {
+ Utils.broadcast("", "§4 =§2 Starting backup now.", null);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "save-all");
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "save-off");
+ }
+
+ /** Prints the backup finished message and turns on world saving */
+ @Command(hook = "script_backup_end")
+ public void print_backup_end(CommandSender sender)
+ {
+ Utils.broadcast("", "§4 =§2 Backup completed.", null);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "save-on");
+ }
+
+ /** Prints the backup error message and turns on world saving */
+ @Command(hook = "script_backup_error")
+ public void print_backup_error(CommandSender sender)
+ {
+ Utils.broadcast("", "§4 =§c§l Error while backing up!", null);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "save-on");
+ }
+
+ /** Prints the world trimming started message and starts trimming */
+ @Command(hook = "script_trim")
+ public void print_backup_trim(CommandSender sender)
+ {
+ Utils.broadcast("", "§4 =§3 Deleting all chunks beyond border now.", null);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "wb Creative trim 1000000 15");
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "wb trim confirm");
+ }
+
+ /** Prints the trimming finished message
+ * arg 0 size difference of world
+ * arg 1: world border trim data */
+ @Command(hook = "script_trim_result")
+ public void print_backup_trim_res(CommandSender sender, String size, String data)
+ {
+ Utils.broadcast("", "§4 =§3 Chunk deletion saved " + data + " (§a" + size + "MB§3)", null);
+ }
+
+ /** Prints the database backup started message and admin-chat warning */
+ @Command(hook = "script_backup_database_begin")
+ public void print_backup_db_begin(CommandSender sender)
+ {
+ Utils.broadcast("", "§6 =§2 Starting database backup now.", null);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ac §aLogblock may be unavailable!");
+ }
+
+ /** Prints the database dumps compression started message */
+ @Command(hook = "script_backup_database_dumps")
+ public void print_backup_db_dumps(CommandSender sender)
+ {
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ac §aDumps completed, logblock available again.");
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ac §aNow compressing dumps, will take a while...");
+ }
+
+ /** Prints the database finished message and backup size in admin-chat
+ * arg 0 size of backup */
+ @Command(hook = "script_backup_database_end")
+ public void print_backup_db_end(CommandSender sender, String size)
+ {
+ Utils.broadcast("", "§6 =§2 Database backup completed.", null);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ac §abackup size: §2" + size + "MB§a.");
+ }
+
+ /** Prints the database backup error message */
+ @Command(hook = "script_backup_database_error")
+ public void print_backup_db_error(CommandSender sender)
+ {
+ Utils.broadcast("", "§6 =§c§l Error while backing up database!", null);
+ }
+
+ /** Prints the database backup abort message */
+ @Command(hook = "script_backup_database_abort")
+ public void print_backup_db_abort(CommandSender sender)
+ {
+ Utils.broadcast("", "§6 =§2 Database backup aborted.", null);
+ }
+
+ /** Prints the spigot update message */
+ @Command(hook = "script_spigot_update")
+ public void print_update(CommandSender sender)
+ {
+ Utils.broadcast("", "§9 =§2 A new Spigot version has been downloaded!", null);
+ Utils.broadcast("", "§9 =§2 Update will be applied after the next reboot.", null);
+ }
+
+ /** Prints the admin-chat warning for disk is filled
+ * arg 0 fill percentage */
+ @Command(hook = "script_disk_filled")
+ public void print_disk_filled(CommandSender sender, String percentage)
+ {
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
+ "ac §4§lWARNING:§6 Disk is filled > 96% (" + percentage + "%);");
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ac §4 Server will shut down at 98%!");
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ac §4 Contact an admin §nimmediately§4!");
+ }
+
+ /** Saves all worlds, kicks players and shuts down the server
+ * arg 0: reason */
+ @Command(hook = "script_shutdown")
+ public void shutdown(CommandSender sender, String reason)
+ {
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "save-all");
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "kickall " + reason);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "stop");
+ }
+}