From ce219e208c8fcf1e8fe69c27974975b6abcb5328 Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Sun, 24 Sep 2017 21:17:07 +0300 Subject: [PATCH 01/11] Check the right type --- .../src/main/java/us/myles/ViaVersion/api/PacketWrapper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 6182d5d92..6421495e8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -149,10 +149,11 @@ public class PacketWrapper { } } else { Pair read = readableObjects.poll(); - if (read.getKey().equals(type) || (type.getBaseClass().equals(read.getKey().getBaseClass()) && type.getOutputClass().equals(read.getKey().getOutputClass()))) { + Type rtype = read.getKey(); + if (rtype.equals(type) || (type.getBaseClass().equals(rtype.getBaseClass()) && type.getOutputClass().equals(rtype.getOutputClass()))) { return (T) read.getValue(); } else { - if (type == Type.NOTHING) { + if (rtype == Type.NOTHING) { return read(type); // retry } else { Exception e = new IOException("Unable to read type " + type.getTypeName() + ", found " + read.getKey().getTypeName()); From 343e316e4c7386ce7d0b1402a2bf88dd2289b7bb Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Sun, 24 Sep 2017 21:35:38 +0300 Subject: [PATCH 02/11] Make InvContainerItemProvider --- .../ViaVersion/bukkit/platform/BukkitViaLoader.java | 5 +++++ .../providers/BukkitInvContainerItemProvider.java | 13 +++++++++++++ .../protocol1_12to1_11_1/Protocol1_12To1_11_1.java | 7 +++++++ .../providers/InvContainerItemProvider.java | 11 +++++++++++ 4 files changed, 36 insertions(+) create mode 100644 bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java index 49bf0aa91..3d2a53084 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java @@ -1,10 +1,12 @@ package us.myles.ViaVersion.bukkit.platform; import lombok.AllArgsConstructor; + import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; + import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -12,9 +14,11 @@ import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.platform.ViaPlatformLoader; import us.myles.ViaVersion.bukkit.listeners.UpdateListener; import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.*; +import us.myles.ViaVersion.bukkit.providers.BukkitInvContainerItemProvider; import us.myles.ViaVersion.bukkit.providers.BukkitViaBulkChunkTranslator; import us.myles.ViaVersion.bukkit.providers.BukkitViaMovementTransmitter; import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; @@ -60,6 +64,7 @@ public class BukkitViaLoader implements ViaPlatformLoader { /* Providers */ Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator()); Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter()); + Via.getManager().getProviders().use(InvContainerItemProvider.class, new BukkitInvContainerItemProvider()); Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() { @Override public Item getHandItem(final UserConnection info) { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java new file mode 100644 index 000000000..99c8fa8df --- /dev/null +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java @@ -0,0 +1,13 @@ +package us.myles.ViaVersion.bukkit.providers; + +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; + +public class BukkitInvContainerItemProvider extends InvContainerItemProvider { + + @Override + public boolean registerInvClickPacket(int windowId, short slotId, byte button, short amumber, int mode, UserConnection uconnection) { + // TODO: lets add some stuff here :) + return true; + } +} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java index f153ea234..49d5cb373 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java @@ -12,6 +12,7 @@ import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.entities.Entity1_12Types; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; +import us.myles.ViaVersion.api.platform.providers.ViaProviders; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; @@ -19,6 +20,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_12; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.packets.InventoryPackets; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -384,6 +386,11 @@ public class Protocol1_12To1_11_1 extends Protocol { newId += 3; return newId; } + + @Override + protected void register(ViaProviders providers) { + providers.register(InvContainerItemProvider.class, new InvContainerItemProvider()); + } @Override public void init(UserConnection userConnection) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java new file mode 100644 index 000000000..5455906cb --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java @@ -0,0 +1,11 @@ +package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers; + +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.platform.providers.Provider; + +public class InvContainerItemProvider implements Provider { + + public boolean registerInvClickPacket(int windowId, short slotId, byte button, short amumber, int mode, UserConnection uconnection) { + return false; // not supported :/ plays very sad violin + } +} \ No newline at end of file From b2669129f28607cf6d4b985f73ae27c0effa849e Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Sun, 24 Sep 2017 22:11:54 +0300 Subject: [PATCH 03/11] More work on the inv provider --- .../BukkitInvContainerItemProvider.java | 6 ++++-- .../packets/InventoryPackets.java | 19 ++++++++++++++++++- .../providers/InvContainerItemProvider.java | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java index 99c8fa8df..3b11a50e5 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java @@ -6,8 +6,10 @@ import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainer public class BukkitInvContainerItemProvider extends InvContainerItemProvider { @Override - public boolean registerInvClickPacket(int windowId, short slotId, byte button, short amumber, int mode, UserConnection uconnection) { + public boolean registerInvClickPacket(short windowId, short slotId, short anumber, UserConnection uconnection) { // TODO: lets add some stuff here :) - return true; + //http://wiki.vg/index.php?title=Protocol&oldid=13223#Click_Window + System.out.println("QUICK ACTION windowId: " + windowId + " slotId: " + slotId + " button: " + 0 + " anumber: " + anumber + " mode: " + 1); + return false; // change to true once supported } } \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java index d59b713a2..743d52d0f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.packets; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; @@ -8,6 +9,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.BedRewriter; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; public class InventoryPackets { public static void register(Protocol1_12To1_11_1 protocol) { @@ -118,8 +120,23 @@ public class InventoryPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { + byte button = wrapper.get(Type.BYTE, 0); + int mode = wrapper.get(Type.VAR_INT, 0); Item item = wrapper.get(Type.ITEM, 0); - BedRewriter.toServerItem(item); + // QUICK_MOVE PATCH (Shift + (click/double click)) + if (mode == 1 && button == 0 && item == null) { + short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0); + short slotId = wrapper.get(Type.SHORT, 0); + short anumber = wrapper.get(Type.SHORT, 1); + InvContainerItemProvider provider = Via.getManager().getProviders().get(InvContainerItemProvider.class); + boolean succeed = provider.registerInvClickPacket(windowId, slotId, anumber, wrapper.user()); + if (succeed) { + wrapper.cancel(); + } + // otherwise just pass through so the server sends the PacketPlayOutTransaction packet. + } else { + BedRewriter.toServerItem(item); + } } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java index 5455906cb..e928136ea 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java @@ -5,7 +5,7 @@ import us.myles.ViaVersion.api.platform.providers.Provider; public class InvContainerItemProvider implements Provider { - public boolean registerInvClickPacket(int windowId, short slotId, byte button, short amumber, int mode, UserConnection uconnection) { + public boolean registerInvClickPacket(short windowId, short slotId, short anumber, UserConnection uconnection) { return false; // not supported :/ plays very sad violin } } \ No newline at end of file From 976c418c9effd6f08691af7aa95cf8eba60ffdbd Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Mon, 25 Sep 2017 16:13:56 +0300 Subject: [PATCH 04/11] Start implementing inv update task --- .../BukkitInvContainerUpdateTask.java | 22 +++++++++++++++++++ .../BukkitInvContainerItemProvider.java | 17 ++++++++++++-- .../storage/InvItemStorage.java | 13 +++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java new file mode 100644 index 000000000..5f6d9e977 --- /dev/null +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java @@ -0,0 +1,22 @@ +package us.myles.ViaVersion.bukkit.protocol1_12to1_11_1; + +import java.util.UUID; + +import us.myles.ViaVersion.bukkit.providers.BukkitInvContainerItemProvider; + +public class BukkitInvContainerUpdateTask implements Runnable { + + private BukkitInvContainerItemProvider provider; + private UUID uuid; + + public BukkitInvContainerUpdateTask(BukkitInvContainerItemProvider provider, UUID uuid) { + this.provider = provider; + this.uuid = uuid; + } + + @Override + public void run() { + // TODO Auto-generated method stub + provider.onTaskExecuted(uuid); + } +} \ No newline at end of file diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java index 3b11a50e5..a02078e3b 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java @@ -1,15 +1,28 @@ package us.myles.ViaVersion.bukkit.providers; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.bukkit.protocol1_12to1_11_1.BukkitInvContainerUpdateTask; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; public class BukkitInvContainerItemProvider extends InvContainerItemProvider { + private static Map updateTasks = new ConcurrentHashMap<>(); + @Override public boolean registerInvClickPacket(short windowId, short slotId, short anumber, UserConnection uconnection) { + ProtocolInfo info = uconnection.get(ProtocolInfo.class); // TODO: lets add some stuff here :) - //http://wiki.vg/index.php?title=Protocol&oldid=13223#Click_Window - System.out.println("QUICK ACTION windowId: " + windowId + " slotId: " + slotId + " button: " + 0 + " anumber: " + anumber + " mode: " + 1); + // http://wiki.vg/index.php?title=Protocol&oldid=13223#Click_Window + System.out.println("info: " + info + " QUICK ACTION windowId: " + windowId + " slotId: " + slotId + " button: " + 0 + " anumber: " + anumber + " mode: " + 1); return false; // change to true once supported } + + public void onTaskExecuted(UUID uuid) { + updateTasks.remove(uuid); + } } \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java new file mode 100644 index 000000000..d20fa9d0e --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java @@ -0,0 +1,13 @@ +package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public class InvItemStorage { + + private short windowId; + private short slotId; + private short actionNumber; +} \ No newline at end of file From b3d3921f6ecea0c446e1b4ba2ac0a068680ed9bc Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Mon, 25 Sep 2017 18:04:39 +0300 Subject: [PATCH 05/11] Support item provider on a 1.8 server ... 1.9 is on the way --- .../BukkitInvContainerUpdateTask.java | 39 ++++- .../BukkitInvContainerItemProvider.java | 145 +++++++++++++++++- .../storage/InvItemStorage.java | 2 + 3 files changed, 180 insertions(+), 6 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java index 5f6d9e977..39068f2d8 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java @@ -1,22 +1,55 @@ package us.myles.ViaVersion.bukkit.protocol1_12to1_11_1; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.UUID; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + import us.myles.ViaVersion.bukkit.providers.BukkitInvContainerItemProvider; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.InvItemStorage; public class BukkitInvContainerUpdateTask implements Runnable { private BukkitInvContainerItemProvider provider; - private UUID uuid; + private final UUID uuid; + private final List items; public BukkitInvContainerUpdateTask(BukkitInvContainerItemProvider provider, UUID uuid) { this.provider = provider; this.uuid = uuid; + this.items = Collections.synchronizedList(new ArrayList<>()); + } + + public void addItem(short windowId, short slotId, short anumber) { + InvItemStorage storage = new InvItemStorage(windowId, slotId, anumber); + items.add(storage); } @Override public void run() { - // TODO Auto-generated method stub - provider.onTaskExecuted(uuid); + Player p = Bukkit.getServer().getPlayer(uuid); + if (p == null) { + provider.onTaskExecuted(uuid); + return; + } + try { + synchronized (items) { + for (InvItemStorage storage : items) { + Object packet = provider.buildWindowClickPacket(p, storage); + boolean result = provider.sendPlayer(p, packet); + System.out.println("item result: " + result); + if (!result) { + break; + } + } + System.out.println("items: " + items); + items.clear(); + } + } finally { + provider.onTaskExecuted(uuid); + } } } \ No newline at end of file diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java index a02078e3b..7fad14feb 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java @@ -1,28 +1,167 @@ package us.myles.ViaVersion.bukkit.providers; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitScheduler; + import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.bukkit.protocol1_12to1_11_1.BukkitInvContainerUpdateTask; +import us.myles.ViaVersion.bukkit.util.NMSUtil; import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.InvItemStorage; +import us.myles.ViaVersion.util.ReflectionUtil; public class BukkitInvContainerItemProvider extends InvContainerItemProvider { private static Map updateTasks = new ConcurrentHashMap<>(); + private boolean supported; + // packet class + private Class wclickPacketClass; + // Use for nms + private Method nmsItemMethod; + private Method ephandle; + private Field connection; + private Method packetMethod; + + public BukkitInvContainerItemProvider() { + this.supported = isSupported(); + setupReflection(); + } @Override public boolean registerInvClickPacket(short windowId, short slotId, short anumber, UserConnection uconnection) { + if (!supported) { + return false; + } ProtocolInfo info = uconnection.get(ProtocolInfo.class); - // TODO: lets add some stuff here :) + UUID uuid = info.getUuid(); + BukkitInvContainerUpdateTask utask = updateTasks.get(uuid); + final boolean registered = utask != null; + if (!registered) { + utask = new BukkitInvContainerUpdateTask(this, uuid); + updateTasks.put(uuid, utask); + } // http://wiki.vg/index.php?title=Protocol&oldid=13223#Click_Window - System.out.println("info: " + info + " QUICK ACTION windowId: " + windowId + " slotId: " + slotId + " button: " + 0 + " anumber: " + anumber + " mode: " + 1); - return false; // change to true once supported + utask.addItem(windowId, slotId, anumber); + if (!registered) { + scheduleTask(utask); + } + return true; + } + + public Object buildWindowClickPacket(Player p, InvItemStorage storage) { + if (!supported) { + return null; + } + InventoryView inv = p.getOpenInventory(); + short slotId = storage.getSlotId(); + if (slotId > inv.countSlots()) { + return null; // wrong container open? + } + ItemStack itemstack = inv.getItem(slotId); + if (itemstack == null) { + return null; + } + Object cinstance = null; + try { + Object nmsItem = nmsItemMethod.invoke(null, itemstack); + // TODO: PASSTHROUGH PROTOCOLS? (Make InvItemStorage inheritance from Item?) + cinstance = wclickPacketClass.newInstance(); + ReflectionUtil.set(cinstance, "a", (int) storage.getWindowId()); + ReflectionUtil.set(cinstance, "slot", (int) slotId); + ReflectionUtil.set(cinstance, "button", 0); // shift + left mouse click + ReflectionUtil.set(cinstance, "d", storage.getActionNumber()); + ReflectionUtil.set(cinstance, "item", nmsItem); + // TODO: THIS MUST BE AN ENUM on 1.9+ SERVERS!! + ReflectionUtil.set(cinstance, "shift", 1); // mode + } catch (Exception e) { + e.printStackTrace(); + } + return cinstance; + } + + public boolean sendPlayer(Player p, Object packet) { + if (packet == null) { + return false; + } + try { + Object entityPlayer = ephandle.invoke(p); + Object pconnection = connection.get(entityPlayer); + // send + packetMethod.invoke(pconnection, packet); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + return false; + } + return true; } public void onTaskExecuted(UUID uuid) { updateTasks.remove(uuid); } + + private void scheduleTask(BukkitInvContainerUpdateTask utask) { + BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); + Plugin instance = Bukkit.getServer().getPluginManager().getPlugin("ViaVersion"); + scheduler.runTaskLater(instance, utask, 5); // 5 ticks later. + } + + private void setupReflection() { + if (!supported) { + return; + } + try { + this.wclickPacketClass = NMSUtil.nms("PacketPlayInWindowClick"); + Class citemStack = NMSUtil.obc("inventory.CraftItemStack"); + this.nmsItemMethod = citemStack.getDeclaredMethod("asNMSCopy", ItemStack.class); + } catch (Exception e) { + this.supported = false; + return; + } + try { + this.ephandle = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle"); + } catch (NoSuchMethodException | ClassNotFoundException e) { + this.supported = false; + throw new RuntimeException("Couldn't find CraftPlayer", e); + } + try { + this.connection = NMSUtil.nms("EntityPlayer").getDeclaredField("playerConnection"); + } catch (NoSuchFieldException | ClassNotFoundException e) { + this.supported = false; + throw new RuntimeException("Couldn't find Player Connection", e); + } + try { + this.packetMethod = NMSUtil.nms("PlayerConnection").getDeclaredMethod("a", wclickPacketClass); + } catch (NoSuchMethodException | ClassNotFoundException e) { + this.supported = false; + throw new RuntimeException("Couldn't find CraftPlayer", e); + } + } + + private boolean isSupported() { + int protocolId = ProtocolRegistry.SERVER_PROTOCOL; + if (protocolId == 47) { + return true; // 1.8 + } /**else if (protocolId >= 107 && protocolId <= 110) { + return true; // 1.9 + } else if (protocolId == 210) { + return true; // 1.10 + } else if (protocolId == 315 || protocolId == 316) { + return true; // 1.11 + }*/ + // this is not needed on 1.12+ + return false; + } } \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java index d20fa9d0e..9deb38231 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java @@ -2,8 +2,10 @@ package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.ToString; @AllArgsConstructor +@ToString @Getter public class InvItemStorage { From 1c4e0051a06b0943be13de00c68a68ed3adedabf Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Mon, 25 Sep 2017 21:49:43 +0300 Subject: [PATCH 06/11] Finish inventory provider + Support 1.9+ servers --- .../BukkitInvContainerUpdateTask.java | 2 -- .../BukkitInvContainerItemProvider.java | 27 ++++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java index 39068f2d8..4e9fad983 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java @@ -40,12 +40,10 @@ public class BukkitInvContainerUpdateTask implements Runnable { for (InvItemStorage storage : items) { Object packet = provider.buildWindowClickPacket(p, storage); boolean result = provider.sendPlayer(p, packet); - System.out.println("item result: " + result); if (!result) { break; } } - System.out.println("items: " + items); items.clear(); } } finally { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java index 7fad14feb..d4e7746c1 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java @@ -29,6 +29,7 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { private boolean supported; // packet class private Class wclickPacketClass; + private Object clickTypeEnum; // Use for nms private Method nmsItemMethod; private Method ephandle; @@ -76,16 +77,19 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { } Object cinstance = null; try { - Object nmsItem = nmsItemMethod.invoke(null, itemstack); - // TODO: PASSTHROUGH PROTOCOLS? (Make InvItemStorage inheritance from Item?) cinstance = wclickPacketClass.newInstance(); + Object nmsItem = nmsItemMethod.invoke(null, itemstack); ReflectionUtil.set(cinstance, "a", (int) storage.getWindowId()); ReflectionUtil.set(cinstance, "slot", (int) slotId); ReflectionUtil.set(cinstance, "button", 0); // shift + left mouse click ReflectionUtil.set(cinstance, "d", storage.getActionNumber()); ReflectionUtil.set(cinstance, "item", nmsItem); - // TODO: THIS MUST BE AN ENUM on 1.9+ SERVERS!! - ReflectionUtil.set(cinstance, "shift", 1); // mode + int protocolId = ProtocolRegistry.SERVER_PROTOCOL; + if (protocolId == 47) { + ReflectionUtil.set(cinstance, "shift", 1); + } else if (protocolId >= 107) { // 1.9+ + ReflectionUtil.set(cinstance, "shift", clickTypeEnum); + } } catch (Exception e) { e.printStackTrace(); } @@ -115,7 +119,7 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { private void scheduleTask(BukkitInvContainerUpdateTask utask) { BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); Plugin instance = Bukkit.getServer().getPluginManager().getPlugin("ViaVersion"); - scheduler.runTaskLater(instance, utask, 5); // 5 ticks later. + scheduler.runTaskLater(instance, utask, 2); // 2 ticks later (possible double click action). } private void setupReflection() { @@ -124,6 +128,9 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { } try { this.wclickPacketClass = NMSUtil.nms("PacketPlayInWindowClick"); + Class eclassz = NMSUtil.nms("InventoryClickType"); + Object[] constants = eclassz.getEnumConstants(); + this.clickTypeEnum = constants[1]; // QUICK_MOVE Class citemStack = NMSUtil.obc("inventory.CraftItemStack"); this.nmsItemMethod = citemStack.getDeclaredMethod("asNMSCopy", ItemStack.class); } catch (Exception e) { @@ -152,15 +159,9 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { private boolean isSupported() { int protocolId = ProtocolRegistry.SERVER_PROTOCOL; - if (protocolId == 47) { + if (protocolId >= 47 && protocolId <= 316) { return true; // 1.8 - } /**else if (protocolId >= 107 && protocolId <= 110) { - return true; // 1.9 - } else if (protocolId == 210) { - return true; // 1.10 - } else if (protocolId == 315 || protocolId == 316) { - return true; // 1.11 - }*/ + } // this is not needed on 1.12+ return false; } From d57ef2b303c0fd351df7b268ee1799a47cb8af36 Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Thu, 28 Sep 2017 20:44:49 +0300 Subject: [PATCH 07/11] Fix inv provider not working on 1.8 servers --- .../BukkitInvContainerItemProvider.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java index d4e7746c1..c52256651 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java @@ -16,6 +16,7 @@ import org.bukkit.scheduler.BukkitScheduler; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; +import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.bukkit.protocol1_12to1_11_1.BukkitInvContainerUpdateTask; import us.myles.ViaVersion.bukkit.util.NMSUtil; import us.myles.ViaVersion.protocols.base.ProtocolInfo; @@ -68,6 +69,9 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { } InventoryView inv = p.getOpenInventory(); short slotId = storage.getSlotId(); + if (slotId < 0) { // clicked out of inv slot + return null; + } if (slotId > inv.countSlots()) { return null; // wrong container open? } @@ -85,9 +89,9 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { ReflectionUtil.set(cinstance, "d", storage.getActionNumber()); ReflectionUtil.set(cinstance, "item", nmsItem); int protocolId = ProtocolRegistry.SERVER_PROTOCOL; - if (protocolId == 47) { + if (protocolId == ProtocolVersion.v1_8.getId()) { ReflectionUtil.set(cinstance, "shift", 1); - } else if (protocolId >= 107) { // 1.9+ + } else if (protocolId >= ProtocolVersion.v1_9.getId()) { // 1.9+ ReflectionUtil.set(cinstance, "shift", clickTypeEnum); } } catch (Exception e) { @@ -128,14 +132,17 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { } try { this.wclickPacketClass = NMSUtil.nms("PacketPlayInWindowClick"); - Class eclassz = NMSUtil.nms("InventoryClickType"); - Object[] constants = eclassz.getEnumConstants(); - this.clickTypeEnum = constants[1]; // QUICK_MOVE + int protocolId = ProtocolRegistry.SERVER_PROTOCOL; + if (protocolId >= ProtocolVersion.v1_9.getId()) { + Class eclassz = NMSUtil.nms("InventoryClickType"); + Object[] constants = eclassz.getEnumConstants(); + this.clickTypeEnum = constants[1]; // QUICK_MOVE + } Class citemStack = NMSUtil.obc("inventory.CraftItemStack"); this.nmsItemMethod = citemStack.getDeclaredMethod("asNMSCopy", ItemStack.class); } catch (Exception e) { this.supported = false; - return; + throw new RuntimeException("Couldn't find required inventory classes", e); } try { this.ephandle = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle"); @@ -159,10 +166,10 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { private boolean isSupported() { int protocolId = ProtocolRegistry.SERVER_PROTOCOL; - if (protocolId >= 47 && protocolId <= 316) { - return true; // 1.8 + if (protocolId >= ProtocolVersion.v1_8.getId() && protocolId <= ProtocolVersion.v1_11_1.getId()) { + return true; // 1.8-1.11.2 } - // this is not needed on 1.12+ + // this is not needed on 1.12+ servers return false; } } \ No newline at end of file From 2703e849cbad9d93fe174c05b82b368735c53bbe Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Thu, 28 Sep 2017 20:47:13 +0300 Subject: [PATCH 08/11] Increase the waiting time --- .../bukkit/providers/BukkitInvContainerItemProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java index c52256651..1ef717745 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java @@ -123,7 +123,7 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { private void scheduleTask(BukkitInvContainerUpdateTask utask) { BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); Plugin instance = Bukkit.getServer().getPluginManager().getPlugin("ViaVersion"); - scheduler.runTaskLater(instance, utask, 2); // 2 ticks later (possible double click action). + scheduler.runTaskLater(instance, utask, 5); // 5 ticks later (possible double click action). } private void setupReflection() { From a27808ade12944f854d3add43c5d74be9569536e Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Thu, 5 Oct 2017 22:05:53 +0300 Subject: [PATCH 09/11] Add config for quick move action patch --- .../ViaVersion/bukkit/platform/BukkitConfigAPI.java | 5 +++++ .../ViaVersion/bukkit/platform/BukkitViaLoader.java | 4 +++- .../ViaVersion/bungee/platform/BungeeConfigAPI.java | 7 ++++++- .../java/us/myles/ViaVersion/api/ViaVersionConfig.java | 9 ++++++++- .../protocol1_12to1_11_1/packets/InventoryPackets.java | 6 +++++- common/src/main/resources/assets/viaversion/config.yml | 2 ++ .../ViaVersion/sponge/platform/SpongeConfigAPI.java | 7 ++++++- 7 files changed, 35 insertions(+), 5 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java index b4ccbc593..b95e0b5c1 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java @@ -164,6 +164,11 @@ public class BukkitConfigAPI extends Config implements ViaVersionConfig { public boolean is1_12NBTArrayFix() { return getBoolean("chat-nbt-fix", true); } + + @Override + public boolean is1_12QuickMoveActionFix() { + return getBoolean("quick-move-action-fix", true); + } @Override public List getBlockedProtocols() { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java index 3d2a53084..d511ec0d1 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java @@ -64,7 +64,9 @@ public class BukkitViaLoader implements ViaPlatformLoader { /* Providers */ Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator()); Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter()); - Via.getManager().getProviders().use(InvContainerItemProvider.class, new BukkitInvContainerItemProvider()); + if (plugin.getConf().is1_12QuickMoveActionFix()) { + Via.getManager().getProviders().use(InvContainerItemProvider.class, new BukkitInvContainerItemProvider()); + } Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() { @Override public Item getHandItem(final UserConnection info) { diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java index a69b8e056..e4f8d7a1f 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java @@ -10,7 +10,7 @@ import java.net.URL; import java.util.*; public class BungeeConfigAPI extends Config implements ViaVersionConfig { - private static List UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "anti-xray-patch"); + private static List UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "anti-xray-patch", "quick-move-action-fix"); public BungeeConfigAPI(File configFile) { super(new File(configFile, "config.yml")); @@ -203,6 +203,11 @@ public class BungeeConfigAPI extends Config implements ViaVersionConfig { public boolean is1_12NBTArrayFix() { return getBoolean("chat-nbt-fix", true); } + + @Override + public boolean is1_12QuickMoveActionFix() { + return false; + } @Override public List getBlockedProtocols() { diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java index 90f85ff39..98578e5d0 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -209,7 +209,14 @@ public interface ViaVersionConfig { * @return True if enabled */ boolean is1_12NBTArrayFix(); - + + /** + * Should we fix shift quick move action for 1.12 clients + * + * @return True if enabled + */ + boolean is1_12QuickMoveActionFix(); + /** * Get the blocked protocols * diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java index 743d52d0f..4a473ec48 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java @@ -120,9 +120,13 @@ public class InventoryPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { + Item item = wrapper.get(Type.ITEM, 0); + if (!Via.getConfig().is1_12QuickMoveActionFix()) { + BedRewriter.toServerItem(item); + return; + } byte button = wrapper.get(Type.BYTE, 0); int mode = wrapper.get(Type.VAR_INT, 0); - Item item = wrapper.get(Type.ITEM, 0); // QUICK_MOVE PATCH (Shift + (click/double click)) if (mode == 1 && button == 0 && item == null) { short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0); diff --git a/common/src/main/resources/assets/viaversion/config.yml b/common/src/main/resources/assets/viaversion/config.yml index 43855685b..a90a40505 100644 --- a/common/src/main/resources/assets/viaversion/config.yml +++ b/common/src/main/resources/assets/viaversion/config.yml @@ -84,6 +84,8 @@ hologram-y: -0.96 piston-animation-patch: false # Should we fix nbt for 1.12 and above clients in chat messages (causes invalid item) chat-nbt-fix: true +# Should we fix shift quick move action for 1.12 clients (causes shift + double click not to work when moving items) (only works on 1.8-1.11.2 bukkit based servers) +quick-move-action-fix: true # #----------------------------------------------------------# # 1.9 & 1.10 CLIENTS ON 1.8 SERVERS OPTIONS # diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java index 5910be1f1..da5cd7dcc 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java @@ -13,7 +13,7 @@ import java.util.Map; import java.util.Optional; public class SpongeConfigAPI extends Config implements ViaVersionConfig { - private static List UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval", "bungee-ping-save", "bungee-servers"); + private static List UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval", "bungee-ping-save", "bungee-servers", "quick-move-action-fix"); private final PluginContainer pluginContainer; public SpongeConfigAPI(PluginContainer pluginContainer, File configFile) { @@ -185,6 +185,11 @@ public class SpongeConfigAPI extends Config implements ViaVersionConfig { public boolean is1_12NBTArrayFix() { return getBoolean("chat-nbt-fix", true); } + + @Override + public boolean is1_12QuickMoveActionFix() { + return false; + } @Override public List getBlockedProtocols() { From 471f1ae71d623a54bd7c96aaedfa3d75cc714ecd Mon Sep 17 00:00:00 2001 From: mmxw11 Date: Thu, 5 Oct 2017 22:11:06 +0300 Subject: [PATCH 10/11] Try make it compile with Travis... ... don't use diamond operators? --- .../protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java | 2 +- .../bukkit/providers/BukkitInvContainerItemProvider.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java index 4e9fad983..bda6e06ba 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java @@ -20,7 +20,7 @@ public class BukkitInvContainerUpdateTask implements Runnable { public BukkitInvContainerUpdateTask(BukkitInvContainerItemProvider provider, UUID uuid) { this.provider = provider; this.uuid = uuid; - this.items = Collections.synchronizedList(new ArrayList<>()); + this.items = Collections.synchronizedList(new ArrayList()); } public void addItem(short windowId, short slotId, short anumber) { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java index 1ef717745..94faba7a6 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java @@ -26,7 +26,7 @@ import us.myles.ViaVersion.util.ReflectionUtil; public class BukkitInvContainerItemProvider extends InvContainerItemProvider { - private static Map updateTasks = new ConcurrentHashMap<>(); + private static Map updateTasks = new ConcurrentHashMap(); private boolean supported; // packet class private Class wclickPacketClass; From e372a5682701e680953eb231ad49b27062f410f2 Mon Sep 17 00:00:00 2001 From: Myles Date: Sun, 8 Oct 2017 15:33:43 +0100 Subject: [PATCH 11/11] Refactor code to make field / class names better --- .../us/myles/ViaVersion/ViaVersionPlugin.java | 5 + .../bukkit/platform/BukkitViaLoader.java | 6 +- ... => BukkitInventoryQuickMoveProvider.java} | 105 ++++++++---------- .../BukkitInventoryUpdateTask.java} | 22 ++-- .../us/myles/ViaVersion/BungeePlugin.java | 5 + .../ViaVersion/api/platform/ViaPlatform.java | 10 ++ .../Protocol1_12To1_11_1.java | 4 +- .../packets/InventoryPackets.java | 10 +- ...r.java => InventoryQuickMoveProvider.java} | 4 +- ...vItemStorage.java => ItemTransaction.java} | 5 +- .../us/myles/ViaVersion/SpongePlugin.java | 7 +- 11 files changed, 97 insertions(+), 86 deletions(-) rename bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/{BukkitInvContainerItemProvider.java => BukkitInventoryQuickMoveProvider.java} (60%) rename bukkit/src/main/java/us/myles/ViaVersion/bukkit/{protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java => tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java} (61%) rename common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/{InvContainerItemProvider.java => InventoryQuickMoveProvider.java} (58%) rename common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/{InvItemStorage.java => ItemTransaction.java} (79%) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index fe9d09438..a8fa210fc 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -174,6 +174,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { } } + @Override + public TaskId runSync(Runnable runnable, Long ticks) { + return new BukkitTaskId(getServer().getScheduler().runTaskLater(this, runnable, ticks).getTaskId()); + } + @Override public TaskId runRepeatingSync(Runnable runnable, Long ticks) { return new BukkitTaskId(getServer().getScheduler().runTaskTimer(this, runnable, ticks, 0).getTaskId()); diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java index d511ec0d1..a6525ae32 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java @@ -14,11 +14,11 @@ import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.platform.ViaPlatformLoader; import us.myles.ViaVersion.bukkit.listeners.UpdateListener; import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.*; -import us.myles.ViaVersion.bukkit.providers.BukkitInvContainerItemProvider; +import us.myles.ViaVersion.bukkit.providers.BukkitInventoryQuickMoveProvider; import us.myles.ViaVersion.bukkit.providers.BukkitViaBulkChunkTranslator; import us.myles.ViaVersion.bukkit.providers.BukkitViaMovementTransmitter; import us.myles.ViaVersion.protocols.base.ProtocolInfo; -import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; @@ -65,7 +65,7 @@ public class BukkitViaLoader implements ViaPlatformLoader { Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator()); Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter()); if (plugin.getConf().is1_12QuickMoveActionFix()) { - Via.getManager().getProviders().use(InvContainerItemProvider.class, new BukkitInvContainerItemProvider()); + Via.getManager().getProviders().use(InventoryQuickMoveProvider.class, new BukkitInventoryQuickMoveProvider()); } Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() { @Override diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java similarity index 60% rename from bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java rename to bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java index 94faba7a6..df0c48e62 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInvContainerItemProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java @@ -1,5 +1,19 @@ package us.myles.ViaVersion.bukkit.providers; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; +import us.myles.ViaVersion.api.Via; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.protocol.ProtocolRegistry; +import us.myles.ViaVersion.api.protocol.ProtocolVersion; +import us.myles.ViaVersion.bukkit.tasks.protocol1_12to1_11_1.BukkitInventoryUpdateTask; +import us.myles.ViaVersion.bukkit.util.NMSUtil; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.ItemTransaction; +import us.myles.ViaVersion.util.ReflectionUtil; + import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -7,63 +21,46 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryView; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitScheduler; +public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider { -import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.protocol.ProtocolRegistry; -import us.myles.ViaVersion.api.protocol.ProtocolVersion; -import us.myles.ViaVersion.bukkit.protocol1_12to1_11_1.BukkitInvContainerUpdateTask; -import us.myles.ViaVersion.bukkit.util.NMSUtil; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; -import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; -import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.InvItemStorage; -import us.myles.ViaVersion.util.ReflectionUtil; - -public class BukkitInvContainerItemProvider extends InvContainerItemProvider { - - private static Map updateTasks = new ConcurrentHashMap(); + private static Map updateTasks = new ConcurrentHashMap(); private boolean supported; // packet class - private Class wclickPacketClass; + private Class windowClickPacketClass; private Object clickTypeEnum; // Use for nms private Method nmsItemMethod; - private Method ephandle; + private Method craftPlayerHandle; private Field connection; private Method packetMethod; - public BukkitInvContainerItemProvider() { + public BukkitInventoryQuickMoveProvider() { this.supported = isSupported(); setupReflection(); } @Override - public boolean registerInvClickPacket(short windowId, short slotId, short anumber, UserConnection uconnection) { + public boolean registerQuickMove(short windowId, short slotId, short actionId, UserConnection userConnection) { if (!supported) { return false; } - ProtocolInfo info = uconnection.get(ProtocolInfo.class); + ProtocolInfo info = userConnection.get(ProtocolInfo.class); UUID uuid = info.getUuid(); - BukkitInvContainerUpdateTask utask = updateTasks.get(uuid); - final boolean registered = utask != null; + BukkitInventoryUpdateTask updateTask = updateTasks.get(uuid); + final boolean registered = updateTask != null; if (!registered) { - utask = new BukkitInvContainerUpdateTask(this, uuid); - updateTasks.put(uuid, utask); + updateTask = new BukkitInventoryUpdateTask(this, uuid); + updateTasks.put(uuid, updateTask); } // http://wiki.vg/index.php?title=Protocol&oldid=13223#Click_Window - utask.addItem(windowId, slotId, anumber); + updateTask.addItem(windowId, slotId, actionId); if (!registered) { - scheduleTask(utask); + Via.getPlatform().runSync(updateTask, 5L); } return true; } - public Object buildWindowClickPacket(Player p, InvItemStorage storage) { + public Object buildWindowClickPacket(Player p, ItemTransaction storage) { if (!supported) { return null; } @@ -79,25 +76,25 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { if (itemstack == null) { return null; } - Object cinstance = null; + Object packet = null; try { - cinstance = wclickPacketClass.newInstance(); + packet = windowClickPacketClass.newInstance(); Object nmsItem = nmsItemMethod.invoke(null, itemstack); - ReflectionUtil.set(cinstance, "a", (int) storage.getWindowId()); - ReflectionUtil.set(cinstance, "slot", (int) slotId); - ReflectionUtil.set(cinstance, "button", 0); // shift + left mouse click - ReflectionUtil.set(cinstance, "d", storage.getActionNumber()); - ReflectionUtil.set(cinstance, "item", nmsItem); + ReflectionUtil.set(packet, "a", (int) storage.getWindowId()); + ReflectionUtil.set(packet, "slot", (int) slotId); + ReflectionUtil.set(packet, "button", 0); // shift + left mouse click + ReflectionUtil.set(packet, "d", storage.getActionId()); + ReflectionUtil.set(packet, "item", nmsItem); int protocolId = ProtocolRegistry.SERVER_PROTOCOL; if (protocolId == ProtocolVersion.v1_8.getId()) { - ReflectionUtil.set(cinstance, "shift", 1); + ReflectionUtil.set(packet, "shift", 1); } else if (protocolId >= ProtocolVersion.v1_9.getId()) { // 1.9+ - ReflectionUtil.set(cinstance, "shift", clickTypeEnum); + ReflectionUtil.set(packet, "shift", clickTypeEnum); } } catch (Exception e) { e.printStackTrace(); } - return cinstance; + return packet; } public boolean sendPlayer(Player p, Object packet) { @@ -105,10 +102,10 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { return false; } try { - Object entityPlayer = ephandle.invoke(p); - Object pconnection = connection.get(entityPlayer); + Object entityPlayer = craftPlayerHandle.invoke(p); + Object playerConnection = connection.get(entityPlayer); // send - packetMethod.invoke(pconnection, packet); + packetMethod.invoke(playerConnection, packet); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); return false; @@ -120,46 +117,36 @@ public class BukkitInvContainerItemProvider extends InvContainerItemProvider { updateTasks.remove(uuid); } - private void scheduleTask(BukkitInvContainerUpdateTask utask) { - BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); - Plugin instance = Bukkit.getServer().getPluginManager().getPlugin("ViaVersion"); - scheduler.runTaskLater(instance, utask, 5); // 5 ticks later (possible double click action). - } - private void setupReflection() { if (!supported) { return; } try { - this.wclickPacketClass = NMSUtil.nms("PacketPlayInWindowClick"); + this.windowClickPacketClass = NMSUtil.nms("PacketPlayInWindowClick"); int protocolId = ProtocolRegistry.SERVER_PROTOCOL; if (protocolId >= ProtocolVersion.v1_9.getId()) { Class eclassz = NMSUtil.nms("InventoryClickType"); Object[] constants = eclassz.getEnumConstants(); this.clickTypeEnum = constants[1]; // QUICK_MOVE } - Class citemStack = NMSUtil.obc("inventory.CraftItemStack"); - this.nmsItemMethod = citemStack.getDeclaredMethod("asNMSCopy", ItemStack.class); + Class craftItemStack = NMSUtil.obc("inventory.CraftItemStack"); + this.nmsItemMethod = craftItemStack.getDeclaredMethod("asNMSCopy", ItemStack.class); } catch (Exception e) { - this.supported = false; throw new RuntimeException("Couldn't find required inventory classes", e); } try { - this.ephandle = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle"); + this.craftPlayerHandle = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle"); } catch (NoSuchMethodException | ClassNotFoundException e) { - this.supported = false; throw new RuntimeException("Couldn't find CraftPlayer", e); } try { this.connection = NMSUtil.nms("EntityPlayer").getDeclaredField("playerConnection"); } catch (NoSuchFieldException | ClassNotFoundException e) { - this.supported = false; throw new RuntimeException("Couldn't find Player Connection", e); } try { - this.packetMethod = NMSUtil.nms("PlayerConnection").getDeclaredMethod("a", wclickPacketClass); + this.packetMethod = NMSUtil.nms("PlayerConnection").getDeclaredMethod("a", windowClickPacketClass); } catch (NoSuchMethodException | ClassNotFoundException e) { - this.supported = false; throw new RuntimeException("Couldn't find CraftPlayer", e); } } diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java similarity index 61% rename from bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java rename to bukkit/src/main/java/us/myles/ViaVersion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java index bda6e06ba..e83d3772d 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/protocol1_12to1_11_1/BukkitInvContainerUpdateTask.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.bukkit.protocol1_12to1_11_1; +package us.myles.ViaVersion.bukkit.tasks.protocol1_12to1_11_1; import java.util.ArrayList; import java.util.Collections; @@ -8,23 +8,23 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import us.myles.ViaVersion.bukkit.providers.BukkitInvContainerItemProvider; -import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.InvItemStorage; +import us.myles.ViaVersion.bukkit.providers.BukkitInventoryQuickMoveProvider; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.ItemTransaction; -public class BukkitInvContainerUpdateTask implements Runnable { +public class BukkitInventoryUpdateTask implements Runnable { - private BukkitInvContainerItemProvider provider; + private BukkitInventoryQuickMoveProvider provider; private final UUID uuid; - private final List items; + private final List items; - public BukkitInvContainerUpdateTask(BukkitInvContainerItemProvider provider, UUID uuid) { + public BukkitInventoryUpdateTask(BukkitInventoryQuickMoveProvider provider, UUID uuid) { this.provider = provider; this.uuid = uuid; - this.items = Collections.synchronizedList(new ArrayList()); + this.items = Collections.synchronizedList(new ArrayList()); } - public void addItem(short windowId, short slotId, short anumber) { - InvItemStorage storage = new InvItemStorage(windowId, slotId, anumber); + public void addItem(short windowId, short slotId, short actionId) { + ItemTransaction storage = new ItemTransaction(windowId, slotId, actionId); items.add(storage); } @@ -37,7 +37,7 @@ public class BukkitInvContainerUpdateTask implements Runnable { } try { synchronized (items) { - for (InvItemStorage storage : items) { + for (ItemTransaction storage : items) { Object packet = provider.buildWindowClickPacket(p, storage); boolean result = provider.sendPlayer(p, packet); if (!result) { diff --git a/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java b/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java index 2f22fce64..a8a66d113 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java +++ b/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java @@ -79,6 +79,11 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener { return runAsync(runnable); } + @Override + public TaskId runSync(Runnable runnable, Long ticks) { + return new BungeeTaskId(getProxy().getScheduler().schedule(this, runnable, ticks * 50, TimeUnit.MILLISECONDS).getId()); + } + @Override public TaskId runRepeatingSync(Runnable runnable, Long ticks) { return new BungeeTaskId(getProxy().getScheduler().schedule(this, runnable, 0, ticks * 50, TimeUnit.MILLISECONDS).getId()); diff --git a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java index d241dbc03..796910a52 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java +++ b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java @@ -59,6 +59,16 @@ public interface ViaPlatform { */ TaskId runSync(Runnable runnable); + /** + * Run a task Sync after a interval + * This must be only used after plugin enable. + * + * @param runnable The task to run + * @param ticks The interval to run it after + * @return The Task ID + */ + TaskId runSync(Runnable runnable, Long ticks); + /** * Run a task at a repeating interval. * Initial interval is the same as repeat. diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java index 49d5cb373..89ffcb518 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java @@ -20,7 +20,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_12; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.packets.InventoryPackets; -import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -389,7 +389,7 @@ public class Protocol1_12To1_11_1 extends Protocol { @Override protected void register(ViaProviders providers) { - providers.register(InvContainerItemProvider.class, new InvContainerItemProvider()); + providers.register(InventoryQuickMoveProvider.class, new InventoryQuickMoveProvider()); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java index 4a473ec48..08231ad12 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java @@ -9,7 +9,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.BedRewriter; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1; -import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InvContainerItemProvider; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider; public class InventoryPackets { public static void register(Protocol1_12To1_11_1 protocol) { @@ -128,12 +128,12 @@ public class InventoryPackets { byte button = wrapper.get(Type.BYTE, 0); int mode = wrapper.get(Type.VAR_INT, 0); // QUICK_MOVE PATCH (Shift + (click/double click)) - if (mode == 1 && button == 0 && item == null) { + if (mode == 1 && button == 0 && item == null) { short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0); short slotId = wrapper.get(Type.SHORT, 0); - short anumber = wrapper.get(Type.SHORT, 1); - InvContainerItemProvider provider = Via.getManager().getProviders().get(InvContainerItemProvider.class); - boolean succeed = provider.registerInvClickPacket(windowId, slotId, anumber, wrapper.user()); + short actionId = wrapper.get(Type.SHORT, 1); + InventoryQuickMoveProvider provider = Via.getManager().getProviders().get(InventoryQuickMoveProvider.class); + boolean succeed = provider.registerQuickMove(windowId, slotId, actionId, wrapper.user()); if (succeed) { wrapper.cancel(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InventoryQuickMoveProvider.java similarity index 58% rename from common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java rename to common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InventoryQuickMoveProvider.java index e928136ea..906b72dc4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InvContainerItemProvider.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/providers/InventoryQuickMoveProvider.java @@ -3,9 +3,9 @@ package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.platform.providers.Provider; -public class InvContainerItemProvider implements Provider { +public class InventoryQuickMoveProvider implements Provider { - public boolean registerInvClickPacket(short windowId, short slotId, short anumber, UserConnection uconnection) { + public boolean registerQuickMove(short windowId, short slotId, short actionId, UserConnection userConnection) { return false; // not supported :/ plays very sad violin } } \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/ItemTransaction.java similarity index 79% rename from common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java rename to common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/ItemTransaction.java index 9deb38231..9ae0109c2 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/InvItemStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/ItemTransaction.java @@ -7,9 +7,8 @@ import lombok.ToString; @AllArgsConstructor @ToString @Getter -public class InvItemStorage { - +public class ItemTransaction { private short windowId; private short slotId; - private short actionNumber; + private short actionId; } \ No newline at end of file diff --git a/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java b/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java index b5ba95b7d..b20365674 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java +++ b/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java @@ -3,7 +3,6 @@ package us.myles.ViaVersion; import com.google.gson.JsonObject; import com.google.inject.Inject; import org.spongepowered.api.Game; -import org.spongepowered.api.Sponge; import org.spongepowered.api.config.DefaultConfig; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; @@ -113,6 +112,12 @@ public class SpongePlugin implements ViaPlatform { return new SpongeTaskId(null); } + @Override + public TaskId runSync(Runnable runnable, Long ticks) { + Long delay = ticks * 50L; + return new SpongeTaskId(syncExecutor.schedule(runnable, delay, TimeUnit.MILLISECONDS).getTask()); + } + @Override public TaskId runRepeatingSync(Runnable runnable, Long ticks) { Long time = ticks * 50L;