Work on entities

This commit is contained in:
fullwall 2012-06-23 18:01:28 +08:00
parent 577814d57b
commit 18fba3a5b5
49 changed files with 373 additions and 1768 deletions

View File

@ -55,7 +55,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.2.5-R1.4-SNAPSHOT</version>
<version>1.2.5-R4.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>

View File

@ -15,10 +15,8 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.bukkit.BukkitConverter;
import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.npc.entity.EntityHumanNPC;
import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.Util;
import org.bukkit.Bukkit;
@ -27,8 +25,6 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -81,10 +77,10 @@ public class EventListen implements Listener {
*/
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (!npcRegistry.isNPC(event.getEntity()))
NPC npc = BukkitConverter.toNPC(event.getEntity());
if (npc == null)
return;
NPC npc = npcRegistry.getNPC(event.getEntity());
NPCDamageEvent damageEvent;
if (event instanceof EntityDamageByEntityEvent) {
NPCDamageByEntityEvent damageByEntityEvent = new NPCDamageByEntityEvent(npc, event.getDamage(),
@ -108,19 +104,34 @@ public class EventListen implements Listener {
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (!npcRegistry.isNPC(event.getEntity()))
NPC npc = BukkitConverter.toNPC(event.getEntity());
if (npc == null)
return;
NPC npc = npcRegistry.getNPC(event.getEntity());
npc.despawn();
}
/*
* Player events
*/
@EventHandler
public void onEntityTarget(EntityTargetEvent event) {
if (event.isCancelled() || !npcRegistry.isNPC(event.getEntity()) || !(event.getTarget() instanceof Player))
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
if (!BukkitConverter.isNPC(event.getPlayer()))
return;
NPC npc = npcRegistry.getNPC(event.getEntity());
Player player = (Player) event.getTarget();
((CraftServer) Bukkit.getServer()).getHandle().players.remove(((CraftPlayer) event.getPlayer()).getHandle());
}
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (event.isCancelled())
return;
NPC npc = BukkitConverter.toNPC(event.getRightClicked());
if (npc == null)
return;
Player player = BukkitConverter.toPlayer(event.getPlayer());
// Call right-click event
NPCRightClickEvent rightClickEvent = new NPCRightClickEvent(npc, player);
@ -133,27 +144,6 @@ public class EventListen implements Listener {
npc.getAttachment(Text.class).sendText(player);
}
/*
* Player events
*/
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
if (!(((CraftPlayer) event.getPlayer()).getHandle() instanceof EntityHumanNPC))
return;
((CraftServer) Bukkit.getServer()).getHandle().players.remove(((CraftPlayer) event.getPlayer()).getHandle());
}
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!npcRegistry.isNPC(event.getRightClicked()))
return;
// Call target event for NPCs
Bukkit.getPluginManager().callEvent(
new EntityTargetEvent(event.getRightClicked(), event.getPlayer(), TargetReason.CUSTOM));
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Editor.leave(event.getPlayer().getName());

View File

@ -5,8 +5,12 @@ import net.citizensnpcs.api.abstraction.MobType;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.Entity;
import net.citizensnpcs.api.abstraction.entity.NPCHolder;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.EntityType;
public class BukkitConverter {
@ -40,4 +44,20 @@ public class BukkitConverter {
// TODO Auto-generated method stub
return null;
}
public static NPC toNPC(org.bukkit.entity.Entity entity) {
net.minecraft.server.Entity handle = ((CraftEntity) entity).getHandle();
if (handle instanceof NPCHolder) {
return ((NPCHolder) handle).getNPC();
}
return null;
}
public static boolean isNPC(org.bukkit.entity.Entity entity) {
return toNPC(entity) != null;
}
public static Player toPlayer(org.bukkit.entity.Player player) {
return new BukkitPlayer(player);
}
}

View File

@ -73,4 +73,9 @@ public class BukkitEntity implements Entity {
}
return true;
}
@Override
public boolean isDead() {
return entity.isDead();
}
}

View File

@ -16,6 +16,11 @@ public class BukkitPlayer extends BukkitLivingEntity implements Player {
return getPlayer().getName();
}
@Override
public ItemStack getItemInHand() {
return getEquipment(Equipment.CARRIED);
}
@Override
public boolean hasPermission(String perm) {
return getPlayer().hasPermission(perm);

View File

@ -1,9 +1,9 @@
package net.citizensnpcs.editor;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.EventHandler;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.bukkit.BukkitConverter;
import net.citizensnpcs.bukkit.BukkitPlayer;
import net.citizensnpcs.util.Messaging;
@ -40,8 +40,7 @@ public class EquipmentEditor extends Editor {
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked()))
|| !event.getPlayer().equals(player))
if (!npc.equals(BukkitConverter.toNPC(event.getRightClicked())) || !event.getPlayer().equals(player))
return;
if (npc instanceof Equipable) {

View File

@ -8,6 +8,10 @@ import javax.xml.stream.Location;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityTypes;
import org.bukkit.craftbukkit.CraftWorld;
@SuppressWarnings("unchecked")
public abstract class CitizensMobNPC extends CitizensNPC {

View File

@ -2,10 +2,7 @@ package net.citizensnpcs.npc;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.LivingEntity;
import net.citizensnpcs.api.attachment.Attachment;
import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.event.NPCSpawnEvent;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.AbstractNPC;
import net.citizensnpcs.api.npc.NPCRegistry;
@ -24,39 +21,13 @@ public class CitizensNPC extends AbstractNPC {
super(CitizensAPI.getNPCRegistry(), name);
}
@Override
public boolean despawn() {
if (!isSpawned()) {
Messaging.debug(String.format("The NPC with the ID '%d' is already despawned.", getId()));
return false;
}
CitizensAPI.getServer().callEvent(new NPCDespawnEvent(this));
getEntity().remove();
controller = null;
return true;
}
@Override
protected Attachment getAttachmentFor(Class<? extends Attachment> clazz) {
// TODO Auto-generated method stub
return null;
return CitizensAPI.getAttachmentFactory().getAttachment(clazz);
}
private Attachment getAttachmentFor(String name) {
// TODO Auto-generated method stub
return null;
}
@Override
public LivingEntity getEntity() {
return (LivingEntity) controller.getEntity();
}
@Override
public boolean isSpawned() {
return getEntity() != null;
return CitizensAPI.getAttachmentFactory().getAttachment(name);
}
public void load(DataKey root) {
@ -94,31 +65,6 @@ public class CitizensNPC extends AbstractNPC {
}
}
@Override
public boolean spawn(WorldVector at) {
if (at == null)
throw new IllegalArgumentException("location cannot be null");
if (isSpawned()) {
Messaging.debug("NPC (ID: " + getId() + ") is already spawned.");
return false;
}
NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, at);
CitizensAPI.getServer().callEvent(spawnEvent);
if (spawnEvent.isCancelled())
return false;
controller.spawn(at);
// Set the spawned state
getAttachment(CurrentLocation.class).setLocation(at);
spawned = true;
// Modify NPC using traits after the entity has been created
for (Attachment attached : attachments.values())
attached.onSpawn();
return true;
}
@Override
public void update() {
try {

View File

@ -1,132 +1,110 @@
package net.citizensnpcs.npc;
import java.lang.reflect.Constructor;
import java.security.acl.Owner;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class CitizensTraitManager {/*implements TraitManager {
private final Map<Class<? extends Trait>, Constructor<? extends Trait>> CACHED_CTORS = new HashMap<Class<? extends Trait>, Constructor<? extends Trait>>();
private final Map<Plugin, Map<String, Class<? extends Trait>>> registered = new HashMap<Plugin, Map<String, Class<? extends Trait>>>();
import net.citizensnpcs.api.abstraction.Equipment;
import net.citizensnpcs.api.abstraction.MobType;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.trait.Age;
import net.citizensnpcs.trait.Behaviour;
import net.citizensnpcs.trait.Controllable;
import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.Saddle;
import net.citizensnpcs.trait.Sheared;
import net.citizensnpcs.trait.VillagerProfession;
import net.citizensnpcs.trait.WoolColor;
import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.trait.waypoint.Waypoints;
// TODO: handle Plugin-setting/names better and avoid cruft. also find a
// way to avoid naming conflicts
public CitizensTraitManager(Plugin plugin) {
registerTrait(new TraitFactory(Age.class).withName("age").withPlugin(plugin));
registerTrait(new TraitFactory(CurrentLocation.class).withName("location").withPlugin(plugin));
registerTrait(new TraitFactory(Equipment.class).withName("equipment").withPlugin(plugin));
registerTrait(new TraitFactory(Inventory.class).withName("inventory").withPlugin(plugin));
registerTrait(new TraitFactory(LookClose.class).withName("lookclose").withPlugin(plugin));
registerTrait(new TraitFactory(MobType.class).withName("type").withPlugin(plugin));
registerTrait(new TraitFactory(Owner.class).withName("owner").withPlugin(plugin));
registerTrait(new TraitFactory(Powered.class).withName("powered").withPlugin(plugin));
registerTrait(new TraitFactory(Saddle.class).withName("saddle").withPlugin(plugin));
registerTrait(new TraitFactory(Sheared.class).withName("sheared").withPlugin(plugin));
registerTrait(new TraitFactory(Spawned.class).withName("spawned").withPlugin(plugin));
registerTrait(new TraitFactory(Text.class).withName("text").withPlugin(plugin));
registerTrait(new TraitFactory(VillagerProfession.class).withName("profession").withPlugin(plugin));
registerTrait(new TraitFactory(Waypoints.class).withName("waypoints").withPlugin(plugin));
registerTrait(new TraitFactory(WoolColor.class).withName("woolcolor").withPlugin(plugin));
registerTrait(new TraitFactory(Controllable.class).withName("controllable").withPlugin(plugin));
registerTrait(new TraitFactory(Behaviour.class).withName("behaviour").withPlugin(plugin));
}
public class CitizensTraitManager implements TraitManager {
private final Map<Class<? extends Trait>, Constructor<? extends Trait>> CACHED_CTORS = new HashMap<Class<? extends Trait>, Constructor<? extends Trait>>();
private final Map<Plugin, Map<String, Class<? extends Trait>>> registered = new HashMap<Plugin, Map<String, Class<? extends Trait>>>();
@SuppressWarnings("unchecked")
private <T extends Trait> T create(Class<T> trait, NPC npc) {
Constructor<? extends Trait> constructor;
// TODO: handle Plugin-setting/names better and avoid cruft. also find a
// way to avoid naming conflicts
public CitizensTraitManager(Plugin plugin) {
registerTrait(new TraitFactory(Age.class).withName("age").withPlugin(plugin));
registerTrait(new TraitFactory(CurrentLocation.class).withName("location").withPlugin(plugin));
registerTrait(new TraitFactory(Equipment.class).withName("equipment").withPlugin(plugin));
registerTrait(new TraitFactory(Inventory.class).withName("inventory").withPlugin(plugin));
registerTrait(new TraitFactory(LookClose.class).withName("lookclose").withPlugin(plugin));
registerTrait(new TraitFactory(MobType.class).withName("type").withPlugin(plugin));
registerTrait(new TraitFactory(Owner.class).withName("owner").withPlugin(plugin));
registerTrait(new TraitFactory(Powered.class).withName("powered").withPlugin(plugin));
registerTrait(new TraitFactory(Saddle.class).withName("saddle").withPlugin(plugin));
registerTrait(new TraitFactory(Sheared.class).withName("sheared").withPlugin(plugin));
registerTrait(new TraitFactory(Spawned.class).withName("spawned").withPlugin(plugin));
registerTrait(new TraitFactory(Text.class).withName("text").withPlugin(plugin));
registerTrait(new TraitFactory(VillagerProfession.class).withName("profession").withPlugin(plugin));
registerTrait(new TraitFactory(Waypoints.class).withName("waypoints").withPlugin(plugin));
registerTrait(new TraitFactory(WoolColor.class).withName("woolcolor").withPlugin(plugin));
registerTrait(new TraitFactory(Controllable.class).withName("controllable").withPlugin(plugin));
registerTrait(new TraitFactory(Behaviour.class).withName("behaviour").withPlugin(plugin));
}
if (!CACHED_CTORS.containsKey(trait)) {
try {
// TODO: replace this fixed constructor with a context class
// which can have extra environment variables.
constructor = trait.getConstructor(NPC.class);
if (constructor == null)
constructor = trait.getConstructor(CitizensNPC.class);
constructor.setAccessible(true);
} catch (Exception ex) {
constructor = null;
}
CACHED_CTORS.put(trait, constructor);
} else
constructor = CACHED_CTORS.get(trait);
@SuppressWarnings("unchecked")
private <T extends Trait> T create(Class<T> trait, NPC npc) {
Constructor<? extends Trait> constructor;
try {
if (constructor == null || npc == null)
return trait.newInstance();
return (T) constructor.newInstance(npc);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
if (!CACHED_CTORS.containsKey(trait)) {
try {
// TODO: replace this fixed constructor with a context class
// which can have extra environment variables.
constructor = trait.getConstructor(NPC.class);
if (constructor == null)
constructor = trait.getConstructor(CitizensNPC.class);
constructor.setAccessible(true);
} catch (Exception ex) {
constructor = null;
}
CACHED_CTORS.put(trait, constructor);
} else
constructor = CACHED_CTORS.get(trait);
@Override
public <T extends Trait> T getTrait(Class<T> clazz) {
return getTrait(clazz, null);
}
try {
if (constructor == null || npc == null)
return trait.newInstance();
return (T) constructor.newInstance(npc);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("unchecked")
public <T extends Trait> T getTrait(Class<T> clazz, NPC npc) {
for (Entry<Plugin, Map<String, Class<? extends Trait>>> entry : registered.entrySet()) {
for (Entry<String, Class<? extends Trait>> subEntry : entry.getValue().entrySet()) {
if (!subEntry.getValue().equals(clazz))
continue;
Trait trait = create(subEntry.getValue(), npc);
if (trait == null)
return null;
trait.setPlugin(entry.getKey());
trait.setName(subEntry.getKey());
return (T) trait;
}
}
return null;
}
@Override
public <T extends Trait> T getTrait(Class<T> clazz) {
return getTrait(clazz, null);
}
@SuppressWarnings("unchecked")
@Override
public <T extends Trait> T getTrait(String name) {
for (Map<String, Class<? extends Trait>> entry : registered.values()) {
if (!entry.containsKey(name))
continue;
return (T) create(entry.get(name), null);
}
return null;
}
@SuppressWarnings("unchecked")
public <T extends Trait> T getTrait(Class<T> clazz, NPC npc) {
for (Entry<Plugin, Map<String, Class<? extends Trait>>> entry : registered.entrySet()) {
for (Entry<String, Class<? extends Trait>> subEntry : entry.getValue().entrySet()) {
if (!subEntry.getValue().equals(clazz))
continue;
Trait trait = create(subEntry.getValue(), npc);
if (trait == null)
return null;
trait.setPlugin(entry.getKey());
trait.setName(subEntry.getKey());
return (T) trait;
}
}
return null;
}
@SuppressWarnings("unchecked")
public <T extends Trait> T getTrait(String name, NPC npc) {
for (Map<String, Class<? extends Trait>> entry : registered.values()) {
Class<? extends Trait> clazz = entry.get(name);
if (clazz == null)
continue;
return (T) getTrait(clazz, npc);
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public <T extends Trait> T getTrait(String name) {
for (Map<String, Class<? extends Trait>> entry : registered.values()) {
if (!entry.containsKey(name))
continue;
return (T) create(entry.get(name), null);
}
return null;
}
@SuppressWarnings("unchecked")
public <T extends Trait> T getTrait(String name, NPC npc) {
for (Map<String, Class<? extends Trait>> entry : registered.values()) {
Class<? extends Trait> clazz = entry.get(name);
if (clazz == null)
continue;
return (T) getTrait(clazz, npc);
}
return null;
}
@Override
public void registerTrait(TraitFactory factory) {
Map<String, Class<? extends Trait>> map = registered.get(factory.getTraitPlugin());
if (map == null)
map = new HashMap<String, Class<? extends Trait>>();
map.put(factory.getTraitName(), factory.getTraitClass());
registered.put(factory.getTraitPlugin(), map);
}
@Override
public void registerTrait(TraitFactory factory) {
Map<String, Class<? extends Trait>> map = registered.get(factory.getTraitPlugin());
if (map == null)
map = new HashMap<String, Class<? extends Trait>>();
map.put(factory.getTraitName(), factory.getTraitClass());
registered.put(factory.getTraitPlugin(), map);
}*/
}

View File

@ -15,6 +15,9 @@ import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.mozilla.javascript.ContextFactory.Listener;
public class NPCSelector implements Listener {
@ -69,7 +72,7 @@ public class NPCSelector implements Listener {
npc.setMetadata("selectors", new FixedMetadataValue(plugin, "console"));
}
Bukkit.getPluginManager().callEvent(new NPCSelectEvent(npc, sender));
CitizensAPI.getServer().callEvent(new NPCSelectEvent(npc, sender));
}
public NPC getSelected(CommandSender sender) {

View File

@ -1,46 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensBlazeNPC extends CitizensMobNPC {
public CitizensBlazeNPC(int id, String name) {
super(id, name, EntityBlazeNPC.class);
}
@Override
public Blaze getBukkitEntity() {
return (Blaze) getHandle().getBukkitEntity();
}
public static class EntityBlazeNPC extends EntityBlaze implements NPCHandle {
private final CitizensNPC npc;
public EntityBlazeNPC(World world) {
this(world, null);
}
public EntityBlazeNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
if (npc != null)
npc.update();
else
super.d_();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,40 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensCaveSpiderNPC extends CitizensMobNPC {
public CitizensCaveSpiderNPC(int id, String name) {
super(id, name, EntityCaveSpiderNPC.class);
}
@Override
public CaveSpider getBukkitEntity() {
return (CaveSpider) getHandle().getBukkitEntity();
}
public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHandle {
private final CitizensNPC npc;
public EntityCaveSpiderNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,45 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensChickenNPC extends CitizensMobNPC {
public CitizensChickenNPC(int id, String name) {
super(id, name, EntityChickenNPC.class);
}
@Override
public Chicken getBukkitEntity() {
return (Chicken) getHandle().getBukkitEntity();
}
public static class EntityChickenNPC extends EntityChicken implements NPCHandle {
private final CitizensNPC npc;
public EntityChickenNPC(World world) {
this(world, null);
}
public EntityChickenNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,45 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensCowNPC extends CitizensMobNPC {
public CitizensCowNPC(int id, String name) {
super(id, name, EntityCowNPC.class);
}
@Override
public Cow getBukkitEntity() {
return (Cow) getHandle().getBukkitEntity();
}
public static class EntityCowNPC extends EntityCow implements NPCHandle {
private final CitizensNPC npc;
public EntityCowNPC(World world) {
this(world, null);
}
public EntityCowNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,49 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensCreeperNPC extends CitizensMobNPC {
public CitizensCreeperNPC(int id, String name) {
super(id, name, EntityCreeperNPC.class);
}
@Override
public Creeper getBukkitEntity() {
return (Creeper) getHandle().getBukkitEntity();
}
public static class EntityCreeperNPC extends EntityCreeper implements NPCHandle {
private final CitizensNPC npc;
public EntityCreeperNPC(World world) {
this(world, null);
}
public EntityCreeperNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void a(EntityWeatherLighting entityweatherlighting) {
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,43 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensEnderDragonNPC extends CitizensMobNPC {
public CitizensEnderDragonNPC(int id, String name) {
super(id, name, EntityEnderDragonNPC.class);
}
@Override
public EnderDragon getBukkitEntity() {
return (EnderDragon) getHandle().getBukkitEntity();
}
public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHandle {
private final CitizensNPC npc;
public EntityEnderDragonNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
}
@Override
public void e() {
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,87 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.Equipment;
import net.citizensnpcs.api.abstraction.ItemStack;
import net.citizensnpcs.api.abstraction.Material;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.editor.Equipable;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.util.Messaging;
public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
public CitizensEndermanNPC(int id, String name) {
super(id, name, EntityEndermanNPC.class);
}
@Override
public void equip(Player equipper) {
ItemStack hand = equipper.getItemInHand();
if (!hand.getType().isBlock()) {
Messaging.sendError(equipper, "Invalid block!");
return;
}
MaterialData carried = getBukkitEntity().getCarriedMaterial();
if (carried.getItemType() == Material.AIR) {
if (hand.getType() == Material.AIR) {
Messaging.sendError(equipper, "Invalid block!");
return;
}
} else {
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), carried.toItemStack(1));
getBukkitEntity().setCarriedMaterial(hand.getData());
}
ItemStack set = hand;
if (set.getType() != Material.AIR) {
if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1);
else
hand = null;
equipper.setItemInHand(hand);
set.setAmount(1);
}
getTrait(Equipment.class).set(0, set);
}
@Override
public Enderman getBukkitEntity() {
return (Enderman) getHandle().getBukkitEntity();
}
public static class EntityEndermanNPC extends EntityEnderman implements NPCHandle {
private final CitizensNPC npc;
public EntityEndermanNPC(World world) {
this(world, null);
}
public EntityEndermanNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
}
@Override
public void e() {
if (npc != null)
npc.update();
else
super.e();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,46 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensGhastNPC extends CitizensMobNPC {
public CitizensGhastNPC(int id, String name) {
super(id, name, EntityGhastNPC.class);
}
@Override
public Ghast getBukkitEntity() {
return (Ghast) getHandle().getBukkitEntity();
}
public static class EntityGhastNPC extends EntityGhast implements NPCHandle {
private final CitizensNPC npc;
public EntityGhastNPC(World world) {
this(world, null);
}
public EntityGhastNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
if (npc != null)
npc.update();
else
super.d_();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,39 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensGiantNPC extends CitizensMobNPC {
public CitizensGiantNPC(int id, String name) {
super(id, name, EntityGiantNPC.class);
}
@Override
public Giant getBukkitEntity() {
return (Giant) getHandle().getBukkitEntity();
}
public static class EntityGiantNPC extends EntityGiantZombie implements NPCHandle {
private final CitizensNPC npc;
public EntityGiantNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,135 +1,124 @@
package net.citizensnpcs.npc.entity;
import javax.xml.stream.Location;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.Equipment;
import net.citizensnpcs.api.abstraction.ItemStack;
import net.citizensnpcs.api.abstraction.Material;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.editor.Equipable;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
public class CitizensHumanNPC {/* extends CitizensNPC implements Equipable {
public class CitizensHumanNPC extends CitizensNPC implements Equipable {
public CitizensHumanNPC(int id, String name) {
super(id, name);
}
public CitizensHumanNPC(int id, String name) {
super(id, name);
}
@Override
protected EntityLiving createHandle(final Location loc) {
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
final EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws), this);
handle.getBukkitEntity().teleport(loc);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
handle.X = loc.getYaw() % 360;
// set the head yaw in another tick - if done immediately,
// minecraft will not update it.
}
});
return handle;
}
@Override
protected EntityLiving createHandle(final Location loc) {
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
final EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws), this);
handle.getBukkitEntity().teleport(loc);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
handle.X = loc.getYaw() % 360;
// set the head yaw in another tick - if done immediately,
// minecraft will not update it.
}
});
return handle;
}
@Override
public void equip(Player equipper) {
ItemStack hand = equipper.getItemInHand();
Equipment trait = getTrait(Equipment.class);
int slot = 0;
Material type = hand == null ? Material.AIR : hand.getType();
// First, determine the slot to edit
switch (type) {
case PUMPKIN:
case JACK_O_LANTERN:
case LEATHER_HELMET:
case CHAINMAIL_HELMET:
case GOLD_HELMET:
case IRON_HELMET:
case DIAMOND_HELMET:
if (!equipper.isSneaking())
slot = 1;
break;
case LEATHER_CHESTPLATE:
case CHAINMAIL_CHESTPLATE:
case GOLD_CHESTPLATE:
case IRON_CHESTPLATE:
case DIAMOND_CHESTPLATE:
if (!equipper.isSneaking())
slot = 2;
break;
case LEATHER_LEGGINGS:
case CHAINMAIL_LEGGINGS:
case GOLD_LEGGINGS:
case IRON_LEGGINGS:
case DIAMOND_LEGGINGS:
if (!equipper.isSneaking())
slot = 3;
break;
case LEATHER_BOOTS:
case CHAINMAIL_BOOTS:
case GOLD_BOOTS:
case IRON_BOOTS:
case DIAMOND_BOOTS:
if (!equipper.isSneaking())
slot = 4;
break;
case AIR:
for (int i = 0; i < 5; i++) {
if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) {
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(i));
trait.set(i, null);
}
}
Messaging.sendF(equipper, "<e>%s<a>had all of its items removed.", getName());
}
// Drop any previous equipment on the ground
if (trait.get(slot) != null && trait.get(slot).getType() != Material.AIR)
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(slot));
@Override
public void equip(Player equipper) {
ItemStack hand = equipper.getItemInHand();
Equipment trait = getTrait(Equipment.class);
int slot = 0;
Material type = hand == null ? Material.AIR : hand.getType();
// First, determine the slot to edit
switch (type) {
case PUMPKIN:
case JACK_O_LANTERN:
case LEATHER_HELMET:
case CHAINMAIL_HELMET:
case GOLD_HELMET:
case IRON_HELMET:
case DIAMOND_HELMET:
if (!equipper.isSneaking())
slot = 1;
break;
case LEATHER_CHESTPLATE:
case CHAINMAIL_CHESTPLATE:
case GOLD_CHESTPLATE:
case IRON_CHESTPLATE:
case DIAMOND_CHESTPLATE:
if (!equipper.isSneaking())
slot = 2;
break;
case LEATHER_LEGGINGS:
case CHAINMAIL_LEGGINGS:
case GOLD_LEGGINGS:
case IRON_LEGGINGS:
case DIAMOND_LEGGINGS:
if (!equipper.isSneaking())
slot = 3;
break;
case LEATHER_BOOTS:
case CHAINMAIL_BOOTS:
case GOLD_BOOTS:
case IRON_BOOTS:
case DIAMOND_BOOTS:
if (!equipper.isSneaking())
slot = 4;
break;
case AIR:
for (int i = 0; i < 5; i++) {
if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) {
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(i));
trait.set(i, null);
}
}
Messaging.sendF(equipper, "<e>%s<a>had all of its items removed.", getName());
}
// Drop any previous equipment on the ground
if (trait.get(slot) != null && trait.get(slot).getType() != Material.AIR)
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(slot));
// Now edit the equipment based on the slot
if (type != Material.AIR) {
// Set the proper slot with one of the item
ItemStack clone = hand.clone();
clone.setAmount(1);
trait.set(slot, clone);
// Now edit the equipment based on the slot
if (type != Material.AIR) {
// Set the proper slot with one of the item
ItemStack clone = hand.clone();
clone.setAmount(1);
trait.set(slot, clone);
if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1);
else
hand = null;
equipper.setItemInHand(hand);
}
}
if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1);
else
hand = null;
equipper.setItemInHand(hand);
}
}
@Override
public Player getBukkitEntity() {
return getHandle().getBukkitEntity();
}
@Override
public Player getBukkitEntity() {
return getHandle().getBukkitEntity();
}
@Override
public EntityHumanNPC getHandle() {
return (EntityHumanNPC) mcEntity;
}
@Override
public EntityHumanNPC getHandle() {
return (EntityHumanNPC) mcEntity;
}
@Override
public void setName(String name) {
super.setName(name);
Location prev = getBukkitEntity().getLocation();
despawn();
spawn(prev);
}
@Override
public void setName(String name) {
super.setName(name);
Location prev = getBukkitEntity().getLocation();
despawn();
spawn(prev);
}
@Override
public void update() {
super.update();
if (isSpawned() && getBukkitEntity().getLocation().getChunk().isLoaded()) {
mcEntity.move(0, -0.2, 0);
// gravity! also works around an entity.onGround not updating issue
// (onGround is normally updated by the client)
}
}
@Override
public void update() {
super.update();
if (isSpawned() && getBukkitEntity().getLocation().getChunk().isLoaded()) {
mcEntity.move(0, -0.2, 0);
// gravity! also works around an entity.onGround not updating issue
// (onGround is normally updated by the client)
}
}*/
}

View File

@ -1,40 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensIronGolemNPC extends CitizensMobNPC {
public CitizensIronGolemNPC(int id, String name) {
super(id, name, EntityIronGolemNPC.class);
}
@Override
public IronGolem getBukkitEntity() {
return (IronGolem) getHandle().getBukkitEntity();
}
public static class EntityIronGolemNPC extends EntityIronGolem implements NPCHandle {
private final CitizensNPC npc;
public EntityIronGolemNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,47 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensMagmaCubeNPC extends CitizensMobNPC {
public CitizensMagmaCubeNPC(int id, String name) {
super(id, name, EntityMagmaCubeNPC.class);
}
@Override
public MagmaCube getBukkitEntity() {
return (MagmaCube) getHandle().getBukkitEntity();
}
public static class EntityMagmaCubeNPC extends EntityMagmaCube implements NPCHandle {
private final CitizensNPC npc;
public EntityMagmaCubeNPC(World world) {
this(world, null);
}
public EntityMagmaCubeNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
setSize(3);
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
if (npc != null)
npc.update();
else
super.d_();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,45 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensMushroomCowNPC extends CitizensMobNPC {
public CitizensMushroomCowNPC(int id, String name) {
super(id, name, EntityMushroomCowNPC.class);
}
@Override
public MushroomCow getBukkitEntity() {
return (MushroomCow) getHandle().getBukkitEntity();
}
public static class EntityMushroomCowNPC extends EntityMushroomCow implements NPCHandle {
private final CitizensNPC npc;
public EntityMushroomCowNPC(World world) {
this(world, null);
}
public EntityMushroomCowNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,45 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensOcelotNPC extends CitizensMobNPC {
public CitizensOcelotNPC(int id, String name) {
super(id, name, EntityOcelotNPC.class);
}
@Override
public Ocelot getBukkitEntity() {
return (Ocelot) getHandle().getBukkitEntity();
}
public static class EntityOcelotNPC extends EntityOcelot implements NPCHandle {
private final CitizensNPC npc;
public EntityOcelotNPC(World world) {
this(world, null);
}
public EntityOcelotNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,75 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.ItemStack;
import net.citizensnpcs.api.abstraction.Material;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.editor.Equipable;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.trait.Saddle;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
public CitizensPigNPC(int id, String name) {
super(id, name, EntityPigNPC.class);
}
@Override
public void equip(Player equipper) {
ItemStack hand = equipper.getItemInHand();
if (hand.getType() == Material.SADDLE) {
if (!getBukkitEntity().hasSaddle()) {
getTrait(Saddle.class).toggle();
equipper.setItemInHand(null);
Messaging.send(equipper, StringHelper.wrap(getName()) + " is now saddled.");
}
} else {
if (getBukkitEntity().hasSaddle()) {
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(),
new ItemStack(Material.SADDLE, 1));
getTrait(Saddle.class).toggle();
Messaging.send(equipper, StringHelper.wrap(getName()) + " is no longer saddled.");
}
}
}
@Override
public Pig getBukkitEntity() {
return (Pig) getHandle().getBukkitEntity();
}
public static class EntityPigNPC extends EntityPig implements NPCHandle {
private final CitizensNPC npc;
public EntityPigNPC(World world) {
this(world, null);
}
public EntityPigNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void a(EntityWeatherLighting entityweatherlighting) {
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,46 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensPigZombieNPC extends CitizensMobNPC {
public CitizensPigZombieNPC(int id, String name) {
super(id, name, EntityPigZombieNPC.class);
}
@Override
public PigZombie getBukkitEntity() {
return (PigZombie) getHandle().getBukkitEntity();
}
public static class EntityPigZombieNPC extends EntityPigZombie implements NPCHandle {
private final CitizensNPC npc;
public EntityPigZombieNPC(World world) {
this(world, null);
}
public EntityPigZombieNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
if (npc != null)
npc.update();
else
super.d_();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,82 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.ItemStack;
import net.citizensnpcs.api.abstraction.Material;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.abstraction.entity.Sheep;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.editor.Equipable;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.trait.Sheared;
import net.citizensnpcs.trait.WoolColor;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
public CitizensSheepNPC(int id, String name) {
super(id, name, EntitySheepNPC.class);
}
@Override
public void equip(Player equipper) {
ItemStack hand = equipper.getItemInHand();
if (hand.getType() == Material.SHEARS) {
Messaging.send(equipper, StringHelper.wrap(getName()) + " is "
+ (getTrait(Sheared.class).toggle() ? "now" : "no longer") + " sheared.");
} else if (hand.getType() == Material.INK_SACK) {
if (getBukkitEntity().getColor() == DyeColor.getByData((byte) (15 - hand.getData().getData())))
return;
DyeColor color = DyeColor.getByData((byte) (15 - hand.getData().getData()));
getTrait(WoolColor.class).setColor(color);
Messaging.send(
equipper,
StringHelper.wrap(getName()) + " is now "
+ StringHelper.wrap(color.name().toLowerCase().replace("_", " ")) + ".");
if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1);
else
hand = null;
equipper.setItemInHand(hand);
} else {
getTrait(WoolColor.class).setColor(DyeColor.WHITE);
Messaging.send(equipper, StringHelper.wrap(getName()) + " is now " + StringHelper.wrap("white") + ".");
}
}
@Override
public Sheep getBukkitEntity() {
return (Sheep) getHandle().getBukkitEntity();
}
public static class EntitySheepNPC extends EntitySheep implements NPCHandle {
private final CitizensNPC npc;
public EntitySheepNPC(World world) {
this(world, null);
}
public EntitySheepNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,45 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensSilverfishNPC extends CitizensMobNPC {
public CitizensSilverfishNPC(int id, String name) {
super(id, name, EntitySilverfishNPC.class);
}
@Override
public Silverfish getBukkitEntity() {
return (Silverfish) getHandle().getBukkitEntity();
}
public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHandle {
private final CitizensNPC npc;
public EntitySilverfishNPC(World world) {
this(world, null);
}
public EntitySilverfishNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,47 +0,0 @@
package net.citizensnpcs.npc.entity;
import java.rmi.server.Skeleton;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensSkeletonNPC extends CitizensMobNPC {
public CitizensSkeletonNPC(int id, String name) {
super(id, name, EntitySkeletonNPC.class);
}
@Override
public Skeleton getBukkitEntity() {
return (Skeleton) getHandle().getBukkitEntity();
}
public static class EntitySkeletonNPC extends EntitySkeleton implements NPCHandle {
private final CitizensNPC npc;
public EntitySkeletonNPC(World world) {
this(world, null);
}
public EntitySkeletonNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,46 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensSlimeNPC extends CitizensMobNPC {
public CitizensSlimeNPC(int id, String name) {
super(id, name, EntitySlimeNPC.class);
}
@Override
public Slime getBukkitEntity() {
return (Slime) getHandle().getBukkitEntity();
}
public static class EntitySlimeNPC extends EntitySlime implements NPCHandle {
private final CitizensNPC npc;
public EntitySlimeNPC(World world) {
this(world, null);
}
public EntitySlimeNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
setSize(3);
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,40 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensSnowmanNPC extends CitizensMobNPC {
public CitizensSnowmanNPC(int id, String name) {
super(id, name, EntitySnowmanNPC.class);
}
@Override
public Snowman getBukkitEntity() {
return (Snowman) getHandle().getBukkitEntity();
}
public static class EntitySnowmanNPC extends EntitySnowman implements NPCHandle {
private final CitizensNPC npc;
public EntitySnowmanNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,45 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensSpiderNPC extends CitizensMobNPC {
public CitizensSpiderNPC(int id, String name) {
super(id, name, EntitySpiderNPC.class);
}
@Override
public Spider getBukkitEntity() {
return (Spider) getHandle().getBukkitEntity();
}
public static class EntitySpiderNPC extends EntitySpider implements NPCHandle {
private final CitizensNPC npc;
public EntitySpiderNPC(World world) {
this(world, null);
}
public EntitySpiderNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,46 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensSquidNPC extends CitizensMobNPC {
public CitizensSquidNPC(int id, String name) {
super(id, name, EntitySquidNPC.class);
}
@Override
public Squid getBukkitEntity() {
return (Squid) getHandle().getBukkitEntity();
}
public static class EntitySquidNPC extends EntitySquid implements NPCHandle {
private final CitizensNPC npc;
public EntitySquidNPC(World world) {
this(world, null);
}
public EntitySquidNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
if (npc != null)
npc.update();
else
super.d_();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,45 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensVillagerNPC extends CitizensMobNPC {
public CitizensVillagerNPC(int id, String name) {
super(id, name, EntityVillagerNPC.class);
}
@Override
public Villager getBukkitEntity() {
return (Villager) getHandle().getBukkitEntity();
}
public static class EntityVillagerNPC extends EntityVillager implements NPCHandle {
private final CitizensNPC npc;
public EntityVillagerNPC(World world) {
this(world, null);
}
public EntityVillagerNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,45 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensWolfNPC extends CitizensMobNPC {
public CitizensWolfNPC(int id, String name) {
super(id, name, EntityWolfNPC.class);
}
@Override
public Wolf getBukkitEntity() {
return (Wolf) getHandle().getBukkitEntity();
}
public static class EntityWolfNPC extends EntityWolf implements NPCHandle {
private final CitizensNPC npc;
public EntityWolfNPC(World world) {
this(world, null);
}
public EntityWolfNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -1,45 +0,0 @@
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
public class CitizensZombieNPC extends CitizensMobNPC {
public CitizensZombieNPC(int id, String name) {
super(id, name, EntityZombieNPC.class);
}
@Override
public Zombie getBukkitEntity() {
return (Zombie) getHandle().getBukkitEntity();
}
public static class EntityZombieNPC extends EntityZombie implements NPCHandle {
private final CitizensNPC npc;
public EntityZombieNPC(World world) {
this(world, null);
}
public EntityZombieNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
@Override
public NPC getNPC() {
return npc;
}
}
}

View File

@ -2,30 +2,36 @@ package net.citizensnpcs.npc.entity;
import java.io.IOException;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.abstraction.entity.NPCHolder;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.network.NPCNetHandler;
import net.citizensnpcs.npc.network.NPCNetworkManager;
import net.citizensnpcs.npc.network.NPCSocket;
import net.citizensnpcs.npc.network.EmptyNetHandler;
import net.citizensnpcs.npc.network.EmptyNetworkManager;
import net.citizensnpcs.npc.network.EmptySocket;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.ItemInWorldManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Navigation;
import net.minecraft.server.NetHandler;
import net.minecraft.server.NetworkManager;
public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
private CitizensNPC npc;
public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string,
public EntityHumanNPC(MinecraftServer minecraftServer, net.minecraft.server.World world, String string,
ItemInWorldManager itemInWorldManager, NPC npc) {
super(minecraftServer, world, string, itemInWorldManager);
this.npc = (CitizensNPC) npc;
itemInWorldManager.setGameMode(0);
NPCSocket socket = new NPCSocket();
NetworkManager netMgr = new NPCNetworkManager(socket, "npc mgr", new NetHandler() {
EmptySocket socket = new EmptySocket();
NetworkManager netMgr = new EmptyNetworkManager(socket, "npc mgr", new NetHandler() {
@Override
public boolean c() {
return false;
}
});
netServerHandler = new NPCNetHandler(minecraftServer, netMgr, this);
netServerHandler = new EmptyNetHandler(minecraftServer, netMgr, this);
netMgr.a(netServerHandler);
try {

View File

@ -1,69 +0,0 @@
package net.citizensnpcs.npc.network;
public class NPCNetHandler extends NetServerHandler {
public NPCNetHandler(MinecraftServer minecraftServer, NetworkManager networkManager, EntityPlayer entityPlayer) {
super(minecraftServer, networkManager, entityPlayer);
}
@Override
public void a() {
}
@Override
public void a(Packet102WindowClick packet) {
}
@Override
public void a(Packet106Transaction packet) {
}
@Override
public void a(Packet10Flying packet) {
}
@Override
public void a(Packet130UpdateSign packet) {
}
@Override
public void a(Packet14BlockDig packet) {
}
@Override
public void a(Packet15Place packet) {
}
@Override
public void a(Packet16BlockItemSwitch packet) {
}
@Override
public void a(Packet255KickDisconnect packet) {
}
@Override
public void a(Packet28EntityVelocity packet) {
}
@Override
public void a(Packet3Chat packet) {
}
@Override
public void a(Packet51MapChunk packet) {
}
@Override
public void a(String string, Object[] objects) {
}
@Override
public void sendMessage(String string) {
}
@Override
public void sendPacket(Packet packet) {
}
}

View File

@ -1,48 +0,0 @@
package net.citizensnpcs.npc.network;
import java.lang.reflect.Field;
import java.net.Socket;
public class NPCNetworkManager extends NetworkManager {
public NPCNetworkManager(Socket socket, String string, NetHandler netHandler) {
super(socket, string, netHandler);
try {
// the field above the 3 synchronized lists
Field f = NetworkManager.class.getDeclaredField("l");
f.setAccessible(true);
f.set(this, false);
} catch (Exception e) {
}
}
@Override
public void a() {
}
@Override
public void a(NetHandler netHandler) {
}
@Override
public void a(String s, Object... objects) {
}
@Override
public void b() {
}
@Override
public void d() {
}
@Override
public int e() {
return 0;
}
@Override
public void queue(Packet packet) {
}
}

View File

@ -1,20 +0,0 @@
package net.citizensnpcs.npc.network;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class NPCSocket extends Socket {
@Override
public InputStream getInputStream() {
return new ByteArrayInputStream(new byte[10]);
}
@Override
public OutputStream getOutputStream() {
return new ByteArrayOutputStream();
}
}

View File

@ -1,14 +1,14 @@
package net.citizensnpcs.spout;
import org.spout.vanilla.controller.VanillaControllerTypes;
import org.spout.vanilla.controller.living.player.VanillaPlayer;
import org.spout.vanilla.controller.source.HealthChangeReason;
import net.citizensnpcs.api.abstraction.Equipment;
import net.citizensnpcs.api.abstraction.ItemStack;
import net.citizensnpcs.api.abstraction.MobType;
import net.citizensnpcs.api.abstraction.entity.Player;
import org.spout.vanilla.controller.VanillaControllerTypes;
import org.spout.vanilla.controller.living.player.VanillaPlayer;
import org.spout.vanilla.controller.source.HealthChangeReason;
public class SpoutPlayer extends SpoutEntity implements Player {
private final VanillaPlayer player;
@ -24,7 +24,7 @@ public class SpoutPlayer extends SpoutEntity implements Player {
@Override
public MobType getType() {
return SpoutConverter.toMobType(VanillaControllerTypes.PLAYER);
return SpoutConverter.toMobType(VanillaControllerTypes.HUMAN);
}
@Override
@ -59,13 +59,13 @@ public class SpoutPlayer extends SpoutEntity implements Player {
case CARRIED:
return SpoutConverter.toItemStack(player.getInventory().getCurrentItem());
case HELMET:
return SpoutConverter.toItemStack(player.getInventory().getHelmet());
return SpoutConverter.toItemStack(player.getInventory().getArmor().getHelmet().getItem());
case BOOTS:
return SpoutConverter.toItemStack(player.getInventory().getBoots());
return SpoutConverter.toItemStack(player.getInventory().getArmor().getBoots().getItem());
case CHESTPLATE:
return SpoutConverter.toItemStack(player.getInventory().getChestPlate());
return SpoutConverter.toItemStack(player.getInventory().getArmor().getChestPlate().getItem());
case LEGGINGS:
return SpoutConverter.toItemStack(player.getInventory().getLeggings());
return SpoutConverter.toItemStack(player.getInventory().getArmor().getLeggings().getItem());
default:
return null;
}

View File

@ -1,12 +1,12 @@
package net.citizensnpcs.spout;
import net.citizensnpcs.api.abstraction.Server;
import org.spout.api.event.Event;
import org.spout.api.event.HandlerList;
import org.spout.api.event.Listener;
import org.spout.api.scheduler.TaskPriority;
import net.citizensnpcs.api.abstraction.Server;
public class SpoutServer implements Server {
private final CitizensSpout plugin;
@ -16,32 +16,33 @@ public class SpoutServer implements Server {
@Override
public void callEvent(Object event) {
plugin.getGame().getEventManager().callEvent((Event) event);
plugin.getEngine().getEventManager().callEvent((Event) event);
}
@Override
public void registerEvents(Object listener) {
plugin.getGame().getEventManager().registerEvents((Listener) listener, plugin);
plugin.getEngine().getEventManager().registerEvents((Listener) listener, plugin);
}
@Override
public void schedule(Runnable task) {
plugin.getGame().getScheduler().scheduleSyncDelayedTask(plugin, task);
plugin.getEngine().getScheduler().scheduleSyncDelayedTask(plugin, task);
}
@Override
public void schedule(Runnable task, long delay) {
plugin.getGame().getScheduler().scheduleSyncDelayedTask(plugin, task, delay, TaskPriority.NORMAL);
plugin.getEngine().getScheduler().scheduleSyncDelayedTask(plugin, task, delay, TaskPriority.NORMAL);
}
@Override
public void scheduleRepeating(Runnable task, long delay) {
plugin.getGame().getScheduler().scheduleSyncRepeatingTask(plugin, task, 0, delay, TaskPriority.NORMAL);
plugin.getEngine().getScheduler().scheduleSyncRepeatingTask(plugin, task, 0, delay, TaskPriority.NORMAL);
}
@Override
public void scheduleRepeating(Runnable task, long initialDelay, long repeatDelay) {
plugin.getGame().getScheduler().scheduleSyncRepeatingTask(plugin, task, initialDelay, repeatDelay, TaskPriority.NORMAL);
plugin.getEngine().getScheduler()
.scheduleSyncRepeatingTask(plugin, task, initialDelay, repeatDelay, TaskPriority.NORMAL);
}
@Override

View File

@ -1,14 +1,17 @@
package net.citizensnpcs.trait;
import net.citizensnpcs.api.abstraction.EventHandler;
import net.citizensnpcs.api.abstraction.Listener;
import net.citizensnpcs.api.attachment.Attachment;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.npc.CitizensNPC;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityPlayer;
import org.mozilla.javascript.ContextFactory.Listener;
import org.bukkit.craftbukkit.entity.CraftPlayer;
//TODO: reduce reliance on CitizensNPC
public class Controllable extends Attachment implements Runnable, Listener, Toggleable {

View File

@ -7,6 +7,7 @@ import java.util.List;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.Entity;
import net.citizensnpcs.api.abstraction.entity.LandMob;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.attachment.Attachment;
import net.citizensnpcs.api.exception.NPCLoadException;
@ -16,10 +17,10 @@ import net.citizensnpcs.api.util.DataKey;
public class LookClose extends Attachment implements Runnable, Toggleable {
private boolean enabled = Setting.DEFAULT_LOOK_CLOSE.asBoolean();
private Player lookingAt;
private final NPC npc;
private final LandMob entity;
public LookClose(NPC npc) {
this.npc = npc;
this.entity = (LandMob) npc.getEntity();
}
private void faceEntity(Entity from, Entity at) {
@ -50,23 +51,22 @@ public class LookClose extends Attachment implements Runnable, Toggleable {
@Override
public void run() {
if (!enabled || npc.getAI().hasDestination())
if (!enabled || entity.hasDestination())
return;
if (hasInvalidTarget()) {
if (hasInvalidTarget())
findNewTarget();
}
if (lookingAt != null) {
faceEntity(npc.getEntity(), lookingAt);
}
if (lookingAt != null)
faceEntity(entity, lookingAt);
}
private void findNewTarget() {
List<Entity> nearby = npc.getEntity().getNearbyEntities(2.5, 5, 2.5);
List<Entity> nearby = entity.getNearbyEntities(2.5, 5, 2.5);
Collections.sort(nearby, new Comparator<Entity>() {
@Override
public int compare(Entity o1, Entity o2) {
double d1 = o1.getLocation().distanceSquared(npc.getEntity().getLocation());
double d2 = o2.getLocation().distanceSquared(npc.getEntity().getLocation());
double d1 = o1.getLocation().distanceSquared(entity.getLocation());
double d2 = o2.getLocation().distanceSquared(entity.getLocation());
return Double.compare(d1, d2);
}
});
@ -82,8 +82,8 @@ public class LookClose extends Attachment implements Runnable, Toggleable {
private boolean hasInvalidTarget() {
if (lookingAt == null)
return true;
if (!lookingAt.isOnline() || lookingAt.getWorld() != npc.getEntity().getWorld()
|| lookingAt.getLocation().distanceSquared(npc.getEntity().getLocation()) > 5) {
if (!lookingAt.isOnline() || lookingAt.getWorld() != entity.getWorld()
|| lookingAt.getLocation().distanceSquared(entity.getLocation()) > 5) {
lookingAt = null;
return true;
}

View File

@ -1,6 +1,5 @@
package net.citizensnpcs.trait;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.EventHandler;
import net.citizensnpcs.api.abstraction.Listener;
import net.citizensnpcs.api.abstraction.entity.Sheep;
@ -8,6 +7,9 @@ import net.citizensnpcs.api.attachment.Attachment;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.bukkit.BukkitConverter;
import org.bukkit.event.player.PlayerShearEntityEvent;
public class Sheared extends Attachment implements Toggleable, Listener {
private final NPC npc;
@ -29,7 +31,7 @@ public class Sheared extends Attachment implements Toggleable, Listener {
@EventHandler
public void onPlayerShearEntityEvent(PlayerShearEntityEvent event) {
if (npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getEntity())))
if (npc.equals(BukkitConverter.toNPC(event.getEntity())))
event.setCancelled(true);
}

View File

@ -6,16 +6,19 @@ import java.util.List;
import javax.xml.stream.Location;
import net.citizensnpcs.api.abstraction.EventHandler;
import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
import org.bukkit.Bukkit;
import org.bukkit.event.player.PlayerItemHeldEvent;
import com.google.common.collect.Lists;
public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoint> {
private final GenericWaypointCallback callback = new GenericWaypointCallback(this);
private final List<Waypoint> waypoints = Lists.newArrayList();
@Override
@ -92,11 +95,6 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
};
}
@Override
public NavigationCallback getCallback() {
return callback;
}
@Override
public Iterator<Waypoint> iterator() {
return waypoints.iterator();
@ -114,7 +112,6 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
@Override
public void onAttach() {
callback.onProviderChanged();
}
@Override
@ -122,7 +119,7 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
key.removeKey("points");
key = key.getRelative("points");
for (int i = 0; i < waypoints.size(); ++i) {
Location location = waypoints.get(i).getLocation();
WorldVector location = waypoints.get(i).getLocation();
DataKey root = key.getRelative(Integer.toString(i) + ".location");
root.setString("world", location.getWorld().getName());
root.setDouble("x", location.getX());

View File

@ -1,15 +1,45 @@
package net.citizensnpcs.trait.waypoint;
import javax.xml.stream.Location;
import net.citizensnpcs.api.abstraction.WorldVector;
public class Waypoint {
private final Location location;
private final WorldVector location;
public Waypoint(Location location) {
public Waypoint(WorldVector location) {
this.location = location;
}
public Location getLocation() {
public WorldVector getLocation() {
return location;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((location == null) ? 0 : location.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Waypoint other = (Waypoint) obj;
if (location == null) {
if (other.location != null) {
return false;
}
} else if (!location.equals(other.location)) {
return false;
}
return true;
}
}

View File

@ -1,7 +1,6 @@
package net.citizensnpcs.trait.waypoint;
import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.ai.AI;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.editor.Editor;
@ -16,14 +15,6 @@ public interface WaypointProvider {
*/
public Editor createEditor(Player player);
/**
* Returns the {@link NavigationCallback} linked to this provider. This will
* be linked to the NPC's {@link AI}.
*
* @return The callback in use
*/
public NavigationCallback getCallback();
/**
* Loads from the specified {@link DataKey}.
*

View File

@ -6,15 +6,12 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import javax.xml.stream.Location;
import org.apache.commons.lang.Validate;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.abstraction.Material;
import net.citizensnpcs.api.abstraction.World;
import net.citizensnpcs.api.abstraction.entity.Player;
import org.apache.commons.lang.Validate;
import com.google.common.base.Splitter;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@ -115,14 +112,14 @@ public class Util {
if (parts.contains("*"))
return true;
for (String part : Splitter.on(',').split(parts)) {
if (Material.matchMaterial(part) == player.getItemInHand().getType()) {
if (Material.match(part) == player.getItemInHand().getType()) {
return true;
}
}
return false;
}
public static void sendToOnline(Packet... packets) {
/*public static void sendToOnline(Packet... packets) {
Validate.notNull(packets, "packets cannot be null");
for (Player player : Bukkit.getOnlinePlayers()) {
if (player == null || !player.isOnline())
@ -145,5 +142,5 @@ public class Util {
}
((CraftPlayer) ply).getHandle().netServerHandler.sendPacket(packet);
}
}
}*/
}