Use a target player from a command to a Listener?

Discussion in 'Plugin Development' started by MistaKewl, Aug 23, 2015.

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

    MistaKewl

    Hey Bukkit community! I'm making a plugin where if you type /stats [Player] a InventoryGUI will pop up showing the players stats, like faction info. I've gotten the target player from when someone types "/stats [Player]" but then how would I grab stuff from the target player in a Listener? Here's my code:
    Code:
                if (cmd.getName().equalsIgnoreCase("stats") && args.length == 1) {
                    if (p.getServer().getPlayer(args[0]) != null) {
                        Player target = getServer().getPlayer(args[0]);
                        p.openInventory(inventory);
    
                    }
                    else {
                        p.sendMessage("Player is not available!");
                    }
                } else {
                    sender.sendMessage("You're not a player");
                }
    
                return true;
            } return true;
        }
        @EventHandler
        public void onOpen(InventoryOpenEvent e) {
            if (((e.getPlayer() instanceof Player)) && (e.getInventory().equals(inventory))) {
                Player p = (Player) e.getPlayer();
            }
        }
    You can see I've put:
    Code:
    Player target = getServer().getPlayer(args[0]);
    What would I do if I wanted to get stuff from that player and use it on the Inventory GUI, how would I do that? Sorry if I'm not being clear enough.
     
  2. Store the player and the target player in a HashMap when opening the gui and remove it when closing it
     
    MistaKewl likes this.
  3. Offline

    MistaKewl

    Sorry, I'm still learning java itself, and don't know too much, how would I go around doing that?
    and thanks for the reply.
     
  4. Offline

    SuperSniper

    .
     
    Last edited: Aug 23, 2015
  5. Offline

    MistaKewl

    Thanks but I can't use hashmap.add?

    EDIT: Nevermind, thanks I think I did it.
     
  6. That's why spoonfeeding is bad. Especially when it is completely wrong:
    HashMap<K, V> not HashMap<T>
    And the method is: .put(key, value);
     
Thread Status:
Not open for further replies.

Share This Page