/Reply broken

Discussion in 'Spigot Plugin Development' started by LazerShadow, Jun 6, 2015.

  1. I made a /message and /reply command but when I message someone then do /reply it says that I have not messaged anyone. Here is my code maybe someone can find out why.

    Code (Javascript):
    package Commands;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.UUID;

    import me.bubblefat.Main;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;


    public class Message implements CommandExecutor{
       
        private HashMap<UUID, UUID> Person = new HashMap<UUID, UUID>();
        public static List<String> Playerr = new ArrayList<String>();
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("message")) {
               
                Player player = (Player) sender;
               
                if(Main.IsMuted(player, 1)){
                    player.sendMessage(ChatColor.GOLD + "Punish> " + ChatColor.GRAY + "You have been muted by §c" + Main.config.getString(player.getName() + ".Muter") + " §7becuase of §c" + Main.config.getString(player.getName() + ".MuteReason") + "§7 for lifetime.");
                    return true;
                } else {
               
                Player target = Bukkit.getPlayer(args[0]);
               
                if(target !=null) {
                   
                    String message = "";
                    for (int i = 1; i != args.length; i++)
                    message += args[i] + " ";
                   
                    target.sendMessage(ChatColor.GRAY + sender.getName() + ChatColor.DARK_GRAY + " >> §7" + target.getName() + " " + ChatColor.RED + ChatColor.BOLD + message);
                    target.playSound(target.getLocation(), Sound.NOTE_PIANO, 1, 1);
                    player.sendMessage(ChatColor.GRAY + sender.getName() + ChatColor.DARK_GRAY + " >> §7" + target.getName() + " " + ChatColor.RED + ChatColor.BOLD + message);
                    //Person.put(player.getUniqueId(), target.getUniqueId());
                   
                    if(!Playerr.contains(target.getName())){
                        Playerr.add(player.getName());
                    }

                } else {
                    player.sendMessage(ChatColor.GOLD + "Server> " + ChatColor.GRAY + "Could not find player.");
                }
               
                if(args.length == 0) {
                    player.sendMessage(ChatColor.GOLD + "Server> " + ChatColor.GRAY + "Improper usage. " + ChatColor.RED + "/message <player> <message>" + ChatColor.GRAY + ".");
                    return true;
                }
               
                if(args.length == 1) {
                    player.sendMessage(ChatColor.GOLD + "Server> " + ChatColor.GRAY + "Improper usage. " + ChatColor.RED + "/message <player> <message>" + ChatColor.GRAY + ".");
                    return true;
                }
                               
                return true;  
            }
            }
           
            if (cmd.getName().equalsIgnoreCase("reply")) {
                Player player = (Player) sender;
                Player target = (Player) Bukkit.getServer().getPlayer(Person.get(player.getUniqueId()));
               
               
                if(target !=null){
                if(args.length == 0){
                    player.sendMessage(ChatColor.GOLD + "Server> " + ChatColor.GRAY + "Improper usage. " + ChatColor.RED + "/message <player> <message>" + ChatColor.GRAY + ".");
                    return true;
                } else {
                String message = "";
                for (int i = 0; i != args.length; i++)
                message += args[i] + " ";
               
                target.sendMessage(ChatColor.GRAY + sender.getName() + ChatColor.DARK_GRAY + " >> §7" + target.getName() + " " + ChatColor.RED + ChatColor.BOLD + message);
                target.playSound(target.getLocation(), Sound.NOTE_PIANO, 1, 1);
                player.sendMessage(ChatColor.GRAY + sender.getName() + ChatColor.DARK_GRAY + " >> §7" + target.getName() + " " + ChatColor.RED + ChatColor.BOLD + message);
                return true;
                }
                } else {
                    player.sendMessage(ChatColor.GOLD + "Server> §7You have not messaged anyone.");
                    return true;
                }
            }
           
            return false;
        }

    }
     
     
  2. you need to add the uuid's to the Person map, you currently have it commented out
    //Person.put(player.getUniqueId(), target.getUniqueId());
     
    • Agree Agree x 1
    • Informative Informative x 1
  3. I feel stupid for not noticing this, although it still doesn't work...
     
  4. Probably because you'll want to reverse them, the person replying needs to have their id as the key too look up.
    Player pl; = player sending message
    Player player; = player receiving message
    playerMessageMap().put(player.getUniqueID(), pl.getUniqueID());
    that way the reply can look up
    Player pl; = player replying
    playerMessageMap().get(pl.getUniqueID()); would return the person that sent a message to you for reply.
    You are putting them in your map the other way around.