Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 08:10:09 +01:00
Fix JSON for title packet, #24. Also implement method for generic JSON fixing woo!
Dieser Commit ist enthalten in:
Ursprung
6b3fb6424c
Commit
8ceee31299
@ -2,23 +2,20 @@ package us.myles.ViaVersion.transformers;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.spacehq.mc.protocol.data.game.chunk.Column;
|
import org.spacehq.mc.protocol.data.game.chunk.Column;
|
||||||
import org.spacehq.mc.protocol.util.NetUtil;
|
import org.spacehq.mc.protocol.util.NetUtil;
|
||||||
|
|
||||||
import us.myles.ViaVersion.*;
|
import us.myles.ViaVersion.*;
|
||||||
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
||||||
import us.myles.ViaVersion.metadata.MetaIndex;
|
import us.myles.ViaVersion.metadata.MetaIndex;
|
||||||
import us.myles.ViaVersion.metadata.NewType;
|
import us.myles.ViaVersion.metadata.NewType;
|
||||||
import us.myles.ViaVersion.sounds.SoundEffect;
|
|
||||||
import us.myles.ViaVersion.metadata.Type;
|
import us.myles.ViaVersion.metadata.Type;
|
||||||
import us.myles.ViaVersion.packets.PacketType;
|
import us.myles.ViaVersion.packets.PacketType;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
|
import us.myles.ViaVersion.sounds.SoundEffect;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -64,8 +61,7 @@ public class OutgoingTransformer {
|
|||||||
SoundEffect effect = SoundEffect.getByName(name);
|
SoundEffect effect = SoundEffect.getByName(name);
|
||||||
int catid = 0;
|
int catid = 0;
|
||||||
String newname = name;
|
String newname = name;
|
||||||
if(effect != null)
|
if (effect != null) {
|
||||||
{
|
|
||||||
catid = effect.getCategory().getId();
|
catid = effect.getCategory().getId();
|
||||||
newname = effect.getNewName();
|
newname = effect.getNewName();
|
||||||
}
|
}
|
||||||
@ -90,9 +86,17 @@ public class OutgoingTransformer {
|
|||||||
}
|
}
|
||||||
if (packet == PacketType.PLAY_DISCONNECT) {
|
if (packet == PacketType.PLAY_DISCONNECT) {
|
||||||
String reason = readString(input);
|
String reason = readString(input);
|
||||||
if (reason.startsWith("\""))
|
writeString(fixJson(reason), output);
|
||||||
reason = "{\"text\":" + reason + "}";
|
return;
|
||||||
writeString(reason,output);
|
}
|
||||||
|
if (packet == PacketType.PLAY_TITLE) {
|
||||||
|
int action = PacketUtil.readVarInt(input);
|
||||||
|
PacketUtil.writeVarInt(action, output);
|
||||||
|
if (action == 0 || action == 1) {
|
||||||
|
String text = PacketUtil.readString(input);
|
||||||
|
PacketUtil.writeString(fixJson(text), output);
|
||||||
|
}
|
||||||
|
output.writeBytes(input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (packet == PacketType.PLAY_ENTITY_TELEPORT) {
|
if (packet == PacketType.PLAY_ENTITY_TELEPORT) {
|
||||||
@ -268,12 +272,9 @@ public class OutgoingTransformer {
|
|||||||
String type = readString(input);
|
String type = readString(input);
|
||||||
String windowTitle = readString(input);
|
String windowTitle = readString(input);
|
||||||
|
|
||||||
if (windowTitle.startsWith("\""))
|
|
||||||
windowTitle = "{\"text\":" + windowTitle + "}";;
|
|
||||||
|
|
||||||
output.writeByte(windowId);
|
output.writeByte(windowId);
|
||||||
writeString(type, output);
|
writeString(type, output);
|
||||||
writeString(windowTitle,output);
|
writeString(fixJson(windowTitle), output);
|
||||||
output.writeBytes(input);
|
output.writeBytes(input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -320,15 +321,7 @@ public class OutgoingTransformer {
|
|||||||
output.writeLong(location);
|
output.writeLong(location);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
String line = PacketUtil.readString(input);
|
String line = PacketUtil.readString(input);
|
||||||
if (line == null || line.equalsIgnoreCase("null")) {
|
PacketUtil.writeString(fixJson(line), output);
|
||||||
line = "{\"text\":\"\"}";
|
|
||||||
} else {
|
|
||||||
if (!line.startsWith("\"") && !line.startsWith("{"))
|
|
||||||
line = "\"" + line + "\"";
|
|
||||||
if (line.startsWith("\""))
|
|
||||||
line = "{\"text\":" + line + "}";
|
|
||||||
}
|
|
||||||
PacketUtil.writeString(line, output);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (packet == PacketType.PLAY_SPAWN_PLAYER) {
|
if (packet == PacketType.PLAY_SPAWN_PLAYER) {
|
||||||
@ -440,6 +433,18 @@ public class OutgoingTransformer {
|
|||||||
output.writeBytes(input);
|
output.writeBytes(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String fixJson(String line) {
|
||||||
|
if (line == null || line.equalsIgnoreCase("null")) {
|
||||||
|
line = "{\"text\":\"\"}";
|
||||||
|
} else {
|
||||||
|
if (!line.startsWith("\"") && !line.startsWith("{"))
|
||||||
|
line = "\"" + line + "\"";
|
||||||
|
if (line.startsWith("\""))
|
||||||
|
line = "{\"text\":" + line + "}";
|
||||||
|
}
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
private void transformMetadata(Object dw, ByteBuf output) {
|
private void transformMetadata(Object dw, ByteBuf output) {
|
||||||
// get entity
|
// get entity
|
||||||
try {
|
try {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren