@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element toggle = scriptEntry.getElement("state");
Element traitName = scriptEntry.getElement("trait");
NPC npc = ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getCitizen();
dB.report(scriptEntry, getName(),
traitName.debug() +
toggle.debug() +
((BukkitScriptEntryData)scriptEntry.entryData).getNPC().debug());
Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(traitName.asString());
if (trait == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Trait not found: " + traitName.asString());
return;
}
switch (Toggle.valueOf(toggle.asString())) {
case TRUE:
case ON:
if (npc.hasTrait(trait))
dB.echoError(scriptEntry.getResidingQueue(), "NPC already has trait '" + traitName.asString() + "'");
else
npc.addTrait(trait);
break;
case FALSE:
case OFF:
if (!npc.hasTrait(trait))
dB.echoError(scriptEntry.getResidingQueue(), "NPC does not have trait '" + traitName.asString() + "'");
else
npc.removeTrait(trait);
break;
case TOGGLE:
if (npc.hasTrait(trait))
npc.removeTrait(trait);
else
npc.addTrait(trait);
break;
}
}