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