Plugin Help Message Reply

Discussion in 'Plugin Help/Development/Requests' started by bubblefat_, Jan 27, 2015.

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

    bubblefat_

    How do you make a /r or /reply command for a /msg. I know it has to do something with HashMaps but I don't know much about them so Ill need code.
     
  2. Offline

    pie_flavor

    @bubblefat_ Simple really. Make a HashMap<UUID, UUID> somewhere it can be easily accessed. When someone does msg, store their UUID under the recipient's UUID. So map.put(recipient.getUniqueId(), sender.getUniqueId()). Then just use get(recipient.getUniqueId()) to get the UUID of the player who sent the message.
     
  3. Offline

    bubblefat_

    @pie_flavor

    I am doing something wrong. It come up with an error for sender.getUniqueId().

    Code:
        public Map<String, String> lastRecieved = new HashMap<String, String>();
       
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("message")) {
               
                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);
                    sender.sendMessage(ChatColor.GRAY + sender.getName() + ChatColor.DARK_GRAY + " >> §7" + target.getName() + " " + ChatColor.RED + ChatColor.BOLD + message);
                    Map.put(target.getUniqueId(), sender.getUniqueId());
     
  4. Offline

    pie_flavor

    sender is a CommandSender, not a Player necessarily, so you would need to cast it to player first. Also, your HashMap is of type String, String. Make it of type UUID, UUID.
     
  5. Offline

    bubblefat_

    @pie_flavor Im not sure if Im doing this right, so could you take this code and make it work?

    Code:
        public Map<UUID, UUID> lastRecieved = new HashMap<UUID, UUID>();
       
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("message")) {
               
                Player target = Bukkit.getPlayer(args[0]);
                Player player = (Player) sender;
               
                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);
                    sender.sendMessage(ChatColor.GRAY + sender.getName() + ChatColor.DARK_GRAY + " >> §7" + target.getName() + " " + ChatColor.RED + ChatColor.BOLD + message);
                    Map.put(recipient.getUniqueId(), player.getUniqueId());
     
  6. Offline

    pie_flavor

    @bubblefat_ Don't just copy my code, understand what it does first. You put the name recipient in there, but it doesn't mean anything in the context of your program. Replace it with target. Also, don't type Map.put, type lastReceived.put as the latter option actually means something.
     
  7. Offline

    bubblefat_

    @pie_flavor Does this look good?

    Code:
        public Map<UUID, UUID> lastRecieved = new HashMap<UUID, UUID>();
        private Map<UUID, UUID> lastReceived;
       
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
          
            if (cmd.getName().equalsIgnoreCase("message")) {
              
                Player target = Bukkit.getPlayer(args[0]);
                Player player = (Player) sender;
              
                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);
                    sender.sendMessage(ChatColor.GRAY + sender.getName() + ChatColor.DARK_GRAY + " >> §7" + target.getName() + " " + ChatColor.RED + ChatColor.BOLD + message);
                    lastReceived.put(target.getUniqueId(), player.getUniqueId());
                    
     
  8. Offline

    pie_flavor

  9. Offline

    bubblefat_

    @pie_flavor In the reply command how do I get the player?
     
  10. Offline

    nverdier

    @bubblefat_ Well you would have to store the player's last messagee in a HashMap, and then get it when they use that command...
     
  11. Offline

    pie_flavor

    *sighs inwardly*
     
  12. Offline

    nverdier

  13. Offline

    8jy89hui

    @nverdier you would not need the players last message.... Pie has already explained exactly how to do this..... You dont need to store the messages... Just the sender and the getter
     
  14. Offline

    nverdier

    @8jy89hui Yes. I told you to store the player's last messagee. So the last person they messaged. And no need to store UUIDs, just make sure to remove the players when they disconnect/the server shuts down.
     
Thread Status:
Not open for further replies.

Share This Page