forked from SteamWar/SteamWar
Unreflect more stuff
This commit is contained in:
@@ -39,11 +39,6 @@ public class WideningTransformer implements ClassFileTransformer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
|
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
|
||||||
byte[] result = patcher.patch(className, classfileBuffer);
|
return patcher.patch(className, classfileBuffer);
|
||||||
if (result == null) {
|
|
||||||
return classfileBuffer;
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,3 +11,6 @@ mutable field org/bukkit/craftbukkit/block/CraftBlockState world Lorg/bukkit/cra
|
|||||||
|
|
||||||
# For TickManager
|
# For TickManager
|
||||||
accessible field net/minecraft/server/ServerTickRateManager remainingSprintTicks J
|
accessible field net/minecraft/server/ServerTickRateManager remainingSprintTicks J
|
||||||
|
|
||||||
|
# Test
|
||||||
|
accessible field net/minecraft/core/registries/BuiltInRegistries BLOCK_ENTITY_TYPE Lnet/minecraft/core/Registry;
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
package de.steamwar.bausystem.utils;
|
||||||
|
|
||||||
|
import com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector;
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.IncompleteRegionException;
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
@@ -32,16 +33,19 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
|||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
|
import com.sk89q.worldedit.regions.selector.*;
|
||||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||||
import de.steamwar.Reflection;
|
import com.sk89q.worldedit.world.World;
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
@@ -91,17 +95,36 @@ public class WorldEditUtils {
|
|||||||
.getRegionSelector(BukkitAdapter.adapt(player.getWorld()));
|
.getRegionSelector(BukkitAdapter.adapt(player.getWorld()));
|
||||||
return new Pair<>(regionSelector.getClass(), regionSelector.getVertices()
|
return new Pair<>(regionSelector.getClass(), regionSelector.getVertices()
|
||||||
.stream()
|
.stream()
|
||||||
.map(blockVector3 -> blockVector3 == null ? null : adapt(player.getWorld(), blockVector3))
|
.map(blockVector3 -> {
|
||||||
|
if (blockVector3 == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return BukkitAdapter.adapt(player.getWorld(), blockVector3);
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Map<Class<? extends RegionSelector>, Function<World, RegionSelector>> constructors = new HashMap<>();
|
||||||
|
static {
|
||||||
|
constructors.put(CuboidRegionSelector.class, CuboidRegionSelector::new);
|
||||||
|
constructors.put(ExtendingCuboidRegionSelector.class, ExtendingCuboidRegionSelector::new);
|
||||||
|
constructors.put(Polygonal2DRegionSelector.class, Polygonal2DRegionSelector::new);
|
||||||
|
constructors.put(EllipsoidRegionSelector.class, EllipsoidRegionSelector::new);
|
||||||
|
constructors.put(SphereRegionSelector.class, SphereRegionSelector::new);
|
||||||
|
constructors.put(CylinderRegionSelector.class, CylinderRegionSelector::new);
|
||||||
|
constructors.put(ConvexPolyhedralRegionSelector.class, ConvexPolyhedralRegionSelector::new);
|
||||||
|
constructors.put(PolyhedralRegionSelector.class, PolyhedralRegionSelector::new);
|
||||||
|
}
|
||||||
|
|
||||||
public void setVertices(Player player, Class<? extends RegionSelector> clazz, List<Location> vertices) {
|
public void setVertices(Player player, Class<? extends RegionSelector> clazz, List<Location> vertices) {
|
||||||
LocalSession localSession = WorldEdit.getInstance()
|
LocalSession localSession = WorldEdit.getInstance()
|
||||||
.getSessionManager()
|
.getSessionManager()
|
||||||
.get(BukkitAdapter.adapt(player));
|
.get(BukkitAdapter.adapt(player));
|
||||||
|
|
||||||
Reflection.Constructor constructorInvoker = Reflection.getConstructor(clazz, com.sk89q.worldedit.world.World.class);
|
Function<World, RegionSelector> constructor = constructors.get(clazz);
|
||||||
RegionSelector regionSelector = (RegionSelector) constructorInvoker.invoke(BukkitAdapter.adapt(player.getWorld()));
|
if (constructor == null) return;
|
||||||
|
RegionSelector regionSelector = constructor.apply(BukkitAdapter.adapt(player.getWorld()));
|
||||||
localSession.setRegionSelector(BukkitAdapter.adapt(player.getWorld()), regionSelector);
|
localSession.setRegionSelector(BukkitAdapter.adapt(player.getWorld()), regionSelector);
|
||||||
|
|
||||||
if (vertices.isEmpty()) return;
|
if (vertices.isEmpty()) return;
|
||||||
@@ -127,13 +150,9 @@ public class WorldEditUtils {
|
|||||||
try {
|
try {
|
||||||
BlockVector3 min = regionSelector.getRegion().getMinimumPoint();
|
BlockVector3 min = regionSelector.getRegion().getMinimumPoint();
|
||||||
BlockVector3 max = regionSelector.getRegion().getMaximumPoint();
|
BlockVector3 max = regionSelector.getRegion().getMaximumPoint();
|
||||||
return new Pair<>(adapt(player.getWorld(), min), adapt(player.getWorld(), max));
|
return new Pair<>(BukkitAdapter.adapt(player.getWorld(), min), BukkitAdapter.adapt(player.getWorld(), max));
|
||||||
} catch (IncompleteRegionException e) {
|
} catch (IncompleteRegionException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Location adapt(World world, BlockVector3 blockVector3) {
|
|
||||||
return new Location(world, blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ version: "2.0"
|
|||||||
depend: [ WorldEdit, SpigotCore ]
|
depend: [ WorldEdit, SpigotCore ]
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
main: de.steamwar.bausystem.BauSystem
|
main: de.steamwar.bausystem.BauSystem
|
||||||
api-version: "1.13"
|
api-version: "1.21"
|
||||||
website: "https://steamwar.de"
|
website: "https://steamwar.de"
|
||||||
description: "So unseriös wie wir sind: BauSystem nur besser."
|
description: "So unseriös wie wir sind: BauSystem nur besser."
|
||||||
|
|
||||||
|
|||||||
@@ -39,5 +39,7 @@ tasks.register<DevServer>("DevBau21") {
|
|||||||
dependsOn(":SchematicSystem:shadowJar")
|
dependsOn(":SchematicSystem:shadowJar")
|
||||||
dependsOn(":AccessWidener:shadowJar")
|
dependsOn(":AccessWidener:shadowJar")
|
||||||
template = "Bau21"
|
template = "Bau21"
|
||||||
|
// TODO: Add to every new server start! newer than 1.21 inclusive!
|
||||||
jvmArgs = "-javaagent:/home/yoyonow/Bau21/plugins/AccessWidener.jar=start"
|
jvmArgs = "-javaagent:/home/yoyonow/Bau21/plugins/AccessWidener.jar=start"
|
||||||
|
setdParams(mapOf("paper.disablePluginRemapping" to "true"))
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-11
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.utils;
|
||||||
|
|
||||||
import de.steamwar.Reflection;
|
|
||||||
import de.steamwar.core.CraftbukkitWrapper;
|
import de.steamwar.core.CraftbukkitWrapper;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.events.BoardingEvent;
|
import de.steamwar.fightsystem.events.BoardingEvent;
|
||||||
@@ -51,7 +50,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -82,18 +81,13 @@ public class TechHiderWrapper extends StateDependent implements Listener {
|
|||||||
.map(CraftMagicNumbers::getBlock)
|
.map(CraftMagicNumbers::getBlock)
|
||||||
.collect(Collectors.toUnmodifiableSet());
|
.collect(Collectors.toUnmodifiableSet());
|
||||||
|
|
||||||
Object blockEntityType;
|
|
||||||
try {
|
|
||||||
blockEntityType = BuiltInRegistries.class.getDeclaredField("BLOCK_ENTITY_TYPE").get(null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
Reflection.Method method = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.core.Registry"), "get", Optional.class, ResourceLocation.class);
|
|
||||||
Set<BlockEntityType<?>> blockEntityTypeToObfuscate = Config.GameModeConfig.Techhider.HiddenBlockEntities.stream()
|
Set<BlockEntityType<?>> blockEntityTypeToObfuscate = Config.GameModeConfig.Techhider.HiddenBlockEntities.stream()
|
||||||
.map((id) -> {
|
.map(id -> {
|
||||||
ResourceLocation loc = ResourceLocation.parse(id);
|
ResourceLocation loc = ResourceLocation.parse(id);
|
||||||
return ((Optional<Holder.Reference<BlockEntityType<?>>>) method.invoke(blockEntityType, loc)).get().value();
|
return BuiltInRegistries.BLOCK_ENTITY_TYPE.get(loc).orElse(null);
|
||||||
})
|
})
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(Holder.Reference::value)
|
||||||
.collect(Collectors.toUnmodifiableSet());
|
.collect(Collectors.toUnmodifiableSet());
|
||||||
|
|
||||||
new TechHider(CraftMagicNumbers.getBlock(Config.GameModeConfig.Techhider.ObfuscateWith), new AccessPrivilegeProvider() {
|
new TechHider(CraftMagicNumbers.getBlock(Config.GameModeConfig.Techhider.ObfuscateWith), new AccessPrivilegeProvider() {
|
||||||
|
|||||||
@@ -19,292 +19,13 @@
|
|||||||
|
|
||||||
package de.steamwar;
|
package de.steamwar;
|
||||||
|
|
||||||
import de.steamwar.core.Core;
|
|
||||||
import jdk.internal.misc.Unsafe;
|
import jdk.internal.misc.Unsafe;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public final class Reflection {
|
public final class Reflection {
|
||||||
|
|
||||||
public static final int MAJOR_VERSION;
|
|
||||||
public static final int MINOR_VERSION;
|
|
||||||
|
|
||||||
static {
|
|
||||||
String[] version = Bukkit.getServer().getBukkitVersion().split("-")[0].split("\\.");
|
|
||||||
MAJOR_VERSION = Integer.parseInt(version[1]);
|
|
||||||
MINOR_VERSION = version.length > 2 ? Integer.parseInt(version[2]) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String ORG_BUKKIT_CRAFTBUKKIT = Bukkit.getServer().getClass().getPackage().getName();
|
|
||||||
public static final String LEGACY_NET_MINECRAFT_SERVER = ORG_BUKKIT_CRAFTBUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
|
||||||
|
|
||||||
private static final Map<String, String> spigotClassnames = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
// See https://mappings.dev for complete mappings
|
|
||||||
spigotClassnames.put("net.minecraft.Util", "net.minecraft.SystemUtils");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.core.BlockPos", "net.minecraft.core.BlockPosition");
|
|
||||||
spigotClassnames.put("net.minecraft.core.DefaultedRegistry", "net.minecraft.core.RegistryBlocks");
|
|
||||||
spigotClassnames.put("net.minecraft.core.IdMapper", "net.minecraft.core.RegistryBlockID");
|
|
||||||
spigotClassnames.put("net.minecraft.core.Vec3i", "net.minecraft.core.BaseBlockPosition");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.nbt.CompoundTag", "net.minecraft.nbt.NBTTagCompound");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.network.Connection", "net.minecraft.network.NetworkManager");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.network.chat.Component", "net.minecraft.network.chat.IChatBaseComponent");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAddEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket", "net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAnimatePacket", "net.minecraft.network.protocol.game.PacketPlayOutAnimation");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockBreak");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket", "net.minecraft.network.protocol.game.PacketPlayOutTileEntityData");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockAction");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockChange");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundContainerClosePacket", "net.minecraft.network.protocol.game.PacketPlayOutCloseWindow");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundEntityEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityStatus");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundExplodePacket", "net.minecraft.network.protocol.game.PacketPlayOutExplosion");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundGameEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutGameStateChange");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo", "net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutWorldEvent");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket", "net.minecraft.network.protocol.game.PacketPlayOutWorldParticles");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntity");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMove");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutEntityLook");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket", "net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundRotateHeadPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetObjectivePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetScorePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardScore");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSoundPacket", "net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundContainerClickPacket", "net.minecraft.network.protocol.game.PacketPlayInWindowClick");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket", "net.minecraft.network.protocol.game.PacketPlayInUseEntity");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$EnumEntityUseAction");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$b");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInLook");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket", "net.minecraft.network.protocol.game.PacketPlayInBlockDig");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket", "net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayInUpdateSign");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundUseItemPacket", "net.minecraft.network.protocol.game.PacketPlayInBlockPlace");
|
|
||||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket", "net.minecraft.network.protocol.game.PacketPlayInUseItem");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.network.syncher.EntityDataAccessor", "net.minecraft.network.syncher.DataWatcherObject");
|
|
||||||
spigotClassnames.put("net.minecraft.network.syncher.EntityDataSerializer", "net.minecraft.network.syncher.DataWatcherSerializer");
|
|
||||||
spigotClassnames.put("net.minecraft.network.syncher.EntityDataSerializers", "net.minecraft.network.syncher.DataWatcherRegistry");
|
|
||||||
spigotClassnames.put("net.minecraft.network.syncher.SynchedEntityData$DataItem", "net.minecraft.network.syncher.DataWatcher$Item");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.server.ServerScoreboard$Method", "net.minecraft.server.ScoreboardServer$Action");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.server.level.ChunkMap", "net.minecraft.server.level.PlayerChunkMap");
|
|
||||||
spigotClassnames.put("net.minecraft.server.level.ChunkMap$TrackedEntity", "net.minecraft.server.level.PlayerChunkMap$EntityTracker");
|
|
||||||
spigotClassnames.put("net.minecraft.server.level.ServerChunkCache", "net.minecraft.server.level.ChunkProviderServer");
|
|
||||||
spigotClassnames.put("net.minecraft.server.level.ServerLevel", "net.minecraft.server.level.WorldServer");
|
|
||||||
spigotClassnames.put("net.minecraft.server.level.ServerPlayer", "net.minecraft.server.level.EntityPlayer");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.server.network.ServerConnectionListener", "net.minecraft.server.network.ServerConnection");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.world.InteractionHand", "net.minecraft.world.EnumHand");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.world.entity.EntityType", "net.minecraft.world.entity.EntityTypes");
|
|
||||||
spigotClassnames.put("net.minecraft.world.entity.Pose", "net.minecraft.world.entity.EntityPose");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.world.entity.item.PrimedTnt", "net.minecraft.world.entity.item.EntityTNTPrimed");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.world.entity.projectile.AbstractArrow", "net.minecraft.world.entity.projectile.EntityArrow");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.world.level.GameType", "net.minecraft.world.level.EnumGamemode");
|
|
||||||
spigotClassnames.put("net.minecraft.world.level.LevelAccessor", "net.minecraft.world.level.GeneratorAccess");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.world.level.block.state.BlockState", "net.minecraft.world.level.block.state.IBlockData");
|
|
||||||
spigotClassnames.put("net.minecraft.world.level.block.state.StateDefinition", "net.minecraft.world.level.block.state.BlockStateList");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.world.level.chunk.LevelChunk", "net.minecraft.world.level.chunk.Chunk");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.world.level.material.FlowingFluid", "net.minecraft.world.level.material.FluidTypeFlowing");
|
|
||||||
spigotClassnames.put("net.minecraft.world.level.material.Fluids", "net.minecraft.world.level.material.FluidTypes");
|
|
||||||
spigotClassnames.put("net.minecraft.world.level.material.FluidState", "net.minecraft.world.level.material.Fluid");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.world.phys.BlockHitResult", "net.minecraft.world.phys.MovingObjectPositionBlock");
|
|
||||||
spigotClassnames.put("net.minecraft.world.phys.Vec3", "net.minecraft.world.phys.Vec3D");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.resources.ResourceLocation", "net.minecraft.resources.MinecraftKey");
|
|
||||||
|
|
||||||
spigotClassnames.put("net.minecraft.util.ProgressListener", "net.minecraft.util.IProgressUpdate");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Class<?> getClass(String name) {
|
|
||||||
try {
|
|
||||||
if (name.startsWith("org.bukkit.craftbukkit")) {
|
|
||||||
return Class.forName(ORG_BUKKIT_CRAFTBUKKIT + name.substring(22));
|
|
||||||
} else if (MAJOR_VERSION < 17 && name.startsWith("net.minecraft")) {
|
|
||||||
return Class.forName(LEGACY_NET_MINECRAFT_SERVER + "." + spigotClassnames.getOrDefault(name, name).split("[.](?=[^.]*$)")[1]);
|
|
||||||
} else if (MAJOR_VERSION < 21 || MINOR_VERSION < 4) {
|
|
||||||
return Class.forName(spigotClassnames.getOrDefault(name, name));
|
|
||||||
} else {
|
|
||||||
Class<?> clazz = null;
|
|
||||||
try {
|
|
||||||
clazz = Class.forName(name);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
}
|
|
||||||
if (clazz != null && clazz.getName().equals(name)) {
|
|
||||||
return clazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return Core.class.getClassLoader().getParent().loadClass(name);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
if (clazz == null) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return clazz;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new IllegalArgumentException("Cannot find " + name, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public static class Field<T> {
|
|
||||||
private final java.lang.reflect.Field f;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public T get(Object target) {
|
|
||||||
try {
|
|
||||||
return (T) f.get(target);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new IllegalArgumentException("Cannot read field", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(Object target, Object value) {
|
|
||||||
try {
|
|
||||||
f.set(target, value);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new IllegalArgumentException("Cannot write field", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Field<T> getField(Class<?> target, String name, Class<T> fieldType) {
|
|
||||||
return getField(target, name, fieldType, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Field<T> getField(Class<?> target, Class<T> fieldType, int index) {
|
|
||||||
return getField(target, null, fieldType, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Field<T> getField(Class<?> target, Class<T> fieldType, int index, Class<?>... parameters) {
|
|
||||||
return getField(target, null, fieldType, index, parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> Field<T> getField(Class<?> target, String name, Class<T> fieldType, int index, Class<?>... parameters) {
|
|
||||||
for (final java.lang.reflect.Field field : target.getDeclaredFields()) {
|
|
||||||
if (matching(field, name, fieldType, parameters) && index-- <= 0) {
|
|
||||||
field.setAccessible(true);
|
|
||||||
return new Field<>(field);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search in parent classes
|
|
||||||
if (target.getSuperclass() != null) {
|
|
||||||
return getField(target.getSuperclass(), name, fieldType, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("Cannot find field with type " + fieldType);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> boolean matching(java.lang.reflect.Field field, String name, Class<T> fieldType, Class<?>... parameters) {
|
|
||||||
if (name != null && !field.getName().equals(name)) return false;
|
|
||||||
|
|
||||||
if (!fieldType.isAssignableFrom(field.getType())) return false;
|
|
||||||
|
|
||||||
if (parameters.length > 0) {
|
|
||||||
Type[] arguments = ((ParameterizedType) field.getGenericType()).getActualTypeArguments();
|
|
||||||
|
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
|
||||||
if (arguments[i] instanceof ParameterizedType ? ((ParameterizedType) arguments[i]).getRawType() != parameters[i] : arguments[i] != parameters[i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public static class Method {
|
|
||||||
private final java.lang.reflect.Method m;
|
|
||||||
|
|
||||||
public Object invoke(Object target, Object... arguments) {
|
|
||||||
try {
|
|
||||||
return m.invoke(target, arguments);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException("Cannot invoke method " + m, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Method getTypedMethod(Class<?> clazz, String methodName, Class<?> returnType, Class<?>... params) {
|
|
||||||
for (final java.lang.reflect.Method method : clazz.getDeclaredMethods()) {
|
|
||||||
if ((methodName == null || method.getName().equals(methodName))
|
|
||||||
&& (returnType == null || method.getReturnType().equals(returnType))
|
|
||||||
&& Arrays.equals(method.getParameterTypes(), params)) {
|
|
||||||
method.setAccessible(true);
|
|
||||||
return new Method(method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search in every superclass
|
|
||||||
if (clazz.getSuperclass() != null) {
|
|
||||||
return getTypedMethod(clazz.getSuperclass(), methodName, returnType, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException(String.format("Cannot find method %s (%s).", methodName, Arrays.asList(params)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public static class Constructor {
|
|
||||||
private final java.lang.reflect.Constructor<?> c;
|
|
||||||
|
|
||||||
public Object invoke(Object... arguments) {
|
|
||||||
try {
|
|
||||||
return c.newInstance(arguments);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException("Cannot invoke constructor " + c, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Constructor getConstructor(Class<?> clazz, Class<?>... params) {
|
|
||||||
for (final java.lang.reflect.Constructor<?> constructor : clazz.getDeclaredConstructors()) {
|
|
||||||
if (Arrays.equals(constructor.getParameterTypes(), params)) {
|
|
||||||
constructor.setAccessible(true);
|
|
||||||
return new Constructor(constructor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(params)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object newInstance(Class<?> clazz) {
|
public static Object newInstance(Class<?> clazz) {
|
||||||
try {
|
try {
|
||||||
return Unsafe.getUnsafe().allocateInstance(clazz);
|
return Unsafe.getUnsafe().allocateInstance(clazz);
|
||||||
|
|||||||
@@ -19,13 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.core;
|
package de.steamwar.core;
|
||||||
|
|
||||||
import de.steamwar.Reflection;
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
|
||||||
import net.minecraft.network.syncher.EntityDataSerializer;
|
|
||||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
|
||||||
import net.minecraft.network.syncher.SynchedEntityData;
|
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@@ -40,15 +35,4 @@ public class BountifulWrapper {
|
|||||||
if (type == ChatMessageType.CHAT) type = ChatMessageType.SYSTEM;
|
if (type == ChatMessageType.CHAT) type = ChatMessageType.SYSTEM;
|
||||||
player.spigot().sendMessage(type, msg);
|
player.spigot().sendMessage(type, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Class<?> dataWatcherRegistry = EntityDataSerializers.class;
|
|
||||||
private static final Class<?> dataWatcherSerializer = EntityDataSerializer.class;
|
|
||||||
|
|
||||||
public Object getDataWatcherObject(int index, Class<?> type) {
|
|
||||||
return new EntityDataAccessor<>(index, (EntityDataSerializer<Object>) Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getDataWatcherItem(Object dwo, Object value) {
|
|
||||||
return new SynchedEntityData.DataItem<>((EntityDataAccessor<Object>) dwo, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* 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
|
* the Free Software Foundation, either versionStrings 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later versionStrings.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.core;
|
package de.steamwar.core;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.Reflection;
|
|
||||||
import de.steamwar.command.SWCommandUtils;
|
import de.steamwar.command.SWCommandUtils;
|
||||||
import de.steamwar.command.SWTypeMapperCreator;
|
import de.steamwar.command.SWTypeMapperCreator;
|
||||||
import de.steamwar.command.TabCompletionCache;
|
import de.steamwar.command.TabCompletionCache;
|
||||||
@@ -49,9 +48,13 @@ public class Core extends JavaPlugin {
|
|||||||
|
|
||||||
public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader());
|
public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader());
|
||||||
|
|
||||||
|
@Getter
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static int getVersion() {
|
private static final int version;
|
||||||
return Reflection.MAJOR_VERSION;
|
|
||||||
|
static {
|
||||||
|
String[] versionStrings = Bukkit.getServer().getBukkitVersion().split("-")[0].split("\\.");
|
||||||
|
version = Integer.parseInt(versionStrings[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2025 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.core;
|
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
|
||||||
import net.minecraft.network.chat.contents.PlainTextContents;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class FlatteningWrapper {
|
|
||||||
|
|
||||||
public Object formatDisplayName(String displayName) {
|
|
||||||
return displayName != null ? Optional.of((Object) MutableComponent.create(PlainTextContents.create(displayName))) : Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -49,7 +49,7 @@ public class RArmorStand extends REntity implements RInteractableEntity<RArmorSt
|
|||||||
super.spawn(packetSink);
|
super.spawn(packetSink);
|
||||||
|
|
||||||
if (size != null && size != Size.NORMAL) {
|
if (size != null && size != Size.NORMAL) {
|
||||||
packetSink.accept(getDataWatcherPacket(sizeWatcher, size.value));
|
entityDataPacket().add(sizeWatcher, size.value).send(packetSink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ public class RBlockDisplay extends RDisplay {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<BlockState> blockWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.BLOCK_STATE);
|
private static final EntityDataAccessor<BlockState> blockWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.BLOCK_STATE);
|
||||||
|
|
||||||
private void getBlock(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getBlock(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) {
|
if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) {
|
||||||
packetSink.accept(blockWatcher, ((CraftBlockData) block).getState());
|
packetSink.add(blockWatcher, ((CraftBlockData) block).getState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,18 +89,13 @@ public abstract class RDisplay extends REntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
protected final void sendPacket(Consumer<Object> packetSink, BiConsumer<Boolean, BiConsumer<Object, Object>>... dataSinkSinks) {
|
protected final void sendPacket(Consumer<Object> packetSink, BiConsumer<Boolean, EntityDataPacketBuilder>... dataSinkSinks) {
|
||||||
List<Object> keyValueData = new ArrayList<>();
|
EntityDataPacketBuilder builder = entityDataPacket();
|
||||||
boolean ignoreDefault = packetSink == updatePacketSink;
|
boolean ignoreDefault = packetSink == updatePacketSink;
|
||||||
for (BiConsumer<Boolean, BiConsumer<Object, Object>> dataSinkSink : dataSinkSinks) {
|
for (BiConsumer<Boolean, EntityDataPacketBuilder> dataSinkSink : dataSinkSinks) {
|
||||||
dataSinkSink.accept(ignoreDefault, (dataWatcher, value) -> {
|
dataSinkSink.accept(ignoreDefault, builder);
|
||||||
keyValueData.add(dataWatcher);
|
|
||||||
keyValueData.add(value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (!keyValueData.isEmpty()) {
|
|
||||||
packetSink.accept(getDataWatcherPacket(keyValueData.toArray()));
|
|
||||||
}
|
}
|
||||||
|
if (!builder.isEmpty()) builder.send(packetSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransform(@NonNull Transformation transform) {
|
public void setTransform(@NonNull Transformation transform) {
|
||||||
@@ -113,12 +108,12 @@ public abstract class RDisplay extends REntity {
|
|||||||
private static final EntityDataAccessor<Vector3f> scaleWatcher = new EntityDataAccessor<>(12, EntityDataSerializers.VECTOR3);
|
private static final EntityDataAccessor<Vector3f> scaleWatcher = new EntityDataAccessor<>(12, EntityDataSerializers.VECTOR3);
|
||||||
private static final EntityDataAccessor<Quaternionf> rightRotationWatcher = new EntityDataAccessor<>(14, EntityDataSerializers.QUATERNION);
|
private static final EntityDataAccessor<Quaternionf> rightRotationWatcher = new EntityDataAccessor<>(14, EntityDataSerializers.QUATERNION);
|
||||||
|
|
||||||
private void getTransformData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
private void getTransformData(boolean ignoreDefault, EntityDataPacketBuilder dataSink) {
|
||||||
if (ignoreDefault || !transform.equals(DEFAULT_TRANSFORM)) {
|
if (ignoreDefault || !transform.equals(DEFAULT_TRANSFORM)) {
|
||||||
dataSink.accept(translationWatcher, transform.getTranslation());
|
dataSink.add(translationWatcher, transform.getTranslation());
|
||||||
dataSink.accept(leftRotationWatcher, transform.getLeftRotation());
|
dataSink.add(leftRotationWatcher, transform.getLeftRotation());
|
||||||
dataSink.accept(scaleWatcher, transform.getScale());
|
dataSink.add(scaleWatcher, transform.getScale());
|
||||||
dataSink.accept(rightRotationWatcher, transform.getRightRotation());
|
dataSink.add(rightRotationWatcher, transform.getRightRotation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +125,10 @@ public abstract class RDisplay extends REntity {
|
|||||||
private static final EntityDataAccessor<Integer> transformationInterpolationDurationWatcher = new EntityDataAccessor<>(9, EntityDataSerializers.INT);
|
private static final EntityDataAccessor<Integer> transformationInterpolationDurationWatcher = new EntityDataAccessor<>(9, EntityDataSerializers.INT);
|
||||||
private static final EntityDataAccessor<Integer> positionOrRotationInterpolationDurationWatcher = new EntityDataAccessor<>(10, EntityDataSerializers.INT);
|
private static final EntityDataAccessor<Integer> positionOrRotationInterpolationDurationWatcher = new EntityDataAccessor<>(10, EntityDataSerializers.INT);
|
||||||
|
|
||||||
private void getInterpolationDuration(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getInterpolationDuration(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || interpolationDelay != 0) {
|
if (ignoreDefault || interpolationDelay != 0) {
|
||||||
packetSink.accept(transformationInterpolationDurationWatcher, interpolationDuration);
|
packetSink.add(transformationInterpolationDurationWatcher, interpolationDuration);
|
||||||
packetSink.accept(positionOrRotationInterpolationDurationWatcher, interpolationDuration);
|
packetSink.add(positionOrRotationInterpolationDurationWatcher, interpolationDuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,9 +139,9 @@ public abstract class RDisplay extends REntity {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Float> viewRangeWatcher = new EntityDataAccessor<>(17, EntityDataSerializers.FLOAT);
|
private static final EntityDataAccessor<Float> viewRangeWatcher = new EntityDataAccessor<>(17, EntityDataSerializers.FLOAT);
|
||||||
|
|
||||||
private void getViewRange(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getViewRange(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || viewRange != 1.0F) {
|
if (ignoreDefault || viewRange != 1.0F) {
|
||||||
packetSink.accept(viewRangeWatcher, viewRange);
|
packetSink.add(viewRangeWatcher, viewRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,9 +152,9 @@ public abstract class RDisplay extends REntity {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Float> shadowRadiusWatcher = new EntityDataAccessor<>(18, EntityDataSerializers.FLOAT);
|
private static final EntityDataAccessor<Float> shadowRadiusWatcher = new EntityDataAccessor<>(18, EntityDataSerializers.FLOAT);
|
||||||
|
|
||||||
private void getShadowRadius(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getShadowRadius(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || shadowRadius != 0.0F) {
|
if (ignoreDefault || shadowRadius != 0.0F) {
|
||||||
packetSink.accept(shadowRadiusWatcher, shadowRadius);
|
packetSink.add(shadowRadiusWatcher, shadowRadius);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,9 +165,9 @@ public abstract class RDisplay extends REntity {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Float> shadowStrengthWatcher = new EntityDataAccessor<>(19, EntityDataSerializers.FLOAT);
|
private static final EntityDataAccessor<Float> shadowStrengthWatcher = new EntityDataAccessor<>(19, EntityDataSerializers.FLOAT);
|
||||||
|
|
||||||
private void getShadowStrength(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getShadowStrength(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || shadowStrength != 1.0F) {
|
if (ignoreDefault || shadowStrength != 1.0F) {
|
||||||
packetSink.accept(shadowStrengthWatcher, shadowStrength);
|
packetSink.add(shadowStrengthWatcher, shadowStrength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,9 +178,9 @@ public abstract class RDisplay extends REntity {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Float> displayWidthWatcher = new EntityDataAccessor<>(20, EntityDataSerializers.FLOAT);
|
private static final EntityDataAccessor<Float> displayWidthWatcher = new EntityDataAccessor<>(20, EntityDataSerializers.FLOAT);
|
||||||
|
|
||||||
private void getDisplayWidth(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getDisplayWidth(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || displayWidth != 0.0F) {
|
if (ignoreDefault || displayWidth != 0.0F) {
|
||||||
packetSink.accept(displayWidthWatcher, displayWidth);
|
packetSink.add(displayWidthWatcher, displayWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,9 +191,9 @@ public abstract class RDisplay extends REntity {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Float> displayHeightWatcher = new EntityDataAccessor<>(21, EntityDataSerializers.FLOAT);
|
private static final EntityDataAccessor<Float> displayHeightWatcher = new EntityDataAccessor<>(21, EntityDataSerializers.FLOAT);
|
||||||
|
|
||||||
private void getDisplayHeight(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getDisplayHeight(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || displayHeight != 0.0F) {
|
if (ignoreDefault || displayHeight != 0.0F) {
|
||||||
packetSink.accept(displayHeightWatcher, displayHeight);
|
packetSink.add(displayHeightWatcher, displayHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,9 +204,9 @@ public abstract class RDisplay extends REntity {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Integer> interpolationDelayWatcher = new EntityDataAccessor<>(8, EntityDataSerializers.INT);
|
private static final EntityDataAccessor<Integer> interpolationDelayWatcher = new EntityDataAccessor<>(8, EntityDataSerializers.INT);
|
||||||
|
|
||||||
private void getInterpolationDelay(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getInterpolationDelay(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || interpolationDelay != 0) {
|
if (ignoreDefault || interpolationDelay != 0) {
|
||||||
packetSink.accept(interpolationDelayWatcher, interpolationDelay);
|
packetSink.add(interpolationDelayWatcher, interpolationDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,9 +217,9 @@ public abstract class RDisplay extends REntity {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Byte> billboardWatcher = new EntityDataAccessor<>(15, EntityDataSerializers.BYTE);
|
private static final EntityDataAccessor<Byte> billboardWatcher = new EntityDataAccessor<>(15, EntityDataSerializers.BYTE);
|
||||||
|
|
||||||
private void getBillboard(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getBillboard(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || billboard != Display.Billboard.FIXED) {
|
if (ignoreDefault || billboard != Display.Billboard.FIXED) {
|
||||||
packetSink.accept(billboardWatcher, (byte) billboard.ordinal());
|
packetSink.add(billboardWatcher, (byte) billboard.ordinal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +230,9 @@ public abstract class RDisplay extends REntity {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Integer> glowColorOverrideWatcher = new EntityDataAccessor<>(22, EntityDataSerializers.INT);
|
private static final EntityDataAccessor<Integer> glowColorOverrideWatcher = new EntityDataAccessor<>(22, EntityDataSerializers.INT);
|
||||||
|
|
||||||
private void getGlowColorOverride(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getGlowColorOverride(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || glowColorOverride != null) {
|
if (ignoreDefault || glowColorOverride != null) {
|
||||||
packetSink.accept(glowColorOverrideWatcher, glowColorOverride == null ? -1 : glowColorOverride.asARGB());
|
packetSink.add(glowColorOverrideWatcher, glowColorOverride == null ? -1 : glowColorOverride.asARGB());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,9 +243,9 @@ public abstract class RDisplay extends REntity {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Integer> brightnessWatcher = new EntityDataAccessor<>(16, EntityDataSerializers.INT);
|
private static final EntityDataAccessor<Integer> brightnessWatcher = new EntityDataAccessor<>(16, EntityDataSerializers.INT);
|
||||||
|
|
||||||
private void getBrightness(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getBrightness(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || brightness != null) {
|
if (ignoreDefault || brightness != null) {
|
||||||
packetSink.accept(brightnessWatcher, brightness == null ? -1 : brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20);
|
packetSink.add(brightnessWatcher, brightness == null ? -1 : brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ package de.steamwar.entity;
|
|||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import de.steamwar.Reflection;
|
import de.steamwar.Reflection;
|
||||||
import de.steamwar.core.BountifulWrapper;
|
|
||||||
import de.steamwar.core.FlatteningWrapper;
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
import net.minecraft.network.chat.contents.PlainTextContents;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
@@ -193,12 +193,12 @@ public class REntity {
|
|||||||
|
|
||||||
public void setPose(Pose pose) {
|
public void setPose(Pose pose) {
|
||||||
this.pose = pose;
|
this.pose = pose;
|
||||||
server.updateEntity(this, getDataWatcherPacket(poseDataWatcher, pose));
|
server.updateEntity(this, entityDataPacket().add(poseDataWatcher, pose).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnFire(boolean perma) {
|
public void setOnFire(boolean perma) {
|
||||||
fireTick = perma ? -1 : 21;
|
fireTick = perma ? -1 : 21;
|
||||||
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
server.updateEntity(this, entityDataPacket().add(entityStatusWatcher, getEntityStatus()).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOnFire() {
|
public boolean isOnFire() {
|
||||||
@@ -207,20 +207,18 @@ public class REntity {
|
|||||||
|
|
||||||
public void setInvisible(boolean invisible) {
|
public void setInvisible(boolean invisible) {
|
||||||
this.invisible = invisible;
|
this.invisible = invisible;
|
||||||
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
server.updateEntity(this, entityDataPacket().add(entityStatusWatcher, getEntityStatus()).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBowDrawn(boolean drawn, boolean offHand) {
|
public void setBowDrawn(boolean drawn, boolean offHand) {
|
||||||
bowDrawn = drawn;
|
bowDrawn = drawn;
|
||||||
server.updateEntity(this, getDataWatcherPacket(poseDataWatcher, Pose.SHOOTING));
|
server.updateEntity(this, entityDataPacket().add(poseDataWatcher, Pose.SHOOTING).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplayName(String displayName) {
|
public void setDisplayName(String displayName) {
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
server.updateEntity(this, getDataWatcherPacket(
|
server.updateEntity(this, entityDataPacket().add(nameWatcher, formatDisplayName(displayName))
|
||||||
nameWatcher, FlatteningWrapper.formatDisplayName(displayName),
|
.add(nameVisibleWatcher, displayName != null).build());
|
||||||
nameVisibleWatcher, displayName != null
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItem(Object slot, ItemStack stack) {
|
public void setItem(Object slot, ItemStack stack) {
|
||||||
@@ -234,12 +232,12 @@ public class REntity {
|
|||||||
|
|
||||||
public void setNoGravity(boolean noGravity) {
|
public void setNoGravity(boolean noGravity) {
|
||||||
this.noGravity = noGravity;
|
this.noGravity = noGravity;
|
||||||
server.updateEntity(this, getDataWatcherPacket(noGravityDataWatcher, noGravity));
|
server.updateEntity(this, entityDataPacket().add(noGravityDataWatcher, noGravity).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGlowing(boolean glowing) {
|
public void setGlowing(boolean glowing) {
|
||||||
this.isGlowing = glowing;
|
this.isGlowing = glowing;
|
||||||
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
server.updateEntity(this, entityDataPacket().add(entityStatusWatcher, getEntityStatus()).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClientboundAddEntityPacket spawnPacketGenerator() {
|
private ClientboundAddEntityPacket spawnPacketGenerator() {
|
||||||
@@ -263,20 +261,22 @@ public class REntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pose != Pose.STANDING) {
|
if (pose != Pose.STANDING) {
|
||||||
packetSink.accept(getDataWatcherPacket(poseDataWatcher, pose));
|
entityDataPacket().add(poseDataWatcher, pose).send(packetSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte status = getEntityStatus();
|
byte status = getEntityStatus();
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
packetSink.accept(getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
entityDataPacket().add(entityStatusWatcher, getEntityStatus()).send(packetSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayName != null) {
|
if (displayName != null) {
|
||||||
packetSink.accept(getDataWatcherPacket(nameWatcher, FlatteningWrapper.formatDisplayName(displayName), nameVisibleWatcher, true));
|
entityDataPacket().add(nameWatcher, formatDisplayName(displayName))
|
||||||
|
.add(nameVisibleWatcher, true)
|
||||||
|
.send(packetSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (noGravity) {
|
if (noGravity) {
|
||||||
packetSink.accept(getDataWatcherPacket(noGravityDataWatcher, true));
|
entityDataPacket().add(noGravityDataWatcher, true).send(packetSink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ public class REntity {
|
|||||||
if (fireTick > 0) {
|
if (fireTick > 0) {
|
||||||
fireTick--;
|
fireTick--;
|
||||||
if (fireTick == 0) {
|
if (fireTick == 0) {
|
||||||
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
server.updateEntity(this, entityDataPacket().add(entityStatusWatcher, getEntityStatus()).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,13 +315,29 @@ public class REntity {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object getDataWatcherPacket(Object... dataWatcherKeyValues) {
|
protected EntityDataPacketBuilder entityDataPacket() {
|
||||||
ArrayList<SynchedEntityData.DataValue<?>> nativeWatchers = new ArrayList<>(1);
|
return new EntityDataPacketBuilder();
|
||||||
for (int i = 0; i < dataWatcherKeyValues.length; i += 2) {
|
|
||||||
nativeWatchers.add(((SynchedEntityData.DataItem<?>) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i + 1])).value());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ClientboundSetEntityDataPacket(entityId, nativeWatchers);
|
public class EntityDataPacketBuilder {
|
||||||
|
private List<SynchedEntityData.DataValue<?>> values = new ArrayList<>();
|
||||||
|
|
||||||
|
public <T> EntityDataPacketBuilder add(EntityDataAccessor<T> accessor, T value) {
|
||||||
|
values.add(new SynchedEntityData.DataItem<>(accessor, value).value());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return values.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientboundSetEntityDataPacket build() {
|
||||||
|
return new ClientboundSetEntityDataPacket(entityId, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(Consumer<Object> packetSink) {
|
||||||
|
packetSink.accept(build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getTeleportPacket() {
|
private Object getTeleportPacket() {
|
||||||
@@ -364,4 +380,8 @@ public class REntity {
|
|||||||
private int calcVelocity(double value) {
|
private int calcVelocity(double value) {
|
||||||
return (int) (Math.max(-3.9, Math.min(value, 3.9)) * 8000);
|
return (int) (Math.max(-3.9, Math.min(value, 3.9)) * 8000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Optional<Component> formatDisplayName(String displayName) {
|
||||||
|
return displayName != null ? Optional.of(MutableComponent.create(PlainTextContents.create(displayName))) : Optional.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,13 @@
|
|||||||
|
|
||||||
package de.steamwar.entity;
|
package de.steamwar.entity;
|
||||||
|
|
||||||
import de.steamwar.core.BountifulWrapper;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||||
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -61,18 +60,13 @@ public class RInteraction extends REntity implements RInteractableEntity<RIntera
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
protected final void sendPacket(Consumer<Object> packetSink, BiConsumer<Boolean, BiConsumer<Object, Object>>... dataSinkSinks) {
|
protected final void sendPacket(Consumer<Object> packetSink, BiConsumer<Boolean, EntityDataPacketBuilder>... dataSinkSinks) {
|
||||||
List<Object> keyValueData = new ArrayList<>();
|
EntityDataPacketBuilder builder = entityDataPacket();
|
||||||
boolean ignoreDefault = packetSink == updatePacketSink;
|
boolean ignoreDefault = packetSink == updatePacketSink;
|
||||||
for (BiConsumer<Boolean, BiConsumer<Object, Object>> dataSinkSink : dataSinkSinks) {
|
for (BiConsumer<Boolean, EntityDataPacketBuilder> dataSinkSink : dataSinkSinks) {
|
||||||
dataSinkSink.accept(ignoreDefault, (dataWatcher, value) -> {
|
dataSinkSink.accept(ignoreDefault, builder);
|
||||||
keyValueData.add(dataWatcher);
|
|
||||||
keyValueData.add(value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (!keyValueData.isEmpty()) {
|
|
||||||
packetSink.accept(getDataWatcherPacket(keyValueData.toArray()));
|
|
||||||
}
|
}
|
||||||
|
if (!builder.isEmpty()) builder.send(packetSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInteractionWidth(float interactionWidth) {
|
public void setInteractionWidth(float interactionWidth) {
|
||||||
@@ -80,11 +74,11 @@ public class RInteraction extends REntity implements RInteractableEntity<RIntera
|
|||||||
sendPacket(updatePacketSink, this::getInteractionWidthData);
|
sendPacket(updatePacketSink, this::getInteractionWidthData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Object interactionWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Float.class);
|
private static final EntityDataAccessor<Float> interactionWidthWatcher = new EntityDataAccessor<>(8, EntityDataSerializers.FLOAT);
|
||||||
|
|
||||||
private void getInteractionWidthData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
private void getInteractionWidthData(boolean ignoreDefault, EntityDataPacketBuilder dataSink) {
|
||||||
if (ignoreDefault || interactionWidth != 1.0) {
|
if (ignoreDefault || interactionWidth != 1.0) {
|
||||||
dataSink.accept(interactionWidthWatcher, interactionWidth);
|
dataSink.add(interactionWidthWatcher, interactionWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +87,11 @@ public class RInteraction extends REntity implements RInteractableEntity<RIntera
|
|||||||
sendPacket(updatePacketSink, this::getInteractionHeightData);
|
sendPacket(updatePacketSink, this::getInteractionHeightData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Object interactionHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Float.class);
|
private static final EntityDataAccessor<Float> interactionHeightWatcher = new EntityDataAccessor<>(9, EntityDataSerializers.FLOAT);
|
||||||
|
|
||||||
private void getInteractionHeightData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
private void getInteractionHeightData(boolean ignoreDefault, EntityDataPacketBuilder dataSink) {
|
||||||
if (ignoreDefault || interactionHeight != 1.0) {
|
if (ignoreDefault || interactionHeight != 1.0) {
|
||||||
dataSink.accept(interactionHeightWatcher, interactionHeight);
|
dataSink.add(interactionHeightWatcher, interactionHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,11 +100,11 @@ public class RInteraction extends REntity implements RInteractableEntity<RIntera
|
|||||||
sendPacket(updatePacketSink, this::getResponsiveData);
|
sendPacket(updatePacketSink, this::getResponsiveData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Object responsiveWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Boolean.class);
|
private static final EntityDataAccessor<Boolean> responsiveWatcher = new EntityDataAccessor<>(10, EntityDataSerializers.BOOLEAN);
|
||||||
|
|
||||||
private void getResponsiveData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
private void getResponsiveData(boolean ignoreDefault, EntityDataPacketBuilder dataSink) {
|
||||||
if (ignoreDefault || !responsive) {
|
if (ignoreDefault || !responsive) {
|
||||||
dataSink.accept(responsiveWatcher, responsive);
|
dataSink.add(responsiveWatcher, responsive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,9 +63,9 @@ public class RItemDisplay extends RDisplay {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<net.minecraft.world.item.ItemStack> itemStackWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.ITEM_STACK);
|
private static final EntityDataAccessor<net.minecraft.world.item.ItemStack> itemStackWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.ITEM_STACK);
|
||||||
|
|
||||||
private void getItemStack(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getItemStack(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || !itemStack.equals(DEFAULT_ITEM_STACK)) {
|
if (ignoreDefault || !itemStack.equals(DEFAULT_ITEM_STACK)) {
|
||||||
packetSink.accept(itemStackWatcher, CraftItemStack.asNMSCopy(itemStack));
|
packetSink.add(itemStackWatcher, CraftItemStack.asNMSCopy(itemStack));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,9 +76,9 @@ public class RItemDisplay extends RDisplay {
|
|||||||
sendPacket(updatePacketSink, this::getItemDisplayTransform);
|
sendPacket(updatePacketSink, this::getItemDisplayTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getItemDisplayTransform(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getItemDisplayTransform(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || itemDisplayTransform != ItemDisplay.ItemDisplayTransform.NONE) {
|
if (ignoreDefault || itemDisplayTransform != ItemDisplay.ItemDisplayTransform.NONE) {
|
||||||
packetSink.accept(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal());
|
packetSink.add(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ package de.steamwar.entity;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import de.steamwar.core.BountifulWrapper;
|
|
||||||
import de.steamwar.core.ProtocolWrapper;
|
import de.steamwar.core.ProtocolWrapper;
|
||||||
import de.steamwar.network.CoreNetworkHandler;
|
import de.steamwar.network.CoreNetworkHandler;
|
||||||
import de.steamwar.network.NetworkSender;
|
import de.steamwar.network.NetworkSender;
|
||||||
@@ -29,6 +28,8 @@ import de.steamwar.network.packets.common.PlayerSkinRequestPacket;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
||||||
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||||
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -42,7 +43,7 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class RPlayer extends REntity implements RInteractableEntity<RPlayer> {
|
public class RPlayer extends REntity implements RInteractableEntity<RPlayer> {
|
||||||
|
|
||||||
private static final Object skinPartsDataWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Byte.class);
|
private static final EntityDataAccessor<Byte> skinPartsDataWatcher = new EntityDataAccessor<>(17, EntityDataSerializers.BYTE);
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final UUID actualUUID;
|
private final UUID actualUUID;
|
||||||
@@ -85,7 +86,7 @@ public class RPlayer extends REntity implements RInteractableEntity<RPlayer> {
|
|||||||
@Override
|
@Override
|
||||||
void spawn(Consumer<Object> packetSink) {
|
void spawn(Consumer<Object> packetSink) {
|
||||||
packetSink.accept(getNamedSpawnPacket());
|
packetSink.accept(getNamedSpawnPacket());
|
||||||
packetSink.accept(getDataWatcherPacket(skinPartsDataWatcher, (byte) 0x7F));
|
entityDataPacket().add(skinPartsDataWatcher, (byte) 0x7F).send(packetSink);
|
||||||
|
|
||||||
for (Map.Entry<Object, ItemStack> entry : itemSlots.entrySet()) {
|
for (Map.Entry<Object, ItemStack> entry : itemSlots.entrySet()) {
|
||||||
packetSink.accept(getEquipmentPacket(entry.getKey(), entry.getValue()));
|
packetSink.accept(getEquipmentPacket(entry.getKey(), entry.getValue()));
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ public class RTextDisplay extends RDisplay {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Component> textWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.COMPONENT);
|
private static final EntityDataAccessor<Component> textWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.COMPONENT);
|
||||||
|
|
||||||
private void getText(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getText(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || !text.isEmpty()) {
|
if (ignoreDefault || !text.isEmpty()) {
|
||||||
packetSink.accept(textWatcher, MutableComponent.create(PlainTextContents.create(text)));
|
packetSink.add(textWatcher, MutableComponent.create(PlainTextContents.create(text)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,9 +90,9 @@ public class RTextDisplay extends RDisplay {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Integer> lineWidthWatcher = new EntityDataAccessor<>(24, EntityDataSerializers.INT);
|
private static final EntityDataAccessor<Integer> lineWidthWatcher = new EntityDataAccessor<>(24, EntityDataSerializers.INT);
|
||||||
|
|
||||||
private void getLineWidth(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getLineWidth(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || lineWidth != 200) {
|
if (ignoreDefault || lineWidth != 200) {
|
||||||
packetSink.accept(lineWidthWatcher, lineWidth);
|
packetSink.add(lineWidthWatcher, lineWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,9 +103,9 @@ public class RTextDisplay extends RDisplay {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Byte> textOpacityWatcher = new EntityDataAccessor<>(26, EntityDataSerializers.BYTE);
|
private static final EntityDataAccessor<Byte> textOpacityWatcher = new EntityDataAccessor<>(26, EntityDataSerializers.BYTE);
|
||||||
|
|
||||||
private void getTextOpacity(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getTextOpacity(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || textOpacity != (byte) -1) {
|
if (ignoreDefault || textOpacity != (byte) -1) {
|
||||||
packetSink.accept(textOpacityWatcher, textOpacity);
|
packetSink.add(textOpacityWatcher, textOpacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +126,9 @@ public class RTextDisplay extends RDisplay {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Integer> backgroundColorWatcher = new EntityDataAccessor<>(25, EntityDataSerializers.INT);
|
private static final EntityDataAccessor<Integer> backgroundColorWatcher = new EntityDataAccessor<>(25, EntityDataSerializers.INT);
|
||||||
|
|
||||||
private void getBackgroundColor(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getBackgroundColor(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
if (ignoreDefault || backgroundColor != null) {
|
if (ignoreDefault || backgroundColor != null) {
|
||||||
packetSink.accept(backgroundColorWatcher, backgroundColor);
|
packetSink.add(backgroundColorWatcher, backgroundColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ public class RTextDisplay extends RDisplay {
|
|||||||
|
|
||||||
private static final EntityDataAccessor<Byte> textStatusWatcher = new EntityDataAccessor<>(27, EntityDataSerializers.BYTE);
|
private static final EntityDataAccessor<Byte> textStatusWatcher = new EntityDataAccessor<>(27, EntityDataSerializers.BYTE);
|
||||||
|
|
||||||
private void getTextStatus(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
private void getTextStatus(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||||
byte status = 0;
|
byte status = 0;
|
||||||
|
|
||||||
if (shadowed) {
|
if (shadowed) {
|
||||||
@@ -167,7 +167,7 @@ public class RTextDisplay extends RDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ignoreDefault || status != 0) {
|
if (ignoreDefault || status != 0) {
|
||||||
packetSink.accept(textStatusWatcher, status);
|
packetSink.add(textStatusWatcher, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,16 +19,13 @@
|
|||||||
|
|
||||||
package de.steamwar.techhider.legacy;
|
package de.steamwar.techhider.legacy;
|
||||||
|
|
||||||
import de.steamwar.Reflection;
|
|
||||||
import de.steamwar.techhider.ProtocolUtils;
|
import de.steamwar.techhider.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
|
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.util.SimpleBitStorage;
|
import net.minecraft.util.SimpleBitStorage;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -85,12 +82,9 @@ public class ChunkHider {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Registry<BlockEntityType<?>> registry = Reflection.getField(BuiltInRegistries.class, "BLOCK_ENTITY_TYPE", Registry.class).get(null);
|
|
||||||
private static final Reflection.Method getKey = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.core.Registry"), "getKey", ResourceLocation.class, Object.class);
|
|
||||||
|
|
||||||
protected boolean tileEntityVisible(Set<String> hiddenBlockEntities, ClientboundLevelChunkPacketData.BlockEntityInfo tile) {
|
protected boolean tileEntityVisible(Set<String> hiddenBlockEntities, ClientboundLevelChunkPacketData.BlockEntityInfo tile) {
|
||||||
BlockEntityType<?> type = tile.type;
|
BlockEntityType<?> type = tile.type;
|
||||||
String path = ((ResourceLocation) getKey.invoke(registry, type)).getPath();
|
String path = BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(type).getPath();
|
||||||
return !hiddenBlockEntities.contains(path);
|
return !hiddenBlockEntities.contains(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ abstract class WidenerExtension {
|
|||||||
abstract val accessWidenerFiles: ConfigurableFileCollection
|
abstract val accessWidenerFiles: ConfigurableFileCollection
|
||||||
|
|
||||||
fun fromCatalog(vararg dependencies: Provider<MinimalExternalModuleDependency>) {
|
fun fromCatalog(vararg dependencies: Provider<MinimalExternalModuleDependency>) {
|
||||||
val files = dependencies.map { dependency ->
|
dependencies.map { dependency ->
|
||||||
project.provider {
|
project.provider {
|
||||||
val dep = dependency.get()
|
val dep = dependency.get()
|
||||||
|
|
||||||
@@ -45,8 +45,6 @@ abstract class WidenerExtension {
|
|||||||
}
|
}
|
||||||
.file
|
.file
|
||||||
}
|
}
|
||||||
}
|
}.let { inputJars.from(it) }
|
||||||
|
|
||||||
inputJars.from(files)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,8 +23,6 @@ widener.accessWidenerFiles.setFrom(
|
|||||||
fileTree("src/") { include("**/*.accesswidener") }
|
fileTree("src/") { include("**/*.accesswidener") }
|
||||||
)
|
)
|
||||||
|
|
||||||
// ─── Tasks (unchanged from before) ───────────────────────────────────────────
|
|
||||||
|
|
||||||
val jarWidenerClasspath = rootProject.project(":AccessWidener")
|
val jarWidenerClasspath = rootProject.project(":AccessWidener")
|
||||||
.tasks.named("shadowJar")
|
.tasks.named("shadowJar")
|
||||||
.get().outputs.files
|
.get().outputs.files
|
||||||
@@ -68,7 +66,6 @@ project.gradle.projectsEvaluated {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.named("compileJava") {
|
tasks.named("compileJava") {
|
||||||
// dependsOn(allWidenedJars.buildDependencies)
|
|
||||||
dependsOn(allWidenedJars)
|
dependsOn(allWidenedJars)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user