ArrayList size/get problem

Discussion in 'Plugin Development' started by Goksi, Apr 23, 2018.

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

    Goksi

    Hi i am trying to make simple pvp event plugin, but when its about to broadcast the winner, code just wont execute. Code: https://pastebin.com/e6rWJ8dV it wont execute from elseif(ostalo ==1), is there some other way to check is it only 1 item in arraylist ? Maybe i am getting player from arraylist wrong ?

    Whole class: https://pastebin.com/Mh5mmrNe
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Goksi Please post your main class, and the Commands class
     
  3. Offline

    Goksi

  4. Offline

    timtower Administrator Administrator Moderator

    @Goksi Try to initialize pvp and cmd in the onEnable, the the plugin is loaded enough to be functional.
    Also please use UUID's instead of Player objects.
     
  5. Offline

    Goksi

    I initialized it in onEnable, method still do not work if its only 1 player in arraylist
     
  6. Offline

    timtower Administrator Administrator Moderator

    Can you print the value of ostalo?
     
  7. Offline

    Goksi

    When pvp event is enabled? (When "igr" arraylist have 2 or more players ?)
    Code:
    [10:18:50 INFO]: GoksiL issued server command: /i dsword 1
    [10:18:55 INFO]: Value of ostalo is 2
    [10:18:55 INFO]: Aertfy was slain by GoksiL
    Code:
    public void onDeath(PlayerDeathEvent e) {
            Player p = e.getEntity();
            int ostalo = cmds.igr.size();
            if(cmds.igr.contains(p)) {
                cmds.igr.remove(p);
                cmds.mrtv.add(p);
                Bukkit.broadcastMessage("Value of ostalo is " + ostalo);
     
  8. Offline

    timtower Administrator Administrator Moderator

    When the method is not working as it should.
     
  9. Offline

    Goksi

    When it needs to announce a winner (when only winner stays in array)
    Code:
    else if(ostalo == 1) {
                Player win = cmds.igr.get(0);
                int x = cmds.pl.getConfig().getInt("spawnX");
                int y = cmds.pl.getConfig().getInt("spawnY");
                int z = cmds.pl.getConfig().getInt("spawnZ");
                World w = win.getWorld();
                Location spawn = new Location(w, x,  y, z);
                win.teleport(spawn);
                this.clearInv(win);
                this.loadInv(win);
                cmds.igr.remove(win);
                cmds.mrtv.clear();
                cmds.event = false;
                Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', cmds.pl.getConfig().getString("win").replaceAll("%igrac%", win.getName())));
                       
            } else return;
     
  10. Offline

    timtower Administrator Administrator Moderator

    @Goksi But what is the value of ostalo when that runs?
     
  11. Offline

    Goksi

    Now i realise its 2 in onDeathEvent but after that it goes to 1, so i must check for it after onDeath event, where should i check for it ?

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 24, 2018
Thread Status:
Not open for further replies.

Share This Page