From c5ce18777ffb0b909864441e065c70110821810d Mon Sep 17 00:00:00 2001 From: GIGABAIT93 <59637348+GIGABAIT93@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:53:03 +0200 Subject: [PATCH] update --- .../java/com/vcmi/commands/HelpCommand.java | 26 +++++++++ src/main/java/com/vcmi/config/Lang.java | 2 +- .../java/com/vcmi/config/data/LangYAML.java | 58 ++++++++++++------- src/main/java/com/vcmi/modules/Modules.java | 2 + .../vcmi/modules/text/TextReaderModule.java | 1 + src/main/resources/readme.txt | 33 +++++++++++ 6 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/vcmi/commands/HelpCommand.java create mode 100644 src/main/resources/readme.txt diff --git a/src/main/java/com/vcmi/commands/HelpCommand.java b/src/main/java/com/vcmi/commands/HelpCommand.java new file mode 100644 index 0000000..e4278ed --- /dev/null +++ b/src/main/java/com/vcmi/commands/HelpCommand.java @@ -0,0 +1,26 @@ +package com.vcmi.commands; + +import com.vcmi.config.Lang; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import java.util.List; + +public class HelpCommand implements SimpleCommand { + + @Override + public void execute(Invocation invocation) { + CommandSource source = invocation.source(); + if (!hasPermission(invocation)) { + source.sendMessage(Lang.no_perms.get()); + return; + } + + source.sendMessage(Lang.help.get()); + + } + + @Override + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("vcmi.help"); + } +} diff --git a/src/main/java/com/vcmi/config/Lang.java b/src/main/java/com/vcmi/config/Lang.java index e8a7a16..a0151ae 100644 --- a/src/main/java/com/vcmi/config/Lang.java +++ b/src/main/java/com/vcmi/config/Lang.java @@ -17,7 +17,7 @@ public enum Lang { rcon_unknown_error("rcon_unknown_error"), rcon_empty_command("rcon_empty_command"), rcon_invalid_command_or_server("rcon_invalid_command_or_server"), player_time("player_time"), player_not_found("player_not_found"), player_time_other("player_time_other"), player_time_usage("player_time_usage"), player_time_days("player_time_days"), player_time_hours("player_time_hours"), player_time_minutes("player_time_minutes"), player_time_seconds("player_time_seconds"), - modules("modules"); + modules("modules"), help("help"); private final String key; diff --git a/src/main/java/com/vcmi/config/data/LangYAML.java b/src/main/java/com/vcmi/config/data/LangYAML.java index 4b3be86..c066e07 100644 --- a/src/main/java/com/vcmi/config/data/LangYAML.java +++ b/src/main/java/com/vcmi/config/data/LangYAML.java @@ -2,8 +2,10 @@ import com.vcmi.config.Config; import com.vcmi.VCMI; +import com.vcmi.config.Lang; import org.simpleyaml.configuration.file.YamlConfiguration; import org.simpleyaml.configuration.file.YamlFile; + import java.io.File; import java.io.IOException; @@ -35,13 +37,13 @@ public static void reload() { setConfigValue("no_command", "&cNo such command"); setConfigValue("reload", "&aAll configurations reloaded"); - yamlFile.setComment("rcon_manager_reload","Rcon Manager"); + yamlFile.setComment("rcon_manager_reload", "Rcon Manager"); setConfigValue("rcon_manager_reload", "&aConfigurations Rcon Manager reloaded"); setConfigValue("rcon_auth_error", "&6{server}: &cAuthentication Error. Please check your server configuration and ensure the server is available"); setConfigValue("rcon_io_error", "&6{server}: &cIO Error. Please check your server configuration and ensure the server is available"); - setConfigValue( "rcon_unknown_error", "&6{server}: &cUnknown host error. Please check the server IP address configuration"); + setConfigValue("rcon_unknown_error", "&6{server}: &cUnknown host error. Please check the server IP address configuration"); - yamlFile.setComment("rcon_server_reload","Rcon Server"); + yamlFile.setComment("rcon_server_reload", "Rcon Server"); setConfigValue("rcon_server_reload", "&aConfigurations Rcon Server reloaded"); setConfigValue("rcon_connect_notify", "&aRcon connection from: &7[&3&l{address}&7] &aCommand: &3&l{command}"); setConfigValue("rcon_usage", "&6Usage: rcon [server/all/reload] [command]"); @@ -50,28 +52,43 @@ public static void reload() { setConfigValue("rcon_response", "&6{server}: &a{response}"); setConfigValue("rcon_response_empty", "There is no response from the server"); - yamlFile.setComment("bash_usage","Bash Module"); - setConfigValue( "bash_usage", "&6Usage: bash [script/reload] [info/(script args)]"); - setConfigValue( "bash_runner_reload", "&aConfigurations BASH Runner reloaded"); - setConfigValue( "bash_out_script", "{response}"); + yamlFile.setComment("bash_usage", "Bash Module"); + setConfigValue("bash_usage", "&6Usage: bash [script/reload] [info/(script args)]"); + setConfigValue("bash_runner_reload", "&aConfigurations BASH Runner reloaded"); + setConfigValue("bash_out_script", "{response}"); - yamlFile.setComment("php_usage","Php Module"); - setConfigValue( "php_usage", "&6Usage: php [script/reload] [info/(script args)]"); + yamlFile.setComment("php_usage", "Php Module"); + setConfigValue("php_usage", "&6Usage: php [script/reload] [info/(script args)]"); setConfigValue("php_runner_reload", "&aConfigurations PHP Runner reloaded"); - setConfigValue( "php_out_script", "{response}"); + setConfigValue("php_out_script", "{response}"); - yamlFile.setComment("player_time_usage","PlayerTime Module"); - setConfigValue( "player_time_usage", "&6Usage: vptime [Player]"); + yamlFile.setComment("player_time_usage", "PlayerTime Module"); + setConfigValue("player_time_usage", "&6Usage: vptime [Player]"); setConfigValue("player_time", "&aYour game time: {time}"); - setConfigValue( "player_time_other", "&aGame time {player}: {time}"); - setConfigValue( "player_not_found", "&c{player} not found"); - setConfigValue( "player_time_days", " days "); - setConfigValue( "player_time_hours", " hours "); - setConfigValue( "player_time_minutes", " minutes "); - setConfigValue( "player_time_seconds", " seconds "); + setConfigValue("player_time_other", "&aGame time {player}: {time}"); + setConfigValue("player_not_found", "&c{player} not found"); + setConfigValue("player_time_days", " days "); + setConfigValue("player_time_hours", " hours "); + setConfigValue("player_time_minutes", " minutes "); + setConfigValue("player_time_seconds", " seconds "); + + yamlFile.setComment("modules", "Modules"); + setConfigValue("modules", "{module} is {status}"); + + yamlFile.setComment("help", "Help"); + setConfigValue("help", "&6Available commands:" + + "\n&6/vcmi &7- &6Show help." + + "\n&6/vcmireload &7- &6Reload all configurations." + + "\n&6/vcmimodules &7- &6Show all modules." + + "\n&6/vptime &7- &6Returns your total playing time." + + "\n&6/vptime [player] &7- &6Returns the specified player's total playing time." + + "\n&6/rcon [server/all/reload] [command] &7- &6Sends the specified command to the specified server or all servers." + + "\n&6/php [script/reload] [args] &7- &6Executes the specified PHP script." + + "\n&6/bash [script/reload] [args] &7- &6Executes the specified Bash script." + + "\n&6/rules &7- &6Reads the specified text file." + + "\n&6/readme &7- &6Reads the specified text file." + ); - yamlFile.setComment("modules","Modules"); - setConfigValue("modules","{module} is {status}"); yamlFile.save(); @@ -79,6 +96,7 @@ public static void reload() { e.printStackTrace(); } } + private static void setConfigValue(String path, Object defaultValue) { if (!yamlFile.contains(path)) { yamlFile.set(path, defaultValue); diff --git a/src/main/java/com/vcmi/modules/Modules.java b/src/main/java/com/vcmi/modules/Modules.java index b93ba4e..2d813cc 100644 --- a/src/main/java/com/vcmi/modules/Modules.java +++ b/src/main/java/com/vcmi/modules/Modules.java @@ -1,5 +1,6 @@ package com.vcmi.modules; +import com.vcmi.commands.HelpCommand; import com.vcmi.commands.ModulesCommand; import com.vcmi.config.Config; import com.vcmi.Message; @@ -30,6 +31,7 @@ public class Modules { public Modules() { Util.registerCommand("vcmireload", "vreload", new ReloadCommand()); + Util.registerCommand("vcmi", "vcmihelp", new HelpCommand()); Util.registerCommand("vcmimodules", "vmodules", new ModulesCommand()); Message.info("..."); Message.info("VCMI loading modules..."); diff --git a/src/main/java/com/vcmi/modules/text/TextReaderModule.java b/src/main/java/com/vcmi/modules/text/TextReaderModule.java index 2879361..1a61f9b 100644 --- a/src/main/java/com/vcmi/modules/text/TextReaderModule.java +++ b/src/main/java/com/vcmi/modules/text/TextReaderModule.java @@ -17,6 +17,7 @@ public class TextReaderModule { public static void load() { if (dir.toFile().mkdirs()){ Util.copyFile(dir.toString(), "rules.txt"); + Util.copyFile(dir.toString(), "readme.txt"); } Message.info("Text Reader module enabled"); } diff --git a/src/main/resources/readme.txt b/src/main/resources/readme.txt new file mode 100644 index 0000000..2a61082 --- /dev/null +++ b/src/main/resources/readme.txt @@ -0,0 +1,33 @@ +[center]VCMI Plugin +[center]A Velocity Plugin for Comprehensive Server Management + +Modules: + +PlayerTime: +Tracks total playtime. Commands: +- Click to run'>/vptime - Shows your total playtime. +- Click to copy'>/vptime {player} - Shows specified player's playtime. + +RconManager: +Execute RCON commands remotely. +- Click to copy RCON command'>/rcon {server/all/reload} {command} - Command execution. +- Click to run example command'>/rcon all list - Execute example RCON command. + +PhpModule: +Extend functionality with PHP scripts. +- Click to copy PHP command'>/php {script/reload} {args} - Execute PHP scripts. +- Click to run example script'>/php index info - Execute example PHP script. + +BashModule: +Execute Bash scripts from the console or chat. +- Click to copy Bash command'>/bash {script/reload} {args} - Run Bash scripts. +- Click to run example script'>/bash run - Execute example Bash script. + +TextReader: +Read and display text files. +- Click to read rules.txt file'>/rules - Display rules.txt file content. + +HttpRequest: +Perform HTTP requests and command execution based on responses. +- Click to run command'>/linkaccount 12345 - Execute command based on response. +