Player name

Discussion in 'Spigot Plugin Development' started by Norrd, Jun 3, 2015.

  1. Hey. I have a plugin where you do /kick <playername> and it opens and inventory with reasons why you might wnat to kick the player. How would I make it so that the player name that is stored as an argument to be taken across to the other class without using a variable. I don;t want to use a variable because when another player uses the command while the other player is still in the inventory it breaks for the other player :/
  2. Inkzzz

    Resource Staff

    So, you're trying to do what exactly? When a player does /kick it opens a gui?
  3. When a player does /kick <playername> it opens a Inventory where they have several reasons (set oin the config) for which they can kick the player for
  4. He wants to make a punishing menu like on Mineplex (/punish [player]). Mineplex does this so that staff don't punish players for the wrong amount of time, as well as so the punishing staff can know how many times the player has been punished before for the same or similar offenses.

    You can always put the players name in the title of the GUI, and some how get the username of that player from the GUI, then pass it on to your method in another class.
  5. Ty @ZyphoirMC
  6. I don't understand why something would be breaking if two people do the command at once. Are you using a lot of static variables?
  7. You could give the item an itemmeta with the playername.
    • Like Like x 1
    • Agree Agree x 1
    • Useful Useful x 1
  8. I'm having a bit of trouble understanding what exactly you are saying in the rest of your post, but why not just give the other class a constructor that takes the Player as an argument?
  9. Right so how I have it at the moment is that the inventory name is set to the player who runs the command. However when I am in the listener class I get the inventory name which is equal to the player getting kicked but the plugin doesn't recognise the player and it isn't working.
    Code (Text):
            String ps = e.getInventory().getName();
            Player p = plugin.getServer().getPlayer(ps);
  10. Makes sense maybe re-read what you just said?

    You wrote:
    > You set the Inventory name to be like the Player who runs the command
    > Listener doesn't work because it reads the Name of the Player who runs the command and not (how you want it) the name of the player you want tp punish.

    You can save the Name of the Player you want to punish in the name of an Item in the Inventory. You can then retreive it with:
    String playername = ChatColor.stripColor(event.getInventory().getItem(<slot number>).getDisplayName());
  11. Thank you! I am sorry if it didn't make sense I am tierd after a long day at school and yeah. Once again sorry and thank you I have never seen or heard of the .stripcolor before so thank you very much!
  12. Sorry to bother you again but the player can still click in their own inventory when in the inventory and I am stuck on how I would prevent that please could you help? Thank you once again!
    #12 Norrd, Jun 4, 2015
    Last edited: Jun 4, 2015
  13. create new inventory.
  14. Wait they can drag items? Make sure you set it as cancelled if the item is null.
  15. I wouldn't really care about that, although it might fix some errors from the console; so there's a advantage for doing that
    Although, it's a /kick plugin, I doubt players would be able to do it and the owner won't really mind if they take an apple etc from the kick menu
  16. They cannot drag items in the inventory but items from their own! Idk how to stop this either... Please help!