From 1cead965658b106bfb59f1d3b00d097a1c942a62 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Thu, 21 Sep 2023 18:44:07 +0800 Subject: [PATCH] Weather world properties --- src/main/java/com/moulberry/axiom/AxiomPaper.java | 2 +- .../server/ServerWorldPropertiesRegistry.java | 6 +++--- .../axiom/world_properties/server/ServerWorldProperty.java | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index 8cf5dd2..5692863 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -172,7 +172,7 @@ public class AxiomPaper extends JavaPlugin implements Listener { if (properties != null) { ServerWorldProperty property = properties.getById(new ResourceLocation("axiom:pause_weather")); if (property != null) { - ((ServerWorldProperty)property).setValue(event.getWorld(), Boolean.valueOf(event.getValue())); + ((ServerWorldProperty)property).setValue(event.getWorld(), !Boolean.parseBoolean(event.getValue())); } } } 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 3044d9a..91414d2 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 @@ -7,6 +7,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.GameRules; +import org.bukkit.GameRule; import org.bukkit.World; import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; import org.bukkit.entity.Player; @@ -58,7 +59,6 @@ public class ServerWorldPropertiesRegistry { public void registerDefault(World world) { ServerLevel serverLevel = ((CraftWorld)world).getHandle(); - GameRules gameRules = serverLevel.getGameRules(); // Time WorldPropertyCategory timeCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.time", true); @@ -76,8 +76,8 @@ public class ServerWorldPropertiesRegistry { ServerWorldProperty pauseWeather = new ServerWorldProperty<>(new ResourceLocation("axiom:pause_weather"), "axiom.editorui.window.world_properties.pause_weather", - true, WorldPropertyWidgetType.CHECKBOX, !gameRules.getRule(GameRules.RULE_WEATHER_CYCLE).get(), bool -> { - gameRules.getRule(GameRules.RULE_WEATHER_CYCLE).set(!bool, serverLevel); + true, WorldPropertyWidgetType.CHECKBOX, !world.getGameRuleValue(GameRule.DO_WEATHER_CYCLE), bool -> { + world.setGameRule(GameRule.DO_WEATHER_CYCLE, !bool); return false; }); 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 9027af9..5f861f7 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 @@ -50,10 +50,8 @@ public class ServerWorldProperty { } public void setValue(World world, T value) { - if (!value.equals(this.value)) { - this.value = value; - this.sync(world); - } + this.value = value; + this.sync(world); } public void sync(World world) {