diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java index 59561eb94..91670f017 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.UUID; import org.bukkit.Location; import org.bukkit.Material; @@ -19,6 +20,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import mineplex.core.Managers; @@ -66,7 +68,7 @@ public class CakeShopModule extends CakeModule private final Map _npcs; private final CakeResourceShop _shop; private final Map> _items; - private final Map> _ownedItems; + private final Map> _ownedItems; private final Map> _ownedTeamItems; public CakeShopModule(CakeWars game) @@ -126,8 +128,6 @@ public class CakeShopModule extends CakeModule entity.setCustomNameVisible(true); } - team.GetPlayers(false).forEach(player -> _ownedItems.put(player, new HashSet<>())); - _ownedTeamItems.put(team, new HashSet<>()); }); @@ -268,10 +268,20 @@ public class CakeShopModule extends CakeModule @EventHandler public void playerDeath(PlayerDeathEvent event) { - Player player = event.getEntity(); - Set items = _ownedItems.get(player); + onDeath(event.getEntity()); + } - if (items != null && !_game.getCakePlayerModule().isUsingRuneOfHolding(player)) + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + onDeath(event.getPlayer()); + } + + private void onDeath(Player player) + { + Set items = getOwnedItems(player); + + if (!_game.getCakePlayerModule().isUsingRuneOfHolding(player)) { items.removeIf(item -> !item.getItemType().isOnePerTeam()); } @@ -279,7 +289,7 @@ public class CakeShopModule extends CakeModule public boolean ownsItem(Player player, CakeItem item) { - return _ownedItems.get(player).contains(item); + return getOwnedItems(player).contains(item); } public boolean ownsItem(GameTeam team, CakeItem item) @@ -289,7 +299,7 @@ public class CakeShopModule extends CakeModule public Set getOwnedItems(Player player) { - return _ownedItems.get(player); + return _ownedItems.computeIfAbsent(player.getUniqueId(), k -> new HashSet<>()); } public Set getOwnedItems(GameTeam team)