use of com.denizenscript.denizen.objects.EntityTag 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.server.v1_16_R3.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.e(customId);
nmsEntity.a_(customUUID);
}
EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
for (Mechanism mechanism : mechanisms) {
entity.safeAdjustDuplicate(mechanism);
}
nmsEntity.dead = false;
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) -> {
EntityPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
PlayerConnection conn = nmsPlayer.playerConnection;
final EntityTrackerEntry tracker = new EntityTrackerEntry(world.getHandle(), nmsEntity, 1, true, conn::sendPacket, Collections.singleton(nmsPlayer));
tracker.b(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.b(((CraftPlayer) player.getPlayerEntity()).getHandle());
wasOnline = true;
}
tracker.a();
} 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.a();
}
}
};
fake.triggerDestroyPacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.a(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
}
}
trackers.clear();
};
return fake;
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class BlockHelperImpl method setSpawnerSpawnedType.
@Override
public void setSpawnerSpawnedType(CreatureSpawner spawner, EntityTag entity) {
spawner.setSpawnedType(entity.getBukkitEntityType());
if (entity.getWaitingMechanisms() == null || entity.getWaitingMechanisms().size() == 0) {
return;
}
try {
// Wrangle a fake entity
Entity nmsEntity = ((CraftWorld) spawner.getWorld()).createEntity(spawner.getLocation(), entity.getBukkitEntityType().getEntityClass());
EntityTag entityTag = new EntityTag(nmsEntity.getBukkitEntity());
entityTag.isFake = true;
entityTag.isFakeValid = true;
for (Mechanism mechanism : entity.getWaitingMechanisms()) {
entityTag.safeAdjustDuplicate(mechanism);
}
nmsEntity.unsetRemoved();
// Store it into the spawner
CraftCreatureSpawner bukkitSpawner = (CraftCreatureSpawner) spawner;
SpawnerBlockEntity nmsSnapshot = (SpawnerBlockEntity) craftBlockEntityState_snapshot.get(bukkitSpawner);
BaseSpawner nmsSpawner = nmsSnapshot.getSpawner();
SpawnData toSpawn = nmsSpawner.nextSpawnData;
net.minecraft.nbt.CompoundTag tag = toSpawn.getEntityToSpawn();
nmsEntity.saveWithoutId(tag);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method getMobSpawnerDisplayEntity.
@Override
public EntityTag getMobSpawnerDisplayEntity(CreatureSpawner spawner) {
SpawnerBlockEntity nmsSpawner = BlockHelperImpl.getTE((CraftCreatureSpawner) spawner);
net.minecraft.world.entity.Entity nmsEntity = nmsSpawner.getSpawner().getOrCreateDisplayEntity(((CraftWorld) spawner.getWorld()).getHandle());
return new EntityTag(nmsEntity.getBukkitEntity());
}
use of com.denizenscript.denizen.objects.EntityTag 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;
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAreaEffectCloud method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("base_potion")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("type")) {
return new ElementTag(getHelper().getBPName()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_upgraded")) {
return new ElementTag(getHelper().getBPUpgraded()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_extended")) {
return new ElementTag(getHelper().getBPExtended()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getBPName() + "," + getHelper().getBPUpgraded() + "," + getHelper().getBPExtended()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("particle")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("color")) {
return new ColorTag(getHelper().getColor()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getParticle()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("duration")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("on_use")) {
return new DurationTag(getHelper().getDurationOnUse()).getObjectAttribute(attribute.fulfill(1));
}
return new DurationTag(getHelper().getDuration()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("radius")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("on_use")) {
return new ElementTag(getHelper().getRadiusOnUse()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("per_tick")) {
return new ElementTag(getHelper().getRadiusPerTick()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getRadius()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("reapplication_delay")) {
return new DurationTag(getHelper().getReappDelay()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("wait_time")) {
return new DurationTag(getHelper().getWaitTime()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_custom_effect")) {
if (attribute.hasParam()) {
PotionEffectType effectType = PotionEffectType.getByName(attribute.getParam());
for (PotionEffect effect : getHelper().getCustomEffects()) {
if (effect.getType().equals(effectType)) {
return new ElementTag(true).getObjectAttribute(attribute.fulfill(1));
}
}
return new ElementTag(false).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().hasCustomEffects()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("source")) {
ProjectileSource shooter = getHelper().getSource();
if (shooter instanceof LivingEntity) {
return new EntityTag((LivingEntity) shooter).getObjectAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("custom_effects")) {
List<PotionEffect> effects = getHelper().getCustomEffects();
if (!attribute.hasParam()) {
ListTag list = new ListTag();
for (PotionEffect effect : effects) {
list.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles());
}
return list.getObjectAttribute(attribute.fulfill(1));
}
int val = attribute.getIntParam() - 1;
if (val < 0 || val >= effects.size()) {
return null;
}
attribute = attribute.fulfill(1);
PotionEffect effect = effects.get(val);
// -->
if (attribute.startsWith("type")) {
return new ElementTag(effect.getType().getName()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("amplifier")) {
return new ElementTag(effect.getAmplifier()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("duration")) {
return new DurationTag((long) effect.getDuration()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_particles")) {
return new ElementTag(effect.hasParticles()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_ambient")) {
return new ElementTag(effect.isAmbient()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles()).getObjectAttribute(attribute);
}
return null;
}
Aggregations