Search in sources :

Example 1 with BiomeNMS

use of com.denizenscript.denizen.nms.abstracts.BiomeNMS in project Denizen-For-Bukkit by DenizenScript.

the class BiomeTag method valueOf.

@Fetchable("b")
public static BiomeTag valueOf(String string, TagContext context) {
    if (string.startsWith("b@")) {
        string = string.substring(2);
    }
    string = CoreUtilities.toLowerCase(string);
    int comma = string.indexOf(',');
    String worldName = null, biomeName = string;
    if (comma != -1) {
        worldName = string.substring(0, comma);
        biomeName = string.substring(comma + 1);
    }
    World world = Bukkit.getWorlds().get(0);
    if (worldName != null) {
        WorldTag worldTag = WorldTag.valueOf(worldName, context);
        if (worldTag == null || worldTag.getWorld() == null) {
            return null;
        }
        world = worldTag.getWorld();
    }
    BiomeNMS biome = NMSHandler.getInstance().getBiomeNMS(world, biomeName);
    if (biome == null) {
        return null;
    }
    return new BiomeTag(biome);
}
Also used : BiomeNMS(com.denizenscript.denizen.nms.abstracts.BiomeNMS) World(org.bukkit.World)

Example 2 with BiomeNMS

use of com.denizenscript.denizen.nms.abstracts.BiomeNMS in project Denizen-For-Bukkit by DenizenScript.

the class WorldTag method registerTags.

public static void registerTags() {
    AbstractFlagTracker.registerFlagHandlers(tagProcessor);
    // ///////////////////
    // ENTITY LIST ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <WorldTag.entities[(<matcher>)]>
    // @returns ListTag(EntityTag)
    // @description
    // Returns a list of entities in this world.
    // Optionally specify an entity type matcher to filter down to.
    // -->
    registerTag(ListTag.class, "entities", (attribute, object) -> {
        ListTag entities = new ListTag();
        String matcher = attribute.hasParam() ? attribute.getParam() : null;
        for (Entity entity : object.getEntitiesForTag()) {
            EntityTag current = new EntityTag(entity);
            if (matcher == null || BukkitScriptEvent.tryEntity(current, matcher)) {
                entities.addObject(current.getDenizenObject());
            }
        }
        return entities;
    });
    // <--[tag]
    // @attribute <WorldTag.living_entities>
    // @returns ListTag(EntityTag)
    // @description
    // Returns a list of living entities in this world.
    // This includes Players, mobs, NPCs, etc., but excludes dropped items, experience orbs, etc.
    // -->
    registerTag(ListTag.class, "living_entities", (attribute, object) -> {
        ListTag entities = new ListTag();
        for (Entity entity : object.getLivingEntitiesForTag()) {
            entities.addObject(new EntityTag(entity).getDenizenObject());
        }
        return entities;
    });
    // <--[tag]
    // @attribute <WorldTag.players>
    // @returns ListTag(PlayerTag)
    // @description
    // Returns a list of online players in this world.
    // -->
    registerTag(ListTag.class, "players", (attribute, object) -> {
        ListTag players = new ListTag();
        for (Player player : object.getWorld().getPlayers()) {
            if (!EntityTag.isNPC(player)) {
                players.addObject(new PlayerTag(player));
            }
        }
        return players;
    });
    // <--[tag]
    // @attribute <WorldTag.spawned_npcs>
    // @returns ListTag(NPCTag)
    // @description
    // Returns a list of spawned NPCs in this world.
    // -->
    registerTag(ListTag.class, "spawned_npcs", (attribute, object) -> {
        ListTag npcs = new ListTag();
        World thisWorld = object.getWorld();
        for (NPC npc : CitizensAPI.getNPCRegistry()) {
            if (npc.isSpawned() && npc.getStoredLocation().getWorld().equals(thisWorld)) {
                npcs.addObject(new NPCTag(npc));
            }
        }
        return npcs;
    });
    // <--[tag]
    // @attribute <WorldTag.npcs>
    // @returns ListTag(NPCTag)
    // @description
    // Returns a list of all NPCs in this world.
    // -->
    registerTag(ListTag.class, "npcs", (attribute, object) -> {
        ListTag npcs = new ListTag();
        World thisWorld = object.getWorld();
        for (NPC npc : CitizensAPI.getNPCRegistry()) {
            Location location = npc.getStoredLocation();
            if (location != null) {
                World world = location.getWorld();
                if (world != null && world.equals(thisWorld)) {
                    npcs.addObject(new NPCTag(npc));
                }
            }
        }
        return npcs;
    });
    // ///////////////////
    // GEOGRAPHY ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <WorldTag.can_generate_structures>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the world will generate structures.
    // -->
    registerTag(ElementTag.class, "can_generate_structures", (attribute, object) -> {
        return new ElementTag(object.getWorld().canGenerateStructures());
    });
    // <--[tag]
    // @attribute <WorldTag.loaded_chunks>
    // @returns ListTag(ChunkTag)
    // @description
    // Returns a list of all the currently loaded chunks.
    // -->
    registerTag(ListTag.class, "loaded_chunks", (attribute, object) -> {
        ListTag chunks = new ListTag();
        for (Chunk ent : object.getWorld().getLoadedChunks()) {
            chunks.addObject(new ChunkTag(ent));
        }
        return chunks;
    });
    registerTag(ChunkTag.class, "random_loaded_chunk", (attribute, object) -> {
        Deprecations.worldRandomLoadedChunkTag.warn(attribute.context);
        int random = CoreUtilities.getRandom().nextInt(object.getWorld().getLoadedChunks().length);
        return new ChunkTag(object.getWorld().getLoadedChunks()[random]);
    });
    // <--[tag]
    // @attribute <WorldTag.sea_level>
    // @returns ElementTag(Number)
    // @description
    // Returns the level of the sea.
    // -->
    registerTag(ElementTag.class, "sea_level", (attribute, object) -> {
        return new ElementTag(object.getWorld().getSeaLevel());
    });
    // <--[tag]
    // @attribute <WorldTag.max_height>
    // @returns ElementTag(Number)
    // @description
    // Returns the maximum block height of the world.
    // -->
    registerTag(ElementTag.class, "max_height", (attribute, object) -> {
        return new ElementTag(object.getWorld().getMaxHeight());
    });
    // <--[tag]
    // @attribute <WorldTag.min_height>
    // @returns ElementTag(Number)
    // @description
    // Returns the minimum block height of the world.
    // -->
    registerTag(ElementTag.class, "min_height", (attribute, object) -> {
        return new ElementTag(object.getWorld().getMinHeight());
    });
    // <--[tag]
    // @attribute <WorldTag.spawn_location>
    // @returns LocationTag
    // @mechanism WorldTag.spawn_location
    // @description
    // Returns the spawn location of the world.
    // -->
    registerTag(LocationTag.class, "spawn_location", (attribute, object) -> {
        return new LocationTag(object.getWorld().getSpawnLocation());
    });
    // <--[tag]
    // @attribute <WorldTag.world_type>
    // @returns ElementTag
    // @description
    // Returns the world type of the world.
    // Can return any enum from: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/WorldType.html>
    // -->
    registerTag(ElementTag.class, "world_type", (attribute, object) -> {
        return new ElementTag(object.getWorld().getWorldType().getName());
    });
    // ///////////////////
    // IDENTIFICATION ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <WorldTag.name>
    // @returns ElementTag
    // @description
    // Returns the name of the world.
    // -->
    tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
        return new ElementTag(object.world_name);
    });
    // <--[tag]
    // @attribute <WorldTag.seed>
    // @returns ElementTag
    // @description
    // Returns the world seed.
    // -->
    registerTag(ElementTag.class, "seed", (attribute, object) -> {
        return new ElementTag(object.getWorld().getSeed());
    });
    // ///////////////////
    // SETTINGS ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <WorldTag.allows_animals>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether animals can spawn in this world.
    // -->
    registerTag(ElementTag.class, "allows_animals", (attribute, object) -> {
        return new ElementTag(object.getWorld().getAllowAnimals());
    });
    // <--[tag]
    // @attribute <WorldTag.allows_monsters>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether monsters can spawn in this world.
    // -->
    registerTag(ElementTag.class, "allows_monsters", (attribute, object) -> {
        return new ElementTag(object.getWorld().getAllowMonsters());
    });
    // <--[tag]
    // @attribute <WorldTag.allows_pvp>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether player versus player combat is allowed in this world.
    // -->
    registerTag(ElementTag.class, "allows_pvp", (attribute, object) -> {
        return new ElementTag(object.getWorld().getPVP());
    });
    // <--[tag]
    // @attribute <WorldTag.auto_save>
    // @returns ElementTag(Boolean)
    // @mechanism WorldTag.auto_save
    // @description
    // Returns whether the world automatically saves.
    // -->
    registerTag(ElementTag.class, "auto_save", (attribute, object) -> {
        return new ElementTag(object.getWorld().isAutoSave());
    });
    // <--[tag]
    // @attribute <WorldTag.ambient_spawn_limit>
    // @returns ElementTag(Number)
    // @mechanism WorldTag.ambient_spawn_limit
    // @description
    // Returns the number of ambient mobs that can spawn in a chunk in this world.
    // -->
    registerTag(ElementTag.class, "ambient_spawn_limit", (attribute, object) -> {
        return new ElementTag(object.getWorld().getAmbientSpawnLimit());
    });
    // <--[tag]
    // @attribute <WorldTag.animal_spawn_limit>
    // @returns ElementTag(Number)
    // @mechanism WorldTag.animal_spawn_limit
    // @description
    // Returns the number of animals that can spawn in a chunk in this world.
    // -->
    registerTag(ElementTag.class, "animal_spawn_limit", (attribute, object) -> {
        return new ElementTag(object.getWorld().getAnimalSpawnLimit());
    });
    // <--[tag]
    // @attribute <WorldTag.monster_spawn_limit>
    // @returns ElementTag(Number)
    // @mechanism WorldTag.monster_spawn_limit
    // @description
    // Returns the number of monsters that can spawn in a chunk in this world.
    // -->
    registerTag(ElementTag.class, "monster_spawn_limit", (attribute, object) -> {
        return new ElementTag(object.getWorld().getMonsterSpawnLimit());
    });
    // <--[tag]
    // @attribute <WorldTag.water_animal_spawn_limit>
    // @returns ElementTag(Number)
    // @mechanism WorldTag.water_animal_spawn_limit
    // @description
    // Returns the number of water animals that can spawn in a chunk in this world.
    // -->
    registerTag(ElementTag.class, "water_animal_spawn_limit", (attribute, object) -> {
        return new ElementTag(object.getWorld().getWaterAnimalSpawnLimit());
    });
    // <--[tag]
    // @attribute <WorldTag.difficulty>
    // @returns ElementTag
    // @mechanism WorldTag.difficulty
    // @description
    // Returns the name of the difficulty level.
    // -->
    registerTag(ElementTag.class, "difficulty", (attribute, object) -> {
        return new ElementTag(object.getWorld().getDifficulty().name());
    });
    // <--[tag]
    // @attribute <WorldTag.hardcore>
    // @returns ElementTag(Boolean)
    // @mechanism WorldTag.hardcore
    // @description
    // Returns whether the world is in hardcore mode.
    // -->
    registerTag(ElementTag.class, "hardcore", (attribute, object) -> {
        return new ElementTag(object.getWorld().isHardcore());
    });
    // <--[tag]
    // @attribute <WorldTag.keep_spawn>
    // @returns ElementTag(Boolean)
    // @mechanism WorldTag.keep_spawn
    // @description
    // Returns whether the world's spawn area should be kept loaded into memory.
    // -->
    registerTag(ElementTag.class, "keep_spawn", (attribute, object) -> {
        return new ElementTag(object.getWorld().getKeepSpawnInMemory());
    });
    // <--[tag]
    // @attribute <WorldTag.ticks_per_animal_spawn>
    // @returns DurationTag
    // @mechanism WorldTag.ticks_per_animal_spawns
    // @description
    // Returns the world's ticks per animal spawn value.
    // -->
    registerTag(DurationTag.class, "ticks_per_animal_spawn", (attribute, object) -> {
        return new DurationTag(object.getWorld().getTicksPerAnimalSpawns());
    });
    // <--[tag]
    // @attribute <WorldTag.ticks_per_monster_spawn>
    // @returns DurationTag
    // @mechanism WorldTag.ticks_per_monster_spawns
    // @description
    // Returns the world's ticks per monster spawn value.
    // -->
    registerTag(DurationTag.class, "ticks_per_monster_spawn", (attribute, object) -> {
        return new DurationTag(object.getWorld().getTicksPerMonsterSpawns());
    });
    // <--[tag]
    // @attribute <WorldTag.duration_since_created>
    // @returns DurationTag
    // @description
    // Returns the total duration of time since this world was first created.
    // -->
    registerTag(DurationTag.class, "duration_since_created", (attribute, object) -> {
        return new DurationTag(object.getWorld().getGameTime());
    });
    // ///////////////////
    // TIME ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <WorldTag.time>
    // @returns ElementTag(Number)
    // @mechanism WorldTag.time
    // @description
    // Returns the relative in-game time of this world.
    // -->
    registerTag(ObjectTag.class, "time", (attribute, object) -> {
        // -->
        if (attribute.startsWith("duration", 2)) {
            attribute.fulfill(1);
            return new DurationTag(object.getWorld().getTime());
        } else // -->
        if (attribute.startsWith("full", 2)) {
            attribute.fulfill(1);
            return new DurationTag(object.getWorld().getFullTime());
        } else // -->
        if (attribute.startsWith("period", 2)) {
            attribute.fulfill(1);
            long time = object.getWorld().getTime();
            String period;
            if (time >= 23000) {
                period = "dawn";
            } else if (time >= 13500) {
                period = "night";
            } else if (time >= 12500) {
                period = "dusk";
            } else {
                period = "day";
            }
            return new ElementTag(period);
        } else {
            return new ElementTag(object.getWorld().getTime());
        }
    });
    // <--[tag]
    // @attribute <WorldTag.moon_phase>
    // @returns ElementTag(Number)
    // @description
    // Returns the current phase of the moon, as a number from 1 to 8.
    // -->
    registerTag(ElementTag.class, "moon_phase", (attribute, object) -> {
        return new ElementTag((int) ((object.getWorld().getFullTime() / 24000) % 8) + 1);
    }, "moonphase");
    // ///////////////////
    // WEATHER ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <WorldTag.has_storm>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether there is currently a storm in this world.
    // ie, whether it is raining. To check for thunder, use <@link tag WorldTag.thundering>.
    // -->
    registerTag(ElementTag.class, "has_storm", (attribute, object) -> {
        return new ElementTag(object.getWorld().hasStorm());
    });
    // <--[tag]
    // @attribute <WorldTag.thunder_duration>
    // @returns DurationTag
    // @mechanism WorldTag.thunder_duration
    // @description
    // Returns the duration of thunder.
    // -->
    registerTag(DurationTag.class, "thunder_duration", (attribute, object) -> {
        return new DurationTag((long) object.getWorld().getThunderDuration());
    });
    // <--[tag]
    // @attribute <WorldTag.thundering>
    // @returns ElementTag(Boolean)
    // @mechanism WorldTag.thundering
    // @description
    // Returns whether it is currently thundering in this world.
    // -->
    registerTag(ElementTag.class, "thundering", (attribute, object) -> {
        return new ElementTag(object.getWorld().isThundering());
    });
    // <--[tag]
    // @attribute <WorldTag.weather_duration>
    // @returns DurationTag
    // @mechanism WorldTag.weather_duration
    // @description
    // Returns the duration of storms.
    // -->
    registerTag(DurationTag.class, "weather_duration", (attribute, object) -> {
        return new DurationTag((long) object.getWorld().getWeatherDuration());
    });
    // <--[tag]
    // @attribute <WorldTag.environment>
    // @returns ElementTag
    // @description
    // Returns the environment of the world: NORMAL, NETHER, or THE_END.
    // -->
    registerTag(ElementTag.class, "environment", (attribute, object) -> {
        return new ElementTag(object.getWorld().getEnvironment().name());
    });
    // ///////////////////
    // WORLD BORDER ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <WorldTag.border_size>
    // @returns ElementTag(Decimal)
    // @description
    // Returns the size of the world border in this world.
    // -->
    registerTag(ElementTag.class, "border_size", (attribute, object) -> {
        return new ElementTag(object.getWorld().getWorldBorder().getSize());
    });
    // <--[tag]
    // @attribute <WorldTag.border_center>
    // @returns LocationTag
    // @description
    // Returns the center of the world border in this world.
    // -->
    registerTag(LocationTag.class, "border_center", (attribute, object) -> {
        return new LocationTag(object.getWorld().getWorldBorder().getCenter());
    });
    // <--[tag]
    // @attribute <WorldTag.border_damage>
    // @returns ElementTag(Decimal)
    // @description
    // Returns the amount of damage caused by crossing the world border in this world.
    // -->
    registerTag(ElementTag.class, "border_damage", (attribute, object) -> {
        return new ElementTag(object.getWorld().getWorldBorder().getDamageAmount());
    });
    // <--[tag]
    // @attribute <WorldTag.border_damage_buffer>
    // @returns ElementTag(Decimal)
    // @description
    // Returns the damage buffer of the world border in this world.
    // -->
    registerTag(ElementTag.class, "border_damage_buffer", (attribute, object) -> {
        return new ElementTag(object.getWorld().getWorldBorder().getDamageBuffer());
    });
    // <--[tag]
    // @attribute <WorldTag.border_warning_distance>
    // @returns ElementTag(Number)
    // @description
    // Returns the warning distance of the world border in this world.
    // -->
    registerTag(ElementTag.class, "border_warning_distance", (attribute, object) -> {
        return new ElementTag(object.getWorld().getWorldBorder().getWarningDistance());
    });
    // <--[tag]
    // @attribute <WorldTag.border_warning_time>
    // @returns DurationTag
    // @description
    // Returns warning time of the world border in this world as a duration.
    // -->
    registerTag(DurationTag.class, "border_warning_time", (attribute, object) -> {
        return new DurationTag(object.getWorld().getWorldBorder().getWarningTime());
    });
    // <--[tag]
    // @attribute <WorldTag.gamerule[<gamerule>]>
    // @returns ElementTag
    // @description
    // Returns the current value of the specified gamerule in the world.
    // Note that the name is case-sensitive... so "doFireTick" is correct, but "dofiretick" is not.
    // -->
    registerTag(ElementTag.class, "gamerule", (attribute, object) -> {
        if (!attribute.hasParam()) {
            attribute.echoError("The tag 'worldtag.gamerule[...]' must have an input value.");
            return null;
        }
        GameRule rule = GameRule.getByName(attribute.getParam());
        Object result = object.getWorld().getGameRuleValue(rule);
        return new ElementTag(result == null ? "null" : result.toString());
    });
    // <--[tag]
    // @attribute <WorldTag.gamerule_map>
    // @returns MapTag
    // @description
    // Returns a map of all the current values of all gamerules in the world.
    // -->
    registerTag(MapTag.class, "gamerule_map", (attribute, object) -> {
        MapTag map = new MapTag();
        for (GameRule rule : GameRule.values()) {
            Object result = object.getWorld().getGameRuleValue(rule);
            if (result != null) {
                map.putObject(rule.getName(), new ElementTag(result.toString()));
            }
        }
        return map;
    });
    // <--[tag]
    // @attribute <WorldTag.dragon_portal_location>
    // @returns LocationTag
    // @description
    // Returns the location of the ender dragon exit portal, if any (only for end worlds).
    // -->
    registerTag(LocationTag.class, "dragon_portal_location", (attribute, object) -> {
        DragonBattle battle = object.getWorld().getEnderDragonBattle();
        if (battle == null) {
            return null;
        }
        if (battle.getEndPortalLocation() == null) {
            return null;
        }
        return new LocationTag(battle.getEndPortalLocation());
    });
    // <--[tag]
    // @attribute <WorldTag.ender_dragon>
    // @returns EntityTag
    // @description
    // Returns the ender dragon entity currently fighting in this world, if any (only for end worlds).
    // -->
    registerTag(EntityTag.class, "ender_dragon", (attribute, object) -> {
        DragonBattle battle = object.getWorld().getEnderDragonBattle();
        if (battle == null) {
            return null;
        }
        if (battle.getEnderDragon() == null) {
            return null;
        }
        return new EntityTag(battle.getEnderDragon());
    });
    // <--[tag]
    // @attribute <WorldTag.gateway_locations>
    // @returns ListTag(LocationTag)
    // @description
    // Returns a list of possible gateway portal locations, if any (only for end worlds).
    // Not all of these will necessarily generate.
    // In current implementation, this is a list of exactly 20 locations in a circle around the world origin (with radius of 96 blocks).
    // -->
    registerTag(ListTag.class, "gateway_locations", (attribute, object) -> {
        DragonBattle battle = object.getWorld().getEnderDragonBattle();
        if (battle == null) {
            return null;
        }
        ListTag list = new ListTag();
        for (int i = 0; i < 20; i++) {
            // This math based on EndDragonFight#spawnNewGateway
            int x = (int) Math.floor(96.0D * Math.cos(2.0D * (-Math.PI + (Math.PI / 20.0) * i)));
            int z = (int) Math.floor(96.0D * Math.sin(2.0D * (-Math.PI + (Math.PI / 20.0) * i)));
            list.addObject(new LocationTag(object.getWorld(), x, 75, z));
        }
        return list;
    });
    // <--[tag]
    // @attribute <WorldTag.biomes>
    // @returns ListTag(BiomeTag)
    // @description
    // Returns a list of all biomes in this world (including custom biomes).
    // -->
    registerTag(ListTag.class, "biomes", (attribute, object) -> {
        ListTag output = new ListTag();
        for (BiomeNMS biome : NMSHandler.getInstance().getBiomes(object.getWorld())) {
            output.addObject(new BiomeTag(biome));
        }
        return output;
    });
    // <--[tag]
    // @attribute <WorldTag.advanced_matches[<matcher>]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the world matches some matcher text, using the system behind <@link language Advanced Script Event Matching>.
    // -->
    registerTag(ElementTag.class, "advanced_matches", (attribute, object) -> {
        if (!attribute.hasParam()) {
            return null;
        }
        return new ElementTag(BukkitScriptEvent.tryWorld(object, attribute.getParam()));
    });
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) BiomeNMS(com.denizenscript.denizen.nms.abstracts.BiomeNMS) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) DragonBattle(org.bukkit.boss.DragonBattle) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) FlaggableObject(com.denizenscript.denizencore.flags.FlaggableObject) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Aggregations

BiomeNMS (com.denizenscript.denizen.nms.abstracts.BiomeNMS)2 FlaggableObject (com.denizenscript.denizencore.flags.FlaggableObject)1 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 MapTag (com.denizenscript.denizencore.objects.core.MapTag)1 NPC (net.citizensnpcs.api.npc.NPC)1 World (org.bukkit.World)1 DragonBattle (org.bukkit.boss.DragonBattle)1 Entity (org.bukkit.entity.Entity)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Player (org.bukkit.entity.Player)1