Search in sources :

Example 6 with Anchor

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]));
        }
    }
}
Also used : Anchor(net.citizensnpcs.util.Anchor) DataKey(net.citizensnpcs.api.util.DataKey) Location(org.bukkit.Location)

Example 7 with Anchor

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;
            }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Anchors(net.citizensnpcs.trait.Anchors) Anchor(net.citizensnpcs.util.Anchor) NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Aggregations

Anchor (net.citizensnpcs.util.Anchor)7 Anchors (net.citizensnpcs.trait.Anchors)4 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 NPC (net.citizensnpcs.api.npc.NPC)2 Trait (net.citizensnpcs.api.trait.Trait)2 DataKey (net.citizensnpcs.api.util.DataKey)2 Pose (net.citizensnpcs.util.Pose)2 LocationTag (com.denizenscript.denizen.objects.LocationTag)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 AssignmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)1 FlaggableObject (com.denizenscript.denizencore.flags.FlaggableObject)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)1 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 FlagManager (net.aufdemrand.denizen.flags.FlagManager)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)1 Element (net.aufdemrand.denizencore.objects.Element)1