Search in sources :

Example 1 with Waypoints

use of net.citizensnpcs.trait.waypoint.Waypoints in project Denizen-For-Bukkit by DenizenScript.

the class dNPC method adjust.

@Override
public void adjust(Mechanism mechanism) {
    Element value = mechanism.getValue();
    // -->
    if (mechanism.matches("set_assignment") && mechanism.requireObject(dScript.class)) {
        getAssignmentTrait().setAssignment(value.asType(dScript.class).getName(), null);
    }
    // -->
    if (mechanism.matches("remove_assignment")) {
        getAssignmentTrait().removeAssignment(null);
    }
    // -->
    if (mechanism.matches("set_nickname")) {
        getNicknameTrait().setNickname(value.asString());
    }
    // -->
    if (mechanism.matches("remove_nickname")) {
        getNicknameTrait().removeNickname();
    }
    // -->
    if (mechanism.matches("set_entity_type") && mechanism.requireObject(dEntity.class)) {
        getCitizen().setBukkitEntityType(value.asType(dEntity.class).getBukkitEntityType());
    }
    // -->
    if (mechanism.matches("name") || mechanism.matches("set_name")) {
        getCitizen().setName(value.asString().length() > 64 ? value.asString().substring(0, 64) : value.asString());
    }
    // -->
    if (mechanism.matches("owner")) {
        getCitizen().getTrait(Owner.class).setOwner(value.asString());
    }
    // -->
    if (mechanism.matches("skin_blob")) {
        if (!mechanism.hasValue()) {
            getCitizen().data().remove(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA);
            getCitizen().data().remove(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA);
        } else {
            String[] dat = mechanism.getValue().asString().split(";");
            getCitizen().data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA, dat[0]);
            getCitizen().data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA, dat.length > 0 ? dat[1] : null);
        }
        if (getCitizen().isSpawned()) {
            getCitizen().despawn(DespawnReason.PENDING_RESPAWN);
            getCitizen().spawn(getCitizen().getStoredLocation());
        }
    }
    // -->
    if (mechanism.matches("skin")) {
        if (!mechanism.hasValue()) {
            getCitizen().data().remove(NPC.PLAYER_SKIN_UUID_METADATA);
        } else {
            getCitizen().data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, mechanism.getValue().asString());
        }
        if (getCitizen().isSpawned()) {
            getCitizen().despawn(DespawnReason.PENDING_RESPAWN);
            getCitizen().spawn(getCitizen().getStoredLocation());
        }
    }
    // -->
    if (mechanism.matches("item_type") && mechanism.requireObject(dItem.class)) {
        dItem item = mechanism.getValue().asType(dItem.class);
        Material mat = item.getMaterial().getMaterial();
        int data = item.getMaterial().getData((byte) 0);
        switch(getEntity().getType()) {
            case DROPPED_ITEM:
                ((org.bukkit.entity.Item) getEntity()).getItemStack().setType(mat);
                //((ItemController.ItemNPC) getEntity()).setType(mat, data);
                break;
            case ITEM_FRAME:
                ((ItemFrame) getEntity()).getItem().setType(mat);
                //((ItemFrameController.ItemFrameNPC) getEntity()).setType(mat, data);
                break;
            case FALLING_BLOCK:
                //((FallingBlockController.FallingBlockNPC) getEntity()).setType(mat, data);
                break;
            default:
                dB.echoError("NPC is the not an item type!");
                break;
        }
        if (getCitizen().isSpawned()) {
            getCitizen().despawn();
            getCitizen().spawn(getCitizen().getStoredLocation());
        }
    }
    // -->
    if (mechanism.matches("spawn")) {
        if (mechanism.requireObject("Invalid dLocation specified. Assuming last known NPC location.", dLocation.class)) {
            getCitizen().spawn(value.asType(dLocation.class));
        } else {
            getCitizen().spawn(getCitizen().getStoredLocation());
        }
    }
    // -->
    if (mechanism.matches("range") && mechanism.requireFloat()) {
        getCitizen().getNavigator().getDefaultParameters().range(mechanism.getValue().asFloat());
    }
    // -->
    if (mechanism.matches("attack_range") && mechanism.requireFloat()) {
        getCitizen().getNavigator().getDefaultParameters().attackRange(mechanism.getValue().asFloat());
    }
    // -->
    if (mechanism.matches("speed") && mechanism.requireFloat()) {
        getCitizen().getNavigator().getDefaultParameters().speedModifier(mechanism.getValue().asFloat());
    }
    // -->
    if (mechanism.matches("despawn")) {
        getCitizen().despawn(DespawnReason.PLUGIN);
    }
    // -->
    if (mechanism.matches("set_protected") && mechanism.requireBoolean()) {
        getCitizen().setProtected(value.asBoolean());
    }
    // -->
    if (mechanism.matches("lookclose") && mechanism.requireBoolean()) {
        getLookCloseTrait().lookClose(value.asBoolean());
    }
    // -->
    if (mechanism.matches("set_examiner")) {
        if (mechanism.getValue().toString().equalsIgnoreCase("default")) {
            getNavigator().getLocalParameters().clearExaminers();
            getNavigator().getLocalParameters().examiner(new MinecraftBlockExaminer());
        } else if (mechanism.getValue().toString().equalsIgnoreCase("fly")) {
            getNavigator().getLocalParameters().clearExaminers();
            getNavigator().getLocalParameters().examiner(new FlyingBlockExaminer());
        } else if (mechanism.getValue().toString().equalsIgnoreCase("path")) {
            getNavigator().getLocalParameters().clearExaminers();
            getNavigator().getLocalParameters().examiner(new PathBlockExaminer(this, null));
        }
    }
    // -->
    if (mechanism.matches("teleport_on_stuck") && mechanism.requireBoolean()) {
        if (value.asBoolean()) {
            getNavigator().getDefaultParameters().stuckAction(TeleportStuckAction.INSTANCE);
        } else {
            getNavigator().getDefaultParameters().stuckAction(null);
        }
    }
    // -->
    if (mechanism.matches("set_distance") && mechanism.requireDouble()) {
        getNavigator().getDefaultParameters().distanceMargin(mechanism.getValue().asDouble());
    }
    // -->
    if (mechanism.matches("add_waypoint") && mechanism.requireObject(dLocation.class)) {
        if (!getCitizen().hasTrait(Waypoints.class)) {
            getCitizen().addTrait(Waypoints.class);
        }
        Waypoints wp = getCitizen().getTrait(Waypoints.class);
        if ((wp.getCurrentProvider() instanceof WaypointProvider.EnumerableWaypointProvider)) {
            ((List<Waypoint>) ((WaypointProvider.EnumerableWaypointProvider) wp.getCurrentProvider()).waypoints()).add(new Waypoint(value.asType(dLocation.class)));
        }
    }
    // Iterate through this object's properties' mechanisms
    for (Property property : PropertyParser.getProperties(this)) {
        property.adjust(mechanism);
        if (mechanism.fulfilled()) {
            break;
        }
    }
    // Pass along to dEntity mechanism handler if not already handled.
    if (!mechanism.fulfilled()) {
        if (isSpawned()) {
            new dEntity(getEntity()).adjust(mechanism);
        } else {
            mechanism.reportInvalid();
        }
    }
}
Also used : MinecraftBlockExaminer(net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer) Waypoints(net.citizensnpcs.trait.waypoint.Waypoints) PathBlockExaminer(net.aufdemrand.denizen.npc.examiners.PathBlockExaminer) Owner(net.citizensnpcs.api.trait.trait.Owner) Material(org.bukkit.Material) Waypoint(net.citizensnpcs.trait.waypoint.Waypoint) WaypointProvider(net.citizensnpcs.trait.waypoint.WaypointProvider) FlyingBlockExaminer(net.citizensnpcs.api.astar.pathfinder.FlyingBlockExaminer) ArrayList(java.util.ArrayList) List(java.util.List) Waypoint(net.citizensnpcs.trait.waypoint.Waypoint) Property(net.aufdemrand.denizencore.objects.properties.Property)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 PathBlockExaminer (net.aufdemrand.denizen.npc.examiners.PathBlockExaminer)1 Property (net.aufdemrand.denizencore.objects.properties.Property)1 FlyingBlockExaminer (net.citizensnpcs.api.astar.pathfinder.FlyingBlockExaminer)1 MinecraftBlockExaminer (net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer)1 Owner (net.citizensnpcs.api.trait.trait.Owner)1 Waypoint (net.citizensnpcs.trait.waypoint.Waypoint)1 WaypointProvider (net.citizensnpcs.trait.waypoint.WaypointProvider)1 Waypoints (net.citizensnpcs.trait.waypoint.Waypoints)1 Material (org.bukkit.Material)1