Skip to content

Commit

Permalink
SpoilPlayerTNTFeature code improvements (#892)
Browse files Browse the repository at this point in the history
SpoilPlayerTNTFeature code improvements
  • Loading branch information
ImYenil authored Oct 31, 2023
1 parent d6f167f commit 8e66b27
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,23 @@ public void onPlace(BlockPlaceEvent event) {
public void inventorySwitch(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
IArena arena = Arena.getArenaByPlayer(player);
if (arena == null || !arena.isPlayer(player) || arena.isSpectator(player)) return;

// Ensure the player is in an arena, is not a spectator, and is indeed a player
if (arena == null || !arena.isPlayer(player) || arena.isSpectator(player)) {
return;
}

boolean hasTnt = player.getInventory().contains(Material.TNT);

if (instance.playersWithTnt.contains(player)) {
if (player.getInventory().contains(Material.TNT)) return;
instance.playersWithTnt.remove(player);
} else if (!instance.playersWithTnt.contains(player)) {
if (!player.getInventory().contains(Material.TNT)) return;
instance.playersWithTnt.add(player);
if (!hasTnt) {
instance.playersWithTnt.remove(player);
}
} else {
if (hasTnt) {
instance.playersWithTnt.add(player);
}
}
}
}
}
}

0 comments on commit 8e66b27

Please sign in to comment.