put players in array list, remove after 5 deaths, stop the game if array is null

Discussion in 'Plugin Development' started by GayZoTe, Jun 21, 2015.

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

    GayZoTe

    hello bukkit ! it's my first thread and I hope this will not be the last ! i'm french so sorry for the english.. :p

    i've make a mini game plugin (485 lines actually ^^' ) and i block in 1 point..

    i'ts a zombie game, if a player die 5 five times, he go in spectator mode, and he see others players, if all players are in spectator, the game stop.
    but ?.. but my code doesn't work, i don't know why..

    in the join of a player, her UUID are add in an arraylist :

    Code:
    public void Join(PlayerJoinEvent event)
      { 
    Player p = event.getPlayer();
    UUID i = p.getUniqueId();
       array.add(i);
    }
    okay the game start normally, they game... ho ! a player die for the 5 time, okay so we remove her UUID no?

    Code:
    public void onDeath(PlayerMoveEvent event)
      {
       Player p = event.getPlayer();
       World w = p.getWorld();
       Scoreboard board = p.getScoreboard();
       String name = p.getName();
    @SuppressWarnings("deprecation")
    int sc = board.getObjective(DisplaySlot.PLAYER_LIST).getScore(Bukkit.getOfflinePlayer(name)).getScore();
    
    if(sc == 5)
    {
      Player pp = event.getPlayer();
      UUID i = pp.getUniqueId();
      array.remove(i);
      p.setGameMode(GameMode.SPECTATOR);
    }
    }
    (the objective in the player list is the deathcount ^^)
    and he go in spectator mode

    okay, another playermoveevent for check if the array list is null :

    Code:
    public void onmove(PlayerMoveEvent event)
    {
        if(array == null)
        {
    //Functions for stop the game
        }}
    so?? so the function for go in spectator mode when i die 5 times work, but, i'm single and the game don't stop.
    so what the fuck ? x'D

    (i've created a function if a player quit, her uuid are deleted)

    please help me :(
     
  2. Offline

    Twisted_Panda

    HashMaps are better than ArrayList if you're checking for deaths, if that is what you're doing.
     
  3. Offline

    caderape

    @GayZoTe After emoving a player from the list, check the size. If it's one, stop the game.
     
  4. Offline

    CD3

    Building on @canderape, the code should be:
    Code:
    public void OnMove(PlayerMoveEvent event){
    
         if (array.length == 1){
              // stopping code here.
         }
    }
    
    What your code is doing is waiting until all players are no longer in the array, meaning that the sole survivor would have to kill themselves to end it.
     
  5. Offline

    Boomer

    you wanted to check on-dying, but used move event...
     
  6. Offline

    GayZoTe

    @Twisted_Panda how i use that ? x'D

    @caderape why one ?

    @Boomer yes, sometimes it buge and it was not until the 6th death

    @CD3 okay so i replace my if by the (array.length == 1) and i'ts work ? i test at 9AM and i say if it's work :D

    ok i understand your idea ( @caderape @CD3 ) are the same xD i've tested and.. array.length doesn't exist.. and
    if(array.size() == 1) are incompatibles types
    EDIT: eclipse troll me it's good, i test
    EDIT2: doesn't work.. but i wan't the game stop if ALL PLAYERS are spectator, not the final player alive i don't know if your understand this :p
    so..? :D

    EDIT by Timtower: merged posts

    bump

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

    GayZoTe

    bump!
     
  8. @GayZoTe Arrays and ArrayLists are very different things - you're using an ArrayList here, yet have confused some and made them thought that you're using an array :) Also, a list doesn't become "null" when it's empty, it simply becomes and empty (size 0) list. What exactly are you having issue with?
     
    nlthijs48 likes this.
  9. Offline

    GayZoTe

    i've dropped the idea of array and arraylist, i've thought was a stupid thing : create a public static int, put the number of players online when the game start, if a player die, remove 1 in the int, and check if the int is equal to 1 !
    i'ts work, but the code to get online players
    for(Player online : Bukkit.getOnlinePlayers())
    i think is bad, i've put a code to teleport all players to the hub in a player move event, and only the player of the event are teleported..
    if you solve this problem, this game and another game i've made are finally good, so help me :(
    EDIT: the problems are : only one player are teleported to another server (bungeecord), and it's not if all players are dead, only one player ..

    Code:
    for(Player online : Bukkit.getServer().getOnlinePlayers()){
                    if(Timer == 0) //if party has started
                    {
    if(players == 0) //if all players are dead
    {
                        Player p = event.getPlayer();
                            World w = p.getWorld();
                            Location loc = new Location (w, -1192, 37, 1061);
                            online.teleport(loc);
                            w.setSpawnLocation(-1192, 37, 1061);
                            online.getInventory().clear();
                            online.playSound(loc, Sound.SPLASH, 1, 0);
                            sendTitle(online,  "\u00A79\u00A7LPartie terminée !", "");
                            online.setAllowFlight(false);
                            online.setGameMode(GameMode.SURVIVAL);
                            String na1me  = online.getName();
                            Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
                            ByteArrayDataOutput out = ByteStreams.newDataOutput();
                            out.writeUTF("Connect");
                            out.writeUTF("hub");
                            online.sendPluginMessage(this, "BungeeCord", out.toByteArray());
                       
                            Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "reload");
                            Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard objectives remove Kills");
                            Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard objectives remove PV");
                            Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard objectives remove Morts");
                            Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "difficulty 0");
    
                    }
    so problems :

    - all functions are only in one player
    - all functions start if one player dead, not all players

    EDIT by Timtower: merged posts

    bump, there is all class http://pastebin.com/wMzsBmhz :(

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

    Twisted_Panda

    Your code doesn't really make since to me and I don't know why you're giving your main class 2 instances.
    Just add everyone into an arraylist
    Code:
    ArrayList<String> players = new ArrayList<String>();
    Remove if they died or what ever, check if the size of the players = 0. and so forth
     
  11. Offline

    GayZoTe

    how i add players ? and remove ? (i say that for don't make a wrong code)
     
  12. Offline

    Twisted_Panda

    Have you actually looked into it..

    Code:
    urArray.add(arg0)
    urArray.remove(arg0)
    urArray.size()
     
  13. Offline

    GayZoTe

    the array list must be a static variable .. i add static ?
    and, how can i get online players in int ?
     
  14. Offline

    Twisted_Panda

    Learn basic java first, it would be a big help..
    public static ArrayList

    Add everyone online and ready to play add to arraylist. Loop threw it check if their online get size of the arraylist and there you go online players
     
  15. Basic Java would dictate it not be a public static field, though :)
     
  16. Offline

    Twisted_Panda

    [​IMG]
     
  17. Offline

    GayZoTe

    i've paste your stuff, i've widely the bases of the java :)
    i'm french, and seriously i don't understand..
     
  18. Online

    timtower Administrator Administrator Moderator

    Locked
    Bungeecord requires offline mode, offline mode is not supported.
     
Thread Status:
Not open for further replies.

Share This Page