use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class BukkitQueueProperties method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <QueueTag.npc>
// @returns NPCTag
// @mechanism QueueTag.linked_npc
// @description
// Returns the NPCTag linked to a queue.
// -->
PropertyParser.<BukkitQueueProperties, NPCTag>registerTag(NPCTag.class, "npc", (attribute, object) -> {
NPCTag npc = null;
if (object.queue.getLastEntryExecuted() != null) {
npc = ((BukkitScriptEntryData) object.queue.getLastEntryExecuted().entryData).getNPC();
} else if (object.queue.getEntries().size() > 0) {
npc = ((BukkitScriptEntryData) object.queue.getEntries().get(0).entryData).getNPC();
} else if (!attribute.hasAlternative()) {
attribute.echoError("Can't determine a linked NPC.");
}
return npc;
});
// <--[tag]
// @attribute <QueueTag.player>
// @returns PlayerTag
// @mechanism QueueTag.linked_player
// @description
// Returns the PlayerTag linked to a queue.
// -->
PropertyParser.<BukkitQueueProperties, PlayerTag>registerTag(PlayerTag.class, "player", (attribute, object) -> {
PlayerTag player = null;
if (object.queue.getLastEntryExecuted() != null) {
player = ((BukkitScriptEntryData) object.queue.getLastEntryExecuted().entryData).getPlayer();
} else if (object.queue.getEntries().size() > 0) {
player = ((BukkitScriptEntryData) object.queue.getEntries().get(0).entryData).getPlayer();
} else {
attribute.echoError("Can't determine a linked player.");
}
return player;
});
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class BukkitQueueProperties method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("linked_player") && mechanism.requireObject(PlayerTag.class)) {
PlayerTag player = mechanism.valueAsType(PlayerTag.class);
for (ScriptEntry entry : queue.getEntries()) {
BukkitScriptEntryData data = (BukkitScriptEntryData) entry.entryData;
data.setPlayer(player);
}
}
// -->
if (mechanism.matches("linked_npc") && mechanism.requireObject(NPCTag.class)) {
NPCTag npc = mechanism.valueAsType(NPCTag.class);
for (ScriptEntry entry : queue.getEntries()) {
BukkitScriptEntryData data = (BukkitScriptEntryData) entry.entryData;
data.setNPC(npc);
}
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class ZapCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("script") && !scriptEntry.hasObject("step") && arg.hasPrefix() && arg.getPrefix().matchesArgumentType(ScriptTag.class)) {
Deprecations.zapPrefix.warn(scriptEntry);
scriptEntry.addObject("script", arg.getPrefix().asType(ScriptTag.class));
scriptEntry.addObject("step", arg.asElement());
} else if (!scriptEntry.hasObject("script") && arg.matchesArgumentType(ScriptTag.class) && arg.asType(ScriptTag.class).getContainer() instanceof InteractScriptContainer && arg.limitToOnlyPrefix("script")) {
scriptEntry.addObject("script", arg.asType(ScriptTag.class));
} else if (!scriptEntry.hasObject("step") && arg.limitToOnlyPrefix("step")) {
scriptEntry.addObject("step", arg.asElement());
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.limitToOnlyPrefix("duration")) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else {
arg.reportUnhandled();
}
}
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
if (player == null || !player.isValid()) {
throw new InvalidArgumentsException("Must have player context!");
}
if (!scriptEntry.hasObject("script")) {
ScriptTag script = scriptEntry.getScript();
if (script != null) {
if (script.getContainer() instanceof InteractScriptContainer) {
scriptEntry.addObject("script", script);
} else if (script.getContainer() instanceof AssignmentScriptContainer) {
InteractScriptContainer interact = ((AssignmentScriptContainer) script.getContainer()).interact;
if (interact != null) {
scriptEntry.addObject("script", new ScriptTag(interact));
}
}
}
if (!scriptEntry.hasObject("script")) {
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
if (npc != null && npc.getCitizen().hasTrait(AssignmentTrait.class)) {
AssignmentTrait trait = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
for (AssignmentScriptContainer container : trait.containerCache) {
if (container != null && container.getInteract() != null) {
scriptEntry.addObject("script", new ScriptTag(container.getInteract()));
break;
}
}
}
}
if (!scriptEntry.hasObject("script")) {
throw new InvalidArgumentsException("No script to zap! Must be in an interact script, or have a linked NPC with an associated interact script.");
}
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class AttachCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
LocationTag offset = scriptEntry.getObjectTag("offset");
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
EntityTag target = scriptEntry.getObjectTag("to");
List<PlayerTag> forPlayers = (List<PlayerTag>) scriptEntry.getObject("for");
ElementTag cancel = scriptEntry.getElement("cancel");
ElementTag relative = scriptEntry.getElement("relative");
ElementTag sync_server = scriptEntry.getElement("sync_server");
ElementTag no_rotate = scriptEntry.getElement("no_rotate");
ElementTag no_pitch = scriptEntry.getElement("no_pitch");
ElementTag yaw_offset = scriptEntry.getElement("yaw_offset");
ElementTag pitch_offset = scriptEntry.getElement("pitch_offset");
boolean shouldCancel = cancel.asBoolean();
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("entities", entities), shouldCancel ? cancel : target, relative, offset, yaw_offset, pitch_offset, sync_server, no_rotate, no_pitch, db("for", forPlayers));
}
BiConsumer<EntityTag, UUID> procPlayer = (entity, player) -> {
if (shouldCancel) {
EntityAttachmentHelper.removeAttachment(entity.getUUID(), player);
} else {
EntityAttachmentHelper.AttachmentData attachment = new EntityAttachmentHelper.AttachmentData();
attachment.attached = entity;
attachment.to = target;
attachment.positionalOffset = offset == null ? null : offset.clone();
attachment.offsetRelative = relative.asBoolean();
attachment.yawAngleOffset = yaw_offset.asFloat();
attachment.pitchAngleOffset = pitch_offset.asFloat();
attachment.syncServer = sync_server.asBoolean();
attachment.forPlayer = player;
attachment.noRotate = no_rotate.asBoolean();
attachment.noPitch = no_pitch.asBoolean();
EntityAttachmentHelper.registerAttachment(attachment);
}
};
for (EntityTag entity : entities) {
if (!entity.isSpawned() && !entity.isFake && !shouldCancel) {
Debug.echoError("Cannot attach entity '" + entity + "': entity is not spawned.");
continue;
}
if (forPlayers == null) {
procPlayer.accept(entity, null);
} else {
for (PlayerTag player : forPlayers) {
procPlayer.accept(entity, player.getUUID());
}
}
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method sendEntitySpawn.
@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
CraftWorld world = ((CraftWorld) location.getWorld());
net.minecraft.world.entity.Entity nmsEntity;
if (entityType.isCustom()) {
if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
}
}
nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
} else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
String name = null;
String skin = null;
for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
if (mechanism.matches("name")) {
name = mechanism.getValue().asString();
mechanisms.remove(mechanism);
} else if (mechanism.matches("skin")) {
skin = mechanism.getValue().asString();
mechanisms.remove(mechanism);
}
if (name != null && skin != null) {
break;
}
}
nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
} else {
throw new IllegalArgumentException("entityType");
}
} else {
nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
}
if (customUUID != null) {
nmsEntity.setId(customId);
nmsEntity.setUUID(customUUID);
}
EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
entity.isFake = true;
entity.isFakeValid = true;
for (Mechanism mechanism : mechanisms) {
entity.safeAdjustDuplicate(mechanism);
}
nmsEntity.unsetRemoved();
FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
fake.entity = new EntityTag(entity.getBukkitEntity());
fake.entity.isFake = true;
fake.entity.isFakeValid = true;
List<TrackerData> trackers = new ArrayList<>();
fake.triggerSpawnPacket = (player) -> {
ServerPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
ServerGamePacketListenerImpl conn = nmsPlayer.connection;
final ServerEntity tracker = new ServerEntity(world.getHandle(), nmsEntity, 1, true, conn::send, Collections.singleton(nmsPlayer.connection));
tracker.addPairing(nmsPlayer);
final TrackerData data = new TrackerData();
data.player = player;
data.tracker = tracker;
trackers.add(data);
if (autoTrack) {
new BukkitRunnable() {
boolean wasOnline = true;
@Override
public void run() {
if (!fake.entity.isFakeValid) {
cancel();
return;
}
if (player.isOnline()) {
if (!wasOnline) {
tracker.addPairing(((CraftPlayer) player.getPlayerEntity()).getHandle());
wasOnline = true;
}
tracker.sendChanges();
} else if (wasOnline) {
wasOnline = false;
}
}
}.runTaskTimer(Denizen.getInstance(), 1, 1);
}
};
for (PlayerTag player : players) {
fake.triggerSpawnPacket.accept(player);
}
fake.triggerUpdatePacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.sendChanges();
}
}
};
fake.triggerDestroyPacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.removePairing(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
}
}
trackers.clear();
};
return fake;
}
Aggregations