Fix CW shops

This commit is contained in:
Sam 2018-07-23 19:48:02 +01:00 committed by Alexander Meech
parent 1cd7e45c0c
commit a653e66863
1 changed files with 18 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -19,6 +20,7 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.Managers; import mineplex.core.Managers;
@ -66,7 +68,7 @@ public class CakeShopModule extends CakeModule
private final Map<NPC, CakeResource> _npcs; private final Map<NPC, CakeResource> _npcs;
private final CakeResourceShop _shop; private final CakeResourceShop _shop;
private final Map<CakeResource, List<CakeItem>> _items; private final Map<CakeResource, List<CakeItem>> _items;
private final Map<Player, Set<CakeItem>> _ownedItems; private final Map<UUID, Set<CakeItem>> _ownedItems;
private final Map<GameTeam, Set<CakeItem>> _ownedTeamItems; private final Map<GameTeam, Set<CakeItem>> _ownedTeamItems;
public CakeShopModule(CakeWars game) public CakeShopModule(CakeWars game)
@ -126,8 +128,6 @@ public class CakeShopModule extends CakeModule
entity.setCustomNameVisible(true); entity.setCustomNameVisible(true);
} }
team.GetPlayers(false).forEach(player -> _ownedItems.put(player, new HashSet<>()));
_ownedTeamItems.put(team, new HashSet<>()); _ownedTeamItems.put(team, new HashSet<>());
}); });
@ -268,10 +268,20 @@ public class CakeShopModule extends CakeModule
@EventHandler @EventHandler
public void playerDeath(PlayerDeathEvent event) public void playerDeath(PlayerDeathEvent event)
{ {
Player player = event.getEntity(); onDeath(event.getEntity());
Set<CakeItem> items = _ownedItems.get(player); }
if (items != null && !_game.getCakePlayerModule().isUsingRuneOfHolding(player)) @EventHandler
public void playerQuit(PlayerQuitEvent event)
{
onDeath(event.getPlayer());
}
private void onDeath(Player player)
{
Set<CakeItem> items = getOwnedItems(player);
if (!_game.getCakePlayerModule().isUsingRuneOfHolding(player))
{ {
items.removeIf(item -> !item.getItemType().isOnePerTeam()); items.removeIf(item -> !item.getItemType().isOnePerTeam());
} }
@ -279,7 +289,7 @@ public class CakeShopModule extends CakeModule
public boolean ownsItem(Player player, CakeItem item) 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) public boolean ownsItem(GameTeam team, CakeItem item)
@ -289,7 +299,7 @@ public class CakeShopModule extends CakeModule
public Set<CakeItem> getOwnedItems(Player player) public Set<CakeItem> getOwnedItems(Player player)
{ {
return _ownedItems.get(player); return _ownedItems.computeIfAbsent(player.getUniqueId(), k -> new HashSet<>());
} }
public Set<CakeItem> getOwnedItems(GameTeam team) public Set<CakeItem> getOwnedItems(GameTeam team)