forked from kaboomserver/extras
Allow ping command to affect other people (#304)
* Add flat world & allow ping command to affect other people * Finalize worldCreator * Delete world modules * Enforce checkstyle
This commit is contained in:
parent
972b7a7456
commit
192daa0a9b
2 changed files with 28 additions and 11 deletions
|
@ -46,12 +46,12 @@ public final class Main extends JavaPlugin {
|
|||
public void onLoad() {
|
||||
/* Fill lists */
|
||||
Collections.addAll(
|
||||
BlockPhysics.getBlockFaces(),
|
||||
BlockFace.NORTH,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST,
|
||||
BlockFace.EAST,
|
||||
BlockFace.UP
|
||||
BlockPhysics.getBlockFaces(),
|
||||
BlockFace.NORTH,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST,
|
||||
BlockFace.EAST,
|
||||
BlockFace.UP
|
||||
);
|
||||
|
||||
/* Load missing config.yml defaults */
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package pw.kaboom.extras.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
@ -9,9 +10,21 @@ 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);
|
||||
Player target;
|
||||
|
||||
if (args.length == 0) {
|
||||
target = (Player) sender;
|
||||
} else {
|
||||
target = Bukkit.getPlayer(args[0]);
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
sender.sendMessage("Player \"" + args[0] + "\" not found");
|
||||
return true;
|
||||
}
|
||||
|
||||
final int ping = target.spigot().getPing();
|
||||
final int d = (int) Math.floor((float) ping / 100);
|
||||
ChatColor highlighting = ChatColor.WHITE;
|
||||
|
||||
switch (d) {
|
||||
|
@ -34,7 +47,11 @@ public final class CommandPing implements CommandExecutor {
|
|||
break;
|
||||
}
|
||||
|
||||
player.sendMessage("Your ping is " + highlighting + ping + "ms.");
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("Your ping is " + highlighting + ping + "ms.");
|
||||
} else {
|
||||
sender.sendMessage(target.getName() + "'s ping is " + highlighting + ping + "ms.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue