Fix payload handling

This commit is contained in:
IzzelAliz 2020-05-17 17:08:59 +08:00
parent a34e52a68e
commit 6bd2da2fd3
2 changed files with 10 additions and 10 deletions

View File

@ -63,7 +63,6 @@ def embedLibs = ['org.spongepowered:mixin:0.8', 'org.ow2.asm:asm-util:6.2',
dependencies { dependencies {
minecraft 'net.minecraftforge:forge:1.14.4-28.2.0' minecraft 'net.minecraftforge:forge:1.14.4-28.2.0'
annotationProcessor 'org.spongepowered:mixin:0.8'
compile group: 'org.jetbrains', name: 'annotations', version: '19.0.0' compile group: 'org.jetbrains', name: 'annotations', version: '19.0.0'
for (def lib : embedLibs) { for (def lib : embedLibs) {
embedJar "$lib@jar" embedJar "$lib@jar"

View File

@ -59,6 +59,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SharedConstants; import net.minecraft.util.SharedConstants;
import net.minecraft.util.StringUtils;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -1619,12 +1620,12 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB
private void arclight$customPayload(CCustomPayloadPacket packet, CallbackInfo ci) { private void arclight$customPayload(CCustomPayloadPacket packet, CallbackInfo ci) {
if (packet.channel.equals(CUSTOM_REGISTER)) { if (packet.channel.equals(CUSTOM_REGISTER)) {
try { try {
final String channels = packet.data.toString(Charsets.UTF_8); String channels = packet.data.toString(Charsets.UTF_8);
String[] split; for (String channel :channels.split("\0")){
for (int length = (split = channels.split("\u0000")).length, i = 0; i < length; ++i) { if (!StringUtils.isNullOrEmpty(channel)) {
final String channel = split[i];
this.getPlayer().addChannel(channel); this.getPlayer().addChannel(channel);
} }
}
} catch (Exception ex) { } catch (Exception ex) {
LOGGER.error("Couldn't register custom payload", ex); LOGGER.error("Couldn't register custom payload", ex);
this.disconnect("Invalid payload REGISTER!"); this.disconnect("Invalid payload REGISTER!");
@ -1632,11 +1633,11 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB
} else if (packet.channel.equals(CUSTOM_UNREGISTER)) { } else if (packet.channel.equals(CUSTOM_UNREGISTER)) {
try { try {
final String channels = packet.data.toString(Charsets.UTF_8); final String channels = packet.data.toString(Charsets.UTF_8);
String[] split2; for (String channel :channels.split("\0")){
for (int length2 = (split2 = channels.split("\u0000")).length, j = 0; j < length2; ++j) { if (!StringUtils.isNullOrEmpty(channel)) {
final String channel = split2[j];
this.getPlayer().removeChannel(channel); this.getPlayer().removeChannel(channel);
} }
}
} catch (Exception ex) { } catch (Exception ex) {
LOGGER.error("Couldn't unregister custom payload", ex); LOGGER.error("Couldn't unregister custom payload", ex);
this.disconnect("Invalid payload UNREGISTER!"); this.disconnect("Invalid payload UNREGISTER!");