mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-25 18:47:40 +01:00
Fixes
This commit is contained in:
parent
4fb0b03e29
commit
6d95c73f5c
@ -52,7 +52,7 @@ public class Citizens extends JavaPlugin {
|
||||
private Settings config;
|
||||
private boolean compatible;
|
||||
private final CitizensCharacterManager characterManager = new CitizensCharacterManager();
|
||||
private final CitizensTraitManager traitManager = new CitizensTraitManager();
|
||||
private CitizensTraitManager traitManager;
|
||||
private CitizensNPCManager npcManager;
|
||||
private Storage saves; // TODO: refactor this into an NPCStore (remove
|
||||
// dependency on Storage).
|
||||
@ -159,6 +159,7 @@ public class Citizens extends JavaPlugin {
|
||||
|
||||
// Register API managers
|
||||
npcManager = new CitizensNPCManager(this, saves);
|
||||
traitManager = new CitizensTraitManager(this);
|
||||
CitizensAPI.setNPCManager(npcManager);
|
||||
CitizensAPI.setCharacterManager(characterManager);
|
||||
CitizensAPI.setTraitManager(traitManager);
|
||||
@ -248,8 +249,8 @@ public class Citizens extends JavaPlugin {
|
||||
if (!key.keyExists("name"))
|
||||
throw new NPCLoadException("Could not find a name for the NPC with ID '" + id + "'.");
|
||||
|
||||
NPC npc = npcManager.createNPC(EntityType.valueOf(key.getString("traits.type").toUpperCase()), id, key
|
||||
.getString("name"), null);
|
||||
NPC npc = npcManager.createNPC(EntityType.valueOf(key.getString("traits.type").toUpperCase()), id,
|
||||
key.getString("name"), null);
|
||||
try {
|
||||
((CitizensNPC) npc).load(key);
|
||||
} catch (NPCException ex) {
|
||||
|
@ -53,7 +53,6 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
runnables.remove(traits.get(trait.getClass()));
|
||||
}
|
||||
if (trait instanceof Listener)
|
||||
// TODO: insert plugin instance somehow
|
||||
Bukkit.getPluginManager().registerEvents((Listener) trait, trait.getPlugin());
|
||||
|
||||
Map<Class<? extends Trait>, Trait> map = traits.get(trait.getPlugin());
|
||||
@ -119,8 +118,9 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
if (traits.get(plugin).containsKey(clazz))
|
||||
trait = traits.get(plugin).get(clazz);
|
||||
if (trait == null)
|
||||
addTrait(traitManager.getTrait(clazz, this));
|
||||
trait = traitManager.getTrait(clazz, this);
|
||||
|
||||
addTrait(trait);
|
||||
return trait != null ? clazz.cast(trait) : null;
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitFactory;
|
||||
@ -27,14 +27,15 @@ import net.citizensnpcs.trait.VillagerProfession;
|
||||
import net.citizensnpcs.trait.WoolColor;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
import net.citizensnpcs.trait.waypoint.Waypoints;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
public class CitizensTraitManager implements TraitManager {
|
||||
private final Map<Plugin, Map<String, Class<? extends Trait>>> registered = new HashMap<Plugin, Map<String, Class<? extends Trait>>>();
|
||||
private final Map<Class<? extends Trait>, Constructor<? extends Trait>> CACHED_CTORS = new HashMap<Class<? extends Trait>, Constructor<? extends Trait>>();
|
||||
|
||||
public CitizensTraitManager() {
|
||||
public CitizensTraitManager(Citizens plugin) {
|
||||
// Register Citizens traits
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("Citizens");
|
||||
Messaging.log("Plugin: " + plugin);
|
||||
|
||||
registerTrait(new TraitFactory(Age.class).withName("age").withPlugin(plugin));
|
||||
registerTrait(new TraitFactory(CurrentLocation.class).withName("location").withPlugin(plugin));
|
||||
@ -84,10 +85,10 @@ public class CitizensTraitManager implements TraitManager {
|
||||
for (Entry<String, Class<? extends Trait>> subEntry : entry.getValue().entrySet()) {
|
||||
if (!subEntry.getValue().equals(clazz))
|
||||
continue;
|
||||
Trait t = create(subEntry.getValue(), npc);
|
||||
t.setName(subEntry.getKey());
|
||||
t.setPlugin(entry.getKey());
|
||||
return (T) t;
|
||||
Trait trait = create(subEntry.getValue(), npc);
|
||||
trait.setName(subEntry.getKey());
|
||||
trait.setPlugin(entry.getKey());
|
||||
return (T) trait;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -44,7 +44,6 @@ public class Saddle extends Trait implements Toggleable, Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
// TODO: Complete trait/plugin system
|
||||
if (CitizensAPI.getNPCManager().isNPC(event.getRightClicked()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -31,8 +31,6 @@ public class Sheared extends Trait implements Toggleable, Listener {
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
// TODO Get rid of instanceof's, add
|
||||
// TraitFactory.withTypes(EntityType...) or similar
|
||||
if (npc.getBukkitEntity() instanceof Sheep)
|
||||
((Sheep) npc.getBukkitEntity()).setSheared(sheared);
|
||||
}
|
||||
@ -46,7 +44,6 @@ public class Sheared extends Trait implements Toggleable, Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerShearEntityEvent(PlayerShearEntityEvent event) {
|
||||
// TODO: Complete trait/plugin system
|
||||
if (CitizensAPI.getNPCManager().isNPC(event.getEntity()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ public class WoolColor extends Trait implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onSheepDyeWool(SheepDyeWoolEvent event) {
|
||||
// TODO: Complete trait/plugin system
|
||||
if (CitizensAPI.getNPCManager().isNPC(event.getEntity()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user