2022-01-29 15:28:28 +01:00
|
|
|
/*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.steamwar.bausystem.utils;
|
|
|
|
|
|
|
|
import com.comphenix.tinyprotocol.Reflection;
|
2023-02-04 14:31:24 +01:00
|
|
|
import de.steamwar.bausystem.features.util.NoClipCommand;
|
2022-01-29 15:28:28 +01:00
|
|
|
import net.minecraft.server.v1_15_R1.*;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.GameMode;
|
2022-03-29 12:37:32 +02:00
|
|
|
import org.bukkit.Material;
|
2022-01-29 15:28:28 +01:00
|
|
|
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.CraftItemStack;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.TNTPrimed;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.function.LongSupplier;
|
|
|
|
|
2022-08-06 11:15:33 +02:00
|
|
|
public class NMSWrapper15 implements NMSWrapper {
|
2022-01-29 15:28:28 +01:00
|
|
|
|
2022-03-29 11:43:37 +02:00
|
|
|
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
|
2022-08-06 11:15:33 +02:00
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public void setInternalGameMode(Player player, GameMode gameMode) {
|
|
|
|
playerGameMode.set(((CraftPlayer) player).getHandle().playerInteractManager, EnumGamemode.getById(gameMode.getValue()));
|
|
|
|
}
|
|
|
|
|
2022-07-30 17:43:40 +02:00
|
|
|
@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()));
|
2022-07-31 21:21:20 +02:00
|
|
|
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
|
|
|
player.updateInventory();
|
2022-07-30 17:43:40 +02:00
|
|
|
}
|
|
|
|
|
2022-03-29 11:43:37 +02:00
|
|
|
private static final Reflection.FieldAccessor<Integer> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0);
|
2022-08-06 11:15:33 +02:00
|
|
|
|
2022-03-29 11:43:37 +02:00
|
|
|
@Override
|
|
|
|
public void setGameStateChangeReason(Object packet) {
|
|
|
|
gameStateChangeReason.set(packet, 3);
|
|
|
|
}
|
|
|
|
|
2022-03-29 12:29:19 +02:00
|
|
|
@Override
|
|
|
|
public void setPlayerBuildAbilities(Player player) {
|
|
|
|
((CraftPlayer) player).getHandle().abilities.mayBuild = true;
|
|
|
|
((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true;
|
|
|
|
}
|
|
|
|
|
2022-03-29 12:37:32 +02:00
|
|
|
@Override
|
|
|
|
public Material pathMaterial() {
|
|
|
|
return Material.GRASS_PATH;
|
|
|
|
}
|
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
private static final int threshold = 2048;
|
2022-08-06 11:15:33 +02:00
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
@Override
|
|
|
|
public boolean checkItemStack(ItemStack item) {
|
|
|
|
net.minecraft.server.v1_15_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
|
|
|
NBTTagCompound tag = nmsItem.getTag();
|
|
|
|
if (tag != null && tag.hasKey("BlockEntityTag")) {
|
|
|
|
NBTTagCompound blockTag = tag.getCompound("BlockEntityTag");
|
|
|
|
if (blockTag.hasKey("Items")) {
|
|
|
|
return drillDown(blockTag.getList("Items", 10), 0, 0) > threshold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int drillDown(NBTTagList items, int layer, int start) {
|
|
|
|
if (layer > 2) return start + threshold;
|
|
|
|
int invalid = start;
|
|
|
|
for (NBTBase nbtBase : items) {
|
|
|
|
if (!(nbtBase instanceof NBTTagCompound))
|
|
|
|
continue;
|
|
|
|
NBTTagCompound slot = (NBTTagCompound) nbtBase;
|
|
|
|
if (slot.hasKey("tag")) {
|
|
|
|
invalid += slot.getByte("Count");
|
|
|
|
NBTTagCompound iTag = slot.getCompound("tag");
|
|
|
|
if (iTag.hasKey("BlockEntityTag")) {
|
|
|
|
NBTTagCompound blockTag = iTag.getCompound("BlockEntityTag");
|
|
|
|
if (blockTag.hasKey("Items")) {
|
|
|
|
invalid = drillDown(blockTag.getList("Items", 10), layer + 1, invalid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (invalid > threshold)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return invalid;
|
|
|
|
}
|
|
|
|
|
2022-08-06 11:15:33 +02:00
|
|
|
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion");
|
|
|
|
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0);
|
|
|
|
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1);
|
|
|
|
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2);
|
|
|
|
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0);
|
|
|
|
private final Reflection.FieldAccessor<List> 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);
|
|
|
|
}
|
2022-01-29 15:28:28 +01:00
|
|
|
}
|