added temporary selection API until Bukkit adds metadata

This commit is contained in:
aPunch 2012-02-14 05:45:50 -06:00
parent 7d8f0fb9bb
commit 958751f61f
3 changed files with 5 additions and 2 deletions

Binary file not shown.

View File

@ -89,7 +89,7 @@ public class EventListen implements Listener {
NPC npc = npcManager.getNPC(event.getEntity()); NPC npc = npcManager.getNPC(event.getEntity());
Player player = (Player) event.getTarget(); Player player = (Player) event.getTarget();
if (!npcManager.npcIsSelectedByPlayer(player, npc)) { if (!npcManager.isNPCSelectedByPlayer(player, npc)) {
if (player.hasPermission("citizens.npc.select") if (player.hasPermission("citizens.npc.select")
&& player.getItemInHand().getTypeId() == Setting.SELECTION_ITEM.asInt() && player.getItemInHand().getTypeId() == Setting.SELECTION_ITEM.asInt()
&& npc.getTrait(Owner.class).getOwner().equals(player.getName())) { && npc.getTrait(Owner.class).getOwner().equals(player.getName())) {

View File

@ -86,6 +86,7 @@ public class CitizensNPCManager implements NPCManager {
return npcs; return npcs;
} }
@Override
public NPC getSelectedNPC(Player player) { public NPC getSelectedNPC(Player player) {
for (int id : selected.keySet()) { for (int id : selected.keySet()) {
if (selected.get(id).contains(player.getName())) if (selected.get(id).contains(player.getName()))
@ -104,7 +105,8 @@ public class CitizensNPCManager implements NPCManager {
return npcs.iterator(); return npcs.iterator();
} }
public boolean npcIsSelectedByPlayer(Player player, NPC npc) { @Override
public boolean isNPCSelectedByPlayer(Player player, NPC npc) {
if (!selected.containsKey(npc.getId())) if (!selected.containsKey(npc.getId()))
return false; return false;
return selected.get(npc.getId()).contains(player.getName()); return selected.get(npc.getId()).contains(player.getName());
@ -118,6 +120,7 @@ public class CitizensNPCManager implements NPCManager {
selected.removeAll(npc.getId()); selected.removeAll(npc.getId());
} }
@Override
public void selectNPC(Player player, NPC npc) { public void selectNPC(Player player, NPC npc) {
// Remove existing selection if any // Remove existing selection if any
NPC existing = getSelectedNPC(player); NPC existing = getSelectedNPC(player);