Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registry - more registries #6806

Merged
merged 5 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/ch/njol/skript/bukkitutil/BukkitUtils.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
19 changes: 16 additions & 3 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<Cat.Type> 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.")
Expand Down Expand Up @@ -1514,7 +1521,13 @@ public String toVariableNameString(EnchantmentOffer eo) {
}
}));

Classes.registerClass(new EnumClassInfo<>(Attribute.class, "attributetype", "attribute types")
ClassInfo<Attribute> 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."
Expand Down
43 changes: 43 additions & 0 deletions src/main/resources/lang/default.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down