Search in sources :

Example 81 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class BlockCrack method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
    Element progress = scriptEntry.getElement("progress");
    dLocation location = scriptEntry.getdObject("location");
    Element stack = scriptEntry.getElement("stack");
    dB.report(scriptEntry, getName(), aH.debugList("players", players) + progress.debug() + location.debug() + stack.debug());
    Location loc = location.getBlock().getLocation();
    if (!progressTracker.containsKey(loc)) {
        progressTracker.put(loc, new HashMap<UUID, IntHolder>());
        lastBase += 10;
    }
    Map<UUID, IntHolder> uuidInt = progressTracker.get(loc);
    boolean stackVal = stack.asBoolean();
    PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
    for (dPlayer player : players) {
        if (!player.isOnline()) {
            dB.echoError("Players must be online!");
            continue;
        }
        Player playerEnt = player.getPlayerEntity();
        UUID uuid = playerEnt.getUniqueId();
        if (!uuidInt.containsKey(uuid)) {
            IntHolder newIntHolder = new IntHolder();
            newIntHolder.theInt = lastBase;
            newIntHolder.base = lastBase;
            uuidInt.put(uuid, newIntHolder);
        }
        IntHolder intHolder = uuidInt.get(uuid);
        if (!stackVal && intHolder.theInt > intHolder.base) {
            for (int i = intHolder.base; i <= intHolder.theInt; i++) {
                packetHelper.showBlockCrack(playerEnt, i, loc, -1);
            }
            intHolder.theInt = intHolder.base;
        } else if (stackVal && intHolder.theInt - intHolder.base > 10) {
            continue;
        }
        int id = stackVal ? intHolder.theInt++ : intHolder.theInt;
        packetHelper.showBlockCrack(player.getPlayerEntity(), id, loc, progress.asInt() - 1);
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) PacketHelper(net.aufdemrand.denizen.nms.interfaces.PacketHelper) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) UUID(java.util.UUID) Location(org.bukkit.Location) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 82 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class ChatCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dList talkers = scriptEntry.getdObject("talkers");
    dList targets = scriptEntry.getdObject("targets");
    Element message = scriptEntry.getElement("message");
    Element chatRange = scriptEntry.getElement("range");
    dB.report(scriptEntry, getName(), talkers.debug() + targets.debug() + message.debug() + chatRange.debug());
    // Create new speech context
    DenizenSpeechContext context = new DenizenSpeechContext(TagManager.cleanOutputFully(message.asString()), scriptEntry, chatRange.asDouble());
    if (!targets.isEmpty()) {
        for (dEntity ent : targets.filter(dEntity.class)) {
            context.addRecipient(ent.getBukkitEntity());
        }
    }
    for (dEntity talker : talkers.filter(dEntity.class)) {
        Entity entity = talker.getBukkitEntity();
        if (entity != null) {
            context.setTalker(entity);
            new DenizenSpeechController(entity).speak(context);
        } else {
            dB.echoDebug(scriptEntry, "Chat Talker is not spawned! Cannot talk.");
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) DenizenSpeechController(net.aufdemrand.denizen.npc.speech.DenizenSpeechController) DenizenSpeechContext(net.aufdemrand.denizen.npc.speech.DenizenSpeechContext)

Example 83 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class GlowCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    final ArrayList<dEntity> entities = (ArrayList<dEntity>) scriptEntry.getObject("entities");
    Element glowing = scriptEntry.getElement("glowing");
    dB.report(scriptEntry, getName(), aH.debugList("entities", entities) + glowing.debug());
    boolean shouldGlow = glowing.asBoolean();
    final UUID puuid = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer().getUniqueId();
    if (puuid == null) {
        dB.echoError(scriptEntry.getResidingQueue(), "Invalid/non-spawned player link!");
        return;
    }
    for (dEntity ent : entities) {
        if (Depends.citizens != null && CitizensAPI.getNPCRegistry().isNPC(ent.getLivingEntity())) {
            CitizensAPI.getNPCRegistry().getNPC(ent.getLivingEntity()).data().setPersistent(NPC.GLOWING_METADATA, shouldGlow);
        }
        if (shouldGlow) {
            HashSet<UUID> players = glowViewers.get(ent.getLivingEntity().getEntityId());
            if (players == null) {
                players = new HashSet<UUID>();
                glowViewers.put(ent.getLivingEntity().getEntityId(), players);
            }
            players.add(puuid);
        } else {
            HashSet<UUID> players = glowViewers.get(ent.getLivingEntity().getEntityId());
            if (players != null) {
                players.remove(puuid);
                shouldGlow = !players.isEmpty();
                if (!shouldGlow) {
                    glowViewers.remove(ent.getLivingEntity().getEntityId());
                }
            }
        }
        ent.getLivingEntity().setGlowing(shouldGlow);
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 84 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class ListenCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element action = scriptEntry.getElement("action");
    Element type = scriptEntry.getElement("type");
    Element id = scriptEntry.getElement("id");
    dScript finish_script = (dScript) scriptEntry.getObject("finish_script");
    dB.report(scriptEntry, getName(), action.debug() + (type != null ? type.debug() : "") + id.debug() + (finish_script != null ? finish_script.debug() : ""));
    dB.echoError(scriptEntry.getResidingQueue(), "Warning: Listen is outdated and may become unsupported in the future.");
    List<aH.Argument> arguments = (ArrayList<aH.Argument>) scriptEntry.getObject("args");
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case NEW:
            // First make sure there isn't already a 'player listener' for this player with the specified ID.
            if (DenizenAPI.getCurrentInstance().getListenerRegistry().getListenersFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()) != null && DenizenAPI.getCurrentInstance().getListenerRegistry().getListenersFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()).containsKey(CoreUtilities.toLowerCase(id.asString()))) {
                dB.echoError(scriptEntry.getResidingQueue(), "Cancelled creation of NEW listener! Listener ID '" + id.asString() + "' already exists!");
                break;
            }
            // Also make sure there is a valid script input
            if (finish_script == null) {
                dB.echoError("Must specify a valid script!");
                break;
            }
            try {
                DenizenAPI.getCurrentInstance().getListenerRegistry().get(type.asString()).createInstance(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()).build(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString(), type.asString(), arguments, finish_script, ((BukkitScriptEntryData) scriptEntry.entryData).getNPC());
            } catch (Exception e) {
                dB.echoDebug(scriptEntry, "Cancelled creation of NEW listener!");
                // Why? Maybe a wrong listener type...
                if (DenizenAPI.getCurrentInstance().getListenerRegistry().get(type.asString()) == null) {
                    dB.echoError(scriptEntry.getResidingQueue(), "Invalid listener type!");
                } else // Just print the stacktrace if anything else, so we can debug other possible
                // problems.
                {
                    dB.echoError(scriptEntry.getResidingQueue(), e);
                }
                // Deconstruct the listener in case it was partially created while erroring out.
                try {
                    DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()).cancel();
                } catch (Exception ex) {
                }
            }
            break;
        case FINISH:
            if (DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()) != null) {
                DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()).finish();
            }
            break;
        case CANCEL:
            if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() != null) {
                if (id != null) {
                    if (DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()) != null) {
                        DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()).cancel();
                    } else {
                        for (AbstractListener listener : DenizenAPI.getCurrentInstance().getListenerRegistry().getListenersFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()).values()) {
                            listener.cancel();
                        }
                    }
                }
            } else {
                DenizenAPI.getCurrentInstance().getSaves().set("Listeners." + ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getName() + "." + id, null);
            }
            break;
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) ArrayList(java.util.ArrayList) AbstractListener(net.aufdemrand.denizen.listeners.AbstractListener) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Example 85 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class PushableCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dNPC denizenNPC = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
    if (denizenNPC == null) {
        throw new CommandExecutionException("No valid NPC attached to this queue!");
    }
    PushableTrait trait = denizenNPC.getPushableTrait();
    Element state = scriptEntry.getElement("state");
    Duration delay = scriptEntry.getdObject("delay");
    Element returnable = scriptEntry.getElement("return");
    if (state == null && delay == null && returnable == null) {
        state = new Element("TOGGLE");
    }
    dB.report(scriptEntry, getName(), (state != null ? state.debug() : "") + (delay != null ? delay.debug() : "") + (returnable != null ? returnable.debug() : ""));
    if (delay != null) {
        trait.setDelay(delay.getSecondsAsInt());
    }
    if (returnable != null) {
        trait.setReturnable(returnable.asBoolean());
    }
    if (state != null) {
        switch(Toggle.valueOf(state.asString().toUpperCase())) {
            case TRUE:
            case ON:
                trait.setPushable(true);
                break;
            case FALSE:
            case OFF:
                trait.setPushable(false);
                break;
            case TOGGLE:
                trait.setPushable(!trait.isPushable());
                break;
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) Duration(net.aufdemrand.denizencore.objects.Duration) PushableTrait(net.aufdemrand.denizen.npc.traits.PushableTrait)

Aggregations

Element (net.aufdemrand.denizencore.objects.Element)166 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)74 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)49 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)46 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)38 EventHandler (org.bukkit.event.EventHandler)38 List (java.util.List)29 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)28 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)27 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)21 Duration (net.aufdemrand.denizencore.objects.Duration)20 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)16 ArrayList (java.util.ArrayList)14 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)14 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)14 Player (org.bukkit.entity.Player)11 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)10 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)10 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)9