Mini-Game Slots!

Discussion in 'Plugin Development' started by zDubsCrazy, Apr 25, 2014.

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

    zDubsCrazy

    I know that making a complex plugin, of Mini-Game, it's very complicated. But now I have everything in my humble mind, just wanted to know how do I put slots in my arena. For example: Only 15 players may enter the arena, the player number 16, will not be teleported. I hope you can help me!

    Thanks!
     
  2. Offline

    Onlineids

    Whatever method you use to teleport just add the players to a List<Player>, and check each time if it reaches 15 and then make it so it wont let the next person do this.
     
  3. Offline

    zDubsCrazy

    Onlineids
    I was just using it. But precisely in this way:
    Code:java
    1. ArrayList<Player> slots = new ArraryList<Player>();
    2. if(slots.size() < 15) {
    3. // Teleportation Code
    4. } else {
    5. p.sendMessage(ChatColor.RED + "This arena is full.");
    6. }


    And when the player clicks on plate:

    Code:java
    1. @EventHandler
    2. public void onClick(PlayerInteractEvent event) {
    3. if(event.getClickedBlock().getType().equals(Material.SIGN_POST)) {
    4. slots.add(player);
    5. }
    6. }


    Logically in a way somewhat different.
     
  4. Offline

    Onlineids

    Make it List<Player> slots = new ArrayList<Player>();
     
  5. Offline

    Gater12

    zDubsCrazy Onlineids
    Shouldn't store Player objects in a list. It can cause memory leaks unless you know how to use it and track it properly to avoid the memory leak.
     
  6. Offline

    Onlineids

    The way hes using it, it wont.
     
  7. Offline

    zDubsCrazy

    Gater12
    Is there another alternative?
     
  8. Offline

    Gater12

    zDubsCrazy Onlineids
    Just to be safe, change the List type to String and store the player's name instead. No memory leaks no trouble.
     
  9. Offline

    zDubsCrazy

  10. Offline

    Onlineids

    List<Player> doesn't cause memory leaks
     
  11. Offline

    Flybelette

    Code:java
    1. List<Player> inArena = new ArrayList<Player>();
    2.  
    3. @EventHandler
    4. public void onClick(PlayerInteractEvent event) {
    5. if(event.getClickedBlock().getType().equals(Material.SIGN_POST)) {
    6. if(inArena.size() < 16){
    7. inArena.add(event.getPlayer());
    8. //Player teleport
    9. }
    10. else event.getPlayer().sendMessage(ChatColor.RED+"Sorry, you can't join this game !");
    11. }
    12. }
     
  12. Offline

    zDubsCrazy

  13. Offline

    Onlineids

    Why, whats the problem?
     
  14. Offline

    zDubsCrazy

    Flybelette
    It works? I am used this method and not work.
     
  15. Offline

    Flybelette

    Have you register the PlayerInteractEvent ?
     
  16. Offline

    zDubsCrazy

    Onlineids
    Gives an error and nothing happens!
     
  17. Offline

    Gater12

    Onlineids
    zDubsCrazy
    While I do admit, it is faster to store Player objects in a List as you don't you have to get them through Bukkit.getPlayerExact() but ^

    Are you sure you are using it right?
    Code:java
    1. List<String> list = new ArrayList<String>();
    2. list.add(p.getName());
    3. Player listP = Bukkit.getPlayerExact(list.get(0));
     
  18. Offline

    zDubsCrazy

    Flybelette
    Sure!

    Gater12
    This work correctly?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  19. Offline

    Onlineids

    Thats why you remove them on quit....
     
  20. Offline

    Gater12

    zDubsCrazy
    It should... but other methods should also work, too.

    What is the error you said you got?
     
  21. Offline

    zDubsCrazy

    Onlineids
    The way I presented is not working. Has another aternative?
     
  22. Offline

    Flybelette

    Could you give us the error and the code you are using ?
     
  23. Offline

    zDubsCrazy

    Gater12
    A large error in the console and nothing happens! Neither the teleport happens!

    Flybelette
    The code is what I have presented on the topic. The error i am post after, in a little while.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  24. Offline

    Gater12

    zDubsCrazy
    Post the error. The error helps us see what is wrong.
     
  25. Offline

    zDubsCrazy

    Gater12
    I'm already getting it.
     
  26. Offline

    coasterman10

    It's still more reliable to store the player's name or UUID, especially when you want to be able to remember a player after they log out.
     
  27. Offline

    zDubsCrazy

  28. Offline

    coasterman10

    zDubsCrazy Player objects are not a solid representation of a player's identity. When a player quits and logs back on, there is a good chance the new Player object is not the same one as the one they were associated with before they logged out.

    Using String or UUID to identify players will solve many problems.
     
  29. Offline

    zDubsCrazy

Thread Status:
Not open for further replies.

Share This Page