Search in sources :

Example 86 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class LightCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    LocationTag location = scriptEntry.getObjectTag("location");
    ElementTag light = scriptEntry.getElement("light");
    ElementTag reset = scriptEntry.getElement("reset");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), location, reset, light, duration);
    }
    if (!Utilities.isLocationYSafe(location)) {
        Debug.echoError(scriptEntry, "Invalid light location!");
        return;
    }
    for (int x = -1; x <= 1; x++) {
        for (int z = -1; z <= 1; z++) {
            location.clone().add(x * 16, 0, z * 16).getChunk().load();
        }
    }
    if (!reset.asBoolean()) {
        int brightness = light.asInt();
        if (brightness < 0 || brightness > 15) {
            Debug.echoError("Light brightness must be between 0 and 15, inclusive!");
            return;
        }
        NMSHandler.getInstance().createBlockLight(location, brightness, duration == null ? 0 : duration.getTicks());
    } else {
        BlockLight.removeLight(location);
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 87 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class PlaySoundCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("entities");
    ElementTag soundElement = scriptEntry.getElement("sound");
    ElementTag volumeElement = scriptEntry.argForPrefixAsElement("volume", "1");
    ElementTag pitchElement = scriptEntry.argForPrefixAsElement("pitch", "1");
    boolean custom = scriptEntry.argAsBoolean("custom");
    ElementTag sound_category = scriptEntry.argForPrefixAsElement("sound_category", "MASTER");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("locations", locations), db("entities", players), soundElement, volumeElement, pitchElement, db("custom", custom));
    }
    String sound = soundElement.asString();
    float volume = volumeElement.asFloat();
    float pitch = pitchElement.asFloat();
    String category = sound_category.asString().toUpperCase();
    try {
        if (players == null) {
            if (custom) {
                for (LocationTag location : locations) {
                    NMSHandler.getSoundHelper().playSound(null, location, sound, volume, pitch, category);
                }
            } else {
                for (LocationTag location : locations) {
                    NMSHandler.getSoundHelper().playSound(null, location, Sound.valueOf(sound.toUpperCase()), volume, pitch, category);
                }
            }
        } else if (locations != null) {
            for (LocationTag location : locations) {
                for (PlayerTag player : players) {
                    if (custom) {
                        NMSHandler.getSoundHelper().playSound(player.getPlayerEntity(), location, sound, volume, pitch, category);
                    } else {
                        NMSHandler.getSoundHelper().playSound(player.getPlayerEntity(), location, Sound.valueOf(sound.toUpperCase()), volume, pitch, category);
                    }
                }
            }
        } else {
            for (PlayerTag player : players) {
                if (custom) {
                    NMSHandler.getSoundHelper().playSound(player.getPlayerEntity(), player.getLocation(), sound, volume, pitch, category);
                } else {
                    NMSHandler.getSoundHelper().playSound(player.getPlayerEntity(), player.getLocation(), Sound.valueOf(sound.toUpperCase()), volume, pitch, category);
                }
            }
        }
    } catch (Exception e) {
        Debug.echoDebug(scriptEntry, "Unable to play sound.");
        if (Debug.verbose) {
            Debug.echoError(e);
        }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 88 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class PlayerItemTakesDamageScriptEvent method onPlayerItemTakesDamage.

@EventHandler
public void onPlayerItemTakesDamage(PlayerItemDamageEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    item = new ItemTag(event.getItem());
    location = new LocationTag(event.getPlayer().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 89 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class PlayerUsesPortalScriptEvent method onPlayerEntersPortal.

@EventHandler
public void onPlayerEntersPortal(PlayerPortalEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    entity = new EntityTag(event.getPlayer());
    to = event.getTo() == null ? null : new LocationTag(event.getTo());
    from = new LocationTag(event.getFrom());
    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 90 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class PlayerWalkScriptEvent method onPlayerMoves.

@EventHandler
public void onPlayerMoves(PlayerMoveEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    old_location = new LocationTag(event.getFrom());
    new_location = new LocationTag(event.getTo());
    this.event = event;
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) EventHandler(org.bukkit.event.EventHandler)

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