Search in sources :

Example 6 with Notable

use of com.denizenscript.denizencore.objects.notable.Notable in project Denizen-For-Bukkit by DenizenScript.

the class CuboidTag method valueOf.

@Fetchable("cu")
public static CuboidTag valueOf(String string, TagContext context) {
    if (string == null) {
        return null;
    }
    if (CoreUtilities.toLowerCase(string).startsWith("cu@")) {
        string = string.substring("cu@".length());
    }
    Notable noted = NoteManager.getSavedObject(string);
    if (noted instanceof CuboidTag) {
        return (CuboidTag) noted;
    }
    if (CoreUtilities.contains(string, '@')) {
        if (CoreUtilities.contains(string, '|') && string.contains("l@")) {
            Debug.echoError("Warning: likely improperly constructed CuboidTag '" + string + "' - use to_cuboid");
        } else {
            return null;
        }
    }
    if (CoreUtilities.contains(string, '|')) {
        ListTag positions = ListTag.valueOf(string, context);
        if (positions.size() > 1 && LocationTag.matches(positions.get(0)) && LocationTag.matches(positions.get(1))) {
            if (positions.size() % 2 != 0) {
                if (context == null || context.showErrors()) {
                    Debug.echoError("valueOf CuboidTag returning null (Uneven number of locations): '" + string + "'.");
                }
                return null;
            }
            CuboidTag toReturn = new CuboidTag();
            for (int i = 0; i < positions.size(); i += 2) {
                LocationTag pos_1 = LocationTag.valueOf(positions.get(i), context);
                LocationTag pos_2 = LocationTag.valueOf(positions.get(i + 1), context);
                if (pos_1 == null || pos_2 == null) {
                    if (context == null || context.showErrors()) {
                        Debug.echoError("valueOf in CuboidTag returning null (null locations): '" + string + "'.");
                    }
                    return null;
                }
                if (pos_1.getWorldName() == null || pos_2.getWorldName() == null) {
                    if (context == null || context.showErrors()) {
                        Debug.echoError("valueOf in CuboidTag returning null (null worlds): '" + string + "'.");
                    }
                    return null;
                }
                toReturn.addPair(pos_1, pos_2);
            }
            if (toReturn.pairs.size() > 0) {
                return toReturn;
            }
        }
    } else if (CoreUtilities.contains(string, ',')) {
        List<String> subStrs = CoreUtilities.split(string, ',');
        if (subStrs.size() < 7 || (subStrs.size() - 1) % 6 != 0) {
            if (context == null || context.showErrors()) {
                Debug.echoError("valueOf CuboidTag returning null (Improper number of commas): '" + string + "'.");
            }
            return null;
        }
        CuboidTag toReturn = new CuboidTag();
        String worldName = subStrs.get(0);
        if (worldName.startsWith("w@")) {
            worldName = worldName.substring("w@".length());
        }
        try {
            for (int i = 0; i < subStrs.size() - 1; i += 6) {
                LocationTag locationOne = new LocationTag(parseRoundDouble(subStrs.get(i + 1)), parseRoundDouble(subStrs.get(i + 2)), parseRoundDouble(subStrs.get(i + 3)), worldName);
                LocationTag locationTwo = new LocationTag(parseRoundDouble(subStrs.get(i + 4)), parseRoundDouble(subStrs.get(i + 5)), parseRoundDouble(subStrs.get(i + 6)), worldName);
                toReturn.addPair(locationOne, locationTwo);
            }
        } catch (NumberFormatException ex) {
            if (context == null || context.showErrors()) {
                Debug.echoError("valueOf CuboidTag returning null (Improper number value inputs): '" + ex.getMessage() + "'.");
            }
            return null;
        }
        if (toReturn.pairs.size() > 0) {
            return toReturn;
        }
    }
    if (context == null || context.showErrors()) {
        Debug.echoError("Minor: valueOf CuboidTag returning null: " + string);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Notable(com.denizenscript.denizencore.objects.notable.Notable) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 7 with Notable

use of com.denizenscript.denizencore.objects.notable.Notable in project Denizen-For-Bukkit by DenizenScript.

the class AreaEnterExitScriptEvent method processNewPosition.

public void processNewPosition(EntityTag entity, Location pos, Event eventCause) {
    if (onlyTrackPlayers && !entity.isPlayer()) {
        return;
    }
    HashSet<String> inAreas = entitiesInArea.get(entity.getUUID());
    if (doTrackAll || matchers != null || flagTracked != null) {
        for (CuboidTag cuboid : NoteManager.getAllType(CuboidTag.class)) {
            if (anyMatch(cuboid.noteName, cuboid)) {
                processSingle(cuboid, entity, inAreas, pos, eventCause);
            }
        }
        for (EllipsoidTag ellipsoid : NoteManager.getAllType(EllipsoidTag.class)) {
            if (anyMatch(ellipsoid.noteName, ellipsoid)) {
                processSingle(ellipsoid, entity, inAreas, pos, eventCause);
            }
        }
        for (PolygonTag polygon : NoteManager.getAllType(PolygonTag.class)) {
            if (anyMatch(polygon.noteName, polygon)) {
                processSingle(polygon, entity, inAreas, pos, eventCause);
            }
        }
    } else {
        for (String name : exactTracked) {
            Notable obj = NoteManager.getSavedObject(name);
            if (!(obj instanceof AreaContainmentObject)) {
                Debug.echoError("Invalid area enter/exit event area '" + name + "'");
                continue;
            }
            processSingle((AreaContainmentObject) obj, entity, inAreas, pos, eventCause);
        }
    }
    if (inAreas != null && inAreas.isEmpty()) {
        entitiesInArea.remove(entity.getUUID());
    }
}
Also used : Notable(com.denizenscript.denizencore.objects.notable.Notable)

Aggregations

Notable (com.denizenscript.denizencore.objects.notable.Notable)7 Denizen (com.denizenscript.denizen.Denizen)1 BukkitScriptEvent (com.denizenscript.denizen.events.BukkitScriptEvent)1 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)1 AssignmentTrait (com.denizenscript.denizen.npc.traits.AssignmentTrait)1 com.denizenscript.denizen.objects (com.denizenscript.denizen.objects)1 BossBarCommand (com.denizenscript.denizen.scripts.commands.server.BossBarCommand)1 AssignmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)1 CommandScriptHelper (com.denizenscript.denizen.scripts.containers.core.CommandScriptHelper)1 InventoryScriptContainer (com.denizenscript.denizen.scripts.containers.core.InventoryScriptContainer)1 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)1 ScoreboardHelper (com.denizenscript.denizen.utilities.ScoreboardHelper)1 Settings (com.denizenscript.denizen.utilities.Settings)1 Utilities (com.denizenscript.denizen.utilities.Utilities)1 VanillaTagHelper (com.denizenscript.denizen.utilities.VanillaTagHelper)1 Depends (com.denizenscript.denizen.utilities.depends.Depends)1 SlotHelper (com.denizenscript.denizen.utilities.inventory.SlotHelper)1 DenizenCore (com.denizenscript.denizencore.DenizenCore)1 ScriptEvent (com.denizenscript.denizencore.events.ScriptEvent)1 TickScriptEvent (com.denizenscript.denizencore.events.core.TickScriptEvent)1