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

View File

@ -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<NPC, CakeResource> _npcs;
private final CakeResourceShop _shop;
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;
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<CakeItem> 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<CakeItem> 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<CakeItem> getOwnedItems(Player player)
{
return _ownedItems.get(player);
return _ownedItems.computeIfAbsent(player.getUniqueId(), k -> new HashSet<>());
}
public Set<CakeItem> getOwnedItems(GameTeam team)