From f6f41ca2ab9a9e7bdd381b111aa8929fb2443be6 Mon Sep 17 00:00:00 2001 From: Shane Bee Date: Mon, 1 Jul 2024 06:10:17 -0700 Subject: [PATCH] Registry - more registries (#6806) * Registry - more registries * BukkitClasses - make registryExists method public * BukkitUtils - create a bukkit utils class --------- Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> --- .../njol/skript/bukkitutil/BukkitUtils.java | 21 +++++++++ .../skript/classes/data/BukkitClasses.java | 19 ++++++-- src/main/resources/lang/default.lang | 43 +++++++++++++++++++ 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ch/njol/skript/bukkitutil/BukkitUtils.java diff --git a/src/main/java/ch/njol/skript/bukkitutil/BukkitUtils.java b/src/main/java/ch/njol/skript/bukkitutil/BukkitUtils.java new file mode 100644 index 00000000000..df551c268f5 --- /dev/null +++ b/src/main/java/ch/njol/skript/bukkitutil/BukkitUtils.java @@ -0,0 +1,21 @@ +package ch.njol.skript.bukkitutil; + +import ch.njol.skript.Skript; +import org.bukkit.Registry; + +/** + * Utility class with methods pertaining to Bukkit API + */ +public class BukkitUtils { + + /** + * Check if a registry exists + * + * @param registry Registry to check for (Fully qualified name of registry) + * @return True if registry exists else false + */ + public static boolean registryExists(String registry) { + return Skript.classExists("org.bukkit.Registry") && Skript.fieldExists(Registry.class, registry); + } + +} diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index 69710a1ad00..530c3df07a5 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -29,6 +29,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import ch.njol.skript.bukkitutil.BukkitUtils; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Difficulty; @@ -980,7 +981,7 @@ public String toVariableNameString(final ItemStack i) { .changer(DefaultChangers.itemChanger)); ClassInfo biomeClassInfo; - if (Skript.classExists("org.bukkit.Registry") && Skript.fieldExists(Registry.class, "BIOME")) { + if (BukkitUtils.registryExists("BIOME")) { biomeClassInfo = new RegistryClassInfo<>(Biome.class, Registry.BIOME, "biome", "biomes"); } else { biomeClassInfo = new EnumClassInfo<>(Biome.class, "biome", "biomes"); @@ -1453,7 +1454,13 @@ public String toVariableNameString(FireworkEffect effect) { .examples("") .since("2.5")); if (Skript.classExists("org.bukkit.entity.Cat$Type")) { - Classes.registerClass(new EnumClassInfo<>(Cat.Type.class, "cattype", "cat types") + ClassInfo catTypeClassInfo; + if (BukkitUtils.registryExists("CAT_VARIANT")) { + catTypeClassInfo = new RegistryClassInfo<>(Cat.Type.class, Registry.CAT_VARIANT, "cattype", "cat types"); + } else { + catTypeClassInfo = new EnumClassInfo<>(Cat.Type.class, "cattype", "cat types"); + } + Classes.registerClass(catTypeClassInfo .user("cat ?(type|race)s?") .name("Cat Type") .description("Represents the race/type of a cat entity.") @@ -1514,7 +1521,13 @@ public String toVariableNameString(EnchantmentOffer eo) { } })); - Classes.registerClass(new EnumClassInfo<>(Attribute.class, "attributetype", "attribute types") + ClassInfo attributeClassInfo; + if (BukkitUtils.registryExists("ATTRIBUTE")) { + attributeClassInfo = new RegistryClassInfo<>(Attribute.class, Registry.ATTRIBUTE, "attributetype", "attribute types"); + } else { + attributeClassInfo = new EnumClassInfo<>(Attribute.class, "attributetype", "attribute types"); + } + Classes.registerClass(attributeClassInfo .user("attribute ?types?") .name("Attribute Type") .description("Represents the type of an attribute. Note that this type does not contain any numerical values." diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang index 701cd9d07b9..38d8cc68f1f 100644 --- a/src/main/resources/lang/default.lang +++ b/src/main/resources/lang/default.lang @@ -2164,11 +2164,14 @@ genes: # -- Attribute Types -- attribute types: + # Enum variation generic_armor: generic armor, armor generic_armor_toughness: generic armor toughness, armor toughness generic_attack_damage: generic attack damage, attack damage generic_attack_knockback: generic attack knockback, attack knockback generic_attack_speed: generic attack speed, attack speed + generic_burning_time: generic burning time, burning time + generic_explosion_knockback_resistance: generic explosion knockback resistance, explosion knockback resistance generic_flying_speed: generic flying speed, flying speed generic_follow_range: generic follow range, follow range generic_gravity: generic gravity, gravity @@ -2177,16 +2180,56 @@ attribute types: generic_luck: generic luck, luck generic_max_absorption: generic max absorption, max absorption generic_max_health: generic max health, max health + generic_movement_efficiency: generic movement efficiency, movement efficiency generic_movement_speed: generic movement speed, movement speed + generic_oxygen_bonus: generic oxygen bonus, oxygen bonus generic_safe_fall_distance: generic safe fall distance, safe fall distance generic_fall_damage_multiplier: generic fall damage multiplier, fall damage multiplier generic_scale: generic scale, scale generic_step_height: generic step height, step height + generic_water_movement_efficiency: generic water movement efficiency, water movement efficiency horse_jump_strength: horse jump strength player_block_break_speed: player block break speed, block break speed player_block_interaction_range: player block interaction range, block interaction range player_entity_interaction_range: player entity interaction range, entity interaction range + player_mining_efficiency: player mining efficiency, mining efficiency + player_sneaking_speed: player sneaking speed, sneaking speed + player_submerged_mining_speed: player submerged mining speed, submerged mining speed + player_sweeping_damage_ratio: player sweeping damage ratio, sweeping damage ratio zombie_spawn_reinforcements: zombie spawn reinforcements + # Registry variation (minecraft keys) + generic.armor: generic armor, armor + generic.armor_toughness: generic armor toughness, armor toughness + generic.attack_damage: generic attack damage, attack damage + generic.attack_knockback: generic attack knockback, attack knockback + generic.attack_speed: generic attack speed, attack speed + generic.burning_time: generic burning time, burning time + generic.explosion_knockback_resistance: generic explosion knockback resistance, explosion knockback resistance + generic.flying_speed: generic flying speed, flying speed + generic.follow_range: generic follow range, follow range + generic.gravity: generic gravity, gravity + generic.jump_strength: generic jump strength, jump strength + generic.knockback_resistance: generic knockback resistance, knockback resistance + generic.luck: generic luck, luck + generic.max_absorption: generic max absorption, max absorption + generic.max_health: generic max health, max health + generic.movement_efficiency: generic movement efficiency, movement efficiency + generic.movement_speed: generic movement speed, movement speed + generic.oxygen_bonus: generic oxygen bonus, oxygen bonus + generic.safe_fall_distance: generic safe fall distance, safe fall distance + generic.fall_damage_multiplier: generic fall damage multiplier, fall damage multiplier + generic.scale: generic scale, scale + generic.step_height: generic step height, step height + generic.water_movement_efficiency: generic water movement efficiency, water movement efficiency + horse_jump_strength: horse jump strength + player.block_break_speed: player block break speed, block break speed + player.block_interaction_range: player block interaction range, block interaction range + player.entity_interaction_range: player entity interaction range, entity interaction range + player.mining_efficiency: player mining efficiency, mining efficiency + player.sneaking_speed: player sneaking speed, sneaking speed + player.submerged_mining_speed: player submerged mining speed, submerged mining speed + player.sweeping_damage_ratio: player sweeping damage ratio, sweeping damage ratio + zombie.spawn_reinforcements: zombie spawn reinforcements # -- Environments -- environments: