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