Multiple Questions!!!

Discussion in 'Plugin Development' started by BurnerDiamond, Dec 31, 2014.

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

    BurnerDiamond

    I'm trying to make a kitpvp plugin.

    I want to add a scoreboard which holds kills/deaths/points

    Question 1:

    How do I get a player's deaths/kills. I know I can make an integer for the points since it needs subtracting and adding but how do I hold/get players data.

    Question: 2

    How do I GIVE players permissions if they click an item.
    How do I REMOVE players permissions if they click an item.

    I know how to make it happen if he clicks it, but how do I do I GIVE him a permission if he clicks it.

    Basically in quick things thins is my plugin

    1. When a player gets a kill he gets +1 Point
    2. When he he has enough points and he clicks something, he can upgrade.
    3. If he can click the button(has the perms), it takes away a certain amount of points and that's it.
     
  2. Offline

    SuchSwegMuchWow

    @BurnerDiamond
    1) Use a HashMap to store player stats and on disable save HashMap to config file
    2) You can use Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "your command to add permission");
     
  3. Offline

    BurnerDiamond

    Do you have any tutorials for HashMaps which I could use?

    Also how would I do it
     
  4. Offline

    BurnerDiamond

    Could I have an example of the HashMap I would use?

    For example:

    I need to store player deaths/points/kills

    I need just an example nothing else.
     
  5. @BurnerDiamond
    Creating HashMaps:
    HashMap<Player, Integer> deaths = new HashMap<Player, Integer>();
    HashMap<Player, Integer> points = new HashMap<Player, Integer>();
    HashMap<Player, Integer> kills = new HashMap<Player, Integer>();

    Saving something on HashMaps:
    int po = (Points);
    int d = (Deaths);
    int k = (Kills);

    deaths.put(player, d);
    points.put(player, po);
    kills.put(player, k);

    Obtaining something from HashMaps:
    int d = deaths.get(player);
    int po = points.get(player);
    int k = kills.get(player);
     
  6. Offline

    BurnerDiamond

    Thanks, and how would I set an integer...

    as in

    get(k) - 1000 = new(int k)

    is it possible?

    @Juancomaster1998

    Do you mean "points" or "Points"???

    I don't know whether it's the points from the HashMap or something else.

    Or int x = (Player.getDeaths)

    Code so far =

    Code:
     public static HashMap<Player, Integer> points = new HashMap<Player, Integer>();
         public static HashMap<Player, Integer> deaths = new HashMap<Player, Integer>();
         public static HashMap<Player, Integer> kills = new HashMap<Player, Integer>();
        
         public static int x = (deaths);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  7. Offline

    SuchSwegMuchWow

    @BurnerDiamond

    Code:
    deaths.put(player.getName(), deaths.get(player.getName()) + 1;
    Basically, your getting players death from HashMap and adding 1 more to it and putting in back into the HashMap
     
  8. Offline

    teej107

    Why are you ignoring Object Oriented Programming and encapsulation?
     
    Konato_K likes this.
  9. Offline

    Flamedek

    @BurnerDiamond One thing, in this case you don't want to store Player objects in the maps.
    Because if someone logs out, the Player object is removed from the game but still in your map, causing it to keep using memory. and this keeps going when players log in log out, which is a memory leak, but can also lead to inproper data (if a player relogs it will be in there twice, causing problems).

    Instead you should store their UUID. So replace all the 'Player' in the maps with 'UUID'.
    Then when you want to store data use player.getUniqueId() to get their UUID.
     
  10. Offline

    teej107

    You don't understand how Maps work don't you? A UUID will still be in the Map when the Player leaves too. What you need to do is make sure that the player gets removed from the Map when the player leaves.
     
  11. Offline

    hexaan

    At this rate we might as well write your whole plugin...

    Try and do some research and ask specific questions. At this point you are just hoping somebody will give you an entire piece of code.
     
  12. Offline

    Flamedek

    @teej107 I do understand how (Hash)Maps work, and these are two seperate things. What I said would defeneatly help when players relog. As they have the same UUID but a diferent Player object.
    However, in this case you could also choose to remove them from the map completly, and just save the data to a file which would indeed be a better option
     
  13. Offline

    Luke_Lax

    This thread is going down hill fast...

    What you want to do is...

    • Listen for the player death event, get the killer get the dead person
    • Understand that hashmaps will be cleared upon a restart so you will want a permanent storage method such as YAML (yml) or SQL (overkill for this)
    • Add the points / whatever to the file
    • Done
    Google is really helpful for basic things like this
     
    mythbusterma likes this.
Thread Status:
Not open for further replies.

Share This Page