Retrieving a target player from another method

Discussion in 'Spigot Plugin Development' started by DecisionsYT, May 30, 2016.

Thread Status:
Not open for further replies.
  1. Hey!

    In my Punish plugin, you type /punish (Player) (Reason)

    It opens a GUI with one item showing the target player and another item showing the reason. I have 3 items as well. One for kicking the target player. One for muting the player. One for banning the player. In the InventoryClickEvent, what I don't know how to do, is getting that player I typed in when I did /punish (Player) (Reason) in the onCommand method and do some stuff with it from there. Any suggestions??

    - DecisionsYT
    • Funny Funny x 1
  2. You'll want to store that player in a new instance of your PunishGUI class (or whatever you choose to call it) whenever a player with the right permissions types /punish.

    If you don't already have a separate class for your GUI, make one! It will make organizing your code much easier.
  3. I do.
  4. maybe try something like this?

    Code (Text):
    Player targetplayer = Bukkit.getPlayer(args[1]);
    Then you have the targetplayer.
  5. I have that.

    For getting the target person.

    Player target = Bukkit.getServer().getPlayerExact(args[0]);
  6. That wasn't the question, also it would be args[0] ;)
    • Agree Agree x 1
  7. Do you have any suggestions??
  8. Just store the stuff in the inventory when the sender types the command. Then if the inventory closes remove the player. If someone clicks on it get the person from the hashmap and kick them.

    Hashmap should store string uuid of opener (guy who wants to kick them) and the string uuid of who they typed in.
  9. I don't understand that? Isn't there a way to get the target from like this
  10. K so

    Two players:
    Admin - guy who wants to kick Bob
    Bob - guy who is being kicked

    Admin types /punish Bob being bad

    This does two main things:
    - First it opens an inventory
    - Second it store the sender and Bob into a hashmap. So the hashmap looks like this

    Admin - Bob

    Now you make an inventory click event. You do all your checks for the inventory items to make sure it is a punish inventory.

    Then you do

    Code (Text):
    if (hashmap.containsKey(personWhoClicked.getUniqueID()) {
        Player admin = personWhoClicked;
        Player bob = Bukkit.getPlayer(hashmap.get(Bob));

    Then remove them and also remove them on inventory close.
  11. So how would you remove the player??
  12. hashmap.remove(admin, Bob);

    If you don't know basic things like hashmap you should stop and go learn Java fully
    • Like Like x 1
    • Agree Agree x 1
Thread Status:
Not open for further replies.