Search in sources :

Example 36 with LocationTag

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);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) EventHandler(org.bukkit.event.EventHandler)

Example 37 with LocationTag

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);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) EventHandler(org.bukkit.event.EventHandler)

Example 38 with LocationTag

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);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) EventHandler(org.bukkit.event.EventHandler)

Example 39 with LocationTag

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);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) EventHandler(org.bukkit.event.EventHandler)

Example 40 with LocationTag

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);
}
Also used : MemoryNPCDataStore(net.citizensnpcs.api.npc.MemoryNPCDataStore) NPC(net.citizensnpcs.api.npc.NPC) LocationTag(com.denizenscript.denizen.objects.LocationTag) ChunkTag(com.denizenscript.denizen.objects.ChunkTag) ClickRedirectTrait(net.citizensnpcs.trait.ClickRedirectTrait) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ArmorStandTrait(net.citizensnpcs.trait.ArmorStandTrait) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry)

Aggregations

LocationTag (com.denizenscript.denizen.objects.LocationTag)133 EventHandler (org.bukkit.event.EventHandler)69 EntityTag (com.denizenscript.denizen.objects.EntityTag)45 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)40 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)33 List (java.util.List)21 ItemTag (com.denizenscript.denizen.objects.ItemTag)18 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)15 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)14 ListTag (com.denizenscript.denizencore.objects.core.ListTag)13 NPCTag (com.denizenscript.denizen.objects.NPCTag)12 Location (org.bukkit.Location)11 ArrayList (java.util.ArrayList)8 Entity (org.bukkit.entity.Entity)8 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)6 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)6 Player (org.bukkit.entity.Player)6 Vector (org.bukkit.util.Vector)6 UUID (java.util.UUID)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5