diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index 6a152570..9111ee64 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -37,7 +37,6 @@ 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; @@ -48,9 +47,10 @@ import java.util.ArrayList; import java.util.List; import java.util.function.LongSupplier; -public class NMSWrapper15 implements NMSWrapper.INMSWrapper { +public class NMSWrapper15 implements NMSWrapper { private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + @Override @SuppressWarnings("deprecation") public void setInternalGameMode(Player player, GameMode gameMode) { @@ -80,6 +80,7 @@ public class NMSWrapper15 implements NMSWrapper.INMSWrapper { private static final List> packets = new ArrayList<>(); private static final Vec3D noMotion = new Vec3D(0, 0, 0); + @Override public void createTickCache(World world) { packets.clear(); @@ -105,6 +106,7 @@ public class NMSWrapper15 implements NMSWrapper.INMSWrapper { } private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0); + @Override public void setGameStateChangeReason(Object packet) { gameStateChangeReason.set(packet, 3); @@ -127,6 +129,7 @@ public class NMSWrapper15 implements NMSWrapper.INMSWrapper { } private static final int threshold = 2048; + @Override public boolean checkItemStack(ItemStack item) { net.minecraft.server.v1_15_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); @@ -183,4 +186,17 @@ public class NMSWrapper15 implements NMSWrapper.INMSWrapper { public AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt) { return new TraceEntity15(world, tntPosition, tnt); } + + private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.FieldAccessor c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.FieldAccessor d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.FieldAccessor e = Reflection.getField(explosionPacket, List.class, 0); + + @Override + public Object resetExplosionKnockback(Object packet) { + PacketPlayOutExplosion packetPlayOutExplosion = (PacketPlayOutExplosion) packet; + return new PacketPlayOutExplosion(a.get(packetPlayOutExplosion), b.get(packetPlayOutExplosion), c.get(packetPlayOutExplosion), d.get(packetPlayOutExplosion), e.get(packetPlayOutExplosion), Vec3D.a); + } } diff --git a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index 48a4a32a..9b3878e9 100644 --- a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -52,9 +52,10 @@ import java.util.ArrayList; import java.util.List; import java.util.function.LongSupplier; -public class NMSWrapper18 implements NMSWrapper.INMSWrapper { +public class NMSWrapper18 implements NMSWrapper { private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + @Override @SuppressWarnings("deprecation") public void setInternalGameMode(Player player, GameMode gameMode) { @@ -85,6 +86,7 @@ public class NMSWrapper18 implements NMSWrapper.INMSWrapper { private static final List> packets = new ArrayList<>(); private static final Vec3D noMotion = new Vec3D(0, 0, 0); + @Override public void createTickCache(World world) { packets.clear(); @@ -109,6 +111,7 @@ public class NMSWrapper18 implements NMSWrapper.INMSWrapper { } private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + @Override public void setGameStateChangeReason(Object packet) { gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d); @@ -131,6 +134,7 @@ public class NMSWrapper18 implements NMSWrapper.INMSWrapper { } private static final int threshold = 2048; + @Override public boolean checkItemStack(ItemStack item) { net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); @@ -187,4 +191,17 @@ public class NMSWrapper18 implements NMSWrapper.INMSWrapper { public AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt) { return new TraceEntity18(world, tntPosition, tnt); } + + private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.FieldAccessor c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.FieldAccessor d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.FieldAccessor e = Reflection.getField(explosionPacket, List.class, 0); + + @Override + public Object resetExplosionKnockback(Object packet) { + PacketPlayOutExplosion packetPlayOutExplosion = (PacketPlayOutExplosion) packet; + return new PacketPlayOutExplosion(a.get(packetPlayOutExplosion), b.get(packetPlayOutExplosion), c.get(packetPlayOutExplosion), d.get(packetPlayOutExplosion), e.get(packetPlayOutExplosion), null); + } } diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index 9066ac01..4424f100 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -52,9 +52,10 @@ import java.util.ArrayList; import java.util.List; import java.util.function.LongSupplier; -public class NMSWrapper19 implements NMSWrapper.INMSWrapper { +public class NMSWrapper19 implements NMSWrapper { private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + @Override @SuppressWarnings("deprecation") public void setInternalGameMode(Player player, GameMode gameMode) { @@ -85,6 +86,7 @@ public class NMSWrapper19 implements NMSWrapper.INMSWrapper { private static final List> packets = new ArrayList<>(); private static final Vec3D noMotion = new Vec3D(0, 0, 0); + @Override public void createTickCache(World world) { packets.clear(); @@ -109,6 +111,7 @@ public class NMSWrapper19 implements NMSWrapper.INMSWrapper { } private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + @Override public void setGameStateChangeReason(Object packet) { gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d); @@ -131,6 +134,7 @@ public class NMSWrapper19 implements NMSWrapper.INMSWrapper { } private static final int threshold = 2048; + @Override public boolean checkItemStack(ItemStack item) { net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); @@ -187,4 +191,17 @@ public class NMSWrapper19 implements NMSWrapper.INMSWrapper { public AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt) { return new TraceEntity19(world, tntPosition, tnt); } + + private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.FieldAccessor c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.FieldAccessor d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.FieldAccessor e = Reflection.getField(explosionPacket, List.class, 0); + + @Override + public Object resetExplosionKnockback(Object packet) { + PacketPlayOutExplosion packetPlayOutExplosion = (PacketPlayOutExplosion) packet; + return new PacketPlayOutExplosion(a.get(packetPlayOutExplosion), b.get(packetPlayOutExplosion), c.get(packetPlayOutExplosion), d.get(packetPlayOutExplosion), e.get(packetPlayOutExplosion), null); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java new file mode 100644 index 00000000..f1cb74ce --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java @@ -0,0 +1,45 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.world; + +import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.utils.NMSWrapper; +import de.steamwar.bausystem.utils.ProtocolAPI; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +import java.util.function.BiFunction; + +@Linked(LinkageType.PLAIN) +public class NoCreativeKnockback { + + private Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + + { + BiFunction knockbackResetter = (player, o) -> { + if (player.getGameMode() != GameMode.CREATIVE) return o; + return NMSWrapper.impl.resetExplosionKnockback(o); + }; + + ProtocolAPI.setOutgoingHandler(explosionPacket, knockbackResetter); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java index 6d39bace..356076d3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.NMSWrapper; +import de.steamwar.bausystem.utils.ProtocolWrapper; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; @@ -46,7 +47,8 @@ public class LinkageUtils { objectMap.put(Config.class, Config.getInstance()); objectMap.put(BauSystem.class, BauSystem.getInstance()); objectMap.put(FlatteningWrapper.class, FlatteningWrapper.impl); - objectMap.put(NMSWrapper.INMSWrapper.class, NMSWrapper.impl); + objectMap.put(NMSWrapper.class, NMSWrapper.impl); + objectMap.put(ProtocolWrapper.class, ProtocolWrapper.impl); } public void link() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java index 565f0707..24fe02f6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java @@ -35,30 +35,28 @@ import org.bukkit.util.Vector; import java.util.function.LongSupplier; -public class NMSWrapper { - private NMSWrapper() {} +public interface NMSWrapper { + NMSWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); - public static final INMSWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); + void setInternalGameMode(Player player, GameMode gameMode); + void setSlotToItemStack(Player player, Object o); - public interface INMSWrapper { - void setInternalGameMode(Player player, GameMode gameMode); - void setSlotToItemStack(Player player, Object o); + void init(LongSupplier longSupplier); + void createTickCache(World world); + void sendTickPackets(); - void init(LongSupplier longSupplier); - void createTickCache(World world); - void sendTickPackets(); + void setGameStateChangeReason(Object packet); + void setPlayerBuildAbilities(Player player); - void setGameStateChangeReason(Object packet); - void setPlayerBuildAbilities(Player player); + Particle tntPositionParticle(); + Material pathMaterial(); - Particle tntPositionParticle(); - Material pathMaterial(); + boolean checkItemStack(ItemStack item); - boolean checkItemStack(ItemStack item); + AbstractWarpEntity createWarp(World world, Vector position, String name); + AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight); + AbstractDetonatorEntity constructDetonator(World world, Vector position); + AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt); - AbstractWarpEntity createWarp(World world, Vector position, String name); - AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight); - AbstractDetonatorEntity constructDetonator(World world, Vector position); - AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt); - } + Object resetExplosionKnockback(Object packet); }