Help

Discussion in 'Plugin Development' started by xCyanide, Aug 19, 2013.

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

    xCyanide

    Okay, so I created an player sort of object so I can get the players kills and stuff, but if I call it like this PlayerObject player = new PlayerObject(player); it will reset the kills every time. Does anyone know how I can call this object without resetting the kills and stuff?
     
  2. Offline

    Mattredsox

    You shouldn't be making a new PlayerObject every time you want to call it. I would recommend that you do something similar to Bukkit.getPlayer() and save all of the PlayerObjects in a List and access them whenever you need it.

    You may already know this too but you have to save all of the kills in a data/config or MySQL database because it won't be stored when the server reboots.
     
  3. Offline

    xCyanide

    Mattredsox
    I don't want my kills to be saved, but I want to be able to check the players kills for a round and then I want the kills to reset after a round end(This is for a mini-game).
     
  4. Offline

    Mattredsox

    Then all you will need to do is save all of the PlayerObjects that you make in a List and access the PlayerObject from that list when you need it.

    If you need an example with code I would be willing to code something up for you quickly.
     
  5. Offline

    xCyanide

    Mattredsox
    An example code would be nice :D I am still getting the hang of creating objects and using them.
     
  6. Offline

    Mattredsox

    Here is some code for you to work off of:

    Code:java
    1. List<PlayerObject> playerObjects = new ArrayList<PlayerObject>();
    2.  
    3. public void createPlayer(Player player)
    4. {
    5. PlayerObject playerObj = new PlayerObject(player);
    6.  
    7. playerObjects.add(playerObj);
    8. }
    9.  
    10. public PlayerObject getPlayerObject(Player player)
    11. {
    12. for (PlayerObject playerObj : playerObjects)
    13. {
    14. if (playerObj.getPlayer().getName() == player.getName())
    15. {
    16. return playerObj;
    17. }
    18. }
    19. }
     
Thread Status:
Not open for further replies.

Share This Page