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);
}
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());
}
}
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++;
}
}
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);
}
}
}
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!?");
}
}
}
Aggregations