Update Forge to MC 1.20.6 (#3883)

This commit is contained in:
bloodmc 2024-05-08 18:09:02 -04:00 committed by GitHub
parent 484b04c17b
commit 5c1ea5633e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 45 additions and 43 deletions

View File

@ -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"

View File

@ -2,8 +2,8 @@ plugins {
alias(libs.plugins.forgegradle)
}
sourceCompatibility = 1.8
targetCompatibility = 17
sourceCompatibility = 17
targetCompatibility = 21
minecraft {
mappings channel: 'official', version: minecraftVersion

View File

@ -1,2 +1,2 @@
minecraftVersion=1.20.4
forgeVersion=49.0.3
minecraftVersion=1.20.6
forgeVersion=50.0.9

View File

@ -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"

View File

@ -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<LPForgePlugin, CommandSour
}
public static net.minecraft.network.chat.Component toNativeText(Component component) {
return Serializer.fromJson(GsonComponentSerializer.gson().serializeToTree(component));
return Serializer.fromJson(GsonComponentSerializer.gson().serializeToTree(component), RegistryAccess.EMPTY);
}
}

View File

@ -44,16 +44,14 @@ import java.util.Locale;
public class UserCapabilityImpl implements UserCapability {
private static LazyOptional<UserCapability> getCapability(Player player) {
if (!player.isRemoved()) {
return player.getCapability(CAPABILITY);
} else {
player.reviveCaps();
try {
return player.getCapability(CAPABILITY);
} finally {
player.invalidateCaps();
}
LazyOptional<UserCapability> 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);
}
/**

View File

@ -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());
}
}
}

View File

@ -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) {

View File

@ -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<CommandSourceStack> dispatcher) {
public static void inject(LPForgePlugin plugin, CommandDispatcher<CommandSourceStack> dispatcher) {
Iterable<CommandNodeWithParent> 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<CommandSourceStack> {
private final LPForgePlugin plugin;
private final String permission;
private final Predicate<CommandSourceStack> delegate;
private InjectedPermissionRequirement(String permission, Predicate<CommandSourceStack> delegate) {
private InjectedPermissionRequirement(LPForgePlugin plugin, String permission, Predicate<CommandSourceStack> 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));

View File

@ -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" }