Search in sources :

Example 31 with BukkitScriptEntryData

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

the class ExperienceCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Type type = (Type) scriptEntry.getObject("type");
    Integer quantity = (Integer) scriptEntry.getObject("quantity");
    Boolean level = (Boolean) scriptEntry.getObject("level");
    Boolean silent = (Boolean) scriptEntry.getObject("silent");
    dB.report(scriptEntry, name, aH.debugObj("Type", type.toString()) + aH.debugObj("Quantity", level ? quantity.toString() + " levels" : quantity.toString()) + aH.debugObj("Player", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getName()));
    Player player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity();
    switch(type) {
        case SET:
            if (level) {
                ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().setLevel(quantity);
            } else if (!silent) {
                player.setExp(quantity);
            //setTotalExperience(player, quantity);
            } else {
                setSilentTotalExperience(player, quantity);
            }
            break;
        case GIVE:
            if (level) {
                player.setLevel(player.getLevel() + quantity);
            } else if (!silent) {
                //giveExperience(player, quantity);
                player.giveExp(quantity);
            } else {
                giveSilentExperience(player, quantity);
            }
            break;
        case TAKE:
            if (level) {
                int value = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().getLevel() - quantity;
                ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().setLevel(value <= 0 ? 0 : value);
            } else if (!silent) {
                player.setExp(player.getExp() - quantity);
            //giveExperience(player, -quantity);
            } else {
                giveSilentExperience(player, -quantity);
            }
            break;
    }
}
Also used : Player(org.bukkit.entity.Player) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData)

Example 32 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData 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 33 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData 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 34 with BukkitScriptEntryData

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

the class LookcloseCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dB.report(scriptEntry, getName(), ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().debug() + aH.debugObj("realistic", scriptEntry.getObject("realistic")) + aH.debugObj("range", scriptEntry.getObject("range")) + aH.debugObj("toggle", scriptEntry.getObject("toggle")));
    // Get the instance of the trait that belongs to the target NPC
    LookClose trait = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen().getTrait(LookClose.class);
    // Handle toggle
    if (scriptEntry.hasObject("toggle")) {
        trait.lookClose(scriptEntry.getElement("toggle").asBoolean());
    }
    // Handle realistic
    if (scriptEntry.hasObject("realistic")) {
        trait.setRealisticLooking(true);
    } else {
        trait.setRealisticLooking(false);
    }
    // Handle range
    if (scriptEntry.hasObject("range")) {
        trait.setRange(scriptEntry.getElement("range").asInt());
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) LookClose(net.citizensnpcs.trait.LookClose)

Example 35 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData 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

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