mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 11:38:26 +01:00
Fix for controllables not creating the trait properly
This commit is contained in:
parent
8cf64ddc73
commit
8225f3e57b
@ -118,7 +118,7 @@ public class Citizens extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
restoreOldClassLoader();
|
||||
tearDownScripting();
|
||||
// Don't bother with this part if MC versions are not compatible
|
||||
if (compatible) {
|
||||
save();
|
||||
@ -145,7 +145,6 @@ public class Citizens extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
registerScriptHelpers();
|
||||
replaceClassLoader();
|
||||
|
||||
config = new Settings(getDataFolder());
|
||||
|
||||
@ -176,6 +175,10 @@ public class Citizens extends JavaPlugin {
|
||||
}
|
||||
|
||||
// Run metrics last
|
||||
startMetrics();
|
||||
}
|
||||
|
||||
private void startMetrics() {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -233,6 +236,7 @@ public class Citizens extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void registerScriptHelpers() {
|
||||
setupScripting();
|
||||
ScriptCompiler compiler = CitizensAPI.getScriptCompiler();
|
||||
compiler.registerGlobalContextProvider(new EventRegistrar(this));
|
||||
compiler.registerGlobalContextProvider(new PluginProvider(this));
|
||||
@ -247,13 +251,13 @@ public class Citizens extends JavaPlugin {
|
||||
getServer().getPluginManager().callEvent(new CitizensReloadEvent());
|
||||
}
|
||||
|
||||
private void replaceClassLoader() {
|
||||
private void setupScripting() {
|
||||
contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(getClassLoader());
|
||||
// workaround to fix scripts not loading plugin classes properly
|
||||
}
|
||||
|
||||
private void restoreOldClassLoader() {
|
||||
private void tearDownScripting() {
|
||||
Thread.currentThread().setContextClassLoader(contextClassLoader);
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ import net.citizensnpcs.command.CommandContext;
|
||||
import net.citizensnpcs.command.Requirements;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.command.exception.NoPermissionsException;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.npc.CitizensTraitManager;
|
||||
import net.citizensnpcs.trait.Age;
|
||||
@ -100,7 +99,7 @@ public class NPCCommands {
|
||||
npc.removeTrait(Controllable.class);
|
||||
Messaging.send(player, StringHelper.wrap(npc.getName()) + " can no longer be controlled.");
|
||||
} else {
|
||||
npc.addTrait(new Controllable((CitizensNPC) npc));
|
||||
npc.addTrait(traitManager.getTrait(Controllable.class, npc));
|
||||
Messaging.send(player, StringHelper.wrap(npc.getName()) + " can now be controlled.");
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
|
||||
@Override
|
||||
public void addTrait(Trait trait) {
|
||||
// TODO: right now every addTrait call has to be wrapped with
|
||||
// TraitManager.getTrait(Class, NPC) -- this is bad, need to fix this.
|
||||
if (trait == null) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot register a null trait. Was it registered properly?");
|
||||
return;
|
||||
@ -52,8 +54,9 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
if (traits.containsKey(trait.getClass()))
|
||||
runnables.remove(traits.get(trait.getClass()));
|
||||
}
|
||||
if (trait instanceof Listener)
|
||||
if (trait instanceof Listener) {
|
||||
Bukkit.getPluginManager().registerEvents((Listener) trait, trait.getPlugin());
|
||||
}
|
||||
|
||||
Map<Class<? extends Trait>, Trait> map = traits.get(trait.getPlugin());
|
||||
if (map == null)
|
||||
|
Loading…
Reference in New Issue
Block a user