Line 35 is causing the error.. (Player target = Bukkit.getServer().getPlayer(args[0]);
Unsure why, the code works but it throws out an error.
Unsure why, the code works but it throws out an error.
Code:
package me.nikk.Fess.commands;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import me.nikk.Fess.utils.Configuration;
public class Ping
implements Listener, CommandExecutor{
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
@SuppressWarnings("unused")
Player player = (Player)sender;
if (cmd.getName().equalsIgnoreCase("ping")){
if(sender instanceof Player)
{
Player p = (Player)sender;
if(p.hasPermission("fess.ping"))
{
int ping = ((CraftPlayer) sender).getHandle().ping;
p.sendMessage("");
p.sendMessage(Configuration.pluginprefix + ChatColor.GREEN + " Your ping is " + ChatColor.YELLOW + ping);
p.sendMessage("");
}
if (args.length == 0);
{
Player target = Bukkit.getServer().getPlayer(args[0]);
if (target == null)
{
sender.sendMessage(Configuration.pluginprefix + " " + ChatColor.DARK_RED + "Player cannot be found!");
}
int tping = ((CraftPlayer) target).getHandle().ping;
p.sendMessage("");
p.sendMessage(Configuration.pluginprefix + ChatColor.YELLOW + " " + target.getName() + ChatColor.GREEN + "'s ping is " + ChatColor.YELLOW + tping);
p.sendMessage("");
}
}
else
{
sender.sendMessage(Configuration.pluginprefix + " " + Configuration.nopermission);
}
}
else
{
sender.sendMessage(Configuration.pluginprefix + ChatColor.RED + "This is a ingame command! Join to use this.");
}
return false;
}
}
