Search in sources :

Example 71 with PlayerTag

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

the class FakeSpawnCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    EntityTag entity = scriptEntry.getObjectTag("entity");
    LocationTag location = scriptEntry.getObjectTag("location");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag cancel = scriptEntry.getElement("cancel");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), entity, cancel, location, duration, db("players", players));
    }
    if (cancel != null && cancel.asBoolean()) {
        if (entity.isFake) {
            FakeEntity fakeEnt = FakeEntity.idsToEntities.get(entity.getUUID());
            if (fakeEnt != null) {
                fakeEnt.cancelEntity();
            } else {
                Debug.echoDebug(scriptEntry, "Entity '" + entity + "' cannot be cancelled: not listed in fake-entity map.");
            }
        }
    } else {
        FakeEntity created = FakeEntity.showFakeEntityTo(players, entity, location, duration);
        scriptEntry.addObject("faked_entity", created.entity);
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 72 with PlayerTag

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

the class KickCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag reason = scriptEntry.getElement("reason");
    List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("targets", targets), reason);
    }
    for (PlayerTag player : targets) {
        if (player.isValid() && player.isOnline()) {
            player.getPlayerEntity().kickPlayer(reason.toString());
        }
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 73 with PlayerTag

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

the class ClickableCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ScriptTag script = scriptEntry.getObjectTag("script");
    ElementTag path = scriptEntry.getElement("path");
    ElementTag cancel = scriptEntry.argForPrefixAsElement("cancel", null);
    List<PlayerTag> forPlayers = scriptEntry.argForPrefixList("for", PlayerTag.class, true);
    ElementTag usages = scriptEntry.argForPrefixAsElement("usages", null);
    ListTag definitions = scriptEntry.argForPrefix("def", ListTag.class, true);
    DurationTag until = scriptEntry.argForPrefix("until", DurationTag.class, true);
    MapTag defMap = scriptEntry.getObjectTag("def_map");
    if (script == null && cancel == null) {
        throw new InvalidArgumentsRuntimeException("Missing script argument!");
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), script, cancel, path, usages, definitions, defMap, until, db("for", forPlayers));
    }
    if (cancel != null) {
        UUID id;
        try {
            id = UUID.fromString(cancel.asString());
        } catch (IllegalArgumentException ex) {
            Debug.echoError("Invalid cancel ID: " + ex.getMessage());
            return;
        }
        Clickable clicky = clickables.remove(id);
        if (clicky == null) {
            Debug.echoDebug(scriptEntry, "Cancelled ID didn't exist, nothing to cancel.");
        } else {
            Debug.echoDebug(scriptEntry, "Cancelled.");
        }
        return;
    }
    UUID id = UUID.randomUUID();
    Clickable newClickable = new Clickable();
    newClickable.script = script;
    newClickable.path = path == null ? null : path.asString();
    newClickable.definitions = definitions;
    newClickable.remainingUsages = usages == null ? -1 : usages.asInt();
    newClickable.until = until == null ? 0 : (System.currentTimeMillis() + until.getMillis());
    newClickable.context = scriptEntry.context;
    newClickable.npc = Utilities.getEntryNPC(scriptEntry);
    newClickable.defMap = defMap;
    if (forPlayers != null) {
        newClickable.forPlayers = new HashSet<>(forPlayers.size());
        for (PlayerTag player : forPlayers) {
            newClickable.forPlayers.add(player.getUUID());
        }
    }
    clickables.put(id, newClickable);
    scriptEntry.addObject("command", new ElementTag("/denizenclickable " + id));
    scriptEntry.addObject("id", new ElementTag(id.toString()));
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) InvalidArgumentsRuntimeException(com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException)

Example 74 with PlayerTag

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

the class DenizenCommand method tabComplete.

@Override
public List<String> tabComplete(CommandSender commandSender, String alias, String[] arguments) {
    if (!script.hasTabCompleteProcedure()) {
        return super.tabComplete(commandSender, alias, arguments);
    }
    Map<String, ObjectTag> context = new HashMap<>();
    String raw_args = "";
    if (arguments.length > 0) {
        StringBuilder rawArgsBuilder = new StringBuilder();
        for (String arg : arguments) {
            rawArgsBuilder.append(arg).append(' ');
        }
        raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
    }
    List<String> args = Arrays.asList(ArgumentHelper.buildArgs(raw_args));
    context.put("args", new ListTag(args, true));
    context.put("raw_args", new ElementTag(raw_args, true));
    context.put("alias", new ElementTag(alias, true));
    PlayerTag player = null;
    NPCTag npc = null;
    if (commandSender instanceof Player) {
        Player pl = (Player) commandSender;
        if (EntityTag.isCitizensNPC(pl)) {
            npc = NPCTag.fromEntity(pl);
        } else {
            player = PlayerTag.mirrorBukkitPlayer(pl);
        }
        context.put("server", new ElementTag(false));
    } else {
        context.put("server", new ElementTag(true));
    }
    if (Depends.citizens != null && npc == null) {
        NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
        if (citizen != null) {
            npc = new NPCTag(citizen);
        }
    }
    return script.runTabCompleteProcedure(player, npc, context, arguments);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Player(org.bukkit.entity.Player) HashMap(java.util.HashMap) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 75 with PlayerTag

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

the class DenizenCommand method execute.

@Override
public boolean execute(CommandSender commandSender, String commandLabel, String[] arguments) {
    if (!testPermission(commandSender)) {
        return true;
    }
    Map<String, ObjectTag> context = new HashMap<>();
    String raw_args = "";
    if (arguments.length > 0) {
        StringBuilder rawArgsBuilder = new StringBuilder();
        for (String arg : arguments) {
            rawArgsBuilder.append(arg).append(' ');
        }
        raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
    }
    List<String> args = Arrays.asList(ArgumentHelper.buildArgs(raw_args));
    context.put("args", new ListTag(args, true));
    context.put("raw_args", new ElementTag(raw_args, true));
    context.put("alias", new ElementTag(commandLabel, true));
    PlayerTag player = null;
    NPCTag npc = null;
    if (commandSender instanceof Player) {
        Player pl = (Player) commandSender;
        if (EntityTag.isCitizensNPC(pl)) {
            npc = NPCTag.fromEntity(pl);
        } else {
            player = PlayerTag.mirrorBukkitPlayer(pl);
        }
        context.put("server", new ElementTag(false));
        context.put("source_type", new ElementTag("player"));
    } else {
        if (commandSender instanceof BlockCommandSender) {
            context.put("command_block_location", new LocationTag(((BlockCommandSender) commandSender).getBlock().getLocation()));
            context.put("server", new ElementTag(false));
            context.put("source_type", new ElementTag("command_block"));
        } else if (commandSender instanceof CommandMinecart) {
            context.put("command_minecart", new EntityTag((CommandMinecart) commandSender));
            context.put("server", new ElementTag(false));
            context.put("source_type", new ElementTag("command_minecart"));
        } else {
            context.put("server", new ElementTag(true));
            context.put("source_type", new ElementTag("server"));
        }
    }
    if (Depends.citizens != null && npc == null) {
        NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
        if (citizen != null) {
            npc = new NPCTag(citizen);
        }
    }
    script.runCommandScript(player, npc, context);
    return true;
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Player(org.bukkit.entity.Player) HashMap(java.util.HashMap) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) CommandMinecart(org.bukkit.entity.minecart.CommandMinecart) LocationTag(com.denizenscript.denizen.objects.LocationTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) BlockCommandSender(org.bukkit.command.BlockCommandSender)

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