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
This commit is contained in:
Business Goose 2021-03-02 20:36:25 +00:00 committed by GitHub
parent 97696ae601
commit 0e6db230d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 1 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ target/
.classpath
.project
*.iml
.theia/

View file

@ -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|

View file

@ -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());

View file

@ -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;
}
}

View file

@ -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