Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-25 15:50:10 +01:00
Change package for slot rewriter.
Dieser Commit ist enthalten in:
Ursprung
88ff4ee9ca
Commit
c2edf45846
@ -11,8 +11,8 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.slot.ItemSlotRewriter;
|
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
||||||
import us.myles.ViaVersion.api.slot.ItemSlotRewriter.ItemStack;
|
import us.myles.ViaVersion.slot.ItemSlotRewriter.ItemStack;
|
||||||
import us.myles.ViaVersion.util.PacketUtil;
|
import us.myles.ViaVersion.util.PacketUtil;
|
||||||
|
|
||||||
public class MetadataRewriter {
|
public class MetadataRewriter {
|
||||||
|
@ -1,191 +1,191 @@
|
|||||||
package us.myles.ViaVersion.api.slot;
|
package us.myles.ViaVersion.slot;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
import org.spacehq.opennbt.tag.builtin.StringTag;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import us.myles.ViaVersion.CancelException;
|
import us.myles.ViaVersion.CancelException;
|
||||||
import us.myles.ViaVersion.util.PacketUtil;
|
import us.myles.ViaVersion.util.PacketUtil;
|
||||||
|
|
||||||
public class ItemSlotRewriter {
|
public class ItemSlotRewriter {
|
||||||
|
|
||||||
public static void rewrite1_9To1_8(ByteBuf input, ByteBuf output) throws CancelException {
|
public static void rewrite1_9To1_8(ByteBuf input, ByteBuf output) throws CancelException {
|
||||||
try {
|
try {
|
||||||
ItemStack item = readItemStack(input);
|
ItemStack item = readItemStack(input);
|
||||||
fixIdsFrom1_9To1_8(item);
|
fixIdsFrom1_9To1_8(item);
|
||||||
writeItemStack(item, output);
|
writeItemStack(item, output);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Error while rewriting an item slot.");
|
System.out.println("Error while rewriting an item slot.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new CancelException();
|
throw new CancelException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rewrite1_8To1_9(ByteBuf input, ByteBuf output) throws CancelException {
|
public static void rewrite1_8To1_9(ByteBuf input, ByteBuf output) throws CancelException {
|
||||||
try {
|
try {
|
||||||
ItemStack item = readItemStack(input);
|
ItemStack item = readItemStack(input);
|
||||||
fixIdsFrom1_8To1_9(item);
|
fixIdsFrom1_8To1_9(item);
|
||||||
writeItemStack(item, output);
|
writeItemStack(item, output);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Error while rewriting an item slot.");
|
System.out.println("Error while rewriting an item slot.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new CancelException();
|
throw new CancelException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fixIdsFrom1_9To1_8(ItemStack item) {
|
public static void fixIdsFrom1_9To1_8(ItemStack item) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
if (item.id == Material.MONSTER_EGG.getId() && item.data == 0) {
|
if (item.id == Material.MONSTER_EGG.getId() && item.data == 0) {
|
||||||
CompoundTag tag = item.tag;
|
CompoundTag tag = item.tag;
|
||||||
int data = 0;
|
int data = 0;
|
||||||
if (tag != null && tag.get("EntityTag") instanceof CompoundTag) {
|
if (tag != null && tag.get("EntityTag") instanceof CompoundTag) {
|
||||||
CompoundTag entityTag = tag.get("EntityTag");
|
CompoundTag entityTag = tag.get("EntityTag");
|
||||||
if (entityTag.get("id") instanceof StringTag) {
|
if (entityTag.get("id") instanceof StringTag) {
|
||||||
StringTag id = entityTag.get("id");
|
StringTag id = entityTag.get("id");
|
||||||
data = ENTTIY_NAME_TO_ID.get(id.getValue());
|
data = ENTTIY_NAME_TO_ID.get(id.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item.tag = null;
|
item.tag = null;
|
||||||
item.data = (short) data;
|
item.data = (short) data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fixIdsFrom1_8To1_9(ItemStack item) {
|
public static void fixIdsFrom1_8To1_9(ItemStack item) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
if (item.id == Material.MONSTER_EGG.getId() && item.data != 0) {
|
if (item.id == Material.MONSTER_EGG.getId() && item.data != 0) {
|
||||||
CompoundTag tag = item.tag;
|
CompoundTag tag = item.tag;
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
tag = new CompoundTag("tag");
|
tag = new CompoundTag("tag");
|
||||||
}
|
}
|
||||||
CompoundTag entityTag = new CompoundTag("EntityTag");
|
CompoundTag entityTag = new CompoundTag("EntityTag");
|
||||||
StringTag id = new StringTag("id", ENTTIY_ID_TO_NAME.get(Integer.valueOf(item.data)));
|
StringTag id = new StringTag("id", ENTTIY_ID_TO_NAME.get(Integer.valueOf(item.data)));
|
||||||
entityTag.put(id);
|
entityTag.put(id);
|
||||||
tag.put(entityTag);
|
tag.put(entityTag);
|
||||||
item.tag = tag;
|
item.tag = tag;
|
||||||
item.data = 0;
|
item.data = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack readItemStack(ByteBuf input) throws IOException {
|
public static ItemStack readItemStack(ByteBuf input) throws IOException {
|
||||||
short id = input.readShort();
|
short id = input.readShort();
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
ItemStack item = new ItemStack();
|
ItemStack item = new ItemStack();
|
||||||
item.id = id;
|
item.id = id;
|
||||||
item.amount = input.readByte();
|
item.amount = input.readByte();
|
||||||
item.data = input.readShort();
|
item.data = input.readShort();
|
||||||
item.tag = PacketUtil.readNBT(input);
|
item.tag = PacketUtil.readNBT(input);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeItemStack(ItemStack item, ByteBuf output) throws IOException {
|
public static void writeItemStack(ItemStack item, ByteBuf output) throws IOException {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
output.writeShort(-1);
|
output.writeShort(-1);
|
||||||
} else {
|
} else {
|
||||||
output.writeShort(item.id);
|
output.writeShort(item.id);
|
||||||
output.writeByte(item.amount);
|
output.writeByte(item.amount);
|
||||||
output.writeShort(item.data);
|
output.writeShort(item.data);
|
||||||
PacketUtil.writeNBT(output, item.tag);
|
PacketUtil.writeNBT(output, item.tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ItemStack {
|
public static class ItemStack {
|
||||||
|
|
||||||
private short id;
|
private short id;
|
||||||
private byte amount;
|
private byte amount;
|
||||||
private short data;
|
private short data;
|
||||||
private CompoundTag tag;
|
private CompoundTag tag;
|
||||||
|
|
||||||
public static ItemStack fromBukkit(org.bukkit.inventory.ItemStack stack) {
|
public static ItemStack fromBukkit(org.bukkit.inventory.ItemStack stack) {
|
||||||
ItemStack item = new ItemStack();
|
ItemStack item = new ItemStack();
|
||||||
item.id = (short) stack.getTypeId();
|
item.id = (short) stack.getTypeId();
|
||||||
item.amount = (byte) stack.getAmount();
|
item.amount = (byte) stack.getAmount();
|
||||||
item.data = stack.getData().getData();
|
item.data = stack.getData().getData();
|
||||||
// TODO: nbt
|
// TODO: nbt
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, Integer> ENTTIY_NAME_TO_ID = new HashMap<>();
|
private static Map<String, Integer> ENTTIY_NAME_TO_ID = new HashMap<>();
|
||||||
private static Map<Integer, String> ENTTIY_ID_TO_NAME = new HashMap<>();
|
private static Map<Integer, String> ENTTIY_ID_TO_NAME = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
register(1, "Item");
|
register(1, "Item");
|
||||||
register(2, "XPOrb");
|
register(2, "XPOrb");
|
||||||
register(7, "ThrownEgg");
|
register(7, "ThrownEgg");
|
||||||
register(8, "LeashKnot");
|
register(8, "LeashKnot");
|
||||||
register(9, "Painting");
|
register(9, "Painting");
|
||||||
register(10, "Arrow");
|
register(10, "Arrow");
|
||||||
register(11, "Snowball");
|
register(11, "Snowball");
|
||||||
register(12, "Fireball");
|
register(12, "Fireball");
|
||||||
register(13, "SmallFireball");
|
register(13, "SmallFireball");
|
||||||
register(14, "ThrownEnderpearl");
|
register(14, "ThrownEnderpearl");
|
||||||
register(15, "EyeOfEnderSignal");
|
register(15, "EyeOfEnderSignal");
|
||||||
register(16, "ThrownPotion");
|
register(16, "ThrownPotion");
|
||||||
register(17, "ThrownExpBottle");
|
register(17, "ThrownExpBottle");
|
||||||
register(18, "ItemFrame");
|
register(18, "ItemFrame");
|
||||||
register(19, "WitherSkull");
|
register(19, "WitherSkull");
|
||||||
register(20, "PrimedTnt");
|
register(20, "PrimedTnt");
|
||||||
register(21, "FallingSand");
|
register(21, "FallingSand");
|
||||||
register(22, "FireworksRocketEntity");
|
register(22, "FireworksRocketEntity");
|
||||||
register(30, "ArmorStand");
|
register(30, "ArmorStand");
|
||||||
register(40, "MinecartCommandBlock");
|
register(40, "MinecartCommandBlock");
|
||||||
register(41, "Boat");
|
register(41, "Boat");
|
||||||
register(42, "MinecartRideable");
|
register(42, "MinecartRideable");
|
||||||
register(43, "MinecartChest");
|
register(43, "MinecartChest");
|
||||||
register(44, "MinecartFurnace");
|
register(44, "MinecartFurnace");
|
||||||
register(45, "MinecartTNT");
|
register(45, "MinecartTNT");
|
||||||
register(46, "MinecartHopper");
|
register(46, "MinecartHopper");
|
||||||
register(47, "MinecartSpawner");
|
register(47, "MinecartSpawner");
|
||||||
register(48, "Mob");
|
register(48, "Mob");
|
||||||
register(49, "Monster");
|
register(49, "Monster");
|
||||||
register(50, "Creeper");
|
register(50, "Creeper");
|
||||||
register(51, "Skeleton");
|
register(51, "Skeleton");
|
||||||
register(52, "Spider");
|
register(52, "Spider");
|
||||||
register(53, "Giant");
|
register(53, "Giant");
|
||||||
register(54, "Zombie");
|
register(54, "Zombie");
|
||||||
register(55, "Slime");
|
register(55, "Slime");
|
||||||
register(56, "Ghast");
|
register(56, "Ghast");
|
||||||
register(57, "PigZombie");
|
register(57, "PigZombie");
|
||||||
register(58, "Enderman");
|
register(58, "Enderman");
|
||||||
register(59, "CaveSpider");
|
register(59, "CaveSpider");
|
||||||
register(60, "Silverfish");
|
register(60, "Silverfish");
|
||||||
register(61, "Blaze");
|
register(61, "Blaze");
|
||||||
register(62, "LavaSlime");
|
register(62, "LavaSlime");
|
||||||
register(63, "EnderDragon");
|
register(63, "EnderDragon");
|
||||||
register(64, "WitherBoss");
|
register(64, "WitherBoss");
|
||||||
register(65, "Bat");
|
register(65, "Bat");
|
||||||
register(66, "Witch");
|
register(66, "Witch");
|
||||||
register(67, "Endermite");
|
register(67, "Endermite");
|
||||||
register(68, "Guardian");
|
register(68, "Guardian");
|
||||||
register(90, "Pig");
|
register(90, "Pig");
|
||||||
register(91, "Sheep");
|
register(91, "Sheep");
|
||||||
register(92, "Cow");
|
register(92, "Cow");
|
||||||
register(93, "Chicken");
|
register(93, "Chicken");
|
||||||
register(94, "Squid");
|
register(94, "Squid");
|
||||||
register(95, "Wolf");
|
register(95, "Wolf");
|
||||||
register(96, "MushroomCow");
|
register(96, "MushroomCow");
|
||||||
register(97, "SnowMan");
|
register(97, "SnowMan");
|
||||||
register(98, "Ozelot");
|
register(98, "Ozelot");
|
||||||
register(99, "VillagerGolem");
|
register(99, "VillagerGolem");
|
||||||
register(100, "EntityHorse");
|
register(100, "EntityHorse");
|
||||||
register(101, "Rabbit");
|
register(101, "Rabbit");
|
||||||
register(120, "Villager");
|
register(120, "Villager");
|
||||||
register(200, "EnderCrystal");
|
register(200, "EnderCrystal");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void register(Integer id, String name) {
|
private static void register(Integer id, String name) {
|
||||||
ENTTIY_ID_TO_NAME.put(id, name);
|
ENTTIY_ID_TO_NAME.put(id, name);
|
||||||
ENTTIY_NAME_TO_ID.put(name, id);
|
ENTTIY_NAME_TO_ID.put(name, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import us.myles.ViaVersion.CancelException;
|
import us.myles.ViaVersion.CancelException;
|
||||||
import us.myles.ViaVersion.ConnectionInfo;
|
import us.myles.ViaVersion.ConnectionInfo;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.slot.ItemSlotRewriter;
|
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
||||||
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.util.PacketUtil;
|
import us.myles.ViaVersion.util.PacketUtil;
|
||||||
@ -13,7 +13,6 @@ import us.myles.ViaVersion.util.ReflectionUtil;
|
|||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public class IncomingTransformer {
|
public class IncomingTransformer {
|
||||||
private final ConnectionInfo info;
|
private final ConnectionInfo info;
|
||||||
@ -181,7 +180,7 @@ public class IncomingTransformer {
|
|||||||
|
|
||||||
ItemStack inHand = ViaVersionPlugin.getHandItem(info);
|
ItemStack inHand = ViaVersionPlugin.getHandItem(info);
|
||||||
try {
|
try {
|
||||||
us.myles.ViaVersion.api.slot.ItemSlotRewriter.ItemStack item = us.myles.ViaVersion.api.slot.ItemSlotRewriter.ItemStack.fromBukkit(inHand);
|
ItemSlotRewriter.ItemStack item = ItemSlotRewriter.ItemStack.fromBukkit(inHand);
|
||||||
ItemSlotRewriter.fixIdsFrom1_9To1_8(item);
|
ItemSlotRewriter.fixIdsFrom1_9To1_8(item);
|
||||||
ItemSlotRewriter.writeItemStack(item, output);
|
ItemSlotRewriter.writeItemStack(item, output);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -205,7 +204,7 @@ public class IncomingTransformer {
|
|||||||
// write item in hand
|
// write item in hand
|
||||||
ItemStack inHand = ViaVersionPlugin.getHandItem(info);
|
ItemStack inHand = ViaVersionPlugin.getHandItem(info);
|
||||||
try {
|
try {
|
||||||
us.myles.ViaVersion.api.slot.ItemSlotRewriter.ItemStack item = us.myles.ViaVersion.api.slot.ItemSlotRewriter.ItemStack.fromBukkit(inHand);
|
us.myles.ViaVersion.slot.ItemSlotRewriter.ItemStack item = us.myles.ViaVersion.slot.ItemSlotRewriter.ItemStack.fromBukkit(inHand);
|
||||||
ItemSlotRewriter.fixIdsFrom1_9To1_8(item);
|
ItemSlotRewriter.fixIdsFrom1_9To1_8(item);
|
||||||
ItemSlotRewriter.writeItemStack(item, output);
|
ItemSlotRewriter.writeItemStack(item, output);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -11,7 +11,7 @@ import us.myles.ViaVersion.CancelException;
|
|||||||
import us.myles.ViaVersion.ConnectionInfo;
|
import us.myles.ViaVersion.ConnectionInfo;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import us.myles.ViaVersion.api.slot.ItemSlotRewriter;
|
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
||||||
import us.myles.ViaVersion.metadata.MetadataRewriter;
|
import us.myles.ViaVersion.metadata.MetadataRewriter;
|
||||||
import us.myles.ViaVersion.packets.PacketType;
|
import us.myles.ViaVersion.packets.PacketType;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren