updated to latest Bukkit and Craftbukkit

This commit is contained in:
aPunch 2012-03-01 04:45:44 -06:00
parent b9aa42873f
commit 2ce3e60aa0
9 changed files with 37 additions and 168 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -103,8 +103,8 @@ public class Citizens extends JavaPlugin {
}
NPC npc = null;
if (player != null)
npc = npcManager.getSelectedNPC(player);
if (player != null && player.getMetadata("selected").size() > 0)
npc = npcManager.getNPC(player.getMetadata("selected").get(0).asInt());
try {
commands.execute(split, player, player == null ? sender : player, npc);

View File

@ -137,7 +137,7 @@ public class EventListen implements Listener {
NPC npc = npcManager.getNPC(event.getEntity());
Player player = (Player) event.getTarget();
if (!npcManager.isNPCSelectedByPlayer(player, npc)) {
if (player.getMetadata("selected").size() == 0 || player.getMetadata("selected").get(0).asInt() != npc.getId()) {
if (player.getItemInHand().getTypeId() == Setting.SELECTION_ITEM.asInt()
&& (npc.getTrait(Owner.class).getOwner().equals(player.getName()) || player
.hasPermission("citizens.admin"))) {

View File

@ -1,32 +1,32 @@
package net.citizensnpcs.npc;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.event.NPCSpawnEvent;
import net.citizensnpcs.api.npc.AbstractNPC;
import net.citizensnpcs.api.trait.trait.Inventory;
import net.citizensnpcs.api.trait.trait.SpawnLocation;
import net.citizensnpcs.api.trait.trait.Spawned;
import net.citizensnpcs.npc.ai.CitizensAI;
import net.citizensnpcs.util.Messaging;
import net.minecraft.server.EntityLiving;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public abstract class CitizensNPC extends AbstractNPC {
protected final CitizensNPCManager manager;
protected final CitizensAI ai = new CitizensAI(this);
protected EntityLiving mcEntity;
protected final NPCInventory inventory;
protected final Inventory inventory;
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
super(id, name);
this.manager = manager;
inventory = new NPCInventory(this);
inventory = Bukkit.getServer().createInventory(this, 36, name);
}
@Override
@ -84,11 +84,9 @@ public abstract class CitizensNPC extends AbstractNPC {
@Override
public void remove() {
manager.remove(this);
if (isSpawned())
despawn();
manager.remove(this);
((Citizens) Bukkit.getServer().getPluginManager().getPlugin("Citizens")).getStorage().getKey("npc")
.removeKey(String.valueOf(getId()));
}
@Override
@ -116,16 +114,8 @@ public abstract class CitizensNPC extends AbstractNPC {
@Override
public org.bukkit.inventory.Inventory getInventory() {
return inventory.asInventory();
}
@Override
public boolean openInventory(Player player) {
if (!isSpawned())
return false;
getInventory().setContents(getTrait(Inventory.class).getContents());
inventory.show(player);
return true;
inventory.setContents(getTrait(net.citizensnpcs.api.trait.trait.Inventory.class).getContents());
return inventory;
}
@Override
@ -137,6 +127,5 @@ public abstract class CitizensNPC extends AbstractNPC {
@Override
public void setName(String name) {
super.setName(name);
inventory.setName(name);
}
}

View File

@ -5,6 +5,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.event.NPCSelectEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCManager;
@ -15,20 +16,21 @@ import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.util.ByIdArray;
import net.citizensnpcs.util.NPCBuilder;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
public class CitizensNPCManager implements NPCManager {
private final Citizens plugin;
private final ByIdArray<NPC> npcs = new ByIdArray<NPC>();
private final SetMultimap<Integer, String> selected = HashMultimap.create();
private final Storage saves;
private final NPCBuilder npcBuilder = new NPCBuilder();
public CitizensNPCManager(Storage saves) {
plugin = (Citizens) Bukkit.getPluginManager().getPlugin("Citizens");
this.saves = saves;
}
@ -52,7 +54,7 @@ public class CitizensNPCManager implements NPCManager {
public void despawn(NPC npc, boolean deselect) {
npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation());
if (!deselect)
selected.removeAll(npc.getId());
npc.removeMetadata("selectors", plugin);
npc.getBukkitEntity().remove();
}
@ -85,15 +87,6 @@ public class CitizensNPCManager implements NPCManager {
return npcs;
}
@Override
public NPC getSelectedNPC(Player player) {
for (int id : selected.keySet()) {
if (selected.get(id).contains(player.getName()))
return getNPC(id);
}
return null;
}
@Override
public boolean isNPC(Entity entity) {
return getNPC(entity) != null;
@ -104,39 +97,45 @@ public class CitizensNPCManager implements NPCManager {
return npcs.iterator();
}
@Override
public boolean isNPCSelectedByPlayer(Player player, NPC npc) {
if (!selected.containsKey(npc.getId()))
return false;
return selected.get(npc.getId()).contains(player.getName());
}
public void remove(NPC npc) {
if (npc.isSpawned())
npc.getBukkitEntity().remove();
npcs.remove(npc.getId());
saves.getKey("npc").removeKey(String.valueOf(npc.getId()));
selected.removeAll(npc.getId());
// Remove metadata from selectors
if (npc.hasMetadata("selectors"))
for (MetadataValue value : npc.getMetadata("selectors"))
if (Bukkit.getPlayer(value.asString()) != null)
Bukkit.getPlayer(value.asString()).removeMetadata("selected", plugin);
npc.removeMetadata("selectors", plugin);
}
public void removeAll() {
while (iterator().hasNext()) {
NPC npc = iterator().next();
saves.getKey("npc").removeKey(String.valueOf(npc.getId()));
selected.removeAll(npc.getId());
// Remove metadata from selectors
if (npc.hasMetadata("selectors"))
for (MetadataValue value : npc.getMetadata("selectors"))
if (Bukkit.getPlayer(value.asString()) != null)
Bukkit.getPlayer(value.asString()).removeMetadata("selected", plugin);
npc.removeMetadata("selectors", plugin);
if (npc.isSpawned())
npc.getBukkitEntity().remove();
iterator().remove();
}
}
@Override
public void selectNPC(Player player, NPC npc) {
// Remove existing selection if any
NPC existing = getSelectedNPC(player);
if (existing != null)
selected.get(existing.getId()).remove(player.getName());
selected.put(npc.getId(), player.getName());
if (player.hasMetadata("selected"))
player.removeMetadata("selected", plugin);
player.setMetadata("selected", new FixedMetadataValue(plugin, npc.getId()));
npc.setMetadata("selectors", new FixedMetadataValue(plugin, player.getName()));
// Remove editor if the player has one
Editor.leave(player);

View File

@ -1,110 +0,0 @@
package net.citizensnpcs.npc;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.StringHelper;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.IInventory;
import net.minecraft.server.ItemStack;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public class NPCInventory implements IInventory {
private final int size = 36;
private final NPC npc;
private final ItemStack[] contents;
private final Inventory inventory = new CraftInventory(this);
private String name;
public NPCInventory(NPC npc) {
this.npc = npc;
name = StringHelper.parseColors(npc.getFullName());
contents = new ItemStack[size];
}
@Override
public int getSize() {
return contents.length;
}
@Override
public ItemStack getItem(int i) {
return contents[i];
}
@Override
public ItemStack splitStack(int i, int j) {
if (contents[i].count <= j) {
ItemStack itemstack = contents[i];
contents[i] = null;
return itemstack;
} else {
ItemStack itemstack = contents[i].a(j);
if (contents[i].count == 0)
contents[i] = null;
return itemstack;
}
}
@Override
public void setItem(int i, ItemStack itemstack) {
contents[i] = itemstack;
}
@Override
public String getName() {
return name;
}
@Override
public int getMaxStackSize() {
return 64;
}
@Override
public void update() {
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void f() {
}
@Override
public void g() {
// close
org.bukkit.inventory.ItemStack[] bukkitItems = new org.bukkit.inventory.ItemStack[size];
int index = 0;
for (ItemStack item : contents) {
if (item != null)
bukkitItems[index] = new CraftItemStack(item);
index++;
}
npc.getTrait(net.citizensnpcs.api.trait.trait.Inventory.class).setContents(bukkitItems);
}
@Override
public ItemStack[] getContents() {
return contents;
}
public Inventory asInventory() {
return inventory;
}
public void show(Player player) {
((CraftPlayer) player).getHandle().a(this);
}
public void setName(String name) {
this.name = StringHelper.parseColors(name);
}
}

View File

@ -5,7 +5,6 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.NetServerHandler;
import net.minecraft.server.NetworkManager;
import net.minecraft.server.Packet;
import net.minecraft.server.Packet101CloseWindow;
import net.minecraft.server.Packet102WindowClick;
import net.minecraft.server.Packet106Transaction;
import net.minecraft.server.Packet10Flying;
@ -28,14 +27,6 @@ public class NPCNetHandler extends NetServerHandler {
public void a() {
}
@Override
public void a(Packet packet) {
}
@Override
public void a(Packet101CloseWindow packet) {
}
@Override
public void a(Packet102WindowClick packet) {
}