Code (Java): @Getter @RequiredArgsConstructor public class War { private final List<UUID> teamOne; private final List<UUID> teamTwo; private final WarType warType; private final List<UUID> teamOneAlive; private final List<UUID> teamTwoAlive; @Nullable private final Island winnerIsland; } Code (Java): private void tryPrepareForWar(Set<Queue> queueSet) { for (Queue inQueue : queueSet) { if (inQueue.getUuid().equals(getPlayer().getUniqueId())) continue; getTeamMates().add(getPlayer().getUniqueId()); List<UUID> teamTwo = inQueue.getTeamMates(); teamTwo.add(inQueue.getUuid()); ShardWars.getPlayerQueueManagerMap().get(inQueue.getUuid()).removeFromQueue(); removeFromQueue(); new WarManager(new War(getTeamMates(), teamTwo, getWarType(), getTeamMates(), teamTwo, null)).startWar(); break; } } Code (Java): WarManager warManager = ShardWars.getPlayerWarManagerMap().get(player.getUniqueId()); War war = warManager.getWar(); if (war.getTeamOneAlive().isEmpty()) { warManager.endWar(Core.getInstance().skyblockManager.getIsland(war.getTeamTwo().get(0)), Core.getInstance().skyblockManager.getIsland(war.getTeamOne().get(0))); return; } if (war.getTeamTwoAlive().isEmpty()) { warManager.endWar(Core.getInstance().skyblockManager.getIsland(war.getTeamOne().get(0)), Core.getInstance().skyblockManager.getIsland(war.getTeamTwo().get(0))); return; } I'm using the Spigot API and I'm creating a player verse player type plugin. I'm using lombok for getters and constructors. War#getTeamOne() and War#getTeamTwo() randomly become empty. I print the lists throughout the code and it contains a value, but then just before I do WarManager#endWar(), the list is empty. Nowhere in my project do I remove from either of those lists. Any idea why that is? If you need to see more code, lmk.
Be aware, I didn't look to in deep with your code. Just some notes that may make debugging easier so you can find your issue. Make a team class Have a collection of living players Have a collection of dead players Make methods inside this class to make your life easier, and the code more readable. Add debugging print statements. Like, whenever a player dies say System.out.println("HEY, THIS DUDE IS DEAD") If you still can't find your issue, your should probably send more code. With your debugging statements, you should be able to find where the issue is.
Do you ever replace the list variables with new lists? Are you referencing an incorrect version of your objects, one where the lists have not been initialized?
Code (Java): public void removeFromQueue() { switch (getWarType()) { case ONEVONE: ShardWars.getOneVerseOneQueues().remove(ShardWars.getPlayerQueueMap().get(getPlayer().getUniqueId())); case TWOVTWO: ShardWars.getTwoVerseTwoQueues().remove(ShardWars.getPlayerQueueMap().get(getPlayer().getUniqueId())); case FOURVFOUR: ShardWars.getFourVerseFourQueues().remove(ShardWars.getPlayerQueueMap().get(getPlayer().getUniqueId())); } }
Dunno if that is the reason, but use an Iterator and call Iterator#remove(). You are modifying the set as you are looping, which can cause some weird behavior... Again, not sure if that works
Could you explain what you mean? Like this? Code (Java): for (Iterator<Queue> iterator = queueSet.iterator(); iterator.hasNext(); ) { Queue inQueue = iterator.next();
Code (Java): ShardWars.getPlayerQueueManagerMap().get(inQueue.getUuid()).removeFromQueue(); iterator.remove(); ?
This is confusing since you have two calls to remove something from the queue... Just replace the applicable (one of these) Code (Java): ShardWars.getPlayerQueueManagerMap().get(inQueue.getUuid()).removeFromQueue(); removeFromQueue(); with Code (Java): iterator.remove();
Code (Text): private void tryPrepareForWar(Set<Queue> queueSet) { for (Iterator<Queue> iterator = queueSet.iterator(); iterator.hasNext(); ) { Queue inQueue = iterator.next(); if (inQueue.getUuid().equals(getPlayer().getUniqueId())) continue; List<UUID> teamOne = getTeamMates(); teamOne.add(getPlayer().getUniqueId()); List<UUID> teamTwo = inQueue.getTeamMates(); teamTwo.add(inQueue.getUuid()); WarType warType = getWarType(); ShardWars.getPlayerQueueManagerMap().get(inQueue.getUuid()).removeFromQueue(); iterator.remove(); new WarManager(new War(teamOne, teamTwo, warType, teamOne, teamTwo, null)).startWar(); break; } }