mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 18:45:29 +01:00
updated to latest Bukkit and Craftbukkit
This commit is contained in:
parent
b9aa42873f
commit
2ce3e60aa0
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -103,8 +103,8 @@ public class Citizens extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NPC npc = null;
|
NPC npc = null;
|
||||||
if (player != null)
|
if (player != null && player.getMetadata("selected").size() > 0)
|
||||||
npc = npcManager.getSelectedNPC(player);
|
npc = npcManager.getNPC(player.getMetadata("selected").get(0).asInt());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
commands.execute(split, player, player == null ? sender : player, npc);
|
commands.execute(split, player, player == null ? sender : player, npc);
|
||||||
|
@ -137,7 +137,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.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()
|
if (player.getItemInHand().getTypeId() == Setting.SELECTION_ITEM.asInt()
|
||||||
&& (npc.getTrait(Owner.class).getOwner().equals(player.getName()) || player
|
&& (npc.getTrait(Owner.class).getOwner().equals(player.getName()) || player
|
||||||
.hasPermission("citizens.admin"))) {
|
.hasPermission("citizens.admin"))) {
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
package net.citizensnpcs.npc;
|
package net.citizensnpcs.npc;
|
||||||
|
|
||||||
import net.citizensnpcs.Citizens;
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
||||||
import net.citizensnpcs.api.event.NPCSpawnEvent;
|
import net.citizensnpcs.api.event.NPCSpawnEvent;
|
||||||
import net.citizensnpcs.api.npc.AbstractNPC;
|
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.SpawnLocation;
|
||||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.npc.ai.CitizensAI;
|
import net.citizensnpcs.npc.ai.CitizensAI;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
|
|
||||||
import net.minecraft.server.EntityLiving;
|
import net.minecraft.server.EntityLiving;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
public abstract class CitizensNPC extends AbstractNPC {
|
public abstract class CitizensNPC extends AbstractNPC {
|
||||||
protected final CitizensNPCManager manager;
|
protected final CitizensNPCManager manager;
|
||||||
protected final CitizensAI ai = new CitizensAI(this);
|
protected final CitizensAI ai = new CitizensAI(this);
|
||||||
protected EntityLiving mcEntity;
|
protected EntityLiving mcEntity;
|
||||||
protected final NPCInventory inventory;
|
protected final Inventory inventory;
|
||||||
|
|
||||||
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
|
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
inventory = new NPCInventory(this);
|
inventory = Bukkit.getServer().createInventory(this, 36, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,11 +84,9 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
|
manager.remove(this);
|
||||||
if (isSpawned())
|
if (isSpawned())
|
||||||
despawn();
|
despawn();
|
||||||
manager.remove(this);
|
|
||||||
((Citizens) Bukkit.getServer().getPluginManager().getPlugin("Citizens")).getStorage().getKey("npc")
|
|
||||||
.removeKey(String.valueOf(getId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,16 +114,8 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public org.bukkit.inventory.Inventory getInventory() {
|
public org.bukkit.inventory.Inventory getInventory() {
|
||||||
return inventory.asInventory();
|
inventory.setContents(getTrait(net.citizensnpcs.api.trait.trait.Inventory.class).getContents());
|
||||||
}
|
return inventory;
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean openInventory(Player player) {
|
|
||||||
if (!isSpawned())
|
|
||||||
return false;
|
|
||||||
getInventory().setContents(getTrait(Inventory.class).getContents());
|
|
||||||
inventory.show(player);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -137,6 +127,5 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
@Override
|
@Override
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
super.setName(name);
|
super.setName(name);
|
||||||
inventory.setName(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ import java.util.Collection;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.citizensnpcs.Citizens;
|
||||||
import net.citizensnpcs.api.event.NPCSelectEvent;
|
import net.citizensnpcs.api.event.NPCSelectEvent;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.api.npc.NPCManager;
|
import net.citizensnpcs.api.npc.NPCManager;
|
||||||
@ -15,20 +16,21 @@ import net.citizensnpcs.editor.Editor;
|
|||||||
import net.citizensnpcs.util.ByIdArray;
|
import net.citizensnpcs.util.ByIdArray;
|
||||||
import net.citizensnpcs.util.NPCBuilder;
|
import net.citizensnpcs.util.NPCBuilder;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import com.google.common.collect.HashMultimap;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import com.google.common.collect.SetMultimap;
|
|
||||||
|
|
||||||
public class CitizensNPCManager implements NPCManager {
|
public class CitizensNPCManager implements NPCManager {
|
||||||
|
private final Citizens plugin;
|
||||||
private final ByIdArray<NPC> npcs = new ByIdArray<NPC>();
|
private final ByIdArray<NPC> npcs = new ByIdArray<NPC>();
|
||||||
private final SetMultimap<Integer, String> selected = HashMultimap.create();
|
|
||||||
private final Storage saves;
|
private final Storage saves;
|
||||||
private final NPCBuilder npcBuilder = new NPCBuilder();
|
private final NPCBuilder npcBuilder = new NPCBuilder();
|
||||||
|
|
||||||
public CitizensNPCManager(Storage saves) {
|
public CitizensNPCManager(Storage saves) {
|
||||||
|
plugin = (Citizens) Bukkit.getPluginManager().getPlugin("Citizens");
|
||||||
this.saves = saves;
|
this.saves = saves;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
public void despawn(NPC npc, boolean deselect) {
|
public void despawn(NPC npc, boolean deselect) {
|
||||||
npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation());
|
npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation());
|
||||||
if (!deselect)
|
if (!deselect)
|
||||||
selected.removeAll(npc.getId());
|
npc.removeMetadata("selectors", plugin);
|
||||||
npc.getBukkitEntity().remove();
|
npc.getBukkitEntity().remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,15 +87,6 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
return npcs;
|
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
|
@Override
|
||||||
public boolean isNPC(Entity entity) {
|
public boolean isNPC(Entity entity) {
|
||||||
return getNPC(entity) != null;
|
return getNPC(entity) != null;
|
||||||
@ -104,39 +97,45 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
return npcs.iterator();
|
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) {
|
public void remove(NPC npc) {
|
||||||
if (npc.isSpawned())
|
if (npc.isSpawned())
|
||||||
npc.getBukkitEntity().remove();
|
npc.getBukkitEntity().remove();
|
||||||
npcs.remove(npc.getId());
|
npcs.remove(npc.getId());
|
||||||
saves.getKey("npc").removeKey(String.valueOf(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() {
|
public void removeAll() {
|
||||||
while (iterator().hasNext()) {
|
while (iterator().hasNext()) {
|
||||||
NPC npc = iterator().next();
|
NPC npc = iterator().next();
|
||||||
saves.getKey("npc").removeKey(String.valueOf(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);
|
||||||
|
|
||||||
if (npc.isSpawned())
|
if (npc.isSpawned())
|
||||||
npc.getBukkitEntity().remove();
|
npc.getBukkitEntity().remove();
|
||||||
iterator().remove();
|
iterator().remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
if (player.hasMetadata("selected"))
|
||||||
if (existing != null)
|
player.removeMetadata("selected", plugin);
|
||||||
selected.get(existing.getId()).remove(player.getName());
|
|
||||||
selected.put(npc.getId(), player.getName());
|
player.setMetadata("selected", new FixedMetadataValue(plugin, npc.getId()));
|
||||||
|
npc.setMetadata("selectors", new FixedMetadataValue(plugin, player.getName()));
|
||||||
|
|
||||||
// Remove editor if the player has one
|
// Remove editor if the player has one
|
||||||
Editor.leave(player);
|
Editor.leave(player);
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,6 @@ import net.minecraft.server.MinecraftServer;
|
|||||||
import net.minecraft.server.NetServerHandler;
|
import net.minecraft.server.NetServerHandler;
|
||||||
import net.minecraft.server.NetworkManager;
|
import net.minecraft.server.NetworkManager;
|
||||||
import net.minecraft.server.Packet;
|
import net.minecraft.server.Packet;
|
||||||
import net.minecraft.server.Packet101CloseWindow;
|
|
||||||
import net.minecraft.server.Packet102WindowClick;
|
import net.minecraft.server.Packet102WindowClick;
|
||||||
import net.minecraft.server.Packet106Transaction;
|
import net.minecraft.server.Packet106Transaction;
|
||||||
import net.minecraft.server.Packet10Flying;
|
import net.minecraft.server.Packet10Flying;
|
||||||
@ -28,14 +27,6 @@ public class NPCNetHandler extends NetServerHandler {
|
|||||||
public void a() {
|
public void a() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void a(Packet packet) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void a(Packet101CloseWindow packet) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void a(Packet102WindowClick packet) {
|
public void a(Packet102WindowClick packet) {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user