From 0e6db230d459c3f476d4ebdfd49d6fe763df7192 Mon Sep 17 00:00:00 2001 From: Business Goose <44676012+business-goose@users.noreply.github.com> Date: Tue, 2 Mar 2021 20:36:25 +0000 Subject: [PATCH] Add ping command (#14) * Add ping command * Add new command to readme * Make command description make sense * Add alpha-sort and a tab. * No longer use CraftBukkit to get the player's ping, and instead use the Player's spigot object. * Make command description shorter --- .gitignore | 1 + README.md | 1 + pom.xml | 2 +- src/main/java/pw/kaboom/extras/Main.java | 2 + .../kaboom/extras/commands/CommandPing.java | 40 +++++++++++++++++++ src/main/resources/plugin.yml | 4 ++ 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/main/java/pw/kaboom/extras/commands/CommandPing.java diff --git a/.gitignore b/.gitignore index f845591..629e03e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ target/ .classpath .project *.iml +.theia/ \ No newline at end of file diff --git a/README.md b/README.md index 824a5bc..2a7e08a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Extras is a Bukkit plugin that that adds extra functionality to the Kaboom serve |/enchantall | | extras.enchantall | Adds every enchantment to a held item| |/jumpscare | /scare | extras.jumpscare | Scares a player| |/kaboom | | extras.kaboom | I wonder...| +|/ping | /ms, /delay | extras.ping | Gets your ping| |/prefix | /rank, /tag | extras.prefix | Changes your tag| |/pumpkin | | extras.pumpkin | Places a pumpkin on a player's head| |/serverinfo | /specs | extras.serverinfo | Shows detailed server information| diff --git a/pom.xml b/pom.xml index 0db46a2..b2c9284 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ com.comphenix.protocol ProtocolLib 4.4.0 - + diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index 367889a..7b5ce72 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -13,6 +13,7 @@ import pw.kaboom.extras.commands.CommandDestroyEntities; import pw.kaboom.extras.commands.CommandEnchantAll; import pw.kaboom.extras.commands.CommandJumpscare; import pw.kaboom.extras.commands.CommandKaboom; +import pw.kaboom.extras.commands.CommandPing; import pw.kaboom.extras.commands.CommandPrefix; import pw.kaboom.extras.commands.CommandPumpkin; import pw.kaboom.extras.commands.CommandServerInfo; @@ -65,6 +66,7 @@ public final class Main extends JavaPlugin { this.getCommand("enchantall").setExecutor(new CommandEnchantAll()); this.getCommand("jumpscare").setExecutor(new CommandJumpscare()); this.getCommand("kaboom").setExecutor(new CommandKaboom()); + this.getCommand("ping").setExecutor(new CommandPing()); this.getCommand("prefix").setExecutor(new CommandPrefix()); this.getCommand("pumpkin").setExecutor(new CommandPumpkin()); this.getCommand("serverinfo").setExecutor(new CommandServerInfo()); diff --git a/src/main/java/pw/kaboom/extras/commands/CommandPing.java b/src/main/java/pw/kaboom/extras/commands/CommandPing.java new file mode 100644 index 0000000..3c6fe14 --- /dev/null +++ b/src/main/java/pw/kaboom/extras/commands/CommandPing.java @@ -0,0 +1,40 @@ +package pw.kaboom.extras.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public final class CommandPing implements CommandExecutor { + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + final Player player = (Player) sender; + final int ping = player.spigot().getPing(); + final int d = (int) Math.floor(ping / 100); + ChatColor highlighting = ChatColor.WHITE; + + switch (d) { + case 0: + highlighting = ChatColor.GREEN; + break; + case 1: + case 2: + case 3: + case 4: + highlighting = ChatColor.YELLOW; + break; + case 5: + highlighting = ChatColor.RED; + break; + default: + if (d > 5) { + highlighting = ChatColor.DARK_RED; + } + break; + } + + player.sendMessage("Your ping is " + highlighting + ping + "ms."); + return true; + } +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8aba82f..e16ae80 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -34,6 +34,10 @@ commands: kaboom: description: I wonder... permission: extras.kaboom + ping: + aliases: [delay, ms] + description: Gets your ping + permission: extras.ping prefix: aliases: [rank, tag] description: Changes your tag