From c58ddcfc37971178087d7637979a2c17e9a44d09 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 26 Oct 2024 09:53:12 +0100 Subject: [PATCH] Update to MC 1.21.3 --- spark-fabric/build.gradle | 6 +- spark-forge/build.gradle | 4 +- .../spark/forge/ForgeClientCommandSender.java | 71 +++++++++++++++++++ ...der.java => ForgeServerCommandSender.java} | 47 ++++++------ .../spark/forge/ForgeWorldInfoProvider.java | 41 +++-------- .../forge/plugin/ForgeClientSparkPlugin.java | 17 ++--- .../forge/plugin/ForgeServerSparkPlugin.java | 24 +++---- .../spark/forge/plugin/ForgeSparkPlugin.java | 3 - spark-neoforge/build.gradle | 2 +- 9 files changed, 130 insertions(+), 85 deletions(-) create mode 100644 spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientCommandSender.java rename spark-forge/src/main/java/me/lucko/spark/forge/{ForgeCommandSender.java => ForgeServerCommandSender.java} (62%) diff --git a/spark-fabric/build.gradle b/spark-fabric/build.gradle index c38f4498..d2905cd5 100644 --- a/spark-fabric/build.gradle +++ b/spark-fabric/build.gradle @@ -28,8 +28,8 @@ configurations { dependencies { // https://modmuss50.me/fabric.html - minecraft 'com.mojang:minecraft:1.21.2' - mappings 'net.fabricmc:yarn:1.21.2+build.1:v2' + minecraft 'com.mojang:minecraft:1.21.3' + mappings 'net.fabricmc:yarn:1.21.3+build.2:v2' modImplementation 'net.fabricmc:fabric-loader:0.16.7' Set apiModules = [ @@ -40,7 +40,7 @@ dependencies { // Add each module as a dependency apiModules.forEach { - modImplementation(fabricApi.module(it, '0.106.1+1.21.2')) + modImplementation(fabricApi.module(it, '0.106.1+1.21.3')) } include(modImplementation('me.lucko:fabric-permissions-api:0.3.2')) diff --git a/spark-forge/build.gradle b/spark-forge/build.gradle index 948090f4..eaf3edce 100644 --- a/spark-forge/build.gradle +++ b/spark-forge/build.gradle @@ -9,7 +9,7 @@ tasks.withType(JavaCompile) { } minecraft { - mappings channel: 'official', version: '1.21.1' + mappings channel: 'official', version: '1.21.3' accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') reobf = false } @@ -20,7 +20,7 @@ configurations { } dependencies { - minecraft 'net.minecraftforge:forge:1.21.1-52.0.2' + minecraft 'net.minecraftforge:forge:1.21.3-53.0.0' shade project(':spark-common') } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientCommandSender.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientCommandSender.java new file mode 100644 index 00000000..5416370a --- /dev/null +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientCommandSender.java @@ -0,0 +1,71 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package me.lucko.spark.forge; + +import me.lucko.spark.common.command.sender.AbstractCommandSender; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.RegistryAccess; +import net.minecraft.network.chat.Component.Serializer; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.entity.Entity; + +import java.util.Objects; +import java.util.UUID; + +public class ForgeClientCommandSender extends AbstractCommandSender { + public ForgeClientCommandSender(CommandSourceStack source) { + super(source); + } + + @Override + public String getName() { + return this.delegate.getTextName(); + } + + @Override + public UUID getUniqueId() { + Entity entity = this.delegate.getEntity(); + if (entity instanceof LocalPlayer player) { + return player.getUUID(); + } + return null; + } + + @Override + public void sendMessage(Component message) { + MutableComponent component = Serializer.fromJson(GsonComponentSerializer.gson().serializeToTree(message), RegistryAccess.EMPTY); + Objects.requireNonNull(component, "component"); + super.delegate.sendSystemMessage(component); + } + + @Override + public boolean hasPermission(String permission) { + return true; + } + + @Override + protected Object getObjectForComparison() { + return this.delegate.getEntity(); + } +} diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerCommandSender.java similarity index 62% rename from spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java rename to spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerCommandSender.java index 0e65657b..6951d9ae 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerCommandSender.java @@ -21,47 +21,39 @@ package me.lucko.spark.forge; import me.lucko.spark.common.command.sender.AbstractCommandSender; -import me.lucko.spark.forge.plugin.ForgeSparkPlugin; +import me.lucko.spark.forge.plugin.ForgeServerSparkPlugin; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.RegistryAccess; import net.minecraft.network.chat.Component.Serializer; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.rcon.RconConsoleSource; -import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.Entity; import java.util.Objects; import java.util.UUID; -public class ForgeCommandSender extends AbstractCommandSender { - private final ForgeSparkPlugin plugin; +public class ForgeServerCommandSender extends AbstractCommandSender { + private final ForgeServerSparkPlugin plugin; - public ForgeCommandSender(CommandSource source, ForgeSparkPlugin plugin) { - super(source); + public ForgeServerCommandSender(CommandSourceStack commandSource, ForgeServerSparkPlugin plugin) { + super(commandSource); this.plugin = plugin; } @Override public String getName() { - if (super.delegate instanceof Player) { - return ((Player) super.delegate).getGameProfile().getName(); - } else if (super.delegate instanceof MinecraftServer) { + String name = this.delegate.getTextName(); + if (this.delegate.getEntity() != null && name.equals("Server")) { return "Console"; - } else if (super.delegate instanceof RconConsoleSource) { - return "RCON Console"; - } else { - return "unknown:" + super.delegate.getClass().getSimpleName(); } + return name; } @Override public UUID getUniqueId() { - if (super.delegate instanceof Player) { - return ((Player) super.delegate).getUUID(); - } - return null; + Entity entity = this.delegate.getEntity(); + return entity != null ? entity.getUUID() : null; } @Override @@ -73,6 +65,19 @@ public void sendMessage(Component message) { @Override public boolean hasPermission(String permission) { - return this.plugin.hasPermission(super.delegate, permission); + return this.plugin.hasPermission(this.delegate, permission); + } + + @Override + protected Object getObjectForComparison() { + UUID uniqueId = getUniqueId(); + if (uniqueId != null) { + return uniqueId; + } + Entity entity = this.delegate.getEntity(); + if (entity != null) { + return entity; + } + return getName(); } } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeWorldInfoProvider.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeWorldInfoProvider.java index b31b825e..61bea72f 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeWorldInfoProvider.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeWorldInfoProvider.java @@ -120,20 +120,19 @@ public GameRulesResult pollGameRules() { GameRulesResult data = new GameRulesResult(); Iterable levels = this.server.getAllLevels(); - GameRules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor() { - @Override - public > void visit(GameRules.Key key, GameRules.Type type) { - String defaultValue = type.createRule().serialize(); - data.putDefault(key.getId(), defaultValue); + for (ServerLevel level : levels) { + level.getGameRules().visitGameRuleTypes(new GameRules.GameRuleTypeVisitor() { + @Override + public > void visit(GameRules.Key key, GameRules.Type type) { + String defaultValue = type.createRule().serialize(); + data.putDefault(key.getId(), defaultValue); - for (ServerLevel level : levels) { String levelName = level.dimension().location().getPath(); - String value = level.getGameRules().getRule(key).serialize(); data.put(key.getId(), levelName, value); } - } - }); + }); + } return data; } @@ -190,28 +189,8 @@ public ChunksResult pollChunks() { @Override public GameRulesResult pollGameRules() { - ClientLevel level = this.client.level; - if (level == null) { - return null; - } - - GameRulesResult data = new GameRulesResult(); - - String levelName = level.dimension().location().getPath(); - GameRules levelRules = level.getGameRules(); - - GameRules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor() { - @Override - public > void visit(GameRules.Key key, GameRules.Type type) { - String defaultValue = type.createRule().serialize(); - data.putDefault(key.getId(), defaultValue); - - String value = levelRules.getRule(key).serialize(); - data.put(key.getId(), levelName, value); - } - }); - - return data; + // Not available on client since 24w39a + return null; } @Override diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java index 86915a41..607dbe13 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java @@ -31,15 +31,15 @@ import me.lucko.spark.common.sampler.ThreadDumper; import me.lucko.spark.common.tick.TickHook; import me.lucko.spark.common.tick.TickReporter; -import me.lucko.spark.forge.ForgeCommandSender; +import me.lucko.spark.forge.ForgeClientCommandSender; import me.lucko.spark.forge.ForgePlatformInfo; import me.lucko.spark.forge.ForgeSparkMod; import me.lucko.spark.forge.ForgeTickHook; import me.lucko.spark.forge.ForgeTickReporter; import me.lucko.spark.forge.ForgeWorldInfoProvider; import net.minecraft.client.Minecraft; -import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSourceStack; +import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.RegisterClientCommandsEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; @@ -85,7 +85,7 @@ public int run(CommandContext context) throws CommandSyntaxE return 0; } - this.platform.executeCommand(new ForgeCommandSender(context.getSource().getEntity(), this), args); + this.platform.executeCommand(new ForgeClientCommandSender(context.getSource()), args); return Command.SINGLE_SUCCESS; } @@ -96,17 +96,12 @@ public CompletableFuture getSuggestions(CommandContext getCommandSenders() { - return Stream.of(new ForgeCommandSender(this.minecraft.player, this)); + public Stream getCommandSenders() { + return Stream.of(new ForgeClientCommandSender(ClientCommandHandler.getSource())); } @Override diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java index 4af45d92..368ae60b 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java @@ -35,15 +35,14 @@ import me.lucko.spark.common.sampler.ThreadDumper; import me.lucko.spark.common.tick.TickHook; import me.lucko.spark.common.tick.TickReporter; -import me.lucko.spark.forge.ForgeCommandSender; import me.lucko.spark.forge.ForgePlatformInfo; import me.lucko.spark.forge.ForgePlayerPingProvider; +import me.lucko.spark.forge.ForgeServerCommandSender; import me.lucko.spark.forge.ForgeServerConfigProvider; import me.lucko.spark.forge.ForgeSparkMod; import me.lucko.spark.forge.ForgeTickHook; import me.lucko.spark.forge.ForgeTickReporter; import me.lucko.spark.forge.ForgeWorldInfoProvider; -import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; @@ -173,8 +172,7 @@ public int run(CommandContext context) throws CommandSyntaxE return 0; } - CommandSource source = context.getSource().getEntity() != null ? context.getSource().getEntity() : context.getSource().getServer(); - this.platform.executeCommand(new ForgeCommandSender(source, this), args); + this.platform.executeCommand(new ForgeServerCommandSender(context.getSource(), this), args); return Command.SINGLE_SUCCESS; } @@ -185,12 +183,12 @@ public CompletableFuture getSuggestions(CommandContext getCommandSenders() { + public Stream getCommandSenders() { return Stream.concat( - this.server.getPlayerList().getPlayers().stream(), - Stream.of(this.server) - ).map(sender -> new ForgeCommandSender(sender, this)); + this.server.getPlayerList().getPlayers().stream().map(ServerPlayer::createCommandSourceStack), + Stream.of(this.server.createCommandSourceStack()) + ).map(stack -> new ForgeServerCommandSender(stack, this)); } @Override diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java index 5c0761dc..28773269 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java @@ -38,7 +38,6 @@ import me.lucko.spark.common.util.SparkThreadFactory; import me.lucko.spark.forge.ForgeClassSourceLookup; import me.lucko.spark.forge.ForgeSparkMod; -import net.minecraft.commands.CommandSource; import net.minecraftforge.fml.ModList; import net.minecraftforge.forgespi.language.IModInfo; import org.apache.logging.log4j.LogManager; @@ -76,8 +75,6 @@ public void disable() { this.scheduler.shutdown(); } - public abstract boolean hasPermission(CommandSource sender, String permission); - @Override public String getVersion() { return this.mod.getVersion(); diff --git a/spark-neoforge/build.gradle b/spark-neoforge/build.gradle index a2a246c1..2e57e71f 100644 --- a/spark-neoforge/build.gradle +++ b/spark-neoforge/build.gradle @@ -15,7 +15,7 @@ java { } neoForge { - version = "21.2.0-beta" + version = "21.3.3-beta" validateAccessTransformers = true runs {