Solved Getting UUID from HashMap

Discussion in 'Plugin Development' started by DuaneTheDev_, Aug 12, 2017.

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

    DuaneTheDev_

    So awhile ago I posted a similar thread on trying to receive the target player's uuid for the InventoryClickEvent. However, when I thought I had a solution it ended up being static abuse. I was recommended a few options but none of them quite worked.

    So I'm searching for a solution. Basically what I'm doing is upon a command I'm storing the UUID of the command runner, and the UUID of the target into a HashMap

    PHP:
    public static HashMap<UUIDUUIDtargetPlayer = new HashMap<UUIDUUID>();
    PHP:
    } else if(args[0].equalsIgnoreCase("admin")) {
                    if(
    player.hasPermission("ap.admin")) {
                        
    Player target Bukkit.getServer().getPlayer(args[1]);       
                         if(
    target == null) {
                             
    sender.sendMessage(punishmental.tag ChatColor.RED "Sorry! I couldn't find that player.");
                             return 
    true;
                         }
                                
    openAdminGUI(playertarget);
                                
    targetPlayer.put(player.getUniqueId(), target.getUniqueId());
                                return 
    true;                     
                   } else {
                       
    player.sendMessage(punishmental.tag ChatColor.RED "Sorry! You don't have the security level to access this command.");
                       return 
    true;
                   }

    Now the issue I'm running into is trying to define the target by retrieving their UUID from the HashMap inside the InventoryClickEvent which I'm quite unsure of how to achieve. So I'm posting this looking for some guidance.

    PHP:
        @EventHandler
           
    public void onInventoryClick(InventoryClickEvent event) {
               if(!
    ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Offline Punish Menu") && !ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Punish Menu") && !ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Admin Menu"))
                       return;
               
    Player player = (Playerevent.getWhoClicked();
               
    event.setCancelled(true);
               if(
    event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR||!event.getCurrentItem().hasItemMeta())  {
                   
    player.closeInventory();
                   return;
               }

              
               if(
    targetPlayer.containsKey(player.getUniqueId())) {
                   
    Player admin = (Playerevent.getWhoClicked();
                   
    //Player target = ???;
                  
                               
    switch (event.getCurrentItem().getType()) {
                              
                               case 
    IRON_SWORD:
                                   
    player.sendMessage("The target is: " target.getName());
                                   
    //kill the target
                                   
    player.closeInventory();
                                   break;
                              
                               default:
                                   
    player.closeInventory();
                                   break;
                              
                               }
                  
                       }
                   }
     
  2. Offline

    Horsey

    Player target = targetPlayer.get(admin.getUniqueId());
    Put that just after you declare admin.

    Now, you haven't specifed if they're in the same class, If they aren't, I suggest you put 'targetPlayer' in the Main class, and pass it by dependency injection (basically by passing the class thru the constructor of other classes), and then you can modify the list, and the changes will be reflected in other classes.
     
  3. Offline

    DuaneTheDev_

    @Horsey

    Oh, I'm embarassed. Haha. Thanks it's working.
     
Thread Status:
Not open for further replies.

Share This Page