/reply broken

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

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

    bubblefat_

    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:
    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. Offline

    BizarrePlatinum

    @bubblefat_
    You appear to have made your line adding the players to the hashmap a comment.
     
  3. Offline

    bubblefat_

    I feel stupid for not noticing that, although it still doesn't work.
     
  4. Offline

    mine-care

    Carefull with casting! Read my signature
     
  5. Offline

    AdamQpzm

    @bubblefat_ Judging from your code, you are fairly new to Java. Please learn the basics of Java, before trying to make plugins. Bukkit is written in Java, so learning it is compulsory. If you do not learn enough Java, then you will continue to make basics mistakes and will have no idea how to fix them. I would recommend the Oracle tutorials or a Java book. :)
     
Thread Status:
Not open for further replies.

Share This Page