diff --git a/build.gradle.kts b/build.gradle.kts index 931e1af..6a25b45 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,18 +35,19 @@ allprojects { dependencies { // Minestom - implementation("net.minestom:minestom-snapshots:a31d239b51") + implementation("net.minestom:minestom-snapshots:1c528d8ae2") + // Configuration API implementation("org.spongepowered:configurate-hocon:4.1.2") // Kyori stuff (Adventure) - implementation("net.kyori:adventure-text-serializer-plain:4.14.0") - implementation("net.kyori:adventure-text-minimessage:4.14.0") - implementation("net.kyori:adventure-text-serializer-ansi:4.14.0-SNAPSHOT") + implementation("net.kyori:adventure-text-serializer-plain:4.16.0") + implementation("net.kyori:adventure-text-minimessage:4.16.0") + implementation("net.kyori:adventure-text-serializer-ansi:4.17.0") // Logger - implementation("ch.qos.logback:logback-classic:1.4.14") + implementation("ch.qos.logback:logback-classic:1.5.6") // Apache Commons Lang implementation("org.apache.commons:commons-lang3:3.14.0") diff --git a/common/src/main/java/net/endercube/common/EndercubeServer.java b/common/src/main/java/net/endercube/common/EndercubeServer.java index 9a2c43a..0882467 100644 --- a/common/src/main/java/net/endercube/common/EndercubeServer.java +++ b/common/src/main/java/net/endercube/common/EndercubeServer.java @@ -11,7 +11,6 @@ import net.minestom.server.extras.velocity.VelocityProxy; import net.minestom.server.instance.block.BlockHandler; import net.minestom.server.utils.NamespaceID; -import net.minestom.server.world.biomes.Biome; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -155,14 +154,6 @@ public void createServer() { } initEncryption(encryptionMode, globalConfig.getOrSetDefault(globalConfig.getConfig().node("connection", "velocitySecret"), "")); - // Register the void - // Register minecraft:the_void - MinecraftServer.getBiomeManager().addBiome(Biome - .builder() - .name(NamespaceID.from("minecraft:the_void")) - .build() - ); - // Start server int port = Integer.parseInt(globalConfig.getOrSetDefault(globalConfig.getConfig().node("connection", "port"), "25565")); minecraftServer.start("0.0.0.0", port); diff --git a/common/src/main/java/net/endercube/common/config/ConfigFile.java b/common/src/main/java/net/endercube/common/config/ConfigFile.java index 3219e10..e091b44 100644 --- a/common/src/main/java/net/endercube/common/config/ConfigFile.java +++ b/common/src/main/java/net/endercube/common/config/ConfigFile.java @@ -5,6 +5,7 @@ import net.minestom.server.MinecraftServer; import net.minestom.server.coordinate.Pos; import net.minestom.server.coordinate.Vec; +import net.minestom.server.item.ItemComponent; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; import org.jetbrains.annotations.Nullable; @@ -123,8 +124,7 @@ public ItemStack getItemStackFromConfig(ConfigurationNode configNode) { return null; } - return ItemStack.of(material) - .withDisplayName(MiniMessage.miniMessage().deserialize(name)); + return ItemStack.of(material).with(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(name)); } @Nullable diff --git a/common/src/main/java/net/endercube/common/dimensions/FullbrightDimension.java b/common/src/main/java/net/endercube/common/dimensions/FullbrightDimension.java index f1d67ba..0138afa 100644 --- a/common/src/main/java/net/endercube/common/dimensions/FullbrightDimension.java +++ b/common/src/main/java/net/endercube/common/dimensions/FullbrightDimension.java @@ -1,15 +1,18 @@ package net.endercube.common.dimensions; import net.minestom.server.MinecraftServer; +import net.minestom.server.registry.DynamicRegistry; import net.minestom.server.utils.NamespaceID; import net.minestom.server.world.DimensionType; public class FullbrightDimension { - public static final DimensionType INSTANCE = DimensionType.builder(NamespaceID.from("minestom:full_bright")) - .ambientLight(2.0f) - .build(); + + public static final DynamicRegistry.Key INSTANCE; static { - MinecraftServer.getDimensionTypeManager().addDimension(INSTANCE); + INSTANCE = MinecraftServer.getDimensionTypeRegistry().register(DimensionType.builder(NamespaceID.from("dragonescape:full_bright")) + .ambientLight(2.0f) + .build()); } + } diff --git a/common/src/main/java/net/endercube/common/enums/Heads.java b/common/src/main/java/net/endercube/common/enums/Heads.java index f883c42..d5b4ca6 100644 --- a/common/src/main/java/net/endercube/common/enums/Heads.java +++ b/common/src/main/java/net/endercube/common/enums/Heads.java @@ -1,12 +1,12 @@ package net.endercube.common.enums; import net.minestom.server.entity.PlayerSkin; +import net.minestom.server.item.ItemComponent; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; -import net.minestom.server.item.metadata.PlayerHeadMeta; +import net.minestom.server.item.component.HeadProfile; import java.util.Base64; -import java.util.UUID; public enum Heads { QUESTION_MARK("da99b05b9a1db4d29b5e673d77ae54a77eab66818586035c8a2005aeb810602a"); // https://minecraft-heads.com/custom-heads/head/64805 @@ -33,9 +33,6 @@ public String getMcURL() { */ public ItemStack getItemStack() { PlayerSkin playerSkin = new PlayerSkin(Base64.getEncoder().encodeToString(("{textures:{SKIN:{url:\"https://textures.minecraft.net/texture/" + mcURL + "\"}}}").getBytes()), ""); - return ItemStack.of(Material.PLAYER_HEAD).withMeta(PlayerHeadMeta.class, meta -> meta - .skullOwner(UUID.randomUUID()) - .playerSkin(playerSkin) - .build()); + return ItemStack.of(Material.PLAYER_HEAD).with(ItemComponent.PROFILE, new HeadProfile(playerSkin)); } } diff --git a/parkour/src/main/java/net/endercube/parkour/InventoryItems.java b/parkour/src/main/java/net/endercube/parkour/InventoryItems.java index 7dd4157..94d653b 100644 --- a/parkour/src/main/java/net/endercube/parkour/InventoryItems.java +++ b/parkour/src/main/java/net/endercube/parkour/InventoryItems.java @@ -3,58 +3,64 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; +import net.minestom.server.item.ItemComponent; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; import net.minestom.server.tag.Tag; +import java.util.List; + public class InventoryItems { - public static final ItemStack CHECKPOINT_ITEM = ItemStack.builder(Material.ARROW) - .displayName(Component.text("Teleport to current checkpoint")) - .build() + public static final ItemStack CHECKPOINT_ITEM = ItemStack.of(Material.ARROW) + .with(ItemComponent.CUSTOM_NAME, Component.text("Teleport to current checkpoint")) .withTag(Tag.String("action"), "checkpoint"); - public static final ItemStack RESTART_ITEM = ItemStack.builder(Material.BLAZE_POWDER) - .displayName(Component.text("Restart the whole map!")) - .build() + + public static final ItemStack RESTART_ITEM = ItemStack.of(Material.BLAZE_POWDER) + .with(ItemComponent.CUSTOM_NAME, Component.text("Restart the whole map!")) .withTag(Tag.String("action"), "restart"); - public static final ItemStack HUB_ITEM = ItemStack.builder(Material.RED_BED) - .displayName(Component.text("Teleport back to hub")) - .build() + + public static final ItemStack HUB_ITEM = ItemStack.of(Material.RED_BED) + .with(ItemComponent.CUSTOM_NAME, Component.text("Teleport back to hub")) .withTag(Tag.String("action"), "hub"); - public static final ItemStack VISIBILITY_ITEM_VISIBLE = ItemStack.builder(Material.ENDER_EYE) - .displayName(Component.text("Click to hide players")) - .build() + + public static final ItemStack VISIBILITY_ITEM_VISIBLE = ItemStack.of(Material.ENDER_EYE) + .with(ItemComponent.CUSTOM_NAME, Component.text("Click to hide players")) .withTag(Tag.String("action"), "hidePlayers"); - public static final ItemStack VISIBILITY_ITEM_INVISIBLE = ItemStack.builder(Material.ENDER_PEARL) - .displayName(Component.text("Click to show players")) - .build() + + public static final ItemStack VISIBILITY_ITEM_INVISIBLE = ItemStack.of(Material.ENDER_PEARL) + .with(ItemComponent.CUSTOM_NAME, (Component.text("Click to show players"))) .withTag(Tag.String("action"), "showPlayers"); - public static final ItemStack GRIND_MODE_HUB = ItemStack.builder(Material.YELLOW_BED) - .displayName(Component.text("Click to toggle grind mode")) - .lore( - Component.text("→ Go To Hub").color(NamedTextColor.GRAY).decorate(TextDecoration.BOLD), - Component.text(" Open map menu").color(NamedTextColor.GRAY), - Component.text(" Restart map").color(NamedTextColor.GRAY) + + public static final ItemStack GRIND_MODE_HUB = ItemStack.of(Material.YELLOW_BED) + .with(ItemComponent.CUSTOM_NAME, Component.text("Click to toggle grind mode")) + .with(ItemComponent.LORE, + List.of( + Component.text("→ Go To Hub").color(NamedTextColor.GRAY).decorate(TextDecoration.BOLD).asComponent(), + Component.text(" Open map menu").color(NamedTextColor.GRAY).asComponent(), + Component.text(" Restart map").color(NamedTextColor.GRAY).asComponent() + ) ) - .build() .withTag(Tag.String("action"), "set_grindMode_menu"); - public static final ItemStack GRIND_MODE_MENU = ItemStack.builder(Material.PAINTING) - .displayName(Component.text("Click to toggle grind mode")) - .lore( - Component.text(" Go To Hub").color(NamedTextColor.GRAY), - Component.text("→ Open map menu").color(NamedTextColor.GRAY).decorate(TextDecoration.BOLD), - Component.text(" Restart map").color(NamedTextColor.GRAY) + public static final ItemStack GRIND_MODE_MENU = ItemStack.of(Material.PAINTING) + .with(ItemComponent.CUSTOM_NAME, Component.text("Click to toggle grind mode")) + .with(ItemComponent.LORE, + List.of( + Component.text(" Go To Hub").color(NamedTextColor.GRAY), + Component.text("→ Open map menu").color(NamedTextColor.GRAY).decorate(TextDecoration.BOLD), + Component.text(" Restart map").color(NamedTextColor.GRAY) + ) ) - .build() .withTag(Tag.String("action"), "set_grindMode_restart"); - public static final ItemStack GRIND_MODE_RESTART = ItemStack.builder(Material.BLAZE_POWDER) - .displayName(Component.text("Click to toggle grind mode")) - .lore( - Component.text(" Go To Hub").color(NamedTextColor.GRAY), - Component.text(" Open map menu").color(NamedTextColor.GRAY), - Component.text("→ Restart map").color(NamedTextColor.GRAY).decorate(TextDecoration.BOLD) + public static final ItemStack GRIND_MODE_RESTART = ItemStack.of(Material.BLAZE_POWDER) + .with(ItemComponent.CUSTOM_NAME, Component.text("Click to toggle grind mode")) + .with(ItemComponent.LORE, + List.of( + Component.text(" Go To Hub").color(NamedTextColor.GRAY), + Component.text(" Open map menu").color(NamedTextColor.GRAY), + Component.text("→ Restart map").color(NamedTextColor.GRAY).decorate(TextDecoration.BOLD) + ) ) - .build() .withTag(Tag.String("action"), "set_grindMode_hub"); } diff --git a/parkour/src/main/java/net/endercube/parkour/inventories/ParkourMapInventory.java b/parkour/src/main/java/net/endercube/parkour/inventories/ParkourMapInventory.java index 8b47ac1..445383f 100644 --- a/parkour/src/main/java/net/endercube/parkour/inventories/ParkourMapInventory.java +++ b/parkour/src/main/java/net/endercube/parkour/inventories/ParkourMapInventory.java @@ -12,7 +12,9 @@ import net.minestom.server.inventory.InventoryType; import net.minestom.server.inventory.click.ClickType; import net.minestom.server.inventory.condition.InventoryConditionResult; -import net.minestom.server.item.*; +import net.minestom.server.item.ItemComponent; +import net.minestom.server.item.ItemStack; +import net.minestom.server.item.Material; import net.minestom.server.sound.SoundEvent; import net.minestom.server.tag.Tag; import org.jetbrains.annotations.Nullable; @@ -42,19 +44,19 @@ public ParkourMapInventory(boolean hubButton) { // Add the top buttons itemStacks[3] = ItemStack.of(Material.GREEN_CONCRETE) - .withDisplayName( + .with(ItemComponent.CUSTOM_NAME, Component.text("Easy Maps") .color(NamedTextColor.GREEN) ); itemStacks[4] = ItemStack.of(Material.ORANGE_CONCRETE) - .withDisplayName( + .with(ItemComponent.CUSTOM_NAME, Component.text("Medium Maps") .color(NamedTextColor.GREEN) ); itemStacks[5] = ItemStack.of(Material.RED_CONCRETE) - .withDisplayName( + .with(ItemComponent.CUSTOM_NAME, Component.text("Hard Maps") .color(NamedTextColor.GREEN) ); @@ -62,7 +64,7 @@ public ParkourMapInventory(boolean hubButton) { // Add the hub button if it's configured if (hubButton) { itemStacks[44] = ItemStack.of(Material.RED_BED) - .withDisplayName( + .with(ItemComponent.CUSTOM_NAME, Component.text("Back to hub") .color(NamedTextColor.RED) ); @@ -117,11 +119,20 @@ private ItemStack getMapItem(String difficulty, int i) { if (!Objects.equals(mapInstance.getTag(Tag.String("difficulty")), difficulty)) { return; } - pre_maps.add(ItemStack - .of(Objects.requireNonNull(Material.fromNamespaceId(mapInstance.getTag(Tag.String("UI_material"))))) - .withDisplayName(MiniMessage.miniMessage().deserialize(mapInstance.getTag(Tag.String("UI_name")))) - .withTag(Tag.String("map"), mapInstance.getTag(Tag.String("name"))) - .withTag(Tag.Integer("order"), mapInstance.getTag(Tag.Integer("order"))) + String mapName = mapInstance.getTag(Tag.String("name")); + int mapOrder = mapInstance.getTag(Tag.Integer("order")); + + Material UIMaterial = Material.fromNamespaceId(mapInstance.getTag(Tag.String("UI_material"))); + if (UIMaterial == null) { + logger.error("The material for " + mapName + " is incorrect"); + return; + } + + pre_maps.add( + ItemStack.of(UIMaterial) + .with(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(mapInstance.getTag(Tag.String("UI_name")))) + .withTag(Tag.String("map"), mapName) + .withTag(Tag.Integer("order"), mapOrder) ); }); @@ -139,19 +150,14 @@ private ItemStack getMapItem(String difficulty, int i) { private void setGlowing(int slot, boolean state) { if (state) { - inventory.setItemStack(slot, - inventory - .getItemStack(slot) - .withMeta(builder -> builder - .enchantment(Enchantment.KNOCKBACK, (short) 1) - .hideFlag(ItemHideFlag.HIDE_ENCHANTS) - ) + inventory.setItemStack( + slot, + inventory.getItemStack(slot).with(ItemComponent.ENCHANTMENT_GLINT_OVERRIDE, true) ); } else { - inventory.setItemStack(slot, - inventory - .getItemStack(slot) - .withMeta(ItemMeta.Builder::clearEnchantment) + inventory.setItemStack( + slot, + inventory.getItemStack(slot).with(ItemComponent.ENCHANTMENT_GLINT_OVERRIDE, false) ); } diff --git a/spleef/src/main/java/net/endercube/spleef/minigame/inventories/MapVoteInventory.java b/spleef/src/main/java/net/endercube/spleef/minigame/inventories/MapVoteInventory.java index eb5c842..41e15f5 100644 --- a/spleef/src/main/java/net/endercube/spleef/minigame/inventories/MapVoteInventory.java +++ b/spleef/src/main/java/net/endercube/spleef/minigame/inventories/MapVoteInventory.java @@ -6,6 +6,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.minestom.server.inventory.Inventory; import net.minestom.server.inventory.InventoryType; +import net.minestom.server.item.ItemComponent; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; @@ -20,18 +21,18 @@ public MapVoteInventory() { InventoryView maps = mainView.forkRange(0, size - 9); InventoryView actions = mainView.forkRange(size - 9, size); - mainView.fill(inventory, slot -> ItemStack.of(Material.BLACK_STAINED_GLASS_PANE).withDisplayName(Component.empty())); + mainView.fill(inventory, slot -> ItemStack.of(Material.BLACK_STAINED_GLASS_PANE).with(ItemComponent.CUSTOM_NAME, Component.empty())); maps.fill(inventory, slot -> ItemStack.of(Material.MAP)); // just for mockup // Init action bar actions.set(inventory, 0, - ItemStack.of(Material.SEA_PICKLE).withDisplayName(Component.text("Pick all").color(NamedTextColor.GREEN)) + ItemStack.of(Material.SEA_PICKLE).with(ItemComponent.CUSTOM_NAME, Component.text("Pick all").color(NamedTextColor.GREEN)) ); actions.set(inventory, 4, - ItemStack.of(Material.BARRIER).withDisplayName(Component.text("Close").color(NamedTextColor.RED)) + ItemStack.of(Material.BARRIER).with(ItemComponent.CUSTOM_NAME, Component.text("Close").color(NamedTextColor.RED)) ); actions.set(inventory, 8, - Heads.QUESTION_MARK.getItemStack().withDisplayName(Component.text("Help!").color(NamedTextColor.GREEN)) + Heads.QUESTION_MARK.getItemStack().with(ItemComponent.CUSTOM_NAME, Component.text("Help!").color(NamedTextColor.GREEN)) ); this.inventory = inventory;