forked from BLOCKFANTASY/LOOHP-Limbo
Minecraft 1.20.4
This commit is contained in:
@@ -63,8 +63,8 @@ import com.loohp.limbo.network.protocol.packets.PacketPlayInPickItem;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayInPluginMessaging;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayInPosition;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayInPositionAndLook;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayInResourcePackStatus;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayInResourcePackStatus.EnumResourcePackStatus;
|
||||
import com.loohp.limbo.network.protocol.packets.ServerboundResourcePackPacket;
|
||||
import com.loohp.limbo.network.protocol.packets.ServerboundResourcePackPacket.Action;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayInRotation;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayInSetCreativeSlot;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayInTabComplete;
|
||||
@@ -765,11 +765,11 @@ public class ClientConnection extends Thread {
|
||||
Limbo.getInstance().getUnsafe().a(player, event.getSlot());
|
||||
}
|
||||
|
||||
} else if (packetIn instanceof PacketPlayInResourcePackStatus) {
|
||||
PacketPlayInResourcePackStatus rpcheck = (PacketPlayInResourcePackStatus) packetIn;
|
||||
} else if (packetIn instanceof ServerboundResourcePackPacket) {
|
||||
ServerboundResourcePackPacket rpcheck = (ServerboundResourcePackPacket) packetIn;
|
||||
// Pass on result to the events
|
||||
Limbo.getInstance().getEventsManager().callEvent(new PlayerResourcePackStatusEvent(player, rpcheck.getLoadedValue()));
|
||||
if (rpcheck.getLoadedValue().equals(EnumResourcePackStatus.DECLINED) && properties.getResourcePackRequired()) {
|
||||
Limbo.getInstance().getEventsManager().callEvent(new PlayerResourcePackStatusEvent(player, rpcheck.getAction()));
|
||||
if (rpcheck.getAction().equals(Action.DECLINED) && properties.getResourcePackRequired()) {
|
||||
player.disconnect(new TranslatableComponent("multiplayer.requiredTexturePrompt.disconnect"));
|
||||
}
|
||||
} else if (packetIn instanceof PacketPlayInPluginMessaging) {
|
||||
|
||||
+29
-27
@@ -27,32 +27,34 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketPlayOutResourcePackSend extends PacketOut {
|
||||
public class ClientboundResourcePackPushPacket extends PacketOut {
|
||||
|
||||
public static final int MAX_HASH_LENGTH = 40;
|
||||
|
||||
private String url;
|
||||
private String hash;
|
||||
private boolean isForced;
|
||||
private boolean hasPromptMessage;
|
||||
private Component promptMessage;
|
||||
|
||||
public PacketPlayOutResourcePackSend(String url, String hash, boolean isForced, boolean hasPromptMessage, Component promptMessage) {
|
||||
private final UUID id;
|
||||
private final String url;
|
||||
private final String hash;
|
||||
private final boolean required;
|
||||
private final Component prompt;
|
||||
|
||||
public ClientboundResourcePackPushPacket(UUID id, String url, String hash, boolean required, Component promptMessage) {
|
||||
if (hash.length() > MAX_HASH_LENGTH) {
|
||||
throw new IllegalArgumentException("Hash is too long (max " + MAX_HASH_LENGTH + ", was " + hash.length() + ")");
|
||||
}
|
||||
this.id = id;
|
||||
this.url = url;
|
||||
this.hash = hash;
|
||||
this.isForced = isForced;
|
||||
this.hasPromptMessage = hasPromptMessage;
|
||||
if (hasPromptMessage && promptMessage == null) {
|
||||
throw new IllegalArgumentException("promptMessage cannot be null when hasPromptMessage is true");
|
||||
}
|
||||
this.promptMessage = promptMessage;
|
||||
this.required = required;
|
||||
this.prompt = promptMessage;
|
||||
}
|
||||
|
||||
public String getURL() {
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -60,31 +62,31 @@ public class PacketPlayOutResourcePackSend extends PacketOut {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public boolean isForced() {
|
||||
return isForced;
|
||||
public boolean isRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public boolean hasPromptMessage() {
|
||||
return hasPromptMessage;
|
||||
public Component getPrompt() {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
public Component getPromptMessage() {
|
||||
return promptMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serializePacket() throws IOException {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
DataTypeIO.writeUUID(output, id);
|
||||
DataTypeIO.writeString(output, url, StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeString(output, hash, StandardCharsets.UTF_8);
|
||||
output.writeBoolean(isForced);
|
||||
output.writeBoolean(hasPromptMessage);
|
||||
if (hasPromptMessage) {
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(promptMessage), StandardCharsets.UTF_8);
|
||||
output.writeBoolean(required);
|
||||
if (prompt == null) {
|
||||
output.writeBoolean(false);
|
||||
} else {
|
||||
output.writeBoolean(true);
|
||||
DataTypeIO.writeComponent(output, prompt);
|
||||
}
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
+1
-3
@@ -21,12 +21,10 @@ package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ClientboundSetActionBarTextPacket extends PacketOut {
|
||||
|
||||
@@ -46,7 +44,7 @@ public class ClientboundSetActionBarTextPacket extends PacketOut {
|
||||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(actionBar), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, actionBar);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
+1
-3
@@ -21,12 +21,10 @@ package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ClientboundSetSubtitleTextPacket extends PacketOut {
|
||||
|
||||
@@ -46,7 +44,7 @@ public class ClientboundSetSubtitleTextPacket extends PacketOut {
|
||||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(subTitle), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, subTitle);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
+1
-3
@@ -21,12 +21,10 @@ package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ClientboundSetTitleTextPacket extends PacketOut {
|
||||
|
||||
@@ -46,7 +44,7 @@ public class ClientboundSetTitleTextPacket extends PacketOut {
|
||||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(titleText), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, titleText);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
+1
-3
@@ -21,12 +21,10 @@ package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ClientboundSystemChatPacket extends PacketOut {
|
||||
|
||||
@@ -52,7 +50,7 @@ public class ClientboundSystemChatPacket extends PacketOut {
|
||||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(message), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, message);
|
||||
output.writeBoolean(overlay);
|
||||
|
||||
return buffer.toByteArray();
|
||||
|
||||
+1
-3
@@ -21,12 +21,10 @@ package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketLoginOutDisconnect extends PacketOut {
|
||||
|
||||
@@ -46,7 +44,7 @@ public class PacketLoginOutDisconnect extends PacketOut {
|
||||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getLoginOut().get(getClass()));
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(reason), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, reason);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
@@ -22,12 +22,10 @@ package com.loohp.limbo.network.protocol.packets;
|
||||
import com.loohp.limbo.bossbar.KeyedBossBar;
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketPlayOutBoss extends PacketOut {
|
||||
|
||||
@@ -83,7 +81,7 @@ public class PacketPlayOutBoss extends PacketOut {
|
||||
BossBar properties = bossBar.getProperties();
|
||||
switch (action) {
|
||||
case ADD: {
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(properties.name()), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, properties.name());
|
||||
output.writeFloat(properties.progress());
|
||||
DataTypeIO.writeVarInt(output, properties.color().ordinal());
|
||||
DataTypeIO.writeVarInt(output, properties.overlay().ordinal());
|
||||
@@ -98,7 +96,7 @@ public class PacketPlayOutBoss extends PacketOut {
|
||||
break;
|
||||
}
|
||||
case UPDATE_NAME: {
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(properties.name()), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, properties.name());
|
||||
break;
|
||||
}
|
||||
case UPDATE_STYLE: {
|
||||
|
||||
@@ -21,12 +21,10 @@ package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketPlayOutDisconnect extends PacketOut {
|
||||
|
||||
@@ -46,7 +44,7 @@ public class PacketPlayOutDisconnect extends PacketOut {
|
||||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(reason), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, reason);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
+1
-2
@@ -27,7 +27,6 @@ import com.loohp.limbo.utils.DataTypeIO;
|
||||
import com.loohp.limbo.utils.Rotation3f;
|
||||
import com.loohp.limbo.world.BlockPosition;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -129,7 +128,7 @@ public class PacketPlayOutEntityMetadata extends PacketOut {
|
||||
output.writeByte((byte) watch.getValue());
|
||||
break;
|
||||
case CHAT:
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize((Component) watch.getValue()), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, (Component) watch.getValue());
|
||||
break;
|
||||
//case DIRECTION:
|
||||
// break;
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.io.IOException;
|
||||
|
||||
public class PacketPlayOutGameState extends PacketOut {
|
||||
|
||||
private int reason;
|
||||
private float value;
|
||||
private final int reason;
|
||||
private final float value;
|
||||
|
||||
public PacketPlayOutGameState(int reason, float value) {
|
||||
this.reason = reason;
|
||||
|
||||
@@ -23,12 +23,10 @@ import com.loohp.limbo.registry.Registry;
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketPlayOutOpenWindow extends PacketOut {
|
||||
|
||||
@@ -63,7 +61,7 @@ public class PacketPlayOutOpenWindow extends PacketOut {
|
||||
|
||||
DataTypeIO.writeVarInt(output, containerId);
|
||||
DataTypeIO.writeVarInt(output, Registry.MENU_REGISTRY.getId(type));
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(title), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, title);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
+2
-4
@@ -21,12 +21,10 @@ package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketPlayOutPlayerListHeaderFooter extends PacketOut{
|
||||
|
||||
@@ -53,8 +51,8 @@ public class PacketPlayOutPlayerListHeaderFooter extends PacketOut{
|
||||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(header), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(footer), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, header);
|
||||
DataTypeIO.writeComponent(output, footer);
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -21,7 +21,6 @@ package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -74,7 +73,7 @@ public class PacketPlayOutTabComplete extends PacketOut {
|
||||
DataTypeIO.writeString(output, match.getMatch(), StandardCharsets.UTF_8);
|
||||
if (match.getTooltip().isPresent()) {
|
||||
output.writeBoolean(true);
|
||||
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(match.getTooltip().get()), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeComponent(output, match.getTooltip().get());
|
||||
} else {
|
||||
output.writeBoolean(false);
|
||||
}
|
||||
|
||||
+28
-33
@@ -23,43 +23,38 @@ import com.loohp.limbo.utils.DataTypeIO;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketPlayInResourcePackStatus extends PacketIn {
|
||||
public class ServerboundResourcePackPacket extends PacketIn {
|
||||
|
||||
public static enum EnumResourcePackStatus {
|
||||
SUCCESS,
|
||||
DECLINED,
|
||||
FAILED,
|
||||
ACCEPTED;
|
||||
}
|
||||
|
||||
private EnumResourcePackStatus loaded;
|
||||
|
||||
public PacketPlayInResourcePackStatus(EnumResourcePackStatus loaded) {
|
||||
this.loaded = loaded;
|
||||
}
|
||||
|
||||
public PacketPlayInResourcePackStatus(DataInputStream in) throws IOException {
|
||||
this(toLoadedValue(DataTypeIO.readVarInt(in)));
|
||||
}
|
||||
|
||||
public EnumResourcePackStatus getLoadedValue() {
|
||||
return loaded;
|
||||
}
|
||||
public enum Action {
|
||||
|
||||
private static EnumResourcePackStatus toLoadedValue(int value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return EnumResourcePackStatus.SUCCESS;
|
||||
case 1:
|
||||
return EnumResourcePackStatus.DECLINED;
|
||||
case 2:
|
||||
return EnumResourcePackStatus.FAILED;
|
||||
case 3:
|
||||
return EnumResourcePackStatus.ACCEPTED;
|
||||
default:
|
||||
return EnumResourcePackStatus.FAILED;
|
||||
SUCCESSFULLY_LOADED, DECLINED, FAILED_DOWNLOAD, ACCEPTED, DOWNLOADED, INVALID_URL, FAILED_RELOAD, DISCARDED;
|
||||
|
||||
public boolean isTerminal() {
|
||||
return this != ACCEPTED && this != DOWNLOADED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final UUID id;
|
||||
private final Action action;
|
||||
|
||||
public ServerboundResourcePackPacket(UUID id, Action action) {
|
||||
this.id = id;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public ServerboundResourcePackPacket(DataInputStream in) throws IOException {
|
||||
this(DataTypeIO.readUUID(in), Action.values()[DataTypeIO.readVarInt(in)]);
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user