Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
30981f8283
4 files changed
+122
-41
No files matched your search
@@ -0,0 +1,33 @@
|
||||
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
|
||||
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
|
||||
|
||||
name: Gradle Package
|
||||
|
||||
on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 8
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '8'
|
||||
distribution: 'adopt'
|
||||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
settings-path: ${{ github.workspace }} # location for the settings.xml file
|
||||
|
||||
- name: Build with Gradle
|
||||
run: gradle :clean :build
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: packetevents-dev-build.jar
|
||||
path: build/libs
|
||||
+22
-25
@@ -18,25 +18,16 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.in.windowclick;
|
||||
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.enums.EnumUtil;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
private static boolean v_1_17;
|
||||
private static Class<? extends Enum<?>> invClickTypeClass;
|
||||
private static boolean isClickModePrimitive;
|
||||
|
||||
|
||||
public WrappedPacketInWindowClick(NMSPacket packet) {
|
||||
super(packet);
|
||||
@@ -49,48 +40,54 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
if (invClickTypeClass == null) {
|
||||
invClickTypeClass = NMSUtils.getNMEnumClassWithoutException("world.inventory.InventoryClickType");
|
||||
}
|
||||
isClickModePrimitive = Reflection.getField(PacketTypeClasses.Play.Client.WINDOW_CLICK, int.class, 3) != null;
|
||||
}
|
||||
|
||||
// Unique ID for the inventory, 0 for player's inventory
|
||||
public int getWindowId() {
|
||||
return readInt(0);
|
||||
return readInt(v_1_17 ? 1 : 0);
|
||||
}
|
||||
|
||||
public void setWindowId(int windowID) {
|
||||
writeInt(0, windowID);
|
||||
writeInt(v_1_17 ? 1 : 0, windowID);
|
||||
}
|
||||
|
||||
// Id of clicked slot
|
||||
public int getWindowSlot() {
|
||||
return readInt(1);
|
||||
return readInt(v_1_17 ? 3 : 1);
|
||||
}
|
||||
|
||||
public void setWindowSlot(int slot) {
|
||||
writeInt(1, slot);
|
||||
writeInt(v_1_17 ? 3 : 1, slot);
|
||||
}
|
||||
|
||||
// Left or right click
|
||||
public int getWindowButton() {
|
||||
return readInt(2);
|
||||
return readInt(v_1_17 ? 4 : 2);
|
||||
}
|
||||
|
||||
public void setWindowButton(int button) {
|
||||
writeInt(2, button);
|
||||
writeInt(v_1_17 ? 4 : 2, button);
|
||||
}
|
||||
|
||||
public Optional<Short> getActionNumber() {
|
||||
// Used to sync together client and server
|
||||
public int getActionNumber() {
|
||||
if (v_1_17) {
|
||||
return Optional.empty();
|
||||
return readInt(2);
|
||||
}
|
||||
return Optional.of(readShort(0));
|
||||
return readShort(0);
|
||||
}
|
||||
|
||||
public void setActionNumber(short actionNumber) {
|
||||
if (!v_1_17) {
|
||||
writeShort(0, actionNumber);
|
||||
public void setActionNumber(int actionNumber) {
|
||||
if (v_1_17) {
|
||||
writeInt(2, actionNumber);
|
||||
} else {
|
||||
writeShort(0, (short) actionNumber);
|
||||
}
|
||||
}
|
||||
|
||||
// Type of click - shift clicking, hotbar, drag, pickup...
|
||||
public int getMode() {
|
||||
if (isClickModePrimitive) {
|
||||
if (!v_1_17) {
|
||||
return readInt(3);
|
||||
} else {
|
||||
Enum<?> enumConst = readEnumConstant(0, invClickTypeClass);
|
||||
@@ -99,7 +96,7 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
}
|
||||
|
||||
public void setMode(int mode) {
|
||||
if (isClickModePrimitive) {
|
||||
if (!v_1_17) {
|
||||
writeInt(3, mode);
|
||||
} else {
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(invClickTypeClass, mode);
|
||||
@@ -117,6 +114,6 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
}
|
||||
|
||||
public void setClickedItemStack(ItemStack stack) {
|
||||
writeItemStack(0, stack);
|
||||
writeItemStack(0, stack);
|
||||
}
|
||||
}
|
||||
+62
-14
@@ -23,7 +23,6 @@ import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -31,6 +30,8 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
//TODO Test wrapper
|
||||
public class WrappedPacketOutWindowItems extends WrappedPacket implements SendableWrapper {
|
||||
private static boolean v_1_17, v_1_17_1;
|
||||
@@ -38,15 +39,19 @@ public class WrappedPacketOutWindowItems extends WrappedPacket implements Sendab
|
||||
private static Class<?> nonNullListClass;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private int windowID;
|
||||
private int stateID;
|
||||
private List<ItemStack> slotData;
|
||||
private ItemStack heldItem;
|
||||
|
||||
public WrappedPacketOutWindowItems(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutWindowItems(int windowID, List<ItemStack> slots) {
|
||||
public WrappedPacketOutWindowItems(int windowID, int stateID, List<ItemStack> slots, ItemStack heldItem) {
|
||||
this.windowID = windowID;
|
||||
this.stateID = stateID;
|
||||
this.slotData = slots;
|
||||
this.heldItem = heldItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,15 +65,14 @@ public class WrappedPacketOutWindowItems extends WrappedPacket implements Sendab
|
||||
Constructor<?> nonNullListConstructor = nonNullListClass.getDeclaredConstructors()[0];
|
||||
nonNullListConstructor.setAccessible(true);
|
||||
nonNullListInstance = nonNullListConstructor.newInstance(new ArrayList<>(), null);
|
||||
}
|
||||
else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.WINDOW_ITEMS.getConstructor(int.class, int.class, nonNullListClass, NMSUtils.nmsItemStackClass);
|
||||
} else {
|
||||
Constructor<?> nonNullListConstructor = nonNullListClass.getDeclaredConstructor();
|
||||
nonNullListConstructor.setAccessible(true);
|
||||
nonNullListInstance = nonNullListConstructor.newInstance();
|
||||
packetConstructor = PacketTypeClasses.Play.Server.WINDOW_ITEMS.getConstructor(int.class, nonNullListClass);
|
||||
}
|
||||
packetConstructor = PacketTypeClasses.Play.Server.WINDOW_ITEMS.getConstructor(int.class, nonNullListClass);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.WINDOW_ITEMS.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
|
||||
@@ -92,6 +96,22 @@ public class WrappedPacketOutWindowItems extends WrappedPacket implements Sendab
|
||||
}
|
||||
}
|
||||
|
||||
public int getStateId() {
|
||||
if (packet != null) {
|
||||
return readInt(1);
|
||||
} else {
|
||||
return stateID;
|
||||
}
|
||||
}
|
||||
|
||||
public void setStateId(int stateID) {
|
||||
if (packet != null) {
|
||||
writeInt(1, stateID);
|
||||
} else {
|
||||
this.stateID = stateID;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemStack> getSlots() {
|
||||
if (packet != null) {
|
||||
List<ItemStack> slots = new ArrayList<>();
|
||||
@@ -107,8 +127,7 @@ public class WrappedPacketOutWindowItems extends WrappedPacket implements Sendab
|
||||
}
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return slotData;
|
||||
}
|
||||
}
|
||||
@@ -128,21 +147,50 @@ public class WrappedPacketOutWindowItems extends WrappedPacket implements Sendab
|
||||
}
|
||||
writeAnyObject(1, nmsItemStacks);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.slotData = slots;
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<ItemStack> getHeldItem() {
|
||||
if (!v_1_17_1) return Optional.empty();
|
||||
|
||||
if (packet != null) {
|
||||
return Optional.ofNullable(NMSUtils.toBukkitItemStack(readObject(0, NMSUtils.nmsItemStackClass)));
|
||||
} else {
|
||||
return Optional.of(heldItem);
|
||||
}
|
||||
}
|
||||
|
||||
public void setHeldItem(ItemStack heldItem) {
|
||||
if (packet != null) {
|
||||
writeObject(0, NMSUtils.toNMSItemStack(heldItem));
|
||||
} else {
|
||||
this.heldItem = heldItem;
|
||||
}
|
||||
}
|
||||
|
||||
private Object getNMSItemHeld() {
|
||||
if (packet != null) {
|
||||
return readObject(0, NMSUtils.nmsItemStackClass);
|
||||
} else {
|
||||
return NMSUtils.toNMSItemStack(heldItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
|
||||
if (v_1_17_1) {
|
||||
packetInstance = packetConstructor.newInstance(getWindowId(), stateID, nonNullListInstance, getNMSItemHeld());
|
||||
WrappedPacketOutWindowItems wrappedPacketOutWindowItems = new WrappedPacketOutWindowItems(new NMSPacket(packetInstance));
|
||||
wrappedPacketOutWindowItems.setSlots(getSlots());
|
||||
} else if (v_1_17) {
|
||||
packetInstance = packetConstructor.newInstance(getWindowId(), nonNullListInstance);
|
||||
WrappedPacketOutWindowItems wrappedPacketOutWindowItems = new WrappedPacketOutWindowItems(new NMSPacket(packetInstance));
|
||||
wrappedPacketOutWindowItems.setSlots(getSlots());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
WrappedPacketOutWindowItems wrappedPacketOutWindowItems = new WrappedPacketOutWindowItems(new NMSPacket(packetInstance));
|
||||
wrappedPacketOutWindowItems.setWindowId(getWindowId());
|
||||
|
||||
@@ -245,8 +245,11 @@ public final class NMSUtils {
|
||||
blockPosClass = getNMClassWithoutException("core.BlockPosition");
|
||||
}
|
||||
}
|
||||
// Added in 1.18
|
||||
sectionPositionClass = getNMClassWithoutException("core.SectionPosition");
|
||||
|
||||
sectionPositionClass = getNMSClassWithoutException("SectionPosition");
|
||||
if (sectionPositionClass == null) {
|
||||
sectionPositionClass = getNMClassWithoutException("core.SectionPosition");
|
||||
}
|
||||
|
||||
if (version.isNewerThanOrEquals(ServerVersion.v_1_14)) {
|
||||
movingObjectPositionBlockClass = NMSUtils.getNMSClassWithoutException("MovingObjectPositionBlock");
|
||||
|
||||
Reference in new issue
Block a user