Mirror von
https://github.com/Moulberry/AxiomPaperPlugin.git
synchronisiert 2024-11-08 17:40:04 +01:00
Separate ViaVersion methods to avoid ClassNotFoundExceptions
Dieser Commit ist enthalten in:
Ursprung
12fe46f4b0
Commit
cdcf1220bd
@ -4,6 +4,7 @@ import com.moulberry.axiom.AxiomPaper;
|
||||
import com.moulberry.axiom.NbtSanitization;
|
||||
import com.moulberry.axiom.integration.Integration;
|
||||
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
|
||||
import com.moulberry.axiom.viaversion.UnknownVersionHelper;
|
||||
import com.moulberry.axiom.viaversion.ViaVersionHelper;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -63,7 +64,7 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
|
||||
pitch = friendlyByteBuf.readFloat();
|
||||
}
|
||||
|
||||
CompoundTag nbt = ViaVersionHelper.readTagUnknown(friendlyByteBuf, player);
|
||||
CompoundTag nbt = UnknownVersionHelper.readTagUnknown(friendlyByteBuf, player);
|
||||
|
||||
PassengerManipulation passengerManipulation = friendlyByteBuf.readEnum(PassengerManipulation.class);
|
||||
List<UUID> passengers = List.of();
|
||||
|
@ -8,8 +8,7 @@ import com.moulberry.axiom.buffer.BlockBuffer;
|
||||
import com.moulberry.axiom.buffer.CompressedBlockEntity;
|
||||
import com.moulberry.axiom.integration.Integration;
|
||||
import com.moulberry.axiom.integration.SectionPermissionChecker;
|
||||
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
|
||||
import com.moulberry.axiom.viaversion.ViaVersionHelper;
|
||||
import com.moulberry.axiom.viaversion.UnknownVersionHelper;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
|
||||
import net.minecraft.ChatFormatting;
|
||||
@ -78,7 +77,7 @@ public class SetBlockBufferPacketListener {
|
||||
boolean continuation = friendlyByteBuf.readBoolean();
|
||||
|
||||
if (!continuation) {
|
||||
ViaVersionHelper.skipTagUnknown(friendlyByteBuf, player.getBukkitEntity());
|
||||
UnknownVersionHelper.skipTagUnknown(friendlyByteBuf, player.getBukkitEntity());
|
||||
}
|
||||
|
||||
RateLimiter rateLimiter = this.plugin.getBlockBufferRateLimiter(player.getUUID());
|
||||
|
@ -4,6 +4,7 @@ import com.moulberry.axiom.AxiomPaper;
|
||||
import com.moulberry.axiom.NbtSanitization;
|
||||
import com.moulberry.axiom.integration.Integration;
|
||||
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
|
||||
import com.moulberry.axiom.viaversion.UnknownVersionHelper;
|
||||
import com.moulberry.axiom.viaversion.ViaVersionHelper;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -70,7 +71,7 @@ public class SpawnEntityPacketListener implements PluginMessageListener {
|
||||
List<SpawnEntry> entries = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000),
|
||||
buf -> new SpawnEntry(buf.readUUID(), buf.readDouble(), buf.readDouble(),
|
||||
buf.readDouble(), buf.readFloat(), buf.readFloat(),
|
||||
buf.readNullable(buffer -> buffer.readUUID()), ViaVersionHelper.readTagUnknown(buf, player)));
|
||||
buf.readNullable(buffer -> buffer.readUUID()), UnknownVersionHelper.readTagUnknown(buf, player)));
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle();
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.moulberry.axiom.viaversion;
|
||||
|
||||
import com.moulberry.axiom.AxiomPaper;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class UnknownVersionHelper {
|
||||
|
||||
public static void skipTagUnknown(FriendlyByteBuf friendlyByteBuf, Player player) {
|
||||
if (AxiomPaper.PLUGIN.isMismatchedDataVersion(player.getUniqueId())) {
|
||||
try {
|
||||
ViaVersionHelper.skipTagViaVersion(friendlyByteBuf, player);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
friendlyByteBuf.readNbt(); // Discard
|
||||
}
|
||||
}
|
||||
|
||||
public static CompoundTag readTagUnknown(FriendlyByteBuf friendlyByteBuf, Player player) {
|
||||
if (AxiomPaper.PLUGIN.isMismatchedDataVersion(player.getUniqueId())) {
|
||||
try {
|
||||
return ViaVersionHelper.readTagViaVersion(friendlyByteBuf, player);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
return friendlyByteBuf.readNbt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -6,9 +6,7 @@ import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.data.Mappings;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.minecraft.SharedConstants;
|
||||
@ -65,7 +63,7 @@ public class ViaVersionHelper {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public static IdMapper<BlockState> applyMappings(IdMapper<BlockState> registry, Mappings mappings) {
|
||||
private static IdMapper<BlockState> applyMappings(IdMapper<BlockState> registry, Mappings mappings) {
|
||||
IdMapper<BlockState> newBlockRegistry = new IdMapper<>();
|
||||
|
||||
// Add empty mappings for non-existent blocks
|
||||
@ -95,38 +93,20 @@ public class ViaVersionHelper {
|
||||
return newBlockRegistry;
|
||||
}
|
||||
|
||||
private static final int UNNAMED_COMPOUND_TAG_CHANGE_VERSION = ProtocolVersion.v1_20_2.getVersion();
|
||||
private static final int UNNAMED_COMPOUND_TAG_CHANGE_VERSION = 764; // 1.20.2
|
||||
|
||||
public static void skipTagUnknown(FriendlyByteBuf friendlyByteBuf, Player player) {
|
||||
if (AxiomPaper.PLUGIN.isMismatchedDataVersion(player.getUniqueId())) {
|
||||
int playerVersion = Via.getAPI().getPlayerVersion(player.getUniqueId());
|
||||
try {
|
||||
ViaVersionHelper.skipTagViaVersion(friendlyByteBuf, playerVersion);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
friendlyByteBuf.readNbt(); // Discard
|
||||
}
|
||||
}
|
||||
|
||||
public static CompoundTag readTagUnknown(FriendlyByteBuf friendlyByteBuf, Player player) {
|
||||
if (AxiomPaper.PLUGIN.isMismatchedDataVersion(player.getUniqueId())) {
|
||||
int playerVersion = Via.getAPI().getPlayerVersion(player.getUniqueId());
|
||||
try {
|
||||
return ViaVersionHelper.readTagViaVersion(friendlyByteBuf, playerVersion);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
return friendlyByteBuf.readNbt();
|
||||
}
|
||||
public static void skipTagViaVersion(FriendlyByteBuf friendlyByteBuf, Player player) throws Exception {
|
||||
skipTagViaVersion(friendlyByteBuf, Via.getAPI().getPlayerVersion(player.getUniqueId()));
|
||||
}
|
||||
|
||||
public static void skipTagViaVersion(FriendlyByteBuf friendlyByteBuf, int playerVersion) throws Exception {
|
||||
getTagType(playerVersion).read(friendlyByteBuf);
|
||||
}
|
||||
|
||||
public static CompoundTag readTagViaVersion(FriendlyByteBuf friendlyByteBuf, Player player) throws Exception {
|
||||
return readTagViaVersion(friendlyByteBuf, Via.getAPI().getPlayerVersion(player.getUniqueId()));
|
||||
}
|
||||
|
||||
public static CompoundTag readTagViaVersion(FriendlyByteBuf friendlyByteBuf, int playerVersion) throws Exception {
|
||||
Type<com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag> from = getTagType(playerVersion);
|
||||
Type<com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag> to = getTagType(SharedConstants.getProtocolVersion());
|
||||
@ -150,9 +130,9 @@ public class ViaVersionHelper {
|
||||
}
|
||||
|
||||
com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag tag = from.read(friendlyByteBuf);
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer());
|
||||
to.write(buffer, tag);
|
||||
return new FriendlyByteBuf(buffer).readNbt();
|
||||
return buffer.readNbt();
|
||||
}
|
||||
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren