|
11 | 11 | import ch.njol.skript.classes.*; |
12 | 12 | import ch.njol.skript.classes.registry.RegistryClassInfo; |
13 | 13 | import ch.njol.skript.entity.EntityData; |
14 | | -import ch.njol.skript.entity.WolfData; |
| 14 | +import ch.njol.skript.entity.PigData.PigVariantDummy; |
| 15 | +import ch.njol.skript.entity.WolfData.WolfVariantDummy; |
15 | 16 | import ch.njol.skript.expressions.ExprDamageCause; |
16 | 17 | import ch.njol.skript.expressions.base.EventValueExpression; |
17 | 18 | import ch.njol.skript.lang.ParseContext; |
18 | 19 | import ch.njol.skript.lang.util.SimpleLiteral; |
19 | 20 | import ch.njol.skript.localization.Language; |
20 | 21 | import ch.njol.skript.registrations.Classes; |
21 | | -import ch.njol.skript.util.BlockUtils; |
22 | | -import ch.njol.skript.util.PotionEffectUtils; |
23 | | -import ch.njol.skript.util.StringMode; |
24 | | -import ch.njol.skript.util.Utils; |
| 22 | +import ch.njol.skript.util.*; |
25 | 23 | import ch.njol.yggdrasil.Fields; |
26 | 24 | import io.papermc.paper.world.MoonPhase; |
27 | 25 | import org.bukkit.*; |
|
44 | 42 | import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; |
45 | 43 | import org.bukkit.event.entity.EntityTransformEvent.TransformReason; |
46 | 44 | import org.bukkit.event.entity.EntityUnleashEvent; |
| 45 | +import org.bukkit.event.entity.VillagerCareerChangeEvent; |
47 | 46 | import org.bukkit.event.inventory.ClickType; |
48 | 47 | import org.bukkit.event.inventory.InventoryAction; |
49 | 48 | import org.bukkit.event.inventory.InventoryCloseEvent; |
|
52 | 51 | import org.bukkit.event.player.PlayerQuitEvent.QuitReason; |
53 | 52 | import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status; |
54 | 53 | import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; |
| 54 | +import org.bukkit.inventory.BlockInventoryHolder; |
55 | 55 | import org.bukkit.inventory.*; |
56 | 56 | import org.bukkit.metadata.Metadatable; |
57 | 57 | import org.bukkit.potion.PotionEffect; |
@@ -1410,14 +1410,15 @@ public String toVariableNameString(EnchantmentOffer eo) { |
1410 | 1410 | .description("Represents the cause of the action of a potion effect on an entity, e.g. arrow, command") |
1411 | 1411 | .since("2.10")); |
1412 | 1412 |
|
1413 | | - ClassInfo<?> wolfVariantClassInfo; |
1414 | | - if (Skript.classExists("org.bukkit.entity.Wolf$Variant") && BukkitUtils.registryExists("WOLF_VARIANT")) { |
1415 | | - wolfVariantClassInfo = new RegistryClassInfo<>(Wolf.Variant.class, Registry.WOLF_VARIANT, "wolfvariant", "wolf variants"); |
1416 | | - } else { |
1417 | | - /* |
1418 | | - * Registers a dummy/placeholder class to ensure working operation on MC versions that do not have `Wolf.Variant` |
1419 | | - */ |
1420 | | - wolfVariantClassInfo = new ClassInfo<>(WolfData.VariantDummy.class, "wolfvariant"); |
| 1413 | + ClassInfo<?> wolfVariantClassInfo = getRegistryClassInfo( |
| 1414 | + "org.bukkit.entity.Wolf$Variant", |
| 1415 | + "WOLF_VARIANT", |
| 1416 | + "wolfvariant", |
| 1417 | + "wolf variants" |
| 1418 | + ); |
| 1419 | + if (wolfVariantClassInfo == null) { |
| 1420 | + // Registers a dummy/placeholder class to ensure working operation on MC versions that do not have 'Wolf.Variant' (1.20.4-) |
| 1421 | + wolfVariantClassInfo = new ClassInfo<>(WolfVariantDummy.class, "wolfvariant"); |
1421 | 1422 | } |
1422 | 1423 | Classes.registerClass(wolfVariantClassInfo |
1423 | 1424 | .user("wolf ?variants?") |
@@ -1550,14 +1551,82 @@ public String toVariableNameString(WorldBorder border) { |
1550 | 1551 | .changer(DefaultChangers.entityChanger) |
1551 | 1552 | ); |
1552 | 1553 |
|
1553 | | - |
1554 | 1554 | Classes.registerClass(new EnumClassInfo<>(EquipmentSlot.class, "equipmentslot", "equipment slots") |
1555 | 1555 | .user("equipment ?slots?") |
1556 | 1556 | .name("Equipment Slot") |
1557 | 1557 | .description("Represents an equipment slot of an entity.") |
1558 | 1558 | .since("2.11") |
1559 | 1559 | ); |
1560 | 1560 |
|
| 1561 | + ClassInfo<?> pigVariantClassInfo = getRegistryClassInfo( |
| 1562 | + "org.bukkit.entity.Pig$Variant", |
| 1563 | + "PIG_VARIANT", |
| 1564 | + "pigvariant", |
| 1565 | + "pig variants" |
| 1566 | + ); |
| 1567 | + if (pigVariantClassInfo == null) { |
| 1568 | + // Registers a dummy/placeholder class to ensure working operation on MC versions that do not have 'Pig.Variant' (1.21.4-) |
| 1569 | + pigVariantClassInfo = new ClassInfo<>(PigVariantDummy.class, "pigvariant"); |
| 1570 | + } |
| 1571 | + Classes.registerClass(pigVariantClassInfo |
| 1572 | + .user("pig ?variants?") |
| 1573 | + .name("Pig Variant") |
| 1574 | + .description("Represents the variant of a pig entity.", |
| 1575 | + "NOTE: Minecraft namespaces are supported, ex: 'minecraft:warm'.") |
| 1576 | + .since("INSERT VERSION") |
| 1577 | + .requiredPlugins("Minecraft 1.21.5+") |
| 1578 | + .documentationId("PigVariant")); |
| 1579 | + |
| 1580 | + Classes.registerClass(new EnumClassInfo<>(VillagerCareerChangeEvent.ChangeReason.class, "villagercareerchangereason", "villager career change reasons") |
| 1581 | + .user("(villager )?career ?change ?reasons?") |
| 1582 | + .name("Villager Career Change Reason") |
| 1583 | + .description("Represents a reason why a villager changed its career.") |
| 1584 | + .since("INSERT VERSION") |
| 1585 | + ); |
| 1586 | + |
| 1587 | + } |
| 1588 | + |
| 1589 | + /** |
| 1590 | + * Gets a {@link RegistryClassInfo} by checking if the {@link Class} from {@code classPath} exists |
| 1591 | + * and {@link Registry} or {@link io.papermc.paper.registry.RegistryKey} contains {@code registryName}. |
| 1592 | + * @param classPath The {@link String} representation of the desired {@link Class}. |
| 1593 | + * @param registryName The {@link String} representation of the desired {@link Registry}. |
| 1594 | + * @param codeName The name used in patterns. |
| 1595 | + * @param languageNode The language node of the type. |
| 1596 | + * @return {@link RegistryClassInfo} if the class and registry exists, otherwise {@code null}. |
| 1597 | + */ |
| 1598 | + private static <R extends Keyed> @Nullable RegistryClassInfo<?> getRegistryClassInfo( |
| 1599 | + String classPath, |
| 1600 | + String registryName, |
| 1601 | + String codeName, |
| 1602 | + String languageNode |
| 1603 | + ) { |
| 1604 | + if (!Skript.classExists(classPath)) |
| 1605 | + return null; |
| 1606 | + Registry<R> registry = null; |
| 1607 | + if (BukkitUtils.registryExists(registryName)) { |
| 1608 | + try { |
| 1609 | + //noinspection unchecked |
| 1610 | + registry = (Registry<R>) Registry.class.getField(registryName).get(null); |
| 1611 | + } catch (NoSuchFieldException | IllegalAccessException e) { |
| 1612 | + throw new RuntimeException(e); |
| 1613 | + } |
| 1614 | + } else if (PaperUtils.registryExists(registryName)) { |
| 1615 | + registry = PaperUtils.getBukkitRegistry(registryName); |
| 1616 | + } |
| 1617 | + if (registry != null) { |
| 1618 | + Class<R> registryClass; |
| 1619 | + try { |
| 1620 | + //noinspection unchecked |
| 1621 | + registryClass = (Class<R>) Class.forName(classPath); |
| 1622 | + } catch (ClassNotFoundException e) { |
| 1623 | + Skript.debug("Could not retrieve the class with the path: '" + classPath + "'."); |
| 1624 | + throw new RuntimeException(e); |
| 1625 | + } |
| 1626 | + return new RegistryClassInfo<>(registryClass, registry, codeName, languageNode); |
| 1627 | + } |
| 1628 | + Skript.debug("There were no registries found for '" + registryName + "'."); |
| 1629 | + return null; |
1561 | 1630 | } |
1562 | 1631 |
|
1563 | 1632 | } |
0 commit comments