Search in sources :

Example 16 with PlayerTag

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

the class ClickableCommand method runClickable.

public static void runClickable(UUID id, Player player) {
    Clickable clickable = clickables.get(id);
    if (clickable == null) {
        return;
    }
    if (clickable.until != 0 && System.currentTimeMillis() > clickable.until) {
        clickables.remove(id);
        return;
    }
    if (clickable.forPlayers != null && !clickable.forPlayers.contains(player.getUniqueId())) {
        return;
    }
    if (clickable.remainingUsages > 0) {
        clickable.remainingUsages--;
        if (clickable.remainingUsages <= 0) {
            clickables.remove(id);
        }
    }
    Consumer<ScriptQueue> configure = (queue) -> {
        if (clickable.defMap != null) {
            for (Map.Entry<StringHolder, ObjectTag> val : clickable.defMap.map.entrySet()) {
                queue.addDefinition(val.getKey().str, val.getValue());
            }
        }
    };
    ScriptUtilities.createAndStartQueue(clickable.script.getContainer(), clickable.path, new BukkitScriptEntryData(new PlayerTag(player), clickable.npc), null, configure, null, null, clickable.definitions, clickable.context);
}
Also used : Utilities(com.denizenscript.denizen.utilities.Utilities) InvalidArgumentsRuntimeException(com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException) java.util(java.util) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) com.denizenscript.denizencore.objects.core(com.denizenscript.denizencore.objects.core) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) Argument(com.denizenscript.denizencore.objects.Argument) Consumer(java.util.function.Consumer) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue) ScriptUtilities(com.denizenscript.denizencore.utilities.ScriptUtilities) NPCTag(com.denizenscript.denizen.objects.NPCTag) TagContext(com.denizenscript.denizencore.tags.TagContext) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) Debug(com.denizenscript.denizen.utilities.debugging.Debug) AbstractCommand(com.denizenscript.denizencore.scripts.commands.AbstractCommand) TaskScriptContainer(com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer) StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

Example 17 with PlayerTag

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

the class ItemCooldownCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ArrayList<MaterialTag> materials = (ArrayList<MaterialTag>) scriptEntry.getObject("materials");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
    if (player == null) {
        Debug.echoError("Invalid linked player.");
        return;
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("materials", materials), duration);
    }
    for (MaterialTag mat : materials) {
        player.getPlayerEntity().setCooldown(mat.getMaterial(), duration.getTicksAsInt());
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ArrayList(java.util.ArrayList) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 18 with PlayerTag

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

the class ShowFakeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    NetworkInterceptHelper.enable();
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag cancel = scriptEntry.getElement("cancel");
    List<MaterialTag> materials = (List<MaterialTag>) scriptEntry.getObject("materials");
    List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), duration, cancel, db("materials", materials), db("locations", locations), db("players", players));
    }
    boolean shouldCancel = cancel.asBoolean();
    int i = 0;
    for (LocationTag loc : locations) {
        if (!shouldCancel) {
            FakeBlock.showFakeBlockTo(players, loc.getBlockLocation(), materials.get(i % materials.size()), duration, locations.size() < 5);
        } else {
            FakeBlock.stopShowingTo(players, loc.getBlockLocation());
        }
        i++;
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 19 with PlayerTag

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

the class DisguiseCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    NetworkInterceptHelper.enable();
    EntityTag entity = scriptEntry.getObjectTag("entity");
    EntityTag as = scriptEntry.argForPrefix("as", EntityTag.class, true);
    boolean cancel = scriptEntry.argAsBoolean("cancel");
    boolean global = scriptEntry.argAsBoolean("global");
    boolean self = scriptEntry.argAsBoolean("self");
    List<PlayerTag> players = scriptEntry.argForPrefixList("players", PlayerTag.class, true);
    if (as == null && !cancel) {
        throw new InvalidArgumentsRuntimeException("Must specify a valid type to disguise as!");
    }
    if (players == null && !global) {
        PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
        if (player != null && player.isOnline()) {
            players = Collections.singletonList(player);
        } else {
            throw new InvalidArgumentsRuntimeException("Must have a valid player attached, or 'global' set!");
        }
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), entity, db("cancel", cancel), as, db("global", global), db("self", self), db("players", players));
    }
    HashMap<UUID, TrackedDisguise> playerMap = disguises.get(entity.getUUID());
    if (playerMap != null) {
        if (global) {
            for (Map.Entry<UUID, TrackedDisguise> entry : playerMap.entrySet()) {
                entry.getValue().isActive = false;
                if (entry.getKey() == null) {
                    if (entry.getValue().toOthers != null) {
                        FakeEntity.idsToEntities.remove(entry.getValue().toOthers.overrideUUID);
                    }
                    for (Player player : entity.getWorld().getPlayers()) {
                        if (!EntityTag.isNPC(player)) {
                            entry.getValue().removeFor(new PlayerTag(player));
                        }
                    }
                } else {
                    PlayerTag player = new PlayerTag(entry.getKey());
                    entry.getValue().removeFor(player);
                }
            }
            disguises.remove(entity.getUUID());
        } else {
            for (PlayerTag player : players) {
                TrackedDisguise disguise = playerMap.remove(player.getUUID());
                if (disguise != null) {
                    disguise.isActive = false;
                    disguise.removeFor(player);
                    if (disguise.toOthers != null) {
                        FakeEntity.idsToEntities.remove(disguise.toOthers.overrideUUID);
                    }
                    if (playerMap.isEmpty()) {
                        disguises.remove(entity.getUUID());
                    }
                }
            }
        }
    }
    if (!cancel) {
        TrackedDisguise disguise = new TrackedDisguise(entity, as);
        disguise.as.entity = NMSHandler.getPlayerHelper().sendEntitySpawn(new ArrayList<>(), as.getEntityType(), entity.getLocation(), as.mechanisms == null ? null : new ArrayList<>(as.mechanisms), -1, null, false).entity.getBukkitEntity();
        if (global) {
            playerMap = disguises.computeIfAbsent(entity.getUUID(), k -> new HashMap<>());
            playerMap.put(null, disguise);
            disguise.isActive = true;
            ArrayList<PlayerTag> playerSet = players == null ? new ArrayList<>() : new ArrayList<>(players);
            for (Player player : entity.getWorld().getPlayers()) {
                if (!EntityTag.isNPC(player) && !playerSet.contains(new PlayerTag(player)) && (self || !player.getUniqueId().equals(entity.getUUID()))) {
                    playerSet.add(new PlayerTag(player));
                }
            }
            disguise.sendTo(playerSet);
        } else {
            for (PlayerTag player : players) {
                playerMap = disguises.computeIfAbsent(entity.getUUID(), k -> new HashMap<>());
                playerMap.put(player.getUUID(), disguise);
                disguise.isActive = true;
            }
            disguise.sendTo(players);
        }
    }
}
Also used : HandlerList(org.bukkit.event.HandlerList) Utilities(com.denizenscript.denizen.utilities.Utilities) InvalidArgumentsRuntimeException(com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException) java.util(java.util) NMSHandler(com.denizenscript.denizen.nms.NMSHandler) PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) Argument(com.denizenscript.denizencore.objects.Argument) EventHandler(org.bukkit.event.EventHandler) Location(org.bukkit.Location) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) NetworkInterceptHelper(com.denizenscript.denizen.utilities.packets.NetworkInterceptHelper) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EntityType(org.bukkit.entity.EntityType) Denizen(com.denizenscript.denizen.Denizen) FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) EventPriority(org.bukkit.event.EventPriority) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) EntityTag(com.denizenscript.denizen.objects.EntityTag) Debug(com.denizenscript.denizen.utilities.debugging.Debug) AbstractCommand(com.denizenscript.denizencore.scripts.commands.AbstractCommand) Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) InvalidArgumentsRuntimeException(com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException) EntityTag(com.denizenscript.denizen.objects.EntityTag)

Example 20 with PlayerTag

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

the class NarrateCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    if (scriptEntry.getResidingQueue().procedural) {
        Debug.echoError("'Narrate' should not be used in a procedure script. Consider the 'debug' command instead.");
    }
    List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
    String text = scriptEntry.getElement("text").asString();
    ScriptTag formatObj = scriptEntry.getObjectTag("format");
    ElementTag perPlayerObj = scriptEntry.getElement("per_player");
    ElementTag from = scriptEntry.getElement("from");
    boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
    BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
    if (!perPlayer || targets == null) {
        text = TagManager.tag(text, context);
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("Narrating", text), db("Targets", targets), formatObj, perPlayerObj, from);
    }
    UUID fromId = null;
    if (from != null) {
        if (from.asString().startsWith("p@")) {
            fromId = UUID.fromString(from.asString().substring("p@".length()));
        } else {
            fromId = UUID.fromString(from.asString());
        }
    }
    FormatScriptContainer format = formatObj == null ? null : (FormatScriptContainer) formatObj.getContainer();
    if (targets == null) {
        Bukkit.getServer().getConsoleSender().spigot().sendMessage(FormattedTextHelper.parse(format != null ? format.getFormattedText(text, scriptEntry) : text, ChatColor.WHITE));
        return;
    }
    for (PlayerTag player : targets) {
        if (player != null) {
            if (!player.isOnline()) {
                Debug.echoDebug(scriptEntry, "Player is offline, can't narrate to them. Skipping.");
                continue;
            }
            String personalText = text;
            if (perPlayer) {
                context.player = player;
                personalText = TagManager.tag(personalText, context);
            }
            BaseComponent[] component = FormattedTextHelper.parse(format != null ? format.getFormattedText(personalText, scriptEntry) : personalText, ChatColor.WHITE);
            if (fromId == null) {
                player.getPlayerEntity().spigot().sendMessage(component);
            } else {
                player.getPlayerEntity().spigot().sendMessage(ChatMessageType.CHAT, fromId, component);
            }
        } else {
            Debug.echoError("Narrated to non-existent player!?");
        }
    }
}
Also used : BaseComponent(net.md_5.bungee.api.chat.BaseComponent) BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) UUID(java.util.UUID)

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