Search in sources :

Example 66 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class BanCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
    ListTag addresses = scriptEntry.getObjectTag("addresses");
    ElementTag reason = scriptEntry.getElement("reason");
    TimeTag expire = scriptEntry.getObjectTag("expire");
    ElementTag source = scriptEntry.getElement("source");
    Date expiration = expire == null ? null : new Date(expire.millis());
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), action, db("targets", targets), addresses, reason, expire, source);
    }
    Actions banAction = Actions.valueOf(action.toString().toUpperCase());
    switch(banAction) {
        case ADD:
            if (targets != null) {
                for (PlayerTag player : targets) {
                    if (player.isValid()) {
                        Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), reason.toString(), expiration, source.toString());
                        if (player.isOnline()) {
                            player.getPlayerEntity().kickPlayer(reason.toString());
                        }
                    }
                }
            }
            if (addresses != null) {
                for (String address : addresses) {
                    Bukkit.getBanList(BanList.Type.IP).addBan(address, reason.toString(), expiration, source.toString());
                }
            }
            break;
        case REMOVE:
            if (targets != null) {
                for (PlayerTag player : targets) {
                    if (player.isValid()) {
                        if (player.getOfflinePlayer().isBanned()) {
                            Bukkit.getBanList(BanList.Type.NAME).pardon(player.getName());
                        }
                    }
                }
            }
            if (addresses != null) {
                for (String address : addresses) {
                    Bukkit.getBanList(BanList.Type.IP).pardon(address);
                }
            }
            break;
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BanList(org.bukkit.BanList) List(java.util.List) TimeTag(com.denizenscript.denizencore.objects.core.TimeTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) Date(java.util.Date)

Example 67 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class FakeEquipCommand method parseArgs.

// <--[command]
// @Name FakeEquip
// @Syntax fakeequip [<entity>|...] (for:<player>|...) (duration:<duration>/reset) (hand:<item>) (offhand:<item>) (head:<item>) (chest:<item>) (legs:<item>) (boots:<item>)
// @Required 1
// @Maximum 9
// @Short Fake-equips items and armor on a list of entities for players to see without real change.
// @Group entity
// 
// @Description
// This command fake-equips items and armor on a list of entities.
// 
// The change doesn't happen on-server, and no armor effects will happen from it.
// 
// The equipment can only be seen by certain players. By default, the linked player is used.
// 
// The changes will remain in place for as long as the duration is specified (even if the real equipment is changed).
// The changes can be manually reset early by using the 'reset' argument.
// If you do not provide a duration, the fake equipment will last until manually reset.
// This does not persist across server restarts.
// 
// Set the item to 'air' to unequip any slot.
// 
// @Tags
// <EntityTag.equipment>
// <InventoryTag.equipment>
// 
// @Usage
// Use to fake-equip a stone block on the player's head.
// - fakeequip <player> head:stone duration:10s
// 
// @Usage
// Use to fake-equip an iron helmet on two defined players.
// - fakeequip <[player]>|<[someplayer]> head:iron_helmet duration:1m
// 
// @Usage
// Use to fake-unequip all armor off the player.
// - fakeequip <player> head:air chest:air legs:air boots:air duration:5s
// 
// @Usage
// Use to make all players within 30 blocks of an entity see it permanently equip a shield.
// - fakeequip <[entity]> offhand:shield for:<[entity].find_players_within[30]> duration:0
// 
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    EquipmentOverride equipment = new EquipmentOverride();
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else if (arg.matchesPrefix("duration") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (arg.matches("reset")) {
            scriptEntry.addObject("reset", new ElementTag(true));
        } else if (arg.matchesPrefix("for") && arg.matchesArgumentList(PlayerTag.class)) {
            scriptEntry.addObject("for", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else if (arg.matchesPrefix("head", "helmet") && arg.matchesArgumentType(ItemTag.class)) {
            equipment.head = arg.asType(ItemTag.class);
        } else if (arg.matchesPrefix("chest", "chestplate") && arg.matchesArgumentType(ItemTag.class)) {
            equipment.chest = arg.asType(ItemTag.class);
        } else if (arg.matchesPrefix("legs", "leggings") && arg.matchesArgumentType(ItemTag.class)) {
            equipment.legs = arg.asType(ItemTag.class);
        } else if (arg.matchesPrefix("boots", "feet") && arg.matchesArgumentType(ItemTag.class)) {
            equipment.boots = arg.asType(ItemTag.class);
        } else if (arg.matchesPrefix("offhand") && arg.matchesArgumentType(ItemTag.class)) {
            equipment.offhand = arg.asType(ItemTag.class);
        } else if (arg.matchesPrefix("hand") && arg.matchesArgumentType(ItemTag.class)) {
            equipment.hand = arg.asType(ItemTag.class);
        } else {
            arg.reportUnhandled();
        }
    }
    if (equipment.isEmpty() && !scriptEntry.hasObject("reset")) {
        throw new InvalidArgumentsException("Must specify equipment!");
    }
    if (!scriptEntry.hasObject("for")) {
        PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
        if (player == null) {
            throw new InvalidArgumentsException("Must specify a for player!");
        }
        scriptEntry.addObject("for", Collections.singletonList(player));
    }
    scriptEntry.addObject("equipment", equipment);
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 68 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class AssignmentCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ScriptTag script = scriptEntry.getObjectTag("script");
    Action action = (Action) scriptEntry.getObject("action");
    List<NPCTag> npcs = (List<NPCTag>) scriptEntry.getObject("npcs");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("action", action), script, db("npc", npcs));
    }
    PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
    for (NPCTag npc : npcs) {
        switch(action) {
            case SET:
                {
                    if (script == null) {
                        throw new InvalidArgumentsRuntimeException("Missing script!");
                    }
                    AssignmentTrait assignment = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
                    assignment.clearAssignments(player);
                    assignment.addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
                    break;
                }
            case ADD:
                if (script == null) {
                    throw new InvalidArgumentsRuntimeException("Missing script!");
                }
                npc.getCitizen().getOrAddTrait(AssignmentTrait.class).addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
                break;
            case REMOVE:
                if (script == null) {
                    Deprecations.assignmentRemove.warn(scriptEntry);
                    if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
                        npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
                        npc.getCitizen().removeTrait(AssignmentTrait.class);
                    }
                } else {
                    if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
                        AssignmentTrait trait = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
                        trait.removeAssignmentScript(script.getName(), player);
                        trait.checkAutoRemove();
                    }
                }
                break;
            case CLEAR:
                if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
                    npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
                    npc.getCitizen().removeTrait(AssignmentTrait.class);
                }
                break;
        }
    }
}
Also used : AssignmentTrait(com.denizenscript.denizen.npc.traits.AssignmentTrait) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) InvalidArgumentsRuntimeException(com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException) List(java.util.List) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)

Example 69 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class MoneyCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    ElementTag quantity = scriptEntry.getElement("quantity");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("Player(s)", players), action, quantity);
    }
    Economy eco = Depends.economy;
    double amt = quantity.asDouble();
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case GIVE:
            for (PlayerTag player : players) {
                eco.depositPlayer(player.getOfflinePlayer(), amt);
            }
            break;
        case TAKE:
            for (PlayerTag player : players) {
                eco.withdrawPlayer(player.getOfflinePlayer(), amt);
            }
            break;
        case SET:
            for (PlayerTag player : players) {
                double balance = eco.getBalance(player.getOfflinePlayer());
                if (amt > balance) {
                    eco.depositPlayer(player.getOfflinePlayer(), amt - balance);
                } else {
                    eco.withdrawPlayer(player.getOfflinePlayer(), balance - amt);
                }
            }
            break;
    }
}
Also used : Economy(net.milkbowl.vault.economy.Economy) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 70 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class OpenTradesCommand method execute.

public void execute(ScriptEntry scriptEntry) {
    ElementTag title = scriptEntry.getElement("title");
    EntityTag entity = scriptEntry.getObjectTag("entity");
    List<TradeTag> trades = (List<TradeTag>) scriptEntry.getObject("trades");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), entity, db("trades", trades), title, db("players", players));
    }
    if (entity != null) {
        if (players.size() > 1) {
            Debug.echoError("No more than one player can access the same entity!");
            return;
        }
        if (entity.getBukkitEntity() instanceof Merchant) {
            PlayerTag player = players.get(0);
            if (player.isValid() && player.isOnline()) {
                player.getPlayerEntity().openMerchant((Merchant) entity.getBukkitEntity(), true);
            } else {
                Debug.echoError("Tried to make a nonexistent or offline player trade with a villager entity!");
            }
            return;
        }
        Debug.echoError("The specified entity isn't a merchant!");
        return;
    }
    List<MerchantRecipe> recipes = new ArrayList<>();
    for (TradeTag trade : trades) {
        recipes.add(trade.getRecipe());
    }
    for (PlayerTag player : players) {
        if (player.isValid() && player.isOnline()) {
            Merchant merchant = Bukkit.createMerchant(title.asString());
            merchant.setRecipes(recipes);
            player.getPlayerEntity().openMerchant(merchant, true);
        } else {
            Debug.echoError("Tried to make a nonexistent or offline player view a virtual trading inventory!");
        }
    }
}
Also used : MerchantRecipe(org.bukkit.inventory.MerchantRecipe) Merchant(org.bukkit.inventory.Merchant) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ArrayList(java.util.ArrayList) TradeTag(com.denizenscript.denizen.objects.TradeTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ArrayList(java.util.ArrayList) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Aggregations

PlayerTag (com.denizenscript.denizen.objects.PlayerTag)81 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)41 Player (org.bukkit.entity.Player)26 List (java.util.List)23 NPCTag (com.denizenscript.denizen.objects.NPCTag)22 EntityTag (com.denizenscript.denizen.objects.EntityTag)16 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)15 ListTag (com.denizenscript.denizencore.objects.core.ListTag)15 LocationTag (com.denizenscript.denizen.objects.LocationTag)14 ItemTag (com.denizenscript.denizen.objects.ItemTag)12 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)11 EventHandler (org.bukkit.event.EventHandler)11 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)8 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)8 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)8 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)7 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)7 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)7 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)6 Argument (com.denizenscript.denizencore.objects.Argument)6