use of net.citizensnpcs.util.Anchor in project Citizens2 by CitizensDev.
the class Anchors method load.
@Override
public void load(DataKey key) throws NPCLoadException {
for (DataKey sub : key.getRelative("list").getIntegerSubKeys()) {
String[] parts = sub.getString("").split(";");
Location location;
try {
location = new Location(Bukkit.getServer().getWorld(parts[1]), Double.valueOf(parts[2]), Double.valueOf(parts[3]), Double.valueOf(parts[4]));
anchors.add(new Anchor(parts[0], location));
} catch (NumberFormatException e) {
Messaging.logTr(Messages.SKIPPING_INVALID_ANCHOR, sub.name(), e.getMessage());
} catch (NullPointerException e) {
// Invalid world/location/etc. Still enough data to build an
// unloaded anchor
anchors.add(new Anchor(parts[0], sub.getString("").split(";", 2)[1]));
}
}
}
use of net.citizensnpcs.util.Anchor in project Denizen-For-Bukkit by DenizenScript.
the class AnchorCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
Action action = (Action) scriptEntry.getObject("action");
LocationTag location = scriptEntry.getObjectTag("location");
ElementTag range = scriptEntry.getElement("range");
ElementTag id = scriptEntry.getElement("id");
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), npc, db("action", action.name()), id, location, range);
}
Anchors anchors = npc.getCitizen().getOrAddTrait(Anchors.class);
switch(action) {
case ADD:
{
if (location == null) {
Debug.echoError("Must specify a location!");
return;
}
Anchor existing = anchors.getAnchor(id.asString());
if (existing != null) {
anchors.removeAnchor(existing);
}
anchors.addAnchor(id.asString(), location);
break;
}
case REMOVE:
{
Anchor n = anchors.getAnchor(id.asString());
if (n == null) {
Debug.echoError(scriptEntry, "Invalid anchor name '" + id.asString() + "'");
} else {
anchors.removeAnchor(n);
}
break;
}
}
}
Aggregations