Search in sources :

Example 26 with Element

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

the class InvisibleCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    Element state = scriptEntry.getElement("state");
    dEntity target = (dEntity) scriptEntry.getObject("target");
    // Report to dB
    dB.report(scriptEntry, getName(), state.debug() + target.debug());
    if (target.isCitizensNPC()) {
        NPC npc = target.getDenizenNPC().getCitizen();
        if (!npc.hasTrait(InvisibleTrait.class)) {
            npc.addTrait(InvisibleTrait.class);
        }
        InvisibleTrait trait = npc.getTrait(InvisibleTrait.class);
        switch(Action.valueOf(state.asString().toUpperCase())) {
            case FALSE:
                trait.setInvisible(false);
                break;
            case TRUE:
                trait.setInvisible(true);
                break;
            case TOGGLE:
                trait.toggle();
                break;
        }
    } else {
        switch(Action.valueOf(state.asString().toUpperCase())) {
            case FALSE:
                if (target.getBukkitEntity() instanceof ArmorStand) {
                    ((ArmorStand) target.getBukkitEntity()).setVisible(true);
                } else {
                    target.getLivingEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                }
                break;
            case TRUE:
                if (target.getBukkitEntity() instanceof ArmorStand) {
                    ((ArmorStand) target.getBukkitEntity()).setVisible(false);
                } else {
                    new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1).apply(target.getLivingEntity());
                }
                break;
            case TOGGLE:
                if (target.getBukkitEntity() instanceof ArmorStand) {
                    if (((ArmorStand) target.getBukkitEntity()).isVisible()) {
                        ((ArmorStand) target.getBukkitEntity()).setVisible(true);
                    } else {
                        ((ArmorStand) target.getBukkitEntity()).setVisible(false);
                    }
                } else {
                    if (target.getLivingEntity().hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                        target.getLivingEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                    } else {
                        new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1).apply(target.getLivingEntity());
                    }
                }
                break;
        }
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) ArmorStand(org.bukkit.entity.ArmorStand) PotionEffect(org.bukkit.potion.PotionEffect) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) InvisibleTrait(net.aufdemrand.denizen.npc.traits.InvisibleTrait)

Example 27 with Element

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

the class TakeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dInventory inventory = (dInventory) scriptEntry.getObject("inventory");
    Element qty = scriptEntry.getElement("qty");
    Element displayname = scriptEntry.getElement("displayname");
    Element slot = scriptEntry.getElement("slot");
    dList titleAuthor = scriptEntry.getdObject("cover");
    Type type = (Type) scriptEntry.getObject("type");
    Object items_object = scriptEntry.getObject("items");
    List<dItem> items = null;
    if (items_object != null) {
        items = (List<dItem>) items_object;
    }
    dB.report(scriptEntry, getName(), aH.debugObj("Type", type.name()) + qty.debug() + (inventory != null ? inventory.debug() : "") + (displayname != null ? displayname.debug() : "") + aH.debugObj("Items", items) + (slot != null ? slot.debug() : "") + (titleAuthor != null ? titleAuthor.debug() : ""));
    switch(type) {
        case INVENTORY:
            inventory.clear();
            break;
        case ITEMINHAND:
            int inHandAmt = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().getItemInHand().getAmount();
            int theAmount = (int) qty.asDouble();
            ItemStack newHandItem = new ItemStack(0);
            if (theAmount > inHandAmt) {
                dB.echoDebug(scriptEntry, "...player did not have enough of the item in hand, so Denizen just took as many as it could. To avoid this situation, use an IF <PLAYER.ITEM_IN_HAND.QTY>.");
                ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setItemInHand(newHandItem);
            } else {
                // amount is just right!
                if (theAmount == inHandAmt) {
                    ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setItemInHand(newHandItem);
                } else {
                    // amount is less than what's in hand, need to make a new itemstack of what's left...
                    newHandItem = new ItemStack(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().getItemInHand().getType(), inHandAmt - theAmount, ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().getItemInHand().getData().getData());
                    newHandItem.setItemMeta(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().getItemInHand().getItemMeta());
                    ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setItemInHand(newHandItem);
                    ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().updateInventory();
                }
            }
            break;
        case MONEY:
            if (Depends.economy != null) {
                Depends.economy.withdrawPlayer(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer(), qty.asDouble());
            } else {
                dB.echoError(scriptEntry.getResidingQueue(), "No economy loaded! Have you installed Vault and a compatible economy plugin?");
            }
            break;
        case ITEM:
            for (dItem item : items) {
                ItemStack is = item.getItemStack();
                is.setAmount(qty.asInt());
                if (!inventory.removeItem(item, item.getAmount())) {
                    dB.echoDebug(scriptEntry, "Inventory does not contain at least " + qty.asInt() + " of " + item.getFullString() + "... Taking as much as possible...");
                }
            }
            break;
        case BYDISPLAY:
            int found_items = 0;
            if (displayname == null) {
                dB.echoError(scriptEntry.getResidingQueue(), "Must specify a displayname!");
                return;
            }
            for (ItemStack it : inventory.getContents()) {
                if (found_items < qty.asInt() && it != null && it.hasItemMeta() && it.getItemMeta().hasDisplayName() && it.getItemMeta().getDisplayName().equalsIgnoreCase(displayname.identify())) {
                    int amt = it.getAmount();
                    if (found_items + it.getAmount() <= qty.asInt()) {
                        inventory.getInventory().removeItem(it);
                    } else {
                        it.setAmount(it.getAmount() - (qty.asInt() - found_items));
                        break;
                    }
                    found_items += amt;
                }
            }
            break;
        case SLOT:
            inventory.setSlots(slot.asInt() - 1, new ItemStack(Material.AIR));
            break;
        case BYCOVER:
            inventory.removeBook(titleAuthor.get(0), titleAuthor.size() > 1 ? titleAuthor.get(1) : null, qty.asInt());
            break;
    }
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dInventory(net.aufdemrand.denizen.objects.dInventory) ItemStack(org.bukkit.inventory.ItemStack)

Example 28 with Element

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

the class AnchorCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    Action action = (Action) scriptEntry.getObject("action");
    dLocation location = (dLocation) scriptEntry.getObject("location");
    Element range = (Element) scriptEntry.getObject("range");
    Element id = (Element) scriptEntry.getObject("id");
    dNPC npc = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
    // Report to dB
    dB.report(scriptEntry, getName(), npc.debug() + action.name() + id.debug() + (location != null ? location.debug() : "") + (range != null ? range.debug() : ""));
    if (!npc.getCitizen().hasTrait(Anchors.class)) {
        npc.getCitizen().addTrait(Anchors.class);
    }
    switch(action) {
        case ADD:
            npc.getCitizen().getTrait(Anchors.class).addAnchor(id.asString(), location);
            return;
        case ASSUME:
            {
                Anchor n = npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString());
                if (n == null) {
                    dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
                } else {
                    npc.getEntity().teleport(n.getLocation());
                }
            }
            return;
        case WALKNEAR:
            {
                Anchor n = npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString());
                if (n == null) {
                    dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
                } else if (range == null) {
                    dB.echoError(scriptEntry.getResidingQueue(), "Must specify a range!");
                } else {
                    npc.getNavigator().setTarget(Utilities.getWalkableLocationNear(n.getLocation(), range.asInt()));
                }
            }
            return;
        case WALKTO:
            {
                Anchor n = npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString());
                if (n == null) {
                    dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
                } else {
                    npc.getNavigator().setTarget(n.getLocation());
                }
            }
            return;
        case REMOVE:
            {
                Anchor n = npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString());
                if (n == null) {
                    dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
                } else {
                    npc.getCitizen().getTrait(Anchors.class).removeAnchor(n);
                }
            }
    }
}
Also used : Anchors(net.citizensnpcs.trait.Anchors) Anchor(net.citizensnpcs.util.Anchor) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 29 with Element

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

the class BreakCommand method execute.

// <--[action]
// @Actions
// dig
//
// @Triggers when the NPC breaks a block with the Break Command
//
// @Context
// <context.location> returns the location the NPC Dug
// <context.material> Returns the Block dug
//
// -->
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    final dLocation location = (dLocation) scriptEntry.getObject("location");
    final dNPC npc = (dNPC) scriptEntry.getObject("entity");
    Element radius = scriptEntry.getElement("radius");
    final HashMap<String, dObject> context = new HashMap<String, dObject>();
    dMaterial material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
    context.put("location", location);
    context.put("material", material);
    dB.report(scriptEntry, getName(), location.debug() + npc.debug() + radius.debug());
    final ScriptEntry se = scriptEntry;
    BlockBreaker.BlockBreakerConfiguration config = new BlockBreaker.BlockBreakerConfiguration();
    config.item(npc.getLivingEntity().getEquipment().getItemInHand());
    config.radius(radius.asDouble());
    config.callback(new Runnable() {

        @Override
        public void run() {
            npc.action("dig", null, context);
            se.setFinished(true);
        }
    });
    BlockBreaker breaker = npc.getCitizen().getBlockBreaker(location.getBlock(), config);
    if (breaker.shouldExecute()) {
        TaskRunnable run = new TaskRunnable(breaker);
        run.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), run, 0, 1);
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) HashMap(java.util.HashMap) Element(net.aufdemrand.denizencore.objects.Element) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) BlockBreaker(net.citizensnpcs.api.npc.BlockBreaker) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 30 with Element

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

the class TextTags method specialCharacterTags.

@TagManager.TagEvents
public void specialCharacterTags(ReplaceableTagEvent event) {
    if (!event.getName().startsWith("&")) {
        return;
    }
    String lower = CoreUtilities.toLowerCase(event.getName());
    Attribute attribute = event.getAttributes();
    // -->
    if (lower.equals("&nl")) {
        event.setReplaced(new Element("\n").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&amp")) {
        event.setReplaced(new Element("&").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&cm")) {
        event.setReplaced(new Element(",").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&ss")) {
        event.setReplaced(new Element("§").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&sq")) {
        event.setReplaced(new Element("'").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&sp")) {
        event.setReplaced(new Element(String.valueOf(' ')).getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&nbsp")) {
        event.setReplaced(new Element(String.valueOf((char) 0x00A0)).getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&dq")) {
        event.setReplaced(new Element("\"").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&co")) {
        event.setReplaced(new Element(":").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&sc")) {
        event.setReplaced(new Element(String.valueOf((char) 0x2011)).getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&rb")) {
        event.setReplaced(new Element("]").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&lb")) {
        event.setReplaced(new Element("[").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&rc")) {
        event.setReplaced(new Element("}").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&lc")) {
        event.setReplaced(new Element("{").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&ns")) {
        event.setReplaced(new Element("#").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&pc")) {
        event.setReplaced(new Element("%").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&pipe")) {
        event.setReplaced(new Element("|").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&ds")) {
        event.setReplaced(new Element("$").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&lt")) {
        event.setReplaced(new Element(String.valueOf((char) 0x01)).getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&gt")) {
        event.setReplaced(new Element(String.valueOf((char) 0x02)).getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&bs")) {
        event.setReplaced(new Element("\\").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&at")) {
        event.setReplaced(new Element("@").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&dot")) {
        event.setReplaced(new Element(".").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (lower.equals("&hrt")) {
        event.setReplaced(new Element("♥").getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("&chr") && attribute.hasContext(1)) {
        event.setReplaced(String.valueOf((char) Integer.parseInt(attribute.getContext(1), 16)));
    }
}
Also used : Attribute(net.aufdemrand.denizencore.tags.Attribute) Element(net.aufdemrand.denizencore.objects.Element)

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