use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerEntersBedScriptEvent method onPlayerEntersBed.
@EventHandler
public void onPlayerEntersBed(PlayerBedEnterEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
location = new LocationTag(event.getBed().getLocation());
this.event = event;
fire(event);
}
use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.
the class PotionSplashScriptEvent method onPotionSplash.
@EventHandler
public void onPotionSplash(PotionSplashEvent event) {
potion = new ItemTag(event.getPotion().getItem());
location = new LocationTag(event.getEntity().getLocation());
this.event = event;
fire(event);
}
use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.
the class GenericGameEventScriptEvent method onGenericGameEvent.
@EventHandler
public void onGenericGameEvent(GenericGameEvent event) {
location = new LocationTag(event.getLocation());
this.event = event;
fire(event);
}
use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.
the class VehicleMoveScriptEvent method onVehicleMove.
@EventHandler
public void onVehicleMove(VehicleMoveEvent event) {
to = new LocationTag(event.getTo());
from = new LocationTag(event.getFrom());
vehicle = new EntityTag(event.getVehicle());
this.event = event;
fire(event);
}
use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.
the class SittingTrait method forceEntitySit.
public void forceEntitySit(Entity entity, Location location, boolean isRetry) {
if (sitStandNPC != null) {
sitStandNPC.destroy();
}
entity.setMetadata("denizen.sitting", new FixedMetadataValue(Denizen.getInstance(), true));
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("DenizenSitRegistry");
if (registry == null) {
registry = CitizensAPI.createNamedNPCRegistry("DenizenSitRegistry", new MemoryNPCDataStore());
}
NPC npc = CitizensAPI.getNPCRegistry().getNPC(entity);
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, SIT_STAND_NAME);
sitStandNPC = holder;
if (npc != null) {
holder.addTrait(new ClickRedirectTrait(npc));
Messaging.debug("(Denizen) SittingTrait: Spawning chair for", npc.getId(), "as id", holder.getId());
}
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);
trait.setSmall(true);
trait.setMarker(true);
trait.setVisible(false);
holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
boolean spawned = holder.spawn(location);
if (!spawned || !holder.isSpawned()) {
if (isRetry) {
Debug.echoError("NPC " + (npc == null ? "null" : npc.getId()) + " sit failed (" + spawned + "," + holder.isSpawned() + "): cannot spawn chair id " + holder.getId() + " at " + new LocationTag(location).identifySimple() + " ChunkIsLoaded=" + new ChunkTag(location).isLoaded());
holder.destroy();
sitStandNPC = null;
} else {
Messaging.debug("(Denizen) SittingTrait: retrying failed sit for", npc.getId());
Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
if (npc.isSpawned()) {
forceEntitySit(entity, location, true);
}
}, 5);
}
return;
}
holder.data().set("is-denizen-seat", true);
new BukkitRunnable() {
@Override
public void cancel() {
super.cancel();
if (entity.isValid() && entity.hasMetadata("denizen.sitting")) {
entity.removeMetadata("denizen.sitting", Denizen.getInstance());
}
if (holder.getTraits().iterator().hasNext()) {
// Hacky NPC-already-removed test
holder.destroy();
}
if (sitStandNPC == holder) {
sitStandNPC = null;
}
}
@Override
public void run() {
if (holder != sitStandNPC) {
cancel();
} else if (!holder.getTraits().iterator().hasNext()) {
// Hacky NPC-already-removed test
cancel();
} else if (!entity.isValid() || !entity.hasMetadata("denizen.sitting") || !entity.getMetadata("denizen.sitting").get(0).asBoolean()) {
cancel();
} else if (npc != null && !npc.isSpawned()) {
cancel();
} else if (!holder.isSpawned()) {
cancel();
} else if (!NMS.getPassengers(holder.getEntity()).contains(entity)) {
holder.getEntity().addPassenger(entity);
}
}
}.runTaskTimer(Denizen.getInstance(), 0, 1);
}
Aggregations