Search in sources :

Example 6 with BukkitScriptEntryData

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

the class TimeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Fetch objects
    Duration value = (Duration) scriptEntry.getObject("value");
    dWorld world = (dWorld) scriptEntry.getObject("world");
    Element type_element = scriptEntry.getElement("type");
    Type type = Type.valueOf(type_element.asString().toUpperCase());
    // Report to dB
    dB.report(scriptEntry, getName(), type_element.debug() + value.debug() + world.debug());
    if (type.equals(Type.GLOBAL)) {
        world.getWorld().setTime(value.getTicks());
    } else {
        if (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
            dB.echoError("Must have a valid player link!");
        } else {
            ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setPlayerTime(value.getTicks(), true);
        }
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld)

Example 7 with BukkitScriptEntryData

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

the class ViewerCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    dB.echoError(scriptEntry.getResidingQueue(), "This command is deprecated! If you use this, please " + "contact Morphan1 or mcmonkey on irc.esper.net#denizen-dev");
    // Get objects
    String direction = scriptEntry.hasObject("direction") ? ((Element) scriptEntry.getObject("direction")).asString() : null;
    Action action = (Action) scriptEntry.getObject("action");
    Type type = scriptEntry.hasObject("type") ? (Type) scriptEntry.getObject("type") : null;
    Display display = scriptEntry.hasObject("display") ? (Display) scriptEntry.getObject("display") : null;
    final String id = scriptEntry.getObject("id").toString();
    if (viewers.containsKey(id)) {
        ((BukkitScriptEntryData) scriptEntry.entryData).setPlayer(dPlayer.valueOf(viewers.get(id).getContent().split("; ")[1]));
    }
    dLocation location = scriptEntry.hasObject("location") ? (dLocation) scriptEntry.getObject("location") : null;
    String content = scriptEntry.hasObject("display") ? display.toString() + "; " + ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer().getUniqueId() : null;
    switch(action) {
        case CREATE:
            if (viewers.containsKey(id)) {
                dB.echoDebug(scriptEntry, "Viewer ID " + id + " already exists!");
                return;
            }
            Viewer viewer = new Viewer(id, content, location);
            viewers.put(id, viewer);
            final Block sign = location.getBlock();
            sign.setType(Material.valueOf(type.name()));
            if (direction != null) {
                Utilities.setSignRotation(sign.getState(), direction);
            } else {
                Utilities.setSignRotation(sign.getState());
            }
            int task = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), new Runnable() {

                public void run() {
                    Player player = Bukkit.getPlayer(UUID.fromString(viewers.get(id).getContent().split("; ")[1]));
                    if (player == null) {
                        Utilities.setSignLines((Sign) viewers.get(id).getLocation().getBlock().getState(), new String[] { "", viewers.get(id).getContent().split("; ")[1], "is offline.", "" });
                    } else {
                        Utilities.setSignLines((Sign) viewers.get(id).getLocation().getBlock().getState(), new String[] { String.valueOf((int) player.getLocation().getX()), String.valueOf((int) player.getLocation().getY()), String.valueOf((int) player.getLocation().getZ()), player.getWorld().getName() });
                    }
                }
            }, 0, 20);
            viewer.setTask(task);
            viewer.save();
            break;
        case MODIFY:
            if (!viewers.containsKey(id)) {
                dB.echoDebug(scriptEntry, "Viewer ID " + id + " doesn't exist!");
                return;
            }
            if (content != null) {
                viewers.get(id).setContent(content);
            }
            if (location != null) {
                if (type == null) {
                    type = Type.valueOf(viewers.get(id).getLocation().getBlock().getType().name());
                }
                Bukkit.getScheduler().cancelTask(viewers.get(id).getTask());
                int newTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), new Runnable() {

                    public void run() {
                        Player player = Bukkit.getPlayer(UUID.fromString(viewers.get(id).getContent().split("; ")[1]));
                        if (player == null) {
                            Utilities.setSignLines((Sign) viewers.get(id).getLocation().getBlock().getState(), new String[] { "", viewers.get(id).getContent().split("; ")[1], "is offline.", "" });
                        } else {
                            Utilities.setSignLines((Sign) viewers.get(id).getLocation().getBlock().getState(), new String[] { String.valueOf((int) player.getLocation().getX()), String.valueOf((int) player.getLocation().getY()), String.valueOf((int) player.getLocation().getZ()), player.getWorld().getName() });
                        }
                    }
                }, 0, 20);
                viewers.get(id).getLocation().getBlock().setType(Material.AIR);
                viewers.get(id).setLocation(location);
                viewers.get(id).setTask(newTask);
                location.getBlock().setType(Material.valueOf(type.name()));
            }
            break;
        case REMOVE:
            if (!viewers.containsKey(id)) {
                dB.echoDebug(scriptEntry, "Viewer ID " + id + " doesn't exist!");
                return;
            }
            Block block = viewers.get(id).getLocation().getBlock();
            block.setType(Material.AIR);
            Bukkit.getScheduler().cancelTask(viewers.get(id).getTask());
            viewers.get(id).remove();
            viewers.remove(id);
    }
}
Also used : Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 8 with BukkitScriptEntryData

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

the class CommandScriptContainer method runTabCompleteProcedure.

public List<String> runTabCompleteProcedure(dPlayer player, dNPC npc, Map<String, dObject> context) {
    // Add the reqId to each of the entries for the determine command
    List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "TAB COMPLETE");
    long id = DetermineCommand.getNewId();
    ScriptBuilder.addObjectToEntries(entries, "ReqId", id);
    ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(getName())).setReqId(id).addEntries(entries);
    if (context != null) {
        OldEventManager.OldEventContextSource oecs = new OldEventManager.OldEventContextSource();
        oecs.contexts = context;
        queue.setContextSource(oecs);
    }
    queue.start();
    if (DetermineCommand.hasOutcome(id)) {
        return dList.valueOf(DetermineCommand.getOutcome(id).get(0));
    } else {
        return new ArrayList<String>();
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) OldEventManager(net.aufdemrand.denizencore.events.OldEventManager) ArrayList(java.util.ArrayList) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) ScriptQueue(net.aufdemrand.denizencore.scripts.queues.ScriptQueue)

Example 9 with BukkitScriptEntryData

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

the class CommandScriptContainer method runAllowedHelpProcedure.

public boolean runAllowedHelpProcedure(dPlayer player, dNPC npc, Map<String, dObject> context) {
    // Add the reqId to each of the entries for the determine command
    List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "ALLOWED HELP");
    long id = DetermineCommand.getNewId();
    ScriptBuilder.addObjectToEntries(entries, "ReqId", id);
    ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(getName())).setReqId(id).addEntries(entries);
    if (context != null) {
        OldEventManager.OldEventContextSource oecs = new OldEventManager.OldEventContextSource();
        oecs.contexts = context;
        queue.setContextSource(oecs);
    }
    queue.start();
    return DetermineCommand.hasOutcome(id) && DetermineCommand.getOutcome(id).get(0).equalsIgnoreCase("true");
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) OldEventManager(net.aufdemrand.denizencore.events.OldEventManager) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) ScriptQueue(net.aufdemrand.denizencore.scripts.queues.ScriptQueue)

Example 10 with BukkitScriptEntryData

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

the class FireworkCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    final dLocation location = scriptEntry.hasObject("location") ? (dLocation) scriptEntry.getObject("location") : ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation();
    Element type = (Element) scriptEntry.getObject("type");
    Element power = (Element) scriptEntry.getObject("power");
    boolean flicker = scriptEntry.hasObject("flicker");
    boolean trail = scriptEntry.hasObject("trail");
    List<dColor> primary = (List<dColor>) scriptEntry.getObject("primary");
    List<dColor> fade = (List<dColor>) scriptEntry.getObject("fade");
    // Report to dB
    dB.report(scriptEntry, getName(), location.debug() + type.debug() + power.debug() + (flicker ? aH.debugObj("flicker", flicker) : "") + (trail ? aH.debugObj("trail", trail) : "") + aH.debugObj("primary colors", primary.toString()) + (fade != null ? aH.debugObj("fade colors", fade.toString()) : ""));
    Firework firework = location.getWorld().spawn(location, Firework.class);
    FireworkMeta fireworkMeta = firework.getFireworkMeta();
    fireworkMeta.setPower(power.asInt());
    Builder fireworkBuilder = FireworkEffect.builder();
    fireworkBuilder.with(FireworkEffect.Type.valueOf(type.asString().toUpperCase()));
    fireworkBuilder.withColor(Conversion.convertColors(primary));
    if (fade != null) {
        fireworkBuilder.withFade(Conversion.convertColors(fade));
    }
    if (flicker) {
        fireworkBuilder.withFlicker();
    }
    if (trail) {
        fireworkBuilder.withTrail();
    }
    fireworkMeta.addEffects(fireworkBuilder.build());
    firework.setFireworkMeta(fireworkMeta);
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dColor(net.aufdemrand.denizen.objects.dColor) Firework(org.bukkit.entity.Firework) Builder(org.bukkit.FireworkEffect.Builder) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

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