From 8c6fd853aba54277ff6f7422f88d6c1a1c94a42b Mon Sep 17 00:00:00 2001 From: Moulberry Date: Thu, 16 Nov 2023 17:36:13 +0800 Subject: [PATCH] WorldProperties: Use NamespacedKey instead of ResourceLocation --- .../java/com/moulberry/axiom/WorldPropertiesExample.java | 9 +++++---- .../server/ServerWorldPropertiesRegistry.java | 7 ++++--- .../world_properties/server/ServerWorldProperty.java | 8 +++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/WorldPropertiesExample.java b/src/main/java/com/moulberry/axiom/WorldPropertiesExample.java index a9f5444..e1a8b72 100644 --- a/src/main/java/com/moulberry/axiom/WorldPropertiesExample.java +++ b/src/main/java/com/moulberry/axiom/WorldPropertiesExample.java @@ -7,6 +7,7 @@ import com.moulberry.axiom.world_properties.server.ServerWorldProperty; import net.kyori.adventure.text.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Unit; +import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -21,28 +22,28 @@ public class WorldPropertiesExample implements Listener { World world = event.getWorld(); - ServerWorldProperty checkbox = new ServerWorldProperty<>(new ResourceLocation("axiom:checkbox"), + ServerWorldProperty checkbox = new ServerWorldProperty<>(new NamespacedKey("axiom", "checkbox"), "Checkbox", false, WorldPropertyWidgetType.CHECKBOX, false, bool -> { world.sendMessage(Component.text("Checkbox: " + bool)); // Do something with input return true; // true to sync with client }); - ServerWorldProperty slider = new ServerWorldProperty<>(new ResourceLocation("axiom:slider"), + ServerWorldProperty slider = new ServerWorldProperty<>(new NamespacedKey("axiom", "slider"), "Slider", false, new WorldPropertyWidgetType.Slider(0, 8), 4, integer -> { world.sendMessage(Component.text("Slider: " + integer)); // Do something with input return true; // true to sync with client }); - ServerWorldProperty textbox = new ServerWorldProperty<>(new ResourceLocation("axiom:textbox"), + ServerWorldProperty textbox = new ServerWorldProperty<>(new NamespacedKey("axiom", "textbox"), "Textbox", false, WorldPropertyWidgetType.TEXTBOX, "Hello", string -> { world.sendMessage(Component.text("Textbox: " + string)); // Do something with input return true; // true to sync with client }); - ServerWorldProperty button = new ServerWorldProperty<>(new ResourceLocation("axiom:button"), + ServerWorldProperty button = new ServerWorldProperty<>(new NamespacedKey("axiom", "button"), "Button", false, WorldPropertyWidgetType.BUTTON, Unit.INSTANCE, unit -> { world.sendMessage(Component.text("Button pressed")); // Do something with input diff --git a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java index 774b549..cb15a52 100644 --- a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java +++ b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.GameRules; import org.bukkit.GameRule; +import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; import org.bukkit.entity.Player; @@ -64,7 +65,7 @@ public class ServerWorldPropertiesRegistry { // Time WorldPropertyCategory timeCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.time", true); - ServerWorldProperty time = new ServerWorldProperty<>(new ResourceLocation("axiom:time"), + ServerWorldProperty time = new ServerWorldProperty<>(new NamespacedKey("axiom", "time"), "axiom.editorui.window.world_properties.time", true, WorldPropertyWidgetType.TIME, 0, integer -> false ); @@ -75,14 +76,14 @@ public class ServerWorldPropertiesRegistry { WorldPropertyCategory weatherCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.weather", true); - ServerWorldProperty pauseWeather = new ServerWorldProperty<>(new ResourceLocation("axiom:pause_weather"), + ServerWorldProperty pauseWeather = new ServerWorldProperty<>(new NamespacedKey("axiom", "pause_weather"), "axiom.editorui.window.world_properties.pause_weather", true, WorldPropertyWidgetType.CHECKBOX, !world.getGameRuleValue(GameRule.DO_WEATHER_CYCLE), bool -> { world.setGameRule(GameRule.DO_WEATHER_CYCLE, !bool); return false; }); - ServerWorldProperty weatherType = new ServerWorldProperty<>(new ResourceLocation("axiom:weather_type"), + ServerWorldProperty weatherType = new ServerWorldProperty<>(new NamespacedKey("axiom", "weather_type"), "axiom.editorui.window.world_properties.clear_weather", true, new WorldPropertyWidgetType.ButtonArray( List.of("axiom.editorui.window.world_properties.rain_weather", "axiom.editorui.window.world_properties.thunder_weather") diff --git a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldProperty.java b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldProperty.java index e5c8d5b..0d44f90 100644 --- a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldProperty.java +++ b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldProperty.java @@ -6,7 +6,9 @@ import com.moulberry.axiom.world_properties.WorldPropertyWidgetType; import io.netty.buffer.Unpooled; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import org.bukkit.NamespacedKey; import org.bukkit.World; +import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey; import org.bukkit.entity.Player; import java.util.function.Predicate; @@ -20,9 +22,9 @@ public class ServerWorldProperty { private T value; private Predicate handler; - public ServerWorldProperty(ResourceLocation id, String name, boolean localizeName, WorldPropertyWidgetType widget, - T value, Predicate handler) { - this.id = id; + public ServerWorldProperty(NamespacedKey id, String name, boolean localizeName, WorldPropertyWidgetType widget, + T value, Predicate handler) { + this.id = CraftNamespacedKey.toMinecraft(id); this.name = name; this.localizeName = localizeName; this.widget = widget;