update to use EntityType instead of CreatureType

This commit is contained in:
aPunch 2012-02-23 17:45:45 -06:00
parent 1e8f9de47d
commit edcdcf1aec
9 changed files with 45 additions and 41 deletions

5
README
View File

@ -2,3 +2,8 @@
Citizens is an NPC plugin for the Bukkit API. It was first released on March 5, 2011, and has since seen numerous updates. Citizens Citizens is an NPC plugin for the Bukkit API. It was first released on March 5, 2011, and has since seen numerous updates. Citizens
provides an API itself, which developers can use to create their own NPC characters. provides an API itself, which developers can use to create their own NPC characters.
Compatible With:
-CitizensAPI 2.0
-Bukkit 1.1-R5
-CraftBukkit 1.1-R5

View File

@ -1,6 +1,6 @@
<project name="Citizens" default="dist" basedir="."> <project name="Citizens" default="dist" basedir=".">
<description> <description>
Citizens build file Build file used for testing purposes
</description> </description>
<!-- set global properties for this build --> <!-- set global properties for this build -->
<property name="src" location="src" /> <property name="src" location="src" />
@ -16,8 +16,8 @@
<javac srcdir="${src}" destdir="${build}" debug="on" debuglevel="lines,vars,source" includeantruntime="false" encoding="Cp1252"> <javac srcdir="${src}" destdir="${build}" debug="on" debuglevel="lines,vars,source" includeantruntime="false" encoding="Cp1252">
<classpath> <classpath>
<pathelement path="${lib}" /> <pathelement path="${lib}" />
<pathelement location="${lib}/bukkit-1.1-R3.jar" /> <pathelement location="${lib}/bukkit-1.1-R5-SNAPSHOT.jar" />
<pathelement location="${lib}/craftbukkit-1.1-R3.jar" /> <pathelement location="${lib}/craftbukkit-1.1-R5-SNAPSHOT.jar" />
<pathelement location="${lib}/CitizensAPI.jar" /> <pathelement location="${lib}/CitizensAPI.jar" />
<pathelement location="${lib}/hamcrest.jar" /> <pathelement location="${lib}/hamcrest.jar" />
<pathelement location="${lib}/junit-dep-4.10.jar" /> <pathelement location="${lib}/junit-dep-4.10.jar" />

Binary file not shown.

View File

@ -44,7 +44,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.CreatureType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -267,8 +267,7 @@ public class Citizens extends JavaPlugin {
throw new NPCLoadException("Could not find a name for the NPC with ID '" + id + "'."); throw new NPCLoadException("Could not find a name for the NPC with ID '" + id + "'.");
String type = key.getString("traits.type").toUpperCase(); String type = key.getString("traits.type").toUpperCase();
NPC npc = npcManager.createNPC(type.equalsIgnoreCase("DEFAULT") ? null : CreatureType.valueOf(type), id, NPC npc = npcManager.createNPC(EntityType.valueOf(type), id, key.getString("name"), null);
key.getString("name"), null);
try { try {
npc.load(key); npc.load(key);
} catch (NPCException ex) { } catch (NPCException ex) {

View File

@ -18,7 +18,7 @@ import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.StringHelper;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.CreatureType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@ -56,10 +56,10 @@ public class NPCCommands {
Messaging.sendError(player, "NPC names cannot be longer than 16 characters. The name has been shortened."); Messaging.sendError(player, "NPC names cannot be longer than 16 characters. The name has been shortened.");
name = name.substring(0, 15); name = name.substring(0, 15);
} }
CreatureType type = null; EntityType type = EntityType.PLAYER;
if (args.hasValueFlag("type")) if (args.hasValueFlag("type"))
try { try {
type = CreatureType.valueOf(args.getFlag("type").toUpperCase().replace('-', '_')); type = EntityType.valueOf(args.getFlag("type").toUpperCase().replace('-', '_'));
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
Messaging.sendError(player, "'" + args.getFlag("type") Messaging.sendError(player, "'" + args.getFlag("type")
+ "' is not a valid mob type. Using default NPC."); + "' is not a valid mob type. Using default NPC.");
@ -84,7 +84,7 @@ public class NPCCommands {
create.addTrait(new Owner(player.getName())); create.addTrait(new Owner(player.getName()));
// Set the mob type // Set the mob type
create.addTrait(new MobType(type == null ? "DEFAULT" : type.toString())); create.addTrait(new MobType(type.toString()));
create.spawn(player.getLocation()); create.spawn(player.getLocation());
npcManager.selectNPC(player, create); npcManager.selectNPC(player, create);

View File

@ -14,8 +14,8 @@ import net.citizensnpcs.api.util.Storage;
import net.citizensnpcs.util.ByIdArray; import net.citizensnpcs.util.ByIdArray;
import net.citizensnpcs.util.NPCBuilder; import net.citizensnpcs.util.NPCBuilder;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
@ -31,7 +31,7 @@ public class CitizensNPCManager implements NPCManager {
this.saves = saves; this.saves = saves;
} }
public NPC createNPC(CreatureType type, int id, String name, Character character) { public NPC createNPC(EntityType type, int id, String name, Character character) {
if (npcs.contains(id)) if (npcs.contains(id))
throw new IllegalArgumentException("An NPC already has the ID '" + id + "'."); throw new IllegalArgumentException("An NPC already has the ID '" + id + "'.");
@ -42,12 +42,12 @@ public class CitizensNPCManager implements NPCManager {
} }
@Override @Override
public NPC createNPC(CreatureType type, String name) { public NPC createNPC(EntityType type, String name) {
return createNPC(type, name, null); return createNPC(type, name, null);
} }
@Override @Override
public NPC createNPC(CreatureType type, String name, Character character) { public NPC createNPC(EntityType type, String name, Character character) {
return createNPC(type, generateUniqueId(), name, character); return createNPC(type, generateUniqueId(), name, character);
} }

View File

@ -30,38 +30,38 @@ import net.citizensnpcs.npc.entity.CitizensVillagerNPC;
import net.citizensnpcs.npc.entity.CitizensWolfNPC; import net.citizensnpcs.npc.entity.CitizensWolfNPC;
import net.citizensnpcs.npc.entity.CitizensZombieNPC; import net.citizensnpcs.npc.entity.CitizensZombieNPC;
import org.bukkit.entity.CreatureType; import org.bukkit.entity.EntityType;
public class NPCBuilder { public class NPCBuilder {
private static final Map<CreatureType, Class<? extends CitizensNPC>> types = new HashMap<CreatureType, Class<? extends CitizensNPC>>(); private static final Map<EntityType, Class<? extends CitizensNPC>> types = new HashMap<EntityType, Class<? extends CitizensNPC>>();
static { static {
types.put(CreatureType.BLAZE, CitizensBlazeNPC.class); types.put(EntityType.BLAZE, CitizensBlazeNPC.class);
types.put(CreatureType.CAVE_SPIDER, CitizensCaveSpiderNPC.class); types.put(EntityType.CAVE_SPIDER, CitizensCaveSpiderNPC.class);
types.put(CreatureType.CHICKEN, CitizensChickenNPC.class); types.put(EntityType.CHICKEN, CitizensChickenNPC.class);
types.put(CreatureType.COW, CitizensCowNPC.class); types.put(EntityType.COW, CitizensCowNPC.class);
types.put(CreatureType.CREEPER, CitizensCreeperNPC.class); types.put(EntityType.CREEPER, CitizensCreeperNPC.class);
types.put(CreatureType.ENDER_DRAGON, CitizensEnderDragonNPC.class); types.put(EntityType.ENDER_DRAGON, CitizensEnderDragonNPC.class);
types.put(CreatureType.ENDERMAN, CitizensEndermanNPC.class); types.put(EntityType.ENDERMAN, CitizensEndermanNPC.class);
types.put(CreatureType.GHAST, CitizensGhastNPC.class); types.put(EntityType.GHAST, CitizensGhastNPC.class);
types.put(CreatureType.GIANT, CitizensGiantNPC.class); types.put(EntityType.GIANT, CitizensGiantNPC.class);
types.put(CreatureType.MAGMA_CUBE, CitizensMagmaCubeNPC.class); types.put(EntityType.MAGMA_CUBE, CitizensMagmaCubeNPC.class);
types.put(CreatureType.MUSHROOM_COW, CitizensMushroomCowNPC.class); types.put(EntityType.MUSHROOM_COW, CitizensMushroomCowNPC.class);
types.put(CreatureType.PIG, CitizensPigNPC.class); types.put(EntityType.PIG, CitizensPigNPC.class);
types.put(CreatureType.PIG_ZOMBIE, CitizensPigZombieNPC.class); types.put(EntityType.PIG_ZOMBIE, CitizensPigZombieNPC.class);
types.put(CreatureType.SHEEP, CitizensSheepNPC.class); types.put(EntityType.SHEEP, CitizensSheepNPC.class);
types.put(CreatureType.SILVERFISH, CitizensSilverfishNPC.class); types.put(EntityType.SILVERFISH, CitizensSilverfishNPC.class);
types.put(CreatureType.SKELETON, CitizensSkeletonNPC.class); types.put(EntityType.SKELETON, CitizensSkeletonNPC.class);
types.put(CreatureType.SLIME, CitizensSlimeNPC.class); types.put(EntityType.SLIME, CitizensSlimeNPC.class);
types.put(CreatureType.SNOWMAN, CitizensSnowmanNPC.class); types.put(EntityType.SNOWMAN, CitizensSnowmanNPC.class);
types.put(CreatureType.SPIDER, CitizensSpiderNPC.class); types.put(EntityType.SPIDER, CitizensSpiderNPC.class);
types.put(CreatureType.SQUID, CitizensSquidNPC.class); types.put(EntityType.SQUID, CitizensSquidNPC.class);
types.put(CreatureType.VILLAGER, CitizensVillagerNPC.class); types.put(EntityType.VILLAGER, CitizensVillagerNPC.class);
types.put(CreatureType.WOLF, CitizensWolfNPC.class); types.put(EntityType.WOLF, CitizensWolfNPC.class);
types.put(CreatureType.ZOMBIE, CitizensZombieNPC.class); types.put(EntityType.ZOMBIE, CitizensZombieNPC.class);
} }
public CitizensNPC getByType(CreatureType type, CitizensNPCManager npcManager, int id, String name) { public CitizensNPC getByType(EntityType type, CitizensNPCManager npcManager, int id, String name) {
Class<? extends CitizensNPC> npcClass = types.get(type); Class<? extends CitizensNPC> npcClass = types.get(type);
if (npcClass == null) if (npcClass == null)
npcClass = CitizensHumanNPC.class; npcClass = CitizensHumanNPC.class;