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> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>craftbukkit</artifactId>
<version>1.2.5-R1.4-SNAPSHOT</version> <version>1.2.5-R4.1-SNAPSHOT</version>
<type>jar</type> <type>jar</type>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -15,10 +15,8 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry; import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.bukkit.BukkitConverter; import net.citizensnpcs.bukkit.BukkitConverter;
import net.citizensnpcs.editor.Editor; import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.npc.entity.EntityHumanNPC;
import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.text.Text; import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import org.bukkit.Bukkit; 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.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent; 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.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@ -81,10 +77,10 @@ public class EventListen implements Listener {
*/ */
@EventHandler @EventHandler
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if (!npcRegistry.isNPC(event.getEntity())) NPC npc = BukkitConverter.toNPC(event.getEntity());
if (npc == null)
return; return;
NPC npc = npcRegistry.getNPC(event.getEntity());
NPCDamageEvent damageEvent; NPCDamageEvent damageEvent;
if (event instanceof EntityDamageByEntityEvent) { if (event instanceof EntityDamageByEntityEvent) {
NPCDamageByEntityEvent damageByEntityEvent = new NPCDamageByEntityEvent(npc, event.getDamage(), NPCDamageByEntityEvent damageByEntityEvent = new NPCDamageByEntityEvent(npc, event.getDamage(),
@ -108,19 +104,34 @@ public class EventListen implements Listener {
@EventHandler @EventHandler
public void onEntityDeath(EntityDeathEvent event) { public void onEntityDeath(EntityDeathEvent event) {
if (!npcRegistry.isNPC(event.getEntity())) NPC npc = BukkitConverter.toNPC(event.getEntity());
if (npc == null)
return; return;
NPC npc = npcRegistry.getNPC(event.getEntity());
npc.despawn(); npc.despawn();
} }
/*
* Player events
*/
@EventHandler @EventHandler
public void onEntityTarget(EntityTargetEvent event) { public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
if (event.isCancelled() || !npcRegistry.isNPC(event.getEntity()) || !(event.getTarget() instanceof Player)) if (!BukkitConverter.isNPC(event.getPlayer()))
return; return;
NPC npc = npcRegistry.getNPC(event.getEntity()); ((CraftServer) Bukkit.getServer()).getHandle().players.remove(((CraftPlayer) event.getPlayer()).getHandle());
Player player = (Player) event.getTarget(); }
@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 // Call right-click event
NPCRightClickEvent rightClickEvent = new NPCRightClickEvent(npc, player); NPCRightClickEvent rightClickEvent = new NPCRightClickEvent(npc, player);
@ -133,27 +144,6 @@ public class EventListen implements Listener {
npc.getAttachment(Text.class).sendText(player); 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 @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Editor.leave(event.getPlayer().getName()); 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.World;
import net.citizensnpcs.api.abstraction.WorldVector; import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.Entity; 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.Location;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
public class BukkitConverter { public class BukkitConverter {
@ -40,4 +44,20 @@ public class BukkitConverter {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; 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; 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(); return getPlayer().getName();
} }
@Override
public ItemStack getItemInHand() {
return getEquipment(Equipment.CARRIED);
}
@Override @Override
public boolean hasPermission(String perm) { public boolean hasPermission(String perm) {
return getPlayer().hasPermission(perm); return getPlayer().hasPermission(perm);

View File

@ -1,9 +1,9 @@
package net.citizensnpcs.editor; package net.citizensnpcs.editor;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.abstraction.EventHandler; import net.citizensnpcs.api.abstraction.EventHandler;
import net.citizensnpcs.api.abstraction.entity.Player; import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.bukkit.BukkitConverter;
import net.citizensnpcs.bukkit.BukkitPlayer; import net.citizensnpcs.bukkit.BukkitPlayer;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
@ -40,8 +40,7 @@ public class EquipmentEditor extends Editor {
@EventHandler @EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked())) if (!npc.equals(BukkitConverter.toNPC(event.getRightClicked())) || !event.getPlayer().equals(player))
|| !event.getPlayer().equals(player))
return; return;
if (npc instanceof Equipable) { 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.abstraction.World;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityTypes;
import org.bukkit.craftbukkit.CraftWorld;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public abstract class CitizensMobNPC extends CitizensNPC { 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.CitizensAPI;
import net.citizensnpcs.api.abstraction.WorldVector; import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.LivingEntity;
import net.citizensnpcs.api.attachment.Attachment; 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.exception.NPCLoadException;
import net.citizensnpcs.api.npc.AbstractNPC; import net.citizensnpcs.api.npc.AbstractNPC;
import net.citizensnpcs.api.npc.NPCRegistry; import net.citizensnpcs.api.npc.NPCRegistry;
@ -24,39 +21,13 @@ public class CitizensNPC extends AbstractNPC {
super(CitizensAPI.getNPCRegistry(), name); 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 @Override
protected Attachment getAttachmentFor(Class<? extends Attachment> clazz) { protected Attachment getAttachmentFor(Class<? extends Attachment> clazz) {
// TODO Auto-generated method stub return CitizensAPI.getAttachmentFactory().getAttachment(clazz);
return null;
} }
private Attachment getAttachmentFor(String name) { private Attachment getAttachmentFor(String name) {
// TODO Auto-generated method stub return CitizensAPI.getAttachmentFactory().getAttachment(name);
return null;
}
@Override
public LivingEntity getEntity() {
return (LivingEntity) controller.getEntity();
}
@Override
public boolean isSpawned() {
return getEntity() != null;
} }
public void load(DataKey root) { 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 @Override
public void update() { public void update() {
try { try {

View File

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

View File

@ -15,6 +15,9 @@ import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.Util; 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; import org.mozilla.javascript.ContextFactory.Listener;
public class NPCSelector implements Listener { public class NPCSelector implements Listener {
@ -69,7 +72,7 @@ public class NPCSelector implements Listener {
npc.setMetadata("selectors", new FixedMetadataValue(plugin, "console")); 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) { 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; package net.citizensnpcs.npc.entity;
import javax.xml.stream.Location;
import net.citizensnpcs.api.CitizensAPI; public class CitizensHumanNPC {/* extends CitizensNPC implements Equipable {
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 CitizensHumanNPC(int id, String name) {
super(id, name);
public CitizensHumanNPC(int id, String name) { }
super(id, name);
} @Override
protected EntityLiving createHandle(final Location loc) {
@Override WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
protected EntityLiving createHandle(final Location loc) { final EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle(); StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws), this);
final EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws, handle.getBukkitEntity().teleport(loc);
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws), this); Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
handle.getBukkitEntity().teleport(loc); @Override
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { public void run() {
@Override handle.X = loc.getYaw() % 360;
public void run() { // set the head yaw in another tick - if done immediately,
handle.X = loc.getYaw() % 360; // minecraft will not update it.
// set the head yaw in another tick - if done immediately, }
// minecraft will not update it. });
} return handle;
}); }
return handle;
} @Override
public void equip(Player equipper) {
@Override ItemStack hand = equipper.getItemInHand();
public void equip(Player equipper) { Equipment trait = getTrait(Equipment.class);
ItemStack hand = equipper.getItemInHand(); int slot = 0;
Equipment trait = getTrait(Equipment.class); Material type = hand == null ? Material.AIR : hand.getType();
int slot = 0; // First, determine the slot to edit
Material type = hand == null ? Material.AIR : hand.getType(); switch (type) {
// First, determine the slot to edit case PUMPKIN:
switch (type) { case JACK_O_LANTERN:
case PUMPKIN: case LEATHER_HELMET:
case JACK_O_LANTERN: case CHAINMAIL_HELMET:
case LEATHER_HELMET: case GOLD_HELMET:
case CHAINMAIL_HELMET: case IRON_HELMET:
case GOLD_HELMET: case DIAMOND_HELMET:
case IRON_HELMET: if (!equipper.isSneaking())
case DIAMOND_HELMET: slot = 1;
if (!equipper.isSneaking()) break;
slot = 1; case LEATHER_CHESTPLATE:
break; case CHAINMAIL_CHESTPLATE:
case LEATHER_CHESTPLATE: case GOLD_CHESTPLATE:
case CHAINMAIL_CHESTPLATE: case IRON_CHESTPLATE:
case GOLD_CHESTPLATE: case DIAMOND_CHESTPLATE:
case IRON_CHESTPLATE: if (!equipper.isSneaking())
case DIAMOND_CHESTPLATE: slot = 2;
if (!equipper.isSneaking()) break;
slot = 2; case LEATHER_LEGGINGS:
break; case CHAINMAIL_LEGGINGS:
case LEATHER_LEGGINGS: case GOLD_LEGGINGS:
case CHAINMAIL_LEGGINGS: case IRON_LEGGINGS:
case GOLD_LEGGINGS: case DIAMOND_LEGGINGS:
case IRON_LEGGINGS: if (!equipper.isSneaking())
case DIAMOND_LEGGINGS: slot = 3;
if (!equipper.isSneaking()) break;
slot = 3; case LEATHER_BOOTS:
break; case CHAINMAIL_BOOTS:
case LEATHER_BOOTS: case GOLD_BOOTS:
case CHAINMAIL_BOOTS: case IRON_BOOTS:
case GOLD_BOOTS: case DIAMOND_BOOTS:
case IRON_BOOTS: if (!equipper.isSneaking())
case DIAMOND_BOOTS: slot = 4;
if (!equipper.isSneaking()) break;
slot = 4; case AIR:
break; for (int i = 0; i < 5; i++) {
case AIR: if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) {
for (int i = 0; i < 5; i++) { equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(i));
if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) { trait.set(i, null);
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());
} }
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)
// Drop any previous equipment on the ground equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(slot));
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) {
// Now edit the equipment based on the slot // Set the proper slot with one of the item
if (type != Material.AIR) { ItemStack clone = hand.clone();
// Set the proper slot with one of the item clone.setAmount(1);
ItemStack clone = hand.clone(); trait.set(slot, clone);
clone.setAmount(1);
trait.set(slot, clone); if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1);
if (hand.getAmount() > 1) else
hand.setAmount(hand.getAmount() - 1); hand = null;
else equipper.setItemInHand(hand);
hand = null; }
equipper.setItemInHand(hand); }
}
} @Override
public Player getBukkitEntity() {
@Override return getHandle().getBukkitEntity();
public Player getBukkitEntity() { }
return getHandle().getBukkitEntity();
} @Override
public EntityHumanNPC getHandle() {
@Override return (EntityHumanNPC) mcEntity;
public EntityHumanNPC getHandle() { }
return (EntityHumanNPC) mcEntity;
} @Override
public void setName(String name) {
@Override super.setName(name);
public void setName(String name) { Location prev = getBukkitEntity().getLocation();
super.setName(name); despawn();
Location prev = getBukkitEntity().getLocation(); spawn(prev);
despawn(); }
spawn(prev);
} @Override
public void update() {
@Override super.update();
public void update() { if (isSpawned() && getBukkitEntity().getLocation().getChunk().isLoaded()) {
super.update(); mcEntity.move(0, -0.2, 0);
if (isSpawned() && getBukkitEntity().getLocation().getChunk().isLoaded()) { // gravity! also works around an entity.onGround not updating issue
mcEntity.move(0, -0.2, 0); // (onGround is normally updated by the client)
// 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 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.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.network.NPCNetHandler; import net.citizensnpcs.npc.network.EmptyNetHandler;
import net.citizensnpcs.npc.network.NPCNetworkManager; import net.citizensnpcs.npc.network.EmptyNetworkManager;
import net.citizensnpcs.npc.network.NPCSocket; 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; 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) { ItemInWorldManager itemInWorldManager, NPC npc) {
super(minecraftServer, world, string, itemInWorldManager); super(minecraftServer, world, string, itemInWorldManager);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
itemInWorldManager.setGameMode(0); itemInWorldManager.setGameMode(0);
NPCSocket socket = new NPCSocket(); EmptySocket socket = new EmptySocket();
NetworkManager netMgr = new NPCNetworkManager(socket, "npc mgr", new NetHandler() { NetworkManager netMgr = new EmptyNetworkManager(socket, "npc mgr", new NetHandler() {
@Override @Override
public boolean c() { public boolean c() {
return false; return false;
} }
}); });
netServerHandler = new NPCNetHandler(minecraftServer, netMgr, this); netServerHandler = new EmptyNetHandler(minecraftServer, netMgr, this);
netMgr.a(netServerHandler); netMgr.a(netServerHandler);
try { 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; 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.Equipment;
import net.citizensnpcs.api.abstraction.ItemStack; import net.citizensnpcs.api.abstraction.ItemStack;
import net.citizensnpcs.api.abstraction.MobType; import net.citizensnpcs.api.abstraction.MobType;
import net.citizensnpcs.api.abstraction.entity.Player; 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 { public class SpoutPlayer extends SpoutEntity implements Player {
private final VanillaPlayer player; private final VanillaPlayer player;
@ -24,7 +24,7 @@ public class SpoutPlayer extends SpoutEntity implements Player {
@Override @Override
public MobType getType() { public MobType getType() {
return SpoutConverter.toMobType(VanillaControllerTypes.PLAYER); return SpoutConverter.toMobType(VanillaControllerTypes.HUMAN);
} }
@Override @Override
@ -59,13 +59,13 @@ public class SpoutPlayer extends SpoutEntity implements Player {
case CARRIED: case CARRIED:
return SpoutConverter.toItemStack(player.getInventory().getCurrentItem()); return SpoutConverter.toItemStack(player.getInventory().getCurrentItem());
case HELMET: case HELMET:
return SpoutConverter.toItemStack(player.getInventory().getHelmet()); return SpoutConverter.toItemStack(player.getInventory().getArmor().getHelmet().getItem());
case BOOTS: case BOOTS:
return SpoutConverter.toItemStack(player.getInventory().getBoots()); return SpoutConverter.toItemStack(player.getInventory().getArmor().getBoots().getItem());
case CHESTPLATE: case CHESTPLATE:
return SpoutConverter.toItemStack(player.getInventory().getChestPlate()); return SpoutConverter.toItemStack(player.getInventory().getArmor().getChestPlate().getItem());
case LEGGINGS: case LEGGINGS:
return SpoutConverter.toItemStack(player.getInventory().getLeggings()); return SpoutConverter.toItemStack(player.getInventory().getArmor().getLeggings().getItem());
default: default:
return null; return null;
} }

View File

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

View File

@ -1,14 +1,17 @@
package net.citizensnpcs.trait; package net.citizensnpcs.trait;
import net.citizensnpcs.api.abstraction.EventHandler; import net.citizensnpcs.api.abstraction.EventHandler;
import net.citizensnpcs.api.abstraction.Listener;
import net.citizensnpcs.api.attachment.Attachment; import net.citizensnpcs.api.attachment.Attachment;
import net.citizensnpcs.api.event.NPCRightClickEvent; import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.exception.NPCLoadException; import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.npc.CitizensNPC; 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 //TODO: reduce reliance on CitizensNPC
public class Controllable extends Attachment implements Runnable, Listener, Toggleable { 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.Settings.Setting;
import net.citizensnpcs.api.abstraction.WorldVector; import net.citizensnpcs.api.abstraction.WorldVector;
import net.citizensnpcs.api.abstraction.entity.Entity; 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.abstraction.entity.Player;
import net.citizensnpcs.api.attachment.Attachment; import net.citizensnpcs.api.attachment.Attachment;
import net.citizensnpcs.api.exception.NPCLoadException; import net.citizensnpcs.api.exception.NPCLoadException;
@ -16,10 +17,10 @@ import net.citizensnpcs.api.util.DataKey;
public class LookClose extends Attachment implements Runnable, Toggleable { public class LookClose extends Attachment implements Runnable, Toggleable {
private boolean enabled = Setting.DEFAULT_LOOK_CLOSE.asBoolean(); private boolean enabled = Setting.DEFAULT_LOOK_CLOSE.asBoolean();
private Player lookingAt; private Player lookingAt;
private final NPC npc; private final LandMob entity;
public LookClose(NPC npc) { public LookClose(NPC npc) {
this.npc = npc; this.entity = (LandMob) npc.getEntity();
} }
private void faceEntity(Entity from, Entity at) { private void faceEntity(Entity from, Entity at) {
@ -50,23 +51,22 @@ public class LookClose extends Attachment implements Runnable, Toggleable {
@Override @Override
public void run() { public void run() {
if (!enabled || npc.getAI().hasDestination()) if (!enabled || entity.hasDestination())
return; return;
if (hasInvalidTarget()) { if (hasInvalidTarget())
findNewTarget(); findNewTarget();
}
if (lookingAt != null) { if (lookingAt != null)
faceEntity(npc.getEntity(), lookingAt); faceEntity(entity, lookingAt);
}
} }
private void findNewTarget() { 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>() { Collections.sort(nearby, new Comparator<Entity>() {
@Override @Override
public int compare(Entity o1, Entity o2) { public int compare(Entity o1, Entity o2) {
double d1 = o1.getLocation().distanceSquared(npc.getEntity().getLocation()); double d1 = o1.getLocation().distanceSquared(entity.getLocation());
double d2 = o2.getLocation().distanceSquared(npc.getEntity().getLocation()); double d2 = o2.getLocation().distanceSquared(entity.getLocation());
return Double.compare(d1, d2); return Double.compare(d1, d2);
} }
}); });
@ -82,8 +82,8 @@ public class LookClose extends Attachment implements Runnable, Toggleable {
private boolean hasInvalidTarget() { private boolean hasInvalidTarget() {
if (lookingAt == null) if (lookingAt == null)
return true; return true;
if (!lookingAt.isOnline() || lookingAt.getWorld() != npc.getEntity().getWorld() if (!lookingAt.isOnline() || lookingAt.getWorld() != entity.getWorld()
|| lookingAt.getLocation().distanceSquared(npc.getEntity().getLocation()) > 5) { || lookingAt.getLocation().distanceSquared(entity.getLocation()) > 5) {
lookingAt = null; lookingAt = null;
return true; return true;
} }

View File

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

View File

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

View File

@ -1,15 +1,45 @@
package net.citizensnpcs.trait.waypoint; package net.citizensnpcs.trait.waypoint;
import javax.xml.stream.Location; import net.citizensnpcs.api.abstraction.WorldVector;
public class Waypoint { public class Waypoint {
private final Location location; private final WorldVector location;
public Waypoint(Location location) { public Waypoint(WorldVector location) {
this.location = location; this.location = location;
} }
public Location getLocation() { public WorldVector getLocation() {
return location; 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; package net.citizensnpcs.trait.waypoint;
import net.citizensnpcs.api.abstraction.entity.Player; import net.citizensnpcs.api.abstraction.entity.Player;
import net.citizensnpcs.api.ai.AI;
import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.editor.Editor; import net.citizensnpcs.editor.Editor;
@ -16,14 +15,6 @@ public interface WaypointProvider {
*/ */
public Editor createEditor(Player player); 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}. * Loads from the specified {@link DataKey}.
* *

View File

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