Manually construct WatchableObjects for custom item frames
This commit is contained in:
parent
bdaea49d56
commit
6418a6006f
@ -1,30 +1,33 @@
|
||||
package mineplex.core.imagemap;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.packethandler.PacketInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.DataWatcher;
|
||||
import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject;
|
||||
import net.minecraft.server.v1_8_R3.EntityItemFrame;
|
||||
import net.minecraft.server.v1_8_R3.ItemStack;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItemFrame;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.packethandler.PacketInfo;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class CustomItemFrames extends MiniPlugin implements IPacketHandler
|
||||
@ -73,7 +76,7 @@ public class CustomItemFrames extends MiniPlugin implements IPacketHandler
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
for (WatchableObject meta : packet.b)
|
||||
for (DataWatcher.WatchableObject meta : packet.b)
|
||||
{
|
||||
if (meta.getIndex().a() == 8)
|
||||
{
|
||||
@ -98,12 +101,13 @@ public class CustomItemFrames extends MiniPlugin implements IPacketHandler
|
||||
public void setItem(Player player, ItemFrame frame, org.bukkit.inventory.ItemStack item)
|
||||
{
|
||||
ItemStack nmsItem = CraftItemStack.asNMSCopy(item.clone());
|
||||
EntityItemFrame nmsEntity = ((CraftItemFrame) frame).getHandle();
|
||||
|
||||
DataWatcher watcher = new DataWatcher(nmsEntity);
|
||||
watcher.add(8, 5, EntityItemFrame.META_ITEM, Optional.fromNullable(nmsItem));
|
||||
DataWatcher.WatchableObject<Optional<ItemStack>> frameMetaItem = new DataWatcher.WatchableObject<>(5, 8, nmsItem, EntityItemFrame.META_ITEM, Optional.fromNullable(nmsItem));
|
||||
|
||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata();
|
||||
packet.a = frame.getEntityId();
|
||||
packet.b = Collections.singletonList(frameMetaItem);
|
||||
|
||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(frame.getEntityId(), watcher, true);
|
||||
_ourPackets.add(packet);
|
||||
|
||||
UtilPlayer.sendPacket(player, packet);
|
||||
|
Loading…
Reference in New Issue
Block a user