Fix inv provider not working on 1.8 servers

This commit is contained in:
mmxw11 2017-09-28 20:44:49 +03:00
parent 5a7626f280
commit d57ef2b303

View File

@ -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;
}
}