Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-24 23:30:15 +01:00
Fix books, also makes ItemSlotRewriter.ItemStack fields public
Dieser Commit ist enthalten in:
Ursprung
cb4a8b24d4
Commit
963f021226
@ -122,6 +122,7 @@ public class ItemSlotRewriter {
|
||||
public static ItemStack readItemStack(ByteBuf input) throws IOException {
|
||||
short id = input.readShort();
|
||||
if (id < 0) {
|
||||
|
||||
return null;
|
||||
} else {
|
||||
ItemStack item = new ItemStack();
|
||||
@ -146,10 +147,10 @@ public class ItemSlotRewriter {
|
||||
|
||||
public static class ItemStack {
|
||||
|
||||
private short id;
|
||||
private byte amount;
|
||||
private short data;
|
||||
private CompoundTag tag;
|
||||
public short id;
|
||||
public byte amount;
|
||||
public short data;
|
||||
public CompoundTag tag;
|
||||
|
||||
public static ItemStack fromBukkit(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack item = new ItemStack();
|
||||
|
@ -1,7 +1,13 @@
|
||||
package us.myles.ViaVersion.transformers;
|
||||
|
||||
import com.avaje.ebeaninternal.server.cluster.Packet;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.spacehq.opennbt.tag.builtin.ListTag;
|
||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
||||
import org.spacehq.opennbt.tag.builtin.Tag;
|
||||
import us.myles.ViaVersion.CancelException;
|
||||
import us.myles.ViaVersion.ConnectionInfo;
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
@ -11,8 +17,10 @@ import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.util.PacketUtil;
|
||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class IncomingTransformer {
|
||||
private final ConnectionInfo info;
|
||||
@ -171,6 +179,26 @@ public class IncomingTransformer {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(packet == PacketType.PLAY_PLUGIN_MESSAGE_REQUEST) {
|
||||
String name = PacketUtil.readString(input);
|
||||
PacketUtil.writeString(name, output);
|
||||
byte[] b = new byte[input.readableBytes()];
|
||||
input.readBytes(b);
|
||||
// patch books
|
||||
if(name.equals("MC|BSign")){
|
||||
ByteBuf in = Unpooled.wrappedBuffer(b);
|
||||
try {
|
||||
ItemSlotRewriter.ItemStack stack = ItemSlotRewriter.readItemStack(in);
|
||||
stack.id = (short) Material.WRITTEN_BOOK.getId();
|
||||
// write
|
||||
ItemSlotRewriter.writeItemStack(stack, output);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
output.writeBytes(b);
|
||||
}
|
||||
if (packet == PacketType.PLAY_PLAYER_BLOCK_PLACEMENT) {
|
||||
Long position = input.readLong();
|
||||
output.writeLong(position);
|
||||
|
@ -1,20 +1,25 @@
|
||||
package us.myles.ViaVersion.transformers;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.spacehq.mc.protocol.data.game.chunk.Column;
|
||||
import org.spacehq.mc.protocol.util.NetUtil;
|
||||
import org.spacehq.opennbt.tag.builtin.ListTag;
|
||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
||||
import org.spacehq.opennbt.tag.builtin.Tag;
|
||||
import us.myles.ViaVersion.CancelException;
|
||||
import us.myles.ViaVersion.ConnectionInfo;
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
||||
import us.myles.ViaVersion.metadata.MetadataRewriter;
|
||||
import us.myles.ViaVersion.packets.PacketType;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
||||
import us.myles.ViaVersion.sounds.SoundEffect;
|
||||
import us.myles.ViaVersion.util.EntityUtil;
|
||||
import us.myles.ViaVersion.util.PacketUtil;
|
||||
@ -96,6 +101,17 @@ public class OutgoingTransformer {
|
||||
output.writeInt(vehicle);
|
||||
return;
|
||||
}
|
||||
if (packet == PacketType.PLAY_PLUGIN_MESSAGE) {
|
||||
String name = PacketUtil.readString(input);
|
||||
PacketUtil.writeString(name, output);
|
||||
byte[] b = new byte[input.readableBytes()];
|
||||
input.readBytes(b);
|
||||
// patch books
|
||||
if(name.equals("MC|BOpen")){
|
||||
PacketUtil.writeVarInt(0, output);
|
||||
}
|
||||
output.writeBytes(b);
|
||||
}
|
||||
if (packet == PacketType.PLAY_DISCONNECT) {
|
||||
String reason = readString(input);
|
||||
writeString(fixJson(reason), output);
|
||||
@ -271,7 +287,7 @@ public class OutgoingTransformer {
|
||||
slot += 1; // add 1 so it's now 2-5
|
||||
}
|
||||
PacketUtil.writeVarInt(slot, output);
|
||||
|
||||
|
||||
ItemSlotRewriter.rewrite1_8To1_9(input, output);
|
||||
return;
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren