Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-25 15:50:10 +01:00
Add sending of hand item back :)
Dieser Commit ist enthalten in:
Ursprung
3cc6bf4c51
Commit
bf11edfaa9
@ -8,6 +8,7 @@ import io.netty.channel.socket.SocketChannel;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
||||||
|
|
||||||
@ -69,4 +70,22 @@ public class Core extends JavaPlugin {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ItemStack getHandItem(final ConnectionInfo info) {
|
||||||
|
try {
|
||||||
|
return Bukkit.getScheduler().callSyncMethod(getPlugin(Core.class), new Callable<ItemStack>() {
|
||||||
|
@Override
|
||||||
|
public ItemStack call() throws Exception {
|
||||||
|
if (info.getPlayer() != null) {
|
||||||
|
return info.getPlayer().getItemInHand();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).get(10, TimeUnit.SECONDS);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Error fetching hand item ");
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,14 @@ package us.myles.ViaVersion.transformers;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import us.myles.ViaVersion.CancelException;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import us.myles.ViaVersion.ConnectionInfo;
|
import us.myles.ViaVersion.*;
|
||||||
import us.myles.ViaVersion.PacketUtil;
|
|
||||||
import us.myles.ViaVersion.ReflectionUtil;
|
|
||||||
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
||||||
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 java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class IncomingTransformer {
|
public class IncomingTransformer {
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
@ -168,8 +167,23 @@ public class IncomingTransformer {
|
|||||||
int face = PacketUtil.readVarInt(input);
|
int face = PacketUtil.readVarInt(input);
|
||||||
output.writeByte(face);
|
output.writeByte(face);
|
||||||
int hand = PacketUtil.readVarInt(input);
|
int hand = PacketUtil.readVarInt(input);
|
||||||
// write item in hand
|
|
||||||
output.writeShort(-1);
|
ItemStack inHand = Core.getHandItem(info);
|
||||||
|
Object item = null;
|
||||||
|
try {
|
||||||
|
Method m = ReflectionUtil.obc("inventory.CraftItemStack").getDeclaredMethod("asNMSCopy", ItemStack.class);
|
||||||
|
item = m.invoke(null, inHand);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketUtil.writeItem(item, output);
|
||||||
|
|
||||||
short curX = input.readUnsignedByte();
|
short curX = input.readUnsignedByte();
|
||||||
output.writeByte(curX);
|
output.writeByte(curX);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren