Ping Plugin | Need Help

Discussion in 'Plugin Development' started by ImHaste, Aug 29, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    ImHaste

    Hey guys! So Im kinda new to this coding stuff and tried to make a plugin that basically pings a player.
    I wanted it so that when someone types /ping it says what your ping is and when you type /ping <player> it gives you the ping of that specific player.

    Here's my code:
    Code:
    package me.pixel;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
       
        public void onEnable() {
            Bukkit.getServer().getConsoleSender().sendMessage("Ping Me is now enabled.");
        }
       
        public void onDisable() {
            Bukkit.getServer().getConsoleSender().sendMessage("Ping Me is nog disabled.");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(!(sender instanceof Player)){
                sender.sendMessage("You are not a player.");
            }
           
            Player player = (Player) sender;
            int p = ((CraftPlayer) player).getHandle().ping;
            if(cmd.getName().equalsIgnoreCase("Ping")){
                if(args.length> 0);
                player.sendMessage(ChatColor.GREEN + "Your ping is" + ChatColor.AQUA + p);
                return true;
                }
           
            Player t = Bukkit.getPlayer(args[0]);
            if(args.length> 1);
            if(t == null){
                player.sendMessage(ChatColor.RED + "That player is not online!");
                return true;
                }
            int pp = ((CraftPlayer) t).getHandle().ping;
            if(!(player == null)) {
            player.sendMessage(ChatColor.BLUE + "PING: " + ChatColor.GREEN + pp);
            }
            return false;
        }
        }
    
    Hope someone can tell me where it went wrong
     
  2. Offline

    ImHaste

    Well, when I type /ping, it gives me my ping like I wanted. But when I type /ping <player> it still gives me my ping and not the one from that specific player :/
     
  3. You are checking if the args length is greater than 0
     
  4. @ImHaste
    Ugh, ugly syntaxes lead to placing random semicolons which make the if statements useless
    Code:
    if(args.length> 0);
    Code:
    if(args.length> 1);
     
    MrBlackIsBack likes this.
  5. Didn't even notice that haha
     
  6. @megamichiel I think you need to take a better look at the syntax before doing Bukkit. Your code has some very basic Java issues.
     
Thread Status:
Not open for further replies.

Share This Page