From 5c1ea5633ed5986c02d3fa1ccf187638d143c091 Mon Sep 17 00:00:00 2001 From: bloodmc Date: Wed, 8 May 2024 18:09:02 -0400 Subject: [PATCH] Update Forge to MC 1.20.6 (#3883) --- forge/build.gradle | 8 ++---- forge/forge-api/build.gradle | 4 +-- forge/gradle.properties | 4 +-- forge/loader/build.gradle | 8 ++---- .../luckperms/forge/ForgeSenderFactory.java | 3 ++- .../capabilities/UserCapabilityImpl.java | 16 +++++------ .../listeners/ForgeConnectionListener.java | 6 +++-- .../messaging/PluginMessageMessenger.java | 8 ++---- .../forge/util/BrigadierInjector.java | 27 ++++++++++++++----- gradle/libs.versions.toml | 4 +-- 10 files changed, 45 insertions(+), 43 deletions(-) diff --git a/forge/build.gradle b/forge/build.gradle index b5d9f80e0..46232d242 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -4,8 +4,8 @@ plugins { alias(libs.plugins.forgegradle) } -sourceCompatibility = 1.8 -targetCompatibility = 17 +sourceCompatibility = 17 +targetCompatibility = 21 blossom { replaceTokenIn 'src/main/java/me/lucko/luckperms/forge/LPForgeBootstrap.java' @@ -23,10 +23,6 @@ dependencies { compileOnly project(':forge:forge-api') } -reobf { - shadowJar {} -} - shadowJar { archiveFileName = "luckperms-forge.jarinjar" diff --git a/forge/forge-api/build.gradle b/forge/forge-api/build.gradle index cf210c2ea..603d1f678 100644 --- a/forge/forge-api/build.gradle +++ b/forge/forge-api/build.gradle @@ -2,8 +2,8 @@ plugins { alias(libs.plugins.forgegradle) } -sourceCompatibility = 1.8 -targetCompatibility = 17 +sourceCompatibility = 17 +targetCompatibility = 21 minecraft { mappings channel: 'official', version: minecraftVersion diff --git a/forge/gradle.properties b/forge/gradle.properties index dda64880a..2cf5a8eaa 100644 --- a/forge/gradle.properties +++ b/forge/gradle.properties @@ -1,2 +1,2 @@ -minecraftVersion=1.20.4 -forgeVersion=49.0.3 \ No newline at end of file +minecraftVersion=1.20.6 +forgeVersion=50.0.9 \ No newline at end of file diff --git a/forge/loader/build.gradle b/forge/loader/build.gradle index 1b6f0040d..31dc998df 100644 --- a/forge/loader/build.gradle +++ b/forge/loader/build.gradle @@ -4,8 +4,8 @@ plugins { id("java-library") } -sourceCompatibility = 1.8 -targetCompatibility = 17 +sourceCompatibility = 17 +targetCompatibility = 21 minecraft { mappings channel: 'official', version: minecraftVersion @@ -43,10 +43,6 @@ processResources { } } -reobf { - shadowJar {} -} - shadowJar { archiveFileName = "LuckPerms-Forge-${project.ext.fullVersion}.jar" diff --git a/forge/src/main/java/me/lucko/luckperms/forge/ForgeSenderFactory.java b/forge/src/main/java/me/lucko/luckperms/forge/ForgeSenderFactory.java index 77d20ebf1..5b2c31f4e 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/ForgeSenderFactory.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/ForgeSenderFactory.java @@ -40,6 +40,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.luckperms.api.util.Tristate; 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.server.level.ServerPlayer; import net.minecraft.server.rcon.RconConsoleSource; @@ -117,7 +118,7 @@ public class ForgeSenderFactory extends SenderFactory getCapability(Player player) { - if (!player.isRemoved()) { - return player.getCapability(CAPABILITY); - } else { - player.reviveCaps(); - try { - return player.getCapability(CAPABILITY); - } finally { - player.invalidateCaps(); - } + LazyOptional optional = player.getCapability(CAPABILITY); + if (optional.isPresent()) { + return optional; } + + // if capability is missing, try to restore them before trying again + player.reviveCaps(); + return player.getCapability(CAPABILITY); } /** diff --git a/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java b/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java index 40f3ed731..95e9bd0d7 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java @@ -43,6 +43,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ConfigurationTask; import net.minecraft.server.network.ServerConfigurationPacketListenerImpl; import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.event.network.GatherLoginConfigurationTasksEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -115,7 +116,7 @@ public class ForgeConnectionListener extends AbstractConnectionListener { } @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onPlayerLoadFromFile(PlayerEvent.LoadFromFile event) { + public void onPlayerLoggedIn(PlayerLoggedInEvent event) { ServerPlayer player = (ServerPlayer) event.getEntity(); GameProfile profile = player.getGameProfile(); @@ -137,6 +138,7 @@ public class ForgeConnectionListener extends AbstractConnectionListener { Component component = TranslationManager.render(Message.LOADING_STATE_ERROR.build(), player.getLanguage()); if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) { player.connection.disconnect(ForgeSenderFactory.toNativeText(component)); + return; } else { player.sendSystemMessage(ForgeSenderFactory.toNativeText(component)); } @@ -154,4 +156,4 @@ public class ForgeConnectionListener extends AbstractConnectionListener { handleDisconnect(player.getGameProfile().getId()); } -} +} \ No newline at end of file diff --git a/forge/src/main/java/me/lucko/luckperms/forge/messaging/PluginMessageMessenger.java b/forge/src/main/java/me/lucko/luckperms/forge/messaging/PluginMessageMessenger.java index a5f285aba..604865019 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/messaging/PluginMessageMessenger.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/messaging/PluginMessageMessenger.java @@ -33,15 +33,13 @@ import me.lucko.luckperms.forge.LPForgePlugin; import net.luckperms.api.messenger.IncomingMessageConsumer; import net.luckperms.api.messenger.Messenger; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.players.PlayerList; import net.minecraftforge.network.ChannelBuilder; import net.minecraftforge.network.EventNetworkChannel; -import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.PacketDistributor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -84,10 +82,8 @@ public class PluginMessageMessenger extends AbstractPluginMessageMessenger imple FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); byteBuf.writeBytes(buf); - byteBuf.writeResourceLocation(CHANNEL); - Packet packet = new ClientboundCustomPayloadPacket(byteBuf); - player.connection.send(packet); + this.channel.send(byteBuf, PacketDistributor.PLAYER.with(player)); SchedulerTask t = taskRef.getAndSet(null); if (t != null) { diff --git a/forge/src/main/java/me/lucko/luckperms/forge/util/BrigadierInjector.java b/forge/src/main/java/me/lucko/luckperms/forge/util/BrigadierInjector.java index 61c74c5f1..365e6fbbe 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/util/BrigadierInjector.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/util/BrigadierInjector.java @@ -30,7 +30,8 @@ import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; import me.lucko.luckperms.common.graph.Graph; import me.lucko.luckperms.common.graph.TraversalAlgorithm; -import me.lucko.luckperms.common.plugin.LuckPermsPlugin; +import me.lucko.luckperms.common.model.User; +import me.lucko.luckperms.forge.LPForgePlugin; import me.lucko.luckperms.forge.capabilities.UserCapability; import me.lucko.luckperms.forge.capabilities.UserCapabilityImpl; import net.luckperms.api.util.Tristate; @@ -68,7 +69,7 @@ public final class BrigadierInjector { * @param plugin the plugin * @param dispatcher the command dispatcher */ - public static void inject(LuckPermsPlugin plugin, CommandDispatcher dispatcher) { + public static void inject(LPForgePlugin plugin, CommandDispatcher dispatcher) { Iterable tree = CommandNodeGraph.INSTANCE.traverse( TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, new CommandNodeWithParent(null, dispatcher.getRoot()) @@ -89,7 +90,7 @@ public final class BrigadierInjector { plugin.getPermissionRegistry().insert(permission); - InjectedPermissionRequirement newRequirement = new InjectedPermissionRequirement(permission, requirement); + InjectedPermissionRequirement newRequirement = new InjectedPermissionRequirement(plugin, permission, requirement); try { REQUIREMENT_FIELD.set(node.node, newRequirement); } catch (IllegalAccessException e) { @@ -127,10 +128,12 @@ public final class BrigadierInjector { * delegating to the existing requirement. */ private static final class InjectedPermissionRequirement implements Predicate { + private final LPForgePlugin plugin; private final String permission; private final Predicate delegate; - private InjectedPermissionRequirement(String permission, Predicate delegate) { + private InjectedPermissionRequirement(LPForgePlugin plugin, String permission, Predicate delegate) { + this.plugin = plugin; this.permission = permission; this.delegate = delegate; } @@ -139,9 +142,19 @@ public final class BrigadierInjector { public boolean test(CommandSourceStack source) { if (source.getEntity() instanceof ServerPlayer) { ServerPlayer player = (ServerPlayer) source.getEntity(); - - UserCapability user = UserCapabilityImpl.get(player); - Tristate state = user.checkPermission(this.permission); + Tristate state = Tristate.UNDEFINED; + // If player is still connecting and has not been added to world then check LP user directly + if (!player.isAddedToWorld()) { + User user = this.plugin.getUserManager().getIfLoaded(player.getUUID()); + if (user == null) { + // Should never happen but just in case... + return false; + } + state = user.getCachedData().getPermissionData().checkPermission(permission); + } else { + UserCapability user = UserCapabilityImpl.get(player); + state = user.checkPermission(this.permission); + } if (state != Tristate.UNDEFINED) { return state.asBoolean() && this.delegate.test(source.withPermission(4)); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 968e3cd3b..0d28dee09 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -shadow = "8.1.1" +shadow = "8.1.7" blossom = "1.3.1" forgegradle = "[6.0,6.2)" loom = "1.6-SNAPSHOT" @@ -7,7 +7,7 @@ licenser = "0.6.1" [plugins] blossom = { id = "net.kyori.blossom", version.ref = "blossom" } -shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } +shadow = { id = "io.github.goooler.shadow", version.ref = "shadow" } forgegradle = { id = "net.minecraftforge.gradle", version.ref = "forgegradle" } loom = { id = "fabric-loom", version.ref = "loom" } licenser = { id = "org.cadixdev.licenser", version.ref = "licenser" } \ No newline at end of file