Search in sources :

Example 46 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class NPCTags method navStuck.

// <--[event]
// @Events
// npc stuck
//
// @Triggers when an NPC's navigator is stuck.
//
// @Context
// <context.action> returns 'teleport' or 'none'
//
// @Determine
// "NONE" to do nothing.
// "TELEPORT" to teleport.
// -->
// <--[action]
// @Actions
// stuck
//
// @Triggers when the NPC's navigator is stuck.
//
// @Context
// <context.action> returns 'teleport' or 'none'
//
// @Determine
// "NONE" to do nothing.
// "TELEPORT" to teleport.
//
// -->
@EventHandler
public void navStuck(NavigationStuckEvent event) {
    dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
    Map<String, dObject> context = new HashMap<String, dObject>();
    context.put("action", new Element(event.getAction() == TeleportStuckAction.INSTANCE ? "teleport" : "none"));
    // Do world script event 'On NPC stuck'
    if (NPCNavigationSmartEvent.IsActive()) {
        List<String> determinations = OldEventManager.doEvents(Arrays.asList("npc stuck"), new BukkitScriptEntryData(null, npc), context);
        for (String determination : determinations) {
            if (determination.equalsIgnoreCase("none")) {
                event.setAction(null);
            }
            if (determination.equalsIgnoreCase("teleport")) {
                event.setAction(TeleportStuckAction.INSTANCE);
            }
        }
    }
    // Do the assignment script action
    if (!event.getNPC().hasTrait(AssignmentTrait.class)) {
        return;
    }
    String determination2 = npc.action("stuck", null, context);
    if (determination2.equalsIgnoreCase("none")) {
        event.setAction(null);
    }
    if (determination2.equalsIgnoreCase("teleport")) {
        event.setAction(TeleportStuckAction.INSTANCE);
    }
}
Also used : AssignmentTrait(net.aufdemrand.denizen.npc.traits.AssignmentTrait) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) HashMap(java.util.HashMap) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) Element(net.aufdemrand.denizencore.objects.Element) EventHandler(org.bukkit.event.EventHandler)

Example 47 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class PlayEffectCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    ParticleHelper particleHelper = NMSHandler.getInstance().getParticleHelper();
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("location") && arg.matchesArgumentList(dLocation.class)) {
            scriptEntry.addObject("location", arg.asType(dList.class).filter(dLocation.class));
        } else if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
            if (particleHelper.hasParticle(arg.getValue())) {
                scriptEntry.addObject("particleeffect", particleHelper.getParticle(arg.getValue()));
            } else if (arg.matches("random")) {
                // Get another effect if "RANDOM" is used
                if (CoreUtilities.getRandom().nextDouble() < 0.5) {
                    // Make sure the new effect is not an invisible effect
                    List<Particle> visible = particleHelper.getVisibleParticles();
                    scriptEntry.addObject("particleeffect", visible.get(CoreUtilities.getRandom().nextInt(visible.size())));
                } else {
                    List<Effect> visual = particleHelper.getVisualEffects();
                    scriptEntry.addObject("effect", visual.get(CoreUtilities.getRandom().nextInt(visual.size())));
                }
            } else if (arg.startsWith("iconcrack_")) {
                // Allow iconcrack_[id],[data] for item break effects (ex: iconcrack_1)
                String shrunk = arg.getValue().substring("iconcrack_".length());
                String[] split = shrunk.split(",");
                Element typeId = new Element(split[0]);
                if (typeId.isInt() && typeId.asInt() > 0 && Material.getMaterial(typeId.asInt()) != null) {
                    scriptEntry.addObject("iconcrack", typeId);
                } else {
                    dB.echoError("Invalid iconcrack_[id]. Must be a valid Material ID, besides 0.");
                }
                Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
                scriptEntry.addObject("iconcrack_data", dataId);
                scriptEntry.addObject("iconcrack_type", new Element("iconcrack"));
            } else if (arg.startsWith("blockcrack_")) {
                String shrunk = arg.getValue().substring("blockcrack_".length());
                String[] split = shrunk.split(",");
                Element typeId = new Element(split[0]);
                if (typeId.isInt() && typeId.asInt() > 0 && Material.getMaterial(typeId.asInt()) != null) {
                    scriptEntry.addObject("iconcrack", typeId);
                } else {
                    dB.echoError("Invalid blockcrack_[id]. Must be a valid Material ID, besides 0.");
                }
                Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
                scriptEntry.addObject("iconcrack_data", dataId);
                scriptEntry.addObject("iconcrack_type", new Element("blockcrack"));
            } else if (arg.startsWith("blockdust_")) {
                String shrunk = arg.getValue().substring("blockdust_".length());
                String[] split = shrunk.split(",");
                Element typeId = new Element(split[0]);
                if (typeId.isInt() && typeId.asInt() > 0 && Material.getMaterial(typeId.asInt()) != null) {
                    scriptEntry.addObject("iconcrack", typeId);
                } else {
                    dB.echoError("Invalid blockdust_[id]. Must be a valid Material ID, besides 0.");
                }
                Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
                scriptEntry.addObject("iconcrack_data", dataId);
                scriptEntry.addObject("iconcrack_type", new Element("blockdust"));
            } else if (particleHelper.hasEffect(arg.getValue())) {
                scriptEntry.addObject("effect", particleHelper.getEffect(arg.getValue()));
            }
        } else if (!scriptEntry.hasObject("radius") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("visibility", "v", "radius", "r")) {
            scriptEntry.addObject("radius", arg.asElement());
        } else if (!scriptEntry.hasObject("data") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("data", "d")) {
            scriptEntry.addObject("data", arg.asElement());
        } else if (!scriptEntry.hasObject("qty") && arg.matchesPrimitive(aH.PrimitiveType.Integer) && arg.matchesPrefix("qty", "q", "quantity")) {
            scriptEntry.addObject("qty", arg.asElement());
        } else if (!scriptEntry.hasObject("offset") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("offset", "o")) {
            double offset = arg.asElement().asDouble();
            scriptEntry.addObject("offset", new dLocation(null, offset, offset, offset));
        } else if (!scriptEntry.hasObject("offset") && arg.matchesArgumentType(dLocation.class) && arg.matchesPrefix("offset", "o")) {
            scriptEntry.addObject("offset", arg.asType(dLocation.class));
        } else if (!scriptEntry.hasObject("targets") && arg.matchesArgumentList(dPlayer.class) && arg.matchesPrefix("targets", "target", "t")) {
            scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
        } else {
            arg.reportUnhandled();
        }
    }
    // Use default values if necessary
    scriptEntry.defaultObject("location", ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() && ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().isSpawned() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation()) : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().isOnline() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation()) : null);
    scriptEntry.defaultObject("data", new Element(0));
    scriptEntry.defaultObject("radius", new Element(15));
    scriptEntry.defaultObject("qty", new Element(1));
    scriptEntry.defaultObject("offset", new dLocation(null, 0.5, 0.5, 0.5));
    if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
        throw new InvalidArgumentsException("Missing effect argument!");
    }
    if (!scriptEntry.hasObject("location")) {
        throw new InvalidArgumentsException("Missing location argument!");
    }
}
Also used : net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) ParticleHelper(net.aufdemrand.denizen.nms.abstracts.ParticleHelper) Particle(net.aufdemrand.denizen.nms.interfaces.Particle) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Effect(net.aufdemrand.denizen.nms.interfaces.Effect) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 48 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class SwitchCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    final dList interactLocations = scriptEntry.getdObject("locations");
    long duration = ((Duration) scriptEntry.getObject("duration")).getTicks();
    final SwitchState switchState = SwitchState.valueOf(scriptEntry.getElement("switchstate").asString());
    final Player player = ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity() : null;
    // Switch the Block
    dB.report(scriptEntry, getName(), interactLocations.debug() + aH.debugObj("duration", duration + "t") + aH.debugObj("switchstate", switchState.name()));
    for (final dLocation interactLocation : interactLocations.filter(dLocation.class)) {
        switchBlock(scriptEntry, interactLocation, switchState, player);
        // If duration set, schedule a delayed task.
        if (duration > 0) {
            // If this block already had a delayed task, cancel it.
            if (taskMap.containsKey(interactLocation)) {
                try {
                    DenizenAPI.getCurrentInstance().getServer().getScheduler().cancelTask(taskMap.get(interactLocation));
                } catch (Exception e) {
                }
            }
            dB.log("Setting delayed task 'SWITCH' for " + interactLocation.identify());
            // Store new delayed task ID, for checking against, then schedule new delayed task.
            taskMap.put(interactLocation, DenizenAPI.getCurrentInstance().getServer().getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {

                public void run() {
                    switchBlock(scriptEntry, interactLocation, SwitchState.TOGGLE, player);
                }
            }, duration));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Example 49 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class WeatherCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Fetch objects
    Value value = Value.valueOf(((Element) scriptEntry.getObject("value")).asString().toUpperCase());
    dWorld world = (dWorld) scriptEntry.getObject("world");
    Type type = scriptEntry.hasObject("type") ? (Type) scriptEntry.getObject("type") : Type.GLOBAL;
    // Report to dB
    dB.report(scriptEntry, getName(), aH.debugObj("type", type.name()) + (type.name().equalsIgnoreCase("player") ? aH.debugObj("player", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()) : "") + (type.name().equalsIgnoreCase("global") ? aH.debugObj("world", world) : "") + aH.debugObj("value", value));
    switch(value) {
        case SUNNY:
            if (type.equals(Type.GLOBAL)) {
                world.getWorld().setStorm(false);
                world.getWorld().setThundering(false);
            } else {
                ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setPlayerWeather(WeatherType.CLEAR);
            }
            break;
        case STORM:
            if (type.equals(Type.GLOBAL)) {
                world.getWorld().setStorm(true);
            } else {
                ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setPlayerWeather(WeatherType.DOWNFALL);
            }
            break;
        case THUNDER:
            // Note: setThundering always creates a storm
            if (type.equals(Type.GLOBAL)) {
                world.getWorld().setThundering(true);
            } else {
                ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setPlayerWeather(WeatherType.DOWNFALL);
            }
            break;
    }
}
Also used : WeatherType(org.bukkit.WeatherType) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld)

Example 50 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class ActionBarCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (arg.matchesPrefix("format", "f")) {
            String formatStr = arg.getValue();
            FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
            if (format == null) {
                dB.echoError("Could not find format script matching '" + formatStr + '\'');
            }
            scriptEntry.addObject("format", format);
        }
        if (arg.matchesPrefix("targets", "target") && arg.matchesArgumentList(dPlayer.class)) {
            scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
        } else if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", new Element(TagManager.cleanOutputFully(arg.raw_value)));
        }
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Must specify a message!");
    }
    if (!scriptEntry.hasObject("targets") && !((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
        throw new InvalidArgumentsException("Must specify target(s).");
    }
    if (!scriptEntry.hasObject("targets")) {
        BukkitScriptEntryData data = (BukkitScriptEntryData) scriptEntry.entryData;
        if (!data.hasPlayer()) {
            throw new InvalidArgumentsException("Must specify valid player Targets!");
        } else {
            scriptEntry.addObject("targets", Arrays.asList(data.getPlayer()));
        }
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) FormatScriptContainer(net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Element(net.aufdemrand.denizencore.objects.Element) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Aggregations

BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)61 Element (net.aufdemrand.denizencore.objects.Element)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)19 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)18 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)18 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)13 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)13 Duration (net.aufdemrand.denizencore.objects.Duration)9 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)8 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)8 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)6 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 AssignmentTrait (net.aufdemrand.denizen.npc.traits.AssignmentTrait)5 net.aufdemrand.denizen.objects.dInventory (net.aufdemrand.denizen.objects.dInventory)5 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)5 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)5 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)5 EventHandler (org.bukkit.event.EventHandler)5