Update master #3

Zusammengeführt
YoyoNow hat 7 Commits von Mirrors/AxiomPaperPlugin:master nach master 2023-09-22 17:32:24 +02:00 zusammengeführt
4 geänderte Dateien mit 72 neuen und 7 gelöschten Zeilen
Nur Änderungen aus Commit 8b107c3a9a werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -11,6 +11,7 @@ import com.moulberry.axiom.world_properties.server.ServerWorldProperty;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.papermc.paper.event.player.PlayerFailMoveEvent; import io.papermc.paper.event.player.PlayerFailMoveEvent;
import io.papermc.paper.event.world.WorldGameRuleChangeEvent;
import io.papermc.paper.network.ChannelInitializeListener; import io.papermc.paper.network.ChannelInitializeListener;
import io.papermc.paper.network.ChannelInitializeListenerHolder; import io.papermc.paper.network.ChannelInitializeListenerHolder;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
@ -21,6 +22,7 @@ import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow; import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.GameRules;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -163,8 +165,21 @@ public class AxiomPaper extends JavaPlugin implements Listener {
}, 20); // Why does this need to be delayed? }, 20); // Why does this need to be delayed?
} }
@EventHandler
public void onGameRuleChanged(WorldGameRuleChangeEvent event) {
if (event.getGameRule() == GameRule.DO_WEATHER_CYCLE) {
ServerWorldPropertiesRegistry properties = getWorldProperties(event.getWorld());
if (properties != null) {
ServerWorldProperty<?> property = properties.getById(new ResourceLocation("axiom:pause_weather"));
if (property != null) {
((ServerWorldProperty<Boolean>)property).setValue(event.getWorld(), Boolean.valueOf(event.getValue()));
}
}
}
}
private ServerWorldPropertiesRegistry createWorldProperties(World world) { private ServerWorldPropertiesRegistry createWorldProperties(World world) {
ServerWorldPropertiesRegistry registry = new ServerWorldPropertiesRegistry(); ServerWorldPropertiesRegistry registry = new ServerWorldPropertiesRegistry(world);
AxiomCreateWorldPropertiesEvent createEvent = new AxiomCreateWorldPropertiesEvent(world, registry); AxiomCreateWorldPropertiesEvent createEvent = new AxiomCreateWorldPropertiesEvent(world, registry);
Bukkit.getPluginManager().callEvent(createEvent); Bukkit.getPluginManager().callEvent(createEvent);

Datei anzeigen

@ -4,6 +4,8 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Unit; import net.minecraft.util.Unit;
import java.util.List;
public interface WorldPropertyWidgetType<T> { public interface WorldPropertyWidgetType<T> {
WorldPropertyDataType<T> dataType(); WorldPropertyDataType<T> dataType();
@ -72,4 +74,17 @@ public interface WorldPropertyWidgetType<T> {
} }
}; };
record ButtonArray(List<String> otherButtons) implements WorldPropertyWidgetType<Integer> {
@Override
public WorldPropertyDataType<Integer> dataType() {
return WorldPropertyDataType.INTEGER;
}
@Override
public void write(FriendlyByteBuf friendlyByteBuf) {
friendlyByteBuf.writeVarInt(5);
friendlyByteBuf.writeCollection(this.otherButtons, FriendlyByteBuf::writeUtf);
}
}
} }

Datei anzeigen

@ -6,6 +6,9 @@ import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.GameRules;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -19,8 +22,8 @@ public class ServerWorldPropertiesRegistry {
private final LinkedHashMap<WorldPropertyCategory, List<ServerWorldProperty<?>>> propertyList = new LinkedHashMap<>(); private final LinkedHashMap<WorldPropertyCategory, List<ServerWorldProperty<?>>> propertyList = new LinkedHashMap<>();
private final Map<ResourceLocation, ServerWorldProperty<?>> propertyMap = new HashMap<>(); private final Map<ResourceLocation, ServerWorldProperty<?>> propertyMap = new HashMap<>();
public ServerWorldPropertiesRegistry() { public ServerWorldPropertiesRegistry(World world) {
this.registerDefault(); this.registerDefault(world);
} }
public ServerWorldProperty<?> getById(ResourceLocation resourceLocation) { public ServerWorldProperty<?> getById(ResourceLocation resourceLocation) {
@ -53,7 +56,10 @@ public class ServerWorldPropertiesRegistry {
buf.accessByteBufWithCorrectSize()); buf.accessByteBufWithCorrectSize());
} }
public void registerDefault() { public void registerDefault(World world) {
ServerLevel serverLevel = ((CraftWorld)world).getHandle();
GameRules gameRules = serverLevel.getGameRules();
// Time // Time
WorldPropertyCategory timeCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.time", true); WorldPropertyCategory timeCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.time", true);
@ -63,6 +69,34 @@ public class ServerWorldPropertiesRegistry {
); );
this.addCategory(timeCategory, List.of(time)); this.addCategory(timeCategory, List.of(time));
// Weather
WorldPropertyCategory weatherCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.weather",
true);
ServerWorldProperty<Boolean> 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);
return false;
});
ServerWorldProperty<Integer> weatherType = new ServerWorldProperty<>(new ResourceLocation("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")
), 0, index -> {
if (index == 0) {
serverLevel.setWeatherParameters(ServerLevel.RAIN_DELAY.sample(serverLevel.random), 0, false, false);
} else if (index == 1) {
serverLevel.setWeatherParameters(0, ServerLevel.RAIN_DURATION.sample(serverLevel.random), true, false);
} else if (index == 2) {
serverLevel.setWeatherParameters(0, ServerLevel.THUNDER_DURATION.sample(serverLevel.random), true, true);
}
return false;
});
this.addCategory(weatherCategory, List.of(pauseWeather, weatherType));
} }
} }

Datei anzeigen

@ -1,7 +1,6 @@
package com.moulberry.axiom.world_properties.server; package com.moulberry.axiom.world_properties.server;
import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.world_properties.WorldPropertyCategory;
import com.moulberry.axiom.world_properties.WorldPropertyDataType; import com.moulberry.axiom.world_properties.WorldPropertyDataType;
import com.moulberry.axiom.world_properties.WorldPropertyWidgetType; import com.moulberry.axiom.world_properties.WorldPropertyWidgetType;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -51,8 +50,10 @@ public class ServerWorldProperty<T> {
} }
public void setValue(World world, T value) { public void setValue(World world, T value) {
this.value = value; if (!value.equals(this.value)) {
this.sync(world); this.value = value;
this.sync(world);
}
} }
public void sync(World world) { public void sync(World world) {