Solved "/cmd <name>" then choose punishment in GUI

Discussion in 'Plugin Development' started by yPedx, Mar 21, 2017.

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

    yPedx

    Hello :D

    I'm VERY curious how people do this.. Let me explain a little more detailed; I'm trying to make a punishGUI, basically you do /punish <name> and then select a punishment in a GUI. But I have no idea how to make the commands inside the GUI affect that specific player..
     
  2. Offline

    N00BHUN73R

    @yPedx
    Hmm, well to achieve this, you obviously need an inventory. You would type /punish player123 and then have that open up your custom gui, I would recommend using a custom InventoryHolder to save the players name. THEN, you listen on the InventoryClickEvent for clicks and run the command based on the item.
     
  3. Offline

    Zombie_Striker

    @yPedx
    1. When a user specifies which player to "punish" (either through another UI or through a command), store the name or uuid of the player. Best place where to store them is in a hashmap.
    2. After that, open the GUI with all the options on how to punish them.
    3. When an option is selected, get the player from the hashmap and punish them.
     
  4. Offline

    yPedx

    The only thing I don't know is, how to store the player's name.

    I'm not that experienced with coding :p But I'll try search up how to make and use hashmaps.
     
  5. Offline

    mehboss

    You need a static variable and a setter if they are in separate classes :p
     
  6. Offline

    Zombie_Striker

    @mehboss
    Don't recommend the static modifier. It does not have to be used in any situation.
     
    mine-care likes this.
  7. Offline

    mine-care

    @Zombie_Striker there it has to in some cases (constant fields across objects) but when it is used, it needs some special care. That is, release all objects pointed-at by static pointers (assign the pointers to null) so that garbage collection can occur.

    Still this statement remains vaigue and -by me- incorrect because it as it stands it defeats Object orientation to some extent... Rather than using static to comunicate between Classes how about using object pointers and references to interact with Objects. :p
     
  8. Offline

    Drkmaster83

  9. Offline

    mehboss

    I read something that said static is for getting variables from other classes. What exactly is this and final used for?


    Sent from my iPhone using Tapatalk
     
  10. Offline

    Caderape2

    @mehboss Constructor can do the same. Static is just an easier way for access to variables and methods.
    But it's a pain for the memory. And bukkit has already too much of static methods.

    Static should be used only for keep a variable safe from instance of the class.
     
  11. Offline

    yPedx

    So;
    HashMap<UUID, Integer> playerScores = new HashMap<UUID, Integer>();
    Is it possible to change this to capture name? If I want to use it in a /ban cmd, does the UUID work? (AdvancedBan) Would it be;
    HashMap<NAME, Integer> playerName= new HashMap<NAME, Integer>();
    I literally have no idea how to do this..

    ! Before you comment "learn Java" or something.. I'm trying.

    EDIT: Wait, I think I've miss understood xD
     
    Last edited: Mar 22, 2017
  12. Offline

    Zombie_Striker

    @yPedx
    If you want to store names, then you should replace UUID/NAME with "String" (Since names are strings). The thing is, players can re-name themselves, so using UUIDs are recommended.
     
  13. Offline

    yPedx

    And you store UUID's with;
    HashMapString playerUUID = new HashMapString();
    ? xD

    Edited.
     
    Last edited: Mar 23, 2017
  14. Offline

    mine-care

    Well static is indeed for accessing CLASS members. Non static however is declaring variables belonging to the perticular Object and not the class.
    Final is a modifier that for variables means that they will only be assigned one value in code and they wont be modifyable after that, for methods it means that they can't be overwritten by a subclass and for classes it means that they can't be superclasses (i.e. a class may not extend a final class)

    static final variables are called constants because they belong to the Class and have a specific value that cant be changed during runtime :)
     
  15. @yPedx Use a UUID, you can easily get the UUID from a name with Bukkit#getPlayer or if they're offline Bukkit#getOfflinePlayer and then just do getUniqueId()
    It is recommended as @Zombie_Striker said.
     
  16. Offline

    yPedx

    The point is, I don't know how to make that code xD :


    I found a page about, but I'm still scratching my head.
     
  17. Offline

    Zombie_Striker

    @yPedx
    To create a hashmap, use
    Code:
    HashMap<KEY,VALUE> hashmap = new HashMap<>();
    Where:
    1. KEY is the class type of what you want the key to be (In this example, use UUID)
    2. Value is the class type of the variable. This will be an Integer.
     
  18. Offline

    yPedx

    Thank you both! I'll try a bit more and see, I'll come back and tell if I got it to work or not.
     
Thread Status:
Not open for further replies.

Share This Page