Fix combat NPC issues

- Cashed out players were treated as combat-logged players
- Player inventories were not cleared before returning items, resulting
  in duplicated items
- Players would be given the "locked slot" item
- Allow multiple stacks of the same type and amount
This commit is contained in:
cnr 2017-02-24 05:49:10 -06:00
parent 68f61bbb20
commit 3858421194
3 changed files with 24 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package mineplex.gemhunters.death.npc;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -24,6 +25,7 @@ import mineplex.core.disguise.DisguiseManager;
import mineplex.core.hologram.HologramManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class NPCManager extends MiniPlugin
@ -39,6 +41,7 @@ public class NPCManager extends MiniPlugin
private Set<CombatLogNPC> _logoutNpcs;
private Set<Integer> _toKillIds;
private Set<UUID> _cashedOutPreventNPCs = new HashSet<>();
private HologramManager _hologramManager;
@ -52,6 +55,12 @@ public class NPCManager extends MiniPlugin
_hologramManager = hologramManager;
}
@EventHandler
public void onCashOut(PlayerCashOutCompleteEvent event)
{
_cashedOutPreventNPCs.add(event.getPlayer().getUniqueId());
}
@EventHandler
public void playerQuit(PlayerQuitEvent event)
{
@ -73,7 +82,7 @@ public class NPCManager extends MiniPlugin
public void spawnLogoutNpc(Player player)
{
if (!hasLogoutNpc(player))
if (!_cashedOutPreventNPCs.remove(player.getUniqueId()) && !hasLogoutNpc(player))
{
CombatLogNPC npc = new CombatLogNPC(player, require(DisguiseManager.class), _hologramManager, player.getGameMode().equals(GameMode.CREATIVE));
npc.spawn();

View File

@ -1,7 +1,7 @@
package mineplex.gemhunters.death.npc;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -12,12 +12,14 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import mineplex.gemhunters.loot.InventoryModule;
public class PlayerInfo
{
private String _playerName;
private UUID _playerUuid;
private ItemStack[] _armor;
private Set<ItemStack> _items;
private List<ItemStack> _items;
private Location _location;
public PlayerInfo(Player player)
@ -42,6 +44,7 @@ public class PlayerInfo
{
Player player = getPlayer();
player.getInventory().clear();
player.getInventory().setArmorContents(_armor);
player.getInventory().addItem(_items.toArray(new ItemStack[0]));
player.teleport(_location);
@ -52,11 +55,6 @@ public class PlayerInfo
return _playerName;
}
public Set<ItemStack> getItems()
{
return _items;
}
public UUID getUniqueId()
{
return _playerUuid;
@ -72,20 +70,20 @@ public class PlayerInfo
return Bukkit.getPlayerExact(_playerName);
}
private Set<ItemStack> fetchItems(PlayerInventory inventory)
private List<ItemStack> fetchItems(PlayerInventory inventory)
{
Set<ItemStack> items = new HashSet<ItemStack>();
List<ItemStack> items = new ArrayList<>();
addItems(items, inventory.getContents());
return items;
}
private void addItems(Set<ItemStack> items, ItemStack[] itemsToAdd)
private void addItems(List<ItemStack> items, ItemStack[] itemsToAdd)
{
for (ItemStack item : itemsToAdd)
{
if (item != null && item.getType() != Material.AIR)
if (item != null && item.getType() != Material.AIR && !item.isSimilar(InventoryModule.LOCKED))
{
items.add(item);
}

View File

@ -28,8 +28,8 @@ import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent;
public class InventoryModule extends MiniPlugin
{
public static final ItemStack LOCKED = new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) 15).setTitle(C.cGray + "Locked").build();
private static final int START_INDEX = 9;
private static final ItemStack LOCKED = new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) 15).setTitle(C.cGray + "Locked").build();
private static final String ITEM_METADATA = "UNLOCKER";
private final LootModule _loot;