Skip to content

Commit

Permalink
v12.0.0 Candidate for MC v1.21.3
Browse files Browse the repository at this point in the history
# Partially Updated for v1.21.3
* Fixes #306
* Fixes #310

> [!IMPORTANT]
> XSeries will no longer follow independent class principle due to a lot of changes caused by previous versions.
> This version implements the abstraction concept from #239 as an experiment. This change was forced because
> Minecraft now uses registries for most enum-like.

* Added XAttribute (For #307)
* ParticleDisplay clone() method now properly copies the "only visible to" setting. (Fixes #309)
  • Loading branch information
CryptoMorin committed Nov 18, 2024
1 parent c4b96a3 commit e05f02e
Show file tree
Hide file tree
Showing 31 changed files with 2,506 additions and 1,863 deletions.
46 changes: 30 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
<id>nms-repo</id>
<url>https://repo.codemc.org/repository/nms/</url>
</repository>
<!-- <repository>-->
<!-- &lt;!&ndash; Sometimes codemc's snapshots don't have the mojang packages. &ndash;&gt;-->
<!-- &lt;!&ndash; https://libraries.minecraft.net/com/mojang/authlib/VERSION/authlib-VERSION.jar &ndash;&gt;-->
<!-- <id>minecraft-libraries</id>-->
<!-- <name>Minecraft Libraries</name>-->
<!-- <url>https://libraries.minecraft.net/</url>-->
<!-- </repository>-->
<repository>
<!-- Sometimes codemc's snapshots don't have the mojang packages. -->
<!-- https://libraries.minecraft.net/com/mojang/authlib/VERSION/authlib-VERSION.jar -->
<id>minecraft-libraries</id>
<name>Minecraft Libraries</name>
<url>https://libraries.minecraft.net/</url>
</repository>
</repositories>

<properties>
Expand All @@ -85,18 +85,32 @@
<!-- 1.19.4-R0.1-SNAPSHOT -->
<!-- 1.20.6-R0.1-SNAPSHOT -->
<!-- 1.21.1-R0.1-SNAPSHOT -->
<spigotVersion>1.21.1-R0.1-SNAPSHOT</spigotVersion>
<!-- 1.21.3-R0.1-SNAPSHOT -->
<!-- mvn install:install-file "-Dfile=C:\Users\Crypto Morin\Desktop\server.jar" -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.21.3-R0.1-EXPR -Dpackaging=jar -DgeneratePom=true -->
<spigotVersion>1.21.3-R0.1-EXPR</spigotVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<!-- <dependency>-->
<!-- <groupId>com.mojang</groupId>-->
<!-- <artifactId>authlib</artifactId>-->
<!-- <version>6.0.54</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>net.sf.jopt-simple</groupId>
<artifactId>jopt-simple</artifactId>
<version>5.0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-iostreams</artifactId>
<version>2.22.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>6.0.55</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
Expand All @@ -107,13 +121,13 @@
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
<version>26.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/cryptomorin/xseries/StandardSound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.cryptomorin.xseries;

final class StandardSound {
}
103 changes: 103 additions & 0 deletions src/main/java/com/cryptomorin/xseries/XAttribute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.cryptomorin.xseries;

import com.cryptomorin.xseries.base.XModule;
import com.cryptomorin.xseries.base.XRegistry;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import java.util.UUID;

public final class XAttribute extends XModule<XAttribute, Attribute> {
private static final XRegistry<XAttribute, Attribute> REGISTRY =
new XRegistry<>(Attribute.class, XAttribute.class, () -> Registry.ATTRIBUTE, XAttribute::new, XAttribute[]::new);

public static final XAttribute
MAX_HEALTH = std(/* v1.20.3+ */ "max_health", "generic_max_health"),
FOLLOW_RANGE = std("follow_range"),
KNOCKBACK_RESISTANCE = std("knockback_resistance"),
MOVEMENT_SPEED = std("movement_speed"),
FLYING_SPEED = std("flying_speed"),
ATTACK_DAMAGE = std("attack_damage"),
ATTACK_KNOCKBACK = std("attack_knockback"),
ATTACK_SPEED = std("attack_speed"),
ARMOR = std("armor"),
ARMOR_TOUGHNESS = std("armor_toughness"),
FALL_DAMAGE_MULTIPLIER = std("fall_damage_multiplier"),
LUCK = std("luck"),
MAX_ABSORPTION = std("max_absorption"),
SAFE_FALL_DISTANCE = std("safe_fall_distance"),
SCALE = std("scale"),
STEP_HEIGHT = std("step_height"),
GRAVITY = std("gravity"),
JUMP_STRENGTH = std("jump_strength"),
BURNING_TIME = std("burning_time"),
EXPLOSION_KNOCKBACK_RESISTANCE = std("explosion_knockback_resistance"),
MOVEMENT_EFFICIENCY = std("movement_efficiency"),
OXYGEN_BONUS = std("oxygen_bonus"),
WATER_MOVEMENT_EFFICIENCY = std("water_movement_efficiency"),
TEMPT_RANGE = std("tempt_range"),
BLOCK_INTERACTION_RANGE = std("block_interaction_range"),
ENTITY_INTERACTION_RANGE = std("entity_interaction_range"),
BLOCK_BREAK_SPEED = std("block_break_speed"),
MINING_EFFICIENCY = std("mining_efficiency"),
SNEAKING_SPEED = std("sneaking_speed"),
SUBMERGED_MINING_SPEED = std("submerged_mining_speed"),
SWEEPING_DAMAGE_RATIO = std("sweeping_damage_ratio"),
SPAWN_REINFORCEMENTS = std("spawn_reinforcements");

private static final boolean SUPPORTS_MODERN_MODIFIERS;

static {
// public AttributeModifier(NamespacedKey key, double amount, AttributeModifier.Operation operation, EquipmentSlotGroup slot)
boolean supportsModernModifiers = false;
try {
// noinspection UnstableApiUsage
AttributeModifier.class.getConstructor(
org.bukkit.NamespacedKey.class,
double.class,
AttributeModifier.Operation.class,
org.bukkit.inventory.EquipmentSlotGroup.class
);
supportsModernModifiers = true;
} catch (NoSuchMethodException | NoClassDefFoundError ignored) {
}

SUPPORTS_MODERN_MODIFIERS = supportsModernModifiers;
}

private XAttribute(Attribute attribute, String[] names) {
super(attribute, names);
}

public AttributeModifier createModifier(@NotNull String key, double amount, @NotNull AttributeModifier.Operation operation, @NotNull EquipmentSlot slot) {
if (SUPPORTS_MODERN_MODIFIERS) {
// noinspection UnstableApiUsage
return new AttributeModifier(NamespacedKey.fromString(key), amount, operation, slot.getGroup());
} else {
// noinspection removal
return new AttributeModifier(UUID.randomUUID(), key, amount, operation, slot);
}
}


public static XAttribute of(Attribute attribute) {
return REGISTRY.getByBukkitForm(attribute);
}

public static Optional<XAttribute> of(String attribute) {
return REGISTRY.getByName(attribute);
}

public static XAttribute[] values() {
return REGISTRY.values();
}

private static XAttribute std(String... names) {
return REGISTRY.std(names);
}
}
21 changes: 11 additions & 10 deletions src/main/java/com/cryptomorin/xseries/XBiome.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum XBiome {
SPARSE_JUNGLE("JUNGLE_EDGE", "JUNGLE_EDGE"),
STONY_SHORE("STONE_SHORE", "STONE_BEACH"),
CHERRY_GROVE,
PALE_GARDEN,
OLD_GROWTH_PINE_TAIGA("GIANT_TREE_TAIGA", "REDWOOD_TAIGA", "MEGA_TAIGA"),
WINDSWEPT_FOREST("WOODED_MOUNTAINS", "EXTREME_HILLS_WITH_TREES", "EXTREME_HILLS_PLUS"),
WOODED_BADLANDS("WOODED_BADLANDS_PLATEAU", "MESA_ROCK", "MESA_PLATEAU_FOREST"),
Expand Down Expand Up @@ -181,16 +182,16 @@ public enum XBiome {
Data.NAMES.put(this.name(), this);
for (String legacy : legacies) Data.NAMES.put(legacy, this);

Biome biome = Enums.getIfPresent(Biome.class, this.name()).orNull();
if (biome == null) {
if (newVersion != null) biome = newVersion.biome;
if (biome == null) {
for (String legacy : legacies) {
biome = Enums.getIfPresent(Biome.class, legacy).orNull();
if (biome != null) break;
}
}
}
Biome biome = null;//Enums.getIfPresent(Biome.class, this.name()).orNull();
// if (biome == null) {
// if (newVersion != null) biome = newVersion.biome;
// if (biome == null) {
// for (String legacy : legacies) {
// biome = Enums.getIfPresent(Biome.class, legacy).orNull();
// if (biome != null) break;
// }
// }
// }
this.biome = biome;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/cryptomorin/xseries/XEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.common.base.Enums;
import com.google.common.base.Strings;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarFlag;
import org.bukkit.boss.BarStyle;
Expand Down Expand Up @@ -332,7 +331,7 @@ public static Entity edit(@NotNull Entity entity, @NotNull ConfigurationSection
LivingEntity living = (LivingEntity) entity;
if (config.isSet("health")) {
double hp = config.getDouble("health");
living.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(hp);
living.getAttribute(XAttribute.MAX_HEALTH.get()).setBaseValue(hp);
living.setHealth(hp);
}

Expand Down
19 changes: 9 additions & 10 deletions src/main/java/com/cryptomorin/xseries/XItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public static void serialize(@NotNull ItemStack item, @NotNull ConfigurationSect
String path = "attributes." + attribute.getKey().name() + '.';
AttributeModifier modifier = attribute.getValue();

config.set(path + "id", modifier.getUniqueId().toString());
// config.set(path + "id", modifier.getUniqueId().toString());
config.set(path + "name", modifier.getName());
config.set(path + "amount", modifier.getAmount());
config.set(path + "operation", modifier.getOperation().name());
Expand Down Expand Up @@ -1114,24 +1114,23 @@ public static ItemStack edit(@NotNull ItemStack item,
ConfigurationSection attributes = config.getConfigurationSection("attributes");
if (attributes != null) {
for (String attribute : attributes.getKeys(false)) {
Attribute attributeInst = Enums.getIfPresent(Attribute.class, attribute.toUpperCase(Locale.ENGLISH)).orNull();
if (attributeInst == null) continue;
Optional<XAttribute> attributeInst = XAttribute.of(attribute);
if (!attributeInst.isPresent()) continue;
ConfigurationSection section = attributes.getConfigurationSection(attribute);
if (section == null) continue;

String attribId = section.getString("id");
UUID id = attribId != null ? UUID.fromString(attribId) : UUID.randomUUID();
// String attribId = section.getString("id");
// UUID id = attribId != null ? UUID.fromString(attribId) : UUID.randomUUID();
EquipmentSlot slot = section.getString("slot") != null ? Enums.getIfPresent(EquipmentSlot.class, section.getString("slot")).or(EquipmentSlot.HAND) : null;

AttributeModifier modifier = new AttributeModifier(
id,
AttributeModifier modifier = attributeInst.get().createModifier(
section.getString("name"),
section.getDouble("amount"),
Enums.getIfPresent(AttributeModifier.Operation.class, section.getString("operation"))
.or(AttributeModifier.Operation.ADD_NUMBER),
slot);

meta.addAttributeModifier(attributeInst, modifier);
slot
);
meta.addAttributeModifier(attributeInst.get().get(), modifier);
}
}
}
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/cryptomorin/xseries/XMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,51 @@ public enum XMaterial /* implements com.cryptomorin.xseries.abstractions.Materia
WEATHERED_CUT_COPPER,
WEATHERED_CUT_COPPER_SLAB,
WEATHERED_CUT_COPPER_STAIRS,
PALE_OAK_PLANKS,
PALE_OAK_SAPLING,
PALE_OAK_LOG,
STRIPPED_PALE_OAK_LOG,
STRIPPED_PALE_OAK_WOOD,
PALE_OAK_WOOD,
PALE_OAK_LEAVES,
PALE_MOSS_CARPET,
PALE_HANGING_MOSS,
PALE_MOSS_BLOCK,
PALE_OAK_SLAB,
CREAKING_HEART,
PALE_OAK_FENCE,
PALE_OAK_STAIRS,
PALE_OAK_BUTTON,
PALE_OAK_PRESSURE_PLATE,
PALE_OAK_DOOR,
PALE_OAK_TRAPDOOR,
PALE_OAK_FENCE_GATE,
PALE_OAK_BOAT,
PALE_OAK_CHEST_BOAT,
PALE_OAK_SIGN,
PALE_OAK_HANGING_SIGN,
WHITE_BUNDLE,
ORANGE_BUNDLE,
MAGENTA_BUNDLE,
LIGHT_BLUE_BUNDLE,
YELLOW_BUNDLE,
LIME_BUNDLE,
PINK_BUNDLE,
GRAY_BUNDLE,
LIGHT_GRAY_BUNDLE,
CYAN_BUNDLE,
PURPLE_BUNDLE,
BLUE_BUNDLE,
BROWN_BUNDLE,
GREEN_BUNDLE,
RED_BUNDLE,
BLACK_BUNDLE,
CREAKING_SPAWN_EGG,
FIELD_MASONED_BANNER_PATTERN,
BORDURE_INDENTED_BANNER_PATTERN,
PALE_OAK_WALL_SIGN,
PALE_OAK_WALL_HANGING_SIGN,
POTTED_PALE_OAK_SAPLING,
WEEPING_VINES,
WEEPING_VINES_PLANT,
WET_SPONGE(1, "SPONGE"),
Expand Down Expand Up @@ -2314,6 +2359,8 @@ private static final class Data {
private static final int VERSION;

static { // This needs to be right below VERSION because of initialization order.
// Null-checked for unit tests that don't run a server.
// noinspection ConstantValue
if (Bukkit.getServer() == null) {
System.err.println("Bukkit.getServer() in null. This should not happen when running a plugin normally");
VERSION = 21;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/cryptomorin/xseries/XPotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ public enum XPotion {
* Special type of effect. Minecraft itself doesn't recognize this as a separate potion type,
* but as a combination of two other potion types. However, Bukkit's {@link PotionType#TURTLE_MASTER} decided
* to add this, whereas {@link PotionEffectType} doesn't have such enum.
* <p>
* This was removed in Mincraft v1.21.3, should we remove it as well?
*
* @since Minecraft v1.21
*/
@Deprecated
TURTLE_MASTER,
UNLUCK("UNLUCKY"),
WATER_BREATHING("WATER_BREATH", "UNDERWATER_BREATHING", "UNDERWATER_BREATH", "AIR"),
Expand Down
Loading

0 comments on commit e05f02e

Please sign in to comment.