From 21d8a2f25d3263836e51cfce794e0f1c6f2bda0c Mon Sep 17 00:00:00 2001 From: TubYoub Date: Wed, 1 May 2024 01:27:10 +0200 Subject: [PATCH] Added /cl info command [bugs] / [changes] - added info and help to TabCompleter - added info and help permissions [additions] - plugin.getVerision() - plugin.isNewVersion() [TODO] / PS: report Problems Took 2 hours 7 minutes --- README.md | 5 ++- .../combatlogger/CombatLoggerPlugin.java | 16 ++++++-- .../combatlogger/commands/CLCommand.java | 40 ++++++++++++++++++- .../combatlogger/commands/CLTabCompleter.java | 2 +- src/main/resources/plugin.yml | 6 +++ 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ccec363..ddb71c9 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ This Minecraft Plugin punishes people when they leave the Server while they are - Ally with another Player, so when you hit each-other the Timer won't start `/cl ally` (requires Permission: `combatlogger.ally`, `default: player`) - `/cl ally add ` to add someone as an ally - `/cl ally remove ` to remove an ally -- Help command `/cl help` displays all the commands a player has permission to use +- List Plugin info's using `/cl info` (requires Permission: `combatlogger.info`, `default: player`) +- Help command `/cl help` displays all the commands a player has permission to use (requires Permission: `combatlogger.help`, `default: player`) ## Permission - `combatlogger.start`: Allows players to start combat for a specific player (`default: op`) - `combatlogger.stop`: Allows players to stop combat for a specific player (`default: op`) @@ -39,6 +40,8 @@ This Minecraft Plugin punishes people when they leave the Server while they are - `combatlogger.settimer`: Allows players to set the combat timer (`default: op`) - `combatlogger.reload`: Allows Players to reload the config and allys (`default: op`) - `combatlogger.ally`: Allows players to ally with other players (`default: player`) +- `combatlogger.info`: Allows Players to use the info command (`default: player`) +- `combatlogger.help`: Allows Players to use the help command (`default: player`) ## Installation To install the plugin, simply download the latest release file and place it in your server's plugins folder. Then, restart your server. ## Support diff --git a/src/main/java/dev/pluginz/combatlogger/CombatLoggerPlugin.java b/src/main/java/dev/pluginz/combatlogger/CombatLoggerPlugin.java index dde259e..42705d2 100644 --- a/src/main/java/dev/pluginz/combatlogger/CombatLoggerPlugin.java +++ b/src/main/java/dev/pluginz/combatlogger/CombatLoggerPlugin.java @@ -37,7 +37,6 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; @@ -66,7 +65,9 @@ public void onEnable() { this.combatManager = new CombatManager(this); if (configManager.isCheckVersion()) { newVersion = VersionChecker.isNewVersionAvailable(version); - this.getLogger().warning("There is a new Version available for BT's CombatLogger"); + if (newVersion) { + this.getLogger().warning("There is a new Version available for BT's CombatLogger"); + } } File allyFile = new File("plugins/CombatLogger/allies.yml"); @@ -86,7 +87,6 @@ public void onEnable() { getCommand("combatlogger").setExecutor(new CLCommand(combatManager,this)); getCommand("combatlogger").setTabCompleter(new CLTabCompleter(this)); - //getCommand("combatLogger".setTabCompleter(new CLTabCompleter()), this); } public CombatManager getCombatManager() { @@ -112,10 +112,20 @@ public void sendPluginMessages(CommandSender sender, String type) { public String getPluginPrefix() { return ChatColor.WHITE + "[" + ChatColor.RED + "BTCL" + ChatColor.WHITE + "] "; } + public String getVersion(){ + return version; + } + public boolean isNewVersion(){ + return newVersion; + } @Override public void onDisable() { configManager.saveConfig(); + this.getLogger().info("-----"); + this.getLogger().info(" "); this.getLogger().warning("If this is a reload please note that this could break the Plugin"); + this.getLogger().info(" "); + this.getLogger().info("-----"); } } diff --git a/src/main/java/dev/pluginz/combatlogger/commands/CLCommand.java b/src/main/java/dev/pluginz/combatlogger/commands/CLCommand.java index 5352c30..893615b 100644 --- a/src/main/java/dev/pluginz/combatlogger/commands/CLCommand.java +++ b/src/main/java/dev/pluginz/combatlogger/commands/CLCommand.java @@ -27,6 +27,8 @@ import dev.pluginz.combatlogger.managers.CombatManager; import dev.pluginz.combatlogger.CombatLoggerPlugin; import dev.pluginz.combatlogger.utils.List; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -49,8 +51,8 @@ public CLCommand(CombatManager combatManager, CombatLoggerPlugin plugin) { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (args.length == 0 || args[0].equalsIgnoreCase("reload")) { - reloadPlugin(sender); + if (args.length == 0) { + sendHelp(sender); return true; } @@ -70,6 +72,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St case "ally": handleAlly(sender, args); return true; + case "info": + infoCommand(sender); + return true; + case "reload": + reloadPlugin(sender); + return true; default: sendHelp(sender); return true; @@ -196,6 +204,33 @@ private void handleAlly(CommandSender sender, String[] args) { sender.sendMessage(plugin.getPluginPrefix() + "Invalid command. Usage: /cl ally "); } } + public void infoCommand(CommandSender sender) { + plugin.sendPluginMessages(sender, "title"); + sender.sendMessage(ChatColor.GREEN + "Author: BTPluginz"); + sender.sendMessage(ChatColor.GREEN + "Version: " + plugin.getVersion()); + if (plugin.getConfigManager().isCheckVersion()) { + if (plugin.isNewVersion()) { + sender.sendMessage(ChatColor.YELLOW + "A new version is available! Update at: " + ChatColor.UNDERLINE + "https://modrinth.com/project/bts-combatlogger"); + } else { + sender.sendMessage(ChatColor.GREEN + "You are using the latest version!"); + } + } else { + sender.sendMessage("Version checking is disabled!"); + } + TextComponent githubLink = new TextComponent(ChatColor.DARK_GRAY + "" + ChatColor.UNDERLINE + "GitHub"); + githubLink.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/BT-Pluginz/CombatLogger")); + githubLink.setUnderlined(true); + sender.spigot().sendMessage(githubLink); + + TextComponent discordLink = new TextComponent(ChatColor.BLUE + "" + ChatColor.UNDERLINE + "Discord"); + discordLink.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://discord.pluginz.dev")); + discordLink.setUnderlined(true); + sender.spigot().sendMessage(discordLink); + + sender.sendMessage("If you have any issues please report them on GitHub or on the Discord."); + plugin.sendPluginMessages(sender,"line"); + + } private void sendHelp(CommandSender sender) { plugin.sendPluginMessages(sender,"title"); if (sender.hasPermission("combatlogger.start") || sender.hasPermission("combatlogger.stop") || sender.hasPermission("combatlogger.list") || sender.hasPermission("combatlogger.settimer") || sender.hasPermission("combatlogger.ally")) { @@ -215,6 +250,7 @@ private void sendHelp(CommandSender sender) { if (sender.hasPermission("combatlogger.ally")){ sender.sendMessage("/cl ally "); } + sender.sendMessage("/cl info - Get Infos about the Plugin"); sender.sendMessage("/cl help - Show this message."); plugin.sendPluginMessages(sender, "line"); } else { diff --git a/src/main/java/dev/pluginz/combatlogger/commands/CLTabCompleter.java b/src/main/java/dev/pluginz/combatlogger/commands/CLTabCompleter.java index a8dcd8a..2395813 100644 --- a/src/main/java/dev/pluginz/combatlogger/commands/CLTabCompleter.java +++ b/src/main/java/dev/pluginz/combatlogger/commands/CLTabCompleter.java @@ -46,7 +46,7 @@ public CLTabCompleter(CombatLoggerPlugin plugin) { @Override public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { List completions = new ArrayList<>(); - List commands = Arrays.asList("start", "stop", "list", "settimer", "ally", "reload"); + List commands = Arrays.asList("start", "stop", "list", "settimer", "ally", "reload", "help", "info"); if (args.length == 1) { for (String cmd : commands) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ef4c508..462bdb4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -28,4 +28,10 @@ permissions: default: op combatlogger.ally: description: Allows players to ally with other players + default: true + combatlogger.help: + description: Allows Players to use the help command + default: true + combatlogger.info: + description: Allows Players to use the info command default: true \ No newline at end of file