use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class AgeCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
AgeType ageType = (AgeType) scriptEntry.getObject("agetype");
int age = scriptEntry.getElement("age").asInt();
boolean lock = scriptEntry.hasObject("lock");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (lock ? db("lock", true) : ""), (ageType != null ? db("agetype", ageType) : db("age", age)), db("entities", entities));
}
for (EntityTag entity : entities) {
if (entity.isSpawned()) {
if (EntityAge.describes(entity)) {
EntityAge property = EntityAge.getFrom(entity);
if (ageType != null) {
if (ageType.equals(AgeType.BABY)) {
property.setAge(-24000);
} else {
property.setAge(0);
}
} else {
property.setAge(age);
}
property.setLock(lock);
} else {
Debug.echoError(scriptEntry, entity.identify() + " is not ageable!");
}
}
}
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class RemoveCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
WorldTag world = scriptEntry.getObjectTag("world");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), world, db("entities", entities));
}
for (EntityTag entity : entities) {
if (entity.isUnique()) {
if (entity.isFake) {
FakeEntity fakeEnt = FakeEntity.idsToEntities.get(entity.getUUID());
if (fakeEnt != null) {
fakeEnt.cancelEntity();
}
} else if (entity.isCitizensNPC()) {
entity.getDenizenNPC().getCitizen().destroy();
} else if (entity.isSpawned()) {
entity.remove();
} else {
Debug.echoError("Tried to remove already-removed entity.");
}
} else {
int removed = 0;
for (Entity worldEntity : world.getEntities()) {
if (entity.getEntityType().equals(DenizenEntityType.getByEntity(worldEntity))) {
worldEntity.remove();
removed++;
}
}
Debug.echoDebug(scriptEntry, "Removed " + removed + " entities from the world.");
if (alwaysWarnOnMassRemove) {
Debug.echoError("Remove command 'Always warn on mass delete' in Denizen config is enabled - mass removal of '" + entity.getEntityType() + "' performed, removing " + removed + " entities.");
}
}
}
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class RotateCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
final List<EntityTag> entities = new ArrayList<>((List<EntityTag>) scriptEntry.getObject("entities"));
final DurationTag duration = scriptEntry.getObjectTag("duration");
final DurationTag frequency = scriptEntry.getObjectTag("frequency");
final ElementTag yaw = scriptEntry.getElement("yaw");
final ElementTag pitch = scriptEntry.getElement("pitch");
boolean cancel = scriptEntry.hasObject("cancel");
final boolean infinite = scriptEntry.hasObject("infinite");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), db("entities", entities), (infinite ? db("duration", "infinite") : duration), frequency, yaw, pitch);
}
for (EntityTag entity : entities) {
if (cancel) {
rotatingEntities.remove(entity.getUUID());
} else {
rotatingEntities.add(entity.getUUID());
}
}
if (cancel) {
return;
}
BukkitRunnable task = new BukkitRunnable() {
int ticks = 0;
int maxTicks = duration.getTicksAsInt();
ArrayList<EntityTag> unusedEntities = new ArrayList<>();
@Override
public void run() {
if (entities.isEmpty()) {
scriptEntry.setFinished(true);
this.cancel();
} else if (infinite || ticks < maxTicks) {
for (EntityTag entity : entities) {
if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
NMSHandler.getEntityHelper().rotate(entity.getBukkitEntity(), EntityHelper.normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()), entity.getLocation().getPitch() + pitch.asFloat());
} else {
rotatingEntities.remove(entity.getUUID());
unusedEntities.add(entity);
}
}
if (!unusedEntities.isEmpty()) {
for (EntityTag unusedEntity : unusedEntities) {
entities.remove(unusedEntity);
}
unusedEntities.clear();
}
ticks = (int) (ticks + frequency.getTicks());
} else {
scriptEntry.setFinished(true);
this.cancel();
}
}
};
task.runTaskTimer(Denizen.getInstance(), 0, frequency.getTicks());
}
use of com.denizenscript.denizen.objects.EntityTag 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.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class GlowCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
NetworkInterceptHelper.enable();
final ArrayList<EntityTag> entities = (ArrayList<EntityTag>) scriptEntry.getObject("entities");
ElementTag glowing = scriptEntry.getElement("glowing");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("entities", entities), glowing);
}
boolean shouldGlow = glowing.asBoolean();
final UUID puuid = Utilities.getEntryPlayer(scriptEntry).getUUID();
for (EntityTag ent : entities) {
if (Depends.citizens != null && CitizensAPI.getNPCRegistry().isNPC(ent.getLivingEntity())) {
CitizensAPI.getNPCRegistry().getNPC(ent.getLivingEntity()).data().setPersistent(NPC.GLOWING_METADATA, shouldGlow);
}
if (shouldGlow) {
HashSet<UUID> players = glowViewers.computeIfAbsent(ent.getLivingEntity().getEntityId(), k -> new HashSet<>());
players.add(puuid);
} else {
HashSet<UUID> players = glowViewers.get(ent.getLivingEntity().getEntityId());
if (players != null) {
players.remove(puuid);
shouldGlow = !players.isEmpty();
if (!shouldGlow) {
glowViewers.remove(ent.getLivingEntity().getEntityId());
}
}
}
ent.getLivingEntity().setGlowing(shouldGlow);
}
}
Aggregations