diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index cd674b63..32ff8d52 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -37,6 +37,7 @@ import org.bukkit.Particle; import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -56,6 +57,20 @@ public class NMSWrapper15 implements NMSWrapper.INMSWrapper { playerGameMode.set(((CraftPlayer) player).getHandle().playerInteractManager, EnumGamemode.getById(gameMode.getValue())); } + @Override + public void setSlotToItemStack(Player player, Object o) { + PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot = (PacketPlayInSetCreativeSlot) o; + int index = packetPlayInSetCreativeSlot.b(); + if (index >= 36 && index <= 44) { + index -= 36; + } else if (index > 44) { + index -= 5; + } else if (index <= 8) { + index = index - 8 + 36; + } + player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.getItemStack())); + } + @Override public void init(LongSupplier longSupplier) { SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong(); diff --git a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index 46b79f19..0e687866 100644 --- a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -26,19 +26,16 @@ import de.steamwar.bausystem.entities.SimulatorEntity18; import de.steamwar.bausystem.entities.TraceEntity18; import de.steamwar.bausystem.entities.WarpEntity18; import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity; -import de.steamwar.bausystem.features.util.NoClipCommand; import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; +import de.steamwar.bausystem.features.util.NoClipCommand; import de.steamwar.bausystem.features.warp.AbstractWarpEntity; import net.minecraft.SystemUtils; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport; -import net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity; -import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange; +import net.minecraft.network.protocol.game.*; import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.phys.Vec3D; @@ -65,6 +62,20 @@ public class NMSWrapper18 implements NMSWrapper.INMSWrapper { } + @Override + public void setSlotToItemStack(Player player, Object o) { + PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot = (PacketPlayInSetCreativeSlot) o; + int index = packetPlayInSetCreativeSlot.b(); + if (index >= 36 && index <= 44) { + index -= 36; + } else if (index > 44) { + index -= 5; + } else if (index <= 8) { + index = index - 8 + 36; + } + player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.c())); + } + @Override public void init(LongSupplier longSupplier) { SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong(); diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index 8bc1fcbb..6a38189e 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -35,16 +35,16 @@ import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport; -import net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity; -import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange; +import net.minecraft.network.protocol.game.*; import net.minecraft.server.level.PlayerInteractManager; +import net.minecraft.world.IInventory; import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.phys.Vec3D; import org.bukkit.*; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryPlayer; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -65,6 +65,20 @@ public class NMSWrapper19 implements NMSWrapper.INMSWrapper { } + @Override + public void setSlotToItemStack(Player player, Object o) { + PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot = (PacketPlayInSetCreativeSlot) o; + int index = packetPlayInSetCreativeSlot.b(); + if (index >= 36 && index <= 44) { + index -= 36; + } else if (index > 44) { + index -= 5; + } else if (index <= 8) { + index = index - 8 + 36; + } + player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.c())); + } + @Override public void init(LongSupplier longSupplier) { SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index 700eb64f..2b79fd47 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -32,11 +32,14 @@ import de.steamwar.bausystem.utils.ProtocolWrapper; import de.steamwar.command.SWCommand; import de.steamwar.core.Core; import lombok.Getter; +import net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot; +import net.minecraft.network.protocol.game.PacketPlayInUseItem; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockCanBuildEvent; +import org.bukkit.event.inventory.InventoryCreativeEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerToggleFlightEvent; @@ -66,6 +69,7 @@ public class NoClipCommand extends SWCommand implements Listener { private static final Class useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); private static final Class blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); private static final Class windowClick = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInWindowClick"); + private static final Class setSlotStack = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInSetCreativeSlot"); @Getter private static final List NOCLIPS = new ArrayList<>(); @@ -95,6 +99,14 @@ public class NoClipCommand extends SWCommand implements Listener { ProtocolAPI.setIncomingHandler(useItem, second); ProtocolAPI.setIncomingHandler(blockDig, second); ProtocolAPI.setIncomingHandler(windowClick, second); + + BiFunction third = (player, o) -> { + if (NOCLIPS.contains(player)) { + NMSWrapper.impl.setSlotToItemStack(player, o); + } + return o; + }; + ProtocolAPI.setIncomingHandler(setSlotStack, third); } @Register(help = true) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java index 3d7d2c05..565f0707 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java @@ -42,6 +42,7 @@ public class NMSWrapper { public interface INMSWrapper { void setInternalGameMode(Player player, GameMode gameMode); + void setSlotToItemStack(Player player, Object o); void init(LongSupplier longSupplier); void createTickCache(World world);