From 3e270643e8e985f94e0d10f43a579c5dd0d8e85a Mon Sep 17 00:00:00 2001 From: TheBreadBeard Date: Wed, 27 Nov 2024 19:18:41 +0100 Subject: [PATCH 001/106] Add private ticket log --- .../discord/listeners/DiscordTicketHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java index a9592c6c..27a20fb6 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java @@ -126,6 +126,14 @@ public class DiscordTicketHandler extends ListenerAdapter { SplitUtil.Strategy.ANYWHERE ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())).forEach(builder -> logChannel.sendMessage(builder.build()).queue()); + SplitUtil.split( + messages.stream() + .map(StringBuilder::toString).collect(Collectors.joining()), + 2000, + SplitUtil.Strategy.NEWLINE, + SplitUtil.Strategy.ANYWHERE + ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())).forEach(builder -> logChannel.sendMessage(builder.build()).queue()); + Chatter.serverteam().prefixless("DISCORD_TICKET_CLOSED", channel.getName()); channel.delete().reason("Closed").queue(); } From b3cd8d843f5da01c75161966473521b8a27df1f3 Mon Sep 17 00:00:00 2001 From: TheBreadBeard Date: Wed, 27 Nov 2024 19:34:19 +0100 Subject: [PATCH 002/106] Add private ticket log --- .../velocitycore/discord/listeners/DiscordTicketHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java index 27a20fb6..d797a6f3 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java @@ -132,7 +132,7 @@ public class DiscordTicketHandler extends ListenerAdapter { 2000, SplitUtil.Strategy.NEWLINE, SplitUtil.Strategy.ANYWHERE - ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())).forEach(builder -> logChannel.sendMessage(builder.build()).queue()); + ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())).forEach(builder -> user.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(builder.build()).queue())); Chatter.serverteam().prefixless("DISCORD_TICKET_CLOSED", channel.getName()); channel.delete().reason("Closed").queue(); From 0134ef1f6181369137666f615968839f0dbc2eb9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 3 Dec 2024 22:43:14 +0100 Subject: [PATCH 003/106] Maybe, Fix Schematics Readers --- .../SQL/src/de/steamwar/sql/NodeData.java | 26 +- .../src/de/steamwar/sql/SchematicNode.java | 5 +- .../fightsystem/utils/WorldeditWrapper14.java | 3 +- .../fightsystem/utils/WorldeditWrapper8.java | 3 +- .../fightsystem/record/PacketProcessor.java | 3 +- .../SchematicCommandUtils.java | 2 +- .../de/steamwar/core/WorldEditWrapper14.java | 57 +- .../de/steamwar/core/WorldEditWrapper18.java | 13 +- SpigotCore/SpigotCore_21/build.gradle.kts | 20 +- .../steamwar/core/FaWeSchematicReaderV3.java | 857 ++++++++++++++++++ .../de/steamwar/core/WorldEditWrapper21.java | 49 +- .../de/steamwar/core/WorldEditWrapper8.java | 46 +- .../src/de/steamwar/core/ErrorHandler.java | 2 +- .../de/steamwar/core/WorldEditWrapper.java | 24 +- .../src/de/steamwar/sql/SchematicData.java | 10 +- SpigotCore/build.gradle.kts | 7 +- .../discord/listeners/DiscordSchemUpload.java | 2 +- .../src/de/steamwar/routes/Schematic.kt | 6 +- 18 files changed, 1010 insertions(+), 125 deletions(-) create mode 100644 SpigotCore/SpigotCore_21/src/de/steamwar/core/FaWeSchematicReaderV3.java diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java index 52743811..c580dc3f 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java @@ -28,12 +28,15 @@ import java.sql.PreparedStatement; import java.util.zip.GZIPInputStream; @AllArgsConstructor +@Getter public class NodeData { static { new SqlTypeMapper<>(PipedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("PipedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream); new SqlTypeMapper<>(ByteArrayInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("ByteArrayInputStream is write only datatype"); }, PreparedStatement::setBinaryStream); new SqlTypeMapper<>(BufferedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("BufferedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream); + + SqlTypeMapper.ordinalEnumMapper(SchematicFormat.class); } private static final Table table = new Table<>(NodeData.class); @@ -48,21 +51,24 @@ public class NodeData { throw new IllegalArgumentException("Node is a directory"); return get.select(rs -> { if(rs.next()) { - return new NodeData(node.getId(), rs.getBoolean("NodeFormat")); + return new NodeData(node.getId(), SchematicFormat.values()[rs.getInt("NodeFormat")]); } else { - return new NodeData(node.getId(), false); + return new NodeData(node.getId(), SchematicFormat.MCEDIT); } }, node); } - @Getter @Field(keys = {Table.PRIMARY}) private final int nodeId; @Field - private boolean nodeFormat; + private SchematicFormat nodeFormat; public InputStream schemData() throws IOException { + return new GZIPInputStream(schemDataRaw()); + } + + public InputStream schemDataRaw() throws IOException { try { return selSchemData.select(rs -> { rs.next(); @@ -81,12 +87,18 @@ public class NodeData { } } - public void saveFromStream(InputStream blob, boolean newFormat) { + public void saveFromStream(InputStream blob, SchematicFormat newFormat) { updateDatabase.update(nodeId, newFormat, blob); nodeFormat = newFormat; } - public boolean getNodeFormat() { - return nodeFormat; + @AllArgsConstructor + @Getter + public enum SchematicFormat { + MCEDIT(".schematic"), + V2(".schem"), + V3(".schem"); + + private final String fileEnding; } } diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java index 3df740da..bece8549 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java @@ -375,11 +375,10 @@ public class SchematicNode { return nodeType == null; } - @Deprecated - public boolean getSchemFormat() { + public String getFileEnding() { if(isDir()) throw new SecurityException("Node is Directory"); - return NodeData.get(this).getNodeFormat(); + return NodeData.get(this).getNodeFormat().getFileEnding(); } public int getRank() { diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 288b89e8..df366205 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -42,6 +42,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; @@ -144,6 +145,6 @@ public class WorldeditWrapper14 implements WorldeditWrapper { throw new SecurityException(e); } - new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), true); + new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.V2); } } diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index 19854db8..018552f2 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -39,6 +39,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; @@ -142,6 +143,6 @@ public class WorldeditWrapper8 implements WorldeditWrapper { throw new SecurityException(e); } - new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), false); + new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.MCEDIT); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index ee0c1af1..e6ed1d3a 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -22,6 +22,7 @@ package de.steamwar.fightsystem.record; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; import de.steamwar.core.TrickyTrialsWrapper; +import de.steamwar.core.WorldEditWrapper; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RPlayer; @@ -519,7 +520,7 @@ public class PacketProcessor implements Listener { public void close() { // FAWE 1.12 calls close... } - }, Core.getVersion() > 12); + }, WorldEditWrapper.getNativeFormat()); execSync(() -> team.pasteSchem(schemId, clipboard)); } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index 753cd3b9..14ecdabb 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -245,7 +245,7 @@ public class SchematicCommandUtils { SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_ELO", player, node.getElo(Season.getSeason())); } - SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_FORMAT", player, node.getSchemFormat() ? ".schem" : ".schematic"); + SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_FORMAT", player, node.getFileEnding()); CheckedSchematic.getLastDeclinedOfNode(node.getId()).stream().findFirst().ifPresent(checkedSchematic -> SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_STATUS", player, checkedSchematic.getEndTime(), checkedSchematic.getDeclineReason())); } else { SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_TYPE", player, SchematicSystem.MESSAGE.parse("UTIL_INFO_TYPE_DIR", player)); diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java index cd116bac..cba992f5 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java @@ -45,6 +45,7 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; import de.steamwar.sql.NoClipboardException; +import de.steamwar.sql.NodeData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -57,24 +58,17 @@ import static com.google.common.base.Preconditions.checkNotNull; public class WorldEditWrapper14 implements WorldEditWrapper { - private static final ClipboardFormat SCHEMATIC = BuiltInClipboardFormat.MCEDIT_SCHEMATIC; - private static final ClipboardFormat SCHEM = BuiltInClipboardFormat.SPONGE_SCHEMATIC; - @Override - public InputStream getPlayerClipboard(Player player, boolean schemFormat) { - return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) -> { - if(schemFormat){ - ClipboardWriter writer = SCHEM.getWriter(outputStream); - writer.write(clipboard); - writer.close(); - }else{ - SCHEMATIC.getWriter(outputStream).write(clipboard); - } + public InputStream getPlayerClipboard(Player player) { + return WorldEditWrapper.getPlayerClipboard(player, (outputStream, clipboard, clipboardHolder) -> { + ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(outputStream); + writer.write(clipboard); + writer.close(); }); } @Override - public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) { + public void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat) { Clipboard clipboard = null; try { clipboard = getClipboard(is, schemFormat); @@ -90,12 +84,16 @@ public class WorldEditWrapper14 implements WorldEditWrapper { } @Override - public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { + public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { try { - if(schemFormat){ - return new SpongeSchematicReader(new NBTInputStream(is)).read(); - }else{ - return new MCEditSchematicReader(new NBTInputStream(is)).read(); + + switch (schemFormat) { + case V2: + return new SpongeSchematicReader(new NBTInputStream(is)).read(); + case MCEDIT: + return new MCEditSchematicReader(new NBTInputStream(is)).read(); + default: + throw new IOException("This schematic format is currently not supported"); } } catch (NullPointerException e) { throw new NoClipboardException(); @@ -455,6 +453,11 @@ public class WorldEditWrapper14 implements WorldEditWrapper { // Check Map schematic = schematicTag.getValue(); + if (schematic.size() == 1) { + schematicTag = requireTag(schematic, "Schematic", CompoundTag.class); + schematic = schematicTag.getValue(); + } + schematicVersion = requireTag(schematic, "Version", IntTag.class).getValue(); return schematicTag; } @@ -499,12 +502,16 @@ public class WorldEditWrapper14 implements WorldEditWrapper { region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE)); } - IntTag paletteMaxTag = getTag(schematic, "PaletteMax", IntTag.class); - Map paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue(); - if (paletteMaxTag != null && paletteObject.size() != paletteMaxTag.getValue()) { - throw new IOException("Block palette size does not match expected size."); + Map blockContainer = null; + boolean v3Mode = false; + + if (schematicVersion == 3) { + blockContainer = requireTag(schematic, "Blocks", CompoundTag.class).getValue(); + v3Mode = true; } + Map paletteObject = requireTag(v3Mode ? blockContainer: schematic, "Palette", CompoundTag.class).getValue(); + Map palette = new HashMap<>(); ParserContext parserContext = new ParserContext(); @@ -526,12 +533,12 @@ public class WorldEditWrapper14 implements WorldEditWrapper { palette.put(id, state); } - byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue(); + byte[] blocks = requireTag(v3Mode ? blockContainer: schematic, v3Mode ? "Data" : "BlockData", ByteArrayTag.class).getValue(); Map> tileEntitiesMap = new HashMap<>(); - ListTag tileEntities = getTag(schematic, "BlockEntities", ListTag.class); + ListTag tileEntities = getTag(v3Mode ? blockContainer: schematic, "BlockEntities", ListTag.class); if (tileEntities == null) { - tileEntities = getTag(schematic, "TileEntities", ListTag.class); + tileEntities = getTag(v3Mode ? blockContainer: schematic, "TileEntities", ListTag.class); } if (tileEntities != null) { List> tileEntityTags = tileEntities.getValue().stream() diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java index 903113c4..23590848 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java @@ -19,10 +19,12 @@ package de.steamwar.core; +import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReader; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.*; import de.steamwar.sql.NoClipboardException; +import de.steamwar.sql.NodeData; import java.io.IOException; import java.io.InputStream; @@ -31,11 +33,18 @@ public class WorldEditWrapper18 extends WorldEditWrapper14 { @Override @SuppressWarnings("removal") - public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { + public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { NBTInputStream nbtStream = new NBTInputStream(is); //Use FAWE reader due to FAWE capability of reading corrupt FAWE schems try { - return (schemFormat ? new SpongeSchematicReader(nbtStream) : new MCEditSchematicReader(nbtStream)).read(); + switch (schemFormat) { + case MCEDIT: + return new MCEditSchematicReader(nbtStream).read(); + case V2: + return new SpongeSchematicReader(nbtStream).read(); + default: + throw new IllegalArgumentException("Unsupported schematic format"); + } } catch (NullPointerException e) { throw new NoClipboardException(); } diff --git a/SpigotCore/SpigotCore_21/build.gradle.kts b/SpigotCore/SpigotCore_21/build.gradle.kts index b9a7805e..8f2acba4 100644 --- a/SpigotCore/SpigotCore_21/build.gradle.kts +++ b/SpigotCore/SpigotCore_21/build.gradle.kts @@ -21,7 +21,13 @@ plugins { steamwar.java } +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} + dependencies { + compileOnly(project(":CommonCore", "default")) compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) compileOnly(project(":SpigotCore:SpigotCore_18", "default")) compileOnly(project(":SpigotCore:SpigotCore_14", "default")) @@ -29,16 +35,6 @@ dependencies { compileOnly(libs.fawe21) - compileOnly(libs.paperapi21) { - attributes { - // Very Hacky, but it works - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) - } - } - compileOnly(libs.nms21) { - attributes { - // Very Hacky, but it works - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) - } - } + compileOnly(libs.paperapi21) + compileOnly(libs.nms21) } diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/FaWeSchematicReaderV3.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/FaWeSchematicReaderV3.java new file mode 100644 index 00000000..9a11dd2e --- /dev/null +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/FaWeSchematicReaderV3.java @@ -0,0 +1,857 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.core; + +import com.fastasyncworldedit.core.extent.clipboard.LinearClipboard; +import com.fastasyncworldedit.core.extent.clipboard.SimpleClipboard; +import com.fastasyncworldedit.core.internal.io.ResettableFileInputStream; +import com.fastasyncworldedit.core.internal.io.VarIntStreamIterator; +import com.fastasyncworldedit.core.math.MutableBlockVector3; +import com.fastasyncworldedit.core.nbt.FaweCompoundTag; +import com.fastasyncworldedit.core.util.IOUtil; +import com.fastasyncworldedit.core.util.MathMan; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.NBTConstants; +import com.sk89q.jnbt.NBTInputStream; +import com.sk89q.jnbt.NBTOutputStream; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.extension.platform.Capability; +import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; +import com.sk89q.worldedit.extent.clipboard.io.sponge.ReaderUtil; +import com.sk89q.worldedit.extent.clipboard.io.sponge.VersionedDataFixer; +import com.sk89q.worldedit.internal.util.LogManagerCompat; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.concurrency.LazyReference; +import com.sk89q.worldedit.world.DataFixer; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockTypes; +import com.sk89q.worldedit.world.block.BlockTypesCache; +import com.sk89q.worldedit.world.entity.EntityType; +import it.unimi.dsi.fastutil.io.FastBufferedInputStream; +import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; +import net.jpountz.lz4.LZ4BlockInputStream; +import net.jpountz.lz4.LZ4BlockOutputStream; +import org.apache.logging.log4j.Logger; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.enginehub.linbus.tree.LinCompoundTag; +import org.enginehub.linbus.tree.LinIntArrayTag; +import org.enginehub.linbus.tree.LinTagType; +import org.jetbrains.annotations.ApiStatus; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.OptionalInt; +import java.util.Set; +import java.util.UUID; +import java.util.function.BooleanSupplier; +import java.util.function.Function; +import java.util.zip.GZIPInputStream; + +/** + * ClipboardReader for the Sponge Schematic Format v3. + * Not necessarily much faster than {@link com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV3Reader}, but uses a + * stream based approach to keep the memory overhead minimal (especially in larger schematics) + * + * @since 2.11.1 + */ +@SuppressWarnings("removal") // JNBT +public class FaWeSchematicReaderV3 implements ClipboardReader { + + private static final Logger LOGGER = LogManagerCompat.getLogger(); + private static final byte CACHE_IDENTIFIER_END = 0x00; + private static final byte CACHE_IDENTIFIER_BLOCK = 0x01; + private static final byte CACHE_IDENTIFIER_BIOMES = 0x02; + private static final byte CACHE_IDENTIFIER_ENTITIES = 0x03; + private static final byte CACHE_IDENTIFIER_BLOCK_TILE_ENTITIES = 0x04; + + private final InputStream parentStream; + private final MutableBlockVector3 dimensions = MutableBlockVector3.at(0, 0, 0); + private final Set remainingTags; + + private DataInputStream dataInputStream; + private NBTInputStream nbtInputStream; + + private VersionedDataFixer dataFixer; + private BlockVector3 offset; + private BlockVector3 origin = BlockVector3.ZERO; + private BlockState[] blockPalette; + private BiomeType[] biomePalette; + private int dataVersion = -1; + + // Only used if the InputStream is not file based (and therefor does not support resets based on FileChannels) + // and the file is unordered + // Data and Palette cache is separated, as the data requires a fully populated palette - and the order is not guaranteed + private byte[] dataCache; + private byte[] paletteCache; + private OutputStream dataCacheWriter; + private OutputStream paletteCacheWriter; + + + public FaWeSchematicReaderV3(@NonNull InputStream stream) { + Objects.requireNonNull(stream, "stream"); + if (stream instanceof ResettableFileInputStream) { + stream.mark(Integer.MAX_VALUE); + this.remainingTags = new HashSet<>(); + } else if (stream instanceof FileInputStream fileInputStream) { + stream = new ResettableFileInputStream(fileInputStream); + stream.mark(Integer.MAX_VALUE); + this.remainingTags = new HashSet<>(); + } else if (stream instanceof FastBufferedInputStream || stream instanceof BufferedInputStream) { + this.remainingTags = null; + } else { + stream = new FastBufferedInputStream(stream); + this.remainingTags = null; + } + this.parentStream = stream; + } + + @Override + public Clipboard read(final UUID uuid, final Function createOutput) throws IOException { + Clipboard clipboard = null; + + this.setSubStreams(); + skipHeader(this.dataInputStream); + + byte type; + String tag; + while ((type = dataInputStream.readByte()) != NBTConstants.TYPE_END) { + tag = this.dataInputStream.readUTF(); + switch (tag) { + case "DataVersion" -> { + final Platform platform = + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING); + this.dataVersion = this.dataInputStream.readInt(); + this.dataFixer = ReaderUtil.getVersionedDataFixer(this.dataVersion, platform, platform.getDataVersion()); + } + case "Metadata" -> { + LinCompoundTag metadataCompoundTag = + (LinCompoundTag) this.nbtInputStream.readTagPayload(NBTConstants.TYPE_COMPOUND, 0).toLinTag(); + + LinCompoundTag worldEditTag = metadataCompoundTag.findTag("WorldEdit", LinTagType.compoundTag()); + if (worldEditTag != null) { // allowed to be optional + LinIntArrayTag originTag = worldEditTag.findTag("Origin", LinTagType.intArrayTag()); + if (originTag != null) { // allowed to be optional + int[] parts = originTag.value(); + + if (parts.length != 3) { + throw new IOException("`Metadata > WorldEdit > Origin` int array length is invalid."); + } + + this.origin = BlockVector3.at(parts[0], parts[1], parts[2]); + } + } + } + case "Offset" -> { + this.dataInputStream.skipNBytes(4); // Array Length field (4 byte int) + this.offset = BlockVector3.at( + this.dataInputStream.readInt(), + this.dataInputStream.readInt(), + this.dataInputStream.readInt() + ); + } + case "Width" -> this.dimensions.mutX(this.dataInputStream.readShort() & 0xFFFF); + case "Height" -> this.dimensions.mutY(this.dataInputStream.readShort() & 0xFFFF); + case "Length" -> this.dimensions.mutZ(this.dataInputStream.readShort() & 0xFFFF); + case "Blocks" -> readBlocks(clipboard); + case "Biomes" -> readBiomes(clipboard); + case "Entities" -> readEntities(clipboard); + default -> this.nbtInputStream.readTagPayloadLazy(type, 0); + } + if (clipboard == null && this.areDimensionsAvailable()) { + clipboard = createOutput.apply(this.dimensions); + } + } + + if (clipboard == null) { + throw new IOException("Invalid schematic - missing dimensions"); + } + if (dataFixer == null) { + throw new IOException("Invalid schematic - missing DataVersion"); + } + + if (this.supportsReset() && !remainingTags.isEmpty()) { + readRemainingDataReset(clipboard); + } else if (this.dataCacheWriter != null || this.paletteCacheWriter != null) { + readRemainingDataCache(clipboard); + } + + clipboard.setOrigin(this.offset.multiply(-1)); + if (clipboard instanceof SimpleClipboard simpleClipboard && !this.offset.equals(BlockVector3.ZERO)) { + clipboard = new BlockArrayClipboard(simpleClipboard, this.offset.add(this.origin)); + } + return clipboard; + } + + + /** + * Reads all locally cached data (due to reset not being available) and applies them to the clipboard. + *

+ * Firstly, closes all cache writers (which adds the END identifier to each and fills the cache byte arrays on this instance) + * If required, creates all missing palettes first (as needed by all remaining data). + * At last writes all missing data (block states, tile entities, biomes, entities). + * + * @param clipboard The clipboard to write into. + * @throws IOException on I/O error. + */ + private void readRemainingDataCache(Clipboard clipboard) throws IOException { + byte identifier; + if (this.paletteCacheWriter != null) { + this.paletteCacheWriter.close(); + } + if (this.dataCacheWriter != null) { + this.dataCacheWriter.close(); + } + if (this.paletteCache != null) { + try (final DataInputStream cacheStream = new DataInputStream(new FastBufferedInputStream( + new LZ4BlockInputStream(new FastBufferedInputStream(new ByteArrayInputStream(this.paletteCache)))))) { + while ((identifier = cacheStream.readByte()) != CACHE_IDENTIFIER_END) { + if (identifier == CACHE_IDENTIFIER_BLOCK) { + this.readPaletteMap(cacheStream, this.provideBlockPaletteInitializer()); + continue; + } + if (identifier == CACHE_IDENTIFIER_BIOMES) { + this.readPaletteMap(cacheStream, this.provideBiomePaletteInitializer()); + continue; + } + throw new IOException("invalid cache state - got identifier: 0x" + identifier); + } + } + } + try (final DataInputStream cacheStream = new DataInputStream(new FastBufferedInputStream( + new LZ4BlockInputStream(new FastBufferedInputStream(new ByteArrayInputStream(this.dataCache))))); + final NBTInputStream cacheNbtIn = new NBTInputStream(cacheStream)) { + while ((identifier = cacheStream.readByte()) != CACHE_IDENTIFIER_END) { + switch (identifier) { + case CACHE_IDENTIFIER_BLOCK -> this.readPaletteData(cacheStream, this.getBlockWriter(clipboard)); + case CACHE_IDENTIFIER_BIOMES -> this.readPaletteData(cacheStream, this.getBiomeWriter(clipboard)); + case CACHE_IDENTIFIER_ENTITIES -> { + cacheStream.skipNBytes(1); // list child type (TAG_Compound) + this.readEntityContainers( + cacheStream, + cacheNbtIn, + DataFixer.FixTypes.ENTITY, + this.provideEntityTransformer(clipboard) + ); + } + case CACHE_IDENTIFIER_BLOCK_TILE_ENTITIES -> { + cacheStream.skipNBytes(1); // list child type (TAG_Compound) + this.readEntityContainers( + cacheStream, + cacheNbtIn, + DataFixer.FixTypes.BLOCK_ENTITY, + this.provideTileEntityTransformer(clipboard) + ); + } + default -> throw new IOException("invalid cache state - got identifier: 0x" + identifier); + } + } + } + } + + /** + * Reset the main stream of this clipboard and reads all remaining data that could not be read or fixed yet. + * Might need two iterations if the DataVersion tag is after the Blocks tag while the Palette inside the Blocks tag is not + * at the first position. + * + * @param clipboard The clipboard to write into. + * @throws IOException on I/O error. + */ + private void readRemainingDataReset(Clipboard clipboard) throws IOException { + byte type; + String tag; + outer: + while (!this.remainingTags.isEmpty()) { + this.reset(); + skipHeader(this.dataInputStream); + while ((type = dataInputStream.readByte()) != NBTConstants.TYPE_END) { + tag = dataInputStream.readUTF(); + byte b = tag.equals("Blocks") ? CACHE_IDENTIFIER_BLOCK : + tag.equals("Biomes") ? CACHE_IDENTIFIER_BIOMES : + tag.equals("Entities") ? CACHE_IDENTIFIER_ENTITIES : + CACHE_IDENTIFIER_END; + if (!this.remainingTags.remove(b)) { + this.nbtInputStream.readTagPayloadLazy(type, 0); + continue; + } + switch (tag) { + case "Blocks" -> readBlocks(clipboard); + case "Biomes" -> readBiomes(clipboard); + case "Entities" -> readEntities(clipboard); + default -> this.nbtInputStream.readTagPayloadLazy(type, 0); // Should never happen, but just in case + } + if (this.remainingTags.isEmpty()) { + break outer; + } + } + } + } + + /** + * {@inheritDoc} + *

+ * Requires {@link #read()}, {@link #read(UUID)} or {@link #read(UUID, Function)} to be called before. + */ + @Override + public OptionalInt getDataVersion() { + return this.dataVersion > -1 ? OptionalInt.of(this.dataVersion) : OptionalInt.empty(); + } + + private void readBlocks(Clipboard target) throws IOException { + this.blockPalette = new BlockState[BlockTypesCache.states.length]; + readPalette( + target != null, + CACHE_IDENTIFIER_BLOCK, + () -> this.blockPalette[0] != null, + this.provideBlockPaletteInitializer(), + this.getBlockWriter(target), + (type, tag) -> { + if (!tag.equals("BlockEntities")) { + try { + this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_LIST, 0); + } catch (IOException e) { + LOGGER.error("Failed to skip additional tag", e); + } + return; + } + try { + this.readTileEntities(target); + } catch (IOException e) { + LOGGER.warn("Failed to read tile entities", e); + } + } + ); + } + + private void readBiomes(Clipboard target) throws IOException { + this.biomePalette = new BiomeType[BiomeType.REGISTRY.size()]; + readPalette( + target != null, + CACHE_IDENTIFIER_BIOMES, + () -> this.biomePalette[0] != null, + this.provideBiomePaletteInitializer(), + this.getBiomeWriter(target), + (type, tag) -> { + try { + this.nbtInputStream.readTagPayloadLazy(type, 0); + } catch (IOException e) { + LOGGER.error("Failed to skip additional tag in biome container: {}", tag, e); + } + } + ); + } + + private void readEntities(@Nullable Clipboard target) throws IOException { + if (target == null || this.dataFixer == null) { + if (supportsReset()) { + this.remainingTags.add(CACHE_IDENTIFIER_ENTITIES); + this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_LIST, 0); + return; + } + // Easier than streaming for now + final NBTOutputStream cacheStream = new NBTOutputStream(this.getDataCacheWriter()); + cacheStream.writeByte(CACHE_IDENTIFIER_ENTITIES); + cacheStream.writeTagPayload(this.nbtInputStream.readTagPayload(NBTConstants.TYPE_LIST, 0)); + return; + } + if (this.dataInputStream.read() != NBTConstants.TYPE_COMPOUND) { + throw new IOException("Expected a compound block for entity"); + } + this.readEntityContainers( + this.dataInputStream, this.nbtInputStream, DataFixer.FixTypes.ENTITY, this.provideEntityTransformer(target) + ); + } + + private void readTileEntities(Clipboard target) throws IOException { + if (target == null || this.dataFixer == null) { + if (supportsReset()) { + this.remainingTags.add(CACHE_IDENTIFIER_BLOCK); // use block identifier, as this method will be called by + // readBlocks again + this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_LIST, 0); + return; + } + // Easier than streaming for now + final NBTOutputStream cacheStream = new NBTOutputStream(this.getDataCacheWriter()); + cacheStream.writeByte(CACHE_IDENTIFIER_BLOCK_TILE_ENTITIES); + cacheStream.writeTagPayload(this.nbtInputStream.readTagPayload(NBTConstants.TYPE_LIST, 0)); + return; + } + if (this.dataInputStream.read() != NBTConstants.TYPE_COMPOUND) { + throw new IOException("Expected a compound block for tile entity"); + } + this.readEntityContainers( + this.dataInputStream, + this.nbtInputStream, + DataFixer.FixTypes.BLOCK_ENTITY, + this.provideTileEntityTransformer(target) + ); + } + + private void readEntityContainers( + DataInputStream stream, + NBTInputStream nbtStream, + DataFixer.FixType fixType, + EntityTransformer transformer + ) throws IOException { + double x, y, z; + LinCompoundTag tag; + String id; + byte type; + int count = stream.readInt(); + while (count-- > 0) { + x = -1; + y = -1; + z = -1; + tag = null; + id = null; + while ((type = stream.readByte()) != NBTConstants.TYPE_END) { + switch (type) { + // Depending on the type of entity container (tile vs "normal") the pos consists of either doubles or ints + case NBTConstants.TYPE_INT_ARRAY -> { + if (!stream.readUTF().equals("Pos")) { + throw new IOException("Expected INT_ARRAY tag to be Pos"); + } + stream.skipNBytes(4); // count of following ints - for pos = 3 + x = stream.readInt(); + y = stream.readInt(); + z = stream.readInt(); + } + case NBTConstants.TYPE_LIST -> { + if (!stream.readUTF().equals("Pos")) { + throw new IOException("Expected LIST tag to be Pos"); + } + if (stream.readByte() != NBTConstants.TYPE_DOUBLE) { + throw new IOException("Expected LIST Pos tag to contain DOUBLE"); + } + stream.skipNBytes(4); // count of following doubles - for pos = 3 + x = stream.readDouble(); + y = stream.readDouble(); + z = stream.readDouble(); + } + case NBTConstants.TYPE_STRING -> { + if (!stream.readUTF().equals("Id")) { + throw new IOException("Expected STRING tag to be Id"); + } + id = stream.readUTF(); + } + case NBTConstants.TYPE_COMPOUND -> { + if (!stream.readUTF().equals("Data")) { + throw new IOException("Expected COMPOUND tag to be Data"); + } + if (!(nbtStream.readTagPayload(NBTConstants.TYPE_COMPOUND, 0).toLinTag() instanceof LinCompoundTag lin)) { + throw new IOException("Data tag could not be read into LinCompoundTag"); + } + tag = lin; + } + default -> throw new IOException("Unexpected tag in compound: " + type); + } + } + if (id == null) { + throw new IOException("Missing Id tag in compound"); + } + if (x < 0 || y < 0 || z < 0) { + throw new IOException("Missing position for entity " + id); + } + if (tag == null) { + transformer.transform(x, y, z, id, LinCompoundTag.of(Map.of())); + continue; + } + tag = this.dataFixer.fixUp(fixType, tag); + if (tag == null) { + LOGGER.warn("Failed to fix-up entity for {} @ {},{},{} - skipping", id, x, y, z); + continue; + } + transformer.transform(x, y, z, id, tag); + } + } + + /** + * The `Palette` tag is required first, as that contains the information of the actual palette size. + * Keeping the whole Data block in memory - which *could* be compressed - is just not it + * + * @param paletteInitializer Invoked for each 'Palette' entry using the actual palette value (e.g. block state) + index + * @param paletteDataApplier Invoked for each 'Data' entry using the data index and the palette index at the data index + */ + private void readPalette( + boolean hasClipboard, + byte paletteType, + BooleanSupplier paletteAlreadyInitialized, + PaletteInitializer paletteInitializer, + PaletteDataApplier paletteDataApplier, + AdditionalTagConsumer additionalTag + ) throws IOException { + boolean hasPalette = paletteAlreadyInitialized.getAsBoolean(); + byte type; + String tag; + while ((type = this.dataInputStream.readByte()) != NBTConstants.TYPE_END) { + tag = this.dataInputStream.readUTF(); + if (tag.equals("Palette")) { + if (hasPalette) { + // Skip palette, as already exists + this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_COMPOUND, 0); + continue; + } + if (!this.readPaletteMap(this.dataInputStream, paletteInitializer)) { + if (this.supportsReset()) { + // Couldn't read - skip palette for now + this.remainingTags.add(paletteType); + this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_COMPOUND, 0); + continue; + } + // Reset not possible, write into cache + final NBTOutputStream cacheWriter = new NBTOutputStream(this.getPaletteCacheWriter()); + cacheWriter.write(paletteType); + cacheWriter.writeTagPayload(this.nbtInputStream.readTagPayload(NBTConstants.TYPE_COMPOUND, 0)); + continue; + } + hasPalette = true; + continue; + } + if (tag.equals("Data")) { + // No palette or dimensions are yet available + if (!hasPalette || this.dataFixer == null || !hasClipboard) { + if (this.supportsReset()) { + this.remainingTags.add(paletteType); + this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_BYTE_ARRAY, 0); + continue; + } + // Reset not possible, write into cache + int byteLen = this.dataInputStream.readInt(); + final DataOutputStream cacheWriter = new DataOutputStream(this.getDataCacheWriter()); + cacheWriter.write(paletteType); + cacheWriter.writeInt(byteLen); + IOUtil.copy(this.dataInputStream, cacheWriter, byteLen); + continue; + } + this.readPaletteData(this.dataInputStream, paletteDataApplier); + continue; + } + additionalTag.accept(type, tag); + } + } + + private void readPaletteData(DataInputStream stream, PaletteDataApplier applier) throws IOException { + int length = stream.readInt(); + // Write data into clipboard + int i = 0; + if (needsVarIntReading(length)) { + for (var iter = new VarIntStreamIterator(stream, length); iter.hasNext(); i++) { + applier.apply(i, (char) iter.nextInt()); + } + return; + } + while (i < length) { + applier.apply(i++, (char) stream.readUnsignedByte()); + } + } + + /** + * Reads the CompoundTag containing the palette mapping ({@code index: value}) and passes each entry to the + * {@link PaletteInitializer}. + *

+ * This method expects that the identifier ({@link NBTConstants#TYPE_COMPOUND}) is already consumed from the stream. + * + * @param stream The stream to read the data from. + * @param initializer The initializer called for each entry with its index and backed value. + * @return {@code true} if the mapping could be read, {@code false} otherwise (e.g. DataFixer is not yet available). + * @throws IOException on I/O error. + */ + private boolean readPaletteMap(DataInputStream stream, PaletteInitializer initializer) throws IOException { + if (this.dataFixer == null) { + return false; + } + while (stream.readByte() != NBTConstants.TYPE_END) { + String value = stream.readUTF(); + char index = (char) stream.readInt(); + initializer.initialize(index, value); + } + return true; + } + + private void indexToPosition(int index, PositionConsumer supplier) { + int y = index / (dimensions.x() * dimensions.z()); + int remainder = index - (y * dimensions.x() * dimensions.z()); + int z = remainder / dimensions.x(); + int x = remainder - z * dimensions.x(); + supplier.accept(x, y, z); + } + + private PaletteDataApplier getBlockWriter(Clipboard target) { + if (target instanceof LinearClipboard linearClipboard) { + return (index, ordinal) -> linearClipboard.setBlock(index, this.blockPalette[ordinal]); + } + return (index, ordinal) -> indexToPosition(index, (x, y, z) -> target.setBlock(x, y, z, this.blockPalette[ordinal])); + } + + private PaletteDataApplier getBiomeWriter(Clipboard target) { + return (index, ordinal) -> indexToPosition(index, (x, y, z) -> target.setBiome(x, y, z, this.biomePalette[ordinal])); + } + + private PaletteInitializer provideBlockPaletteInitializer() { + return (index, value) -> { + if (this.dataFixer == null) { + throw new IllegalStateException("Can't read block palette map if DataFixer is not yet available"); + } + value = dataFixer.fixUp(DataFixer.FixTypes.BLOCK_STATE, value); + try { + this.blockPalette[index] = BlockState.get(value); + } catch (InputParseException e) { + LOGGER.warn("Invalid BlockState in palette: {}. Block will be replaced with air.", value); + this.blockPalette[index] = BlockTypes.AIR.getDefaultState(); + } + }; + } + + private PaletteInitializer provideBiomePaletteInitializer() { + return (index, value) -> { + if (this.dataFixer == null) { + throw new IllegalStateException("Can't read biome palette map if DataFixer is not yet available"); + } + value = dataFixer.fixUp(DataFixer.FixTypes.BIOME, value); + BiomeType biomeType = BiomeTypes.get(value); + if (biomeType == null) { + biomeType = BiomeTypes.PLAINS; + LOGGER.warn("Invalid biome type in palette: {}. Biome will be replaced with plains.", value); + } + this.biomePalette[index] = biomeType; + }; + } + + private EntityTransformer provideEntityTransformer(Clipboard clipboard) { + return (x, y, z, id, tag) -> { + EntityType type = EntityType.REGISTRY.get(id); + if (type == null) { + LOGGER.warn("Invalid entity id: {} - skipping", id); + return; + } + clipboard.createEntity( + new Location(clipboard, Location.at(x, y, z).add(clipboard.getMinimumPoint().toVector3())), + new BaseEntity(type, LazyReference.computed(tag)) + ); + }; + } + + private EntityTransformer provideTileEntityTransformer(Clipboard clipboard) { + return (x, y, z, id, tag) -> clipboard.tile( + MathMan.roundInt(x + clipboard.getMinimumPoint().x()), + MathMan.roundInt(y + clipboard.getMinimumPoint().y()), + MathMan.roundInt(z + clipboard.getMinimumPoint().z()), + FaweCompoundTag.of(tag) + ); + } + + /** + * @return {@code true} if {@code Width}, {@code Length} and {@code Height} are already read from the stream + */ + private boolean areDimensionsAvailable() { + return this.dimensions.x() != 0 && this.dimensions.y() != 0 && this.dimensions.z() != 0; + } + + /** + * Closes this reader instance and all underlying resources. + * + * @throws IOException on I/O error. + */ + @Override + public void close() throws IOException { + parentStream.close(); // closes all underlying resources implicitly + } + + /** + * Resets the main stream to the previously marked position ({@code 0}), if supported (see {@link #supportsReset()}). + * If the stream is reset, the sub streams (for DataInput and NBT) are re-created to respect the new position. + * + * @throws IOException on I/O error. + */ + private void reset() throws IOException { + if (this.supportsReset()) { + this.parentStream.reset(); + this.parentStream.mark(Integer.MAX_VALUE); + this.setSubStreams(); + } + } + + /** + * @return {@code true} if the stream used while instantiating the reader supports resets (without memory overhead). + */ + private boolean supportsReset() { + return this.remainingTags != null; + } + + /** + * Overwrites the DataInput- and NBT-InputStreams (e.g. when the marker of the backed stream updated). + * + * @throws IOException on I/O error. + */ + private void setSubStreams() throws IOException { + this.dataInputStream = new DataInputStream(this.parentStream); + this.nbtInputStream = new NBTInputStream(this.parentStream); + } + + /** + * Creates a new cache writer for non-palette data, if none exists yet. + * Returns either the already created or new one. + * + * @return the output stream for non-palette cache data. + */ + private OutputStream getDataCacheWriter() { + if (this.dataCacheWriter == null) { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(512); + this.dataCacheWriter = new FastBufferedOutputStream(new LZ4BlockOutputStream(byteArrayOutputStream)) { + @Override + public void close() throws IOException { + this.write(CACHE_IDENTIFIER_END); + super.close(); + FaWeSchematicReaderV3.this.dataCache = byteArrayOutputStream.toByteArray(); + } + }; + } + return this.dataCacheWriter; + } + + /** + * Creates a new cache writer for palette data, if none exists yet. + * Returns either the already created or new one. + * + * @return the output stream for palette cache data. + */ + private OutputStream getPaletteCacheWriter() { + if (this.paletteCacheWriter == null) { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(256); + this.paletteCacheWriter = new FastBufferedOutputStream(new LZ4BlockOutputStream(byteArrayOutputStream)) { + @Override + public void close() throws IOException { + this.write(CACHE_IDENTIFIER_END); + super.close(); + FaWeSchematicReaderV3.this.paletteCache = byteArrayOutputStream.toByteArray(); + } + }; + } + return this.paletteCacheWriter; + } + + private boolean needsVarIntReading(int byteArrayLength) { + return byteArrayLength > this.dimensions.x() * this.dimensions.y() * this.dimensions.z(); + } + + /** + * Skips the schematic header including the root compound (empty name) and the root's child compound ("Schematic") + * + * @param dataInputStream The stream containing the schematic data to skip + * @throws IOException on I/O error + */ + private static void skipHeader(DataInputStream dataInputStream) throws IOException { + dataInputStream.skipNBytes(1 + 2); // 1 Byte = TAG_Compound, 2 Bytes = Short (Length of tag name = "") + dataInputStream.skipNBytes(1 + 2 + 9); // as above + 9 bytes = "Schematic" + } + + @ApiStatus.Internal + @FunctionalInterface + private interface PositionConsumer { + + /** + * Called with block location coordinates. + * + * @param x the x coordinate. + * @param y the y coordinate. + * @param z the z coordinate. + */ + void accept(int x, int y, int z); + + } + + @ApiStatus.Internal + @FunctionalInterface + private interface EntityTransformer { + + /** + * Called for each entity from the Schematics {@code Entities} compound list. + * + * @param x the relative x coordinate of the entity. + * @param y the relative y coordinate of the entity. + * @param z the relative z coordinate of the entity. + * @param id the entity id as a resource location (e.g. {@code minecraft:sheep}). + * @param tag the - already fixed, if required - nbt data of the entity. + */ + void transform(double x, double y, double z, String id, LinCompoundTag tag); + + } + + @ApiStatus.Internal + @FunctionalInterface + private interface PaletteInitializer { + + /** + * Called for each palette entry (the mapping part, not data). + * + * @param index the index of the entry, as used in the Data byte array. + * @param value the value for this entry (either biome type as resource location or the block state as a string). + */ + void initialize(char index, String value); + + } + + @ApiStatus.Internal + @FunctionalInterface + private interface PaletteDataApplier { + + /** + * Called for each palette data entry (not the mapping part, but the var-int byte array). + * + * @param index The index of this data entry (due to var-int behaviour not necessarily the index in the data byte array). + * @param ordinal The ordinal of this entry as defined in the palette mapping. + */ + void apply(int index, char ordinal); + + } + + @ApiStatus.Internal + @FunctionalInterface + private interface AdditionalTagConsumer { + + /** + * Called for each unknown nbt tag. + * + * @param type The type of the tag (as defined by the constants in {@link NBTConstants}). + * @param name The name of the tag. + */ + void accept(byte type, String name); + + } + +} diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java index 4ae22cac..60dcce9e 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java @@ -20,33 +20,27 @@ package de.steamwar.core; import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV2; -import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV3; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader; -import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV1Reader; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; +import de.steamwar.sql.NodeData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import org.enginehub.linbus.stream.LinBinaryIO; -import org.enginehub.linbus.stream.LinStream; -import org.enginehub.linbus.tree.LinCompoundTag; -import org.enginehub.linbus.tree.LinRootEntry; -import org.enginehub.linbus.tree.LinTagType; import java.io.*; public class WorldEditWrapper21 implements WorldEditWrapper { @Override - public InputStream getPlayerClipboard(Player player, boolean schemFormat) { - return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) -> { + public InputStream getPlayerClipboard(Player player) { + return WorldEditWrapper.getPlayerClipboard(player, (outputStream, clipboard, clipboardHolder) -> { ClipboardWriter writer = BuiltInClipboardFormat.FAST_V3.getWriter(outputStream); writer.write(clipboard); writer.close(); @@ -54,7 +48,7 @@ public class WorldEditWrapper21 implements WorldEditWrapper { } @Override - public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) { + public void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat) { Clipboard clipboard = null; try { clipboard = getClipboard(is, schemFormat); @@ -70,35 +64,12 @@ public class WorldEditWrapper21 implements WorldEditWrapper { } @Override - public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { - if (!schemFormat) { - return new MCEditSchematicReader(new NBTInputStream(is)).read(); - } else { - BufferedInputStream bis = new BufferedInputStream(is); - - bis.mark(Integer.MAX_VALUE); - - LinStream linStream = LinBinaryIO.read(new DataInputStream(bis)); - - LinCompoundTag entry = LinRootEntry.readFrom(linStream).value(); - - if (entry.value().size() == 1) { - entry = entry.getTag("Schematic", LinTagType.compoundTag()); - } - - bis.reset(); - - switch (entry.getTag("Version", LinTagType.intTag()).valueAsInt()) { - case 1: - return new SpongeSchematicV1Reader(entry.linStream()).read(); - case 2: - return new FastSchematicReaderV2(new NBTInputStream(bis)).read(); - case 3: - return new FastSchematicReaderV3(bis).read(); - default: - throw new IOException("Unknown schematic version"); - } - } + public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { + return switch (schemFormat) { + case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(is)).read(); + case V2 -> new FastSchematicReaderV2(new NBTInputStream(is)).read(); + case V3 -> new FaWeSchematicReaderV3(is).read(); + }; } @Override diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java index f3fc2800..b077a107 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java @@ -37,6 +37,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.registry.WorldData; +import de.steamwar.sql.NodeData; import org.bukkit.entity.Player; import java.io.IOException; @@ -50,13 +51,13 @@ import java.util.stream.Collectors; public class WorldEditWrapper8 implements WorldEditWrapper { @Override - public InputStream getPlayerClipboard(Player player, boolean schemFormat) { - return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) -> + public InputStream getPlayerClipboard(Player player) { + return WorldEditWrapper.getPlayerClipboard(player, (outputStream, clipboard, clipboardHolder) -> ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData())); } @Override - public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) { + public void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat) { WorldData world = new BukkitWorld(player.getWorld()).getWorldData(); Clipboard clipboard; try { @@ -70,11 +71,16 @@ public class WorldEditWrapper8 implements WorldEditWrapper { } @Override - public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { - if(schemFormat) - return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); - else - return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { + switch (schemFormat) { + case MCEDIT: + return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + case V2: + case V3: + return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + default: + throw new IllegalArgumentException("Unsupported schematic format"); + } } @Override @@ -137,6 +143,13 @@ public class WorldEditWrapper8 implements WorldEditWrapper { IDConverter8 ids = new IDConverter8(); Map schematic = schematicTag.getValue(); + boolean v3Mode = false; + + if (schematic.size() == 1) { + schematic = (requireTag(schematic, "Schematic", CompoundTag.class)).getValue(); + v3Mode = true; + } + int width = (requireTag(schematic, "Width", ShortTag.class)).getValue(); int height = (requireTag(schematic, "Height", ShortTag.class)).getValue(); int length = (requireTag(schematic, "Length", ShortTag.class)).getValue(); @@ -167,10 +180,13 @@ public class WorldEditWrapper8 implements WorldEditWrapper { region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector.ONE)); } - IntTag paletteMaxTag = getTag(schematic, "PaletteMax", IntTag.class); - Map paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue(); - if (paletteMaxTag != null && paletteObject.size() != paletteMaxTag.getValue()) - throw new IOException("Block palette size does not match expected size."); + Map blockContainer = null; + + if (v3Mode) { + blockContainer = getTag(schematic, "Blocks", CompoundTag.class).getValue(); + } + + Map paletteObject = requireTag(v3Mode ? blockContainer : schematic, "Palette", CompoundTag.class).getValue(); Map palette = new HashMap<>(); ParserContext parserContext = new ParserContext(); @@ -182,11 +198,11 @@ public class WorldEditWrapper8 implements WorldEditWrapper { palette.put(requireTag(paletteObject, palettePart, IntTag.class).getValue(), new BaseBlock(blockID.getBlockId(), blockID.getDataId())); } - byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue(); + byte[] blocks = requireTag(v3Mode ? blockContainer : schematic, v3Mode ? "Data" : "BlockData", ByteArrayTag.class).getValue(); Map> tileEntitiesMap = new HashMap<>(); - ListTag tileEntities = getTag(schematic, "BlockEntities", ListTag.class); + ListTag tileEntities = getTag(v3Mode ? blockContainer : schematic, "BlockEntities", ListTag.class); if (tileEntities == null) { - tileEntities = getTag(schematic, "TileEntities", ListTag.class); + tileEntities = getTag(v3Mode ? blockContainer : schematic, "TileEntities", ListTag.class); } if (tileEntities != null) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java index c9585847..62a7f2b7 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java @@ -77,7 +77,7 @@ public class ErrorHandler extends Handler { return; try { - SWException.log(message, stacktrace); + //SWException.log(message, stacktrace); } catch (SecurityException e) { Core.getInstance().getLogger().log(Level.INFO, "Could not log error in database", e); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java index 87906944..703fa9e3 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java @@ -26,19 +26,23 @@ import com.sk89q.worldedit.session.ClipboardHolder; import de.steamwar.sql.NoClipboardException; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.Region; +import de.steamwar.sql.NodeData; +import lombok.AllArgsConstructor; +import lombok.Data; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.io.*; +import java.util.concurrent.CompletableFuture; import java.util.logging.Level; public interface WorldEditWrapper { WorldEditWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); - InputStream getPlayerClipboard(Player player, boolean schemFormat); - void setPlayerClipboard(Player player, InputStream is, boolean schemFormat); - Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException; + InputStream getPlayerClipboard(Player player); + void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat); + Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException; Vector getOrigin(Clipboard clipboard); Vector getMinimum(Region region); @@ -49,7 +53,7 @@ public interface WorldEditWrapper { return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); } - public static InputStream getPlayerClipboard(Player player, boolean schemFormat, SchematicWriter consumer) { + static InputStream getPlayerClipboard(Player player, SchematicWriter consumer) { ClipboardHolder clipboardHolder; try { clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard(); @@ -85,7 +89,17 @@ public interface WorldEditWrapper { return inputStream; } - public static interface SchematicWriter { + static NodeData.SchematicFormat getNativeFormat() { + if (Core.getVersion() <= 12) { + return NodeData.SchematicFormat.MCEDIT; + } else if (Core.getVersion() <= 20) { + return NodeData.SchematicFormat.V2; + } else { + return NodeData.SchematicFormat.V3; + } + } + + interface SchematicWriter { void write(OutputStream outputStream, Clipboard clipboard, ClipboardHolder holder) throws IOException; } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java index ecbf86aa..0957bae0 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java @@ -36,7 +36,7 @@ import java.util.zip.GZIPInputStream; public class SchematicData { - public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) { + public static Clipboard clipboardFromStream(InputStream is, NodeData.SchematicFormat schemFormat) { try { return WorldEditWrapper.impl.getClipboard(is, schemFormat); } catch (IOException e) { @@ -61,15 +61,11 @@ public class SchematicData { } public void saveFromPlayer(Player player) throws IOException, NoClipboardException { - saveFromPlayer(player, Core.getVersion() > 12); - } - - public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException { - data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat); + data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player), WorldEditWrapper.getNativeFormat()); } @Deprecated - public void saveFromBytes(byte[] bytes, boolean newFormat) { + public void saveFromBytes(byte[] bytes, NodeData.SchematicFormat newFormat) { data.saveFromStream(new ByteArrayInputStream(bytes), newFormat); } } diff --git a/SpigotCore/build.gradle.kts b/SpigotCore/build.gradle.kts index b7ff647e..d615cfc7 100644 --- a/SpigotCore/build.gradle.kts +++ b/SpigotCore/build.gradle.kts @@ -40,5 +40,10 @@ dependencies { implementation(project(":SpigotCore:SpigotCore_18")) implementation(project(":SpigotCore:SpigotCore_19")) implementation(project(":SpigotCore:SpigotCore_20")) - implementation(project(":SpigotCore:SpigotCore_21")) + implementation(project(":SpigotCore:SpigotCore_21")) { + attributes { + // Very Hacky, but it works + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) + } + } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java index 037eadcd..75892359 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java @@ -79,7 +79,7 @@ public class DiscordSchemUpload extends ListenerAdapter { node = SchematicNode.createSchematic(user.getId(), name, null); try (InputStream in = attachment.getProxy().download().get()) { - NodeData.get(node).saveFromStream(in, fileName.substring(dot).equalsIgnoreCase(".schem")); + NodeData.get(node).saveFromStream(in, fileName.substring(dot).equalsIgnoreCase(".schem") ? NodeData.SchematicFormat.V2 : NodeData.SchematicFormat.MCEDIT); sender.system("DC_SCHEMUPLOAD_SUCCESS", name); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index b873b97d..006b914e 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -88,7 +88,7 @@ fun Route.configureSchematic() { return@get } - call.response.header("Content-Disposition", "attachment; filename=\"${node.name}.${if (data.nodeFormat) "schem" else "schematic"}\"") + call.response.header("Content-Disposition", "attachment; filename=\"${node.name}${data.nodeFormat.fileEnding}\"") call.respondBytes(data.schemData().readAllBytes(), contentType = ContentType.Application.OctetStream, status = HttpStatusCode.OK) } get("/info") { @@ -118,8 +118,8 @@ fun Route.configureSchematic() { node = SchematicNode.createSchematic(user.id, schemName, 0) } - val data = NodeData(node.id, false) - data.saveFromStream(content.inputStream(), schemType == "schem") + val data = NodeData(node.id, NodeData.SchematicFormat.V2) + data.saveFromStream(content.inputStream(), NodeData.SchematicFormat.V2) call.respond(ResponseSchematic(node)) } From 06eec10660baa3b08b9b64d5eed169e0b12f96d0 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 8 Dec 2024 23:18:32 +0100 Subject: [PATCH 004/106] Fixes... --- CommonCore/SQL/src/de/steamwar/sql/NodeData.java | 8 ++------ .../de/steamwar/fightsystem/utils/WorldeditWrapper14.java | 2 +- .../src/de/steamwar/core/WorldEditWrapper14.java | 5 ++--- .../src/de/steamwar/core/WorldEditWrapper18.java | 3 +-- .../src/de/steamwar/core/WorldEditWrapper21.java | 4 ++-- .../src/de/steamwar/core/WorldEditWrapper8.java | 4 ++-- .../src/de/steamwar/core/WorldEditWrapper.java | 7 ++----- .../discord/listeners/DiscordSchemUpload.java | 2 +- 8 files changed, 13 insertions(+), 22 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java index c580dc3f..0de6c6c5 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java @@ -65,10 +65,6 @@ public class NodeData { private SchematicFormat nodeFormat; public InputStream schemData() throws IOException { - return new GZIPInputStream(schemDataRaw()); - } - - public InputStream schemDataRaw() throws IOException { try { return selSchemData.select(rs -> { rs.next(); @@ -96,8 +92,8 @@ public class NodeData { @Getter public enum SchematicFormat { MCEDIT(".schematic"), - V2(".schem"), - V3(".schem"); + SPONGE_V2(".schem"), + SPONGE_V3(".schem"); private final String fileEnding; } diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index df366205..9a0ae4b5 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -145,6 +145,6 @@ public class WorldeditWrapper14 implements WorldeditWrapper { throw new SecurityException(e); } - new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.V2); + new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.SPONGE_V2); } } diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java index cba992f5..ec072aa4 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java @@ -22,7 +22,6 @@ package de.steamwar.core; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.sk89q.jnbt.*; -import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extension.input.InputParseException; @@ -51,7 +50,6 @@ import org.bukkit.util.Vector; import java.io.*; import java.util.*; -import java.util.logging.Level; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; @@ -88,7 +86,8 @@ public class WorldEditWrapper14 implements WorldEditWrapper { try { switch (schemFormat) { - case V2: + case SPONGE_V2: + case SPONGE_V3: return new SpongeSchematicReader(new NBTInputStream(is)).read(); case MCEDIT: return new MCEditSchematicReader(new NBTInputStream(is)).read(); diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java index 23590848..b381ecf7 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java @@ -19,7 +19,6 @@ package de.steamwar.core; -import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReader; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.*; @@ -40,7 +39,7 @@ public class WorldEditWrapper18 extends WorldEditWrapper14 { switch (schemFormat) { case MCEDIT: return new MCEditSchematicReader(nbtStream).read(); - case V2: + case SPONGE_V2: return new SpongeSchematicReader(nbtStream).read(); default: throw new IllegalArgumentException("Unsupported schematic format"); diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java index 60dcce9e..52743f45 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java @@ -67,8 +67,8 @@ public class WorldEditWrapper21 implements WorldEditWrapper { public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { return switch (schemFormat) { case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(is)).read(); - case V2 -> new FastSchematicReaderV2(new NBTInputStream(is)).read(); - case V3 -> new FaWeSchematicReaderV3(is).read(); + case SPONGE_V2 -> new FastSchematicReaderV2(new NBTInputStream(is)).read(); + case SPONGE_V3 -> new FaWeSchematicReaderV3(is).read(); }; } diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java index b077a107..a6aad3b5 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java @@ -75,8 +75,8 @@ public class WorldEditWrapper8 implements WorldEditWrapper { switch (schemFormat) { case MCEDIT: return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); - case V2: - case V3: + case SPONGE_V2: + case SPONGE_V3: return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); default: throw new IllegalArgumentException("Unsupported schematic format"); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java index 703fa9e3..d07bd155 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java @@ -27,14 +27,11 @@ import de.steamwar.sql.NoClipboardException; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.Region; import de.steamwar.sql.NodeData; -import lombok.AllArgsConstructor; -import lombok.Data; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.io.*; -import java.util.concurrent.CompletableFuture; import java.util.logging.Level; public interface WorldEditWrapper { @@ -93,9 +90,9 @@ public interface WorldEditWrapper { if (Core.getVersion() <= 12) { return NodeData.SchematicFormat.MCEDIT; } else if (Core.getVersion() <= 20) { - return NodeData.SchematicFormat.V2; + return NodeData.SchematicFormat.SPONGE_V2; } else { - return NodeData.SchematicFormat.V3; + return NodeData.SchematicFormat.SPONGE_V3; } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java index 75892359..a39837f6 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java @@ -79,7 +79,7 @@ public class DiscordSchemUpload extends ListenerAdapter { node = SchematicNode.createSchematic(user.getId(), name, null); try (InputStream in = attachment.getProxy().download().get()) { - NodeData.get(node).saveFromStream(in, fileName.substring(dot).equalsIgnoreCase(".schem") ? NodeData.SchematicFormat.V2 : NodeData.SchematicFormat.MCEDIT); + NodeData.get(node).saveFromStream(in, fileName.substring(dot).equalsIgnoreCase(".schem") ? NodeData.SchematicFormat.SPONGE_V2 : NodeData.SchematicFormat.MCEDIT); sender.system("DC_SCHEMUPLOAD_SUCCESS", name); } catch (InterruptedException e) { Thread.currentThread().interrupt(); From 336915dd961169fbfd72e89497c1d1e7ebb1c6f5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 21 Dec 2024 12:03:43 +0100 Subject: [PATCH 005/106] Fix Schem Upload --- WebsiteBackend/build.gradle.kts | 1 + .../src/de/steamwar/routes/Schematic.kt | 29 +++++++++++++++++-- settings.gradle.kts | 1 + 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/WebsiteBackend/build.gradle.kts b/WebsiteBackend/build.gradle.kts index 2cf527a7..f93dacde 100644 --- a/WebsiteBackend/build.gradle.kts +++ b/WebsiteBackend/build.gradle.kts @@ -53,4 +53,5 @@ dependencies { implementation(libs.yamlconfig) implementation(libs.kotlinxSerializationCbor) implementation(libs.ktorRateLimit) + implementation(libs.knbt) } \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index 006b914e..0dea01f7 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -22,6 +22,7 @@ package de.steamwar.routes import de.steamwar.plugins.SWAuthPrincipal import de.steamwar.plugins.SWPermissionCheck import de.steamwar.sql.NodeData +import de.steamwar.sql.NodeData.SchematicFormat import de.steamwar.sql.NodeDownload import de.steamwar.sql.NodeMember import de.steamwar.sql.SWException @@ -32,7 +33,10 @@ import io.ktor.server.auth.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* +import kotlinx.coroutines.launch import kotlinx.serialization.Serializable +import kotlinx.serialization.decodeFromByteArray +import net.benwoodworth.knbt.* import java.security.MessageDigest import java.time.Duration import java.time.Instant @@ -71,6 +75,11 @@ data class SchematicCode(val id: Int, val code: String, val expires: Long) @Serializable data class UploadSchematic(val name: String, val content: String) +val nbt = Nbt { + variant = NbtVariant.Java + compression = NbtCompression.Gzip +} + fun Route.configureSchematic() { route("/download/{code}") { get { @@ -112,14 +121,28 @@ fun Route.configureSchematic() { val user = call.principal()!!.user - val content = Base64.getDecoder().decode(file.content) var node = SchematicNode.getSchematicNode(user.id, schemName, 0) if (node == null) { node = SchematicNode.createSchematic(user.id, schemName, 0) } - val data = NodeData(node.id, NodeData.SchematicFormat.V2) - data.saveFromStream(content.inputStream(), NodeData.SchematicFormat.V2) + val content = Base64.getDecoder().decode(file.content) + + var schem = nbt.decodeFromByteArray(content) + + if (schem.size == 1) schem = schem[schem.keys.first()] as NbtCompound + + val version = schem.let { + if (it.containsKey("Materials")) + return@let SchematicFormat.MCEDIT + else if (it.containsKey("Blocks")) + return@let SchematicFormat.SPONGE_V3 + else + return@let SchematicFormat.SPONGE_V2 + } + + val data = NodeData(node.id, version) + data.saveFromStream(content.inputStream(), version) call.respond(ResponseSchematic(node)) } diff --git a/settings.gradle.kts b/settings.gradle.kts index 69d5c67b..07242d37 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -165,6 +165,7 @@ dependencyResolutionManagement { library("yamlconfig", "org.bspfsystems:yamlconfiguration:1.3.0") library("kotlinxSerializationCbor", "org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.4.1") library("ktorRateLimit", "io.ktor:ktor-server-rate-limit:$ktorVersion") + library("knbt", "net.benwoodworth.knbt:knbt:0.11.7") } } } From d08ccc3a98a00bb9f278be435c78861b4fc13987 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 21 Dec 2024 12:30:39 +0100 Subject: [PATCH 006/106] Fix Everything --- .../fightsystem/record/PacketProcessor.java | 2 +- .../de/steamwar/core/WorldEditWrapper14.java | 5 + .../steamwar/core/FaWeSchematicReaderV3.java | 857 ------------------ .../de/steamwar/core/WorldEditWrapper21.java | 12 +- .../de/steamwar/core/WorldEditWrapper8.java | 5 + .../src/de/steamwar/core/ErrorHandler.java | 2 +- .../de/steamwar/core/WorldEditWrapper.java | 12 +- .../src/de/steamwar/sql/SchematicData.java | 2 +- VelocityCore/build.gradle.kts | 2 + .../discord/listeners/DiscordSchemUpload.java | 17 +- .../src/de/steamwar/routes/Schematic.kt | 34 +- settings.gradle.kts | 2 + 12 files changed, 64 insertions(+), 888 deletions(-) delete mode 100644 SpigotCore/SpigotCore_21/src/de/steamwar/core/FaWeSchematicReaderV3.java diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index e6ed1d3a..eafe4377 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -520,7 +520,7 @@ public class PacketProcessor implements Listener { public void close() { // FAWE 1.12 calls close... } - }, WorldEditWrapper.getNativeFormat()); + }, WorldEditWrapper.impl.getNativeFormat()); execSync(() -> team.pasteSchem(schemId, clipboard)); } diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java index ec072aa4..ca96d554 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java @@ -121,6 +121,11 @@ public class WorldEditWrapper14 implements WorldEditWrapper { return new org.bukkit.util.Vector(v.getX(), v.getY(), v.getZ()); } + @Override + public NodeData.SchematicFormat getNativeFormat() { + return NodeData.SchematicFormat.SPONGE_V2; + } + private static class MCEditSchematicReader extends NBTSchematicReader { private final NBTInputStream inputStream; diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/FaWeSchematicReaderV3.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/FaWeSchematicReaderV3.java deleted file mode 100644 index 9a11dd2e..00000000 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/FaWeSchematicReaderV3.java +++ /dev/null @@ -1,857 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.core; - -import com.fastasyncworldedit.core.extent.clipboard.LinearClipboard; -import com.fastasyncworldedit.core.extent.clipboard.SimpleClipboard; -import com.fastasyncworldedit.core.internal.io.ResettableFileInputStream; -import com.fastasyncworldedit.core.internal.io.VarIntStreamIterator; -import com.fastasyncworldedit.core.math.MutableBlockVector3; -import com.fastasyncworldedit.core.nbt.FaweCompoundTag; -import com.fastasyncworldedit.core.util.IOUtil; -import com.fastasyncworldedit.core.util.MathMan; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.jnbt.NBTConstants; -import com.sk89q.jnbt.NBTInputStream; -import com.sk89q.jnbt.NBTOutputStream; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.entity.BaseEntity; -import com.sk89q.worldedit.extension.input.InputParseException; -import com.sk89q.worldedit.extension.platform.Capability; -import com.sk89q.worldedit.extension.platform.Platform; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; -import com.sk89q.worldedit.extent.clipboard.io.sponge.ReaderUtil; -import com.sk89q.worldedit.extent.clipboard.io.sponge.VersionedDataFixer; -import com.sk89q.worldedit.internal.util.LogManagerCompat; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.world.DataFixer; -import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.biome.BiomeTypes; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockTypes; -import com.sk89q.worldedit.world.block.BlockTypesCache; -import com.sk89q.worldedit.world.entity.EntityType; -import it.unimi.dsi.fastutil.io.FastBufferedInputStream; -import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; -import net.jpountz.lz4.LZ4BlockInputStream; -import net.jpountz.lz4.LZ4BlockOutputStream; -import org.apache.logging.log4j.Logger; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.enginehub.linbus.tree.LinCompoundTag; -import org.enginehub.linbus.tree.LinIntArrayTag; -import org.enginehub.linbus.tree.LinTagType; -import org.jetbrains.annotations.ApiStatus; - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.OptionalInt; -import java.util.Set; -import java.util.UUID; -import java.util.function.BooleanSupplier; -import java.util.function.Function; -import java.util.zip.GZIPInputStream; - -/** - * ClipboardReader for the Sponge Schematic Format v3. - * Not necessarily much faster than {@link com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV3Reader}, but uses a - * stream based approach to keep the memory overhead minimal (especially in larger schematics) - * - * @since 2.11.1 - */ -@SuppressWarnings("removal") // JNBT -public class FaWeSchematicReaderV3 implements ClipboardReader { - - private static final Logger LOGGER = LogManagerCompat.getLogger(); - private static final byte CACHE_IDENTIFIER_END = 0x00; - private static final byte CACHE_IDENTIFIER_BLOCK = 0x01; - private static final byte CACHE_IDENTIFIER_BIOMES = 0x02; - private static final byte CACHE_IDENTIFIER_ENTITIES = 0x03; - private static final byte CACHE_IDENTIFIER_BLOCK_TILE_ENTITIES = 0x04; - - private final InputStream parentStream; - private final MutableBlockVector3 dimensions = MutableBlockVector3.at(0, 0, 0); - private final Set remainingTags; - - private DataInputStream dataInputStream; - private NBTInputStream nbtInputStream; - - private VersionedDataFixer dataFixer; - private BlockVector3 offset; - private BlockVector3 origin = BlockVector3.ZERO; - private BlockState[] blockPalette; - private BiomeType[] biomePalette; - private int dataVersion = -1; - - // Only used if the InputStream is not file based (and therefor does not support resets based on FileChannels) - // and the file is unordered - // Data and Palette cache is separated, as the data requires a fully populated palette - and the order is not guaranteed - private byte[] dataCache; - private byte[] paletteCache; - private OutputStream dataCacheWriter; - private OutputStream paletteCacheWriter; - - - public FaWeSchematicReaderV3(@NonNull InputStream stream) { - Objects.requireNonNull(stream, "stream"); - if (stream instanceof ResettableFileInputStream) { - stream.mark(Integer.MAX_VALUE); - this.remainingTags = new HashSet<>(); - } else if (stream instanceof FileInputStream fileInputStream) { - stream = new ResettableFileInputStream(fileInputStream); - stream.mark(Integer.MAX_VALUE); - this.remainingTags = new HashSet<>(); - } else if (stream instanceof FastBufferedInputStream || stream instanceof BufferedInputStream) { - this.remainingTags = null; - } else { - stream = new FastBufferedInputStream(stream); - this.remainingTags = null; - } - this.parentStream = stream; - } - - @Override - public Clipboard read(final UUID uuid, final Function createOutput) throws IOException { - Clipboard clipboard = null; - - this.setSubStreams(); - skipHeader(this.dataInputStream); - - byte type; - String tag; - while ((type = dataInputStream.readByte()) != NBTConstants.TYPE_END) { - tag = this.dataInputStream.readUTF(); - switch (tag) { - case "DataVersion" -> { - final Platform platform = - WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING); - this.dataVersion = this.dataInputStream.readInt(); - this.dataFixer = ReaderUtil.getVersionedDataFixer(this.dataVersion, platform, platform.getDataVersion()); - } - case "Metadata" -> { - LinCompoundTag metadataCompoundTag = - (LinCompoundTag) this.nbtInputStream.readTagPayload(NBTConstants.TYPE_COMPOUND, 0).toLinTag(); - - LinCompoundTag worldEditTag = metadataCompoundTag.findTag("WorldEdit", LinTagType.compoundTag()); - if (worldEditTag != null) { // allowed to be optional - LinIntArrayTag originTag = worldEditTag.findTag("Origin", LinTagType.intArrayTag()); - if (originTag != null) { // allowed to be optional - int[] parts = originTag.value(); - - if (parts.length != 3) { - throw new IOException("`Metadata > WorldEdit > Origin` int array length is invalid."); - } - - this.origin = BlockVector3.at(parts[0], parts[1], parts[2]); - } - } - } - case "Offset" -> { - this.dataInputStream.skipNBytes(4); // Array Length field (4 byte int) - this.offset = BlockVector3.at( - this.dataInputStream.readInt(), - this.dataInputStream.readInt(), - this.dataInputStream.readInt() - ); - } - case "Width" -> this.dimensions.mutX(this.dataInputStream.readShort() & 0xFFFF); - case "Height" -> this.dimensions.mutY(this.dataInputStream.readShort() & 0xFFFF); - case "Length" -> this.dimensions.mutZ(this.dataInputStream.readShort() & 0xFFFF); - case "Blocks" -> readBlocks(clipboard); - case "Biomes" -> readBiomes(clipboard); - case "Entities" -> readEntities(clipboard); - default -> this.nbtInputStream.readTagPayloadLazy(type, 0); - } - if (clipboard == null && this.areDimensionsAvailable()) { - clipboard = createOutput.apply(this.dimensions); - } - } - - if (clipboard == null) { - throw new IOException("Invalid schematic - missing dimensions"); - } - if (dataFixer == null) { - throw new IOException("Invalid schematic - missing DataVersion"); - } - - if (this.supportsReset() && !remainingTags.isEmpty()) { - readRemainingDataReset(clipboard); - } else if (this.dataCacheWriter != null || this.paletteCacheWriter != null) { - readRemainingDataCache(clipboard); - } - - clipboard.setOrigin(this.offset.multiply(-1)); - if (clipboard instanceof SimpleClipboard simpleClipboard && !this.offset.equals(BlockVector3.ZERO)) { - clipboard = new BlockArrayClipboard(simpleClipboard, this.offset.add(this.origin)); - } - return clipboard; - } - - - /** - * Reads all locally cached data (due to reset not being available) and applies them to the clipboard. - *

- * Firstly, closes all cache writers (which adds the END identifier to each and fills the cache byte arrays on this instance) - * If required, creates all missing palettes first (as needed by all remaining data). - * At last writes all missing data (block states, tile entities, biomes, entities). - * - * @param clipboard The clipboard to write into. - * @throws IOException on I/O error. - */ - private void readRemainingDataCache(Clipboard clipboard) throws IOException { - byte identifier; - if (this.paletteCacheWriter != null) { - this.paletteCacheWriter.close(); - } - if (this.dataCacheWriter != null) { - this.dataCacheWriter.close(); - } - if (this.paletteCache != null) { - try (final DataInputStream cacheStream = new DataInputStream(new FastBufferedInputStream( - new LZ4BlockInputStream(new FastBufferedInputStream(new ByteArrayInputStream(this.paletteCache)))))) { - while ((identifier = cacheStream.readByte()) != CACHE_IDENTIFIER_END) { - if (identifier == CACHE_IDENTIFIER_BLOCK) { - this.readPaletteMap(cacheStream, this.provideBlockPaletteInitializer()); - continue; - } - if (identifier == CACHE_IDENTIFIER_BIOMES) { - this.readPaletteMap(cacheStream, this.provideBiomePaletteInitializer()); - continue; - } - throw new IOException("invalid cache state - got identifier: 0x" + identifier); - } - } - } - try (final DataInputStream cacheStream = new DataInputStream(new FastBufferedInputStream( - new LZ4BlockInputStream(new FastBufferedInputStream(new ByteArrayInputStream(this.dataCache))))); - final NBTInputStream cacheNbtIn = new NBTInputStream(cacheStream)) { - while ((identifier = cacheStream.readByte()) != CACHE_IDENTIFIER_END) { - switch (identifier) { - case CACHE_IDENTIFIER_BLOCK -> this.readPaletteData(cacheStream, this.getBlockWriter(clipboard)); - case CACHE_IDENTIFIER_BIOMES -> this.readPaletteData(cacheStream, this.getBiomeWriter(clipboard)); - case CACHE_IDENTIFIER_ENTITIES -> { - cacheStream.skipNBytes(1); // list child type (TAG_Compound) - this.readEntityContainers( - cacheStream, - cacheNbtIn, - DataFixer.FixTypes.ENTITY, - this.provideEntityTransformer(clipboard) - ); - } - case CACHE_IDENTIFIER_BLOCK_TILE_ENTITIES -> { - cacheStream.skipNBytes(1); // list child type (TAG_Compound) - this.readEntityContainers( - cacheStream, - cacheNbtIn, - DataFixer.FixTypes.BLOCK_ENTITY, - this.provideTileEntityTransformer(clipboard) - ); - } - default -> throw new IOException("invalid cache state - got identifier: 0x" + identifier); - } - } - } - } - - /** - * Reset the main stream of this clipboard and reads all remaining data that could not be read or fixed yet. - * Might need two iterations if the DataVersion tag is after the Blocks tag while the Palette inside the Blocks tag is not - * at the first position. - * - * @param clipboard The clipboard to write into. - * @throws IOException on I/O error. - */ - private void readRemainingDataReset(Clipboard clipboard) throws IOException { - byte type; - String tag; - outer: - while (!this.remainingTags.isEmpty()) { - this.reset(); - skipHeader(this.dataInputStream); - while ((type = dataInputStream.readByte()) != NBTConstants.TYPE_END) { - tag = dataInputStream.readUTF(); - byte b = tag.equals("Blocks") ? CACHE_IDENTIFIER_BLOCK : - tag.equals("Biomes") ? CACHE_IDENTIFIER_BIOMES : - tag.equals("Entities") ? CACHE_IDENTIFIER_ENTITIES : - CACHE_IDENTIFIER_END; - if (!this.remainingTags.remove(b)) { - this.nbtInputStream.readTagPayloadLazy(type, 0); - continue; - } - switch (tag) { - case "Blocks" -> readBlocks(clipboard); - case "Biomes" -> readBiomes(clipboard); - case "Entities" -> readEntities(clipboard); - default -> this.nbtInputStream.readTagPayloadLazy(type, 0); // Should never happen, but just in case - } - if (this.remainingTags.isEmpty()) { - break outer; - } - } - } - } - - /** - * {@inheritDoc} - *

- * Requires {@link #read()}, {@link #read(UUID)} or {@link #read(UUID, Function)} to be called before. - */ - @Override - public OptionalInt getDataVersion() { - return this.dataVersion > -1 ? OptionalInt.of(this.dataVersion) : OptionalInt.empty(); - } - - private void readBlocks(Clipboard target) throws IOException { - this.blockPalette = new BlockState[BlockTypesCache.states.length]; - readPalette( - target != null, - CACHE_IDENTIFIER_BLOCK, - () -> this.blockPalette[0] != null, - this.provideBlockPaletteInitializer(), - this.getBlockWriter(target), - (type, tag) -> { - if (!tag.equals("BlockEntities")) { - try { - this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_LIST, 0); - } catch (IOException e) { - LOGGER.error("Failed to skip additional tag", e); - } - return; - } - try { - this.readTileEntities(target); - } catch (IOException e) { - LOGGER.warn("Failed to read tile entities", e); - } - } - ); - } - - private void readBiomes(Clipboard target) throws IOException { - this.biomePalette = new BiomeType[BiomeType.REGISTRY.size()]; - readPalette( - target != null, - CACHE_IDENTIFIER_BIOMES, - () -> this.biomePalette[0] != null, - this.provideBiomePaletteInitializer(), - this.getBiomeWriter(target), - (type, tag) -> { - try { - this.nbtInputStream.readTagPayloadLazy(type, 0); - } catch (IOException e) { - LOGGER.error("Failed to skip additional tag in biome container: {}", tag, e); - } - } - ); - } - - private void readEntities(@Nullable Clipboard target) throws IOException { - if (target == null || this.dataFixer == null) { - if (supportsReset()) { - this.remainingTags.add(CACHE_IDENTIFIER_ENTITIES); - this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_LIST, 0); - return; - } - // Easier than streaming for now - final NBTOutputStream cacheStream = new NBTOutputStream(this.getDataCacheWriter()); - cacheStream.writeByte(CACHE_IDENTIFIER_ENTITIES); - cacheStream.writeTagPayload(this.nbtInputStream.readTagPayload(NBTConstants.TYPE_LIST, 0)); - return; - } - if (this.dataInputStream.read() != NBTConstants.TYPE_COMPOUND) { - throw new IOException("Expected a compound block for entity"); - } - this.readEntityContainers( - this.dataInputStream, this.nbtInputStream, DataFixer.FixTypes.ENTITY, this.provideEntityTransformer(target) - ); - } - - private void readTileEntities(Clipboard target) throws IOException { - if (target == null || this.dataFixer == null) { - if (supportsReset()) { - this.remainingTags.add(CACHE_IDENTIFIER_BLOCK); // use block identifier, as this method will be called by - // readBlocks again - this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_LIST, 0); - return; - } - // Easier than streaming for now - final NBTOutputStream cacheStream = new NBTOutputStream(this.getDataCacheWriter()); - cacheStream.writeByte(CACHE_IDENTIFIER_BLOCK_TILE_ENTITIES); - cacheStream.writeTagPayload(this.nbtInputStream.readTagPayload(NBTConstants.TYPE_LIST, 0)); - return; - } - if (this.dataInputStream.read() != NBTConstants.TYPE_COMPOUND) { - throw new IOException("Expected a compound block for tile entity"); - } - this.readEntityContainers( - this.dataInputStream, - this.nbtInputStream, - DataFixer.FixTypes.BLOCK_ENTITY, - this.provideTileEntityTransformer(target) - ); - } - - private void readEntityContainers( - DataInputStream stream, - NBTInputStream nbtStream, - DataFixer.FixType fixType, - EntityTransformer transformer - ) throws IOException { - double x, y, z; - LinCompoundTag tag; - String id; - byte type; - int count = stream.readInt(); - while (count-- > 0) { - x = -1; - y = -1; - z = -1; - tag = null; - id = null; - while ((type = stream.readByte()) != NBTConstants.TYPE_END) { - switch (type) { - // Depending on the type of entity container (tile vs "normal") the pos consists of either doubles or ints - case NBTConstants.TYPE_INT_ARRAY -> { - if (!stream.readUTF().equals("Pos")) { - throw new IOException("Expected INT_ARRAY tag to be Pos"); - } - stream.skipNBytes(4); // count of following ints - for pos = 3 - x = stream.readInt(); - y = stream.readInt(); - z = stream.readInt(); - } - case NBTConstants.TYPE_LIST -> { - if (!stream.readUTF().equals("Pos")) { - throw new IOException("Expected LIST tag to be Pos"); - } - if (stream.readByte() != NBTConstants.TYPE_DOUBLE) { - throw new IOException("Expected LIST Pos tag to contain DOUBLE"); - } - stream.skipNBytes(4); // count of following doubles - for pos = 3 - x = stream.readDouble(); - y = stream.readDouble(); - z = stream.readDouble(); - } - case NBTConstants.TYPE_STRING -> { - if (!stream.readUTF().equals("Id")) { - throw new IOException("Expected STRING tag to be Id"); - } - id = stream.readUTF(); - } - case NBTConstants.TYPE_COMPOUND -> { - if (!stream.readUTF().equals("Data")) { - throw new IOException("Expected COMPOUND tag to be Data"); - } - if (!(nbtStream.readTagPayload(NBTConstants.TYPE_COMPOUND, 0).toLinTag() instanceof LinCompoundTag lin)) { - throw new IOException("Data tag could not be read into LinCompoundTag"); - } - tag = lin; - } - default -> throw new IOException("Unexpected tag in compound: " + type); - } - } - if (id == null) { - throw new IOException("Missing Id tag in compound"); - } - if (x < 0 || y < 0 || z < 0) { - throw new IOException("Missing position for entity " + id); - } - if (tag == null) { - transformer.transform(x, y, z, id, LinCompoundTag.of(Map.of())); - continue; - } - tag = this.dataFixer.fixUp(fixType, tag); - if (tag == null) { - LOGGER.warn("Failed to fix-up entity for {} @ {},{},{} - skipping", id, x, y, z); - continue; - } - transformer.transform(x, y, z, id, tag); - } - } - - /** - * The `Palette` tag is required first, as that contains the information of the actual palette size. - * Keeping the whole Data block in memory - which *could* be compressed - is just not it - * - * @param paletteInitializer Invoked for each 'Palette' entry using the actual palette value (e.g. block state) + index - * @param paletteDataApplier Invoked for each 'Data' entry using the data index and the palette index at the data index - */ - private void readPalette( - boolean hasClipboard, - byte paletteType, - BooleanSupplier paletteAlreadyInitialized, - PaletteInitializer paletteInitializer, - PaletteDataApplier paletteDataApplier, - AdditionalTagConsumer additionalTag - ) throws IOException { - boolean hasPalette = paletteAlreadyInitialized.getAsBoolean(); - byte type; - String tag; - while ((type = this.dataInputStream.readByte()) != NBTConstants.TYPE_END) { - tag = this.dataInputStream.readUTF(); - if (tag.equals("Palette")) { - if (hasPalette) { - // Skip palette, as already exists - this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_COMPOUND, 0); - continue; - } - if (!this.readPaletteMap(this.dataInputStream, paletteInitializer)) { - if (this.supportsReset()) { - // Couldn't read - skip palette for now - this.remainingTags.add(paletteType); - this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_COMPOUND, 0); - continue; - } - // Reset not possible, write into cache - final NBTOutputStream cacheWriter = new NBTOutputStream(this.getPaletteCacheWriter()); - cacheWriter.write(paletteType); - cacheWriter.writeTagPayload(this.nbtInputStream.readTagPayload(NBTConstants.TYPE_COMPOUND, 0)); - continue; - } - hasPalette = true; - continue; - } - if (tag.equals("Data")) { - // No palette or dimensions are yet available - if (!hasPalette || this.dataFixer == null || !hasClipboard) { - if (this.supportsReset()) { - this.remainingTags.add(paletteType); - this.nbtInputStream.readTagPayloadLazy(NBTConstants.TYPE_BYTE_ARRAY, 0); - continue; - } - // Reset not possible, write into cache - int byteLen = this.dataInputStream.readInt(); - final DataOutputStream cacheWriter = new DataOutputStream(this.getDataCacheWriter()); - cacheWriter.write(paletteType); - cacheWriter.writeInt(byteLen); - IOUtil.copy(this.dataInputStream, cacheWriter, byteLen); - continue; - } - this.readPaletteData(this.dataInputStream, paletteDataApplier); - continue; - } - additionalTag.accept(type, tag); - } - } - - private void readPaletteData(DataInputStream stream, PaletteDataApplier applier) throws IOException { - int length = stream.readInt(); - // Write data into clipboard - int i = 0; - if (needsVarIntReading(length)) { - for (var iter = new VarIntStreamIterator(stream, length); iter.hasNext(); i++) { - applier.apply(i, (char) iter.nextInt()); - } - return; - } - while (i < length) { - applier.apply(i++, (char) stream.readUnsignedByte()); - } - } - - /** - * Reads the CompoundTag containing the palette mapping ({@code index: value}) and passes each entry to the - * {@link PaletteInitializer}. - *

- * This method expects that the identifier ({@link NBTConstants#TYPE_COMPOUND}) is already consumed from the stream. - * - * @param stream The stream to read the data from. - * @param initializer The initializer called for each entry with its index and backed value. - * @return {@code true} if the mapping could be read, {@code false} otherwise (e.g. DataFixer is not yet available). - * @throws IOException on I/O error. - */ - private boolean readPaletteMap(DataInputStream stream, PaletteInitializer initializer) throws IOException { - if (this.dataFixer == null) { - return false; - } - while (stream.readByte() != NBTConstants.TYPE_END) { - String value = stream.readUTF(); - char index = (char) stream.readInt(); - initializer.initialize(index, value); - } - return true; - } - - private void indexToPosition(int index, PositionConsumer supplier) { - int y = index / (dimensions.x() * dimensions.z()); - int remainder = index - (y * dimensions.x() * dimensions.z()); - int z = remainder / dimensions.x(); - int x = remainder - z * dimensions.x(); - supplier.accept(x, y, z); - } - - private PaletteDataApplier getBlockWriter(Clipboard target) { - if (target instanceof LinearClipboard linearClipboard) { - return (index, ordinal) -> linearClipboard.setBlock(index, this.blockPalette[ordinal]); - } - return (index, ordinal) -> indexToPosition(index, (x, y, z) -> target.setBlock(x, y, z, this.blockPalette[ordinal])); - } - - private PaletteDataApplier getBiomeWriter(Clipboard target) { - return (index, ordinal) -> indexToPosition(index, (x, y, z) -> target.setBiome(x, y, z, this.biomePalette[ordinal])); - } - - private PaletteInitializer provideBlockPaletteInitializer() { - return (index, value) -> { - if (this.dataFixer == null) { - throw new IllegalStateException("Can't read block palette map if DataFixer is not yet available"); - } - value = dataFixer.fixUp(DataFixer.FixTypes.BLOCK_STATE, value); - try { - this.blockPalette[index] = BlockState.get(value); - } catch (InputParseException e) { - LOGGER.warn("Invalid BlockState in palette: {}. Block will be replaced with air.", value); - this.blockPalette[index] = BlockTypes.AIR.getDefaultState(); - } - }; - } - - private PaletteInitializer provideBiomePaletteInitializer() { - return (index, value) -> { - if (this.dataFixer == null) { - throw new IllegalStateException("Can't read biome palette map if DataFixer is not yet available"); - } - value = dataFixer.fixUp(DataFixer.FixTypes.BIOME, value); - BiomeType biomeType = BiomeTypes.get(value); - if (biomeType == null) { - biomeType = BiomeTypes.PLAINS; - LOGGER.warn("Invalid biome type in palette: {}. Biome will be replaced with plains.", value); - } - this.biomePalette[index] = biomeType; - }; - } - - private EntityTransformer provideEntityTransformer(Clipboard clipboard) { - return (x, y, z, id, tag) -> { - EntityType type = EntityType.REGISTRY.get(id); - if (type == null) { - LOGGER.warn("Invalid entity id: {} - skipping", id); - return; - } - clipboard.createEntity( - new Location(clipboard, Location.at(x, y, z).add(clipboard.getMinimumPoint().toVector3())), - new BaseEntity(type, LazyReference.computed(tag)) - ); - }; - } - - private EntityTransformer provideTileEntityTransformer(Clipboard clipboard) { - return (x, y, z, id, tag) -> clipboard.tile( - MathMan.roundInt(x + clipboard.getMinimumPoint().x()), - MathMan.roundInt(y + clipboard.getMinimumPoint().y()), - MathMan.roundInt(z + clipboard.getMinimumPoint().z()), - FaweCompoundTag.of(tag) - ); - } - - /** - * @return {@code true} if {@code Width}, {@code Length} and {@code Height} are already read from the stream - */ - private boolean areDimensionsAvailable() { - return this.dimensions.x() != 0 && this.dimensions.y() != 0 && this.dimensions.z() != 0; - } - - /** - * Closes this reader instance and all underlying resources. - * - * @throws IOException on I/O error. - */ - @Override - public void close() throws IOException { - parentStream.close(); // closes all underlying resources implicitly - } - - /** - * Resets the main stream to the previously marked position ({@code 0}), if supported (see {@link #supportsReset()}). - * If the stream is reset, the sub streams (for DataInput and NBT) are re-created to respect the new position. - * - * @throws IOException on I/O error. - */ - private void reset() throws IOException { - if (this.supportsReset()) { - this.parentStream.reset(); - this.parentStream.mark(Integer.MAX_VALUE); - this.setSubStreams(); - } - } - - /** - * @return {@code true} if the stream used while instantiating the reader supports resets (without memory overhead). - */ - private boolean supportsReset() { - return this.remainingTags != null; - } - - /** - * Overwrites the DataInput- and NBT-InputStreams (e.g. when the marker of the backed stream updated). - * - * @throws IOException on I/O error. - */ - private void setSubStreams() throws IOException { - this.dataInputStream = new DataInputStream(this.parentStream); - this.nbtInputStream = new NBTInputStream(this.parentStream); - } - - /** - * Creates a new cache writer for non-palette data, if none exists yet. - * Returns either the already created or new one. - * - * @return the output stream for non-palette cache data. - */ - private OutputStream getDataCacheWriter() { - if (this.dataCacheWriter == null) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(512); - this.dataCacheWriter = new FastBufferedOutputStream(new LZ4BlockOutputStream(byteArrayOutputStream)) { - @Override - public void close() throws IOException { - this.write(CACHE_IDENTIFIER_END); - super.close(); - FaWeSchematicReaderV3.this.dataCache = byteArrayOutputStream.toByteArray(); - } - }; - } - return this.dataCacheWriter; - } - - /** - * Creates a new cache writer for palette data, if none exists yet. - * Returns either the already created or new one. - * - * @return the output stream for palette cache data. - */ - private OutputStream getPaletteCacheWriter() { - if (this.paletteCacheWriter == null) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(256); - this.paletteCacheWriter = new FastBufferedOutputStream(new LZ4BlockOutputStream(byteArrayOutputStream)) { - @Override - public void close() throws IOException { - this.write(CACHE_IDENTIFIER_END); - super.close(); - FaWeSchematicReaderV3.this.paletteCache = byteArrayOutputStream.toByteArray(); - } - }; - } - return this.paletteCacheWriter; - } - - private boolean needsVarIntReading(int byteArrayLength) { - return byteArrayLength > this.dimensions.x() * this.dimensions.y() * this.dimensions.z(); - } - - /** - * Skips the schematic header including the root compound (empty name) and the root's child compound ("Schematic") - * - * @param dataInputStream The stream containing the schematic data to skip - * @throws IOException on I/O error - */ - private static void skipHeader(DataInputStream dataInputStream) throws IOException { - dataInputStream.skipNBytes(1 + 2); // 1 Byte = TAG_Compound, 2 Bytes = Short (Length of tag name = "") - dataInputStream.skipNBytes(1 + 2 + 9); // as above + 9 bytes = "Schematic" - } - - @ApiStatus.Internal - @FunctionalInterface - private interface PositionConsumer { - - /** - * Called with block location coordinates. - * - * @param x the x coordinate. - * @param y the y coordinate. - * @param z the z coordinate. - */ - void accept(int x, int y, int z); - - } - - @ApiStatus.Internal - @FunctionalInterface - private interface EntityTransformer { - - /** - * Called for each entity from the Schematics {@code Entities} compound list. - * - * @param x the relative x coordinate of the entity. - * @param y the relative y coordinate of the entity. - * @param z the relative z coordinate of the entity. - * @param id the entity id as a resource location (e.g. {@code minecraft:sheep}). - * @param tag the - already fixed, if required - nbt data of the entity. - */ - void transform(double x, double y, double z, String id, LinCompoundTag tag); - - } - - @ApiStatus.Internal - @FunctionalInterface - private interface PaletteInitializer { - - /** - * Called for each palette entry (the mapping part, not data). - * - * @param index the index of the entry, as used in the Data byte array. - * @param value the value for this entry (either biome type as resource location or the block state as a string). - */ - void initialize(char index, String value); - - } - - @ApiStatus.Internal - @FunctionalInterface - private interface PaletteDataApplier { - - /** - * Called for each palette data entry (not the mapping part, but the var-int byte array). - * - * @param index The index of this data entry (due to var-int behaviour not necessarily the index in the data byte array). - * @param ordinal The ordinal of this entry as defined in the palette mapping. - */ - void apply(int index, char ordinal); - - } - - @ApiStatus.Internal - @FunctionalInterface - private interface AdditionalTagConsumer { - - /** - * Called for each unknown nbt tag. - * - * @param type The type of the tag (as defined by the constants in {@link NBTConstants}). - * @param name The name of the tag. - */ - void accept(byte type, String name); - - } - -} diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java index 52743f45..d93c095d 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java @@ -26,6 +26,8 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader; +import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV2Reader; +import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV3Reader; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.Region; @@ -33,6 +35,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import de.steamwar.sql.NodeData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import org.enginehub.linbus.stream.LinBinaryIO; import java.io.*; @@ -67,8 +70,8 @@ public class WorldEditWrapper21 implements WorldEditWrapper { public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { return switch (schemFormat) { case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(is)).read(); - case SPONGE_V2 -> new FastSchematicReaderV2(new NBTInputStream(is)).read(); - case SPONGE_V3 -> new FaWeSchematicReaderV3(is).read(); + case SPONGE_V2 -> new SpongeSchematicV2Reader(LinBinaryIO.read(new DataInputStream(is))).read(); + case SPONGE_V3 -> new SpongeSchematicV3Reader(LinBinaryIO.read(new DataInputStream(is))).read(); }; } @@ -93,4 +96,9 @@ public class WorldEditWrapper21 implements WorldEditWrapper { v = transform.apply(v); return new org.bukkit.util.Vector(v.x(), v.y(), v.z()); } + + @Override + public NodeData.SchematicFormat getNativeFormat() { + return NodeData.SchematicFormat.SPONGE_V3; + } } diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java index a6aad3b5..75957933 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java @@ -105,6 +105,11 @@ public class WorldEditWrapper8 implements WorldEditWrapper { return new org.bukkit.util.Vector(v.getX(), v.getY(), v.getZ()); } + @Override + public NodeData.SchematicFormat getNativeFormat() { + return NodeData.SchematicFormat.MCEDIT; + } + private static class SpongeSchematicReader implements ClipboardReader { private final NBTInputStream inputStream; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java index 62a7f2b7..c9585847 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java @@ -77,7 +77,7 @@ public class ErrorHandler extends Handler { return; try { - //SWException.log(message, stacktrace); + SWException.log(message, stacktrace); } catch (SecurityException e) { Core.getInstance().getLogger().log(Level.INFO, "Could not log error in database", e); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java index d07bd155..9928b947 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java @@ -46,6 +46,8 @@ public interface WorldEditWrapper { Vector getMaximum(Region region); Vector applyTransform(Vector vector, Transform transform); + NodeData.SchematicFormat getNativeFormat(); + static WorldEditPlugin getWorldEditPlugin() { return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); } @@ -86,16 +88,6 @@ public interface WorldEditWrapper { return inputStream; } - static NodeData.SchematicFormat getNativeFormat() { - if (Core.getVersion() <= 12) { - return NodeData.SchematicFormat.MCEDIT; - } else if (Core.getVersion() <= 20) { - return NodeData.SchematicFormat.SPONGE_V2; - } else { - return NodeData.SchematicFormat.SPONGE_V3; - } - } - interface SchematicWriter { void write(OutputStream outputStream, Clipboard clipboard, ClipboardHolder holder) throws IOException; } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java index 0957bae0..62f00369 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java @@ -61,7 +61,7 @@ public class SchematicData { } public void saveFromPlayer(Player player) throws IOException, NoClipboardException { - data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player), WorldEditWrapper.getNativeFormat()); + data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player), WorldEditWrapper.impl.getNativeFormat()); } @Deprecated diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index e9d6386e..166df4c4 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -64,4 +64,6 @@ dependencies { implementation(libs.apolloapi) implementation(libs.apollocommon) + + implementation(libs.nbt) } \ No newline at end of file diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java index a39837f6..68b8d360 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java @@ -25,10 +25,13 @@ import de.steamwar.sql.NodeData; import de.steamwar.sql.Punishment; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; +import dev.dewy.nbt.Nbt; +import dev.dewy.nbt.tags.collection.CompoundTag; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; +import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; @@ -38,6 +41,8 @@ import java.util.logging.Level; public class DiscordSchemUpload extends ListenerAdapter { + private static final Nbt NBT = new Nbt(); + private static final List SCHEM_FILE_ENDINGS = Arrays.asList(".schem", ".schematic"); @Override @@ -79,7 +84,17 @@ public class DiscordSchemUpload extends ListenerAdapter { node = SchematicNode.createSchematic(user.getId(), name, null); try (InputStream in = attachment.getProxy().download().get()) { - NodeData.get(node).saveFromStream(in, fileName.substring(dot).equalsIgnoreCase(".schem") ? NodeData.SchematicFormat.SPONGE_V2 : NodeData.SchematicFormat.MCEDIT); + CompoundTag tags = NBT.fromStream(new DataInputStream(in)); + + NodeData.SchematicFormat version = NodeData.SchematicFormat.SPONGE_V2; + + if (tags.size() == 1) { + version = NodeData.SchematicFormat.SPONGE_V3; + } else if (tags.contains("Materials")) { + version = NodeData.SchematicFormat.MCEDIT; + } + + NodeData.get(node).saveFromStream(in, version); sender.system("DC_SCHEMUPLOAD_SUCCESS", name); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index 0dea01f7..e40b5287 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -126,25 +126,29 @@ fun Route.configureSchematic() { node = SchematicNode.createSchematic(user.id, schemName, 0) } - val content = Base64.getDecoder().decode(file.content) + try { + val content = Base64.getDecoder().decode(file.content) - var schem = nbt.decodeFromByteArray(content) + var schem = nbt.decodeFromByteArray(content) - if (schem.size == 1) schem = schem[schem.keys.first()] as NbtCompound + if (schem.size == 1) schem = schem[schem.keys.first()] as NbtCompound - val version = schem.let { - if (it.containsKey("Materials")) - return@let SchematicFormat.MCEDIT - else if (it.containsKey("Blocks")) - return@let SchematicFormat.SPONGE_V3 - else - return@let SchematicFormat.SPONGE_V2 + val version = schem.let { + if (it.containsKey("Materials")) + return@let SchematicFormat.MCEDIT + else if (it.containsKey("Blocks")) + return@let SchematicFormat.SPONGE_V3 + else + return@let SchematicFormat.SPONGE_V2 + } + + val data = NodeData(node.id, version) + data.saveFromStream(content.inputStream(), version) + + call.respond(ResponseSchematic(node)) + } catch (e: Exception) { + call.respond(HttpStatusCode.BadRequest) } - - val data = NodeData(node.id, version) - data.saveFromStream(content.inputStream(), version) - - call.respond(ResponseSchematic(node)) } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 07242d37..670bea38 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -165,7 +165,9 @@ dependencyResolutionManagement { library("yamlconfig", "org.bspfsystems:yamlconfiguration:1.3.0") library("kotlinxSerializationCbor", "org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.4.1") library("ktorRateLimit", "io.ktor:ktor-server-rate-limit:$ktorVersion") + library("knbt", "net.benwoodworth.knbt:knbt:0.11.7") + library("nbt", "dev.dewy:nbt:1.5.1") } } } From ec5382316ad4732f33133f6ec3876d313dfe3a92 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 21 Dec 2024 19:33:23 +0100 Subject: [PATCH 007/106] Fixes --- WebsiteBackend/build.gradle.kts | 2 +- .../src/de/steamwar/routes/Schematic.kt | 17 +++++++---------- settings.gradle.kts | 1 - 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/WebsiteBackend/build.gradle.kts b/WebsiteBackend/build.gradle.kts index f93dacde..d58a5142 100644 --- a/WebsiteBackend/build.gradle.kts +++ b/WebsiteBackend/build.gradle.kts @@ -53,5 +53,5 @@ dependencies { implementation(libs.yamlconfig) implementation(libs.kotlinxSerializationCbor) implementation(libs.ktorRateLimit) - implementation(libs.knbt) + implementation(libs.nbt) } \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index e40b5287..c4d76f80 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -27,16 +27,16 @@ import de.steamwar.sql.NodeDownload import de.steamwar.sql.NodeMember import de.steamwar.sql.SWException import de.steamwar.sql.SchematicNode +import dev.dewy.nbt.Nbt +import dev.dewy.nbt.tags.collection.CompoundTag import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* -import kotlinx.coroutines.launch import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromByteArray -import net.benwoodworth.knbt.* import java.security.MessageDigest import java.time.Duration import java.time.Instant @@ -75,10 +75,7 @@ data class SchematicCode(val id: Int, val code: String, val expires: Long) @Serializable data class UploadSchematic(val name: String, val content: String) -val nbt = Nbt { - variant = NbtVariant.Java - compression = NbtCompression.Gzip -} +val nbt = Nbt() fun Route.configureSchematic() { route("/download/{code}") { @@ -129,14 +126,14 @@ fun Route.configureSchematic() { try { val content = Base64.getDecoder().decode(file.content) - var schem = nbt.decodeFromByteArray(content) + var schem = nbt.fromByteArray(content) - if (schem.size == 1) schem = schem[schem.keys.first()] as NbtCompound + if (schem.size() == 1) schem = schem.first() as CompoundTag val version = schem.let { - if (it.containsKey("Materials")) + if (it.contains("Materials")) return@let SchematicFormat.MCEDIT - else if (it.containsKey("Blocks")) + else if (it.contains("Blocks")) return@let SchematicFormat.SPONGE_V3 else return@let SchematicFormat.SPONGE_V2 diff --git a/settings.gradle.kts b/settings.gradle.kts index 423e814e..8f3fcdcb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -165,7 +165,6 @@ dependencyResolutionManagement { library("kotlinxSerializationCbor", "org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.4.1") library("ktorRateLimit", "io.ktor:ktor-server-rate-limit:$ktorVersion") - library("knbt", "net.benwoodworth.knbt:knbt:0.11.7") library("nbt", "dev.dewy:nbt:1.5.1") } } From 9154077104e438ac0a71c93ce08e700573a47ce6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 23 Dec 2024 12:50:38 +0100 Subject: [PATCH 008/106] Fix TNT League Stage Names --- .../src/de/steamwar/tntleague/game/TNTLeagueGame.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt index d8a36718..e064a350 100644 --- a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt +++ b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt @@ -237,7 +237,7 @@ object TNTLeagueGame { "", blueTeam.name.colorByTeam(blueTeam), redTeam.name.colorByTeam(redTeam), - state.name, + state.lobbyName, TNTLeagueConfig.config.gameTime - gameTimeRemaining, blueTeam.leader?.let { SteamwarUser.get(it.uniqueId).id } ?: 0, redTeam.leader?.let { SteamwarUser.get(it.uniqueId).id } ?: 0, @@ -249,11 +249,11 @@ object TNTLeagueGame { )) } - enum class GameState(val listener: Listener) { - LOBBY(LobbyListener), - STARTING(LobbyListener), - RUNNING(IngameListener), - END(DummyListener); + enum class GameState(val listener: Listener, val lobbyName: String) { + LOBBY(LobbyListener, "PRE_LEADER_SETUP"), + STARTING(LobbyListener, "POST_SCHEM_SETUP"), + RUNNING(IngameListener, "RUNNING"), + END(DummyListener, "SPECTATE"); } enum class WinReason { From fb0a653b0e2eddb342f695c0a23869511c857e80 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 23 Dec 2024 13:05:00 +0100 Subject: [PATCH 009/106] Remove /leader command, allow for Leader promotion --- .../de/steamwar/fightsystem/FightSystem.java | 1 - .../fightsystem/FightSystem.properties | 10 ++-- .../fightsystem/FightSystem_de.properties | 10 ++-- .../de/steamwar/fightsystem/commands/GUI.java | 22 +++++-- .../fightsystem/commands/LeaderCommand.java | 60 ------------------- .../steamwar/fightsystem/fight/FightTeam.java | 7 ++- .../fightsystem/listener/TestJoin.java | 7 --- .../fightsystem/utils/BungeeFightInfo.java | 4 -- FightSystem/FightSystem_Core/src/plugin.yml | 1 - .../src/de/steamwar/inventory/SWItem.java | 11 ++-- 10 files changed, 37 insertions(+), 96 deletions(-) delete mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 6e6b1c40..57400063 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -153,7 +153,6 @@ public class FightSystem extends JavaPlugin { new GamemodeCommand(); new ReadyCommand(); new AkCommand(); - new LeaderCommand(); new LockschemCommand(); new StateCommand(); new SkipCommand(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 9f80ab7e..3d9a9218 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -34,9 +34,6 @@ GAMEMODE_NOT_ALLOWED=§cChanging gamemode is not permitted GAMEMODE_UNKNOWN=§cUnknown gamemode {0} GAMEMODE_HELP=§8/§7gm §8[§egamemode§8] -LEADER_FULL=§cAll teams already have a leader -ALREADY_IN_TEAM=§cYou are already in a team - LOCKSCHEM_HELP=§8/§7lockschem §8[§eteam§8] UNKNOWN_TEAM=§cThis team does not exist LOCKSCHEM_LOCKED=§7Schematic locked @@ -65,7 +62,9 @@ STATE_RUNNING=§eFighting phase STATE_SPECTATE_WIN=§7Victory {0} STATE_SPECTATE_TIE=§7Draw -REMOVE_TITLE=Kick player +MANAGE_TITLE=Manage players +MANAGE_LORE1=§eLeft §7click§8: §ekick +MANAGE_LORE2=§eRight §7click§8: §epromote KIT_SELECTION_TITLE=Kit selection KIT_NO_KITS=§cNo kits found @@ -113,7 +112,7 @@ SKIP_NOT_READY=§c§mSkipping to next event TEAM_CHAT={0}{1}§8» {0}{2} CHOOSE_KIT=§eChoose kit RESPAWN=§eRespawn -REMOVE_PLAYERS=§cKick player +MANAGE_PLAYERS=§cManage players CHOOSE_SCHEMATIC=§eChoose {0} SCHEMATIC_REQUIRED=§cChoose a schematic first ADD_AI=§eAdd AI @@ -141,7 +140,6 @@ NO_TELEPORT=§cYou are not allowed to use this teleport function OPEN_INVENTORY_TO_CUSTOMIZE=§eOpen inventory to customize your kit NO_ENTERN=§cYou may not board NO_TEAMAREA=§cYou are not allowed in the team area -TEST_BECOME_LEADER=§7Become a team leader with §8/§eleader PREPARE_SCHEM_DELETED=§cApparently the schematic to be submitted was deleted. submission aborted. PREPARE_SCHEM_EXISTS=§cThere is already a schematic with the suffix -prepared, please rename or delete it, submission aborted. PREPARE_ACTIVE_PISTON=§cMoving pistons were found in the team area, submission aborted. diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 6723bcfb..d45cdfd0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -32,9 +32,6 @@ GAMEMODE_NOT_ALLOWED=§cSpielmodusänderung verboten GAMEMODE_UNKNOWN=§cUnbekannter Spielmodus {0} GAMEMODE_HELP=§8/§7gm §8[§eSpielmodus§8] -LEADER_FULL=§cAlle Teams haben bereits einen Leader -ALREADY_IN_TEAM=§cDu bist bereits in einem Team - LOCKSCHEM_HELP=§8/§7lockschem §8[§eTeam§8] UNKNOWN_TEAM=§cDieses Team existiert nicht LOCKSCHEM_LOCKED=§7Schematic gesperrt @@ -59,7 +56,9 @@ STATE_RUNNING=§eKampfphase STATE_SPECTATE_WIN=§7Sieg {0} STATE_SPECTATE_TIE=§7Unentschieden -REMOVE_TITLE=Spieler rauswerfen +MANAGE_TITLE=Mitspieler verwalten +MANAGE_LORE1=§eLinksklick§8: §eRauswurf +MANAGE_LORE2=§eRechtsklick§8: §eBefördern KIT_SELECTION_TITLE=Kitauswahl KIT_NO_KITS=§cKeine Kits gefunden @@ -106,7 +105,7 @@ SKIP_READY=§aBeschleunigung zum nächsten Event SKIP_NOT_READY=§c§mBeschleunigung zum nächsten Event CHOOSE_KIT=§eKit wählen RESPAWN=§eRespawn -REMOVE_PLAYERS=§cSpieler rauswerfen +MANAGE_PLAYERS=§cMitspieler verwalten CHOOSE_SCHEMATIC=§e{0} wählen SCHEMATIC_REQUIRED=§cZuerst muss eine Schematic gewählt sein ADD_AI=§eKI hinzufügen @@ -134,7 +133,6 @@ NO_TELEPORT=§cDu darfst diese Teleportfunktion nicht benutzen OPEN_INVENTORY_TO_CUSTOMIZE=§eInventar zum Anpassen des Kits öffnen NO_ENTERN=§cDu darfst nicht entern NO_TEAMAREA=§cDu darfst nicht zu den Teams -TEST_BECOME_LEADER=§7Werde zum Teamleader mit §8/§eleader PREPARE_SCHEM_DELETED=§cAnscheinend wurde die auszufahrende Schematic gelöscht, Einsenden wird abgebrochen. PREPARE_SCHEM_EXISTS=§cEs existiert bereits eine Schem mit Namenszusatz -prepared, diese bitte umbenennen oder löschen, Einsenden wird abgebrochen. PREPARE_ACTIVE_PISTON=§cIm Teambereich wurden sich noch bewegende Pistons gefunden, Einsenden wird abgebrochen. diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index 4834bb0a..2ca6849c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -36,6 +36,7 @@ import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -53,7 +54,11 @@ public class GUI { String name = team.getLeader() != null ? team.getLeader().getEntity().getName() : team.getName(); inv.setItem(pos, SWItem.getDye(colorCode), colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColor() + name), click -> { p.closeInventory(); - JoinRequest.forPlayer(p, team); + + if(ArenaMode.ManualTeams.contains(Config.mode) && team.canbeLeader(p)) + team.addMember(p); + else + JoinRequest.forPlayer(p, team); }); } @@ -117,14 +122,21 @@ public class GUI { inv.open(); } - public static void chooseRemove(Player p){ + public static void managePlayers(Player p){ List> players = SWListInv.createPlayerList(p.getUniqueId()); FightTeam team = Fight.getPlayerTeam(p); if(team == null) return; - players.removeIf(swItemUUIDPair -> !team.equals(Fight.getPlayerTeam(Bukkit.getPlayer(swItemUUIDPair.getObject())))); - SWListInv inv = new SWListInv<>(p, msg.parse("REMOVE_TITLE", p), players, (ClickType click, UUID player) -> { - Commands.kick(p, SteamwarUser.get(player).getUserName()); + players.removeIf(listEntry -> !team.equals(Fight.getPlayerTeam(Bukkit.getPlayer(listEntry.getObject())))); + players.forEach(listEntry -> listEntry.getItem().setLore(msg.parse("MANAGE_LORE1", p), msg.parse("MANAGE_LORE2", p))); + SWListInv inv = new SWListInv<>(p, msg.parse("MANAGE_TITLE", p), players, (ClickType click, UUID player) -> { + if(click.isLeftClick()) { + Commands.kick(p, SteamwarUser.get(player).getUserName()); + } else if(click.isRightClick()) { + LivingEntity target = (LivingEntity) Bukkit.getEntity(player); + if(target != null) + team.setLeader(team.getFightPlayer(target), false); + } p.closeInventory(); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java deleted file mode 100644 index e2151956..00000000 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 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.fightsystem.commands; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; -import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class LeaderCommand implements CommandExecutor { - - public LeaderCommand() { - new StateDependentCommand(ArenaMode.ManualTeams, FightState.Setup, "leader", this); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) - return false; - Player player = (Player) sender; - - if(Fight.getFightPlayer(player) != null) { - FightSystem.getMessage().sendPrefixless("ALREADY_IN_TEAM", player, ChatMessageType.ACTION_BAR); - return false; - } - - for(FightTeam team : Fight.teams()) { - if(team.canbeLeader(player)) { - team.addMember(player); - return false; - } - } - FightSystem.getMessage().sendPrefixless("LEADER_FULL", player, ChatMessageType.ACTION_BAR); - return false; - } -} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 334f3f83..3a6a12a2 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -73,7 +73,7 @@ public class FightTeam { if(ArenaMode.VariableTeams.contains(Config.mode)){ notReadyKit.setItem(2, "REQUESTS", new ItemBuilder(Material.PAPER).build(), GUI::chooseJoinRequests); - notReadyKit.setItem(3, "REMOVE_PLAYERS", new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).build(), GUI::chooseRemove); + notReadyKit.setItem(3, "MANAGE_PLAYERS", SWItem.getPlayerSkull("AdmiralSeekrank").getItemStack(), GUI::managePlayers); if(!AIManager.availableAIs().isEmpty()) notReadyKit.setItem(6, "ADD_AI", new ItemBuilder(Material.REDSTONE).build(), GUI::addAI); } @@ -343,7 +343,10 @@ public class FightTeam { } } - private void setLeader(FightPlayer leader, boolean silent) { + public void setLeader(FightPlayer leader, boolean silent) { + if(this.leader != null) + this.leader.ifPlayer(memberKit::loadToPlayer); + leader.ifPlayer(PersonalKitCreator::closeIfInKitCreator); this.leader = leader; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java index 77240153..13a512a4 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java @@ -22,8 +22,6 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.sql.SteamwarUser; @@ -42,7 +40,6 @@ public class TestJoin implements Listener { @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - FightTeam fightTeam = Fight.getPlayerTeam(player); if(Config.ReplayID != 0 && !SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.MODERATION)) { FightSystem.getMessage().send("CHECK_JOIN_DENIED", player); @@ -50,10 +47,6 @@ public class TestJoin implements Listener { return; } - if (fightTeam == null && Fight.teams().stream().anyMatch(team -> team.canbeLeader(player))) { - FightSystem.getMessage().send("TEST_BECOME_LEADER", player); - } - player.setOp(true); if(FightState.getFightState() == FightState.PRE_LEADER_SETUP){ diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java index 6ffa0e98..783917bb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java @@ -40,10 +40,6 @@ public class BungeeFightInfo { } private void send() { - Player player = Bukkit.getOnlinePlayers().stream().findAny().orElse(null); - if(player == null) - return; - NetworkSender.send(new FightInfoPacket( Config.world.getName(), Config.SchematicType.toDB(), diff --git a/FightSystem/FightSystem_Core/src/plugin.yml b/FightSystem/FightSystem_Core/src/plugin.yml index d8763954..64ece716 100644 --- a/FightSystem/FightSystem_Core/src/plugin.yml +++ b/FightSystem/FightSystem_Core/src/plugin.yml @@ -19,7 +19,6 @@ commands: ready: kit: remove: - leader: lockschem: state: skip: diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java index bc401476..1f9c9813 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java @@ -21,21 +21,19 @@ package de.steamwar.inventory; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; import de.steamwar.core.TrickyTrialsWrapper; -import de.steamwar.core.VersionDependent; import org.bukkit.Material; import org.bukkit.OfflinePlayer; -import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; -import java.util.Collection; +import java.util.Arrays; import java.util.EnumSet; import java.util.List; +import java.util.stream.Collectors; public class SWItem { @@ -192,6 +190,11 @@ public class SWItem { itemStack.setItemMeta(itemMeta); } + public void setLore(String... lore) { + itemMeta.setLore(Arrays.stream(lore).collect(Collectors.toList())); + itemStack.setItemMeta(itemMeta); + } + public void setEnchanted(boolean enchanted) { if (enchanted){ itemMeta.addEnchant(TrickyTrialsWrapper.impl.getUnbreakingEnchantment() , 10, true); From bd87221198026b760dabb0855a05b1c84b5761f1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 23 Dec 2024 13:12:57 +0100 Subject: [PATCH 010/106] Add subcommand to reload gamemodes without full softreload --- .../de/steamwar/velocitycore/commands/DevCommand.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java index 528272fb..e24432cc 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java @@ -21,7 +21,10 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; +import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; +import de.steamwar.sql.UserPerm; +import de.steamwar.velocitycore.ArenaMode; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; @@ -79,6 +82,14 @@ public class DevCommand extends SWCommand { sender.getPlayer().createConnectionRequest(server).fireAndForget(); } + @Register(value = "reloadmodes") + public void reloadModes(Chatter sender) { + if(!sender.user().hasPerm(UserPerm.ADMINISTRATION)) + return; + + ArenaMode.init(); + } + @ClassValidator(value = PlayerChatter.class, local = true) public TypeValidator punishmentGuardChecker() { return (sender, value, messageSender) -> { From 22a8ca4aea23e9f51334e76c8c8bdb1d65090e19 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 24 Dec 2024 14:55:27 +0100 Subject: [PATCH 011/106] Move ViaVersion to Proxy --- BauSystem/BauSystem_Main/build.gradle.kts | 1 - .../BauSystem_Main/src/BauSystem.properties | 4 +- .../src/BauSystem_de.properties | 4 +- .../bausystem/utils/VersionAnnouncer.java | 49 ----------- BauSystem/BauSystem_Main/src/plugin.yml | 2 - SpigotCore/SpigotCore_9/build.gradle.kts | 2 - .../de/steamwar/core/BountifulWrapper9.java | 4 +- SpigotCore/SpigotCore_Main/build.gradle.kts | 1 - .../de/steamwar/core/CheckpointUtilsJ9.java | 3 - .../src/de/steamwar/core/Core.java | 3 - .../core/events/PartialChunkFixer.java | 84 ------------------- SpigotCore/SpigotCore_Main/src/plugin.yml | 1 - .../src/de/steamwar/persistent/Subserver.java | 10 +-- VelocityCore/build.gradle.kts | 3 +- .../steamwar/messages/BungeeCore.properties | 3 + .../messages/BungeeCore_de.properties | 3 + .../steamwar/velocitycore/GameModeConfig.java | 9 +- .../src/de/steamwar/velocitycore/Node.java | 14 ++-- .../steamwar/velocitycore/ServerStarter.java | 14 ++-- .../steamwar/velocitycore/ServerVersion.java | 29 ++++--- .../steamwar/velocitycore/VelocityCore.java | 1 + .../listeners/VersionAnnouncer.java | 47 +++++++++++ settings.gradle.kts | 3 +- 23 files changed, 104 insertions(+), 190 deletions(-) delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java delete mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java create mode 100644 VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java diff --git a/BauSystem/BauSystem_Main/build.gradle.kts b/BauSystem/BauSystem_Main/build.gradle.kts index 8f46699d..5b8f0a89 100644 --- a/BauSystem/BauSystem_Main/build.gradle.kts +++ b/BauSystem/BauSystem_Main/build.gradle.kts @@ -38,7 +38,6 @@ dependencies { compileOnly(libs.spigotapi) compileOnly(libs.axiom) compileOnly(libs.authlib) - compileOnly(libs.viaapi) compileOnly(libs.fawe18) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index c9116dce..929d0c67 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -1013,6 +1013,4 @@ XRAY_OFF=§cXray deactivated COLORREPLACE_HELP=§8//§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §7Replace all blocks of one color with another TYPEREPLACE_HELP=§8//§etypereplace §8[§7type§8] §8[§7type§8] §8- §7Replace all blocks of one type with another # Schematic -SCHEMATIC_GUI_ITEM=§eSchematics -#VersionAnnouncer -SERVER_VERSION=§7This server runs on Minecraft version §e{0} \ No newline at end of file +SCHEMATIC_GUI_ITEM=§eSchematics \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index 45e60f84..4cb20d95 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -954,6 +954,4 @@ XRAY_OFF=§cXray deaktiviert COLORREPLACE_HELP=§8//§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §7Ersetzt eine Farbe mit einer anderen TYPEREPLACE_HELP=§8//§etyreplace §8[§7type§8] §8[§7type§8] §8- §7Ersetzt einen Blockgruppe mit einer anderen # Schematics -SCHEMATIC_GUI_ITEM=§eSchematics -#VersionAnnouncer -SERVER_VERSION=§7Dieser Server läuft auf Minecraft-Version §e{0} \ No newline at end of file +SCHEMATIC_GUI_ITEM=§eSchematics \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java deleted file mode 100644 index ee9e91be..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.utils; - -import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.ViaAPI; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.linkage.Linked; -import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -@Linked -public class VersionAnnouncer implements Listener { - - private final String versionString = Bukkit.getBukkitVersion().split("-", 2)[0]; - - @SuppressWarnings("unchecked") - private final ViaAPI via = Via.getAPI(); - - @EventHandler - public void onJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - if(via.getServerVersion().supportedVersions().contains(via.getPlayerVersion(player))) - return; - - BauSystem.MESSAGE.sendPrefixless("SERVER_VERSION", player, ChatMessageType.ACTION_BAR, versionString); - } -} diff --git a/BauSystem/BauSystem_Main/src/plugin.yml b/BauSystem/BauSystem_Main/src/plugin.yml index 53585eaa..71b08d95 100644 --- a/BauSystem/BauSystem_Main/src/plugin.yml +++ b/BauSystem/BauSystem_Main/src/plugin.yml @@ -2,8 +2,6 @@ name: BauSystem authors: [ Lixfel, YoyoNow, Chaoscaot, Zeanon, D4rkr34lm ] version: "2.0" depend: [ WorldEdit, SpigotCore ] -softdepend: - - ViaVersion load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13" diff --git a/SpigotCore/SpigotCore_9/build.gradle.kts b/SpigotCore/SpigotCore_9/build.gradle.kts index 3463498a..a888faf1 100644 --- a/SpigotCore/SpigotCore_9/build.gradle.kts +++ b/SpigotCore/SpigotCore_9/build.gradle.kts @@ -26,6 +26,4 @@ dependencies { compileOnly(project(":SpigotCore:SpigotCore_8", "default")) compileOnly(libs.nms9) - - compileOnly(libs.viaapi) } diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index fa126698..d35e4239 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -20,10 +20,8 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; -import com.viaversion.viaversion.api.Via; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; -import net.minecraft.server.v1_9_R2.PacketPlayOutEntity; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -38,7 +36,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public void sendMessage(Player player, ChatMessageType type, BaseComponent... msg) { - if(type == ChatMessageType.CHAT && Via.getAPI().getPlayerVersion(player.getUniqueId()) >= 759) + if(type == ChatMessageType.CHAT) type = ChatMessageType.SYSTEM; player.spigot().sendMessage(type, msg); diff --git a/SpigotCore/SpigotCore_Main/build.gradle.kts b/SpigotCore/SpigotCore_Main/build.gradle.kts index 88825bc9..cc941d8c 100644 --- a/SpigotCore/SpigotCore_Main/build.gradle.kts +++ b/SpigotCore/SpigotCore_Main/build.gradle.kts @@ -35,7 +35,6 @@ dependencies { compileOnly(libs.spigotapi) compileOnly(libs.netty) compileOnly(libs.authlib) - compileOnly(libs.viaapi) compileOnly(libs.fastutil) implementation(libs.anvilgui) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index cde82084..50658aea 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -21,7 +21,6 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; -import com.viaversion.viaversion.api.Via; import de.steamwar.sql.internal.Statement; import io.netty.channel.ChannelFuture; import org.bukkit.Bukkit; @@ -99,7 +98,6 @@ class CheckpointUtilsJ9 { Statement.closeAll(); // Close socket - Via.getManager().getInjector().uninject(); Object serverConnection = TinyProtocol.getServerConnection(Core.getInstance()); List channels = channelFutures.get(serverConnection); for(Object future : channels) { @@ -140,7 +138,6 @@ class CheckpointUtilsJ9 { ((ChannelFuture) future).channel().config().setAutoRead(true); } } - Via.getManager().getInjector().inject(); Bukkit.getPluginManager().callEvent(new CRIUWakeupEvent()); Core.getInstance().getLogger().log(Level.INFO, "Checkpoint restored"); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index 9c1e51ef..f4a2b419 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -100,9 +100,6 @@ public class Core extends JavaPlugin{ CheckpointUtils.signalHandler(); new AntiNocom(); - if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null) - new PartialChunkFixer(); - if(Core.getVersion() >= 19) new ServerDataHandler(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java deleted file mode 100644 index 6efab3c5..00000000 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.core.events; - -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; -import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.ViaAPI; -import de.steamwar.core.Core; -import de.steamwar.core.CraftbukkitWrapper; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -/** - * TinyProtocol can't translate BlockEntities during 1.16 to 1.17 conversions du to removed partial chunk update support. This class cancels PartialChunkUpdates for this players and sends them a complete chunk instead. - * This class can only be loaded on 1.9 to 1.15 with active ViaVersion. - **/ -public class PartialChunkFixer { - - private static final int PROTOCOL1_17 = 755; - private static final Class mapChunk = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); - private static final Reflection.FieldAccessor fullChunkFlag = Reflection.getField(mapChunk, boolean.class, 0); - private static final Reflection.FieldAccessor chunkX = Reflection.getField(mapChunk, int.class, 0); - private static final Reflection.FieldAccessor chunkZ = Reflection.getField(mapChunk, int.class, 1); - - private final ViaAPI via = Via.getAPI(); - - private final List chunksToResend = new ArrayList<>(); - - public PartialChunkFixer() { - TinyProtocol.instance.addFilter(mapChunk, this::chunkFilter); - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { - synchronized (chunksToResend) { - for(ResendChunk chunk : chunksToResend) { - CraftbukkitWrapper.impl.sendChunk(chunk.player, chunk.x, chunk.z); - } - chunksToResend.clear(); - } - }, 1, 1); - } - - private Object chunkFilter(Player player, Object packet) { - if(via.getPlayerVersion(player) >= PROTOCOL1_17 && !fullChunkFlag.get(packet)) { - // partial chunk update - synchronized (chunksToResend) { - chunksToResend.add(new ResendChunk(player, chunkX.get(packet), chunkZ.get(packet))); - } - return null; - } - return packet; - } - - private static class ResendChunk { - private final Player player; - private final int x; - private final int z; - - private ResendChunk(Player player, int x, int z) { - this.player = player; - this.x = x; - this.z = z; - } - } -} diff --git a/SpigotCore/SpigotCore_Main/src/plugin.yml b/SpigotCore/SpigotCore_Main/src/plugin.yml index 75652668..a29249d2 100644 --- a/SpigotCore/SpigotCore_Main/src/plugin.yml +++ b/SpigotCore/SpigotCore_Main/src/plugin.yml @@ -4,7 +4,6 @@ author: Lixfel api-version: "1.13" load: STARTUP softdepend: - - ViaVersion - WorldEdit main: de.steamwar.core.Core diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java index 072f1467..d4290814 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java @@ -225,20 +225,16 @@ public class Subserver { if (line.contains("Loading libraries, please wait")) sendProgress(2); else if (line.contains("Starting Minecraft server on")) - sendProgress(4); + sendProgress(5); else if (line.contains("Preparing start region")) - sendProgress(6); - return line.contains("Finished mapping loading"); + sendProgress(8); + return line.contains("Done ("); }); } if (!started) return; - sendProgress(8); - - Thread.sleep(300); - sendProgress(10); for (Player cachedPlayer : cachedPlayers) { sendPlayer(cachedPlayer); diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 78603f8c..2029b3f4 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -47,6 +47,8 @@ java { dependencies { annotationProcessor(libs.velocityapi) compileOnly(libs.velocity) + compileOnly(libs.viaapi) + compileOnly(libs.viavelocity) compileOnly(project(":VelocityCore:Persistent", "default")) @@ -61,6 +63,5 @@ dependencies { } implementation(libs.msgpack) - implementation(libs.apolloprotos) } \ No newline at end of file diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index b133d99b..c018323c 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -728,6 +728,9 @@ MOD_ITEM_BACK=§7Back INV_PAGE_BACK=§{0}Seite zurück INV_PAGE_NEXT=§{0}Seite vor +#VersionAnnouncer +SERVER_VERSION=§7This server runs on Minecraft version §e{0} + #Discord DC_UNLINKED=For this action your Discord account has to be linked to your Minecraft account. To link your accounts go onto the SteamWar Discord to the `regeln-infos` Channel and click on `Minecraft Verknüpfen`. DC_TITLE_SCHEMINFO=Schematic Info diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index 9299064f..26d52987 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -681,6 +681,9 @@ ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten! INV_PAGE_BACK=§{0}Page back INV_PAGE_NEXT=§{0}Next page +#VersionAnnouncer +SERVER_VERSION=§7Dieser Server läuft auf Minecraft-Version §e{0} + #Discord DC_UNLINKED=Für diese Aktion muss dein Minecraftaccount mit deinem Discordaccount verknüpft sein, gehe dazu auf dem SteamWar-Discord in den `regeln-infos` Channel und Klicke auf `Minecraft Verknüpfen`. DC_TITLE_SCHEMINFO=Schematicinfo diff --git a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java index 8dab4d8d..74fb19bf 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java @@ -27,10 +27,13 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; +import java.util.regex.Pattern; @Getter public class GameModeConfig { + private static final Pattern terminatingNumber = Pattern.compile("\\D+(\\d+)$"); + public static void loadAll(Class config, BiConsumer consumer) { File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); if(!folder.exists()) @@ -51,9 +54,9 @@ public class GameModeConfig { @Getter public static class Server { private String Folder; - private String ServerJar; private List ChatNames = Collections.emptyList(); private List Maps; + private boolean Spigot = false; private boolean Ranked = false; private boolean Historic = false; } @@ -66,8 +69,8 @@ public class GameModeConfig { private boolean ManualCheck = true; } - public String getServerJar() { - return getServer().getServerJar(); + public ServerVersion getVersion() { + return ServerVersion.valueOf((getServer().isSpigot() ? "SPIGOT_" : "PAPER_") + terminatingNumber.matcher(getServer().getFolder()).group(1)); } public String getFolder() { diff --git a/VelocityCore/src/de/steamwar/velocitycore/Node.java b/VelocityCore/src/de/steamwar/velocitycore/Node.java index b97ef0ba..23cf808a 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/Node.java +++ b/VelocityCore/src/de/steamwar/velocitycore/Node.java @@ -63,7 +63,7 @@ public abstract class Node { nodes.forEach(consumer); } - public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams); + public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String... dParams); protected abstract ProcessBuilder prepareExecution(String... command); protected abstract void calcLoadLimit(); @@ -95,7 +95,7 @@ public abstract class Node { return hostname; } - protected void constructServerstart(File directory, List cmd, String serverJar, String worldDir, String levelName, int port, String xmx, String... dParams) { + protected void constructServerstart(File directory, List cmd, String serverJar, String worldDir, String levelName, int port, String... dParams) { if (JAVA_8.contains(serverJar)) cmd.add("/usr/lib/jvm/java-8-openj9-amd64/bin/java"); else @@ -105,7 +105,7 @@ public abstract class Node { cmd.add("-D" + param); } cmd.add("-Xshareclasses:nonfatal,name=" + directory.getName()); - cmd.add("-Xmx" + xmx); + cmd.add("-Xmx768M"); cmd.addAll(OPENJ9_ARGS); if (!JAVA_8.contains(serverJar)) { cmd.add("--add-opens"); @@ -142,9 +142,9 @@ public abstract class Node { } @Override - public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams) { + public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String... dParams) { List cmd = new ArrayList<>(); - constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, xmx, dParams); + constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, dParams); ProcessBuilder builder = new ProcessBuilder(cmd); builder.directory(directory); return builder; @@ -174,7 +174,7 @@ public abstract class Node { } @Override - public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams) { + public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String... dParams) { List cmd = new ArrayList<>(); cmd.add("ssh"); cmd.add("-L"); @@ -183,7 +183,7 @@ public abstract class Node { cmd.add("cd"); cmd.add(directory.getPath()); cmd.add(";"); - constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, xmx, dParams); + constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, dParams); return new ProcessBuilder(cmd); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index 1b834390..0fbdf696 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -20,6 +20,8 @@ package de.steamwar.velocitycore; import com.velocitypowered.api.proxy.Player; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; import de.steamwar.messages.Chatter; import de.steamwar.persistent.Arenaserver; import de.steamwar.persistent.Bauserver; @@ -56,8 +58,7 @@ public class ServerStarter { private String worldDir = null; private Node node = null; - private String serverJar = "spigot-1.15.2.jar"; - private String xmx = "768M"; + private ServerVersion version = ServerVersion.PAPER_20; private Portrange portrange = BAU_PORTS; private Function serverNameProvider = port -> node.getName() + port; private BooleanSupplier startCondition = () -> true; @@ -78,7 +79,7 @@ public class ServerStarter { public ServerStarter arena(ArenaMode mode, String map) { portrange = ARENA_PORTS; serverNameProvider = port -> mode.getGameName() + (port - portrange.start); - serverJar = mode.getServerJar(); + version = mode.getVersion(); allowMerge = true; fightMap = map; gameMode = mode.getInternalName(); @@ -145,8 +146,8 @@ public class ServerStarter { } public ServerStarter build(ServerVersion version, UUID owner) { + this.version = version; directory = version.getServerDirectory("Bau"); - serverJar = version.getServerJar(); worldDir = version.getWorldFolder(WORLDS_BASE_PATH); worldName = version != ServerVersion.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString(); checkpoint = true; @@ -219,7 +220,7 @@ public class ServerStarter { } public ServerStarter builder(ServerVersion version, String map, File generator) { - serverJar = version.getServerJar(); + this.version = version; directory = version.getServerDirectory("Builder"); worldDir = version.getWorldFolder(BUILDER_BASE_PATH); worldName = map; @@ -294,6 +295,7 @@ public class ServerStarter { if(checkpoint) arguments.put("checkpoint", checkpointDir.getPath()); + ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().put(serverName, version.getProtocolVersion().getProtocol()); if(checkpoint && checkpointDir.exists()) { try(DataOutputStream out = new DataOutputStream(Files.newOutputStream(new File(checkpointDir, "port").toPath()))) { out.writeInt(port); @@ -313,7 +315,7 @@ public class ServerStarter { private void regularStart(String serverName, int port) { postStart(constructor.construct(serverName, port, node.startServer( - serverJar, directory, worldDir, worldName, port, xmx, arguments.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).toArray(String[]::new) + version.getServerJar(), directory, worldDir, worldName, port, arguments.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).toArray(String[]::new) ), worldCleanup, null)); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index 31b8e39e..fd505e77 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -19,6 +19,8 @@ package de.steamwar.velocitycore; +import com.velocitypowered.api.network.ProtocolVersion; +import lombok.AllArgsConstructor; import lombok.Getter; import java.io.File; @@ -27,12 +29,23 @@ import java.util.Map; import java.util.Set; @Getter +@AllArgsConstructor public enum ServerVersion { - SPIGOT_12("spigot-1.12.2.jar", 12), - SPIGOT_15("spigot-1.15.2.jar", 15), - PAPER_19("paper-1.19.3.jar", 19), - PAPER_20("paper-1.20.1.jar", 20), - PAPER_21("paper-1.21.jar", 21); + SPIGOT_8("spigot-1.8.8.jar", 8, ProtocolVersion.MINECRAFT_1_8), + SPIGOT_9("spigot-1.9.4.jar", 9, ProtocolVersion.MINECRAFT_1_9), + SPIGOT_10("spigot-1.10.2.jar", 10, ProtocolVersion.MINECRAFT_1_10), + SPIGOT_12("spigot-1.12.2.jar", 12, ProtocolVersion.MINECRAFT_1_12_2), + SPIGOT_14("spigot-1.14.4.jar", 14, ProtocolVersion.MINECRAFT_1_14_4), + SPIGOT_15("spigot-1.15.2.jar", 15, ProtocolVersion.MINECRAFT_1_15_2), + + PAPER_8("paper-1.8.8.jar", 8, ProtocolVersion.MINECRAFT_1_8), + PAPER_10("paper-1.10.2.jar", 10, ProtocolVersion.MINECRAFT_1_10), + PAPER_12("paper-1.12.2.jar", 12, ProtocolVersion.MINECRAFT_1_12_2), + PAPER_15("paper-1.15.2.jar", 15, ProtocolVersion.MINECRAFT_1_15_2), + PAPER_18("paper-1.18.2.jar", 15, ProtocolVersion.MINECRAFT_1_18_2), + PAPER_19("paper-1.19.3.jar", 19, ProtocolVersion.MINECRAFT_1_19_3), + PAPER_20("paper-1.20.1.jar", 20, ProtocolVersion.MINECRAFT_1_20), + PAPER_21("paper-1.21.jar", 21, ProtocolVersion.MINECRAFT_1_21_2); private static final Map chatMap = new HashMap<>(); @@ -76,11 +89,7 @@ public enum ServerVersion { private final String serverJar; private final int versionSuffix; - - ServerVersion(String serverJar, int versionSuffix) { - this.serverJar = serverJar; - this.versionSuffix = versionSuffix; - } + private final ProtocolVersion protocolVersion; public String getWorldFolder(String base) { return base + versionSuffix + "/"; diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 6a5b3ade..5e6dca1d 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -152,6 +152,7 @@ public class VelocityCore implements ReloadablePlugin { new BanListener(); new CheckListener(); new IPSanitizer(); + new VersionAnnouncer(); local = new Node.LocalNode(); if(MAIN_SERVER) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java new file mode 100644 index 00000000..c28a8fee --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java @@ -0,0 +1,47 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.velocitycore.listeners; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.server.ServerInfo; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; +import de.steamwar.messages.Chatter; +import de.steamwar.persistent.Subserver; + +public class VersionAnnouncer extends BasicListener { + + @Subscribe + public void postConnect(ServerConnectedEvent e) { + ServerInfo server = e.getServer().getServerInfo(); + if(!Subserver.isBuild(Subserver.getSubserver(server))) + return; + + Player player = e.getPlayer(); + int serverVersion = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().get(server.getName()); + if(Via.getAPI().getPlayerVersion(player) == serverVersion) + return; + + player.sendActionBar(Chatter.of(player).parse("SERVER_VERSION", ProtocolVersion.getProtocolVersion(serverVersion).getMostRecentSupportedVersion())); + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index a29c0412..9389f289 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -116,7 +116,6 @@ dependencyResolutionManagement { library("authlib", "com.mojang:authlib:1.5.25") library("datafixer", "com.mojang:datafixerupper:4.0.26") library("brigadier", "com.mojang:brigadier:1.0.18") - library("viaapi", "com.viaversion:viaversion-api:4.3.1") library("anvilgui", "net.wesjd:anvilgui:1.10.3-SNAPSHOT") library("nms8", "de.steamwar:spigot:1.8") @@ -138,6 +137,8 @@ dependencyResolutionManagement { library("velocity", "de.steamwar:velocity:RELEASE") library("velocityapi", "com.velocitypowered:velocity-api:3.3.0-SNAPSHOT") + library("viaapi", "com.viaversion:viaversion-api:4.3.1") + library("viavelocity", "com.viaversion:viaversion-velocity:4.3.1") library("jda", "net.dv8tion:JDA:5.2.0") library("msgpack", "org.msgpack:msgpack-core:0.9.8") library("apolloprotos", "com.lunarclient:apollo-protos:1.0-SNAPSHOT") From 0f73939bf02f3a496194c6bc9115a5f4fafa713f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 26 Dec 2024 19:11:01 +0100 Subject: [PATCH 012/106] Move and rename Reflection fields --- .../bausystem/utils/NMSWrapper15.java | 22 +- .../utils/PlayerMovementWrapper15.java | 5 +- .../bausystem/utils/NMSWrapper18.java | 26 +- .../utils/PlayerMovementWrapper18.java | 3 +- .../bausystem/utils/NMSWrapper19.java | 27 +- .../utils/PlayerMovementWrapper19.java | 7 +- .../bausystem/utils/NMSWrapper20.java | 16 +- .../utils/PlayerMovementWrapper20.java | 8 +- .../bausystem/utils/NMSWrapper21.java | 8 +- .../features/observer/ObserverTracer.java | 2 +- .../features/simulator/SimulatorCursor.java | 2 +- .../smartplace/SmartPlaceListener.java | 2 +- .../features/tpslimit/PacketCache.java | 10 +- .../features/tpslimit/TPSFreezeUtils.java | 8 +- .../features/tpslimit/TPSLimitUtils.java | 5 +- .../features/util/NoClipCommand.java | 4 +- .../features/world/AntiCursorReCentering.java | 2 +- .../features/world/NoCreativeKnockback.java | 2 +- .../features/world/SignEditFrom20.java | 16 +- .../features/world/SignEditUntil19.java | 14 +- .../bausystem/features/xray/XrayCommand.java | 2 +- .../bausystem/utils/PlaceItemUtils.java | 8 +- .../utils/PlayerMovementWrapper.java | 5 +- .../bausystem/utils/WorldEditUtils.java | 4 +- .../fightsystem/utils/BlockIdWrapper14.java | 30 +- .../fightsystem/utils/BlockIdWrapper18.java | 4 +- .../utils/CraftbukkitWrapper18.java | 14 +- .../fightsystem/utils/HullHiderWrapper18.java | 4 +- .../fightsystem/utils/BlockIdWrapper8.java | 12 +- .../fightsystem/utils/HullHiderWrapper8.java | 6 +- .../fightsystem/utils/BountifulWrapper9.java | 4 +- .../de/steamwar/fightsystem/ai/AIManager.java | 2 +- .../fightsystem/commands/Commands.java | 4 +- .../de/steamwar/fightsystem/fight/Kit.java | 8 +- .../fightsystem/listener/ArrowStopper.java | 2 +- .../fightsystem/listener/ClickAnalyzer.java | 2 +- .../fightsystem/listener/Recording.java | 6 +- .../fightsystem/utils/BlockIdWrapper.java | 6 +- .../steamwar/fightsystem/utils/HullHider.java | 14 +- .../misslewars/slowmo/SlowMoUtils.java | 4 +- .../de/steamwar/core/FlatteningWrapper14.java | 18 +- .../src/de/steamwar/techhider/BlockIds14.java | 14 +- .../steamwar/techhider/ProtocolWrapper14.java | 6 +- .../steamwar/core/CraftbukkitWrapper18.java | 6 +- .../de/steamwar/core/ProtocolWrapper18.java | 10 +- .../de/steamwar/techhider/ChunkHider18.java | 18 +- .../steamwar/techhider/ProtocolWrapper18.java | 10 +- .../de/steamwar/core/ProtocolWrapper19.java | 10 +- .../steamwar/core/CraftbukkitWrapper20.java | 6 +- .../de/steamwar/core/BountifulWrapper21.java | 4 +- .../steamwar/core/CraftbukkitWrapper21.java | 6 +- .../de/steamwar/core/BountifulWrapper8.java | 25 +- .../src/de/steamwar/core/ChatWrapper8.java | 8 +- .../de/steamwar/core/FlatteningWrapper8.java | 16 +- .../de/steamwar/core/ProtocolWrapper8.java | 12 +- .../de/steamwar/scoreboard/SWScoreboard8.java | 18 +- .../de/steamwar/techhider/ChunkHider8.java | 2 +- .../steamwar/techhider/ProtocolWrapper8.java | 18 +- .../de/steamwar/core/BountifulWrapper9.java | 29 +- .../de/steamwar/core/CraftbukkitWrapper9.java | 6 +- .../de/steamwar/techhider/ChunkHider9.java | 14 +- .../comphenix/tinyprotocol/Reflection.java | 416 ------------------ .../comphenix/tinyprotocol/TinyProtocol.java | 15 +- .../src/de/steamwar/Reflection.java | 206 +++++++++ .../de/steamwar/core/CheckpointUtilsJ9.java | 6 +- .../src/de/steamwar/core/CommandRemover.java | 6 +- .../src/de/steamwar/core/Core.java | 5 +- .../src/de/steamwar/core/ErrorHandler.java | 4 +- .../de/steamwar/core/FlatteningWrapper.java | 2 +- .../src/de/steamwar/core/ProtocolWrapper.java | 4 +- .../src/de/steamwar/core/TPSWatcher.java | 6 +- .../core/authlib/AuthlibInjector.java | 4 +- .../de/steamwar/core/events/AntiNocom.java | 8 +- .../core/events/PartialChunkFixer.java | 8 +- .../src/de/steamwar/entity/REntity.java | 36 +- .../src/de/steamwar/entity/REntityServer.java | 8 +- .../src/de/steamwar/entity/RPlayer.java | 4 +- .../network/handlers/ServerDataHandler.java | 2 +- .../de/steamwar/techhider/ProtocolUtils.java | 2 +- .../src/de/steamwar/techhider/TechHider.java | 24 +- 80 files changed, 547 insertions(+), 805 deletions(-) delete mode 100644 SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java diff --git a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index 3b56be55..f279980d 100644 --- a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -19,27 +19,21 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; import net.minecraft.server.v1_15_R1.*; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; -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; public class NMSWrapper15 implements NMSWrapper { - private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + private static final Reflection.Field playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); @Override @SuppressWarnings("deprecation") @@ -63,7 +57,7 @@ public class NMSWrapper15 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0); @Override public void setGameStateChangeReason(Object packet) { @@ -121,11 +115,11 @@ public class NMSWrapper15 implements NMSWrapper { } 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); + private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.Field d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.Field e = Reflection.getField(explosionPacket, List.class, 0); @Override public Object resetExplosionKnockback(Object packet) { diff --git a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/PlayerMovementWrapper15.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/PlayerMovementWrapper15.java index 12f80cdb..f290f7dd 100644 --- a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/PlayerMovementWrapper15.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/PlayerMovementWrapper15.java @@ -19,12 +19,9 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.bausystem.utils.PlayerMovementWrapper; +import de.steamwar.Reflection; import net.minecraft.server.v1_15_R1.EntityPlayer; import net.minecraft.server.v1_15_R1.PacketPlayInFlying; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntity; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; diff --git a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index c12ce0af..22438d02 100644 --- a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -19,36 +19,26 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; -import net.minecraft.SystemUtils; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R2.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; public class NMSWrapper18 implements NMSWrapper { - private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + private static final Reflection.Field playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); @Override @SuppressWarnings("deprecation") @@ -73,7 +63,7 @@ public class NMSWrapper18 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); @Override public void setGameStateChangeReason(Object packet) { @@ -131,11 +121,11 @@ public class NMSWrapper18 implements NMSWrapper { } 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); + private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.Field d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.Field e = Reflection.getField(explosionPacket, List.class, 0); @Override public Object resetExplosionKnockback(Object packet) { diff --git a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/PlayerMovementWrapper18.java b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/PlayerMovementWrapper18.java index d1e186d2..0f1ba669 100644 --- a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/PlayerMovementWrapper18.java +++ b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/PlayerMovementWrapper18.java @@ -19,8 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.bausystem.utils.PlayerMovementWrapper; +import de.steamwar.Reflection; import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.server.level.EntityPlayer; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; diff --git a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index ecdc33be..2c5b2415 100644 --- a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -19,37 +19,26 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; -import net.minecraft.SystemUtils; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; -import net.minecraft.network.syncher.DataWatcher; import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R2.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; public class NMSWrapper19 implements NMSWrapper { - private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + private static final Reflection.Field playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); @Override @SuppressWarnings("deprecation") @@ -73,7 +62,7 @@ public class NMSWrapper19 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); @Override public void setGameStateChangeReason(Object packet) { @@ -131,11 +120,11 @@ public class NMSWrapper19 implements NMSWrapper { } 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); + private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.Field d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.Field e = Reflection.getField(explosionPacket, List.class, 0); @Override public Object resetExplosionKnockback(Object packet) { diff --git a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java index 9815023c..af152ea5 100644 --- a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java +++ b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java @@ -19,17 +19,12 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.server.level.EntityPlayer; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - public class PlayerMovementWrapper19 implements PlayerMovementWrapper { @Override diff --git a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java index 1cb81892..a6d0a8e5 100644 --- a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java +++ b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; @@ -40,7 +40,7 @@ import java.util.List; public class NMSWrapper20 implements NMSWrapper { - private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + private static final Reflection.Field playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); @Override @SuppressWarnings("deprecation") @@ -64,7 +64,7 @@ public class NMSWrapper20 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); @Override public void setGameStateChangeReason(Object packet) { @@ -122,11 +122,11 @@ public class NMSWrapper20 implements NMSWrapper { } 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); + private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.Field d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.Field e = Reflection.getField(explosionPacket, List.class, 0); @Override public Object resetExplosionKnockback(Object packet) { diff --git a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/PlayerMovementWrapper20.java b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/PlayerMovementWrapper20.java index 75701471..f7866a4a 100644 --- a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/PlayerMovementWrapper20.java +++ b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/PlayerMovementWrapper20.java @@ -19,18 +19,12 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.minecraft.network.protocol.game.PacketPlayInFlying; -import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport; import net.minecraft.server.level.EntityPlayer; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - public class PlayerMovementWrapper20 implements PlayerMovementWrapper { @Override diff --git a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java index 1c3ce035..e6308e43 100644 --- a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java +++ b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.NBTBase; @@ -45,7 +45,7 @@ import java.util.Optional; public class NMSWrapper21 implements NMSWrapper { - private static final Reflection.FieldAccessor playerInteractManager = Reflection.getField(EntityPlayer.class, null, PlayerInteractManager.class); + private static final Reflection.Field playerInteractManager = Reflection.getField(EntityPlayer.class, null, PlayerInteractManager.class); @Override public void setInternalGameMode(Player player, GameMode gameMode) { @@ -68,14 +68,14 @@ public class NMSWrapper21 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); @Override public void setGameStateChangeReason(Object packet) { gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d); } - private static final Reflection.FieldAccessor playerAbilities = Reflection.getField(EntityHuman.class, null, PlayerAbilities.class); + private static final Reflection.Field playerAbilities = Reflection.getField(EntityHuman.class, null, PlayerAbilities.class); @Override public void setPlayerBuildAbilities(Player player) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java index 9f641e65..75cecff5 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.observer; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.region.Point; import org.bukkit.Location; import org.bukkit.Material; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index a7664158..23261b62 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.simulator; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 10916beb..36cb3847 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.smartplace; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java index e9076382..fd8eb66b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.tpslimit; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.ChatWrapper; @@ -46,17 +46,17 @@ class PacketCache { private static BukkitTask task = null; private static Class vec3dClass = Reflection.getClass("{nms.world.phys}.Vec3D"); - private static Reflection.FieldAccessor zeroVec3d = (Reflection.FieldAccessor) Reflection.getField(vec3dClass, vec3dClass, 0); + private static Reflection.Field zeroVec3d = (Reflection.Field) Reflection.getField(vec3dClass, vec3dClass, 0); private static Object ZERO_VEC3D = zeroVec3d.get(null); private static Class velocityPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); - private static Reflection.ConstructorInvoker velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass); + private static Reflection.Constructor velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass); private static Class teleportPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); private static Class entityClass = Reflection.getClass("{nms.world.entity}.Entity"); - private static Reflection.ConstructorInvoker teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass); + private static Reflection.Constructor teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass); private static Class craftEntityClass = Reflection.getClass("{obc}.entity.CraftEntity"); - private static Reflection.MethodInvoker getHandle = Reflection.getMethod(craftEntityClass, "getHandle"); + private static Reflection.Method getHandle = Reflection.getMethod(craftEntityClass, "getHandle"); private static Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5, Boolean.class); private static Object fuseDataWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java index 34981161..45b6154f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.tpslimit; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import lombok.Getter; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; @@ -28,11 +28,11 @@ import org.bukkit.World; @UtilityClass public class TPSFreezeUtils { - private static Reflection.FieldAccessor fieldAccessor; + private static Reflection.Field fieldAccessor; @Getter private static final boolean canFreeze; - private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); @Getter private static boolean frozen = false; @@ -40,7 +40,7 @@ public class TPSFreezeUtils { private static final World world = Bukkit.getWorlds().get(0); static { - Reflection.FieldAccessor fieldAccessor; + Reflection.Field fieldAccessor; try { fieldAccessor = Reflection.getField(Reflection.getClass("{nms.server.level}.WorldServer"), "freezed", boolean.class); } catch (IllegalArgumentException e) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java index cdc38f2d..83b8e104 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java @@ -19,15 +19,12 @@ package de.steamwar.bausystem.features.tpslimit; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.utils.PlayerMovementWrapper; import de.steamwar.core.Core; -import de.steamwar.core.TPSWatcher; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index 867ad83d..565286a1 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.util; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import com.mojang.authlib.GameProfile; import de.steamwar.bausystem.BauSystem; @@ -50,7 +50,7 @@ import java.util.function.BiFunction; public class NoClipCommand extends SWCommand implements Listener { public static final Class gameStateChange = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutGameStateChange"); - private static final Reflection.FieldAccessor floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); + private static final Reflection.Field floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); private static final Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); private static final Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java index ff04aa5f..646120d3 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.world; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.linkage.Linked; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java index 19417ec2..72146f9d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.world; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.linkage.Linked; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java index 1ccfb014..4fc0cb31 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.world; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; @@ -52,17 +52,17 @@ public class SignEditFrom20 implements Listener { private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlock"); private static final Class craftWorld = Reflection.getClass("{obc}.CraftWorld"); private static final Class generatorAccess = Reflection.getClass("{nms.world.level}.GeneratorAccess"); - private static final Reflection.MethodInvoker getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); - private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); - private static final Reflection.MethodInvoker at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); + private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); + private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); private static final Class openSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenSignEditor"); - private static final Reflection.FieldAccessor blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); - private static final Reflection.FieldAccessor sideFieldAccessor = Reflection.getField(openSign, boolean.class, 0); + private static final Reflection.Field blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); + private static final Reflection.Field sideFieldAccessor = Reflection.getField(openSign, boolean.class, 0); private static final Class updateSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUpdateSign"); - private static final Reflection.FieldAccessor getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); - private static final Reflection.FieldAccessor stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); + private static final Reflection.Field getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); + private static final Reflection.Field stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); @EventHandler public void editSign(PlayerInteractEvent event) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java index 7aebd4e9..81cf2786 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.world; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; @@ -44,16 +44,16 @@ public class SignEditUntil19 implements Listener { private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlock"); private static final Class craftWorld = Reflection.getClass("{obc}.CraftWorld"); private static final Class generatorAccess = Reflection.getClass("{nms.world.level}.GeneratorAccess"); - private static final Reflection.MethodInvoker getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); - private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); - private static final Reflection.MethodInvoker at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); + private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); + private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); private static final Class openSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenSignEditor"); - private static final Reflection.FieldAccessor blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); + private static final Reflection.Field blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); private static final Class updateSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUpdateSign"); - private static final Reflection.FieldAccessor getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); - private static final Reflection.FieldAccessor stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); + private static final Reflection.Field getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); + private static final Reflection.Field stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); @EventHandler public void editSign(PlayerInteractEvent event) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 59e88ec5..da7981ae 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.xray; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.techhider.TechHiderCommand; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java index bec908a6..e235cae4 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.experimental.UtilityClass; @@ -82,11 +82,11 @@ public class PlaceItemUtils { } private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Reflection.ConstructorInvoker blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); + private static final Reflection.Constructor blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlockState"); private static final Class craftWorld = Reflection.getClass("{obc}.CraftWorld"); - private static final Reflection.FieldAccessor positionAccessor = Reflection.getField(craftBlock, blockPosition, 0); - private static final Reflection.FieldAccessor worldAccessor = Reflection.getField(craftBlock, craftWorld, 0); + private static final Reflection.Field positionAccessor = Reflection.getField(craftBlock, blockPosition, 0); + private static final Reflection.Field worldAccessor = Reflection.getField(craftBlock, craftWorld, 0); /** * Attempt to place an {@link ItemStack} the {@link Player} is holding against a {@link Block} inside the World. diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java index 15aea7f0..b0cebfdd 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java @@ -19,17 +19,16 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.BauSystem; import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.Core; import de.steamwar.core.VersionDependent; import de.steamwar.entity.REntity; import org.bukkit.entity.Player; public interface PlayerMovementWrapper { Class teleportPacket = REntity.teleportPacket; - Reflection.FieldAccessor teleportEntity = REntity.teleportEntity; + Reflection.Field teleportEntity = REntity.teleportEntity; BountifulWrapper.PositionSetter teleportPosition = REntity.teleportPosition; PlayerMovementWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java index 4d20f346..3fef4e48 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; @@ -100,7 +100,7 @@ public class WorldEditUtils { .getSessionManager() .get(BukkitAdapter.adapt(player)); - Reflection.ConstructorInvoker constructorInvoker = Reflection.getConstructor(clazz, com.sk89q.worldedit.world.World.class); + Reflection.Constructor constructorInvoker = Reflection.getConstructor(clazz, com.sk89q.worldedit.world.World.class); RegionSelector regionSelector = (RegionSelector) constructorInvoker.invoke(BukkitAdapter.adapt(player.getWorld())); localSession.setRegionSelector(BukkitAdapter.adapt(player.getWorld()), regionSelector); diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index 5030cb04..84eba7c4 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; @@ -34,10 +34,10 @@ import java.util.Map; public class BlockIdWrapper14 implements BlockIdWrapper { private static final Class chunkProviderServer = Reflection.getClass("{nms.server.level}.ChunkProviderServer"); - private static final Reflection.MethodInvoker getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); + private static final Reflection.Method getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); private static final Class playerChunkMap = Reflection.getClass("{nms.server.level}.PlayerChunkMap"); - private static final Reflection.FieldAccessor getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0); - private static final Reflection.FieldAccessor entityTrackers = Core.getVersion() > 15 ? Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0) : Reflection.getField(playerChunkMap, org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap.class, 0); + private static final Reflection.Field getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0); + private static final Reflection.Field entityTrackers = Core.getVersion() > 15 ? Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0) : Reflection.getField(playerChunkMap, org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap.class, 0); private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); private static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); @@ -47,18 +47,18 @@ public class BlockIdWrapper14 implements BlockIdWrapper { trackers = entityTrackers.get(getPlayerChunkMap.get(getChunkProvider.invoke(getWorldHandle.invoke(Config.world)))); } - private static final Reflection.MethodInvoker getCombinedId = Reflection.getTypedMethod(block, null, int.class, iBlockData); - private static final Reflection.MethodInvoker getNMS = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.CraftBlock"), "getNMS", iBlockData); + private static final Reflection.Method getCombinedId = Reflection.getTypedMethod(block, null, int.class, iBlockData); + private static final Reflection.Method getNMS = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.CraftBlock"), "getNMS", iBlockData); @Override public int blockToId(Block block) { return (int) getCombinedId.invoke(null, getNMS.invoke(block)); } - private static final Reflection.MethodInvoker getByCombinedId = Reflection.getTypedMethod(block, null, iBlockData, int.class); - private static final Reflection.ConstructorInvoker newBlockPosition = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); - private static final Reflection.MethodInvoker getTypeAndData = Reflection.getMethod(worldServer, null, blockPosition, iBlockData, int.class); - private static final Reflection.MethodInvoker removeTileEntity = Reflection.getMethod(worldServer, Core.getVersion() > 15 ? "m" : "removeTileEntity", blockPosition); - private static final Reflection.MethodInvoker flagDirty = Reflection.getMethod(chunkProviderServer, null, blockPosition); + private static final Reflection.Method getByCombinedId = Reflection.getTypedMethod(block, null, iBlockData, int.class); + private static final Reflection.Constructor newBlockPosition = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); + private static final Reflection.Method getTypeAndData = Reflection.getMethod(worldServer, null, blockPosition, iBlockData, int.class); + private static final Reflection.Method removeTileEntity = Reflection.getMethod(worldServer, Core.getVersion() > 15 ? "m" : "removeTileEntity", blockPosition); + private static final Reflection.Method flagDirty = Reflection.getMethod(chunkProviderServer, null, blockPosition); @Override public void setBlock(World world, int x, int y, int z, int blockState) { Object blockData = getByCombinedId.invoke(null, blockState); @@ -71,7 +71,7 @@ public class BlockIdWrapper14 implements BlockIdWrapper { } private static final Class entityTracker = Reflection.getClass("{nms.server.level}.PlayerChunkMap$EntityTracker"); - private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer); + private static final Reflection.Method updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, Entity entity) { Object tracker = trackers.get(entity.getEntityId()); @@ -79,7 +79,7 @@ public class BlockIdWrapper14 implements BlockIdWrapper { updatePlayer.invoke(tracker, getPlayer.invoke(player)); } - private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "a" : "clear", entityPlayer); + private static final Reflection.Method clearPlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "a" : "clear", entityPlayer); @Override public void untrackEntity(Player player, Entity entity) { Object tracker = trackers.get(entity.getEntityId()); @@ -87,8 +87,8 @@ public class BlockIdWrapper14 implements BlockIdWrapper { clearPlayer.invoke(tracker, getPlayer.invoke(player)); } - private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("{obc}.util.CraftMagicNumbers"), "getMaterial", Material.class, block); - private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); + private static final Reflection.Method getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("{obc}.util.CraftMagicNumbers"), "getMaterial", Material.class, block); + private static final Reflection.Method getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); @Override public Material idToMaterial(int blockState) { return (Material)getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(getByCombinedId.invoke(null, blockState))); diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java index c229353a..682fc30f 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -27,7 +27,7 @@ import java.util.*; public class BlockIdWrapper18 extends BlockIdWrapper14 { - private static final Reflection.FieldAccessor hiddenEntities = Reflection.getField(Reflection.getClass("{obc}.entity.CraftPlayer"), Map.class, 0, UUID.class, Set.class); + private static final Reflection.Field hiddenEntities = Reflection.getField(Reflection.getClass("{obc}.entity.CraftPlayer"), Map.class, 0, UUID.class, Set.class); @Override public void trackEntity(Player player, Entity entity) { hiddenEntities.get(player).remove(entity.getUniqueId()); diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java index 72c14f8f..31c17cf1 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.chunk.Chunk; @@ -33,9 +33,9 @@ import java.util.stream.StreamSupport; public class CraftbukkitWrapper18 implements CraftbukkitWrapper { - private static final Reflection.MethodInvoker getWorld = Reflection.getMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle"); - private static final Reflection.MethodInvoker getChunk = Reflection.getTypedMethod(net.minecraft.world.level.World.class, null, Chunk.class, int.class, int.class); - private static final Reflection.MethodInvoker getChunkSections = Reflection.getTypedMethod(Chunk.class, null, ChunkSection[].class); + private static final Reflection.Method getWorld = Reflection.getMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle"); + private static final Reflection.Method getChunk = Reflection.getTypedMethod(net.minecraft.world.level.World.class, null, Chunk.class, int.class, int.class); + private static final Reflection.Method getChunkSections = Reflection.getTypedMethod(Chunk.class, null, ChunkSection[].class); private ChunkSection[] getChunkSections(World world, int x, int z) { return (ChunkSection[]) getChunkSections.invoke(getChunk.invoke(getWorld.invoke(world), x, z)); } @@ -46,7 +46,7 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper { System.arraycopy(getChunkSections(backup, x, z), 0, sections, 0, sections.length); } - private static final Reflection.MethodInvoker getEntity = Reflection.getTypedMethod(Reflection.getClass("{obc}.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class); + private static final Reflection.Method getEntity = Reflection.getTypedMethod(Reflection.getClass("{obc}.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class); protected net.minecraft.world.entity.Entity getEntity(Entity e) { return (net.minecraft.world.entity.Entity) getEntity.invoke(e); } @@ -56,8 +56,8 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper { return getEntity(e).ce(); } - private static final Reflection.MethodInvoker getWorldEntities = Reflection.getTypedMethod(WorldServer.class, null, LevelEntityGetter.class); - private static final Reflection.MethodInvoker getIterable = Reflection.getTypedMethod(LevelEntityGetter.class, null, Iterable.class); + private static final Reflection.Method getWorldEntities = Reflection.getTypedMethod(WorldServer.class, null, LevelEntityGetter.class); + private static final Reflection.Method getIterable = Reflection.getTypedMethod(LevelEntityGetter.class, null, Iterable.class); @Override public Stream entityIterator() { return StreamSupport.stream(((Iterable) getIterable.invoke(getWorldEntities.invoke(getWorld.invoke(Config.world)))).spliterator(), false); diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java index af5f83a1..7a378f43 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap; import net.minecraft.core.BlockPosition; @@ -33,7 +33,7 @@ import java.util.List; public class HullHiderWrapper18 implements HullHiderWrapper { - private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", IBlockData.class); + private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", IBlockData.class); @Override public Object generateBlockChangePacket(List changes) { Object[] blockdata = new Object[changes.size()]; diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index 402f8e60..94633486 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import org.bukkit.Material; import org.bukkit.World; @@ -30,9 +30,9 @@ import org.bukkit.entity.Player; public class BlockIdWrapper8 implements BlockIdWrapper { private static final Class entityTracker = Reflection.getClass("{nms}.EntityTracker"); - private static final Reflection.FieldAccessor getEntityTracker = Reflection.getField(worldServer, entityTracker, 0); + private static final Reflection.Field getEntityTracker = Reflection.getField(worldServer, entityTracker, 0); private static final Class intHashMap = Reflection.getClass("{nms}.IntHashMap"); - private static final Reflection.FieldAccessor getTrackedEntities = Reflection.getField(entityTracker, intHashMap, 0); + private static final Reflection.Field getTrackedEntities = Reflection.getField(entityTracker, intHashMap, 0); private final Object trackers; public BlockIdWrapper8() { @@ -55,8 +55,8 @@ public class BlockIdWrapper8 implements BlockIdWrapper { } private static final Class entityTrackerEntry = Reflection.getClass("{nms}.EntityTrackerEntry"); - private static final Reflection.MethodInvoker get = Reflection.getTypedMethod(intHashMap, "get", Object.class, int.class); - private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTrackerEntry, "updatePlayer", entityPlayer); + private static final Reflection.Method get = Reflection.getTypedMethod(intHashMap, "get", Object.class, int.class); + private static final Reflection.Method updatePlayer = Reflection.getMethod(entityTrackerEntry, "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, Entity entity) { Object tracker = get.invoke(trackers, entity.getEntityId()); @@ -64,7 +64,7 @@ public class BlockIdWrapper8 implements BlockIdWrapper { updatePlayer.invoke(tracker, getPlayer.invoke(player)); } - private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTrackerEntry, "a", entityPlayer); + private static final Reflection.Method clearPlayer = Reflection.getMethod(entityTrackerEntry, "a", entityPlayer); @Override public void untrackEntity(Player player, Entity entity) { Object tracker = get.invoke(trackers, entity.getEntityId()); diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java index af56e404..231a8d0a 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java @@ -19,15 +19,15 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import java.util.List; public class HullHiderWrapper8 implements HullHiderWrapper { - private static final Reflection.ConstructorInvoker newMultiBlockChange = Reflection.getConstructor("{nms}.PacketPlayOutMultiBlockChange", int.class, short[].class, Reflection.getClass("{nms}.Chunk")); - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + private static final Reflection.Constructor newMultiBlockChange = Reflection.getConstructor("{nms}.PacketPlayOutMultiBlockChange", int.class, short[].class, Reflection.getClass("{nms}.Chunk")); + private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); @Override public Object generateBlockChangePacket(List changes) { Hull.IntVector chunk = changes.get(0); diff --git a/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index 96cc9436..67ac4f21 100644 --- a/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.listener.Recording; @@ -45,7 +45,7 @@ public class BountifulWrapper9 implements BountifulWrapper { private static final Class enumHand = Reflection.getClass("{nms.world}.EnumHand"); private static final Object mainHand = enumHand.getEnumConstants()[0]; - private static final Reflection.FieldAccessor blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); + private static final Reflection.Field blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); @Override public boolean mainHand(Object packet) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java index 2cb13f65..3950a201 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.ai; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.FightTeam; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java index b880fa6d..90bca61b 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.commands; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; @@ -39,7 +39,7 @@ import org.bukkit.entity.Player; @UtilityClass public class Commands { - private static final Reflection.FieldAccessor commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); + private static final Reflection.Field commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); public static void injectCommand(Command cmd) { commandMap.get(Bukkit.getServer()).register("FightSystem", cmd); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index e3829099..08853b65 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.fight; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.commands.Commands; @@ -216,10 +216,10 @@ public class Kit { } private static final Class itemStack = Reflection.getClass("{nms.world.item}.ItemStack"); - private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class); + private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class); private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); - private static final Reflection.MethodInvoker getTag = Reflection.getTypedMethod(itemStack, null, nbtTagCompound); - private static final Reflection.MethodInvoker getKeys = Reflection.getTypedMethod(nbtTagCompound, null, Set.class); + private static final Reflection.Method getTag = Reflection.getTypedMethod(itemStack, null, nbtTagCompound); + private static final Reflection.Method getKeys = Reflection.getTypedMethod(nbtTagCompound, null, Set.class); public static boolean hasItems(ItemStack stack) { Set keys = new HashSet<>((Set) getKeys.invoke(getTag.invoke(asNMSCopy.invoke(null, stack)))); keys.remove("Enchantments"); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 3fd7f7dc..18bc11ac 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.listener; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java index 73e2afa9..4ceed83c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.listener; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index b4040b74..31b26c5e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.listener; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.TrickyTrialsWrapper; import de.steamwar.fightsystem.ArenaMode; @@ -78,7 +78,7 @@ public class Recording implements Listener { } public static final Class primedTnt = Reflection.getClass("{nms.world.entity.item}.EntityTNTPrimed"); - private static final Reflection.MethodInvoker getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("{nms.world.entity}.Entity"), "getBukkitEntity", null); + private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("{nms.world.entity}.Entity"), "getBukkitEntity", null); public static void iterateOverEntities(Predicate filter, Consumer consumer) { CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer); } @@ -131,7 +131,7 @@ public class Recording implements Listener { private static final Class blockDigPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); private static final Class playerDigType = blockDigPacket.getDeclaredClasses()[0]; - private static final Reflection.FieldAccessor blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0); + private static final Reflection.Field blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0); private static final Object releaseUseItem = playerDigType.getEnumConstants()[5]; private Object blockDig(Player p, Object packet) { if(!isNotSent(p) && blockDigType.get(packet) == releaseUseItem) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index 354ff9fd..15d1b0f7 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.VersionDependent; import de.steamwar.fightsystem.FightSystem; import org.bukkit.Material; @@ -30,11 +30,11 @@ import org.bukkit.entity.Player; public interface BlockIdWrapper { Class worldServer = Reflection.getClass("{nms.server.level}.WorldServer"); - Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", worldServer); + Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", worldServer); Class craftPlayer = Reflection.getClass("{obc}.entity.CraftPlayer"); Class entityPlayer = Reflection.getClass("{nms.server.level}.EntityPlayer"); - Reflection.MethodInvoker getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); + Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); BlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index c613a4ab..64ec3064 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.entity.REntity; @@ -199,15 +199,15 @@ public class HullHider implements Listener { private static final Class packetPlayOutWorldEvent = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutWorldEvent"); - private static final Reflection.FieldAccessor worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0); - public static final Reflection.FieldAccessor blockPositionY = Reflection.getField("{nms.core}.BaseBlockPosition", int.class, 1); + private static final Reflection.Field worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0); + public static final Reflection.Field blockPositionY = Reflection.getField("{nms.core}.BaseBlockPosition", int.class, 1); private Object worldEventHider(Player player, Object packet) { Object baseBlock = worldEventPosition.get(packet); return packetHider(player, packet, new Location(Config.world, TechHider.blockPositionX.get(baseBlock), blockPositionY.get(baseBlock), TechHider.blockPositionZ.get(baseBlock))); } private static final Class packetPlayOutExplosion = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); - private static final Reflection.FieldAccessor explosionBlocks = Reflection.getField(packetPlayOutExplosion, List.class, 0); + private static final Reflection.Field explosionBlocks = Reflection.getField(packetPlayOutExplosion, List.class, 0); private static final Function explosionLocation = posPacketToLocation(packetPlayOutExplosion, double.class, 1.0); private Object explosionHider(Player player, Object packet) { if(explosionBlocks.get(packet).isEmpty()) @@ -223,9 +223,9 @@ public class HullHider implements Listener { } private static Function posPacketToLocation(Class type, Class posType, double factor) { - Reflection.FieldAccessor x = Reflection.getField(type, posType, 0); - Reflection.FieldAccessor y = Reflection.getField(type, posType, 1); - Reflection.FieldAccessor z = Reflection.getField(type, posType, 2); + Reflection.Field x = Reflection.getField(type, posType, 0); + Reflection.Field y = Reflection.getField(type, posType, 1); + Reflection.Field z = Reflection.getField(type, posType, 2); return packet -> new Location(Config.world, x.get(packet).doubleValue()/factor, y.get(packet).doubleValue()/factor, z.get(packet).doubleValue()/factor); } diff --git a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java index dbde1f0f..457ae789 100644 --- a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java +++ b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java @@ -21,7 +21,7 @@ package de.steamwar.misslewars.slowmo; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Bukkit; import org.bukkit.World; @@ -32,7 +32,7 @@ public class SlowMoUtils { private static final Field field; public static final boolean freezeEnabled; - private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); private static boolean frozen = false; private static final World world; diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index b7a9bf7f..a1fac854 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -226,14 +226,14 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT); } - private static final Reflection.FieldAccessor scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("{nms.network.chat}.IChatBaseComponent"), 0); + private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("{nms.network.chat}.IChatBaseComponent"), 0); @Override public void setScoreboardTitle(Object packet, String title) { scoreboardName.set(packet, ChatWrapper.impl.stringToChatComponent(title)); } private static final Class scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("{nms.server}.ScoreboardServer$Action") : null; - private static final Reflection.FieldAccessor scoreAction = Core.getVersion() < 21 ? Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0) : null; + private static final Reflection.Field scoreAction = Core.getVersion() < 21 ? Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0) : null; private static final Object scoreActionChange = Core.getVersion() < 21 ? scoreActionEnum.getEnumConstants()[0] : null; @Override @@ -330,10 +330,10 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper private static final Class registryBlocks = Reflection.getClass("{nms.core}.RegistryBlocks"); private static final Class entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass(Core.getVersion() > 18 ? "net.minecraft.core.registries.BuiltInRegistries" : "{nms.core}.IRegistry"), registryBlocks, 0, entityTypes).get(null); - private static final Reflection.MethodInvoker get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("{nms.resources}.MinecraftKey")); - private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); - private static final Reflection.FieldAccessor spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); - private static final Reflection.MethodInvoker toMinecraft = Reflection.getMethod("{obc}.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); + private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("{nms.resources}.MinecraftKey")); + private static final Reflection.Field spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); + private static final Reflection.Field spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); + private static final Reflection.Method toMinecraft = Reflection.getMethod("{obc}.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); private static final Map types = new HashMap<>(); static { types.put(EntityType.ARMOR_STAND, 1); @@ -352,8 +352,8 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return player.getClientViewDistance(); } - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftWorld", "getHandle"); - private static final Reflection.MethodInvoker save = Reflection.getMethod("{nms.server.level}.WorldServer", null, Reflection.getClass("{nms.util}.IProgressUpdate"), boolean.class, boolean.class); + private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftWorld", "getHandle"); + private static final Reflection.Method save = Reflection.getMethod("{nms.server.level}.WorldServer", null, Reflection.getClass("{nms.util}.IProgressUpdate"), boolean.class, boolean.class); @Override public void syncSave(World world) { save.invoke(getHandle.invoke(world), null, true, false); diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java index 322ce206..102ab31a 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.google.common.collect.ImmutableList; import org.bukkit.Material; @@ -32,17 +32,17 @@ public class BlockIds14 implements BlockIds { private static final Class fluidTypeFlowing = Reflection.getClass("{nms.world.level.material}.FluidTypeFlowing"); private static final Class fluid = Reflection.getClass("{nms.world.level.material}.Fluid"); - private static final Reflection.MethodInvoker getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); + private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); @Override public int materialToId(Material material) { return getCombinedId(getBlockData.invoke(getBlock(material))); } - private static final Reflection.MethodInvoker getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); - private static final Reflection.MethodInvoker getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); + private static final Reflection.Method getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); + private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("{nms.world.level.material}.FluidTypes"), fluidTypeFlowing, 1).get(null), false); private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, Reflection.getClass("{nms.core}.RegistryBlockID"), 0).get(null); - private static final Reflection.MethodInvoker getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); + private static final Reflection.Method getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); @Override public Set materialToAllIds(Material material) { Set ids = new HashSet<>(); @@ -61,12 +61,12 @@ public class BlockIds14 implements BlockIds { return ids; } - private static final Reflection.MethodInvoker getBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getBlock", TechHider.block, Material.class); + private static final Reflection.Method getBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getBlock", TechHider.block, Material.class); private Object getBlock(Material material) { return getBlock.invoke(null, material); } - private static final Reflection.MethodInvoker getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); + private static final Reflection.Method getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); private int getCombinedId(Object blockData) { return (int) getCombinedId.invoke(null, blockData); } diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java index ea98d273..7c658dbd 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.entity.Player; import java.util.function.BiFunction; @@ -30,8 +30,8 @@ public class ProtocolWrapper14 extends ProtocolWrapper8 { @Override public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, TechHider techHider) { UnaryOperator blockBreakCloner = ProtocolUtils.shallowCloneGenerator(blockBreakPacket); - Reflection.FieldAccessor blockBreakPosition = Reflection.getField(blockBreakPacket, TechHider.blockPosition, 0); - Reflection.FieldAccessor blockBreakBlockData = Reflection.getField(blockBreakPacket, TechHider.iBlockData, 0); + Reflection.Field blockBreakPosition = Reflection.getField(blockBreakPacket, TechHider.blockPosition, 0); + Reflection.Field blockBreakBlockData = Reflection.getField(blockBreakPacket, TechHider.iBlockData, 0); return (p, packet) -> { switch (techHider.getLocationEvaluator().checkBlockPos(p, blockBreakPosition.get(packet))) { diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java index 1627791c..0f6e9d62 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.world.level.World; @@ -29,8 +29,8 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); - private static final Reflection.MethodInvoker getLightEngine = Reflection.getTypedMethod(World.class, null, LightEngine.class); + private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LightEngine.class); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java index 54cc3030..98ae4bab 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; import org.bukkit.GameMode; @@ -30,7 +30,7 @@ import java.util.List; public class ProtocolWrapper18 implements ProtocolWrapper { - private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(equipmentPacket, List.class, 0); + private static final Reflection.Field equipmentStack = Reflection.getField(equipmentPacket, List.class, 0); @Override public void setEquipmentPacketStack(Object packet, Object slot, Object stack) { equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); @@ -38,8 +38,8 @@ public class ProtocolWrapper18 implements ProtocolWrapper { private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); - private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); - private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); + private static final Reflection.Field playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); + private static final Reflection.Field playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); private static final EnumMap actions = new EnumMap<>(PlayerInfoAction.class); static { Object[] nativeActions = playerInfoActionClass.getEnumConstants(); @@ -48,7 +48,7 @@ public class ProtocolWrapper18 implements ProtocolWrapper { actions.put(PlayerInfoAction.REMOVE, nativeActions[4]); } private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override @SuppressWarnings("deprecation") diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java index 16cecb9b..4478a02b 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.Core; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -46,12 +46,12 @@ public class ChunkHider18 implements ChunkHider { private static final UnaryOperator chunkPacketCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkWithLightPacket.class); private static final UnaryOperator chunkDataCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkPacketData.class); - private static final Reflection.FieldAccessor chunkXField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 0); - private static final Reflection.FieldAccessor chunkZField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 1); - private static final Reflection.FieldAccessor chunkData = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, ClientboundLevelChunkPacketData.class, 0); + private static final Reflection.Field chunkXField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 0); + private static final Reflection.Field chunkZField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 1); + private static final Reflection.Field chunkData = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, ClientboundLevelChunkPacketData.class, 0); - private static final Reflection.FieldAccessor dataField = Reflection.getField(ClientboundLevelChunkPacketData.class, byte[].class, 0); - private static final Reflection.FieldAccessor tileEntities = Reflection.getField(ClientboundLevelChunkPacketData.class, List.class, 0); + private static final Reflection.Field dataField = Reflection.getField(ClientboundLevelChunkPacketData.class, byte[].class, 0); + private static final Reflection.Field tileEntities = Reflection.getField(ClientboundLevelChunkPacketData.class, List.class, 0); @Override public BiFunction chunkHiderGenerator(TechHider techHider) { @@ -88,10 +88,10 @@ public class ChunkHider18 implements ChunkHider { } public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); - protected static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); + protected static final Reflection.Field entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); private static final IRegistry tileEntityTypes = Reflection.getField(Core.getVersion() > 18 ? Reflection.getClass("net.minecraft.core.registries.BuiltInRegistries") : IRegistry.class, IRegistry.class, 0, TileEntityTypes.class).get(null); - private static final Reflection.MethodInvoker getKey = Reflection.getTypedMethod(IRegistry.class, null, MinecraftKey.class, Object.class); - private static final Reflection.MethodInvoker getName = Reflection.getTypedMethod(MinecraftKey.class, null, String.class); + private static final Reflection.Method getKey = Reflection.getTypedMethod(IRegistry.class, null, MinecraftKey.class, Object.class); + private static final Reflection.Method getName = Reflection.getTypedMethod(MinecraftKey.class, null, String.class); protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { return !hiddenBlockEntities.contains((String) getName.invoke(getKey.invoke(tileEntityTypes, entityType.get(tile)))); } diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java index 9fef09fd..1553806a 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.minecraft.core.SectionPosition; import net.minecraft.network.protocol.game.PacketPlayOutBlockBreak; import net.minecraft.world.level.block.entity.TileEntitySign; @@ -32,9 +32,9 @@ import java.util.function.BiFunction; public class ProtocolWrapper18 implements ProtocolWrapper { - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); - private static final Reflection.FieldAccessor multiBlockChangePos = Reflection.getField(TechHider.multiBlockChangePacket, short[].class, 0); - private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); + private static final Reflection.Field multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); + private static final Reflection.Field multiBlockChangePos = Reflection.getField(TechHider.multiBlockChangePacket, short[].class, 0); + private static final Reflection.Field multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); @Override public BiFunction multiBlockChangeGenerator(TechHider techHider) { return (p, packet) -> { @@ -81,7 +81,7 @@ public class ProtocolWrapper18 implements ProtocolWrapper { }; } - private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); + private static final Reflection.Field tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); private static final TileEntityTypes signType = Reflection.getField(TileEntityTypes.class, TileEntityTypes.class, 0, TileEntitySign.class).get(null); @Override public boolean unfilteredTileEntityDataAction(Object packet) { diff --git a/SpigotCore/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java b/SpigotCore/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java index f4f399f3..f796dcdd 100644 --- a/SpigotCore/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java +++ b/SpigotCore/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; import net.minecraft.SystemUtils; @@ -35,15 +35,15 @@ import java.util.function.LongSupplier; public class ProtocolWrapper19 implements ProtocolWrapper { - private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(equipmentPacket, List.class, 0); + private static final Reflection.Field equipmentStack = Reflection.getField(equipmentPacket, List.class, 0); @Override public void setEquipmentPacketStack(Object packet, Object slot, Object stack) { equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); } - private static final Reflection.ConstructorInvoker removePacketConstructor = Reflection.getConstructor(ClientboundPlayerInfoRemovePacket.class, List.class); - private static final Reflection.FieldAccessor updateActions = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, EnumSet.class, 0); - private static final Reflection.FieldAccessor updatePlayers = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, List.class, 0); + private static final Reflection.Constructor removePacketConstructor = Reflection.getConstructor(ClientboundPlayerInfoRemovePacket.class, List.class); + private static final Reflection.Field updateActions = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, EnumSet.class, 0); + private static final Reflection.Field updatePlayers = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, List.class, 0); @Override @SuppressWarnings("deprecation") diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java index 68963457..9d0490f5 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.world.level.World; @@ -30,8 +30,8 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper20 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle", ChunkStatus.class); - private static final Reflection.MethodInvoker getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); + private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle", ChunkStatus.class); + private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java index d144c9b6..b749f834 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.minecraft.world.entity.PositionMoveRotation; import net.minecraft.world.phys.Vec3D; @@ -28,7 +28,7 @@ public class BountifulWrapper21 extends BountifulWrapper9 { @Override public BountifulWrapper.PositionSetter getPositionSetter(Class packetClass, int fieldOffset) { try { - Reflection.FieldAccessor field = Reflection.getField(packetClass, PositionMoveRotation.class, 0); + Reflection.Field field = Reflection.getField(packetClass, PositionMoveRotation.class, 0); return (packet, x, y, z, pitch, yaw) -> { PositionMoveRotation pos = field.get(packet); diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java index 2309a2a6..af3a3bd7 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.world.level.World; @@ -30,8 +30,8 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper21 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle", ChunkStatus.class); - private static final Reflection.MethodInvoker getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); + private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle", ChunkStatus.class); + private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java index 54ea45b3..14e84923 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java @@ -19,13 +19,12 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.minecraft.server.v1_8_R3.ChatComponentText; import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.PacketPlayOutChat; -import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -51,7 +50,7 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { } private static final Class watchableObject = Reflection.getClass("{nms}.DataWatcher$WatchableObject"); - private static final Reflection.ConstructorInvoker watchableObjectConstructor = Reflection.getConstructor(watchableObject, int.class, int.class, Object.class); + private static final Reflection.Constructor watchableObjectConstructor = Reflection.getConstructor(watchableObject, int.class, int.class, Object.class); private static final Map, Integer> watchableDatatypes = new HashMap<>(); static { watchableDatatypes.put(byte.class, 0); @@ -68,11 +67,11 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { @Override public BountifulWrapper.PositionSetter getPositionSetter(Class packetClass, int fieldOffset) { - Reflection.FieldAccessor posX = Reflection.getField(packetClass, int.class, fieldOffset); - Reflection.FieldAccessor posY = Reflection.getField(packetClass, int.class, fieldOffset +1); - Reflection.FieldAccessor posZ = Reflection.getField(packetClass, int.class, fieldOffset +2); - Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, byte.class, 0); - Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, byte.class, 1); + Reflection.Field posX = Reflection.getField(packetClass, int.class, fieldOffset); + Reflection.Field posY = Reflection.getField(packetClass, int.class, fieldOffset +1); + Reflection.Field posZ = Reflection.getField(packetClass, int.class, fieldOffset +2); + Reflection.Field lookPitch = Reflection.getField(packetClass, byte.class, 0); + Reflection.Field lookYaw = Reflection.getField(packetClass, byte.class, 1); return (packet, x, y, z, pitch, yaw) -> { posX.set(packet, MathHelper.floor(x * 32)); @@ -85,11 +84,11 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { @Override public BountifulWrapper.PositionSetter getRelMoveSetter(Class packetClass) { - Reflection.FieldAccessor moveX = Reflection.getField(packetClass, "b", byte.class); - Reflection.FieldAccessor moveY = Reflection.getField(packetClass, "c", byte.class); - Reflection.FieldAccessor moveZ = Reflection.getField(packetClass, "d", byte.class); - Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, "e", byte.class); - Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, "f", byte.class); + Reflection.Field moveX = Reflection.getField(packetClass, "b", byte.class); + Reflection.Field moveY = Reflection.getField(packetClass, "c", byte.class); + Reflection.Field moveZ = Reflection.getField(packetClass, "d", byte.class); + Reflection.Field lookYaw = Reflection.getField(packetClass, "e", byte.class); + Reflection.Field lookPitch = Reflection.getField(packetClass, "f", byte.class); return (packet, x, y, z, pitch, yaw) -> { moveX.set(packet, (byte)(x*32)); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java index 951cdc8a..4408679f 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java @@ -19,22 +19,22 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import java.util.ArrayList; import java.util.List; public class ChatWrapper8 implements ChatWrapper { - private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class); + private static final Reflection.Constructor chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class); @Override public Object stringToChatComponent(String text) { return chatComponentConstructor.invoke(text); } private static final Class metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata"); - private static final Reflection.FieldAccessor metadataEntity = Reflection.getField(metadataPacket, int.class, 0); - private static final Reflection.FieldAccessor metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); + private static final Reflection.Field metadataEntity = Reflection.getField(metadataPacket, int.class, 0); + private static final Reflection.Field metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); @Override public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) { Object packet = Reflection.newInstance(metadataPacket); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java index 7d485286..eacf97e3 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.EntityType; @@ -32,9 +32,9 @@ import java.util.Map; public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper { - private static final Reflection.FieldAccessor scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 1); + private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 1); private static final Class scoreActionEnum = Reflection.getClass("{nms}.PacketPlayOutScoreboardScore$EnumScoreboardAction"); - private static final Reflection.FieldAccessor scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0); + private static final Reflection.Field scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0); private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0]; @Override @@ -78,9 +78,9 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper private static final Class dataWatcher = Reflection.getClass("{nms}.DataWatcher"); private static final Class namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn"); - private static final Reflection.FieldAccessor namedSpawnDataWatcher = Reflection.getField(namedSpawnPacket, dataWatcher, 0); + private static final Reflection.Field namedSpawnDataWatcher = Reflection.getField(namedSpawnPacket, dataWatcher, 0); private static final Class entity = Reflection.getClass("{nms}.Entity"); - private static final Reflection.ConstructorInvoker dataWatcherConstructor = Reflection.getConstructor(dataWatcher, entity); + private static final Reflection.Constructor dataWatcherConstructor = Reflection.getConstructor(dataWatcher, entity); @Override public void setNamedSpawnPacketDataWatcher(Object packet) { namedSpawnDataWatcher.set(packet, dataWatcherConstructor.invoke((Object) null)); @@ -92,8 +92,8 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper } - private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9); - private static final Reflection.FieldAccessor spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); + private static final Reflection.Field spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9); + private static final Reflection.Field spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); private static final Map types = new HashMap<>(); static { types.put(TrickyTrialsWrapper.impl.getTntEntityType(), 50); @@ -113,7 +113,7 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper return 10; } - private static final Reflection.MethodInvoker save = Reflection.getMethod("{obc}.CraftWorld", "save", boolean.class); + private static final Reflection.Method save = Reflection.getMethod("{obc}.CraftWorld", "save", boolean.class); @Override public void syncSave(World world) { save.invoke(world, true); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java index 9f0b234b..24a924a0 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import org.bukkit.GameMode; @@ -29,7 +29,7 @@ import java.util.List; public class ProtocolWrapper8 implements ProtocolWrapper { - private static final Reflection.FieldAccessor equipmentSlot; + private static final Reflection.Field equipmentSlot; static { if(Core.getVersion() == 8) { equipmentSlot = Reflection.getField(equipmentPacket, int.class, 1); @@ -39,7 +39,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { } } - private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0); + private static final Reflection.Field equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0); @Override public void setEquipmentPacketStack(Object packet, Object slot, Object stack) { equipmentSlot.set(packet, slot); @@ -48,8 +48,8 @@ public class ProtocolWrapper8 implements ProtocolWrapper { private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); - private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); - private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); + private static final Reflection.Field playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); + private static final Reflection.Field playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); private static final EnumMap actions = new EnumMap<>(PlayerInfoAction.class); static { Object[] nativeActions = playerInfoActionClass.getEnumConstants(); @@ -58,7 +58,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { actions.put(PlayerInfoAction.REMOVE, nativeActions[4]); } private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override @SuppressWarnings("deprecation") diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java index d65cf989..2d4b607e 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java @@ -19,7 +19,7 @@ package de.steamwar.scoreboard; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; @@ -30,15 +30,15 @@ import java.util.HashMap; import java.util.Map; public class SWScoreboard8 implements SWScoreboard { - private static final Reflection.FieldAccessor scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 0); - private static final Reflection.FieldAccessor scoreboardAction = Reflection.getField(FlatteningWrapper.scoreboardObjective, int.class, Core.getVersion() > 15 ? 3 : 0); + private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 0); + private static final Reflection.Field scoreboardAction = Reflection.getField(FlatteningWrapper.scoreboardObjective, int.class, Core.getVersion() > 15 ? 3 : 0); private static final Class scoreboardDisplayEnum = Reflection.getClass("{nms.world.scores.criteria}.IScoreboardCriteria$EnumScoreboardHealthDisplay"); - private static final Reflection.FieldAccessor scoreboardDisplayType = Reflection.getField(FlatteningWrapper.scoreboardObjective, scoreboardDisplayEnum, 0); + private static final Reflection.Field scoreboardDisplayType = Reflection.getField(FlatteningWrapper.scoreboardObjective, scoreboardDisplayEnum, 0); private static final Object displayTypeIntegers = scoreboardDisplayEnum.getEnumConstants()[0]; - private static final Reflection.FieldAccessor scoreName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 0); - private static final Reflection.FieldAccessor scoreScoreboardName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 1); - private static final Reflection.FieldAccessor scoreValue = Reflection.getField(FlatteningWrapper.scoreboardScore, int.class, 0); + private static final Reflection.Field scoreName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 0); + private static final Reflection.Field scoreScoreboardName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 1); + private static final Reflection.Field scoreValue = Reflection.getField(FlatteningWrapper.scoreboardScore, int.class, 0); private static final HashMap playerBoards = new HashMap<>(); //Object -> Scoreboard | Alle Versionen in der Map! private static int toggle = 0; // Scoreboard 0 updates while scoreboard 1 is presenting. toggle marks the current active scoreboard @@ -49,8 +49,8 @@ public class SWScoreboard8 implements SWScoreboard { static { Class scoreboardDisplayObjective = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardDisplayObjective"); - Reflection.FieldAccessor scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0); - Reflection.FieldAccessor scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0); + Reflection.Field scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0); + Reflection.Field scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0); for(int id = 0; id < 2; id++) { DELETE_SCOREBOARD[id] = Reflection.newInstance(FlatteningWrapper.scoreboardObjective); scoreboardName.set(DELETE_SCOREBOARD[id], SIDEBAR + id); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java index 50adcaa3..600050ff 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.entity.Player; import java.util.function.BiFunction; diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java index b0de38c8..04b3c7c8 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.entity.Player; import java.lang.reflect.Array; @@ -28,15 +28,15 @@ import java.util.function.BiFunction; public class ProtocolWrapper8 implements ProtocolWrapper { private static final Class chunkCoordinateIntPair = Reflection.getClass("{nms}.ChunkCoordIntPair"); - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0); - private static final Reflection.FieldAccessor chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0); - private static final Reflection.FieldAccessor chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1); + private static final Reflection.Field multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0); + private static final Reflection.Field chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0); + private static final Reflection.Field chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1); private static final Class multiBlockChangeInfo = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo"); - private static final Reflection.ConstructorInvoker multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData); - private static final Reflection.FieldAccessor multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0); - private static final Reflection.FieldAccessor multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0); + private static final Reflection.Constructor multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData); + private static final Reflection.Field multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0); + private static final Reflection.Field multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0); private static final Class multiBlockChangeInfoArray = Reflection.getClass("[L{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); - private static final Reflection.FieldAccessor multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0); + private static final Reflection.Field multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0); @Override public BiFunction multiBlockChangeGenerator(TechHider techHider) { return (p, packet) -> { @@ -72,7 +72,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { }; } - private static final Reflection.FieldAccessor tileEntityDataAction = Reflection.getField(TechHider.tileEntityDataPacket, int.class, 0); + private static final Reflection.Field tileEntityDataAction = Reflection.getField(TechHider.tileEntityDataPacket, int.class, 0); @Override public boolean unfilteredTileEntityDataAction(Object packet) { return tileEntityDataAction.get(packet) != 9; diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index fa126698..43037fd3 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -19,11 +19,10 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.viaversion.viaversion.api.Via; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; -import net.minecraft.server.v1_9_R2.PacketPlayOutEntity; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -47,14 +46,14 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { private static final Class dataWatcherObject = Reflection.getClass("{nms.network.syncher}.DataWatcherObject"); private static final Class dataWatcherRegistry = Reflection.getClass("{nms.network.syncher}.DataWatcherRegistry"); private static final Class dataWatcherSerializer = Reflection.getClass("{nms.network.syncher}.DataWatcherSerializer"); - private static final Reflection.ConstructorInvoker dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); + private static final Reflection.Constructor dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); @Override public Object getDataWatcherObject(int index, Class type) { return dataWatcherObjectConstructor.invoke(index, Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null)); } private static final Class item = Reflection.getClass("{nms.network.syncher}.DataWatcher$Item"); - private static final Reflection.ConstructorInvoker itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); + private static final Reflection.Constructor itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); @Override public Object getDataWatcherItem(Object dwo, Object value) { return itemConstructor.invoke(dwo, value); @@ -62,13 +61,13 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public BountifulWrapper.PositionSetter getPositionSetter(Class packetClass, int fieldOffset) { - Reflection.FieldAccessor posX = Reflection.getField(packetClass, double.class, fieldOffset); - Reflection.FieldAccessor posY = Reflection.getField(packetClass, double.class, fieldOffset+1); - Reflection.FieldAccessor posZ = Reflection.getField(packetClass, double.class, fieldOffset+2); + Reflection.Field posX = Reflection.getField(packetClass, double.class, fieldOffset); + Reflection.Field posY = Reflection.getField(packetClass, double.class, fieldOffset+1); + Reflection.Field posZ = Reflection.getField(packetClass, double.class, fieldOffset+2); boolean isByteClass = packetClass.getSimpleName().contains("PacketPlayOutEntityTeleport") || packetClass.getSimpleName().contains("PacketPlayOutNamedEntitySpawn"); Class pitchYawType = isByteClass ? byte.class : int.class; - Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, pitchYawType, isByteClass ? 0 : 1); - Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, pitchYawType, isByteClass ? 1 : 2); + Reflection.Field lookPitch = Reflection.getField(packetClass, pitchYawType, isByteClass ? 0 : 1); + Reflection.Field lookYaw = Reflection.getField(packetClass, pitchYawType, isByteClass ? 1 : 2); return (packet, x, y, z, pitch, yaw) -> { posX.set(packet, x); @@ -87,11 +86,11 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public BountifulWrapper.PositionSetter getRelMoveSetter(Class packetClass) { Class type = Core.getVersion() > 12 ? short.class : int.class; - Reflection.FieldAccessor moveX = Reflection.getField(packetClass, "b", type); - Reflection.FieldAccessor moveY = Reflection.getField(packetClass, "c", type); - Reflection.FieldAccessor moveZ = Reflection.getField(packetClass, "d", type); - Reflection.FieldAccessor movePitch = Reflection.getField(packetClass, "e", byte.class); - Reflection.FieldAccessor moveYaw = Reflection.getField(packetClass, "f", byte.class); + Reflection.Field moveX = Reflection.getField(packetClass, "b", type); + Reflection.Field moveY = Reflection.getField(packetClass, "c", type); + Reflection.Field moveZ = Reflection.getField(packetClass, "d", type); + Reflection.Field movePitch = Reflection.getField(packetClass, "e", byte.class); + Reflection.Field moveYaw = Reflection.getField(packetClass, "f", byte.class); return (packet, x, y, z, pitch, yaw) -> { moveX.set(packet, (short)(x*4096)); @@ -104,7 +103,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public BountifulWrapper.UUIDSetter getUUIDSetter(Class packetClass) { - Reflection.FieldAccessor uuidField = Reflection.getField(packetClass, UUID.class, 0); + Reflection.Field uuidField = Reflection.getField(packetClass, UUID.class, 0); return uuidField::set; } diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java index 8d111e31..eb036e22 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import org.bukkit.entity.Player; @@ -27,8 +27,8 @@ public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapp private static final Class chunk = Reflection.getClass("{nms.world.level.chunk}.Chunk"); private static final Class packetPlayOutMapChunk = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMapChunk"); - private static final Reflection.ConstructorInvoker newPacketPlayOutMapChunk = Reflection.getConstructor(packetPlayOutMapChunk, chunk, int.class); - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + private static final Reflection.Constructor newPacketPlayOutMapChunk = Reflection.getConstructor(packetPlayOutMapChunk, chunk, int.class); + private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java index 89f6570f..d305ca12 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.bukkit.entity.Player; @@ -34,14 +34,14 @@ public class ChunkHider9 extends ChunkHider8 { private static final UnaryOperator mapChunkCloner = ProtocolUtils.shallowCloneGenerator(mapChunkPacket); - private static final Reflection.FieldAccessor mapChunkX = Reflection.getField(mapChunkPacket, int.class, 0); - private static final Reflection.FieldAccessor mapChunkZ = Reflection.getField(mapChunkPacket, int.class, 1); - private static final Reflection.FieldAccessor mapChunkBitMask = Reflection.getField(mapChunkPacket, int.class, 2); - private static final Reflection.FieldAccessor mapChunkBlockEntities = Reflection.getField(mapChunkPacket, List.class, 0); - private static final Reflection.FieldAccessor mapChunkData = Reflection.getField(mapChunkPacket, byte[].class, 0); + private static final Reflection.Field mapChunkX = Reflection.getField(mapChunkPacket, int.class, 0); + private static final Reflection.Field mapChunkZ = Reflection.getField(mapChunkPacket, int.class, 1); + private static final Reflection.Field mapChunkBitMask = Reflection.getField(mapChunkPacket, int.class, 2); + private static final Reflection.Field mapChunkBlockEntities = Reflection.getField(mapChunkPacket, List.class, 0); + private static final Reflection.Field mapChunkData = Reflection.getField(mapChunkPacket, byte[].class, 0); private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); - private static final Reflection.MethodInvoker nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); + private static final Reflection.Method nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); @Override public BiFunction chunkHiderGenerator(TechHider techHider) { diff --git a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java deleted file mode 100644 index 4bc66b5c..00000000 --- a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java +++ /dev/null @@ -1,416 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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 com.comphenix.tinyprotocol; - -import de.steamwar.core.Core; -import jdk.internal.misc.Unsafe; -import org.bukkit.Bukkit; - -import java.lang.reflect.*; -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * An utility class that simplifies reflection in Bukkit plugins. - * - * @author Kristian - */ -public final class Reflection { - /** - * An interface for invoking a specific constructor. - */ - public interface ConstructorInvoker { - /** - * Invoke a constructor for a specific class. - * - * @param arguments - the arguments to pass to the constructor. - * @return The constructed object. - */ - Object invoke(Object... arguments); - } - - /** - * An interface for invoking a specific method. - */ - public interface MethodInvoker { - /** - * Invoke a method on a specific target object. - * - * @param target - the target object, or NULL for a static method. - * @param arguments - the arguments to pass to the method. - * @return The return value, or NULL if is void. - */ - Object invoke(Object target, Object... arguments); - } - - /** - * An interface for retrieving the field content. - * - * @param - field type. - */ - public interface FieldAccessor { - /** - * Retrieve the content of a field. - * - * @param target - the target object, or NULL for a static field. - * @return The value of the field. - */ - T get(Object target); - - /** - * Set the content of a field. - * - * @param target - the target object, or NULL for a static field. - * @param value - the new value of the field. - */ - void set(Object target, Object value); - - /** - * Determine if the given object has this field. - * - * @param target - the object to test. - * @return TRUE if it does, FALSE otherwise. - */ - boolean hasField(Object target); - } - - // Deduce the net.minecraft.server.v* package - private static final String OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName(); - private static final String NMS_PREFIX = OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server"); - private static final String VERSION = OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", ""); - - // Variable replacement - private static final Pattern MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}"); - - private Reflection() { - // Seal class - } - - /** - * Retrieve a field accessor for a specific field type and name. - * - * @param target - the target type. - * @param name - the name of the field, or NULL to ignore. - * @param fieldType - a compatible field type. - * @return The field accessor. - */ - public static FieldAccessor getField(Class target, String name, Class fieldType) { - return getField(target, name, fieldType, 0); - } - - /** - * Retrieve a field accessor for a specific field type and name. - * - * @param className - lookup name of the class, see {@link #getClass(String)}. - * @param name - the name of the field, or NULL to ignore. - * @param fieldType - a compatible field type. - * @return The field accessor. - */ - public static FieldAccessor getField(String className, String name, Class fieldType) { - return getField(getClass(className), name, fieldType, 0); - } - - /** - * Retrieve a field accessor for a specific field type and name. - * - * @param target - the target type. - * @param fieldType - a compatible field type. - * @param index - the number of compatible fields to skip. - * @return The field accessor. - */ - public static FieldAccessor getField(Class target, Class fieldType, int index) { - return getField(target, null, fieldType, index); - } - - /** - * Retrieve a field accessor for a specific field type and name. - * - * @param className - lookup name of the class, see {@link #getClass(String)}. - * @param fieldType - a compatible field type. - * @param index - the number of compatible fields to skip. - * @return The field accessor. - */ - public static FieldAccessor getField(String className, Class fieldType, int index) { - return getField(getClass(className), fieldType, index); - } - - public static FieldAccessor getField(Class target, Class fieldType, int index, Class... parameters) { - return getField(target, null, fieldType, index, parameters); - } - - private static FieldAccessor getField(Class target, String name, Class fieldType, int index, Class... parameters) { - for (final Field field : target.getDeclaredFields()) { - if(matching(field, name, fieldType, parameters) && index-- <= 0) { - field.setAccessible(true); - - return new FieldAccessor() { - @Override - @SuppressWarnings("unchecked") - public T get(Object target) { - try { - return (T) field.get(target); - } catch (IllegalAccessException e) { - throw new IllegalArgumentException("Cannot access reflection.", e); - } - } - - @Override - public void set(Object target, Object value) { - try { - field.set(target, value); - } catch (IllegalAccessException e) { - throw new IllegalArgumentException("Cannot access reflection.", e); - } - } - - @Override - public boolean hasField(Object target) { - // target instanceof DeclaringClass - return field.getDeclaringClass().isAssignableFrom(target.getClass()); - } - }; - } - } - - // 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 boolean matching(Field field, String name, Class 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; - } - - /** - * Search for the first publicly and privately defined method of the given name and parameter count. - * - * @param className - lookup name of the class, see {@link #getClass(String)}. - * @param methodName - the method name, or NULL to skip. - * @param params - the expected parameters. - * @return An object that invokes this specific method. - * @throws IllegalStateException If we cannot find this method. - */ - public static MethodInvoker getMethod(String className, String methodName, Class... params) { - return getTypedMethod(getClass(className), methodName, null, params); - } - - /** - * Search for the first publicly and privately defined method of the given name and parameter count. - * - * @param clazz - a class to start with. - * @param methodName - the method name, or NULL to skip. - * @param params - the expected parameters. - * @return An object that invokes this specific method. - * @throws IllegalStateException If we cannot find this method. - */ - public static MethodInvoker getMethod(Class clazz, String methodName, Class... params) { - return getTypedMethod(clazz, methodName, null, params); - } - - /** - * Search for the first publicly and privately defined method of the given name and parameter count. - * - * @param clazz - a class to start with. - * @param methodName - the method name, or NULL to skip. - * @param returnType - the expected return type, or NULL to ignore. - * @param params - the expected parameters. - * @return An object that invokes this specific method. - * @throws IllegalStateException If we cannot find this method. - */ - public static MethodInvoker getTypedMethod(Class clazz, String methodName, Class returnType, Class... params) { - for (final 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 (target, arguments) -> { - try { - return method.invoke(target, arguments); - } catch (Exception e) { - throw new IllegalArgumentException("Cannot invoke method " + method, e); - } - }; - } - } - - // Search in every superclass - if (clazz.getSuperclass() != null) - return getTypedMethod(clazz.getSuperclass(), methodName, returnType, params); - - throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params))); - } - - /** - * Search for the first publically and privately defined constructor of the given name and parameter count. - * - * @param className - lookup name of the class, see {@link #getClass(String)}. - * @param params - the expected parameters. - * @return An object that invokes this constructor. - * @throws IllegalStateException If we cannot find this method. - */ - public static ConstructorInvoker getConstructor(String className, Class... params) { - return getConstructor(getClass(className), params); - } - - /** - * Search for the first publically and privately defined constructor of the given name and parameter count. - * - * @param clazz - a class to start with. - * @param params - the expected parameters. - * @return An object that invokes this constructor. - * @throws IllegalStateException If we cannot find this method. - */ - public static ConstructorInvoker getConstructor(Class clazz, Class... params) { - for (final Constructor constructor : clazz.getDeclaredConstructors()) { - if (Arrays.equals(constructor.getParameterTypes(), params)) { - constructor.setAccessible(true); - - return arguments -> { - try { - return constructor.newInstance(arguments); - } catch (Exception e) { - throw new IllegalArgumentException("Cannot invoke constructor " + constructor, e); - } - }; - } - } - - throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(params))); - } - - /** - * Retrieve a class from its full name, without knowing its type on compile time. - *

- * This is useful when looking up fields by a NMS or OBC type. - *

- * - * @param lookupName - the class name with variables. - * @return The class. - */ - public static Class getUntypedClass(String lookupName) { - @SuppressWarnings({ "rawtypes", "unchecked" }) - Class clazz = (Class) getClass(lookupName); - return clazz; - } - - /** - * Retrieve a class from its full name. - *

- * Strings enclosed with curly brackets - such as {TEXT} - will be replaced according to the following table: - *

- * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
VariableContent
{nms}Actual package name of net.minecraft.server.VERSION
{obc}Actual pacakge name of org.bukkit.craftbukkit.VERSION
{version}The current Minecraft package VERSION, if any.
- * - * @param lookupName - the class name with variables. - * @return The looked up class. - * @throws IllegalArgumentException If a variable or class could not be found. - */ - public static Class getClass(String lookupName) { - try { - return Class.forName(expandVariables(lookupName)); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException("Cannot find " + expandVariables(lookupName), e); - } - } - - /** - * Expand variables such as "{nms}" and "{obc}" to their corresponding packages. - * - * @param name - the full name of the class. - * @return The expanded string. - */ - private static String expandVariables(String name) { - StringBuffer output = new StringBuffer(); - Matcher matcher = MATCH_VARIABLE.matcher(name); - - while (matcher.find()) { - String variable = matcher.group(1); - String replacement; - - // Expand all detected variables - if (variable.startsWith("nms")) { - if(Core.getVersion() >= 17) - replacement = "net.minecraft" + variable.substring(3); - else - replacement = NMS_PREFIX; - } else if ("obc".equals(variable)) - replacement = OBC_PREFIX; - else if ("version".equals(variable)) - replacement = VERSION; - else - throw new IllegalArgumentException("Unknown variable: " + variable); - - // Assume the expanded variables are all packages, and append a dot - if (replacement.length() > 0 && matcher.end() < name.length() && name.charAt(matcher.end()) != '.') - replacement += "."; - matcher.appendReplacement(output, Matcher.quoteReplacement(replacement)); - } - - matcher.appendTail(output); - return output.toString(); - } - - @SuppressWarnings("deprecation") - public static Object newInstance(Class clazz) { - try { - if (Core.getVersion() > 15) { - return Unsafe.getUnsafe().allocateInstance(clazz); - } else { - return clazz.newInstance(); - } - } catch (InstantiationException | IllegalAccessException e) { - throw new SecurityException("Could not create object", e); - } - } -} diff --git a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java index 7019c26d..6997b3ef 100644 --- a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java @@ -19,7 +19,8 @@ package com.comphenix.tinyprotocol; -import com.comphenix.tinyprotocol.Reflection.FieldAccessor; +import de.steamwar.Reflection; +import de.steamwar.Reflection.Field; import de.steamwar.core.Core; import io.netty.channel.Channel; import io.netty.channel.ChannelDuplexHandler; @@ -44,17 +45,17 @@ public class TinyProtocol implements Listener { private static final Class craftServer = Reflection.getClass("{obc}.CraftServer"); private static final Class dedicatedPlayerList = Reflection.getClass("{nms.server.dedicated}.DedicatedPlayerList"); - private static final FieldAccessor getPlayerList = Reflection.getField(craftServer, dedicatedPlayerList, 0); + private static final Field getPlayerList = Reflection.getField(craftServer, dedicatedPlayerList, 0); private static final Class playerList = Reflection.getClass("{nms.server.players}.PlayerList"); private static final Class minecraftServer = Reflection.getClass("{nms.server}.MinecraftServer"); - private static final FieldAccessor getMinecraftServer = Reflection.getField(playerList, minecraftServer, 0); + private static final Field getMinecraftServer = Reflection.getField(playerList, minecraftServer, 0); public static final Class serverConnection = Reflection.getClass("{nms.server.network}.ServerConnection"); - private static final FieldAccessor getServerConnection = Reflection.getField(minecraftServer, serverConnection, 0); + private static final Field getServerConnection = Reflection.getField(minecraftServer, serverConnection, 0); public static Object getServerConnection(Plugin plugin) { return getServerConnection.get(getMinecraftServer.get(getPlayerList.get(plugin.getServer()))); } private static final Class networkManager = Reflection.getClass("{nms.network}.NetworkManager"); - public static final FieldAccessor networkManagers = Reflection.getField(serverConnection, List.class, 0, networkManager); + public static final Field networkManagers = Reflection.getField(serverConnection, List.class, 0, networkManager); public static final TinyProtocol instance = new TinyProtocol(Core.getInstance()); private static int id = 0; @@ -136,8 +137,8 @@ public class TinyProtocol implements Listener { } } - private static final FieldAccessor getChannel = Reflection.getField(networkManager, Channel.class, 0); - private static final FieldAccessor getUUID = Reflection.getField(networkManager, UUID.class, 0); + private static final Field getChannel = Reflection.getField(networkManager, Channel.class, 0); + private static final Field getUUID = Reflection.getField(networkManager, UUID.class, 0); private final class PacketInterceptor extends ChannelDuplexHandler { private final Player player; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java new file mode 100644 index 00000000..26bf8bf2 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -0,0 +1,206 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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; + +import de.steamwar.core.Core; +import jdk.internal.misc.Unsafe; +import lombok.AllArgsConstructor; +import lombok.experimental.UtilityClass; +import org.bukkit.Bukkit; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Arrays; + + +@UtilityClass +public final class Reflection { + + private static final String ORG_BUKKIT_CRAFTBUKKIT = Bukkit.getServer().getClass().getPackage().getName(); + public static final int MAJOR_VERSION = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().split("_", 3)[1]); + private static final String LEGACY_NET_MINECRAFT_SERVER = ORG_BUKKIT_CRAFTBUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server"); + + 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 + "." + name.split("[.](?=[^.]*$)")[1]); + } else { + return Class.forName(name); + } + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("Cannot find " + name, e); + } + } + + @AllArgsConstructor + public static class Field { + private final java.lang.reflect.Field field; + + @SuppressWarnings("unchecked") + public T get(Object target) { + try { + return (T) field.get(target); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException("Cannot read field", e); + } + } + + public void set(Object target, Object value) { + try { + field.set(target, value); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException("Cannot write field", e); + } + } + } + + public static Field getField(Class target, String name, Class fieldType) { + return getField(target, name, fieldType, 0); + } + + public static Field getField(String className, String name, Class fieldType) { + return getField(getClass(className), name, fieldType, 0); + } + + public static Field getField(Class target, Class fieldType, int index) { + return getField(target, null, fieldType, index); + } + + public static Field getField(String className, Class fieldType, int index) { + return getField(getClass(className), fieldType, index); + } + + public static Field getField(Class target, Class fieldType, int index, Class... parameters) { + return getField(target, null, fieldType, index, parameters); + } + + private static Field getField(Class target, String name, Class 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 boolean matching(java.lang.reflect.Field field, String name, Class 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 method; + + public Object invoke(Object target, Object... arguments) { + try { + return method.invoke(target, arguments); + } catch (Exception e) { + throw new IllegalArgumentException("Cannot invoke method " + method, e); + } + } + } + + public static Method getMethod(String className, String methodName, Class... params) { + return getTypedMethod(getClass(className), methodName, null, params); + } + + public static Method getMethod(Class clazz, String methodName, Class... params) { + return getTypedMethod(clazz, methodName, null, params); + } + + 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 constructor; + + public Object invoke(Object... arguments) { + try { + return constructor.newInstance(arguments); + } catch (Exception e) { + throw new IllegalArgumentException("Cannot invoke constructor " + constructor, e); + } + } + } + + public static Constructor getConstructor(String className, Class... params) { + return getConstructor(getClass(className), params); + } + + 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) { + try { + if (Core.getVersion() > 15) { + return Unsafe.getUnsafe().allocateInstance(clazz); + } else { + return clazz.newInstance(); + } + } catch (InstantiationException | IllegalAccessException e) { + throw new SecurityException("Could not create object", e); + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index cde82084..61788dfa 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import com.viaversion.viaversion.api.Via; import de.steamwar.sql.internal.Statement; @@ -91,8 +91,8 @@ class CheckpointUtilsJ9 { } - private static final Reflection.FieldAccessor channelFutures = Reflection.getField(TinyProtocol.serverConnection, List.class, 0, ChannelFuture.class); - private static final Reflection.MethodInvoker bind = Reflection.getMethod(TinyProtocol.serverConnection, null, InetAddress.class, int.class); + private static final Reflection.Field channelFutures = Reflection.getField(TinyProtocol.serverConnection, List.class, 0, ChannelFuture.class); + private static final Reflection.Method bind = Reflection.getMethod(TinyProtocol.serverConnection, null, InetAddress.class, int.class); private static void freezeInternal(Path path) throws Exception { Bukkit.getPluginManager().callEvent(new CRIUSleepEvent()); Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java index bbce1378..712ceaf7 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -29,8 +29,8 @@ import java.util.Map; @UtilityClass public class CommandRemover { - private static final Reflection.FieldAccessor commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); - private static final Reflection.FieldAccessor knownCommands = Reflection.getField(SimpleCommandMap.class, "knownCommands", Map.class); + private static final Reflection.Field commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); + private static final Reflection.Field knownCommands = Reflection.getField(SimpleCommandMap.class, "knownCommands", Map.class); public static void removeAll(String... cmds) { Map knownCmds = knownCommands.get(commandMap.get(Bukkit.getServer())); for (String cmd : cmds) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index 9c1e51ef..b17b2ca8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -20,6 +20,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.Reflection; import de.steamwar.command.*; import de.steamwar.core.authlib.AuthlibInjector; import de.steamwar.core.events.*; @@ -44,10 +45,8 @@ public class Core extends JavaPlugin{ public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader()); - private static final int VERSION = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().split("_", 3)[1]); - public static int getVersion(){ - return VERSION; + return Reflection.MAJOR_VERSION; } private static JavaPlugin instance; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java index c9585847..5a801f11 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.sql.SWException; import java.io.ByteArrayOutputStream; @@ -40,7 +40,7 @@ public class ErrorHandler extends Handler { Logger.getLogger("").addHandler(this); Class watchdogThread = Reflection.getClass("org.spigotmc.WatchdogThread"); - Reflection.FieldAccessor getInstance = Reflection.getField(watchdogThread, watchdogThread, 0); + Reflection.Field getInstance = Reflection.getField(watchdogThread, watchdogThread, 0); Thread watchdog = (Thread) getInstance.get(null); watchdogThreadId = watchdog.getId(); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java index 479760cf..0f7e9e47 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.EntityType; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java index e6787497..8706e2c6 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import org.bukkit.GameMode; @@ -33,7 +33,7 @@ public interface ProtocolWrapper { Class equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment"); Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); - Reflection.MethodInvoker getGameModeById = Reflection.getTypedMethod(enumGamemode, null, enumGamemode, int.class); + Reflection.Method getGameModeById = Reflection.getTypedMethod(enumGamemode, null, enumGamemode, int.class); // 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("{nms.world.entity}.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4}; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index 54a5f7e2..fefba9cd 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Bukkit; public class TPSWatcher { @@ -80,8 +80,8 @@ public class TPSWatcher { } private static final Class minecraftServer = Reflection.getClass("{nms.server}.MinecraftServer"); - private static final Reflection.MethodInvoker getServer = Reflection.getTypedMethod(minecraftServer, "getServer", minecraftServer); - private static final Reflection.FieldAccessor recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class); + private static final Reflection.Method getServer = Reflection.getTypedMethod(minecraftServer, "getServer", minecraftServer); + private static final Reflection.Field recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class); private static double[] getSpigotTPS() { return recentTps.get(getServer.invoke(null)); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java index 0c9c188b..7319f4d4 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java @@ -19,7 +19,7 @@ package de.steamwar.core.authlib; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository; @@ -28,7 +28,7 @@ public class AuthlibInjector { public static void inject() { Class minecraftServerClass = Reflection.getClass("{nms.server}.MinecraftServer"); - Reflection.FieldAccessor gameProfile = Reflection.getField(minecraftServerClass, GameProfileRepository.class, 0); + Reflection.Field gameProfile = Reflection.getField(minecraftServerClass, GameProfileRepository.class, 0); Object minecraftServer = Reflection.getTypedMethod(minecraftServerClass, "getServer", minecraftServerClass).invoke(null); gameProfile.set(minecraftServer, new SteamwarGameProfileRepository((YggdrasilGameProfileRepository) gameProfile.get(minecraftServer))); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index ea7759da..cccdc38c 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -19,7 +19,7 @@ package de.steamwar.core.events; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.sql.SWException; @@ -59,8 +59,8 @@ public class AntiNocom implements Listener { Function getPosition; if(Core.getVersion() > 12) { Class movingObjectPositionBlock = Reflection.getClass("{nms.world.phys}.MovingObjectPositionBlock"); - Reflection.FieldAccessor useItemPosition = Reflection.getField(useItem, movingObjectPositionBlock, 0); - Reflection.FieldAccessor movingBlockPosition = Reflection.getField(movingObjectPositionBlock, TechHider.blockPosition, 0); + Reflection.Field useItemPosition = Reflection.getField(useItem, movingObjectPositionBlock, 0); + Reflection.Field movingBlockPosition = Reflection.getField(movingObjectPositionBlock, TechHider.blockPosition, 0); getPosition = (packet) -> movingBlockPosition.get(useItemPosition.get(packet)); } else { @@ -74,7 +74,7 @@ public class AntiNocom implements Listener { } private static final Class blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); - private static final Reflection.FieldAccessor digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0); + private static final Reflection.Field digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0); private Object onDig(Player player, Object packet) { Object pos = digPosition.get(packet); return isValid(player, "Dig", TechHider.blockPositionX.get(pos), TechHider.blockPositionZ.get(pos)) ? packet : null; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java index 6efab3c5..bca606ec 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java @@ -19,7 +19,7 @@ package de.steamwar.core.events; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.ViaAPI; @@ -39,9 +39,9 @@ public class PartialChunkFixer { private static final int PROTOCOL1_17 = 755; private static final Class mapChunk = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); - private static final Reflection.FieldAccessor fullChunkFlag = Reflection.getField(mapChunk, boolean.class, 0); - private static final Reflection.FieldAccessor chunkX = Reflection.getField(mapChunk, int.class, 0); - private static final Reflection.FieldAccessor chunkZ = Reflection.getField(mapChunk, int.class, 1); + private static final Reflection.Field fullChunkFlag = Reflection.getField(mapChunk, boolean.class, 0); + private static final Reflection.Field chunkX = Reflection.getField(mapChunk, int.class, 0); + private static final Reflection.Field chunkZ = Reflection.getField(mapChunk, int.class, 1); private final ViaAPI via = Via.getAPI(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 6948dc68..d4ffc19d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -19,7 +19,7 @@ package de.steamwar.entity; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.*; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; @@ -161,8 +161,8 @@ public class REntity { } private static final Class animationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutAnimation"); - private static final Reflection.FieldAccessor animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 5 : 6) : 0); - private static final Reflection.FieldAccessor animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 6 : 7) : 1); + private static final Reflection.Field animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 5 : 6) : 0); + private static final Reflection.Field animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 6 : 7) : 1); public void showAnimation(byte animation) { Object packet = Reflection.newInstance(animationPacket); animationEntity.set(packet, entityId); @@ -171,10 +171,10 @@ public class REntity { } private static final Class velocityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); - private static final Reflection.FieldAccessor velocityEntity = Reflection.getField(velocityPacket, int.class, 0); - private static final Reflection.FieldAccessor velocityX = Reflection.getField(velocityPacket, int.class, 1); - private static final Reflection.FieldAccessor velocityY = Reflection.getField(velocityPacket, int.class, 2); - private static final Reflection.FieldAccessor velocityZ = Reflection.getField(velocityPacket, int.class, 3); + private static final Reflection.Field velocityEntity = Reflection.getField(velocityPacket, int.class, 0); + private static final Reflection.Field velocityX = Reflection.getField(velocityPacket, int.class, 1); + private static final Reflection.Field velocityY = Reflection.getField(velocityPacket, int.class, 2); + private static final Reflection.Field velocityZ = Reflection.getField(velocityPacket, int.class, 3); public void setVelocity(double dX, double dY, double dZ) { Object packet = Reflection.newInstance(velocityPacket); velocityEntity.set(packet, entityId); @@ -185,8 +185,8 @@ public class REntity { } private static final Class statusPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityStatus"); - private static final Reflection.FieldAccessor statusEntity = Reflection.getField(statusPacket, int.class, 0); - private static final Reflection.FieldAccessor statusStatus = Reflection.getField(statusPacket, byte.class, 0); + private static final Reflection.Field statusEntity = Reflection.getField(statusPacket, int.class, 0); + private static final Reflection.Field statusStatus = Reflection.getField(statusPacket, byte.class, 0); public void showDamage() { Object packet = Reflection.newInstance(statusPacket); statusEntity.set(packet, entityId); @@ -293,7 +293,7 @@ public class REntity { return 4; } } - private static final Reflection.FieldAccessor additionalData = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, objectDataOffset()); + private static final Reflection.Field additionalData = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, objectDataOffset()); private Object spawnPacketGenerator() { Object packet = spawnPacketGenerator.apply(this); additionalData.set(packet, objectData); @@ -347,7 +347,7 @@ public class REntity { } private static final Class destroyPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityDestroy"); - private static final Reflection.FieldAccessor destroyEntities; + private static final Reflection.Field destroyEntities; static { if(Core.getVersion() > 15) destroyEntities = Reflection.getField(destroyPacket, IntList.class, 0); @@ -394,7 +394,7 @@ public class REntity { } public static final Class teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); - public static final Reflection.FieldAccessor teleportEntity = Reflection.getField(teleportPacket, int.class, 0); + public static final Reflection.Field teleportEntity = Reflection.getField(teleportPacket, int.class, 0); public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0); private Object getTeleportPacket(){ Object packet = Reflection.newInstance(teleportPacket); @@ -404,7 +404,7 @@ public class REntity { } private static final Class entityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity"); - private static final Reflection.FieldAccessor moveEntityId = Reflection.getField(entityPacket, int.class, 0); + private static final Reflection.Field moveEntityId = Reflection.getField(entityPacket, int.class, 0); private static final BountifulWrapper.PositionSetter movePosition = BountifulWrapper.impl.getRelMoveSetter(entityPacket); private static final Class lookPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutEntityLook"); private static final Class movePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutRelEntityMove"); @@ -429,8 +429,8 @@ public class REntity { } private static final Class headRotationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityHeadRotation"); - private static final Reflection.FieldAccessor headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); - private static final Reflection.FieldAccessor headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); + private static final Reflection.Field headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); + private static final Reflection.Field headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); private Object getHeadRotationPacket(){ Object packet = Reflection.newInstance(headRotationPacket); headRotationEntity.set(packet, entityId); @@ -438,10 +438,10 @@ public class REntity { return packet; } - private static final Reflection.FieldAccessor equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0); + private static final Reflection.Field equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0); private static final Class craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack"); - private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class); + private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class); protected Object getEquipmentPacket(Object slot, ItemStack stack){ Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket); equipmentEntity.set(packet, entityId); @@ -462,7 +462,7 @@ public class REntity { } protected static Function spawnPacketGenerator(Class spawnPacket, int posOffset) { - Reflection.FieldAccessor entityId = Reflection.getField(spawnPacket, int.class, 0); + Reflection.Field entityId = Reflection.getField(spawnPacket, int.class, 0); BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset); return entity -> { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 442d05dd..59df0563 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -19,7 +19,7 @@ package de.steamwar.entity; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; @@ -48,13 +48,13 @@ public class REntityServer implements Listener { private static final HashSet emptyPlayers = new HashSet<>(0); private static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); - private static final Reflection.FieldAccessor useEntityTarget = Reflection.getField(useEntity, int.class, 0); + private static final Reflection.Field useEntityTarget = Reflection.getField(useEntity, int.class, 0); private static final Class useEntityEnumAction = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity$EnumEntityUseAction"); - private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); + private static final Reflection.Field useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); private static final Function getEntityAction; static { if(Core.getVersion() > 15) { - Reflection.MethodInvoker useEntityGetAction = Reflection.getMethod(useEntityEnumAction, "a"); + Reflection.Method useEntityGetAction = Reflection.getMethod(useEntityEnumAction, "a"); getEntityAction = value -> ((Enum) useEntityGetAction.invoke(value)).ordinal(); } else { getEntityAction = value -> ((Enum) value).ordinal(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index 1aa10d85..cb4e4638 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -19,7 +19,7 @@ package de.steamwar.entity; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.Core; @@ -93,7 +93,7 @@ public class RPlayer extends REntity { private static final Class namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn"); private static final Function namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, Core.getVersion() == 8 ? 1 : 0); - private static final Reflection.FieldAccessor namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); + private static final Reflection.Field namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); private Object getNamedSpawnPacket() { Object packet = namedSpawnPacketGenerator.apply(this); namedSpawnUUID.set(packet, uuid); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java index bfcbbb5c..47b9a146 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java @@ -19,7 +19,7 @@ package de.steamwar.network.handlers; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; public class ServerDataHandler { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ProtocolUtils.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ProtocolUtils.java index fe7bc707..57f27921 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ProtocolUtils.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ProtocolUtils.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.google.common.primitives.Bytes; import io.netty.buffer.ByteBuf; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 9f3ccf90..d29f082d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import lombok.Getter; @@ -37,19 +37,19 @@ public class TechHider { public static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); private static final Class baseBlockPosition = Reflection.getClass("{nms.core}.BaseBlockPosition"); - public static final Reflection.FieldAccessor blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); - public static final Reflection.FieldAccessor blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1); - public static final Reflection.FieldAccessor blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); + public static final Reflection.Field blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); + public static final Reflection.Field blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1); + public static final Reflection.Field blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); public static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); public static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); - private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); + private static final Reflection.Method getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); public static final Class craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers"); - private static final Reflection.MethodInvoker getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); + private static final Reflection.Method getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); - private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); - private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); + private static final Reflection.Method getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); + private static final Reflection.Method getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); public boolean iBlockDataHidden(Object iBlockData) { return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); } @@ -110,8 +110,8 @@ public class TechHider { private static final Class blockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockChange"); private static final Function blockChangeCloner = ProtocolUtils.shallowCloneGenerator(blockChangePacket); - private static final Reflection.FieldAccessor blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); - private static final Reflection.FieldAccessor blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); + private static final Reflection.Field blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); + private static final Reflection.Field blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); private Object blockChangeHider(Player p, Object packet) { switch (locationEvaluator.checkBlockPos(p, blockChangePosition.get(packet))) { case SKIP: @@ -132,7 +132,7 @@ public class TechHider { } private static final Class blockActionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockAction"); - private static final Reflection.FieldAccessor blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); + private static final Reflection.Field blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); private Object blockActionHider(Player p, Object packet) { if (locationEvaluator.checkBlockPos(p, blockActionPosition.get(packet)) == State.SKIP) return packet; @@ -140,7 +140,7 @@ public class TechHider { } public static final Class tileEntityDataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutTileEntityData"); - private static final Reflection.FieldAccessor tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); + private static final Reflection.Field tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); private Object tileEntityDataHider(Player p, Object packet) { switch (locationEvaluator.checkBlockPos(p, tileEntityDataPosition.get(packet))) { case SKIP: From a16e1e8cee02d6acd858a0e0b0051e1318a852a2 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Dec 2024 21:44:40 +0100 Subject: [PATCH 013/106] Add LastOnline to WhoisCommand --- CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java | 9 +++++++++ .../src/de/steamwar/messages/BungeeCore.properties | 1 + .../src/de/steamwar/messages/BungeeCore_de.properties | 1 + .../de/steamwar/velocitycore/commands/WhoisCommand.java | 9 ++++++--- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java index 96974c61..d5b87b6e 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java @@ -73,6 +73,7 @@ public class SteamwarUser { private static final Statement getPlaytime = new Statement("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?"); private static final Statement getFirstjoin = new Statement("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?"); + private static final Statement getLastonline = new Statement("SELECT MAX(EndTime) AS LastOnline FROM Session WHERE UserID = ?"); private static final Map usersById = new HashMap<>(); private static final Map usersByUUID = new HashMap<>(); @@ -276,6 +277,14 @@ public class SteamwarUser { }, id); } + public Timestamp getLastOnline() { + return getLastonline.select(rs -> { + if (rs.next()) + return rs.getTimestamp("LastOnline"); + return null; + }, id); + } + public void punish(Punishment.PunishmentType punishment, Timestamp time, String banReason, int from, boolean perma) { initPunishments(); punishments.remove(punishment); diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index b133d99b..e8ca12bb 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -626,6 +626,7 @@ WHOIS_ID=§7ID§8: §e{0} WHOIS_PERMS=§7Perms§8: §7{0} WHOIS_DISCORD_ID=§7Discord-ID§8: §e{0} WHOIS_JOINED_FIRST=§7Joined on§8: §e{0} +WHOIS_LAST_ONLINE=§7Last on§8: §e{0} WHOIS_HOURS_PLAYED=§7Online Time§8: §e{0}h WHOIS_CURRENT_PLAYED=§7Current Online Time§8: §e{0}m WHOIS_CURRENT_SERVER=§7Current Server§8: §e{0} diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index 9299064f..db367a1f 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -602,6 +602,7 @@ WHOIS_UUID_HOVER=§eUUID Kopieren WHOIS_ID=§7ID§8: §e{0} WHOIS_DISCORD_ID=§7Discord-ID§8: §e{0} WHOIS_JOINED_FIRST=§7Beigetreten am§8: §e{0} +WHOIS_LAST_ONLINE=§7Zuletzt online§8: §e{0} WHOIS_HOURS_PLAYED=§7Spielzeit§8: §e{0}h WHOIS_CURRENT_PLAYED=§7Aktuell online§8: §e{0}m WHOIS_CURRENT_SERVER=§7Aktueller Server§8: §e{0} diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/WhoisCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/WhoisCommand.java index 6512c9c0..4daa5b78 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/WhoisCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/WhoisCommand.java @@ -20,15 +20,15 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.Player; -import de.steamwar.persistent.Storage; -import de.steamwar.velocitycore.VelocityCore; -import de.steamwar.velocitycore.mods.ModUtils; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; +import de.steamwar.persistent.Storage; import de.steamwar.sql.*; +import de.steamwar.velocitycore.VelocityCore; +import de.steamwar.velocitycore.mods.ModUtils; import lombok.AllArgsConstructor; import lombok.Getter; import net.kyori.adventure.text.event.ClickEvent; @@ -86,9 +86,12 @@ public class WhoisCommand extends SWCommand { if(firstJoin == null && target != null) { firstJoin = Storage.sessions.get(target); } + Timestamp lastOnline = user.getLastOnline(); if(firstJoin != null) sender.system("WHOIS_JOINED_FIRST", firstJoin.toString()); + if (lastOnline != null) + sender.system("WHOIS_LAST_ONLINE", lastOnline.toString()); sender.system("WHOIS_HOURS_PLAYED", new DecimalFormat("###.##").format(onlineTime / 3600d)); if(target != null) { From e9ac198fcb995e48a7256e55227e8da38119296d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 26 Dec 2024 22:41:46 +0100 Subject: [PATCH 014/106] Remove deop on TNTLeague join (mit Lixfel abgesprochen) --- TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt index 1d9eb19d..b01dffd9 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt @@ -46,7 +46,6 @@ object GlobalListener: Listener { with(e.player) { teleport(TNTLeagueWorldConfig.lobby) inventory.clear() - isOp = false gameMode = GameMode.SPECTATOR respawnLocation = TNTLeagueWorldConfig.lobby } From 7eba9231d5eece2144af468b175df967a707c5b9 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 28 Dec 2024 17:15:57 +0100 Subject: [PATCH 015/106] Fix build issues --- .../listeners/DiscordTicketHandler.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java index d797a6f3..f32b4767 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java @@ -41,12 +41,12 @@ import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.buttons.Button; import net.dv8tion.jda.api.utils.SplitUtil; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.kyori.adventure.text.event.ClickEvent; import org.jetbrains.annotations.NotNull; import java.awt.*; import java.time.Instant; -import java.util.Collections; import java.util.LinkedList; import java.util.stream.Collectors; @@ -112,9 +112,12 @@ public class DiscordTicketHandler extends ListenerAdapter { .setTimestamp(Instant.now()) .setTitle(event.getChannel().getName()); + User user; if(channel.getTopic() != null && !channel.getTopic().isEmpty()) { - User user = event.getJDA().retrieveUserById(channel.getTopic()).complete(); + user = event.getJDA().retrieveUserById(channel.getTopic()).complete(); embedBuilder.setAuthor(user.getName(), null, user.getAvatarUrl()); + } else { + user = null; } TextChannel logChannel = event.getGuild().getTextChannelById(TICKET_LOG); @@ -124,15 +127,14 @@ public class DiscordTicketHandler extends ListenerAdapter { 2000, SplitUtil.Strategy.NEWLINE, SplitUtil.Strategy.ANYWHERE - ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())).forEach(builder -> logChannel.sendMessage(builder.build()).queue()); - - SplitUtil.split( - messages.stream() - .map(StringBuilder::toString).collect(Collectors.joining()), - 2000, - SplitUtil.Strategy.NEWLINE, - SplitUtil.Strategy.ANYWHERE - ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())).forEach(builder -> user.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(builder.build()).queue())); + ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())) + .forEach(builder -> { + MessageCreateData createData = builder.build(); + logChannel.sendMessage(createData).queue(); + if (user != null) { + user.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(createData).queue()); + } + }); Chatter.serverteam().prefixless("DISCORD_TICKET_CLOSED", channel.getName()); channel.delete().reason("Closed").queue(); From f111d552004e883874b39fbb4cf7bc3937aa713f Mon Sep 17 00:00:00 2001 From: TheBreadBeard Date: Sat, 28 Dec 2024 17:36:40 +0100 Subject: [PATCH 016/106] Add custom NPC Chats for specific players --- .../src/de/steamwar/lobby/LobbySystem.properties | 2 ++ .../src/de/steamwar/lobby/LobbySystem_de.properties | 2 ++ .../src/de/steamwar/lobby/team/TeamPlayer.java | 11 ++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties index 2d3aa782..7469e86e 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties @@ -10,6 +10,8 @@ NPC_CHAT_2 = §eSteam§8War§f was established in 2019. NPC_CHAT_3 = §fBecome a part of our team by applying via our Discord server (https://steamwar.de/discord). NPC_CHAT_4 = §fYou can develop your own buildserver features with our Lua script system. NPC_CHAT_5 = §fThere are many secrets to discover in this lobby. +## TheBreadBeard +NPC_CHAT_3266_0 = §fI collect Alts like Infinity Stones. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Lists all portals diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties index 73808174..f7422e89 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties @@ -10,6 +10,8 @@ NPC_CHAT_2 = §eSteam§8War§f gibt es seit 2019. NPC_CHAT_3 = §fBewerbe dich gerne für unser Team über unseren Discord-Server (https://steamwar.de/discord). NPC_CHAT_4 = §fDu kannst mit unserm Lua Script-System deine eigenen Bau Features programmieren. NPC_CHAT_5 = §fAuf dieser Lobby sind so einige secrets versteckt. +## TheBreadBeard +NPC_CHAT_3266_0 = §fIch sammle Alts wie Infinity Stones. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Listet alle Portale auf diff --git a/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java b/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java index 2829ec2f..a42d184a 100644 --- a/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java +++ b/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java @@ -144,11 +144,16 @@ public class TeamPlayer extends BasicListener { players.remove(event.getPlayer()); return; } - - String message = "NPC_CHAT_" + random.nextInt(6); SteamwarUser user = SteamwarUser.get(event.getRightClicked().getName()); UserPerm.Prefix prefix = user.prefix(); - LobbySystem.getMessage().send(message, event.getPlayer(), event.getRightClicked().getName(), prefix.getColorCode() + prefix.getChatPrefix()); + Object[] parameters = new Object[]{event.getRightClicked().getName(),prefix.getColorCode() + prefix.getChatPrefix()}; + String message; + try { + message = LobbySystem.getMessage().parsePrefixed("NPC_CHAT_" + user.getId() + "_" + random.nextInt(6), event.getPlayer(),parameters); + } catch (Exception e) { + message = LobbySystem.getMessage().parsePrefixed("NPC_CHAT_" + random.nextInt(6), event.getPlayer(),parameters); + } + event.getPlayer().sendMessage(message); } @EventHandler From ca0f82897ee14b9c84a7a82d069ae633438655d5 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 28 Dec 2024 18:26:04 +0100 Subject: [PATCH 017/106] Remove anti pickaxe drop code --- .../src/de/steamwar/tntleague/events/IngameListener.kt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt index e48ea7e6..ca379821 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt @@ -27,13 +27,11 @@ import de.steamwar.tntleague.inventory.DealerInventory import de.steamwar.tntleague.util.TNTLeagueScoreboard import org.bukkit.GameMode import org.bukkit.Location -import org.bukkit.Material import org.bukkit.entity.EntityType import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.entity.EntityExplodeEvent import org.bukkit.event.player.PlayerAttemptPickupItemEvent -import org.bukkit.event.player.PlayerDropItemEvent import org.bukkit.event.player.PlayerInteractEntityEvent import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.event.player.PlayerMoveEvent @@ -74,13 +72,6 @@ object IngameListener: Listener { } } - @EventHandler - fun onDropPickaxe(e: PlayerDropItemEvent) { - if (e.itemDrop.itemStack.type == Material.DIAMOND_PICKAXE) { - e.isCancelled = true - } - } - @EventHandler fun onPickupCoins(e: PlayerAttemptPickupItemEvent) { if (e.item.itemStack.isSimilar(DealerInventory.coins)) { From f52cec04484c91c5c4467f3ea1d6461a5374742c Mon Sep 17 00:00:00 2001 From: TheBreadBeard Date: Sat, 28 Dec 2024 22:58:35 +0100 Subject: [PATCH 018/106] Add custom NPC Chats for TheBreadBeard --- LobbySystem/src/de/steamwar/lobby/LobbySystem.properties | 5 +++++ .../src/de/steamwar/lobby/LobbySystem_de.properties | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties index 7469e86e..275a99a8 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties @@ -12,6 +12,11 @@ NPC_CHAT_4 = §fYou can develop your own buildserver features with our Lua scrip NPC_CHAT_5 = §fThere are many secrets to discover in this lobby. ## TheBreadBeard NPC_CHAT_3266_0 = §fI collect Alts like Infinity Stones. +NPC_CHAT_3266_1 = &fYou want my Bread? You can have it! Just look for it! I've hidden the best bakery in the world somewhere! +NPC_CHAT_3266_2 = &fHey, I am TheBreadBeard, ex- EuropSuchties Player, formerly (un)known as WarGear_Titan. +NPC_CHAT_3266_3 = &fInventor of Lactose Intolerance, the Placeholder and Infinity-Ring. All technical principles no one knows or needs. +NPC_CHAT_3266_4 = &fKnown for the Lobby-Banners, logos, spontaneous Arenas, as well as an Organizer and Moderator of many Events. +NPC_CHAT_3266_5 = &fFrom Supporter to Moderator to Builder ... Maybe the journey takes me to being a Developer next. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Lists all portals diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties index f7422e89..bf382639 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties @@ -11,7 +11,12 @@ NPC_CHAT_3 = §fBewerbe dich gerne für unser Team über unseren Discord-Server NPC_CHAT_4 = §fDu kannst mit unserm Lua Script-System deine eigenen Bau Features programmieren. NPC_CHAT_5 = §fAuf dieser Lobby sind so einige secrets versteckt. ## TheBreadBeard -NPC_CHAT_3266_0 = §fIch sammle Alts wie Infinity Stones. +NPC_CHAT_3266_0 = §fIch sammel Alts wie Infinity Stones. +NPC_CHAT_3266_1 = &fIhr wollt meine Teigwaren? Die könnt ihr haben! Sucht sie doch! Irgendwo hab ich die beste Bäckerei der Welt versteckt! +NPC_CHAT_3266_2 = &fMoin, Ich bin TheBreadBeard, ehemaliger EuropSuchties Spieler, damals (un)bekannt als WarGear_Titan. +NPC_CHAT_3266_3 = &fErfinder der Laktoseintoleranz, des Platzhalters und des Infinity-Rings. Alles Prinzipien, die keiner kennt und keiner braucht. +NPC_CHAT_3266_4 = &fBekannt für die Lobbybanner, Logos, spontane Arenen, sowie als Leiter von so manchem Event. +NPC_CHAT_3266_5 = &fVon Supporter zu Moderator zu Builder ... Vielleicht führt mich die Reise als Nächstes zum Developer. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Listet alle Portale auf From 7dc56863891b577603612b41adffc02d3bbf81ba Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 31 Dec 2024 11:25:00 +0100 Subject: [PATCH 019/106] Fixes... --- .../src/de/steamwar/core/WorldEditWrapper14.java | 9 ++++----- .../src/de/steamwar/core/WorldEditWrapper18.java | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java index ca96d554..6f5d0ffc 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java @@ -389,7 +389,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper { inputStream.close(); } } - private static class SpongeSchematicReader extends NBTSchematicReader { + public static class SpongeSchematicReader extends NBTSchematicReader { private final NBTInputStream inputStream; private DataFixer fixer = null; @@ -420,7 +420,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper { dataVersion = 1631; // this is a relatively safe assumption unless someone imports a schematic from 1.12, e.g. sponge 7.1- fixer = platform.getDataFixer(); return readVersion1(schematicTag); - } else if (schematicVersion == 2) { + } else if (schematicVersion == 2 || schematicVersion == 3) { dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue(); if (dataVersion < liveDataVersion) { fixer = platform.getDataFixer(); @@ -449,9 +449,6 @@ public class WorldEditWrapper14 implements WorldEditWrapper { private CompoundTag getBaseTag() throws IOException { NamedTag rootTag = inputStream.readNamedTag(); - if (!rootTag.getName().equals("Schematic")) { - throw new IOException("Tag 'Schematic' does not exist or is not first"); - } CompoundTag schematicTag = (CompoundTag) rootTag.getTag(); // Check @@ -460,6 +457,8 @@ public class WorldEditWrapper14 implements WorldEditWrapper { if (schematic.size() == 1) { schematicTag = requireTag(schematic, "Schematic", CompoundTag.class); schematic = schematicTag.getValue(); + } else if (!rootTag.getName().equals("Schematic")) { + throw new IOException("Tag 'Schematic' does not exist or is not first"); } schematicVersion = requireTag(schematic, "Version", IntTag.class).getValue(); diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java index b381ecf7..1c674150 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java @@ -40,7 +40,8 @@ public class WorldEditWrapper18 extends WorldEditWrapper14 { case MCEDIT: return new MCEditSchematicReader(nbtStream).read(); case SPONGE_V2: - return new SpongeSchematicReader(nbtStream).read(); + case SPONGE_V3: + return new WorldEditWrapper14.SpongeSchematicReader(nbtStream).read(); default: throw new IllegalArgumentException("Unsupported schematic format"); } From c1dbce464800c1aaf3d0972e45f87b5f1de68e71 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 31 Dec 2024 18:56:42 +0100 Subject: [PATCH 020/106] Fix EventListener.onPlayerQuit --- .../bausystem/features/script/event/EventListener.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java index 3eb099aa..4c5feada 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java @@ -24,7 +24,6 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.script.ScriptRunner; import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin; import de.steamwar.bausystem.features.script.lua.libs.StorageLib; -import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; @@ -32,7 +31,6 @@ import de.steamwar.core.TrickyTrialsWrapper; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -72,9 +70,10 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onPlayerQuit(PlayerQuitEvent event) { + if(Permission.BUILD.hasPermission(event.getPlayer())) { + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event); + } StorageLib.removePlayer(event.getPlayer()); - if(!Permission.BUILD.hasPermission(event.getPlayer())) return; - ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event); } @EventHandler(priority = EventPriority.HIGH) From d64e32eaa56317c7ad530a39f8bb21069652d201 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Jan 2025 12:56:49 +0100 Subject: [PATCH 021/106] Cleanup code --- .../src/de/steamwar/lobby/team/TeamPlayer.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java b/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java index a42d184a..989fca7a 100644 --- a/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java +++ b/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java @@ -23,7 +23,6 @@ import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.display.NPC; import de.steamwar.lobby.listener.BasicListener; import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserPerm; import lombok.AllArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -135,6 +134,10 @@ public class TeamPlayer extends BasicListener { return false; } + private String parseRandomMessage(Player player, SteamwarUser target, String message) throws MissingResourceException { + return LobbySystem.getMessage().parsePrefixed(message + random.nextInt(6), player, target.getUserName(), target.prefix().getColorCode() + target.prefix().getChatPrefix()); + } + @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if (!(event.getRightClicked() instanceof Villager)) { @@ -144,14 +147,13 @@ public class TeamPlayer extends BasicListener { players.remove(event.getPlayer()); return; } - SteamwarUser user = SteamwarUser.get(event.getRightClicked().getName()); - UserPerm.Prefix prefix = user.prefix(); - Object[] parameters = new Object[]{event.getRightClicked().getName(),prefix.getColorCode() + prefix.getChatPrefix()}; + + SteamwarUser target = SteamwarUser.get(event.getRightClicked().getName()); String message; try { - message = LobbySystem.getMessage().parsePrefixed("NPC_CHAT_" + user.getId() + "_" + random.nextInt(6), event.getPlayer(),parameters); - } catch (Exception e) { - message = LobbySystem.getMessage().parsePrefixed("NPC_CHAT_" + random.nextInt(6), event.getPlayer(),parameters); + message = parseRandomMessage(event.getPlayer(), target, "NPC_CHAT_" + target.getId() + "_"); + } catch (MissingResourceException e) { + message = parseRandomMessage(event.getPlayer(), target, "NPC_CHAT_"); } event.getPlayer().sendMessage(message); } From 025ec2a850470e7b55d39a16c48655533ccb7b6b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 1 Jan 2025 14:12:38 +0100 Subject: [PATCH 022/106] Hotfix: 1.20 Schematic Reader --- .../de/steamwar/core/WorldEditWrapper14.java | 13 ++++++-- .../de/steamwar/core/WorldEditWrapper18.java | 30 +++++-------------- .../de/steamwar/core/WorldEditWrapper21.java | 1 + 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java index 6f5d0ffc..3251e5bc 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java @@ -54,6 +54,7 @@ import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; +@SuppressWarnings("removal") public class WorldEditWrapper14 implements WorldEditWrapper { @Override @@ -88,7 +89,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper { switch (schemFormat) { case SPONGE_V2: case SPONGE_V3: - return new SpongeSchematicReader(new NBTInputStream(is)).read(); + return new SpongeSchematicReader(new NBTInputStream(is), this).read(); case MCEDIT: return new MCEditSchematicReader(new NBTInputStream(is)).read(); default: @@ -126,6 +127,10 @@ public class WorldEditWrapper14 implements WorldEditWrapper { return NodeData.SchematicFormat.SPONGE_V2; } + public Map applyDataFixer(DataFixer fixer, int dataVersion, Map values) { + return fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values), dataVersion).getValue(); + } + private static class MCEditSchematicReader extends NBTSchematicReader { private final NBTInputStream inputStream; @@ -396,15 +401,17 @@ public class WorldEditWrapper14 implements WorldEditWrapper { private int schematicVersion = -1; private int dataVersion = -1; private boolean faweSchem = false; + private final WorldEditWrapper14 wrapper; /** * Create a new instance. * * @param inputStream the input stream to read from */ - public SpongeSchematicReader(NBTInputStream inputStream) { + public SpongeSchematicReader(NBTInputStream inputStream, WorldEditWrapper14 wrapper) { checkNotNull(inputStream); this.inputStream = inputStream; + this.wrapper = wrapper; } @Override @@ -572,7 +579,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper { values.remove("Id"); values.remove("Pos"); if (fixer != null) { - tileEntity = fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values), dataVersion).getValue(); + tileEntity = wrapper.applyDataFixer(fixer, dataVersion, values); } else { tileEntity = values; } diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java index 1c674150..1c216a1a 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java @@ -19,34 +19,18 @@ package de.steamwar.core; -import com.sk89q.jnbt.NBTInputStream; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.extent.clipboard.io.*; -import de.steamwar.sql.NoClipboardException; -import de.steamwar.sql.NodeData; +import com.sk89q.jnbt.AdventureNBTConverter; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.Tag; +import com.sk89q.worldedit.world.DataFixer; -import java.io.IOException; -import java.io.InputStream; +import java.util.Map; public class WorldEditWrapper18 extends WorldEditWrapper14 { @Override @SuppressWarnings("removal") - public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { - NBTInputStream nbtStream = new NBTInputStream(is); - //Use FAWE reader due to FAWE capability of reading corrupt FAWE schems - try { - switch (schemFormat) { - case MCEDIT: - return new MCEditSchematicReader(nbtStream).read(); - case SPONGE_V2: - case SPONGE_V3: - return new WorldEditWrapper14.SpongeSchematicReader(nbtStream).read(); - default: - throw new IllegalArgumentException("Unsupported schematic format"); - } - } catch (NullPointerException e) { - throw new NoClipboardException(); - } + public Map applyDataFixer(DataFixer fixer, int dataVersion, Map values) { + return ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values).asBinaryTag(), dataVersion))).getValue(); } } diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java index d93c095d..52947f3a 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java @@ -67,6 +67,7 @@ public class WorldEditWrapper21 implements WorldEditWrapper { } @Override + @SuppressWarnings("removal") public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { return switch (schemFormat) { case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(is)).read(); From 6b7825ead9965c2424b5bb02102a96dd82fc95fc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Jan 2025 11:05:07 +0100 Subject: [PATCH 023/106] Fix version matching --- .../src/de/steamwar/velocitycore/GameModeConfig.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java index 74fb19bf..208f6df3 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java @@ -27,12 +27,13 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; +import java.util.regex.Matcher; import java.util.regex.Pattern; @Getter public class GameModeConfig { - private static final Pattern terminatingNumber = Pattern.compile("\\D+(\\d+)$"); + private static final Pattern terminatingNumber = Pattern.compile("(\\d+)$"); public static void loadAll(Class config, BiConsumer consumer) { File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); @@ -70,7 +71,9 @@ public class GameModeConfig { } public ServerVersion getVersion() { - return ServerVersion.valueOf((getServer().isSpigot() ? "SPIGOT_" : "PAPER_") + terminatingNumber.matcher(getServer().getFolder()).group(1)); + Matcher matcher = terminatingNumber.matcher(getServer().getFolder()); + matcher.find(); + return ServerVersion.valueOf((getServer().isSpigot() ? "SPIGOT_" : "PAPER_") + matcher.group(1)); } public String getFolder() { From 9f0f11adebf68c802c1a3a7348d4e8380dfbb840 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Jan 2025 17:24:37 +0100 Subject: [PATCH 024/106] Fix entity orientation --- .../src/de/steamwar/core/BountifulWrapper21.java | 2 +- .../src/de/steamwar/core/BountifulWrapper8.java | 7 +++---- .../src/de/steamwar/core/BountifulWrapper9.java | 14 +++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java index d144c9b6..f7ed9508 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java @@ -33,7 +33,7 @@ public class BountifulWrapper21 extends BountifulWrapper9 { return (packet, x, y, z, pitch, yaw) -> { PositionMoveRotation pos = field.get(packet); - field.set(packet, new PositionMoveRotation(new Vec3D(x, y, z), pos.b(), pitch, yaw)); + field.set(packet, new PositionMoveRotation(new Vec3D(x, y, z), pos.b(), yaw, pitch)); }; } catch (IllegalArgumentException e) { return super.getPositionSetter(packetClass, fieldOffset); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java index 54ea45b3..2b7aeab7 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java @@ -25,7 +25,6 @@ import net.md_5.bungee.api.chat.BaseComponent; import net.minecraft.server.v1_8_R3.ChatComponentText; import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.PacketPlayOutChat; -import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -71,15 +70,15 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { Reflection.FieldAccessor posX = Reflection.getField(packetClass, int.class, fieldOffset); Reflection.FieldAccessor posY = Reflection.getField(packetClass, int.class, fieldOffset +1); Reflection.FieldAccessor posZ = Reflection.getField(packetClass, int.class, fieldOffset +2); - Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, byte.class, 0); - Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, byte.class, 1); + Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, byte.class, 0); + Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, byte.class, 1); return (packet, x, y, z, pitch, yaw) -> { posX.set(packet, MathHelper.floor(x * 32)); posY.set(packet, MathHelper.floor(y * 32)); posZ.set(packet, MathHelper.floor(z * 32)); - lookPitch.set(packet, (byte)(pitch * 256 / 360)); lookYaw.set(packet, (byte)(yaw * 256 / 360)); + lookPitch.set(packet, (byte)(pitch * 256 / 360)); }; } diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index fa126698..300d6c8d 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -67,19 +67,19 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { Reflection.FieldAccessor posZ = Reflection.getField(packetClass, double.class, fieldOffset+2); boolean isByteClass = packetClass.getSimpleName().contains("PacketPlayOutEntityTeleport") || packetClass.getSimpleName().contains("PacketPlayOutNamedEntitySpawn"); Class pitchYawType = isByteClass ? byte.class : int.class; - Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, pitchYawType, isByteClass ? 0 : 1); - Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, pitchYawType, isByteClass ? 1 : 2); + Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, pitchYawType, isByteClass ? 0 : 1); + Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, pitchYawType, isByteClass ? 1 : 2); return (packet, x, y, z, pitch, yaw) -> { posX.set(packet, x); posY.set(packet, y); posZ.set(packet, z); if (isByteClass) { - lookPitch.set(packet, (byte) (pitch*256/360)); lookYaw.set(packet, (byte) (yaw*256/360)); + lookPitch.set(packet, (byte) (pitch*256/360)); } else { - lookPitch.set(packet, (int) (pitch*256/360)); lookYaw.set(packet, (int) (yaw*256/360)); + lookPitch.set(packet, (int) (pitch*256/360)); } }; } @@ -90,15 +90,15 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { Reflection.FieldAccessor moveX = Reflection.getField(packetClass, "b", type); Reflection.FieldAccessor moveY = Reflection.getField(packetClass, "c", type); Reflection.FieldAccessor moveZ = Reflection.getField(packetClass, "d", type); - Reflection.FieldAccessor movePitch = Reflection.getField(packetClass, "e", byte.class); - Reflection.FieldAccessor moveYaw = Reflection.getField(packetClass, "f", byte.class); + Reflection.FieldAccessor moveYaw = Reflection.getField(packetClass, "e", byte.class); + Reflection.FieldAccessor movePitch = Reflection.getField(packetClass, "f", byte.class); return (packet, x, y, z, pitch, yaw) -> { moveX.set(packet, (short)(x*4096)); moveY.set(packet, (short)(y*4096)); moveZ.set(packet, (short)(z*4096)); - movePitch.set(packet, (byte)(pitch*256/360)); moveYaw.set(packet, (byte)(yaw*256/360)); + movePitch.set(packet, (byte)(pitch*256/360)); }; } From a3490b801e0223ebcfa938953411d70fe4d4dd0c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 3 Jan 2025 12:55:59 +0100 Subject: [PATCH 025/106] Fix server transfer failure after checkpoint restoration --- .../Persistent/src/de/steamwar/persistent/Subserver.java | 1 + 1 file changed, 1 insertion(+) diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java index d4290814..9050255e 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java @@ -220,6 +220,7 @@ public class Subserver { try { if (checkpoint) { start(process.getErrorStream(), line -> line.contains("Restore finished successfully.")); + Thread.sleep(300); //Wait for port to be reopened } else { start(process.getInputStream(), line -> { if (line.contains("Loading libraries, please wait")) From 088965df595059cdea5ee354fc370b3867dcdf5a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Jan 2025 21:25:32 +0100 Subject: [PATCH 026/106] Potential fix for true IP for floodgate players --- .../velocitycore/listeners/IPSanitizer.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/IPSanitizer.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/IPSanitizer.java index 7b0876a5..bc8c42ba 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/IPSanitizer.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/IPSanitizer.java @@ -20,6 +20,7 @@ package de.steamwar.velocitycore.listeners; import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.proxy.connection.MinecraftConnection; @@ -32,21 +33,32 @@ import de.steamwar.velocitycore.mods.Hostname; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; import java.util.logging.Level; public class IPSanitizer extends BasicListener { - private static final Reflection.Field remoteAddress = new Reflection.Field<>(MinecraftConnection.class, "remoteAddress"); + private static final Map trueAddress = new HashMap<>(); // Will likely slightly leak over time public static InetAddress getTrueAddress(Player player) { - return ((InetSocketAddress) ((ConnectedPlayer)player).getConnection().getChannel().remoteAddress()).getAddress(); + return trueAddress.getOrDefault(player.getUniqueId(), ((InetSocketAddress) ((ConnectedPlayer)player).getConnection().getChannel().remoteAddress()).getAddress()); } - private final InetSocketAddress sanitized = new InetSocketAddress("127.127.127.127", 25565); + private static final Reflection.Field remoteAddress = new Reflection.Field<>(MinecraftConnection.class, "remoteAddress"); + private static final InetSocketAddress sanitized = new InetSocketAddress("127.127.127.127", 25565); @Subscribe public void loginEvent(PreLoginEvent e) { - VelocityCore.getLogger().log(Level.INFO, "%s has logged in with user name %s".formatted(e.getConnection().getRemoteAddress(), e.getUsername())); + InetSocketAddress address = e.getConnection().getRemoteAddress(); + VelocityCore.getLogger().log(Level.INFO, "%s has logged in with user name %s".formatted(address, e.getUsername())); + trueAddress.put(e.getUniqueId(), address.getAddress()); remoteAddress.set(Hostname.getInitialInboundConnection((LoginInboundConnection) e.getConnection()).getConnection(), sanitized); } + + @Subscribe + public void disconnectEvent(DisconnectEvent e) { + trueAddress.remove(e.getPlayer().getUniqueId()); + } } From da148c0e9fc448ed081178e26d923d212c3bccaf Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 6 Jan 2025 10:15:48 +0100 Subject: [PATCH 027/106] Replace {nms} and {obc} tags --- .../bausystem/utils/NMSWrapper15.java | 2 +- .../bausystem/utils/NMSWrapper18.java | 2 +- .../bausystem/utils/NMSWrapper19.java | 2 +- .../bausystem/utils/NMSWrapper20.java | 2 +- .../features/observer/ObserverTracer.java | 2 +- .../features/simulator/SimulatorCursor.java | 6 ++--- .../smartplace/SmartPlaceListener.java | 2 +- .../features/tpslimit/PacketCache.java | 10 ++++---- .../features/tpslimit/TPSFreezeUtils.java | 4 ++-- .../features/tpslimit/TPSLimitUtils.java | 4 ++-- .../features/util/NoClipCommand.java | 14 +++++------ .../features/world/AntiCursorReCentering.java | 2 +- .../features/world/NoCreativeKnockback.java | 2 +- .../features/world/SignEditFrom20.java | 12 +++++----- .../features/world/SignEditUntil19.java | 12 +++++----- .../bausystem/features/xray/XrayCommand.java | 4 ++-- .../bausystem/utils/PlaceItemUtils.java | 6 ++--- .../fightsystem/utils/BlockIdWrapper14.java | 16 ++++++------- .../fightsystem/utils/BlockIdWrapper18.java | 2 +- .../utils/CraftbukkitWrapper18.java | 4 ++-- .../fightsystem/utils/HullHiderWrapper18.java | 2 +- .../fightsystem/utils/BlockIdWrapper8.java | 6 ++--- .../fightsystem/utils/HullHiderWrapper8.java | 4 ++-- .../fightsystem/utils/BountifulWrapper9.java | 2 +- .../fightsystem/commands/Commands.java | 2 +- .../de/steamwar/fightsystem/fight/Kit.java | 6 ++--- .../fightsystem/listener/ArrowStopper.java | 2 +- .../fightsystem/listener/ClickAnalyzer.java | 2 +- .../fightsystem/listener/Recording.java | 8 +++---- .../fightsystem/utils/BlockIdWrapper.java | 8 +++---- .../steamwar/fightsystem/utils/HullHider.java | 12 +++++----- .../misslewars/slowmo/SlowMoUtils.java | 4 ++-- .../de/steamwar/core/FlatteningWrapper14.java | 20 ++++++++-------- .../src/de/steamwar/techhider/BlockIds14.java | 10 ++++---- .../steamwar/core/CraftbukkitWrapper18.java | 2 +- .../de/steamwar/core/ProtocolWrapper18.java | 8 +++---- .../steamwar/core/CraftbukkitWrapper20.java | 2 +- .../steamwar/core/CraftbukkitWrapper21.java | 2 +- .../de/steamwar/core/BountifulWrapper8.java | 2 +- .../src/de/steamwar/core/ChatWrapper8.java | 4 ++-- .../de/steamwar/core/FlatteningWrapper8.java | 10 ++++---- .../de/steamwar/core/ProtocolWrapper8.java | 10 ++++---- .../de/steamwar/scoreboard/SWScoreboard8.java | 4 ++-- .../de/steamwar/techhider/ChunkHider8.java | 2 +- .../steamwar/techhider/ProtocolWrapper8.java | 6 ++--- .../de/steamwar/core/BountifulWrapper9.java | 8 +++---- .../de/steamwar/core/CraftbukkitWrapper9.java | 6 ++--- .../de/steamwar/techhider/ChunkHider9.java | 2 +- .../comphenix/tinyprotocol/TinyProtocol.java | 12 +++++----- .../src/de/steamwar/core/CommandRemover.java | 2 +- .../de/steamwar/core/FlatteningWrapper.java | 4 ++-- .../src/de/steamwar/core/ProtocolWrapper.java | 14 +++++------ .../src/de/steamwar/core/TPSWatcher.java | 2 +- .../core/authlib/AuthlibInjector.java | 2 +- .../de/steamwar/core/events/AntiNocom.java | 6 ++--- .../src/de/steamwar/entity/REntity.java | 22 ++++++++--------- .../src/de/steamwar/entity/REntityServer.java | 4 ++-- .../src/de/steamwar/entity/RPlayer.java | 2 +- .../network/handlers/ServerDataHandler.java | 4 ++-- .../src/de/steamwar/techhider/TechHider.java | 24 +++++++++---------- 60 files changed, 182 insertions(+), 182 deletions(-) diff --git a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index f279980d..37ec1c93 100644 --- a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -114,7 +114,7 @@ public class NMSWrapper15 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); diff --git a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index 22438d02..d3abe191 100644 --- a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -120,7 +120,7 @@ public class NMSWrapper18 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); diff --git a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index 2c5b2415..476f1921 100644 --- a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -119,7 +119,7 @@ public class NMSWrapper19 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); diff --git a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java index a6d0a8e5..3a8cb1bd 100644 --- a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java +++ b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java @@ -121,7 +121,7 @@ public class NMSWrapper20 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java index 75cecff5..c1e08fcf 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java @@ -170,7 +170,7 @@ public class ObserverTracer { } } - private static final Class craftPoweredRail = Reflection.getClass("{obc}.block.impl.CraftPoweredRail"); + private static final Class craftPoweredRail = Reflection.getClass("org.bukkit.craftbukkit.block.impl.CraftPoweredRail"); private boolean checkAllowed(Block block, BlockData blockData) { if (checkMaterial(block)) return true; if (block.getType() == Material.BELL) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 23261b62..6d47f7fe 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -72,9 +72,9 @@ import java.util.stream.Collectors; public class SimulatorCursor implements Listener { private final World WORLD = Bukkit.getWorlds().get(0); - private Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); - private Class look = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInLook"); - private Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); + private Class position = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); + private Class look = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInLook"); + private Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); private Map cursorType = Collections.synchronizedMap(new HashMap<>()); private Map cursors = Collections.synchronizedMap(new HashMap<>()); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 36cb3847..764501bc 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -81,7 +81,7 @@ public class SmartPlaceListener implements Listener { IGNORED.remove(Material.BARRIER); } - private static final Class useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); + private static final Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"); private static final Set SMART_PLACING = new HashSet<>(); private static final Set WAS_EXECUTED = new HashSet<>(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java index fd8eb66b..a7ebbfd1 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java @@ -45,17 +45,17 @@ class PacketCache { private static Set entities = new HashSet<>(); private static BukkitTask task = null; - private static Class vec3dClass = Reflection.getClass("{nms.world.phys}.Vec3D"); + private static Class vec3dClass = Reflection.getClass("net.minecraft.world.phys.Vec3D"); private static Reflection.Field zeroVec3d = (Reflection.Field) Reflection.getField(vec3dClass, vec3dClass, 0); private static Object ZERO_VEC3D = zeroVec3d.get(null); - private static Class velocityPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); + private static Class velocityPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity"); private static Reflection.Constructor velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass); - private static Class teleportPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); - private static Class entityClass = Reflection.getClass("{nms.world.entity}.Entity"); + private static Class teleportPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport"); + private static Class entityClass = Reflection.getClass("net.minecraft.world.entity.Entity"); private static Reflection.Constructor teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass); - private static Class craftEntityClass = Reflection.getClass("{obc}.entity.CraftEntity"); + private static Class craftEntityClass = Reflection.getClass("org.bukkit.craftbukkit.entity.CraftEntity"); private static Reflection.Method getHandle = Reflection.getMethod(craftEntityClass, "getHandle"); private static Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5, Boolean.class); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java index 45b6154f..a1ae36a2 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java @@ -32,7 +32,7 @@ public class TPSFreezeUtils { @Getter private static final boolean canFreeze; - private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", null); @Getter private static boolean frozen = false; @@ -42,7 +42,7 @@ public class TPSFreezeUtils { static { Reflection.Field fieldAccessor; try { - fieldAccessor = Reflection.getField(Reflection.getClass("{nms.server.level}.WorldServer"), "freezed", boolean.class); + fieldAccessor = Reflection.getField(Reflection.getClass("net.minecraft.server.level.WorldServer"), "freezed", boolean.class); } catch (IllegalArgumentException e) { fieldAccessor = null; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java index 83b8e104..62ae1b5c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java @@ -101,8 +101,8 @@ public class TPSLimitUtils { } */ - private static final Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); - private static final Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); + private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); + private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); static { BiFunction positionSetter = (player, o) -> { if (tpsLimiter != null) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index 565286a1..5e7a1b1f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -49,15 +49,15 @@ import java.util.function.BiFunction; @Linked public class NoClipCommand extends SWCommand implements Listener { - public static final Class gameStateChange = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutGameStateChange"); + public static final Class gameStateChange = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutGameStateChange"); private static final Reflection.Field floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); - private static final Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); - private static final Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); - private static final Class useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); - private static final Class blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); - private static final Class windowClick = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInWindowClick"); - private static final Class setSlotStack = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInSetCreativeSlot"); + private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); + private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); + private static final Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"); + private static final Class blockDig = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockDig"); + private static final Class windowClick = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInWindowClick"); + private static final Class setSlotStack = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot"); @Getter private static final List NOCLIPS = new ArrayList<>(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java index 646120d3..acb95394 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java @@ -32,7 +32,7 @@ public class AntiCursorReCentering implements Enable { @Override public void enable() { - Class closeWindow = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutCloseWindow"); + Class closeWindow = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutCloseWindow"); TinyProtocol.instance.addFilter(closeWindow, (player, object) -> { if (player.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) { return object; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java index 72146f9d..2a102972 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java @@ -29,7 +29,7 @@ import org.bukkit.GameMode; public class NoCreativeKnockback { public NoCreativeKnockback() { - TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"), (player, o) -> { + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"), (player, o) -> { if (player.getGameMode() != GameMode.CREATIVE) return o; return NMSWrapper.impl.resetExplosionKnockback(o); }); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java index 4fc0cb31..4618010d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java @@ -48,19 +48,19 @@ import org.bukkit.util.Vector; @MinVersion(20) public class SignEditFrom20 implements Listener { - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlock"); - private static final Class craftWorld = Reflection.getClass("{obc}.CraftWorld"); - private static final Class generatorAccess = Reflection.getClass("{nms.world.level}.GeneratorAccess"); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); + private static final Class craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock"); + private static final Class craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"); + private static final Class generatorAccess = Reflection.getClass("net.minecraft.world.level.GeneratorAccess"); private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); - private static final Class openSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenSignEditor"); + private static final Class openSign = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor"); private static final Reflection.Field blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); private static final Reflection.Field sideFieldAccessor = Reflection.getField(openSign, boolean.class, 0); - private static final Class updateSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUpdateSign"); + private static final Class updateSign = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUpdateSign"); private static final Reflection.Field getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); private static final Reflection.Field stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java index 81cf2786..edf38e68 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java @@ -40,18 +40,18 @@ import org.bukkit.event.player.PlayerInteractEvent; @MaxVersion(19) public class SignEditUntil19 implements Listener { - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlock"); - private static final Class craftWorld = Reflection.getClass("{obc}.CraftWorld"); - private static final Class generatorAccess = Reflection.getClass("{nms.world.level}.GeneratorAccess"); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); + private static final Class craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock"); + private static final Class craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"); + private static final Class generatorAccess = Reflection.getClass("net.minecraft.world.level.GeneratorAccess"); private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); - private static final Class openSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenSignEditor"); + private static final Class openSign = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor"); private static final Reflection.Field blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); - private static final Class updateSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUpdateSign"); + private static final Class updateSign = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUpdateSign"); private static final Reflection.Field getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); private static final Reflection.Field stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index da7981ae..e12a3f76 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -108,8 +108,8 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen }); } - private static final Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); - private static final Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); + private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); + private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); { BiFunction positionSetter = (player, o) -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java index e235cae4..1ede0f63 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java @@ -81,10 +81,10 @@ public class PlaceItemUtils { .collect(Collectors.toSet()); } - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); private static final Reflection.Constructor blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); - private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlockState"); - private static final Class craftWorld = Reflection.getClass("{obc}.CraftWorld"); + private static final Class craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlockState"); + private static final Class craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"); private static final Reflection.Field positionAccessor = Reflection.getField(craftBlock, blockPosition, 0); private static final Reflection.Field worldAccessor = Reflection.getField(craftBlock, craftWorld, 0); diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index 84eba7c4..5d3dfbd0 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -33,14 +33,14 @@ import java.util.Map; public class BlockIdWrapper14 implements BlockIdWrapper { - private static final Class chunkProviderServer = Reflection.getClass("{nms.server.level}.ChunkProviderServer"); + private static final Class chunkProviderServer = Reflection.getClass("net.minecraft.server.level.ChunkProviderServer"); private static final Reflection.Method getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); - private static final Class playerChunkMap = Reflection.getClass("{nms.server.level}.PlayerChunkMap"); + private static final Class playerChunkMap = Reflection.getClass("net.minecraft.server.level.PlayerChunkMap"); private static final Reflection.Field getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0); private static final Reflection.Field entityTrackers = Core.getVersion() > 15 ? Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0) : Reflection.getField(playerChunkMap, org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap.class, 0); - private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); - private static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); + private static final Class block = Reflection.getClass("net.minecraft.world.level.block.Block"); + private static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.IBlockData"); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); private final Map trackers; public BlockIdWrapper14() { @@ -48,7 +48,7 @@ public class BlockIdWrapper14 implements BlockIdWrapper { } private static final Reflection.Method getCombinedId = Reflection.getTypedMethod(block, null, int.class, iBlockData); - private static final Reflection.Method getNMS = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.CraftBlock"), "getNMS", iBlockData); + private static final Reflection.Method getNMS = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock"), "getNMS", iBlockData); @Override public int blockToId(Block block) { return (int) getCombinedId.invoke(null, getNMS.invoke(block)); @@ -70,7 +70,7 @@ public class BlockIdWrapper14 implements BlockIdWrapper { flagDirty.invoke(getChunkProvider.invoke(nworld), pos); } - private static final Class entityTracker = Reflection.getClass("{nms.server.level}.PlayerChunkMap$EntityTracker"); + private static final Class entityTracker = Reflection.getClass("net.minecraft.server.level.PlayerChunkMap$EntityTracker"); private static final Reflection.Method updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, Entity entity) { @@ -87,7 +87,7 @@ public class BlockIdWrapper14 implements BlockIdWrapper { clearPlayer.invoke(tracker, getPlayer.invoke(player)); } - private static final Reflection.Method getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("{obc}.util.CraftMagicNumbers"), "getMaterial", Material.class, block); + private static final Reflection.Method getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"), "getMaterial", Material.class, block); private static final Reflection.Method getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); @Override public Material idToMaterial(int blockState) { diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java index 682fc30f..66ea9b08 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java @@ -27,7 +27,7 @@ import java.util.*; public class BlockIdWrapper18 extends BlockIdWrapper14 { - private static final Reflection.Field hiddenEntities = Reflection.getField(Reflection.getClass("{obc}.entity.CraftPlayer"), Map.class, 0, UUID.class, Set.class); + private static final Reflection.Field hiddenEntities = Reflection.getField(Reflection.getClass("org.bukkit.craftbukkit.entity.CraftPlayer"), Map.class, 0, UUID.class, Set.class); @Override public void trackEntity(Player player, Entity entity) { hiddenEntities.get(player).remove(entity.getUniqueId()); diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java index 31c17cf1..8fa8e7de 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java @@ -33,7 +33,7 @@ import java.util.stream.StreamSupport; public class CraftbukkitWrapper18 implements CraftbukkitWrapper { - private static final Reflection.Method getWorld = Reflection.getMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle"); + private static final Reflection.Method getWorld = Reflection.getMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle"); private static final Reflection.Method getChunk = Reflection.getTypedMethod(net.minecraft.world.level.World.class, null, Chunk.class, int.class, int.class); private static final Reflection.Method getChunkSections = Reflection.getTypedMethod(Chunk.class, null, ChunkSection[].class); private ChunkSection[] getChunkSections(World world, int x, int z) { @@ -46,7 +46,7 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper { System.arraycopy(getChunkSections(backup, x, z), 0, sections, 0, sections.length); } - private static final Reflection.Method getEntity = Reflection.getTypedMethod(Reflection.getClass("{obc}.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class); + private static final Reflection.Method getEntity = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class); protected net.minecraft.world.entity.Entity getEntity(Entity e) { return (net.minecraft.world.entity.Entity) getEntity.invoke(e); } diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java index 7a378f43..9cee390f 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -33,7 +33,7 @@ import java.util.List; public class HullHiderWrapper18 implements HullHiderWrapper { - private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", IBlockData.class); + private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", IBlockData.class); @Override public Object generateBlockChangePacket(List changes) { Object[] blockdata = new Object[changes.size()]; diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index 94633486..5d06a7be 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -29,9 +29,9 @@ import org.bukkit.entity.Player; public class BlockIdWrapper8 implements BlockIdWrapper { - private static final Class entityTracker = Reflection.getClass("{nms}.EntityTracker"); + private static final Class entityTracker = Reflection.getClass("net.minecraft.EntityTracker"); private static final Reflection.Field getEntityTracker = Reflection.getField(worldServer, entityTracker, 0); - private static final Class intHashMap = Reflection.getClass("{nms}.IntHashMap"); + private static final Class intHashMap = Reflection.getClass("net.minecraft.IntHashMap"); private static final Reflection.Field getTrackedEntities = Reflection.getField(entityTracker, intHashMap, 0); private final Object trackers; @@ -54,7 +54,7 @@ public class BlockIdWrapper8 implements BlockIdWrapper { world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); } - private static final Class entityTrackerEntry = Reflection.getClass("{nms}.EntityTrackerEntry"); + private static final Class entityTrackerEntry = Reflection.getClass("net.minecraft.EntityTrackerEntry"); private static final Reflection.Method get = Reflection.getTypedMethod(intHashMap, "get", Object.class, int.class); private static final Reflection.Method updatePlayer = Reflection.getMethod(entityTrackerEntry, "updatePlayer", entityPlayer); @Override diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java index 231a8d0a..03647c5e 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java @@ -26,8 +26,8 @@ import java.util.List; public class HullHiderWrapper8 implements HullHiderWrapper { - private static final Reflection.Constructor newMultiBlockChange = Reflection.getConstructor("{nms}.PacketPlayOutMultiBlockChange", int.class, short[].class, Reflection.getClass("{nms}.Chunk")); - private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + private static final Reflection.Constructor newMultiBlockChange = Reflection.getConstructor("net.minecraft.PacketPlayOutMultiBlockChange", int.class, short[].class, Reflection.getClass("net.minecraft.Chunk")); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle"); @Override public Object generateBlockChangePacket(List changes) { Hull.IntVector chunk = changes.get(0); diff --git a/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index 67ac4f21..18031b0a 100644 --- a/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -43,7 +43,7 @@ import java.util.Map; public class BountifulWrapper9 implements BountifulWrapper { - private static final Class enumHand = Reflection.getClass("{nms.world}.EnumHand"); + private static final Class enumHand = Reflection.getClass("net.minecraft.world.EnumHand"); private static final Object mainHand = enumHand.getEnumConstants()[0]; private static final Reflection.Field blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java index 90bca61b..cff729df 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java @@ -39,7 +39,7 @@ import org.bukkit.entity.Player; @UtilityClass public class Commands { - private static final Reflection.Field commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); + private static final Reflection.Field commandMap = Reflection.getField("org.bukkit.craftbukkit.CraftServer", "commandMap", SimpleCommandMap.class); public static void injectCommand(Command cmd) { commandMap.get(Bukkit.getServer()).register("FightSystem", cmd); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index 08853b65..ea8617d6 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -215,9 +215,9 @@ public class Kit { return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty(); } - private static final Class itemStack = Reflection.getClass("{nms.world.item}.ItemStack"); - private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class); - private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); + private static final Class itemStack = Reflection.getClass("net.minecraft.world.item.ItemStack"); + private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class); + private static final Class nbtTagCompound = Reflection.getClass("net.minecraft.nbt.NBTTagCompound"); private static final Reflection.Method getTag = Reflection.getTypedMethod(itemStack, null, nbtTagCompound); private static final Reflection.Method getKeys = Reflection.getTypedMethod(nbtTagCompound, null, Set.class); public static boolean hasItems(ItemStack stack) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 18bc11ac..6b337646 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -41,7 +41,7 @@ public class ArrowStopper { new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); } - private static final Class entityArrow = Reflection.getClass("{nms.world.entity.projectile}.EntityArrow"); + private static final Class entityArrow = Reflection.getClass("net.minecraft.world.entity.projectile.EntityArrow"); private void run() { Recording.iterateOverEntities(entityArrow::isInstance, entity -> { Projectile arrow = (Projectile) entity; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java index 4ceed83c..3506ec25 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java @@ -43,7 +43,7 @@ public class ClickAnalyzer { public ClickAnalyzer() { TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace); if(Core.getVersion() > 8) - TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), this::onBlockPlace); + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"), this::onBlockPlace); } public Object onBlockPlace(Player player, Object packet) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 31b26c5e..7f6faa56 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -77,8 +77,8 @@ public class Recording implements Listener { return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; } - public static final Class primedTnt = Reflection.getClass("{nms.world.entity.item}.EntityTNTPrimed"); - private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("{nms.world.entity}.Entity"), "getBukkitEntity", null); + public static final Class primedTnt = Reflection.getClass("net.minecraft.world.entity.item.EntityTNTPrimed"); + private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.world.entity.Entity"), "getBukkitEntity", null); public static void iterateOverEntities(Predicate filter, Consumer consumer) { CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer); } @@ -129,7 +129,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entitySpeed(entity); } - private static final Class blockDigPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); + private static final Class blockDigPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockDig"); private static final Class playerDigType = blockDigPacket.getDeclaredClasses()[0]; private static final Reflection.Field blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0); private static final Object releaseUseItem = playerDigType.getEnumConstants()[5]; @@ -139,7 +139,7 @@ public class Recording implements Listener { return packet; } - public static final Class blockPlacePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockPlace"); + public static final Class blockPlacePacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockPlace"); private Object blockPlace(Player p, Object packet) { boolean mainHand = BountifulWrapper.impl.mainHand(packet); if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p)) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index 15d1b0f7..d6039f04 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -29,11 +29,11 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; public interface BlockIdWrapper { - Class worldServer = Reflection.getClass("{nms.server.level}.WorldServer"); - Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", worldServer); + Class worldServer = Reflection.getClass("net.minecraft.server.level.WorldServer"); + Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", worldServer); - Class craftPlayer = Reflection.getClass("{obc}.entity.CraftPlayer"); - Class entityPlayer = Reflection.getClass("{nms.server.level}.EntityPlayer"); + Class craftPlayer = Reflection.getClass("org.bukkit.craftbukkit.entity.CraftPlayer"); + Class entityPlayer = Reflection.getClass("net.minecraft.server.level.EntityPlayer"); Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); BlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 64ec3064..df1248ed 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -71,10 +71,10 @@ public class HullHider implements Listener { packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider); packetHiders.put(packetPlayOutExplosion, this::explosionHider); - posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutWorldParticles", Core.getVersion() >= 18 ? double.class : float.class, 1.0); - posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutNamedSoundEffect", int.class, 8.0); + posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutWorldParticles", Core.getVersion() >= 18 ? double.class : float.class, 1.0); + posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect", int.class, 8.0); if(Core.getVersion() >= 9 && Core.getVersion() < 18) - posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutCustomSoundEffect", int.class, 8.0); + posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect", int.class, 8.0); new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this); new StateDependent(TechHiderWrapper.ENABLED, FightState.Schem) { @@ -198,15 +198,15 @@ public class HullHider implements Listener { } - private static final Class packetPlayOutWorldEvent = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutWorldEvent"); + private static final Class packetPlayOutWorldEvent = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutWorldEvent"); private static final Reflection.Field worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0); - public static final Reflection.Field blockPositionY = Reflection.getField("{nms.core}.BaseBlockPosition", int.class, 1); + public static final Reflection.Field blockPositionY = Reflection.getField("net.minecraft.core.BaseBlockPosition", int.class, 1); private Object worldEventHider(Player player, Object packet) { Object baseBlock = worldEventPosition.get(packet); return packetHider(player, packet, new Location(Config.world, TechHider.blockPositionX.get(baseBlock), blockPositionY.get(baseBlock), TechHider.blockPositionZ.get(baseBlock))); } - private static final Class packetPlayOutExplosion = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + private static final Class packetPlayOutExplosion = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); private static final Reflection.Field explosionBlocks = Reflection.getField(packetPlayOutExplosion, List.class, 0); private static final Function explosionLocation = posPacketToLocation(packetPlayOutExplosion, double.class, 1.0); private Object explosionHider(Player player, Object packet) { diff --git a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java index 457ae789..10b2c05c 100644 --- a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java +++ b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java @@ -32,7 +32,7 @@ public class SlowMoUtils { private static final Field field; public static final boolean freezeEnabled; - private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", null); private static boolean frozen = false; private static final World world; @@ -40,7 +40,7 @@ public class SlowMoUtils { static { Field temp; try { - temp = Reflection.getClass("{nms.server.level}.WorldServer").getField("freezed"); + temp = Reflection.getClass("net.minecraft.server.level.WorldServer").getField("freezed"); } catch (NoSuchFieldException e) { temp = null; } diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index a1fac854..ea9a6be2 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -226,13 +226,13 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT); } - private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("{nms.network.chat}.IChatBaseComponent"), 0); + private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("net.minecraft.network.chat.IChatBaseComponent"), 0); @Override public void setScoreboardTitle(Object packet, String title) { scoreboardName.set(packet, ChatWrapper.impl.stringToChatComponent(title)); } - private static final Class scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("{nms.server}.ScoreboardServer$Action") : null; + private static final Class scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("net.minecraft.server.ScoreboardServer$Action") : null; private static final Reflection.Field scoreAction = Core.getVersion() < 21 ? Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0) : null; private static final Object scoreActionChange = Core.getVersion() < 21 ? scoreActionEnum.getEnumConstants()[0] : null; @@ -300,7 +300,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return head; } - private static final Class entityPose = Reflection.getClass("{nms.world.entity}.EntityPose"); + private static final Class entityPose = Reflection.getClass("net.minecraft.world.entity.EntityPose"); private static final Object standing = entityPose.getEnumConstants()[0]; private static final Object swimming = entityPose.getEnumConstants()[3]; private static final Object sneaking = entityPose.getEnumConstants()[5]; @@ -327,13 +327,13 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return displayName != null ? Optional.of(ChatWrapper.impl.stringToChatComponent(displayName)) : Optional.empty(); } - private static final Class registryBlocks = Reflection.getClass("{nms.core}.RegistryBlocks"); - private static final Class entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); - private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass(Core.getVersion() > 18 ? "net.minecraft.core.registries.BuiltInRegistries" : "{nms.core}.IRegistry"), registryBlocks, 0, entityTypes).get(null); - private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("{nms.resources}.MinecraftKey")); + private static final Class registryBlocks = Reflection.getClass("net.minecraft.core.RegistryBlocks"); + private static final Class entityTypes = Reflection.getClass("net.minecraft.world.entity.EntityTypes"); + private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass(Core.getVersion() > 18 ? "net.minecraft.core.registries.BuiltInRegistries" : "net.minecraft.core.IRegistry"), registryBlocks, 0, entityTypes).get(null); + private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("net.minecraft.resources.MinecraftKey")); private static final Reflection.Field spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); private static final Reflection.Field spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); - private static final Reflection.Method toMinecraft = Reflection.getMethod("{obc}.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); + private static final Reflection.Method toMinecraft = Reflection.getMethod("org.bukkit.craftbukkit.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); private static final Map types = new HashMap<>(); static { types.put(EntityType.ARMOR_STAND, 1); @@ -352,8 +352,8 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return player.getClientViewDistance(); } - private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftWorld", "getHandle"); - private static final Reflection.Method save = Reflection.getMethod("{nms.server.level}.WorldServer", null, Reflection.getClass("{nms.util}.IProgressUpdate"), boolean.class, boolean.class); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftWorld", "getHandle"); + private static final Reflection.Method save = Reflection.getMethod("net.minecraft.server.level.WorldServer", null, Reflection.getClass("net.minecraft.util.IProgressUpdate"), boolean.class, boolean.class); @Override public void syncSave(World world) { save.invoke(getHandle.invoke(world), null, true, false); diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java index 102ab31a..38d5654c 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java @@ -28,9 +28,9 @@ import java.util.Set; public class BlockIds14 implements BlockIds { - private static final Class blockStateList = Reflection.getClass("{nms.world.level.block.state}.BlockStateList"); - private static final Class fluidTypeFlowing = Reflection.getClass("{nms.world.level.material}.FluidTypeFlowing"); - private static final Class fluid = Reflection.getClass("{nms.world.level.material}.Fluid"); + private static final Class blockStateList = Reflection.getClass("net.minecraft.world.level.block.state.BlockStateList"); + private static final Class fluidTypeFlowing = Reflection.getClass("net.minecraft.world.level.material.FluidTypeFlowing"); + private static final Class fluid = Reflection.getClass("net.minecraft.world.level.material.Fluid"); private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); @Override @@ -40,8 +40,8 @@ public class BlockIds14 implements BlockIds { private static final Reflection.Method getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); - private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("{nms.world.level.material}.FluidTypes"), fluidTypeFlowing, 1).get(null), false); - private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, Reflection.getClass("{nms.core}.RegistryBlockID"), 0).get(null); + private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("net.minecraft.world.level.material.FluidTypes"), fluidTypeFlowing, 1).get(null), false); + private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, Reflection.getClass("net.minecraft.core.RegistryBlockID"), 0).get(null); private static final Reflection.Method getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); @Override public Set materialToAllIds(Material material) { diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java index 0f6e9d62..6cfaade4 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java @@ -29,7 +29,7 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle"); private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LightEngine.class); @Override diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java index 98ae4bab..877f398e 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java @@ -36,8 +36,8 @@ public class ProtocolWrapper18 implements ProtocolWrapper { equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); } - private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); - private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); + private static final Class playerInfoPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo"); + private static final Class playerInfoActionClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); private static final Reflection.Field playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); private static final Reflection.Field playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); private static final EnumMap actions = new EnumMap<>(PlayerInfoAction.class); @@ -47,8 +47,8 @@ public class ProtocolWrapper18 implements ProtocolWrapper { actions.put(PlayerInfoAction.GAMEMODE, nativeActions[1]); actions.put(PlayerInfoAction.REMOVE, nativeActions[4]); } - private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.IChatBaseComponent"); + private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$PlayerInfoData", GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override @SuppressWarnings("deprecation") diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java index 9d0490f5..31faa3f0 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper20 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle", ChunkStatus.class); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle", ChunkStatus.class); private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); @Override diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java index af3a3bd7..337ee1db 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper21 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle", ChunkStatus.class); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle", ChunkStatus.class); private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); @Override diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java index 8665a815..9f0d8e1a 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java @@ -49,7 +49,7 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { return index; } - private static final Class watchableObject = Reflection.getClass("{nms}.DataWatcher$WatchableObject"); + private static final Class watchableObject = Reflection.getClass("net.minecraft.DataWatcher$WatchableObject"); private static final Reflection.Constructor watchableObjectConstructor = Reflection.getConstructor(watchableObject, int.class, int.class, Object.class); private static final Map, Integer> watchableDatatypes = new HashMap<>(); static { diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java index 4408679f..5251a4f3 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java @@ -26,13 +26,13 @@ import java.util.List; public class ChatWrapper8 implements ChatWrapper { - private static final Reflection.Constructor chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class); + private static final Reflection.Constructor chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("net.minecraft.network.chat.ChatComponentText"), String.class); @Override public Object stringToChatComponent(String text) { return chatComponentConstructor.invoke(text); } - private static final Class metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata"); + private static final Class metadataPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata"); private static final Reflection.Field metadataEntity = Reflection.getField(metadataPacket, int.class, 0); private static final Reflection.Field metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); @Override diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java index eacf97e3..23ad414b 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java @@ -33,7 +33,7 @@ import java.util.Map; public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper { private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 1); - private static final Class scoreActionEnum = Reflection.getClass("{nms}.PacketPlayOutScoreboardScore$EnumScoreboardAction"); + private static final Class scoreActionEnum = Reflection.getClass("net.minecraft.PacketPlayOutScoreboardScore$EnumScoreboardAction"); private static final Reflection.Field scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0); private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0]; @@ -76,10 +76,10 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper return Byte.valueOf((byte)(pose == FlatteningWrapper.EntityPose.SNEAKING ? 2 : 0)); } - private static final Class dataWatcher = Reflection.getClass("{nms}.DataWatcher"); - private static final Class namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn"); + private static final Class dataWatcher = Reflection.getClass("net.minecraft.DataWatcher"); + private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn"); private static final Reflection.Field namedSpawnDataWatcher = Reflection.getField(namedSpawnPacket, dataWatcher, 0); - private static final Class entity = Reflection.getClass("{nms}.Entity"); + private static final Class entity = Reflection.getClass("net.minecraft.Entity"); private static final Reflection.Constructor dataWatcherConstructor = Reflection.getConstructor(dataWatcher, entity); @Override public void setNamedSpawnPacketDataWatcher(Object packet) { @@ -113,7 +113,7 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper return 10; } - private static final Reflection.Method save = Reflection.getMethod("{obc}.CraftWorld", "save", boolean.class); + private static final Reflection.Method save = Reflection.getMethod("org.bukkit.craftbukkit.CraftWorld", "save", boolean.class); @Override public void syncSave(World world) { save.invoke(world, true); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java index 24a924a0..aaa31c8d 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java @@ -34,7 +34,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { if(Core.getVersion() == 8) { equipmentSlot = Reflection.getField(equipmentPacket, int.class, 1); } else { - Class enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot"); + Class enumItemSlot = Reflection.getClass("net.minecraft.world.entity.EnumItemSlot"); equipmentSlot = Reflection.getField(equipmentPacket, enumItemSlot, 0); } } @@ -46,8 +46,8 @@ public class ProtocolWrapper8 implements ProtocolWrapper { equipmentStack.set(packet, stack); } - private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); - private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); + private static final Class playerInfoPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo"); + private static final Class playerInfoActionClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); private static final Reflection.Field playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); private static final Reflection.Field playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); private static final EnumMap actions = new EnumMap<>(PlayerInfoAction.class); @@ -57,8 +57,8 @@ public class ProtocolWrapper8 implements ProtocolWrapper { actions.put(PlayerInfoAction.GAMEMODE, nativeActions[1]); actions.put(PlayerInfoAction.REMOVE, nativeActions[4]); } - private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.IChatBaseComponent"); + private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$PlayerInfoData", playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override @SuppressWarnings("deprecation") diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java index 2d4b607e..a1648419 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java @@ -32,7 +32,7 @@ import java.util.Map; public class SWScoreboard8 implements SWScoreboard { private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 0); private static final Reflection.Field scoreboardAction = Reflection.getField(FlatteningWrapper.scoreboardObjective, int.class, Core.getVersion() > 15 ? 3 : 0); - private static final Class scoreboardDisplayEnum = Reflection.getClass("{nms.world.scores.criteria}.IScoreboardCriteria$EnumScoreboardHealthDisplay"); + private static final Class scoreboardDisplayEnum = Reflection.getClass("net.minecraft.world.scores.criteria.IScoreboardCriteria$EnumScoreboardHealthDisplay"); private static final Reflection.Field scoreboardDisplayType = Reflection.getField(FlatteningWrapper.scoreboardObjective, scoreboardDisplayEnum, 0); private static final Object displayTypeIntegers = scoreboardDisplayEnum.getEnumConstants()[0]; @@ -48,7 +48,7 @@ public class SWScoreboard8 implements SWScoreboard { private static final Object[] DISPLAY_SIDEBAR = new Object[2]; static { - Class scoreboardDisplayObjective = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardDisplayObjective"); + Class scoreboardDisplayObjective = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardDisplayObjective"); Reflection.Field scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0); Reflection.Field scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0); for(int id = 0; id < 2; id++) { diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java index 600050ff..0aebc6e1 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java @@ -26,7 +26,7 @@ import java.util.function.BiFunction; public class ChunkHider8 implements ChunkHider { - protected static final Class mapChunkPacket = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); + protected static final Class mapChunkPacket = Reflection.getClass("net.minecraft.PacketPlayOutMapChunk"); @Override public Class mapChunkPacket() { return mapChunkPacket; diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java index 04b3c7c8..0f5c6b4d 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java @@ -27,15 +27,15 @@ import java.util.ArrayList; import java.util.function.BiFunction; public class ProtocolWrapper8 implements ProtocolWrapper { - private static final Class chunkCoordinateIntPair = Reflection.getClass("{nms}.ChunkCoordIntPair"); + private static final Class chunkCoordinateIntPair = Reflection.getClass("net.minecraft.ChunkCoordIntPair"); private static final Reflection.Field multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0); private static final Reflection.Field chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0); private static final Reflection.Field chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1); - private static final Class multiBlockChangeInfo = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo"); + private static final Class multiBlockChangeInfo = Reflection.getClass("net.minecraft.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo"); private static final Reflection.Constructor multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData); private static final Reflection.Field multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0); private static final Reflection.Field multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0); - private static final Class multiBlockChangeInfoArray = Reflection.getClass("[L{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); + private static final Class multiBlockChangeInfoArray = Reflection.getClass("[Lnet.minecraft.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); private static final Reflection.Field multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0); @Override public BiFunction multiBlockChangeGenerator(TechHider techHider) { diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index f3642096..629d8365 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -42,16 +42,16 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { player.spigot().sendMessage(type, msg); } - private static final Class dataWatcherObject = Reflection.getClass("{nms.network.syncher}.DataWatcherObject"); - private static final Class dataWatcherRegistry = Reflection.getClass("{nms.network.syncher}.DataWatcherRegistry"); - private static final Class dataWatcherSerializer = Reflection.getClass("{nms.network.syncher}.DataWatcherSerializer"); + private static final Class dataWatcherObject = Reflection.getClass("net.minecraft.network.syncher.DataWatcherObject"); + private static final Class dataWatcherRegistry = Reflection.getClass("net.minecraft.network.syncher.DataWatcherRegistry"); + private static final Class dataWatcherSerializer = Reflection.getClass("net.minecraft.network.syncher.DataWatcherSerializer"); private static final Reflection.Constructor dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); @Override public Object getDataWatcherObject(int index, Class type) { return dataWatcherObjectConstructor.invoke(index, Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null)); } - private static final Class item = Reflection.getClass("{nms.network.syncher}.DataWatcher$Item"); + private static final Class item = Reflection.getClass("net.minecraft.network.syncher.DataWatcher$Item"); private static final Reflection.Constructor itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); @Override public Object getDataWatcherItem(Object dwo, Object value) { diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java index eb036e22..6c44fd87 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java @@ -25,10 +25,10 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Class chunk = Reflection.getClass("{nms.world.level.chunk}.Chunk"); - private static final Class packetPlayOutMapChunk = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMapChunk"); + private static final Class chunk = Reflection.getClass("net.minecraft.world.level.chunk.Chunk"); + private static final Class packetPlayOutMapChunk = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutMapChunk"); private static final Reflection.Constructor newPacketPlayOutMapChunk = Reflection.getConstructor(packetPlayOutMapChunk, chunk, int.class); - private static final Reflection.Method getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle"); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java index d305ca12..c47c0cc4 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java @@ -40,7 +40,7 @@ public class ChunkHider9 extends ChunkHider8 { private static final Reflection.Field mapChunkBlockEntities = Reflection.getField(mapChunkPacket, List.class, 0); private static final Reflection.Field mapChunkData = Reflection.getField(mapChunkPacket, byte[].class, 0); - private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); + private static final Class nbtTagCompound = Reflection.getClass("net.minecraft.nbt.NBTTagCompound"); private static final Reflection.Method nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); @Override diff --git a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java index 6997b3ef..0adf52d3 100644 --- a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java @@ -43,18 +43,18 @@ import java.util.logging.Level; public class TinyProtocol implements Listener { - private static final Class craftServer = Reflection.getClass("{obc}.CraftServer"); - private static final Class dedicatedPlayerList = Reflection.getClass("{nms.server.dedicated}.DedicatedPlayerList"); + private static final Class craftServer = Reflection.getClass("org.bukkit.craftbukkit.CraftServer"); + private static final Class dedicatedPlayerList = Reflection.getClass("net.minecraft.server.dedicated.DedicatedPlayerList"); private static final Field getPlayerList = Reflection.getField(craftServer, dedicatedPlayerList, 0); - private static final Class playerList = Reflection.getClass("{nms.server.players}.PlayerList"); - private static final Class minecraftServer = Reflection.getClass("{nms.server}.MinecraftServer"); + private static final Class playerList = Reflection.getClass("net.minecraft.server.players.PlayerList"); + private static final Class minecraftServer = Reflection.getClass("net.minecraft.server.MinecraftServer"); private static final Field getMinecraftServer = Reflection.getField(playerList, minecraftServer, 0); - public static final Class serverConnection = Reflection.getClass("{nms.server.network}.ServerConnection"); + public static final Class serverConnection = Reflection.getClass("net.minecraft.server.network.ServerConnection"); private static final Field getServerConnection = Reflection.getField(minecraftServer, serverConnection, 0); public static Object getServerConnection(Plugin plugin) { return getServerConnection.get(getMinecraftServer.get(getPlayerList.get(plugin.getServer()))); } - private static final Class networkManager = Reflection.getClass("{nms.network}.NetworkManager"); + private static final Class networkManager = Reflection.getClass("net.minecraft.network.NetworkManager"); public static final Field networkManagers = Reflection.getField(serverConnection, List.class, 0, networkManager); public static final TinyProtocol instance = new TinyProtocol(Core.getInstance()); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java index 712ceaf7..52787db6 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java @@ -29,7 +29,7 @@ import java.util.Map; @UtilityClass public class CommandRemover { - private static final Reflection.Field commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); + private static final Reflection.Field commandMap = Reflection.getField("org.bukkit.craftbukkit.CraftServer", "commandMap", SimpleCommandMap.class); private static final Reflection.Field knownCommands = Reflection.getField(SimpleCommandMap.class, "knownCommands", Map.class); public static void removeAll(String... cmds) { Map knownCmds = knownCommands.get(commandMap.get(Bukkit.getServer())); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java index 0f7e9e47..7262bbae 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java @@ -29,8 +29,8 @@ import org.bukkit.inventory.ItemStack; public class FlatteningWrapper { private FlatteningWrapper() {} - public static final Class scoreboardObjective = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardObjective"); - public static final Class scoreboardScore = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardScore"); + public static final Class scoreboardObjective = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective"); + public static final Class scoreboardScore = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardScore"); public static final IFlatteningWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java index 8706e2c6..915ac467 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java @@ -27,16 +27,16 @@ import java.util.function.LongSupplier; public interface ProtocolWrapper { - Class itemStack = Reflection.getClass("{nms.world.item}.ItemStack"); - Class spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity"); - Class spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntityLiving"); - Class equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment"); + Class itemStack = Reflection.getClass("net.minecraft.world.item.ItemStack"); + Class spawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity"); + Class spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving"); + Class equipmentPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment"); - Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); + Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "net.minecraft.world.level.EnumGamemode" : "net.minecraft.WorldSettings$EnumGamemode"); Reflection.Method getGameModeById = Reflection.getTypedMethod(enumGamemode, null, enumGamemode, int.class); // 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head - Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("{nms.world.entity}.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4}; + Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("net.minecraft.world.entity.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4}; ProtocolWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); @@ -45,7 +45,7 @@ public interface ProtocolWrapper { Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode); default void initTPSWarp(LongSupplier longSupplier) { - Class systemUtils = Reflection.getClass("{nms}.SystemUtils"); + Class systemUtils = Reflection.getClass("net.minecraft.SystemUtils"); Reflection.getField(systemUtils, LongSupplier.class, 0).set(systemUtils, (LongSupplier) () -> System.nanoTime() + longSupplier.getAsLong()); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index fefba9cd..f6714e0e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -79,7 +79,7 @@ public class TPSWatcher { } } - private static final Class minecraftServer = Reflection.getClass("{nms.server}.MinecraftServer"); + private static final Class minecraftServer = Reflection.getClass("net.minecraft.server.MinecraftServer"); private static final Reflection.Method getServer = Reflection.getTypedMethod(minecraftServer, "getServer", minecraftServer); private static final Reflection.Field recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class); private static double[] getSpigotTPS() { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java index 7319f4d4..b9c4011a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java @@ -27,7 +27,7 @@ public class AuthlibInjector { private AuthlibInjector() {} public static void inject() { - Class minecraftServerClass = Reflection.getClass("{nms.server}.MinecraftServer"); + Class minecraftServerClass = Reflection.getClass("net.minecraft.server.MinecraftServer"); Reflection.Field gameProfile = Reflection.getField(minecraftServerClass, GameProfileRepository.class, 0); Object minecraftServer = Reflection.getTypedMethod(minecraftServerClass, "getServer", minecraftServerClass).invoke(null); gameProfile.set(minecraftServer, new SteamwarGameProfileRepository((YggdrasilGameProfileRepository) gameProfile.get(minecraftServer))); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index cccdc38c..8b801d1b 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -54,11 +54,11 @@ public class AntiNocom implements Listener { } private void registerUseItem() { - Class useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); + Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"); Function getPosition; if(Core.getVersion() > 12) { - Class movingObjectPositionBlock = Reflection.getClass("{nms.world.phys}.MovingObjectPositionBlock"); + Class movingObjectPositionBlock = Reflection.getClass("net.minecraft.world.phys.MovingObjectPositionBlock"); Reflection.Field useItemPosition = Reflection.getField(useItem, movingObjectPositionBlock, 0); Reflection.Field movingBlockPosition = Reflection.getField(movingObjectPositionBlock, TechHider.blockPosition, 0); @@ -73,7 +73,7 @@ public class AntiNocom implements Listener { }); } - private static final Class blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); + private static final Class blockDig = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockDig"); private static final Reflection.Field digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0); private Object onDig(Player player, Object packet) { Object pos = digPosition.get(packet); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index d4ffc19d..c2a7c12f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -160,7 +160,7 @@ public class REntity { server.postEntityMove(this, fromX, fromZ); } - private static final Class animationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutAnimation"); + private static final Class animationPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutAnimation"); private static final Reflection.Field animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 5 : 6) : 0); private static final Reflection.Field animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 6 : 7) : 1); public void showAnimation(byte animation) { @@ -170,7 +170,7 @@ public class REntity { server.updateEntity(this, packet); } - private static final Class velocityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); + private static final Class velocityPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity"); private static final Reflection.Field velocityEntity = Reflection.getField(velocityPacket, int.class, 0); private static final Reflection.Field velocityX = Reflection.getField(velocityPacket, int.class, 1); private static final Reflection.Field velocityY = Reflection.getField(velocityPacket, int.class, 2); @@ -184,7 +184,7 @@ public class REntity { server.updateEntity(this, packet); } - private static final Class statusPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityStatus"); + private static final Class statusPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityStatus"); private static final Reflection.Field statusEntity = Reflection.getField(statusPacket, int.class, 0); private static final Reflection.Field statusStatus = Reflection.getField(statusPacket, byte.class, 0); public void showDamage() { @@ -346,7 +346,7 @@ public class REntity { } } - private static final Class destroyPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityDestroy"); + private static final Class destroyPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy"); private static final Reflection.Field destroyEntities; static { if(Core.getVersion() > 15) @@ -393,7 +393,7 @@ public class REntity { return ChatWrapper.impl.getDataWatcherPacket(entityId, dataWatcherKeyValues); } - public static final Class teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); + public static final Class teleportPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport"); public static final Reflection.Field teleportEntity = Reflection.getField(teleportPacket, int.class, 0); public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0); private Object getTeleportPacket(){ @@ -403,12 +403,12 @@ public class REntity { return packet; } - private static final Class entityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity"); + private static final Class entityPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntity"); private static final Reflection.Field moveEntityId = Reflection.getField(entityPacket, int.class, 0); private static final BountifulWrapper.PositionSetter movePosition = BountifulWrapper.impl.getRelMoveSetter(entityPacket); - private static final Class lookPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutEntityLook"); - private static final Class movePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutRelEntityMove"); - private static final Class moveLookPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook"); + private static final Class lookPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutEntityLook"); + private static final Class movePacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMove"); + private static final Class moveLookPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook"); private Object getMoveLookPacket(double diffX, double diffY, double diffZ, boolean rotEq) { Class clazz; if(diffX == 0 && diffY == 0 && diffZ == 0) { @@ -428,7 +428,7 @@ public class REntity { return packet; } - private static final Class headRotationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityHeadRotation"); + private static final Class headRotationPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation"); private static final Reflection.Field headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); private static final Reflection.Field headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); private Object getHeadRotationPacket(){ @@ -440,7 +440,7 @@ public class REntity { private static final Reflection.Field equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0); - private static final Class craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack"); + private static final Class craftItemStack = Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack"); private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class); protected Object getEquipmentPacket(Object slot, ItemStack stack){ Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 59df0563..60778b6a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -47,9 +47,9 @@ public class REntityServer implements Listener { private static final HashSet emptyEntities = new HashSet<>(0); private static final HashSet emptyPlayers = new HashSet<>(0); - private static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); + private static final Class useEntity = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseEntity"); private static final Reflection.Field useEntityTarget = Reflection.getField(useEntity, int.class, 0); - private static final Class useEntityEnumAction = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity$EnumEntityUseAction"); + private static final Class useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseEntity$EnumEntityUseAction"); private static final Reflection.Field useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); private static final Function getEntityAction; static { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index cb4e4638..64b577ea 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -91,7 +91,7 @@ public class RPlayer extends REntity { packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, new GameProfile(uuid, name), GameMode.CREATIVE)); } - private static final Class namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn"); + private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn"); private static final Function namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, Core.getVersion() == 8 ? 1 : 0); private static final Reflection.Field namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); private Object getNamedSpawnPacket() { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java index 47b9a146..8941432b 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java @@ -25,7 +25,7 @@ import com.comphenix.tinyprotocol.TinyProtocol; public class ServerDataHandler { public ServerDataHandler() { - TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.ClientboundServerDataPacket"), (p, o) -> null); - TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.ServerboundChatSessionUpdatePacket"), (player, packet) -> null); + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ClientboundServerDataPacket"), (p, o) -> null); + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket"), (player, packet) -> null); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index d29f082d..dff148ca 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -35,17 +35,17 @@ import java.util.stream.Collectors; public class TechHider { - public static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Class baseBlockPosition = Reflection.getClass("{nms.core}.BaseBlockPosition"); + public static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); + private static final Class baseBlockPosition = Reflection.getClass("net.minecraft.core.BaseBlockPosition"); public static final Reflection.Field blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); public static final Reflection.Field blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1); public static final Reflection.Field blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); - public static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); - public static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); + public static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.IBlockData"); + public static final Class block = Reflection.getClass("net.minecraft.world.level.block.Block"); private static final Reflection.Method getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); - public static final Class craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers"); + public static final Class craftMagicNumbers = Reflection.getClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"); private static final Reflection.Method getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); private static final Reflection.Method getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); @@ -86,14 +86,14 @@ public class TechHider { techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(this)); if(Core.getVersion() > 12 && Core.getVersion() < 19) { - Class blockBreakClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockBreak"); + Class blockBreakClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutBlockBreak"); techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass, this)); } if(Core.getVersion() > 8){ - techhiders.put(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); + techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); } - techhiders.put(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); + techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseEntity"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); } @@ -105,10 +105,10 @@ public class TechHider { techhiders.forEach(TinyProtocol.instance::removeFilter); } - public static final Class multiBlockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMultiBlockChange"); + public static final Class multiBlockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange"); public static final UnaryOperator multiBlockChangeCloner = ProtocolUtils.shallowCloneGenerator(TechHider.multiBlockChangePacket); - private static final Class blockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockChange"); + private static final Class blockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutBlockChange"); private static final Function blockChangeCloner = ProtocolUtils.shallowCloneGenerator(blockChangePacket); private static final Reflection.Field blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); private static final Reflection.Field blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); @@ -131,7 +131,7 @@ public class TechHider { } } - private static final Class blockActionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockAction"); + private static final Class blockActionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutBlockAction"); private static final Reflection.Field blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); private Object blockActionHider(Player p, Object packet) { if (locationEvaluator.checkBlockPos(p, blockActionPosition.get(packet)) == State.SKIP) @@ -139,7 +139,7 @@ public class TechHider { return null; } - public static final Class tileEntityDataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutTileEntityData"); + public static final Class tileEntityDataPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutTileEntityData"); private static final Reflection.Field tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); private Object tileEntityDataHider(Player p, Object packet) { switch (locationEvaluator.checkBlockPos(p, tileEntityDataPosition.get(packet))) { From 94a1ed356948bc48a3d6d66f04aadf2f7d9c21fd Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 6 Jan 2025 10:25:19 +0100 Subject: [PATCH 028/106] More robust version detection. --- .../src/de/steamwar/Reflection.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java index 26bf8bf2..8be1d8c1 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -33,8 +33,15 @@ import java.util.Arrays; @UtilityClass 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 int MAJOR_VERSION = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().split("_", 3)[1]); private static final String LEGACY_NET_MINECRAFT_SERVER = ORG_BUKKIT_CRAFTBUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server"); public static Class getClass(String name) { @@ -53,12 +60,12 @@ public final class Reflection { @AllArgsConstructor public static class Field { - private final java.lang.reflect.Field field; + private final java.lang.reflect.Field f; @SuppressWarnings("unchecked") public T get(Object target) { try { - return (T) field.get(target); + return (T) f.get(target); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Cannot read field", e); } @@ -66,7 +73,7 @@ public final class Reflection { public void set(Object target, Object value) { try { - field.set(target, value); + f.set(target, value); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Cannot write field", e); } @@ -128,13 +135,13 @@ public final class Reflection { @AllArgsConstructor public static class Method { - private final java.lang.reflect.Method method; + private final java.lang.reflect.Method m; public Object invoke(Object target, Object... arguments) { try { - return method.invoke(target, arguments); + return m.invoke(target, arguments); } catch (Exception e) { - throw new IllegalArgumentException("Cannot invoke method " + method, e); + throw new IllegalArgumentException("Cannot invoke method " + m, e); } } } @@ -166,13 +173,13 @@ public final class Reflection { @AllArgsConstructor public static class Constructor { - private final java.lang.reflect.Constructor constructor; + private final java.lang.reflect.Constructor c; public Object invoke(Object... arguments) { try { - return constructor.newInstance(arguments); + return c.newInstance(arguments); } catch (Exception e) { - throw new IllegalArgumentException("Cannot invoke constructor " + constructor, e); + throw new IllegalArgumentException("Cannot invoke constructor " + c, e); } } } From 9888700273a1b2b47d1a4bb8d2322bd77bd7d094 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 6 Jan 2025 16:44:10 +0100 Subject: [PATCH 029/106] Migrate reflections to mojang mapped by default --- .../bausystem/utils/NMSWrapper15.java | 2 +- .../bausystem/utils/NMSWrapper18.java | 2 +- .../bausystem/utils/NMSWrapper19.java | 2 +- .../bausystem/utils/NMSWrapper20.java | 2 +- .../features/simulator/SimulatorCursor.java | 6 +- .../smartplace/SmartPlaceListener.java | 2 +- .../features/tpslimit/PacketCache.java | 6 +- .../features/tpslimit/TPSFreezeUtils.java | 2 +- .../features/tpslimit/TPSLimitUtils.java | 4 +- .../features/util/NoClipCommand.java | 14 +-- .../features/world/AntiCursorReCentering.java | 2 +- .../features/world/NoCreativeKnockback.java | 2 +- .../features/world/SignEditFrom20.java | 8 +- .../features/world/SignEditUntil19.java | 8 +- .../bausystem/features/xray/XrayCommand.java | 4 +- .../bausystem/utils/PlaceItemUtils.java | 2 +- .../fightsystem/utils/BlockIdWrapper14.java | 10 +- .../fightsystem/utils/BountifulWrapper9.java | 2 +- .../de/steamwar/fightsystem/fight/Kit.java | 2 +- .../fightsystem/listener/ArrowStopper.java | 2 +- .../fightsystem/listener/ClickAnalyzer.java | 2 +- .../fightsystem/listener/Recording.java | 6 +- .../fightsystem/utils/BlockIdWrapper.java | 4 +- .../steamwar/fightsystem/utils/HullHider.java | 10 +- .../misslewars/slowmo/SlowMoUtils.java | 2 +- .../de/steamwar/core/FlatteningWrapper14.java | 14 +-- .../src/de/steamwar/techhider/BlockIds14.java | 10 +- .../de/steamwar/core/ProtocolWrapper18.java | 2 +- .../de/steamwar/techhider/ChunkHider18.java | 2 +- .../src/de/steamwar/core/ChatWrapper8.java | 2 +- .../de/steamwar/core/FlatteningWrapper8.java | 2 +- .../de/steamwar/core/ProtocolWrapper8.java | 2 +- .../de/steamwar/core/BountifulWrapper9.java | 8 +- .../de/steamwar/core/CraftbukkitWrapper9.java | 2 +- .../de/steamwar/techhider/ChunkHider9.java | 2 +- .../comphenix/tinyprotocol/TinyProtocol.java | 2 +- .../src/de/steamwar/Reflection.java | 106 ++++++++++++++++++ .../de/steamwar/core/FlatteningWrapper.java | 4 +- .../src/de/steamwar/core/ProtocolWrapper.java | 8 +- .../de/steamwar/core/events/AntiNocom.java | 6 +- .../src/de/steamwar/entity/REntity.java | 20 ++-- .../src/de/steamwar/entity/REntityServer.java | 4 +- .../src/de/steamwar/entity/RPlayer.java | 2 +- .../src/de/steamwar/techhider/TechHider.java | 20 ++-- 44 files changed, 216 insertions(+), 110 deletions(-) diff --git a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index 37ec1c93..b479e5d3 100644 --- a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -114,7 +114,7 @@ public class NMSWrapper15 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); diff --git a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index d3abe191..9763858e 100644 --- a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -120,7 +120,7 @@ public class NMSWrapper18 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); diff --git a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index 476f1921..748cf86d 100644 --- a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -119,7 +119,7 @@ public class NMSWrapper19 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); diff --git a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java index 3a8cb1bd..1cc09e56 100644 --- a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java +++ b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java @@ -121,7 +121,7 @@ public class NMSWrapper20 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 6d47f7fe..de9dae3f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -72,9 +72,9 @@ import java.util.stream.Collectors; public class SimulatorCursor implements Listener { private final World WORLD = Bukkit.getWorlds().get(0); - private Class position = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); - private Class look = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInLook"); - private Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); + private Class position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos"); + private Class look = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot"); + private Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot"); private Map cursorType = Collections.synchronizedMap(new HashMap<>()); private Map cursors = Collections.synchronizedMap(new HashMap<>()); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 764501bc..75b3f8b7 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -81,7 +81,7 @@ public class SmartPlaceListener implements Listener { IGNORED.remove(Material.BARRIER); } - private static final Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"); + private static final Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"); private static final Set SMART_PLACING = new HashSet<>(); private static final Set WAS_EXECUTED = new HashSet<>(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java index a7ebbfd1..a53bd819 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java @@ -45,13 +45,13 @@ class PacketCache { private static Set entities = new HashSet<>(); private static BukkitTask task = null; - private static Class vec3dClass = Reflection.getClass("net.minecraft.world.phys.Vec3D"); + private static Class vec3dClass = Reflection.getClass("net.minecraft.world.phys.Vec3"); private static Reflection.Field zeroVec3d = (Reflection.Field) Reflection.getField(vec3dClass, vec3dClass, 0); private static Object ZERO_VEC3D = zeroVec3d.get(null); - private static Class velocityPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity"); + private static Class velocityPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket"); private static Reflection.Constructor velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass); - private static Class teleportPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport"); + private static Class teleportPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket"); private static Class entityClass = Reflection.getClass("net.minecraft.world.entity.Entity"); private static Reflection.Constructor teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java index a1ae36a2..cb79f6fb 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java @@ -42,7 +42,7 @@ public class TPSFreezeUtils { static { Reflection.Field fieldAccessor; try { - fieldAccessor = Reflection.getField(Reflection.getClass("net.minecraft.server.level.WorldServer"), "freezed", boolean.class); + fieldAccessor = Reflection.getField(Reflection.getClass("net.minecraft.server.level.ServerLevel"), "freezed", boolean.class); } catch (IllegalArgumentException e) { fieldAccessor = null; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java index 62ae1b5c..29068ace 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java @@ -101,8 +101,8 @@ public class TPSLimitUtils { } */ - private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); - private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); + private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos"); + private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot"); static { BiFunction positionSetter = (player, o) -> { if (tpsLimiter != null) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index 5e7a1b1f..03055780 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -49,15 +49,15 @@ import java.util.function.BiFunction; @Linked public class NoClipCommand extends SWCommand implements Listener { - public static final Class gameStateChange = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutGameStateChange"); + public static final Class gameStateChange = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundGameEventPacket"); private static final Reflection.Field floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); - private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); - private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); - private static final Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"); - private static final Class blockDig = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockDig"); - private static final Class windowClick = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInWindowClick"); - private static final Class setSlotStack = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot"); + private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos"); + private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot"); + private static final Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"); + private static final Class blockDig = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket"); + private static final Class windowClick = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundContainerClickPacket"); + private static final Class setSlotStack = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket"); @Getter private static final List NOCLIPS = new ArrayList<>(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java index acb95394..46206a6c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java @@ -32,7 +32,7 @@ public class AntiCursorReCentering implements Enable { @Override public void enable() { - Class closeWindow = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutCloseWindow"); + Class closeWindow = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundContainerClosePacket"); TinyProtocol.instance.addFilter(closeWindow, (player, object) -> { if (player.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) { return object; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java index 2a102972..be950c60 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java @@ -29,7 +29,7 @@ import org.bukkit.GameMode; public class NoCreativeKnockback { public NoCreativeKnockback() { - TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"), (player, o) -> { + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"), (player, o) -> { if (player.getGameMode() != GameMode.CREATIVE) return o; return NMSWrapper.impl.resetExplosionKnockback(o); }); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java index 4618010d..df4164aa 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java @@ -48,19 +48,19 @@ import org.bukkit.util.Vector; @MinVersion(20) public class SignEditFrom20 implements Listener { - private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); private static final Class craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock"); private static final Class craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"); - private static final Class generatorAccess = Reflection.getClass("net.minecraft.world.level.GeneratorAccess"); + private static final Class generatorAccess = Reflection.getClass("net.minecraft.world.level.LevelAccessor"); private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); - private static final Class openSign = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor"); + private static final Class openSign = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket"); private static final Reflection.Field blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); private static final Reflection.Field sideFieldAccessor = Reflection.getField(openSign, boolean.class, 0); - private static final Class updateSign = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUpdateSign"); + private static final Class updateSign = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket"); private static final Reflection.Field getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); private static final Reflection.Field stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java index edf38e68..94b78f84 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java @@ -40,18 +40,18 @@ import org.bukkit.event.player.PlayerInteractEvent; @MaxVersion(19) public class SignEditUntil19 implements Listener { - private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); private static final Class craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock"); private static final Class craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"); - private static final Class generatorAccess = Reflection.getClass("net.minecraft.world.level.GeneratorAccess"); + private static final Class generatorAccess = Reflection.getClass("net.minecraft.world.level.LevelAccessor"); private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); - private static final Class openSign = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor"); + private static final Class openSign = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket"); private static final Reflection.Field blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); - private static final Class updateSign = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUpdateSign"); + private static final Class updateSign = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket"); private static final Reflection.Field getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); private static final Reflection.Field stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index e12a3f76..cad5b633 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -108,8 +108,8 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen }); } - private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); - private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); + private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos"); + private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot"); { BiFunction positionSetter = (player, o) -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java index 1ede0f63..3202c88e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java @@ -81,7 +81,7 @@ public class PlaceItemUtils { .collect(Collectors.toSet()); } - private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); private static final Reflection.Constructor blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); private static final Class craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlockState"); private static final Class craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"); diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index 5d3dfbd0..93b4a811 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -33,14 +33,14 @@ import java.util.Map; public class BlockIdWrapper14 implements BlockIdWrapper { - private static final Class chunkProviderServer = Reflection.getClass("net.minecraft.server.level.ChunkProviderServer"); + private static final Class chunkProviderServer = Reflection.getClass("net.minecraft.server.level.ServerChunkCache"); private static final Reflection.Method getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); - private static final Class playerChunkMap = Reflection.getClass("net.minecraft.server.level.PlayerChunkMap"); + private static final Class playerChunkMap = Reflection.getClass("net.minecraft.server.level.ChunkMap"); private static final Reflection.Field getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0); private static final Reflection.Field entityTrackers = Core.getVersion() > 15 ? Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0) : Reflection.getField(playerChunkMap, org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap.class, 0); private static final Class block = Reflection.getClass("net.minecraft.world.level.block.Block"); - private static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.IBlockData"); - private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); + private static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); private final Map trackers; public BlockIdWrapper14() { @@ -70,7 +70,7 @@ public class BlockIdWrapper14 implements BlockIdWrapper { flagDirty.invoke(getChunkProvider.invoke(nworld), pos); } - private static final Class entityTracker = Reflection.getClass("net.minecraft.server.level.PlayerChunkMap$EntityTracker"); + private static final Class entityTracker = Reflection.getClass("net.minecraft.server.level.ChunkMap$TrackedEntity"); private static final Reflection.Method updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, Entity entity) { diff --git a/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index 18031b0a..48017755 100644 --- a/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -43,7 +43,7 @@ import java.util.Map; public class BountifulWrapper9 implements BountifulWrapper { - private static final Class enumHand = Reflection.getClass("net.minecraft.world.EnumHand"); + private static final Class enumHand = Reflection.getClass("net.minecraft.world.InteractionHand"); private static final Object mainHand = enumHand.getEnumConstants()[0]; private static final Reflection.Field blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index ea8617d6..db97aa27 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -217,7 +217,7 @@ public class Kit { private static final Class itemStack = Reflection.getClass("net.minecraft.world.item.ItemStack"); private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class); - private static final Class nbtTagCompound = Reflection.getClass("net.minecraft.nbt.NBTTagCompound"); + private static final Class nbtTagCompound = Reflection.getClass("net.minecraft.nbt.CompoundTag"); private static final Reflection.Method getTag = Reflection.getTypedMethod(itemStack, null, nbtTagCompound); private static final Reflection.Method getKeys = Reflection.getTypedMethod(nbtTagCompound, null, Set.class); public static boolean hasItems(ItemStack stack) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 6b337646..361b86b6 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -41,7 +41,7 @@ public class ArrowStopper { new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); } - private static final Class entityArrow = Reflection.getClass("net.minecraft.world.entity.projectile.EntityArrow"); + private static final Class entityArrow = Reflection.getClass("net.minecraft.world.entity.projectile.AbstractArrow"); private void run() { Recording.iterateOverEntities(entityArrow::isInstance, entity -> { Projectile arrow = (Projectile) entity; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java index 3506ec25..d4bd10dc 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java @@ -43,7 +43,7 @@ public class ClickAnalyzer { public ClickAnalyzer() { TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace); if(Core.getVersion() > 8) - TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"), this::onBlockPlace); + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"), this::onBlockPlace); } public Object onBlockPlace(Player player, Object packet) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 7f6faa56..117962eb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -77,7 +77,7 @@ public class Recording implements Listener { return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; } - public static final Class primedTnt = Reflection.getClass("net.minecraft.world.entity.item.EntityTNTPrimed"); + public static final Class primedTnt = Reflection.getClass("net.minecraft.world.entity.item.PrimedTnt"); private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.world.entity.Entity"), "getBukkitEntity", null); public static void iterateOverEntities(Predicate filter, Consumer consumer) { CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer); @@ -129,7 +129,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entitySpeed(entity); } - private static final Class blockDigPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockDig"); + private static final Class blockDigPacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket"); private static final Class playerDigType = blockDigPacket.getDeclaredClasses()[0]; private static final Reflection.Field blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0); private static final Object releaseUseItem = playerDigType.getEnumConstants()[5]; @@ -139,7 +139,7 @@ public class Recording implements Listener { return packet; } - public static final Class blockPlacePacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockPlace"); + public static final Class blockPlacePacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemPacket"); private Object blockPlace(Player p, Object packet) { boolean mainHand = BountifulWrapper.impl.mainHand(packet); if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p)) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index d6039f04..a8f5d226 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -29,11 +29,11 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; public interface BlockIdWrapper { - Class worldServer = Reflection.getClass("net.minecraft.server.level.WorldServer"); + Class worldServer = Reflection.getClass("net.minecraft.server.level.ServerLevel"); Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", worldServer); Class craftPlayer = Reflection.getClass("org.bukkit.craftbukkit.entity.CraftPlayer"); - Class entityPlayer = Reflection.getClass("net.minecraft.server.level.EntityPlayer"); + Class entityPlayer = Reflection.getClass("net.minecraft.server.level.ServerPlayer"); Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); BlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index df1248ed..455b960d 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -71,8 +71,8 @@ public class HullHider implements Listener { packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider); packetHiders.put(packetPlayOutExplosion, this::explosionHider); - posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutWorldParticles", Core.getVersion() >= 18 ? double.class : float.class, 1.0); - posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect", int.class, 8.0); + posHiderGenerator("net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket", Core.getVersion() >= 18 ? double.class : float.class, 1.0); + posHiderGenerator("net.minecraft.network.protocol.game.ClientboundSoundPacket", int.class, 8.0); if(Core.getVersion() >= 9 && Core.getVersion() < 18) posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect", int.class, 8.0); @@ -198,15 +198,15 @@ public class HullHider implements Listener { } - private static final Class packetPlayOutWorldEvent = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutWorldEvent"); + private static final Class packetPlayOutWorldEvent = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelEventPacket"); private static final Reflection.Field worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0); - public static final Reflection.Field blockPositionY = Reflection.getField("net.minecraft.core.BaseBlockPosition", int.class, 1); + public static final Reflection.Field blockPositionY = Reflection.getField("net.minecraft.core.Vec3i", int.class, 1); private Object worldEventHider(Player player, Object packet) { Object baseBlock = worldEventPosition.get(packet); return packetHider(player, packet, new Location(Config.world, TechHider.blockPositionX.get(baseBlock), blockPositionY.get(baseBlock), TechHider.blockPositionZ.get(baseBlock))); } - private static final Class packetPlayOutExplosion = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion"); + private static final Class packetPlayOutExplosion = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); private static final Reflection.Field explosionBlocks = Reflection.getField(packetPlayOutExplosion, List.class, 0); private static final Function explosionLocation = posPacketToLocation(packetPlayOutExplosion, double.class, 1.0); private Object explosionHider(Player player, Object packet) { diff --git a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java index 10b2c05c..01e55c37 100644 --- a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java +++ b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java @@ -40,7 +40,7 @@ public class SlowMoUtils { static { Field temp; try { - temp = Reflection.getClass("net.minecraft.server.level.WorldServer").getField("freezed"); + temp = Reflection.getClass("net.minecraft.server.level.ServerLevel").getField("freezed"); } catch (NoSuchFieldException e) { temp = null; } diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index ea9a6be2..2033fc09 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -226,13 +226,13 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT); } - private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("net.minecraft.network.chat.IChatBaseComponent"), 0); + private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("net.minecraft.network.chat.Component"), 0); @Override public void setScoreboardTitle(Object packet, String title) { scoreboardName.set(packet, ChatWrapper.impl.stringToChatComponent(title)); } - private static final Class scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("net.minecraft.server.ScoreboardServer$Action") : null; + private static final Class scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("net.minecraft.server.ServerScoreboard$Method") : null; private static final Reflection.Field scoreAction = Core.getVersion() < 21 ? Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0) : null; private static final Object scoreActionChange = Core.getVersion() < 21 ? scoreActionEnum.getEnumConstants()[0] : null; @@ -300,7 +300,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return head; } - private static final Class entityPose = Reflection.getClass("net.minecraft.world.entity.EntityPose"); + private static final Class entityPose = Reflection.getClass("net.minecraft.world.entity.Pose"); private static final Object standing = entityPose.getEnumConstants()[0]; private static final Object swimming = entityPose.getEnumConstants()[3]; private static final Object sneaking = entityPose.getEnumConstants()[5]; @@ -327,10 +327,10 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return displayName != null ? Optional.of(ChatWrapper.impl.stringToChatComponent(displayName)) : Optional.empty(); } - private static final Class registryBlocks = Reflection.getClass("net.minecraft.core.RegistryBlocks"); - private static final Class entityTypes = Reflection.getClass("net.minecraft.world.entity.EntityTypes"); + private static final Class registryBlocks = Reflection.getClass("net.minecraft.core.DefaultedRegistry"); + private static final Class entityTypes = Reflection.getClass("net.minecraft.world.entity.EntityType"); private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass(Core.getVersion() > 18 ? "net.minecraft.core.registries.BuiltInRegistries" : "net.minecraft.core.IRegistry"), registryBlocks, 0, entityTypes).get(null); - private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("net.minecraft.resources.MinecraftKey")); + private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("net.minecraft.resources.ResourceLocation")); private static final Reflection.Field spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); private static final Reflection.Field spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); private static final Reflection.Method toMinecraft = Reflection.getMethod("org.bukkit.craftbukkit.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); @@ -353,7 +353,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper } private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftWorld", "getHandle"); - private static final Reflection.Method save = Reflection.getMethod("net.minecraft.server.level.WorldServer", null, Reflection.getClass("net.minecraft.util.IProgressUpdate"), boolean.class, boolean.class); + private static final Reflection.Method save = Reflection.getMethod("net.minecraft.server.level.ServerLevel", null, Reflection.getClass("net.minecraft.util.ProgressListener"), boolean.class, boolean.class); @Override public void syncSave(World world) { save.invoke(getHandle.invoke(world), null, true, false); diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java index 38d5654c..ebf5e952 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java @@ -28,9 +28,9 @@ import java.util.Set; public class BlockIds14 implements BlockIds { - private static final Class blockStateList = Reflection.getClass("net.minecraft.world.level.block.state.BlockStateList"); - private static final Class fluidTypeFlowing = Reflection.getClass("net.minecraft.world.level.material.FluidTypeFlowing"); - private static final Class fluid = Reflection.getClass("net.minecraft.world.level.material.Fluid"); + private static final Class blockStateList = Reflection.getClass("net.minecraft.world.level.block.state.StateDefinition"); + private static final Class fluidTypeFlowing = Reflection.getClass("net.minecraft.world.level.material.FlowingFluid"); + private static final Class fluid = Reflection.getClass("net.minecraft.world.level.material.FluidState"); private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); @Override @@ -40,8 +40,8 @@ public class BlockIds14 implements BlockIds { private static final Reflection.Method getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); - private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("net.minecraft.world.level.material.FluidTypes"), fluidTypeFlowing, 1).get(null), false); - private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, Reflection.getClass("net.minecraft.core.RegistryBlockID"), 0).get(null); + private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("net.minecraft.world.level.material.Fluids"), fluidTypeFlowing, 1).get(null), false); + private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, Reflection.getClass("net.minecraft.core.IdMapper"), 0).get(null); private static final Reflection.Method getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); @Override public Set materialToAllIds(Material material) { diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java index 877f398e..e5cdf160 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java @@ -47,7 +47,7 @@ public class ProtocolWrapper18 implements ProtocolWrapper { actions.put(PlayerInfoAction.GAMEMODE, nativeActions[1]); actions.put(PlayerInfoAction.REMOVE, nativeActions[4]); } - private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.IChatBaseComponent"); + private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component"); private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$PlayerInfoData", GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java index 4478a02b..ace24a54 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java @@ -87,7 +87,7 @@ public class ChunkHider18 implements ChunkHider { }; } - public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); + public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo"); protected static final Reflection.Field entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); private static final IRegistry tileEntityTypes = Reflection.getField(Core.getVersion() > 18 ? Reflection.getClass("net.minecraft.core.registries.BuiltInRegistries") : IRegistry.class, IRegistry.class, 0, TileEntityTypes.class).get(null); private static final Reflection.Method getKey = Reflection.getTypedMethod(IRegistry.class, null, MinecraftKey.class, Object.class); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java index 5251a4f3..c41c1710 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java @@ -32,7 +32,7 @@ public class ChatWrapper8 implements ChatWrapper { return chatComponentConstructor.invoke(text); } - private static final Class metadataPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata"); + private static final Class metadataPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket"); private static final Reflection.Field metadataEntity = Reflection.getField(metadataPacket, int.class, 0); private static final Reflection.Field metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); @Override diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java index 23ad414b..b191a069 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java @@ -77,7 +77,7 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper } private static final Class dataWatcher = Reflection.getClass("net.minecraft.DataWatcher"); - private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn"); + private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket"); private static final Reflection.Field namedSpawnDataWatcher = Reflection.getField(namedSpawnPacket, dataWatcher, 0); private static final Class entity = Reflection.getClass("net.minecraft.Entity"); private static final Reflection.Constructor dataWatcherConstructor = Reflection.getConstructor(dataWatcher, entity); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java index aaa31c8d..e30caa17 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java @@ -57,7 +57,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { actions.put(PlayerInfoAction.GAMEMODE, nativeActions[1]); actions.put(PlayerInfoAction.REMOVE, nativeActions[4]); } - private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.IChatBaseComponent"); + private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component"); private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$PlayerInfoData", playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index 629d8365..ce7f6170 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -42,16 +42,16 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { player.spigot().sendMessage(type, msg); } - private static final Class dataWatcherObject = Reflection.getClass("net.minecraft.network.syncher.DataWatcherObject"); - private static final Class dataWatcherRegistry = Reflection.getClass("net.minecraft.network.syncher.DataWatcherRegistry"); - private static final Class dataWatcherSerializer = Reflection.getClass("net.minecraft.network.syncher.DataWatcherSerializer"); + private static final Class dataWatcherObject = Reflection.getClass("net.minecraft.network.syncher.EntityDataAccessor"); + private static final Class dataWatcherRegistry = Reflection.getClass("net.minecraft.network.syncher.EntityDataSerializers"); + private static final Class dataWatcherSerializer = Reflection.getClass("net.minecraft.network.syncher.EntityDataSerializer"); private static final Reflection.Constructor dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); @Override public Object getDataWatcherObject(int index, Class type) { return dataWatcherObjectConstructor.invoke(index, Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null)); } - private static final Class item = Reflection.getClass("net.minecraft.network.syncher.DataWatcher$Item"); + private static final Class item = Reflection.getClass("net.minecraft.network.syncher.SynchedEntityData$DataItem"); private static final Reflection.Constructor itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); @Override public Object getDataWatcherItem(Object dwo, Object value) { diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java index 6c44fd87..608209dc 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java @@ -25,7 +25,7 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Class chunk = Reflection.getClass("net.minecraft.world.level.chunk.Chunk"); + private static final Class chunk = Reflection.getClass("net.minecraft.world.level.chunk.LevelChunk"); private static final Class packetPlayOutMapChunk = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutMapChunk"); private static final Reflection.Constructor newPacketPlayOutMapChunk = Reflection.getConstructor(packetPlayOutMapChunk, chunk, int.class); private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle"); diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java index c47c0cc4..96060822 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java @@ -40,7 +40,7 @@ public class ChunkHider9 extends ChunkHider8 { private static final Reflection.Field mapChunkBlockEntities = Reflection.getField(mapChunkPacket, List.class, 0); private static final Reflection.Field mapChunkData = Reflection.getField(mapChunkPacket, byte[].class, 0); - private static final Class nbtTagCompound = Reflection.getClass("net.minecraft.nbt.NBTTagCompound"); + private static final Class nbtTagCompound = Reflection.getClass("net.minecraft.nbt.CompoundTag"); private static final Reflection.Method nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); @Override diff --git a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java index 0adf52d3..3a0124e0 100644 --- a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java @@ -49,7 +49,7 @@ public class TinyProtocol implements Listener { private static final Class playerList = Reflection.getClass("net.minecraft.server.players.PlayerList"); private static final Class minecraftServer = Reflection.getClass("net.minecraft.server.MinecraftServer"); private static final Field getMinecraftServer = Reflection.getField(playerList, minecraftServer, 0); - public static final Class serverConnection = Reflection.getClass("net.minecraft.server.network.ServerConnection"); + public static final Class serverConnection = Reflection.getClass("net.minecraft.server.network.ServerConnectionListener"); private static final Field getServerConnection = Reflection.getField(minecraftServer, serverConnection, 0); public static Object getServerConnection(Plugin plugin) { return getServerConnection.get(getMinecraftServer.get(getPlayerList.get(plugin.getServer()))); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java index 8be1d8c1..8cb72214 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -28,6 +28,8 @@ 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 @@ -44,6 +46,107 @@ public final class Reflection { private static final String ORG_BUKKIT_CRAFTBUKKIT = Bukkit.getServer().getClass().getPackage().getName(); private static final String LEGACY_NET_MINECRAFT_SERVER = ORG_BUKKIT_CRAFTBUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server"); + private static final Map 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.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")) { @@ -54,6 +157,9 @@ public final class Reflection { return Class.forName(name); } } catch (ClassNotFoundException e) { + if(spigotClassnames.containsKey(name)) + return getClass(spigotClassnames.get(name)); + throw new IllegalArgumentException("Cannot find " + name, e); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java index 7262bbae..b4d954f8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java @@ -29,8 +29,8 @@ import org.bukkit.inventory.ItemStack; public class FlatteningWrapper { private FlatteningWrapper() {} - public static final Class scoreboardObjective = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective"); - public static final Class scoreboardScore = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardScore"); + public static final Class scoreboardObjective = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetObjectivePacket"); + public static final Class scoreboardScore = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetScorePacket"); public static final IFlatteningWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java index 915ac467..9c226741 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java @@ -28,11 +28,11 @@ import java.util.function.LongSupplier; public interface ProtocolWrapper { Class itemStack = Reflection.getClass("net.minecraft.world.item.ItemStack"); - Class spawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity"); + Class spawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddEntityPacket"); Class spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving"); - Class equipmentPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment"); + Class equipmentPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket"); - Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "net.minecraft.world.level.EnumGamemode" : "net.minecraft.WorldSettings$EnumGamemode"); + Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "net.minecraft.world.level.GameType" : "net.minecraft.WorldSettings$EnumGamemode"); Reflection.Method getGameModeById = Reflection.getTypedMethod(enumGamemode, null, enumGamemode, int.class); // 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head @@ -45,7 +45,7 @@ public interface ProtocolWrapper { Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode); default void initTPSWarp(LongSupplier longSupplier) { - Class systemUtils = Reflection.getClass("net.minecraft.SystemUtils"); + Class systemUtils = Reflection.getClass("net.minecraft.Util"); Reflection.getField(systemUtils, LongSupplier.class, 0).set(systemUtils, (LongSupplier) () -> System.nanoTime() + longSupplier.getAsLong()); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index 8b801d1b..14f8badc 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -54,11 +54,11 @@ public class AntiNocom implements Listener { } private void registerUseItem() { - Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"); + Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"); Function getPosition; if(Core.getVersion() > 12) { - Class movingObjectPositionBlock = Reflection.getClass("net.minecraft.world.phys.MovingObjectPositionBlock"); + Class movingObjectPositionBlock = Reflection.getClass("net.minecraft.world.phys.BlockHitResult"); Reflection.Field useItemPosition = Reflection.getField(useItem, movingObjectPositionBlock, 0); Reflection.Field movingBlockPosition = Reflection.getField(movingObjectPositionBlock, TechHider.blockPosition, 0); @@ -73,7 +73,7 @@ public class AntiNocom implements Listener { }); } - private static final Class blockDig = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockDig"); + private static final Class blockDig = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket"); private static final Reflection.Field digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0); private Object onDig(Player player, Object packet) { Object pos = digPosition.get(packet); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index c2a7c12f..e7ecb1a8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -160,7 +160,7 @@ public class REntity { server.postEntityMove(this, fromX, fromZ); } - private static final Class animationPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutAnimation"); + private static final Class animationPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAnimatePacket"); private static final Reflection.Field animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 5 : 6) : 0); private static final Reflection.Field animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 6 : 7) : 1); public void showAnimation(byte animation) { @@ -170,7 +170,7 @@ public class REntity { server.updateEntity(this, packet); } - private static final Class velocityPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity"); + private static final Class velocityPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket"); private static final Reflection.Field velocityEntity = Reflection.getField(velocityPacket, int.class, 0); private static final Reflection.Field velocityX = Reflection.getField(velocityPacket, int.class, 1); private static final Reflection.Field velocityY = Reflection.getField(velocityPacket, int.class, 2); @@ -184,7 +184,7 @@ public class REntity { server.updateEntity(this, packet); } - private static final Class statusPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityStatus"); + private static final Class statusPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundEntityEventPacket"); private static final Reflection.Field statusEntity = Reflection.getField(statusPacket, int.class, 0); private static final Reflection.Field statusStatus = Reflection.getField(statusPacket, byte.class, 0); public void showDamage() { @@ -346,7 +346,7 @@ public class REntity { } } - private static final Class destroyPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy"); + private static final Class destroyPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket"); private static final Reflection.Field destroyEntities; static { if(Core.getVersion() > 15) @@ -393,7 +393,7 @@ public class REntity { return ChatWrapper.impl.getDataWatcherPacket(entityId, dataWatcherKeyValues); } - public static final Class teleportPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport"); + public static final Class teleportPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket"); public static final Reflection.Field teleportEntity = Reflection.getField(teleportPacket, int.class, 0); public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0); private Object getTeleportPacket(){ @@ -403,12 +403,12 @@ public class REntity { return packet; } - private static final Class entityPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntity"); + private static final Class entityPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket"); private static final Reflection.Field moveEntityId = Reflection.getField(entityPacket, int.class, 0); private static final BountifulWrapper.PositionSetter movePosition = BountifulWrapper.impl.getRelMoveSetter(entityPacket); - private static final Class lookPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutEntityLook"); - private static final Class movePacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMove"); - private static final Class moveLookPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook"); + private static final Class lookPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Rot"); + private static final Class movePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos"); + private static final Class moveLookPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot"); private Object getMoveLookPacket(double diffX, double diffY, double diffZ, boolean rotEq) { Class clazz; if(diffX == 0 && diffY == 0 && diffZ == 0) { @@ -428,7 +428,7 @@ public class REntity { return packet; } - private static final Class headRotationPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation"); + private static final Class headRotationPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundRotateHeadPacket"); private static final Reflection.Field headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); private static final Reflection.Field headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); private Object getHeadRotationPacket(){ diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 60778b6a..d5ced550 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -47,9 +47,9 @@ public class REntityServer implements Listener { private static final HashSet emptyEntities = new HashSet<>(0); private static final HashSet emptyPlayers = new HashSet<>(0); - private static final Class useEntity = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseEntity"); + private static final Class useEntity = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"); private static final Reflection.Field useEntityTarget = Reflection.getField(useEntity, int.class, 0); - private static final Class useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseEntity$EnumEntityUseAction"); + private static final Class useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action"); private static final Reflection.Field useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); private static final Function getEntityAction; static { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index 64b577ea..b4aaa3ee 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -91,7 +91,7 @@ public class RPlayer extends REntity { packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, new GameProfile(uuid, name), GameMode.CREATIVE)); } - private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn"); + private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket"); private static final Function namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, Core.getVersion() == 8 ? 1 : 0); private static final Reflection.Field namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); private Object getNamedSpawnPacket() { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index dff148ca..bae5b7be 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -35,13 +35,13 @@ import java.util.stream.Collectors; public class TechHider { - public static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition"); - private static final Class baseBlockPosition = Reflection.getClass("net.minecraft.core.BaseBlockPosition"); + public static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); + private static final Class baseBlockPosition = Reflection.getClass("net.minecraft.core.Vec3i"); public static final Reflection.Field blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); public static final Reflection.Field blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1); public static final Reflection.Field blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); - public static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.IBlockData"); + public static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); public static final Class block = Reflection.getClass("net.minecraft.world.level.block.Block"); private static final Reflection.Method getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); @@ -86,14 +86,14 @@ public class TechHider { techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(this)); if(Core.getVersion() > 12 && Core.getVersion() < 19) { - Class blockBreakClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutBlockBreak"); + Class blockBreakClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket"); techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass, this)); } if(Core.getVersion() > 8){ - techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); + techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); } - techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseEntity"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); + techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); } @@ -105,10 +105,10 @@ public class TechHider { techhiders.forEach(TinyProtocol.instance::removeFilter); } - public static final Class multiBlockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange"); + public static final Class multiBlockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket"); public static final UnaryOperator multiBlockChangeCloner = ProtocolUtils.shallowCloneGenerator(TechHider.multiBlockChangePacket); - private static final Class blockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutBlockChange"); + private static final Class blockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket"); private static final Function blockChangeCloner = ProtocolUtils.shallowCloneGenerator(blockChangePacket); private static final Reflection.Field blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); private static final Reflection.Field blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); @@ -131,7 +131,7 @@ public class TechHider { } } - private static final Class blockActionPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutBlockAction"); + private static final Class blockActionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockEventPacket"); private static final Reflection.Field blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); private Object blockActionHider(Player p, Object packet) { if (locationEvaluator.checkBlockPos(p, blockActionPosition.get(packet)) == State.SKIP) @@ -139,7 +139,7 @@ public class TechHider { return null; } - public static final Class tileEntityDataPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutTileEntityData"); + public static final Class tileEntityDataPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket"); private static final Reflection.Field tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); private Object tileEntityDataHider(Player p, Object packet) { switch (locationEvaluator.checkBlockPos(p, tileEntityDataPosition.get(packet))) { From 053bd06342c274fc28498888242556227dc46676 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 6 Jan 2025 19:18:47 +0100 Subject: [PATCH 030/106] Fix invisible players --- FightSystem/FightSystem_18/build.gradle.kts | 1 + .../fightsystem/utils/BlockIdWrapper18.java | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/FightSystem/FightSystem_18/build.gradle.kts b/FightSystem/FightSystem_18/build.gradle.kts index b140d148..b5d694ed 100644 --- a/FightSystem/FightSystem_18/build.gradle.kts +++ b/FightSystem/FightSystem_18/build.gradle.kts @@ -31,5 +31,6 @@ dependencies { compileOnly(libs.nms18) compileOnly(libs.fawe18) + compileOnly(libs.authlib) compileOnly(libs.fastutil) } diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java index c229353a..992dd451 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java @@ -19,24 +19,29 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import com.mojang.authlib.GameProfile; +import de.steamwar.core.ProtocolWrapper; +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.GameMode; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import java.util.*; - public class BlockIdWrapper18 extends BlockIdWrapper14 { - private static final Reflection.FieldAccessor hiddenEntities = Reflection.getField(Reflection.getClass("{obc}.entity.CraftPlayer"), Map.class, 0, UUID.class, Set.class); @Override public void trackEntity(Player player, Entity entity) { - hiddenEntities.get(player).remove(entity.getUniqueId()); - super.trackEntity(player, entity); + if(entity instanceof Player) + TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, new GameProfile(entity.getUniqueId(), entity.getName()), GameMode.CREATIVE)); + + player.showEntity(FightSystem.getPlugin(), entity); } @Override public void untrackEntity(Player player, Entity entity) { - hiddenEntities.get(player).put(entity.getUniqueId(), new HashSet<>(1)); - super.untrackEntity(player, entity); + player.hideEntity(FightSystem.getPlugin(), entity); + + if(entity instanceof Player) + TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, new GameProfile(entity.getUniqueId(), entity.getName()), GameMode.CREATIVE)); } } From 66f4efb27fa25c02a99945c95bb0addbcb124a21 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 6 Jan 2025 19:24:15 +0100 Subject: [PATCH 031/106] Fix /schem changetype schem type normal --- .../commands/schematiccommand/SchematicCommandUtils.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index 860435b9..f92c7224 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -470,6 +470,9 @@ public class SchematicCommandUtils { } else if (extend == SchematicCommand.Extend.AUSFAHREN) { NetworkSender.send(new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()).getId(), node.getId(), type.toDB())); SchematicSystem.MESSAGE.send("UTIL_TYPE_EXTEND", player); + } else { + node.setSchemtype(type.checkType()); + SchematicSystem.MESSAGE.send("UTIL_SUBMIT_DIRECT_DONE", player); } } } From 46fed25da48297ceec0db4729d86c6849677a1c8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jan 2025 16:38:40 +0100 Subject: [PATCH 032/106] Fix renaming for class name duplications --- SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java index 8cb72214..e666debe 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -153,13 +153,12 @@ public final class Reflection { 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 + "." + name.split("[.](?=[^.]*$)")[1]); + } else if(MAJOR_VERSION < 21 || MINOR_VERSION < 4) { + return Class.forName(spigotClassnames.getOrDefault(name, name)); } else { return Class.forName(name); } } catch (ClassNotFoundException e) { - if(spigotClassnames.containsKey(name)) - return getClass(spigotClassnames.get(name)); - throw new IllegalArgumentException("Cannot find " + name, e); } } From 26bc341c4dfdd3cdaf14dd386a3839e31e653042 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jan 2025 16:57:06 +0100 Subject: [PATCH 033/106] Fix 1.15- reflections --- SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java index e666debe..4e89c8c5 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -152,7 +152,7 @@ public final class Reflection { 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 + "." + name.split("[.](?=[^.]*$)")[1]); + 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 { From 01da293680f49437639d3349fe3ecc6e11658079 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jan 2025 17:05:29 +0100 Subject: [PATCH 034/106] Fix Array reflection --- SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java index 4e89c8c5..92e3d3fd 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -44,7 +44,7 @@ public final class Reflection { } private static final String ORG_BUKKIT_CRAFTBUKKIT = Bukkit.getServer().getClass().getPackage().getName(); - private static final String LEGACY_NET_MINECRAFT_SERVER = ORG_BUKKIT_CRAFTBUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server"); + public static final String LEGACY_NET_MINECRAFT_SERVER = ORG_BUKKIT_CRAFTBUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server"); private static final Map spigotClassnames = new HashMap<>(); static { From 604a1db218fef03534bf2f51c1eafc9038d82e7c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jan 2025 17:06:02 +0100 Subject: [PATCH 035/106] Fix Array reflection --- .../src/de/steamwar/techhider/ProtocolWrapper8.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java index 0f5c6b4d..78633bc1 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java @@ -35,7 +35,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { private static final Reflection.Constructor multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData); private static final Reflection.Field multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0); private static final Reflection.Field multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0); - private static final Class multiBlockChangeInfoArray = Reflection.getClass("[Lnet.minecraft.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); + private static final Class multiBlockChangeInfoArray = Reflection.getClass("[L" + Reflection.LEGACY_NET_MINECRAFT_SERVER + ".PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); private static final Reflection.Field multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0); @Override public BiFunction multiBlockChangeGenerator(TechHider techHider) { From 8e51db3e5b1460aa3003528c94eee16e35b81a4b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jan 2025 17:15:34 +0100 Subject: [PATCH 036/106] Fix tablist --- .../src/de/steamwar/velocitycore/tablist/Tablist.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java index 1c5b74c5..2c380a90 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -142,12 +142,8 @@ public class Tablist extends ChannelInboundHandlerAdapter { } public void onServerPostSwitch() { - if(player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20)) { - if(player.getProtocolVersion().greaterThan(ProtocolVersion.MINECRAFT_1_20)) - current.clear(); - + if(player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20)) sendPacket(player, createTeamPacket); - } } private void injection() { From 1350be9b80e7ee82b09afcaaa164c5cd65c519f7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Jan 2025 12:02:11 +0100 Subject: [PATCH 037/106] Add new roughlyenoughitems plugin channel --- .../de/steamwar/velocitycore/listeners/PluginMessage.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java index 05e91edb..af208aed 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java @@ -137,7 +137,6 @@ public class PluginMessage extends BasicListener { "itemswapper:enableshulker", "itemswapper:enablerefill", //https://github.com/tr7zw/ItemSwapper/tree/main (Easier inventory item swapping) "jade:show_overlay", "jade:receive_data", "jade:server_ping", "jade:server_ping_v1", //https://github.com/Snownee/Jade (Information over block/entity under crosshair) "bclib:hello_client", "bclib:request_files", "bclib:send_files", "bclib:chunker", //https://github.com/quiqueck/BCLib (Library for additional dimensions) - "roughlyenoughitems:ci_msg", "roughlyenoughitems:request_tags_s2c", "roughlyenoughitems:og_not_enough", //https://github.com/shedaniel/RoughlyEnoughItems (Crafting recipe helper) "essentialclient:chunkdebug", "essentialclient:clientscript", "essentialclient:gamerule", //https://github.com/senseiwells/EssentialClient (Carpet mod extension) "couplings:server_config", //https://github.com/ChloeDawn/Couplings (Opens/closes double doors/gates simultaneously) "yigd:grave_overview_s2c", "yigd:grave_selection_s2c", "yigd:player_selection_s2c", //https://github.com/B1n-ry/Youre-in-grave-danger (Adds new block - graves) @@ -190,6 +189,10 @@ public class PluginMessage extends BasicListener { "better-suggestions:entity_scores_response", "better-suggestions:entity_tags_response", //https://github.com/shurik204/better-suggestions (Better command tab completion) "farmingforblockheads:chicken_nest_effect", "farmingforblockheads:market_categories", //https://github.com/TwelveIterationMods/FarmingForBlockheads (Improved farming with new blocks) + //https://github.com/shedaniel/RoughlyEnoughItems (Crafting recipe helper) + "roughlyenoughitems:ci_msg", "roughlyenoughitems:request_tags_s2c", "roughlyenoughitems:og_not_enough", + "roughlyenoughitems:sync_displays", + //https://modrinth.com/mod/servux "servux:structures", "servux:entity_data", "servux:hud_metadata", "servux:debug_service", "servux:tweaks", From a39f172a34ca2205291bab54ff2a6b3defe2e86b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 8 Jan 2025 12:56:51 +0100 Subject: [PATCH 038/106] Fix Schem Upload --- .../discord/listeners/DiscordSchemUpload.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java index 68b8d360..4a202368 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java @@ -31,13 +31,12 @@ import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.logging.Level; +import java.util.zip.GZIPInputStream; public class DiscordSchemUpload extends ListenerAdapter { @@ -84,7 +83,8 @@ public class DiscordSchemUpload extends ListenerAdapter { node = SchematicNode.createSchematic(user.getId(), name, null); try (InputStream in = attachment.getProxy().download().get()) { - CompoundTag tags = NBT.fromStream(new DataInputStream(in)); + byte[] bytes = in.readAllBytes(); + CompoundTag tags = NBT.fromStream(new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes)))); NodeData.SchematicFormat version = NodeData.SchematicFormat.SPONGE_V2; @@ -94,7 +94,7 @@ public class DiscordSchemUpload extends ListenerAdapter { version = NodeData.SchematicFormat.MCEDIT; } - NodeData.get(node).saveFromStream(in, version); + NodeData.get(node).saveFromStream(new ByteArrayInputStream(bytes), version); sender.system("DC_SCHEMUPLOAD_SUCCESS", name); } catch (InterruptedException e) { Thread.currentThread().interrupt(); From 0f1fbc4b88d0b69c16a1420b731ef9e85d631710 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 14 Jan 2025 23:44:30 +0100 Subject: [PATCH 039/106] Test Webhook --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index b0fb3f72..ccd23880 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2024 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 From f7c9c6d796e410495a43282c1b947438afd15fd0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 14 Jan 2025 16:11:13 +0100 Subject: [PATCH 040/106] Fix tablist --- .../src/de/steamwar/velocitycore/tablist/Tablist.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java index 2c380a90..f15bc79c 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -142,8 +142,14 @@ public class Tablist extends ChannelInboundHandlerAdapter { } public void onServerPostSwitch() { - if(player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20)) + if(player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20)) { + if(player.getProtocolVersion().greaterThan(ProtocolVersion.MINECRAFT_1_20)) { + sendTabPacket(current, null); + current.clear(); + } + sendPacket(player, createTeamPacket); + } } private void injection() { From 91d4a2dac35c049189a3d0608898ae0c3085a73d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 15 Jan 2025 10:01:23 +0100 Subject: [PATCH 041/106] Changes for new Server --- VelocityCore/src/de/steamwar/velocitycore/Node.java | 6 +++--- .../src/de/steamwar/velocitycore/ServerStarter.java | 6 +++--- .../src/de/steamwar/velocitycore/ServerVersion.java | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/Node.java b/VelocityCore/src/de/steamwar/velocitycore/Node.java index 23cf808a..9c717886 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/Node.java +++ b/VelocityCore/src/de/steamwar/velocitycore/Node.java @@ -97,9 +97,9 @@ public abstract class Node { protected void constructServerstart(File directory, List cmd, String serverJar, String worldDir, String levelName, int port, String... dParams) { if (JAVA_8.contains(serverJar)) - cmd.add("/usr/lib/jvm/java-8-openj9-amd64/bin/java"); + cmd.add("/usr/lib/jvm/openj9-8/bin/java"); else - cmd.add("/usr/lib/jvm/java-21-openj9-amd64/bin/java"); + cmd.add("/usr/lib/jvm/openj9-21/bin/java"); for(String param : dParams){ cmd.add("-D" + param); @@ -113,7 +113,7 @@ public abstract class Node { cmd.add("-XX:-CRIUSecProvider"); } cmd.add("-jar"); - cmd.add("/binarys/" + serverJar); + cmd.add("/jars/" + serverJar); cmd.add("--log-strip-color"); cmd.add("--world-dir"); cmd.add(worldDir); diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index 0fbdf696..ce3b5240 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -49,10 +49,10 @@ public class ServerStarter { private static final String USER_HOME = System.getProperty("user.home") + "/"; private static final String EVENT_PATH = USER_HOME + "event/"; public static final String TEMP_WORLD_PATH = USER_HOME + "arenaserver/"; - public static final String TUTORIAL_PATH = USER_HOME + "tutorials/"; - public static final String WORLDS_BASE_PATH = USER_HOME + "userworlds"; - public static final String BUILDER_BASE_PATH = USER_HOME + "builder"; + public static final String TUTORIAL_PATH = "/worlds/tutorials/"; + public static final String WORLDS_BASE_PATH = "/worlds/userworlds"; + public static final String BUILDER_BASE_PATH = "/worlds/builder"; private File directory = null; private String worldDir = null; diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index fd505e77..093933bc 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -41,11 +41,10 @@ public enum ServerVersion { PAPER_8("paper-1.8.8.jar", 8, ProtocolVersion.MINECRAFT_1_8), PAPER_10("paper-1.10.2.jar", 10, ProtocolVersion.MINECRAFT_1_10), PAPER_12("paper-1.12.2.jar", 12, ProtocolVersion.MINECRAFT_1_12_2), - PAPER_15("paper-1.15.2.jar", 15, ProtocolVersion.MINECRAFT_1_15_2), PAPER_18("paper-1.18.2.jar", 15, ProtocolVersion.MINECRAFT_1_18_2), PAPER_19("paper-1.19.3.jar", 19, ProtocolVersion.MINECRAFT_1_19_3), PAPER_20("paper-1.20.1.jar", 20, ProtocolVersion.MINECRAFT_1_20), - PAPER_21("paper-1.21.jar", 21, ProtocolVersion.MINECRAFT_1_21_2); + PAPER_21("paper-1.21.3.jar", 21, ProtocolVersion.MINECRAFT_1_21_2); private static final Map chatMap = new HashMap<>(); @@ -66,7 +65,7 @@ public enum ServerVersion { chatMap.put("mwg", ServerVersion.PAPER_20); chatMap.put("miniwargear", ServerVersion.PAPER_20); - chatMap.put("19", ServerVersion.PAPER_19); + /*chatMap.put("19", ServerVersion.PAPER_19); chatMap.put("1.19", ServerVersion.PAPER_19); chatMap.put("1.19.2", ServerVersion.PAPER_19); @@ -76,7 +75,7 @@ public enum ServerVersion { chatMap.put("12", ServerVersion.SPIGOT_12); chatMap.put("1.12", ServerVersion.SPIGOT_12); - chatMap.put("1.12.2", ServerVersion.SPIGOT_12); + chatMap.put("1.12.2", ServerVersion.SPIGOT_12);*/ } public static ServerVersion get(String chat) { From 2564227ec7347c3a42d6edf4596adadc6797216e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 18:18:11 +0100 Subject: [PATCH 042/106] CI Test --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 21b9838c..011b3e37 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * 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 From 12c2ae435deb9191139c34d6d4abb7f5bed6da8b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 18:21:44 +0100 Subject: [PATCH 043/106] CI Test --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index ccd23880..7b474b73 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * 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 From 8e7a6a56caf9e450f3fecc4cec71388dab46423b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 18:23:57 +0100 Subject: [PATCH 044/106] buildSrc/build.gradle aktualisiert --- buildSrc/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index ff9b2587..5aa2e416 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * 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 From 82e6aff4bb0b32cb1c51276a954b1409c0aeab7e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 18:32:49 +0100 Subject: [PATCH 045/106] buildSrc/src/steamwar.java.gradle aktualisiert --- buildSrc/src/steamwar.java.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/steamwar.java.gradle b/buildSrc/src/steamwar.java.gradle index e68f9fda..a0da4a5f 100644 --- a/buildSrc/src/steamwar.java.gradle +++ b/buildSrc/src/steamwar.java.gradle @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * 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 From ceff8e9cd5dc95a159bf6e346468fddd1de42865 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 21:51:09 +0100 Subject: [PATCH 046/106] BauSystem/build.gradle.kts aktualisiert --- BauSystem/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/build.gradle.kts b/BauSystem/build.gradle.kts index 7a02ffa7..712238c8 100644 --- a/BauSystem/build.gradle.kts +++ b/BauSystem/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2024 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 From 2d84cc8ca71609a0e380bc5cdf178a45995ed0c2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 21:54:30 +0100 Subject: [PATCH 047/106] KotlinCore/build.gradle.kts aktualisiert --- KotlinCore/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KotlinCore/build.gradle.kts b/KotlinCore/build.gradle.kts index 0c610074..c3bb85b5 100644 --- a/KotlinCore/build.gradle.kts +++ b/KotlinCore/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2024 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 From 60968283947d361b478372104653b29558ff76b2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 22:00:12 +0100 Subject: [PATCH 048/106] SchematicSystem/build.gradle.kts aktualisiert --- SchematicSystem/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SchematicSystem/build.gradle.kts b/SchematicSystem/build.gradle.kts index 2c9ef365..f9871adc 100644 --- a/SchematicSystem/build.gradle.kts +++ b/SchematicSystem/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2024 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 From 349e36fb6b1fbb0eecc707b30a9d8883bb5f03dc Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 22:12:55 +0100 Subject: [PATCH 049/106] CommandFramework/build.gradle.kts aktualisiert --- CommandFramework/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommandFramework/build.gradle.kts b/CommandFramework/build.gradle.kts index 61fbf34e..7fcb7845 100644 --- a/CommandFramework/build.gradle.kts +++ b/CommandFramework/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2024 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 From 393f840507e9d8463020d4d135abe02a93765129 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 22:14:39 +0100 Subject: [PATCH 050/106] BauSystem/build.gradle.kts aktualisiert --- BauSystem/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/build.gradle.kts b/BauSystem/build.gradle.kts index 712238c8..fd4e9a56 100644 --- a/BauSystem/build.gradle.kts +++ b/BauSystem/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * 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 From 79a0fcb3aa670bc766e040a73b17b1eca1a137c5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 15 Jan 2025 22:20:50 +0100 Subject: [PATCH 051/106] BauSystem/build.gradle.kts aktualisiert --- BauSystem/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/build.gradle.kts b/BauSystem/build.gradle.kts index fd4e9a56..712238c8 100644 --- a/BauSystem/build.gradle.kts +++ b/BauSystem/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2025 SteamWar.de-Serverteam + * Copyright (C) 2024 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 From fe4e486d413009d066933c31e58d2f4c505e121e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 16 Jan 2025 15:07:22 +0100 Subject: [PATCH 052/106] Test CI --- steamwarci.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/steamwarci.yml b/steamwarci.yml index 9e5f7f8e..8a038b62 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -2,35 +2,35 @@ build: - "./gradlew build --no-daemon" artifacts: - "/binarys/bausystem2.0.jar": "BauSystem/build/libs/BauSystem-all.jar" + "/jars/BauSystem.jar": "BauSystem/build/libs/BauSystem-all.jar" - "/binarys/fightsystem.jar": "FightSystem/build/libs/FightSystem-all.jar" - "/binarys/FightSystem_Standalone.jar": "FightSystem/FightSystem_Standalone/build/libs/FightSystem_Standalone-all.jar" + "/jars/FightSystem.jar": "FightSystem/build/libs/FightSystem-all.jar" + #"/binarys/FightSystem_Standalone.jar": "FightSystem/FightSystem_Standalone/build/libs/FightSystem_Standalone-all.jar" - "/binarys/kotlincore.jar": "KotlinCore/build/libs/KotlinCore-all.jar" - "/binarys/tntleague.jar": "TNTLeague/build/libs/TNTLeague.jar" + "/jars/KotlinCore.jar": "KotlinCore/build/libs/KotlinCore-all.jar" + "/jars/TNTLeague.jar": "TNTLeague/build/libs/TNTLeague.jar" - "/binarys/lobbysystem2.0.jar": "LobbySystem/build/libs/LobbySystem.jar" + "/jars/LobbySystem.jar": "LobbySystem/build/libs/LobbySystem.jar" - "/binarys/missilewars.jar": "MissileWars/build/libs/MissileWars.jar" + "/jars/MissileWars.jar": "MissileWars/build/libs/MissileWars.jar" - "/binarys/realtime.jar": "Realtime/build/libs/Realtime.jar" + "/jars/RealTime.jar": "Realtime/build/libs/Realtime.jar" - "/binarys/schematicsystem.jar": "SchematicSystem/build/libs/SchematicSystem-all.jar" + "/jars/SchematicSystem.jar": "SchematicSystem/build/libs/SchematicSystem-all.jar" - "/binarys/spigotcore.jar": "SpigotCore/build/libs/SpigotCore-all.jar" + "/jars/SpigotCore.jar": "SpigotCore/build/libs/SpigotCore-all.jar" - "/binarys/Builder.jar": "Teamserver/build/libs/Teamserver.jar" + "/jars/Builder.jar": "Teamserver/build/libs/Teamserver.jar" - "/binarys/towerrun.jar": "TowerRun/build/libs/TowerRun.jar" + "/jars/TowerRun.jar": "TowerRun/build/libs/TowerRun.jar" - "/binarys/tutorialsystem.jar": "TutorialSystem/build/libs/TutorialSystem.jar" + "/jars/TutorialSystem.jar": "TutorialSystem/build/libs/TutorialSystem.jar" - "/binarys/PersistentVelocityCore.jar": "VelocityCore/Persistent/build/libs/Persistent.jar" - "/binarys/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar" - "/binarys/deployarena.py": "VelocityCore/deployarena.py" + "/jars/PersistentVelocityCore.jar": "VelocityCore/Persistent/build/libs/Persistent.jar" + "/jars/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar" + "/usr/local/bin/deployarena.py": "VelocityCore/deployarena.py" - "/binarys/website-api.jar": "WebsiteBackend/build/libs/WebsiteBackend-all.jar" + "/jars/website-api.jar": "WebsiteBackend/build/libs/WebsiteBackend-all.jar" release: - "sudo systemctl restart api.service" From 4012426e26256d40fc224a39d5e1977fd9e70c96 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 16 Jan 2025 15:19:44 +0100 Subject: [PATCH 053/106] Test CI --- steamwarci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/steamwarci.yml b/steamwarci.yml index 8a038b62..4f4703dc 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -1,4 +1,5 @@ build: + - "printenv" - "./gradlew build --no-daemon" artifacts: From fba7fe5008d719a7c2430112d64ad7be1fc6b486 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 16 Jan 2025 15:23:17 +0100 Subject: [PATCH 054/106] Test CI --- steamwarci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/steamwarci.yml b/steamwarci.yml index 4f4703dc..1e2f6eed 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -2,6 +2,7 @@ build: - "printenv" - "./gradlew build --no-daemon" + artifacts: "/jars/BauSystem.jar": "BauSystem/build/libs/BauSystem-all.jar" From 429f938f1ca3ed8cf9e2c570b146c092c7847737 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 16 Jan 2025 16:26:57 +0100 Subject: [PATCH 055/106] Test CI --- steamwarci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/steamwarci.yml b/steamwarci.yml index 1e2f6eed..4f4703dc 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -2,7 +2,6 @@ build: - "printenv" - "./gradlew build --no-daemon" - artifacts: "/jars/BauSystem.jar": "BauSystem/build/libs/BauSystem-all.jar" From 0c815ee1d5a917874b39a9b00450b166b4653f71 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 16 Jan 2025 16:37:50 +0100 Subject: [PATCH 056/106] Test CI --- steamwarci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/steamwarci.yml b/steamwarci.yml index 4f4703dc..1e2f6eed 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -2,6 +2,7 @@ build: - "printenv" - "./gradlew build --no-daemon" + artifacts: "/jars/BauSystem.jar": "BauSystem/build/libs/BauSystem-all.jar" From eaae2f4009a116d8e3cc030db9e068deb8862ba5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Jan 2025 13:28:57 +0100 Subject: [PATCH 057/106] Adapt to new server, unlock old versions again --- .../de/steamwar/providers/BauServerInfo.java | 9 +----- VelocityCore/deployarena.py | 4 +-- .../steamwar/velocitycore/ServerStarter.java | 28 +++++++++++++------ .../steamwar/velocitycore/ServerVersion.java | 4 +-- .../velocitycore/commands/BauCommand.java | 2 +- .../commands/BuilderCloudCommand.java | 2 +- steamwarci.yml | 1 - 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java index b7de60b1..ddc7839e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java @@ -19,22 +19,15 @@ package de.steamwar.providers; -import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; -import java.util.UUID; - public class BauServerInfo { private static Integer bauOwner = null; static { try { bauOwner = Integer.parseInt(Bukkit.getWorlds().get(0).getName()); - } catch (NumberFormatException e) { - try { - bauOwner = SteamwarUser.get(UUID.fromString(Bukkit.getWorlds().get(0).getName())).getId(); - } catch (IllegalArgumentException ignored) {} - } + } catch (NumberFormatException ignored) {} } public static Integer getOwnerId() { diff --git a/VelocityCore/deployarena.py b/VelocityCore/deployarena.py index d058b8e4..2195e264 100755 --- a/VelocityCore/deployarena.py +++ b/VelocityCore/deployarena.py @@ -37,11 +37,11 @@ if __name__ == "__main__": with open(configfile, 'r') as file: gamemode = yaml.load(file) - builderworld = path.expanduser(f'~/builder{version}/{worldname}') + builderworld = path.expanduser(f'/worlds/builder{version}/{worldname}') arenaworld = f'/servers/{gamemode["Server"]["Folder"]}/arenas/{worldname}' if path.exists(arenaworld): - backupworld = path.expanduser(f'~/backup/arenas/{datetime.datetime.now()}-{worldname}-{version}.tar.xz') + backupworld = path.expanduser(f'/mnt/storage/backup/arenas/{datetime.datetime.now()}-{worldname}-{version}.tar.xz') with tarfile.open(backupworld, 'w:xz') as tar: tar.add(arenaworld, arcname=worldname) diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index ce3b5240..67567ae9 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -46,13 +46,17 @@ public class ServerStarter { private static final Portrange ARENA_PORTS = VelocityCore.MAIN_SERVER ? new Portrange(3000, 3100) : (VelocityCore.get().getConfig().isEventmode() ? new Portrange(4000, 5000) : BAU_PORTS); public static final String SERVER_PATH = "/servers/"; - private static final String USER_HOME = System.getProperty("user.home") + "/"; - private static final String EVENT_PATH = USER_HOME + "event/"; - public static final String TEMP_WORLD_PATH = USER_HOME + "arenaserver/"; - public static final String TUTORIAL_PATH = "/worlds/tutorials/"; - public static final String WORLDS_BASE_PATH = "/worlds/userworlds"; - public static final String BUILDER_BASE_PATH = "/worlds/builder"; + private static final String TMP_DATA = System.getProperty("user.home") + "/"; + private static final String EVENT_PATH = TMP_DATA + "event/"; + public static final String TEMP_WORLD_PATH = TMP_DATA + "arenaserver/"; + + private static final String WORLDS_FOLDER = "/worlds"; + public static final String TUTORIAL_PATH = WORLDS_FOLDER + "/tutorials/"; + public static final String WORLDS_BASE_PATH = WORLDS_FOLDER + "/userworlds"; + public static final String BUILDER_BASE_PATH = WORLDS_FOLDER + "/builder"; + + private static final String WORLDS_STORAGE_BASE_PATH = "/mnt/storage/worlds/userworlds"; private File directory = null; private String worldDir = null; @@ -149,15 +153,21 @@ public class ServerStarter { this.version = version; directory = version.getServerDirectory("Bau"); worldDir = version.getWorldFolder(WORLDS_BASE_PATH); - worldName = version != ServerVersion.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString(); + worldName = String.valueOf(SteamwarUser.get(owner).getId()); checkpoint = true; build(owner); worldSetup = () -> { File world = new File(worldDir, worldName); - if (!world.exists()) - copyWorld(node, new File(directory, "Bauwelt").getPath(), world.getPath()); + if (!world.exists()) { + File storage = new File(version.getWorldFolder(WORLDS_STORAGE_BASE_PATH), worldName); + + if(storage.exists()) + node.execute("mv", storage.getPath(), world.getPath()); + else + copyWorld(node, new File(directory, "Bauwelt").getPath(), world.getPath()); + } }; // Send players to existing server diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index 093933bc..cc7c9d38 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -65,7 +65,7 @@ public enum ServerVersion { chatMap.put("mwg", ServerVersion.PAPER_20); chatMap.put("miniwargear", ServerVersion.PAPER_20); - /*chatMap.put("19", ServerVersion.PAPER_19); + chatMap.put("19", ServerVersion.PAPER_19); chatMap.put("1.19", ServerVersion.PAPER_19); chatMap.put("1.19.2", ServerVersion.PAPER_19); @@ -75,7 +75,7 @@ public enum ServerVersion { chatMap.put("12", ServerVersion.SPIGOT_12); chatMap.put("1.12", ServerVersion.SPIGOT_12); - chatMap.put("1.12.2", ServerVersion.SPIGOT_12);*/ + chatMap.put("1.12.2", ServerVersion.SPIGOT_12); } public static ServerVersion get(String chat) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java index 150df3fd..710bb1be 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java @@ -214,7 +214,7 @@ public class BauCommand extends SWCommand { public void delete(PlayerChatter sender, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { SWInventory inventory = new SWInventory(sender, 9, new Message("BAU_DELETE_GUI_NAME")); inventory.addItem(0, new SWItem(new Message("BAU_DELETE_GUI_DELETE"), 10), click -> { - String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerVersion.SPIGOT_12 ? sender.user().getId() : sender.user().getUUID().toString()); + String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + sender.user().getId(); VelocityCore.schedule(() -> { Bauserver subserver = Bauserver.get(sender.user().getUUID()); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java index 4c5c115d..51c0f1bf 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java @@ -90,7 +90,7 @@ public class BuilderCloudCommand extends SWCommand { } VelocityCore.schedule(() -> { - VelocityCore.local.execute("/binarys/deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map); + VelocityCore.local.execute("deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map); ArenaMode.init(); sender.system("BUILDERCLOUD_DEPLOY_FINISHED"); }).schedule(); diff --git a/steamwarci.yml b/steamwarci.yml index 1e2f6eed..0fa07cde 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -1,5 +1,4 @@ build: - - "printenv" - "./gradlew build --no-daemon" From afd054103966276217285cdc28d7d5109cefe7e8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Jan 2025 13:46:02 +0100 Subject: [PATCH 058/106] Move Replays to File system --- CommonCore/SQL/src/de/steamwar/sql/Fight.java | 11 ++- .../SQL/src/de/steamwar/sql/Replay.java | 74 ------------------- .../fightsystem/record/FileSource.java | 11 ++- .../fightsystem/utils/FightStatistics.java | 9 ++- 4 files changed, 22 insertions(+), 83 deletions(-) delete mode 100644 CommonCore/SQL/src/de/steamwar/sql/Replay.java diff --git a/CommonCore/SQL/src/de/steamwar/sql/Fight.java b/CommonCore/SQL/src/de/steamwar/sql/Fight.java index efa230d2..66efbef9 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/Fight.java +++ b/CommonCore/SQL/src/de/steamwar/sql/Fight.java @@ -35,8 +35,9 @@ import java.util.stream.Collectors; public class Fight { private static final Table table = new Table<>(Fight.class); - private static final SelectStatement getPage = new SelectStatement<>(table, "SELECT f.*, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, (SELECT COUNT(1) FROM Replay WHERE Replay.FightID = f.FightID) as ReplayAvailable FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); + private static final SelectStatement getPage = new SelectStatement<>(table, "SELECT f.*, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); private static final Statement insert = table.insertFields(true, "GameMode", "Server", "StartTime", "Duration", "BlueLeader", "RedLeader", "BlueSchem", "RedSchem", "Win", "WinCondition"); + private static final Statement updateReplayAvailable = table.update(Table.PRIMARY, "ReplayAvailable"); public static List getPage(int page, int elementsPerPage) { List fights = getPage.listSelect(page * elementsPerPage, elementsPerPage); @@ -54,6 +55,10 @@ public class Fight { return insert.insertGetKey(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition); } + public static void markReplayAvailable(int fightID) { + updateReplayAvailable.update(true, fightID); + } + @Getter @Field(keys = {Table.PRIMARY}, autoincrement = true) private final int fightID; @@ -80,10 +85,10 @@ public class Fight { private final int win; @Field private final String wincondition; + @Field + private final boolean replayAvailable; @Field // Virtual field for easy select private final boolean replayAllowed; - @Field // Virtual field for easy select - private final boolean replayAvailable; @Getter private final List bluePlayers = new ArrayList<>(); diff --git a/CommonCore/SQL/src/de/steamwar/sql/Replay.java b/CommonCore/SQL/src/de/steamwar/sql/Replay.java deleted file mode 100644 index a90e2392..00000000 --- a/CommonCore/SQL/src/de/steamwar/sql/Replay.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.sql; - -import de.steamwar.sql.internal.*; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.sql.SQLException; - -@AllArgsConstructor -public class Replay { - - static { - new SqlTypeMapper<>(File.class, "BLOB", (rs, identifier) -> { - try { - File file = File.createTempFile("replay", ".replay"); - file.deleteOnExit(); - Files.copy(rs.getBinaryStream(identifier), file.toPath(), StandardCopyOption.REPLACE_EXISTING); - return file; - } catch (IOException e) { - throw new SQLException(e); - } - }, (st, index, value) -> { - try { - st.setBinaryStream(index, new FileInputStream(value)); - } catch (FileNotFoundException e) { - throw new SQLException(e); - } - }); - } - - private static final Table table = new Table<>(Replay.class); - private static final SelectStatement get = table.select(Table.PRIMARY); - - public static final Statement insert = table.insertAll(); - - public static Replay get(int fightID) { - return get.select(fightID); - } - - public static void save(int fightID, File file) { - insert.update(fightID, file); - } - - @Field(keys = {Table.PRIMARY}) - private final int fightID; - @Getter - @Field - private final File replay; -} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java index 2fcaa59e..9e1a05ea 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java @@ -20,15 +20,18 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; -import de.steamwar.sql.Replay; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Files; import java.util.zip.GZIPInputStream; public class FileSource extends PacketSource { + public static File replayFile(int fightId) { + return new File("/mnt/storage/replays", fightId + ".replay"); + } + public static void startReplay() { if(Config.replayserver()) { try { @@ -41,7 +44,7 @@ public class FileSource extends PacketSource { if(Config.ReplayID > 0) { try { - new FileSource(Replay.get(Config.ReplayID).getReplay()); + new FileSource(replayFile(Config.ReplayID)); } catch (IOException e) { throw new SecurityException("Could not start replay", e); } @@ -49,7 +52,7 @@ public class FileSource extends PacketSource { } public FileSource(File fightFile) throws IOException { - super(new GZIPInputStream(new FileInputStream(fightFile))); + super(new GZIPInputStream(Files.newInputStream(fightFile.toPath()))); new PacketProcessor(this); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 1f46a3a8..35e0fc80 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -27,23 +27,25 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.FileRecorder; +import de.steamwar.fightsystem.record.FileSource; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.network.NetworkSender; import de.steamwar.network.packets.common.FightEndsPacket; -import de.steamwar.sql.Replay; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import lombok.Getter; import org.bukkit.Bukkit; +import java.io.IOException; import java.sql.Timestamp; import java.time.Instant; import java.util.logging.Level; import java.util.stream.Collectors; import static de.steamwar.sql.Fight.create; +import static de.steamwar.sql.Fight.markReplayAvailable; public class FightStatistics { @@ -125,7 +127,10 @@ public class FightStatistics { } try { - Replay.save(fightId, FileRecorder.getFile()); + if(!FileRecorder.getFile().renameTo(FileSource.replayFile(fightId))) + throw new IOException("Failed to move replay"); + + markReplayAvailable(fightId); } catch (Exception e) { Bukkit.getLogger().log(Level.INFO, "Failed to save replay", e); } From d42da4c90310b3a8633c5a4ba9f040e8f7412e28 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 17 Jan 2025 17:40:49 +0100 Subject: [PATCH 059/106] gradle.properties aktualisiert --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9d0945b1..e1095f30 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # # This file is a part of the SteamWar software. # -# Copyright (C) 2024 SteamWar.de-Serverteam +# Copyright (C) 2024 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 From 07185d096033879d765a7ba4efb48ce08f82385a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 17 Jan 2025 17:42:32 +0100 Subject: [PATCH 060/106] Test CI --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e1095f30..91f3a83a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # # This file is a part of the SteamWar software. # -# Copyright (C) 2024 SteamWar.de-Serverteam +# 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 From 3d78a23af18f63746765a0e2bcb0417b3043b69f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 17 Jan 2025 17:44:07 +0100 Subject: [PATCH 061/106] Test CI --- buildSrc/src/steamwar.kotlin.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/steamwar.kotlin.gradle b/buildSrc/src/steamwar.kotlin.gradle index 03b0a99d..72e6d640 100644 --- a/buildSrc/src/steamwar.kotlin.gradle +++ b/buildSrc/src/steamwar.kotlin.gradle @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * 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 From 21b389a99327d1dab925d81e25c2fc3e0eb20547 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 17 Jan 2025 22:28:46 +0100 Subject: [PATCH 062/106] Update Schematic Download and /webpw to new Website --- .../SQL/src/de/steamwar/sql/NodeDownload.java | 2 +- .../SQL/src/de/steamwar/sql/SteamwarUser.java | 7 ++-- .../core/events/PlayerJoinedEvent.java | 2 +- .../commands/PunishmentCommand.java | 2 +- .../commands/WebpasswordCommand.java | 35 +++++-------------- .../listeners/ConnectionListener.java | 3 +- 6 files changed, 18 insertions(+), 33 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java b/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java index b3792b63..030dbf38 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java @@ -35,7 +35,7 @@ import java.time.Instant; public class NodeDownload { private static final char[] HEX = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - private static final String LINK_BASE = "https://steamwar.de/download.php?schem="; + private static final String LINK_BASE = "https://steamwar.de/schematic?code="; private static final Table table = new Table<>(NodeDownload.class); private static final Statement insert = table.insertFields("NodeId", "Link"); diff --git a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java index d5b87b6e..9906d149 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java @@ -122,13 +122,12 @@ public class SteamwarUser { return byDiscord.select(discordId); } - public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer newPlayer, BiConsumer nameUpdate) { + public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer newPlayer) { SteamwarUser user = get(uuid); if (user != null) { if (!user.userName.equals(name)) { updateName.update(name, user.id); - nameUpdate.accept(user.userName, name); user.userName = name; } @@ -359,6 +358,10 @@ public class SteamwarUser { } } + public boolean hasPassword() { + return this.password == null; + } + private byte[] generateHash(String password, byte[] salt) throws InvalidKeySpecException { PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 512); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java index 8936de9a..29b0ffd8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java @@ -35,7 +35,7 @@ public class PlayerJoinedEvent implements Listener{ @EventHandler(priority = EventPriority.LOWEST) private void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - SteamwarUser user = Statement.productionDatabase() ? SteamwarUser.get(player.getUniqueId()) : SteamwarUser.getOrCreate(player.getUniqueId(), player.getName(), uuid -> {}, (oldName, newName) -> {}); + SteamwarUser user = Statement.productionDatabase() ? SteamwarUser.get(player.getUniqueId()) : SteamwarUser.getOrCreate(player.getUniqueId(), player.getName(), uuid -> {}); UserPerm.Prefix prefix = user.prefix(); if(prefix != UserPerm.emptyPrefix) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java index da847019..1dc8ebde 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java @@ -61,7 +61,7 @@ public class PunishmentCommand { return null; } - return SteamwarUser.getOrCreate(uuid, name, u -> {}, (o, n) -> {}); + return SteamwarUser.getOrCreate(uuid, name, u -> {}); } private static UUID getUUIDofOfflinePlayer(String playerName) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java index ff3370c8..3ab97ddf 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java @@ -21,10 +21,9 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.sql.SteamwarUser; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; public class WebpasswordCommand extends SWCommand { @@ -40,33 +39,15 @@ public class WebpasswordCommand extends SWCommand { return; } - ProcessBuilder pb = new ProcessBuilder("php", "/var/www/register.php", sender.user().getUserName(), password); - pb.redirectErrorStream(true); - try { - Process regProcess = pb.start(); - BufferedReader reader = new BufferedReader(new InputStreamReader(regProcess.getInputStream())); - String errorLine; - if((errorLine = reader.readLine()) != null) { - if ("updated".equals(errorLine)) { - sender.system("WEB_UPDATED"); - return; - } else { - throw new SecurityException("Could not create webaccount " + errorLine); - } - } + SteamwarUser user = sender.user(); + boolean resetPW = user.hasPassword(); + user.setPassword(password); + + if (resetPW) { + sender.system("WEB_UPDATED"); + } else { sender.system("WEB_CREATED"); - } catch (IOException e) { - throw new SecurityException("Could not create webaccount", e); - } - } - - public static void changeUsername(String oldUsername, String newUsername){ - ProcessBuilder pb = new ProcessBuilder("php", "/var/www/changename.php", oldUsername, newUsername); - try { - pb.start(); - } catch (IOException e) { - throw new SecurityException("Could not change username", e); } } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java index c1a4b51d..95edeabb 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java @@ -39,6 +39,7 @@ import net.kyori.adventure.text.event.ClickEvent; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import java.util.function.BiConsumer; public class ConnectionListener extends BasicListener { @@ -56,7 +57,7 @@ public class ConnectionListener extends BasicListener { if(!(subject instanceof Player player)) return perm -> Tristate.TRUE; - Set perms = SteamwarUser.getOrCreate(player.getUniqueId(), player.getUsername(), ConnectionListener::newPlayer, WebpasswordCommand::changeUsername).perms(); + Set perms = SteamwarUser.getOrCreate(player.getUniqueId(), player.getUsername(), ConnectionListener::newPlayer).perms(); if(perms.contains(UserPerm.ADMINISTRATION)) return perm -> Tristate.TRUE; else if(perms.contains(UserPerm.TEAM)) From ab4aaf782f44a7c831208829547079ba1a0c2a79 Mon Sep 17 00:00:00 2001 From: TheBreadBeard Date: Mon, 20 Jan 2025 00:42:45 +0100 Subject: [PATCH 063/106] Fix custom NPC Chats color codes for TheBreadBeard --- .../src/de/steamwar/lobby/LobbySystem.properties | 12 ++++++------ .../src/de/steamwar/lobby/LobbySystem_de.properties | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties index 275a99a8..3375de0a 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties @@ -11,12 +11,12 @@ NPC_CHAT_3 = §fBecome a part of our team by applying via our Discord server (ht NPC_CHAT_4 = §fYou can develop your own buildserver features with our Lua script system. NPC_CHAT_5 = §fThere are many secrets to discover in this lobby. ## TheBreadBeard -NPC_CHAT_3266_0 = §fI collect Alts like Infinity Stones. -NPC_CHAT_3266_1 = &fYou want my Bread? You can have it! Just look for it! I've hidden the best bakery in the world somewhere! -NPC_CHAT_3266_2 = &fHey, I am TheBreadBeard, ex- EuropSuchties Player, formerly (un)known as WarGear_Titan. -NPC_CHAT_3266_3 = &fInventor of Lactose Intolerance, the Placeholder and Infinity-Ring. All technical principles no one knows or needs. -NPC_CHAT_3266_4 = &fKnown for the Lobby-Banners, logos, spontaneous Arenas, as well as an Organizer and Moderator of many Events. -NPC_CHAT_3266_5 = &fFrom Supporter to Moderator to Builder ... Maybe the journey takes me to being a Developer next. +NPC_CHAT_3266_0 = §fI collect alts like Infinity Stones. +NPC_CHAT_3266_1 = §fYou want my Bread? You can have it! Just look for it! I've hidden the best bakery in the world somewhere! +NPC_CHAT_3266_2 = §fHey, I am TheBreadBeard, ex- EuropSuchties player, formerly (un)known as WarGear_Titan. +NPC_CHAT_3266_3 = §fInventor of Lactose Intolerance, the Placeholder and Infinity-Ring. All technical principles no one knows or needs. +NPC_CHAT_3266_4 = §fKnown for the lobby-banners, logos, spontaneous arenas, as well as an organizer and moderator of many events. +NPC_CHAT_3266_5 = §fFrom supporter to moderator to builder ... Maybe the journey takes me to being a developer next. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Lists all portals diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties index bf382639..9823f57c 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties @@ -12,11 +12,11 @@ NPC_CHAT_4 = §fDu kannst mit unserm Lua Script-System deine eigenen Bau Feature NPC_CHAT_5 = §fAuf dieser Lobby sind so einige secrets versteckt. ## TheBreadBeard NPC_CHAT_3266_0 = §fIch sammel Alts wie Infinity Stones. -NPC_CHAT_3266_1 = &fIhr wollt meine Teigwaren? Die könnt ihr haben! Sucht sie doch! Irgendwo hab ich die beste Bäckerei der Welt versteckt! -NPC_CHAT_3266_2 = &fMoin, Ich bin TheBreadBeard, ehemaliger EuropSuchties Spieler, damals (un)bekannt als WarGear_Titan. -NPC_CHAT_3266_3 = &fErfinder der Laktoseintoleranz, des Platzhalters und des Infinity-Rings. Alles Prinzipien, die keiner kennt und keiner braucht. -NPC_CHAT_3266_4 = &fBekannt für die Lobbybanner, Logos, spontane Arenen, sowie als Leiter von so manchem Event. -NPC_CHAT_3266_5 = &fVon Supporter zu Moderator zu Builder ... Vielleicht führt mich die Reise als Nächstes zum Developer. +NPC_CHAT_3266_1 = §fIhr wollt meine Teigwaren? Die könnt ihr haben! Sucht sie doch! Irgendwo hab ich die beste Bäckerei der Welt versteckt! +NPC_CHAT_3266_2 = §fMoin, Ich bin TheBreadBeard, ehemaliger EuropSuchties Spieler, damals (un)bekannt als WarGear_Titan. +NPC_CHAT_3266_3 = §fErfinder der Laktoseintoleranz, des Platzhalters und des Infinity-Rings. Alles Prinzipien, die keiner kennt und keiner braucht. +NPC_CHAT_3266_4 = §fBekannt für die Lobbybanner, Logos, spontane Arenen, sowie als Leiter von so manchem Event. +NPC_CHAT_3266_5 = §fVon Supporter zu Moderator zu Builder ... Vielleicht führt mich die Reise als Nächstes zum Developer. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Listet alle Portale auf From 658dcd024d3bfe31c1558a3109287fe4dc92499f Mon Sep 17 00:00:00 2001 From: TheBreadBeard Date: Sat, 28 Dec 2024 17:07:00 +0100 Subject: [PATCH 064/106] Add teamsOnSameLine for Arena Monochrome --- .../tntleague/config/TNTLeagueWorldConfig.kt | 3 +++ .../tntleague/events/IngameListener.kt | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt index 7fc94826..df2dd34e 100644 --- a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt +++ b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt @@ -29,6 +29,7 @@ import org.bukkit.configuration.ConfigurationSection import org.bukkit.configuration.file.YamlConfiguration import org.bukkit.entity.WanderingTrader import java.io.File +import kotlin.math.abs import kotlin.properties.Delegates val world by lazy { plugin.server.worlds.first()!! } @@ -56,6 +57,7 @@ object TNTLeagueWorldConfig { lateinit var blueTeam: TeamConfig lateinit var redTeam: TeamConfig lateinit var lobby: Location + var teamsOnSameLine by Delegates.notNull() lateinit var targetMaterial: Material var minHeight by Delegates.notNull() var target by Delegates.notNull() @@ -64,6 +66,7 @@ object TNTLeagueWorldConfig { try { blueTeam = TeamConfig.fromConfig(config.getConfigurationSection("blueTeam")!!) redTeam = TeamConfig.fromConfig(config.getConfigurationSection("redTeam")!!) + teamsOnSameLine = abs(blueTeam.spawnLocation.blockX - redTeam.spawnLocation.blockX) < 20 lobby = config.getWorldLocation("lobby", blueTeam.spawnLocation.clone().add(redTeam.spawnLocation).multiply(0.5)) targetMaterial = Material.matchMaterial(config.getString("targetMaterial", "IRON_BLOCK")!!)!! minHeight = config.getInt("minHeight", 0) diff --git a/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt index e48ea7e6..976e49a3 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt @@ -38,13 +38,13 @@ import org.bukkit.event.player.PlayerInteractEntityEvent import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.event.player.PlayerMoveEvent -object IngameListener: Listener { +object IngameListener : Listener { @EventHandler fun onEntityInteract(e: PlayerInteractEntityEvent) { if (e.player.gameMode == GameMode.SPECTATOR) return - if(e.rightClicked.type == EntityType.WANDERING_TRADER) { + if (e.rightClicked.type == EntityType.WANDERING_TRADER) { e.isCancelled = true e.player.openInventory(DealerInventory(e.player).getInventory()) } @@ -66,11 +66,12 @@ object IngameListener: Listener { @EventHandler fun onMove(e: PlayerMoveEvent) { - if (TNTLeagueGame.getTeam(e.player) != null) { - if (e.to.blockX >= TNTLeagueWorldConfig.lobby.blockX && e.to.blockX <= TNTLeagueWorldConfig.lobby.blockX + 1 || - e.to.blockZ >= TNTLeagueWorldConfig.lobby.blockZ && e.to.blockZ <= TNTLeagueWorldConfig.lobby.blockZ + 1) { - e.isCancelled = true - } + if (TNTLeagueGame.getTeam(e.player) == null) return + if (e.to.blockZ >= TNTLeagueWorldConfig.lobby.blockZ && e.to.blockZ <= TNTLeagueWorldConfig.lobby.blockZ + 1) { + e.isCancelled = true + } + if (!TNTLeagueWorldConfig.teamsOnSameLine && e.to.blockX >= TNTLeagueWorldConfig.lobby.blockX && e.to.blockX <= TNTLeagueWorldConfig.lobby.blockX + 1) { + e.isCancelled = true } } @@ -84,7 +85,8 @@ object IngameListener: Listener { @EventHandler fun onPickupCoins(e: PlayerAttemptPickupItemEvent) { if (e.item.itemStack.isSimilar(DealerInventory.coins)) { - TNTLeagueGame.getTeam(e.player)?.coins = e.item.itemStack.amount + (TNTLeagueGame.getTeam(e.player)?.coins ?: 0) + TNTLeagueGame.getTeam(e.player)?.coins = + e.item.itemStack.amount + (TNTLeagueGame.getTeam(e.player)?.coins ?: 0) e.item.itemStack.amount = 0 e.isCancelled = true @@ -100,7 +102,7 @@ object IngameListener: Listener { } private fun Map.filterKeysNotNull(destination: MutableMap = mutableMapOf()): Map { - this.forEach { (t, u) -> if(t != null) destination[t] = u } + this.forEach { (t, u) -> if (t != null) destination[t] = u } return destination } } \ No newline at end of file From 2192eddb8bf36e8f9ac7e364a0ed8cf4c83d5088 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2025 11:19:08 +0100 Subject: [PATCH 065/106] Test CI --- steamwarci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/steamwarci.yml b/steamwarci.yml index 0fa07cde..8a038b62 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -1,7 +1,6 @@ build: - "./gradlew build --no-daemon" - artifacts: "/jars/BauSystem.jar": "BauSystem/build/libs/BauSystem-all.jar" From 898f3c785b2e07a87e61906b00e344323ab003e3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2025 11:24:56 +0100 Subject: [PATCH 066/106] Test CI --- steamwarci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/steamwarci.yml b/steamwarci.yml index 8a038b62..0fa07cde 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -1,6 +1,7 @@ build: - "./gradlew build --no-daemon" + artifacts: "/jars/BauSystem.jar": "BauSystem/build/libs/BauSystem-all.jar" From 3be748b92ea850e7dacbd2227335b9eee56d6123 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2025 11:30:05 +0100 Subject: [PATCH 067/106] Fix maven repo location --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 7b474b73..cea601bf 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -44,7 +44,7 @@ dependencyResolutionManagement { maven { if (isInCi) { - url = URI("file:///var/www/html/maven/") + url = URI("file:///var/www/maven/") } else { url = URI("https://steamwar.de/maven/") credentials { From 3d2cba6a286ed860e2c3714572bbe85aa272f581 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2025 12:19:10 +0100 Subject: [PATCH 068/106] Fix tutorials --- VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index 67567ae9..a6707c45 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -195,6 +195,7 @@ public class ServerStarter { } public ServerStarter tutorial(Player owner, Tutorial tutorial) { + version = ServerVersion.SPIGOT_15; directory = new File(SERVER_PATH, "Tutorial"); buildWithTemp(owner); tempWorld(TUTORIAL_PATH + tutorial.getTutorialId()); From 721723716e291f1cb929aa7eada436c019077230 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2025 12:25:55 +0100 Subject: [PATCH 069/106] Fix sign --- CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java | 3 +-- .../velocitycore/commands/WebpasswordCommand.java | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java index 9906d149..d4bed21c 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java @@ -29,7 +29,6 @@ import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; import java.sql.Timestamp; import java.util.*; -import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.logging.Level; import java.util.stream.Collectors; @@ -359,7 +358,7 @@ public class SteamwarUser { } public boolean hasPassword() { - return this.password == null; + return this.password != null; } private byte[] generateHash(String password, byte[] salt) diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java index 3ab97ddf..d19dedd0 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java @@ -23,8 +23,6 @@ import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; -import java.io.IOException; - public class WebpasswordCommand extends SWCommand { public WebpasswordCommand() { @@ -44,10 +42,6 @@ public class WebpasswordCommand extends SWCommand { user.setPassword(password); - if (resetPW) { - sender.system("WEB_UPDATED"); - } else { - sender.system("WEB_CREATED"); - } + sender.system(resetPW ? "WEB_UPDATED" : "WEB_CREATED"); } } From a13039bce42bf107f55523f992e72537d8fe1cec Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2025 12:31:27 +0100 Subject: [PATCH 070/106] Fix unignore message --- VelocityCore/src/de/steamwar/messages/BungeeCore.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index 887a73d6..d9ddc86e 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -541,7 +541,7 @@ TP_USAGE_EVENT=§8/§7tp §8[§ePlayer §7or §eteam§8] UNIGNORE_USAGE=§8/§7unignore §8[§eplayer§8] UNIGNORE_NOT_PLAYER=§cThis player does not exist! UNIGNORE_NOT_IGNORED=§cYou are not ignoring this player. -UNIGNORE_UNIGNORED=§7You ignored §e{0}§8. +UNIGNORE_UNIGNORED=§7You unignored §e{0}§8. #WebregisterCommand WEB_USAGE=§8/§7webpassword §8[§epassword§8] From 6519269d74249a00dc6b70fba6c5b054f9293a12 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 20 Jan 2025 16:07:52 +0100 Subject: [PATCH 071/106] Add bust to RatsChannel threads --- .../velocitycore/discord/DiscordBot.java | 3 +- .../velocitycore/discord/DiscordConfig.java | 2 + .../discord/channels/RatsChannel.java | 108 ++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 10cb773f..20b8d219 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -189,7 +189,8 @@ public class DiscordBot { new DiscordTicketHandler(), new DiscordTeamEvent(), new ChannelListener(), - new DiscordSchemUpload() + new DiscordSchemUpload(), + new RatsChannel() ); commandSetup(jda.retrieveCommands().complete(), jda.updateCommands()); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java index af930d77..60a13f88 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java @@ -56,6 +56,8 @@ public class DiscordConfig { private String ticketcategory; + private Map ratsRoleToThread; + @NoArgsConstructor public static class DiscordRole { diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java new file mode 100644 index 00000000..315d1839 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java @@ -0,0 +1,108 @@ +package de.steamwar.velocitycore.discord.channels; + +import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.discord.DiscordBot; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; +import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.api.utils.AttachedFile; +import net.dv8tion.jda.api.utils.FileUpload; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.*; +import java.util.stream.Collectors; + +public class RatsChannel extends ListenerAdapter { + + private Map ratsChannel = new HashMap<>(); + + public RatsChannel() { + DiscordBot.getInstance().getConfig().getRatsRoleToThread().forEach((roleId, threadId) -> { + Role role = DiscordBot.getGuild().getRoleById(roleId); + if (role != null) return; + ThreadChannel threadChannel = DiscordBot.getGuild().getThreadChannelById(threadId); + if (threadChannel != null) ratsChannel.put(role, threadChannel); + ratsChannel.put(role, threadChannel); + }); + } + + @Override + public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { + updateRatsChannel(event.getRoles()); + } + + @Override + public void onGuildMemberRoleRemove(@NotNull GuildMemberRoleRemoveEvent event) { + updateRatsChannel(event.getRoles()); + } + + private void updateRatsChannel(List roles) { + for (Role role : roles) { + if (!ratsChannel.containsKey(role)) continue; + ThreadChannel channel = ratsChannel.get(role); + + List> ratMembers = loadImages(role) + .entrySet() + .stream() + .sorted(Comparator.comparing(value -> value.getKey().getUserName())) + .collect(Collectors.toList()); + + List messages = new ArrayList<>(channel.getHistory() + .retrievePast(100) + .complete()); + // Need to reverse since they are provided from newest (0) to latest (size() - 1) + Collections.reverse(messages); + + Iterator iterator = messages.iterator(); + if (!iterator.hasNext()) { + channel.sendMessage("# Ratsmitglieder") + .queue(); + } else { + iterator.next(); + } + + for (Map.Entry entry : ratMembers) { + if (iterator.hasNext()) { + Message message = iterator.next(); + if (message.getContentRaw().startsWith("# " + entry.getKey().getUserName())) { + continue; + } + + message.editMessage("## " + entry.getKey().getUserName()) + .setAttachments(AttachedFile.fromData(entry.getValue(), entry.getKey().getUUID().toString() + ".png")) + .queue(); + } else { + channel.sendMessage("## " + entry.getKey().getUserName()) + .addFiles(FileUpload.fromData(entry.getValue(), entry.getKey().getUUID().toString() + ".png")) + .queue(); + } + } + + while (iterator.hasNext()) { + iterator.next().delete().queue(); + } + } + } + + private Map loadImages(Role role) { + Map images = new HashMap<>(); + for (Member member : DiscordBot.getGuild().getMembersWithRoles(role)) { + SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); + if (steamwarUser == null) continue; + + try { + images.put(steamwarUser, new URL("api.steamwar.de/data/skin/" + steamwarUser.getUUID().toString()).openStream()); + } catch (IOException e) { + images.put(steamwarUser, null); + } + } + return images; + } +} From 052e549606bb817f5d4355a442bd2740500f6b5c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2025 16:09:40 +0100 Subject: [PATCH 072/106] Fix replay saving --- .../steamwar/fightsystem/utils/FightStatistics.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 35e0fc80..ae9a56ac 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -38,7 +38,7 @@ import de.steamwar.sql.SteamwarUser; import lombok.Getter; import org.bukkit.Bukkit; -import java.io.IOException; +import java.nio.file.Files; import java.sql.Timestamp; import java.time.Instant; import java.util.logging.Level; @@ -126,14 +126,9 @@ public class FightStatistics { Config.EventKampf.setFight(fightId); } - try { - if(!FileRecorder.getFile().renameTo(FileSource.replayFile(fightId))) - throw new IOException("Failed to move replay"); + Files.move(FileRecorder.getFile().toPath(), FileSource.replayFile(fightId).toPath()); - markReplayAvailable(fightId); - } catch (Exception e) { - Bukkit.getLogger().log(Level.INFO, "Failed to save replay", e); - } + markReplayAvailable(fightId); } catch (Exception e) { Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e); } From 569d5b033e4067856c3dfa5f45ded9392af76fe1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2025 16:14:44 +0100 Subject: [PATCH 073/106] Fix setlocale command --- .../velocitycore/commands/SetLocaleCommand.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java index 689485cf..a2e66b6b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java @@ -19,12 +19,10 @@ package de.steamwar.velocitycore.commands; -import de.steamwar.velocitycore.network.NetworkSender; import de.steamwar.command.SWCommand; -import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.network.packets.server.LocaleInvalidationPacket; - -import java.util.Objects; +import de.steamwar.velocitycore.network.NetworkSender; public class SetLocaleCommand extends SWCommand { @@ -33,8 +31,8 @@ public class SetLocaleCommand extends SWCommand { } @Register - public void genericCommand(Chatter sender) { - sender.user().setLocale(Objects.requireNonNull(sender.getLocale()), true); + public void genericCommand(PlayerChatter sender) { + sender.user().setLocale(sender.getPlayer().getPlayerSettings().getLocale(), true); sender.withPlayer(player -> NetworkSender.send(player, new LocaleInvalidationPacket(sender.user().getId()))); sender.system("LOCK_LOCALE_CHANGED"); } From a9660bd3251bbbed445f825997ef356211c8b712 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 16:40:45 +0100 Subject: [PATCH 074/106] Fix TNTLeague --- .../kotlin/inventory/SWInventoryHolder.kt | 60 ------------------- .../src/de/steamwar/tntleague/TNTLeague.kt | 2 + .../tntleague/events/GlobalListener.kt | 9 --- .../tntleague/events/IngameListener.kt | 2 +- .../tntleague/events/LobbyListener.kt | 5 -- .../steamwar/tntleague/game/TNTLeagueTeam.kt | 2 +- .../tntleague/inventory/CategoryInventory.kt | 6 +- .../tntleague/inventory/DealerInventory.kt | 11 ++-- 8 files changed, 14 insertions(+), 83 deletions(-) delete mode 100644 KotlinCore/src/de/steamwar/kotlin/inventory/SWInventoryHolder.kt diff --git a/KotlinCore/src/de/steamwar/kotlin/inventory/SWInventoryHolder.kt b/KotlinCore/src/de/steamwar/kotlin/inventory/SWInventoryHolder.kt deleted file mode 100644 index 3afb3183..00000000 --- a/KotlinCore/src/de/steamwar/kotlin/inventory/SWInventoryHolder.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.kotlin.inventory - -import org.bukkit.event.inventory.InventoryClickEvent -import org.bukkit.event.inventory.InventoryCloseEvent -import org.bukkit.inventory.Inventory -import org.bukkit.inventory.InventoryHolder -import org.bukkit.inventory.ItemStack - -abstract class SWInventoryHolder: InventoryHolder { - - val _inventory: Inventory by lazy { createInventory() } - - private val callbacks = mutableMapOf Unit>() - - override fun getInventory(): Inventory = _inventory - - abstract fun createInventory(): Inventory - - open fun handleInventoryClick(event: InventoryClickEvent) { - callbacks[event.slot]?.invoke(event) - } - - fun addItem(item: ItemStack, slot: Int, callback: (event: InventoryClickEvent) -> Unit) { - _inventory.setItem(slot, item) - addCallback(slot, callback) - } - - fun addCallback(slot: Int, callback: (event: InventoryClickEvent) -> Unit) { - callbacks[slot] = callback - } - - open fun handleClose(event: InventoryCloseEvent) { } - - operator fun set(slot: Int, item: Pair Unit>) { - addItem(item.first, slot, item.second) - } - - operator fun set(slot: Int, item: ItemStack) { - addItem(item, slot) { } - } -} \ No newline at end of file diff --git a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt index 378dbfc7..fb98840a 100644 --- a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt +++ b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt @@ -19,6 +19,7 @@ package de.steamwar.tntleague +import de.steamwar.kotlin.inventory.SWInventoryHolder import de.steamwar.message.Message import de.steamwar.tntleague.command.AcceptCommand import de.steamwar.tntleague.command.InviteCommand @@ -42,6 +43,7 @@ class TNTLeague : JavaPlugin() { server.pluginManager.registerEvents(LobbyListener, this) server.pluginManager.registerEvents(GlobalListener, this) + server.pluginManager.registerEvents(SWInventoryHolder.InventoryListener, this) logger.info("TNTLeague enabled") diff --git a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt index b01dffd9..1fbadd5a 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt @@ -66,15 +66,6 @@ object GlobalListener: Listener { e.isCancelled = true } - @EventHandler(priority = EventPriority.LOWEST) - fun onPlayerClick(e: InventoryClickEvent) { - val holder = e.inventory.getHolder(false) - if (holder is SWInventoryHolder && e.clickedInventory == holder._inventory) { - e.isCancelled = true - holder.handleInventoryClick(e) - } - } - @EventHandler(priority = EventPriority.LOWEST) fun onPlayerMove(e: PlayerMoveEvent) { if (e.to.blockY < TNTLeagueWorldConfig.minHeight) { diff --git a/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt index ca379821..95b700ef 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt @@ -44,7 +44,7 @@ object IngameListener: Listener { if(e.rightClicked.type == EntityType.WANDERING_TRADER) { e.isCancelled = true - e.player.openInventory(DealerInventory(e.player).getInventory()) + DealerInventory(e.player).open() } } diff --git a/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt index 586b0e79..bb570498 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt @@ -39,11 +39,6 @@ object LobbyListener: Listener { } } - @EventHandler(priority = EventPriority.LOWEST) - fun onPlayerQuit(e: PlayerQuitEvent) { - TNTLeagueGame.playerLeave(e.player) - } - @EventHandler fun onPlayerDamage(e: EntityDamageEvent) { e.isCancelled = true diff --git a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt index 3828d9e8..200f457e 100644 --- a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt +++ b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt @@ -128,7 +128,7 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va fun leave(player: Player) { members.remove(player) - if (TNTLeagueGame.state != TNTLeagueGame.GameState.RUNNING) { + if (TNTLeagueGame.state == TNTLeagueGame.GameState.LOBBY) { if (members.isEmpty()) { plugin.server.onlinePlayers.firstOrNull { it != player && TNTLeagueGame.getTeam(it) == null }?.run { members.add(this) diff --git a/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt b/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt index 3a23812f..dcf1d690 100644 --- a/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt +++ b/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt @@ -19,7 +19,7 @@ package de.steamwar.tntleague.inventory -import de.steamwar.kotlin.inventory.SWInventoryHolder +import de.steamwar.kotlin.KotlinInventory import de.steamwar.tntleague.config.TNTLeagueConfig import de.steamwar.tntleague.inventory.DealerInventory.Companion.buyItem import de.steamwar.tntleague.inventory.DealerInventory.Companion.itemsByCategory @@ -29,8 +29,8 @@ import org.bukkit.Bukkit import org.bukkit.entity.Player import org.bukkit.inventory.Inventory -class CategoryInventory(val player: Player, category: TNTLeagueConfig.ItemCategory): SWInventoryHolder() { - override fun createInventory(): Inventory = Bukkit.createInventory(this, 9 * 6, Component.text(message.parse("DEALER", player))) +class CategoryInventory(player: Player, category: TNTLeagueConfig.ItemCategory): KotlinInventory(player) { + override fun createInventory(): Inventory = Bukkit.createInventory(null, 9 * 6, Component.text(message.parse("DEALER", player))) init { itemsByCategory[category]!!.forEachIndexed { index, item -> diff --git a/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt b/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt index d0af0ca4..384699d1 100644 --- a/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt +++ b/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt @@ -19,8 +19,9 @@ package de.steamwar.tntleague.inventory +import de.steamwar.inventory.SWInventory import de.steamwar.inventory.SWItem -import de.steamwar.kotlin.inventory.SWInventoryHolder +import de.steamwar.kotlin.KotlinInventory import de.steamwar.tntleague.config.TNTLeagueConfig import de.steamwar.tntleague.game.TNTLeagueGame import de.steamwar.tntleague.message @@ -38,7 +39,9 @@ import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataType import java.util.* -class DealerInventory(val player: Player): SWInventoryHolder() { +class DealerInventory(player: Player): KotlinInventory(player) { + + private val inv: SWInventory = SWInventory(player) { createInventory() } init { this[10] = SWItem(Material.REDSTONE_BLOCK, message.parse("DEALER_REDSTONE", player)).itemStack to openCategory(TNTLeagueConfig.ItemCategory.REDSTONE) @@ -51,9 +54,9 @@ class DealerInventory(val player: Player): SWInventoryHolder() { } } - private fun openCategory(cat: TNTLeagueConfig.ItemCategory): (e: InventoryClickEvent) -> Unit = { player.openInventory(CategoryInventory(player, cat).inventory) } + private fun openCategory(cat: TNTLeagueConfig.ItemCategory): (e: InventoryClickEvent) -> Unit = { CategoryInventory(player, cat).open() } - override fun createInventory(): Inventory = plugin.server.createInventory(this, 6 * 9, Component.text(message.parse("DEALER", player))) + override fun createInventory(): Inventory = plugin.server.createInventory(null, 6 * 9, Component.text(message.parse("DEALER", player))) companion object { private val priceKey = NamespacedKey(plugin, "price") From 18418cca2a54d862ba4e1f00f44f754420d01f7c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 16:41:30 +0100 Subject: [PATCH 075/106] fixup! Fix TNTLeague --- TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt | 2 -- TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt | 4 ---- 2 files changed, 6 deletions(-) diff --git a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt index fb98840a..378dbfc7 100644 --- a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt +++ b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt @@ -19,7 +19,6 @@ package de.steamwar.tntleague -import de.steamwar.kotlin.inventory.SWInventoryHolder import de.steamwar.message.Message import de.steamwar.tntleague.command.AcceptCommand import de.steamwar.tntleague.command.InviteCommand @@ -43,7 +42,6 @@ class TNTLeague : JavaPlugin() { server.pluginManager.registerEvents(LobbyListener, this) server.pluginManager.registerEvents(GlobalListener, this) - server.pluginManager.registerEvents(SWInventoryHolder.InventoryListener, this) logger.info("TNTLeague enabled") diff --git a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt index 1fbadd5a..77aa9dfb 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt @@ -19,9 +19,7 @@ package de.steamwar.tntleague.events -import de.steamwar.kotlin.inventory.SWInventoryHolder import de.steamwar.message.SubMessage -import de.steamwar.tntleague.colorByTeam import de.steamwar.tntleague.config.TNTLeagueWorldConfig import de.steamwar.tntleague.game.TNTLeagueGame import de.steamwar.tntleague.game.TNTLeagueTeam @@ -34,9 +32,7 @@ import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.entity.PlayerDeathEvent import org.bukkit.event.inventory.CraftItemEvent -import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.player.* -import java.util.logging.Level object GlobalListener: Listener { From 747bb1055deddfb9647abdad2c7fcb60d08a3270 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 16:43:56 +0100 Subject: [PATCH 076/106] Fix TNTLeague --- .../src/de/steamwar/kotlin/KotlinInventory.kt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt diff --git a/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt b/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt new file mode 100644 index 00000000..3c5f0ae2 --- /dev/null +++ b/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt @@ -0,0 +1,43 @@ +/* + * 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 . + */ + +package de.steamwar.kotlin + +import de.steamwar.inventory.SWInventory +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.Inventory +import org.bukkit.inventory.ItemStack + +abstract class KotlinInventory(val player: Player) { + + private val inv: SWInventory by lazy { SWInventory(player) { createInventory() } } + + abstract fun createInventory(): Inventory + + fun open() = inv.open() + + operator fun set(slot: Int, item: Pair Unit>) { + inv.setItemEvent(slot, item.first, item.second) + } + + operator fun set(slot: Int, item: ItemStack) { + inv.setItemEvent(slot, item) { } + } +} \ No newline at end of file From 90ebc93b140e6440e1c6bad167197c38260c34a5 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 20 Jan 2025 16:44:24 +0100 Subject: [PATCH 077/106] Add bust to RatsChannel threads --- .../velocitycore/discord/DiscordBot.java | 11 +- .../discord/channels/DiscordChannel.java | 10 +- .../discord/channels/RatsChannel.java | 123 ++++++------------ .../channels/StaticMessageChannel.java | 12 ++ 4 files changed, 68 insertions(+), 88 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 20b8d219..1c7bfa4f 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -38,6 +38,7 @@ import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; @@ -190,9 +191,17 @@ public class DiscordBot { new DiscordTeamEvent(), new ChannelListener(), new DiscordSchemUpload(), - new RatsChannel() + new RatsChannel.RastChannelListener() ); + config.getRatsRoleToThread().forEach((roleId, threadId) -> { + Role role = DiscordBot.getGuild().getRoleById(roleId); + if (role == null) return; + ThreadChannel threadChannel = DiscordBot.getGuild().getThreadChannelById(threadId); + if (threadChannel == null) return; + new RatsChannel(role, threadChannel); + }); + commandSetup(jda.retrieveCommands().complete(), jda.updateCommands()); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java index 35e78714..3440e1f5 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java @@ -19,11 +19,11 @@ package de.steamwar.velocitycore.discord.channels; -import de.steamwar.velocitycore.discord.DiscordBot; -import de.steamwar.velocitycore.discord.listeners.ChannelListener; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.discord.DiscordBot; +import de.steamwar.velocitycore.discord.listeners.ChannelListener; import lombok.AllArgsConstructor; import lombok.Getter; import net.dv8tion.jda.api.entities.User; @@ -31,7 +31,6 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; @@ -57,6 +56,11 @@ public class DiscordChannel extends Chatter.PlayerlessChatter { ChannelListener.getChannels().put(this.channel, this); } + public DiscordChannel(MessageChannel channel) { + this(SteamwarUser.get(-1), channel); + ChannelListener.getChannels().put(this.channel, this); + } + public void send(String message) { send(new MessageCreateBuilder() .setContent(message diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java index 315d1839..7f8e9e44 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java @@ -2,107 +2,62 @@ package de.steamwar.velocitycore.discord.channels; import de.steamwar.sql.SteamwarUser; import de.steamwar.velocitycore.discord.DiscordBot; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; -import net.dv8tion.jda.api.utils.AttachedFile; -import net.dv8tion.jda.api.utils.FileUpload; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import org.jetbrains.annotations.NotNull; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; +import java.util.Map; -public class RatsChannel extends ListenerAdapter { +public class RatsChannel extends StaticMessageChannel { - private Map ratsChannel = new HashMap<>(); + private static Map listener = new HashMap<>(); - public RatsChannel() { - DiscordBot.getInstance().getConfig().getRatsRoleToThread().forEach((roleId, threadId) -> { - Role role = DiscordBot.getGuild().getRoleById(roleId); - if (role != null) return; - ThreadChannel threadChannel = DiscordBot.getGuild().getThreadChannelById(threadId); - if (threadChannel != null) ratsChannel.put(role, threadChannel); - ratsChannel.put(role, threadChannel); - }); - } + public RatsChannel(Role role, ThreadChannel threadChannel) { + super(threadChannel, () -> { + MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder(); + messageCreateBuilder.setContent("# Ratsmitglieder"); - @Override - public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { - updateRatsChannel(event.getRoles()); - } + for (Member member : DiscordBot.getGuild().getMembersWithRoles(role)) { + SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); + if (steamwarUser == null) continue; - @Override - public void onGuildMemberRoleRemove(@NotNull GuildMemberRoleRemoveEvent event) { - updateRatsChannel(event.getRoles()); - } - - private void updateRatsChannel(List roles) { - for (Role role : roles) { - if (!ratsChannel.containsKey(role)) continue; - ThreadChannel channel = ratsChannel.get(role); - - List> ratMembers = loadImages(role) - .entrySet() - .stream() - .sorted(Comparator.comparing(value -> value.getKey().getUserName())) - .collect(Collectors.toList()); - - List messages = new ArrayList<>(channel.getHistory() - .retrievePast(100) - .complete()); - // Need to reverse since they are provided from newest (0) to latest (size() - 1) - Collections.reverse(messages); - - Iterator iterator = messages.iterator(); - if (!iterator.hasNext()) { - channel.sendMessage("# Ratsmitglieder") - .queue(); - } else { - iterator.next(); + messageCreateBuilder.addEmbeds(new EmbedBuilder() + .setTitle(steamwarUser.getUserName()) + .setImage("api.steamwar.de/data/skin/" + steamwarUser.getUUID().toString()) + .build()); } - for (Map.Entry entry : ratMembers) { - if (iterator.hasNext()) { - Message message = iterator.next(); - if (message.getContentRaw().startsWith("# " + entry.getKey().getUserName())) { - continue; - } + return messageCreateBuilder; + }, genericComponentInteractionCreateEvent -> {}); - message.editMessage("## " + entry.getKey().getUserName()) - .setAttachments(AttachedFile.fromData(entry.getValue(), entry.getKey().getUUID().toString() + ".png")) - .queue(); - } else { - channel.sendMessage("## " + entry.getKey().getUserName()) - .addFiles(FileUpload.fromData(entry.getValue(), entry.getKey().getUUID().toString() + ".png")) - .queue(); + listener.put(role, this); + } + + public static class RastChannelListener extends ListenerAdapter { + @Override + public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { + updateRatsChannel(event.getRoles()); + } + + @Override + public void onGuildMemberRoleRemove(@NotNull GuildMemberRoleRemoveEvent event) { + updateRatsChannel(event.getRoles()); + } + + private void updateRatsChannel(List roles) { + roles.forEach(role -> { + if (listener.containsKey(role)) { + listener.get(role).update(); } - } - - while (iterator.hasNext()) { - iterator.next().delete().queue(); - } + }); } } - - private Map loadImages(Role role) { - Map images = new HashMap<>(); - for (Member member : DiscordBot.getGuild().getMembersWithRoles(role)) { - SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); - if (steamwarUser == null) continue; - - try { - images.put(steamwarUser, new URL("api.steamwar.de/data/skin/" + steamwarUser.getUUID().toString()).openStream()); - } catch (IOException e) { - images.put(steamwarUser, null); - } - } - return images; - } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java index 3a165915..0db34fc8 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java @@ -21,6 +21,7 @@ package de.steamwar.velocitycore.discord.channels; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.utils.messages.MessageEditData; @@ -55,6 +56,17 @@ public class StaticMessageChannel extends DiscordChannel { update(); } + public StaticMessageChannel(MessageChannel channel, Supplier supplier, Consumer interaction) { + super(channel); + this.supplier = supplier; + this.interaction = interaction; + + if(getChannel().getLatestMessageIdLong() != 0) + message = getChannel().getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); + + update(); + } + public void update() { if (message == null) { getChannel().sendMessage(supplier.get().build()).queue(m -> message = m); From eacae09e4f94d69601ea345ae643440117a27452 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 16:46:53 +0100 Subject: [PATCH 078/106] Fix TNTLeague --- KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt | 5 ++--- .../src/de/steamwar/tntleague/inventory/CategoryInventory.kt | 3 ++- .../src/de/steamwar/tntleague/inventory/DealerInventory.kt | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt b/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt index 3c5f0ae2..54798c49 100644 --- a/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt +++ b/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt @@ -22,14 +22,13 @@ package de.steamwar.kotlin import de.steamwar.inventory.SWInventory import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent -import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack abstract class KotlinInventory(val player: Player) { - private val inv: SWInventory by lazy { SWInventory(player) { createInventory() } } + private val inv: SWInventory by lazy { createInventory() } - abstract fun createInventory(): Inventory + abstract fun createInventory(): SWInventory fun open() = inv.open() diff --git a/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt b/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt index dcf1d690..76200073 100644 --- a/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt +++ b/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt @@ -19,6 +19,7 @@ package de.steamwar.tntleague.inventory +import de.steamwar.inventory.SWInventory import de.steamwar.kotlin.KotlinInventory import de.steamwar.tntleague.config.TNTLeagueConfig import de.steamwar.tntleague.inventory.DealerInventory.Companion.buyItem @@ -30,7 +31,7 @@ import org.bukkit.entity.Player import org.bukkit.inventory.Inventory class CategoryInventory(player: Player, category: TNTLeagueConfig.ItemCategory): KotlinInventory(player) { - override fun createInventory(): Inventory = Bukkit.createInventory(null, 9 * 6, Component.text(message.parse("DEALER", player))) + override fun createInventory() = SWInventory(player, 9 * 6, message.parse("DEALER", player)) init { itemsByCategory[category]!!.forEachIndexed { index, item -> diff --git a/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt b/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt index 384699d1..418c15fb 100644 --- a/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt +++ b/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt @@ -41,8 +41,6 @@ import java.util.* class DealerInventory(player: Player): KotlinInventory(player) { - private val inv: SWInventory = SWInventory(player) { createInventory() } - init { this[10] = SWItem(Material.REDSTONE_BLOCK, message.parse("DEALER_REDSTONE", player)).itemStack to openCategory(TNTLeagueConfig.ItemCategory.REDSTONE) this[12] = SWItem(Material.END_STONE, message.parse("DEALER_BLOCKS", player)).itemStack to openCategory(TNTLeagueConfig.ItemCategory.BLOCKS) @@ -56,7 +54,7 @@ class DealerInventory(player: Player): KotlinInventory(player) { private fun openCategory(cat: TNTLeagueConfig.ItemCategory): (e: InventoryClickEvent) -> Unit = { CategoryInventory(player, cat).open() } - override fun createInventory(): Inventory = plugin.server.createInventory(null, 6 * 9, Component.text(message.parse("DEALER", player))) + override fun createInventory() = SWInventory(player, 9 * 6, message.parse("DEALER", player)) companion object { private val priceKey = NamespacedKey(plugin, "price") From ca076f9ffd4f73b3635fb6f78a55f8746e405d98 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 16:56:10 +0100 Subject: [PATCH 079/106] Fix Schematic Download Link --- CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java b/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java index 030dbf38..71cf83f4 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java @@ -35,7 +35,7 @@ import java.time.Instant; public class NodeDownload { private static final char[] HEX = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - private static final String LINK_BASE = "https://steamwar.de/schematic?code="; + private static final String LINK_BASE = "https://api.steamwar.de/download/"; private static final Table table = new Table<>(NodeDownload.class); private static final Statement insert = table.insertFields("NodeId", "Link"); From af79ef544bee2f07f4aa134409dd539f3dc8590b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2025 16:56:59 +0100 Subject: [PATCH 080/106] Fixes --- .../velocitycore/discord/DiscordBot.java | 17 +---- .../velocitycore/discord/DiscordConfig.java | 2 +- .../discord/channels/CouncilChannel.java | 68 +++++++++++++++++++ .../discord/channels/DiscordChannel.java | 3 +- .../discord/channels/RatsChannel.java | 63 ----------------- .../channels/StaticMessageChannel.java | 9 ++- .../discord/listeners/RoleListener.java | 38 +++++++++++ 7 files changed, 115 insertions(+), 85 deletions(-) create mode 100644 VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java delete mode 100644 VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java create mode 100644 VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 1c7bfa4f..89167565 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -24,10 +24,7 @@ import de.steamwar.messages.Chatter; import de.steamwar.sql.Event; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.discord.channels.*; -import de.steamwar.velocitycore.discord.listeners.ChannelListener; -import de.steamwar.velocitycore.discord.listeners.DiscordSchemUpload; -import de.steamwar.velocitycore.discord.listeners.DiscordTeamEvent; -import de.steamwar.velocitycore.discord.listeners.DiscordTicketHandler; +import de.steamwar.velocitycore.discord.listeners.*; import de.steamwar.velocitycore.discord.util.AuthManager; import lombok.Getter; import net.dv8tion.jda.api.EmbedBuilder; @@ -38,7 +35,6 @@ import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; @@ -166,6 +162,7 @@ public class DiscordBot { .setComponents(actionRows), DiscordTicketHandler::openTicket); eventChannel = new StaticMessageChannel(config.channel("events"), EventChannel::get); checklistChannel = new ChecklistChannel(config.channel("checklist")); + config.getCouncilThread().forEach((roleId, threadId) -> new CouncilChannel(DiscordBot.getGuild().getRoleById(roleId), DiscordBot.getGuild().getThreadChannelById(threadId))); announcementChannel = new DiscordChannel(config.channel("announcement")) { @Override @@ -191,17 +188,9 @@ public class DiscordBot { new DiscordTeamEvent(), new ChannelListener(), new DiscordSchemUpload(), - new RatsChannel.RastChannelListener() + new RoleListener() ); - config.getRatsRoleToThread().forEach((roleId, threadId) -> { - Role role = DiscordBot.getGuild().getRoleById(roleId); - if (role == null) return; - ThreadChannel threadChannel = DiscordBot.getGuild().getThreadChannelById(threadId); - if (threadChannel == null) return; - new RatsChannel(role, threadChannel); - }); - commandSetup(jda.retrieveCommands().complete(), jda.updateCommands()); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java index 60a13f88..7f201abb 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java @@ -56,7 +56,7 @@ public class DiscordConfig { private String ticketcategory; - private Map ratsRoleToThread; + private Map councilThread; @NoArgsConstructor public static class DiscordRole { diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java new file mode 100644 index 00000000..6a949d0b --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -0,0 +1,68 @@ +/* + * 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 . + */ + +package de.steamwar.velocitycore.discord.channels; + +import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.discord.DiscordBot; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CouncilChannel extends StaticMessageChannel { + + private static final Map channels = new HashMap<>(); + + public static void update(List roles) { + for(Role role : roles) { + if (channels.containsKey(role)) { + channels.get(role).update(); + } + } + } + + public CouncilChannel(Role role, ThreadChannel threadChannel) { + super(threadChannel, () -> { + MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder(); + messageCreateBuilder.setContent("# Ratsmitglieder"); + + for (Member member : DiscordBot.getGuild().getMembersWithRoles(role)) { + SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); + if (steamwarUser == null) + continue; + + messageCreateBuilder.addEmbeds(new EmbedBuilder() + .setTitle(steamwarUser.getUserName()) + .setImage("api.steamwar.de/data/skin/" + steamwarUser.getUUID().toString()) + .build()); + } + + return messageCreateBuilder; + }, event -> {}); + + channels.put(role, this); + } + +} diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java index 3440e1f5..b420f601 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java @@ -52,8 +52,7 @@ public class DiscordChannel extends Chatter.PlayerlessChatter { } public DiscordChannel(String channel) { - this(SteamwarUser.get(-1), DiscordBot.getGuild().getTextChannelById(channel)); - ChannelListener.getChannels().put(this.channel, this); + this(DiscordBot.getGuild().getTextChannelById(channel)); } public DiscordChannel(MessageChannel channel) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java deleted file mode 100644 index 7f8e9e44..00000000 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/RatsChannel.java +++ /dev/null @@ -1,63 +0,0 @@ -package de.steamwar.velocitycore.discord.channels; - -import de.steamwar.sql.SteamwarUser; -import de.steamwar.velocitycore.discord.DiscordBot; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent; -import net.dv8tion.jda.api.hooks.ListenerAdapter; -import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class RatsChannel extends StaticMessageChannel { - - private static Map listener = new HashMap<>(); - - public RatsChannel(Role role, ThreadChannel threadChannel) { - super(threadChannel, () -> { - MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder(); - messageCreateBuilder.setContent("# Ratsmitglieder"); - - for (Member member : DiscordBot.getGuild().getMembersWithRoles(role)) { - SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); - if (steamwarUser == null) continue; - - messageCreateBuilder.addEmbeds(new EmbedBuilder() - .setTitle(steamwarUser.getUserName()) - .setImage("api.steamwar.de/data/skin/" + steamwarUser.getUUID().toString()) - .build()); - } - - return messageCreateBuilder; - }, genericComponentInteractionCreateEvent -> {}); - - listener.put(role, this); - } - - public static class RastChannelListener extends ListenerAdapter { - @Override - public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { - updateRatsChannel(event.getRoles()); - } - - @Override - public void onGuildMemberRoleRemove(@NotNull GuildMemberRoleRemoveEvent event) { - updateRatsChannel(event.getRoles()); - } - - private void updateRatsChannel(List roles) { - roles.forEach(role -> { - if (listener.containsKey(role)) { - listener.get(role).update(); - } - }); - } - } -} diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java index 0db34fc8..69549d38 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java @@ -49,18 +49,17 @@ public class StaticMessageChannel extends DiscordChannel { super(channel); this.supplier = supplier; this.interaction = interaction; - - if(getChannel().getLatestMessageIdLong() != 0) - message = getChannel().getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); - - update(); + init(); } public StaticMessageChannel(MessageChannel channel, Supplier supplier, Consumer interaction) { super(channel); this.supplier = supplier; this.interaction = interaction; + init(); + } + private void init() { if(getChannel().getLatestMessageIdLong() != 0) message = getChannel().getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java new file mode 100644 index 00000000..75063344 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java @@ -0,0 +1,38 @@ +/* + * 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 . + */ + +package de.steamwar.velocitycore.discord.listeners; + +import de.steamwar.velocitycore.discord.channels.CouncilChannel; +import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; +import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; + +public class RoleListener extends ListenerAdapter { + @Override + public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { + CouncilChannel.update(event.getRoles()); + } + + @Override + public void onGuildMemberRoleRemove(@NotNull GuildMemberRoleRemoveEvent event) { + CouncilChannel.update(event.getRoles()); + } +} From 35142f108f761770f509137e5b79b4a0024d38cd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 17:03:18 +0100 Subject: [PATCH 081/106] Update Links to new Website --- .../steamwar/messages/BungeeCore.properties | 24 +++++++++---------- .../messages/BungeeCore_de.properties | 24 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index d9ddc86e..8a9316ee 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -369,23 +369,23 @@ R_USAGE=§8/§7r §8[§eanswer§8] #RegelnCommand REGELN_RULES=§7§lRules REGELN_AS=§eAirShip §7Rules -REGELN_AS_HOVER=§7https://steamwar.de/spielmodi/airship-regelwerk/ -REGELN_AS_URL=https://steamwar.de/spielmodi/airship-regelwerk/ +REGELN_AS_HOVER=§7https://steamwar.de/en/rules/airship +REGELN_AS_URL=https://steamwar.de/en/rules/airship REGELN_MWG=§eMiniWarGear §7Rules -REGELN_MWG_HOVER=§7https://steamwar.de/spielmodi/miniwargear-regelwerk/ -REGELN_MWG_URL=https://steamwar.de/spielmodi/miniwargear-regelwerk/ +REGELN_MWG_HOVER=§7https://steamwar.de/en/rules/miniwargear +REGELN_MWG_URL=https://steamwar.de/en/rules/miniwargear REGELN_WG=§eWarGear §7Rules -REGELN_WG_HOVER=§7https://steamwar.de/spielmodi/wargear-regelwerk/ -REGELN_WG_URL=https://steamwar.de/spielmodi/wargear-regelwerk/ +REGELN_WG_HOVER=§7https://steamwar.de/en/rules/wargear +REGELN_WG_URL=https://steamwar.de/en/rules/wargear REGELN_WS=§eWarShip §7Rules -REGELN_WS_HOVER=§7https://steamwar.de/spielmodi/warship-regelwerk/ -REGELN_WS_URL=https://steamwar.de/spielmodi/warship-regelwerk/ +REGELN_WS_HOVER=§7https://steamwar.de/en/rules/warship +REGELN_WS_URL=https://steamwar.de/en/rules/warship REGELN_QG=§eQuickGear §7Rules -REGELN_QG_HOVER=§7https://steamwar.de/spielmodi/quickgear-regelwerk/ -REGELN_QG_URL=https://steamwar.de/spielmodi/quickgear-regelwerk/ +REGELN_QG_HOVER=§7https://steamwar.de/en/rules/quickgear +REGELN_QG_URL=https://steamwar.de/enrules/quickgear REGELN_CONDUCT=§eCode of conduct -REGELN_CONDUCT_HOVER=§7https://steamwar.de/verhaltensrichtlinien/ -REGELN_CONDUCT_URL=https://steamwar.de/verhaltensrichtlinien/ +REGELN_CONDUCT_HOVER=§7https://steamwar.de/en/code-of-conduct +REGELN_CONDUCT_URL=https://steamwar.de/en/code-of-conduct #ReplayCommand REPLAY_TITLE=Most recent fights diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index 364988e1..416edb77 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -350,23 +350,23 @@ R_USAGE=§8/§7r §8[§eAntwort§8] #RegelnCommand REGELN_RULES=§7§lRegelwerke REGELN_AS=§eAirShip§8-§7Regelwerk -REGELN_AS_HOVER=§7https://steamwar.de/spielmodi/airship-regelwerk/ -REGELN_AS_URL=https://steamwar.de/spielmodi/airship-regelwerk/ +REGELN_AS_HOVER=§7https://steamwar.de/regeln/airship +REGELN_AS_URL=https://steamwar.de/regeln/airship REGELN_MWG=§eMiniWarGear§8-§7Regelwerk -REGELN_MWG_HOVER=§7https://steamwar.de/spielmodi/miniwargear-regelwerk/ -REGELN_MWG_URL=https://steamwar.de/spielmodi/miniwargear-regelwerk/ +REGELN_MWG_HOVER=§7https://steamwar.de/regeln/miniwargear +REGELN_MWG_URL=https://steamwar.de/regeln/miniwargear REGELN_WG=§eWarGear§8-§7Regelwerk -REGELN_WG_HOVER=§7https://steamwar.de/spielmodi/wargear-regelwerk/ -REGELN_WG_URL=https://steamwar.de/spielmodi/wargear-regelwerk/ +REGELN_WG_HOVER=§7https://steamwar.de/regeln/wargear +REGELN_WG_URL=https://steamwar.de/regeln/wargear REGELN_WS=§eWarShip§8-§7Regelwerk -REGELN_WS_HOVER=§7https://steamwar.de/spielmodi/warship-regelwerk/ -REGELN_WS_URL=https://steamwar.de/spielmodi/warship-regelwerk/ +REGELN_WS_HOVER=§7https://steamwar.de/regeln/warship +REGELN_WS_URL=https://steamwar.de/regeln/warship REGELN_QG=§eQuickGear§8-§7Regelwerk -REGELN_QG_HOVER=§7https://steamwar.de/spielmodi/quickgear-regelwerk/ -REGELN_QG_URL=https://steamwar.de/spielmodi/quickgear-regelwerk/ +REGELN_QG_HOVER=§7https://steamwar.de/regeln/quickgear +REGELN_QG_URL=https://steamwar.de/regeln/quickgear REGELN_CONDUCT=§eVerhaltensrichtlinien -REGELN_CONDUCT_HOVER=§7https://steamwar.de/verhaltensrichtlinien/ -REGELN_CONDUCT_URL=https://steamwar.de/verhaltensrichtlinien/ +REGELN_CONDUCT_HOVER=§7https://steamwar.de/verhaltensrichtlinien +REGELN_CONDUCT_URL=https://steamwar.de/verhaltensrichtlinien #ReplayCommand REPLAY_TITLE=Letzte Kämpfe From b4accdf0a1f9e43f70d68940ebeaf4d8f9c57b0c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 17:08:24 +0100 Subject: [PATCH 082/106] Update Links to new Website --- .../src/de/steamwar/messages/BungeeCore.properties | 9 ++------- .../src/de/steamwar/messages/BungeeCore_de.properties | 6 ------ .../de/steamwar/velocitycore/commands/RulesCommand.java | 2 +- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index 8a9316ee..c9527253 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -369,23 +369,18 @@ R_USAGE=§8/§7r §8[§eanswer§8] #RegelnCommand REGELN_RULES=§7§lRules REGELN_AS=§eAirShip §7Rules -REGELN_AS_HOVER=§7https://steamwar.de/en/rules/airship REGELN_AS_URL=https://steamwar.de/en/rules/airship REGELN_MWG=§eMiniWarGear §7Rules -REGELN_MWG_HOVER=§7https://steamwar.de/en/rules/miniwargear REGELN_MWG_URL=https://steamwar.de/en/rules/miniwargear REGELN_WG=§eWarGear §7Rules -REGELN_WG_HOVER=§7https://steamwar.de/en/rules/wargear REGELN_WG_URL=https://steamwar.de/en/rules/wargear REGELN_WS=§eWarShip §7Rules -REGELN_WS_HOVER=§7https://steamwar.de/en/rules/warship REGELN_WS_URL=https://steamwar.de/en/rules/warship REGELN_QG=§eQuickGear §7Rules -REGELN_QG_HOVER=§7https://steamwar.de/en/rules/quickgear -REGELN_QG_URL=https://steamwar.de/enrules/quickgear +REGELN_QG_URL=https://steamwar.de/en/rules/quickgear REGELN_CONDUCT=§eCode of conduct -REGELN_CONDUCT_HOVER=§7https://steamwar.de/en/code-of-conduct REGELN_CONDUCT_URL=https://steamwar.de/en/code-of-conduct +URL_FORMAT=§7{0} #ReplayCommand REPLAY_TITLE=Most recent fights diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index 416edb77..c50cf682 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -350,22 +350,16 @@ R_USAGE=§8/§7r §8[§eAntwort§8] #RegelnCommand REGELN_RULES=§7§lRegelwerke REGELN_AS=§eAirShip§8-§7Regelwerk -REGELN_AS_HOVER=§7https://steamwar.de/regeln/airship REGELN_AS_URL=https://steamwar.de/regeln/airship REGELN_MWG=§eMiniWarGear§8-§7Regelwerk -REGELN_MWG_HOVER=§7https://steamwar.de/regeln/miniwargear REGELN_MWG_URL=https://steamwar.de/regeln/miniwargear REGELN_WG=§eWarGear§8-§7Regelwerk -REGELN_WG_HOVER=§7https://steamwar.de/regeln/wargear REGELN_WG_URL=https://steamwar.de/regeln/wargear REGELN_WS=§eWarShip§8-§7Regelwerk -REGELN_WS_HOVER=§7https://steamwar.de/regeln/warship REGELN_WS_URL=https://steamwar.de/regeln/warship REGELN_QG=§eQuickGear§8-§7Regelwerk -REGELN_QG_HOVER=§7https://steamwar.de/regeln/quickgear REGELN_QG_URL=https://steamwar.de/regeln/quickgear REGELN_CONDUCT=§eVerhaltensrichtlinien -REGELN_CONDUCT_HOVER=§7https://steamwar.de/verhaltensrichtlinien REGELN_CONDUCT_URL=https://steamwar.de/verhaltensrichtlinien #ReplayCommand diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/RulesCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/RulesCommand.java index cf403c4d..e379d6b1 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/RulesCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/RulesCommand.java @@ -36,6 +36,6 @@ public class RulesCommand extends SWCommand { sender.system("REGELN_RULES"); for(String ruleset : Arrays.asList("REGELN_AS", "REGELN_MWG", "REGELN_WG", "REGELN_WS", "REGELN_QG", "REGELN_CONDUCT")) - sender.prefixless(ruleset, new Message(ruleset + "_HOVER"), ClickEvent.openUrl(sender.parseToPlain(ruleset + "_URL"))); + sender.prefixless(ruleset, new Message("URL_FORMAT", sender.parseToPlain(ruleset + "_URL")), ClickEvent.openUrl(sender.parseToPlain(ruleset + "_URL"))); } } From 0ce7429151ac2e72b8ce36ddc88aac76074197f8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 17:31:20 +0100 Subject: [PATCH 083/106] Fix Schematic Upload --- .../src/de/steamwar/routes/Schematic.kt | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index c4d76f80..e0b220de 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -19,14 +19,11 @@ package de.steamwar.routes +import de.steamwar.ResponseError import de.steamwar.plugins.SWAuthPrincipal import de.steamwar.plugins.SWPermissionCheck -import de.steamwar.sql.NodeData +import de.steamwar.sql.* import de.steamwar.sql.NodeData.SchematicFormat -import de.steamwar.sql.NodeDownload -import de.steamwar.sql.NodeMember -import de.steamwar.sql.SWException -import de.steamwar.sql.SchematicNode import dev.dewy.nbt.Nbt import dev.dewy.nbt.tags.collection.CompoundTag import io.ktor.http.* @@ -36,12 +33,15 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* import kotlinx.serialization.Serializable -import kotlinx.serialization.decodeFromByteArray +import java.io.BufferedInputStream +import java.io.ByteArrayInputStream +import java.io.DataInputStream import java.security.MessageDigest import java.time.Duration import java.time.Instant import java.time.temporal.ChronoUnit import java.util.* +import java.util.zip.GZIPInputStream @Serializable data class ResponseSchematic(val name: String, val id: Int, val type: String?, val owner: Int, val item: String, val lastUpdate: Long, val rank: Int, val replaceColor: Boolean, val allowReplay: Boolean) { @@ -109,10 +109,20 @@ fun Route.configureSchematic() { post { val file = call.receive() val schemName = file.name.substringBeforeLast(".") + + if (SchematicNode.invalidSchemName(arrayOf(schemName))) { + call.respond(HttpStatusCode.BadRequest, ResponseError( + error = "INVALID_NAME" + )) + return@post + } + val schemType = file.name.substringAfterLast(".") if (schemType != "schem" && schemType != "schematic") { - call.respond(HttpStatusCode.BadRequest) + call.respond(HttpStatusCode.BadRequest, ResponseError( + error = "INVALID_SUFFIX" + )) return@post } @@ -126,7 +136,7 @@ fun Route.configureSchematic() { try { val content = Base64.getDecoder().decode(file.content) - var schem = nbt.fromByteArray(content) + var schem = nbt.fromStream(DataInputStream(BufferedInputStream(GZIPInputStream(ByteArrayInputStream(content))))) if (schem.size() == 1) schem = schem.first() as CompoundTag @@ -144,7 +154,9 @@ fun Route.configureSchematic() { call.respond(ResponseSchematic(node)) } catch (e: Exception) { - call.respond(HttpStatusCode.BadRequest) + call.respond(HttpStatusCode.BadRequest, ResponseError( + error = e.message ?: "GENERIC", code = "UPLOAD_ERROR" + )) } } } From 8da9a3cfbb098f30f77c6b8f670d4caa49f0860a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 17:38:32 +0100 Subject: [PATCH 084/106] Fix Schematic Upload --- WebsiteBackend/src/de/steamwar/routes/Schematic.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index e0b220de..02f12243 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -128,15 +128,15 @@ fun Route.configureSchematic() { val user = call.principal()!!.user - var node = SchematicNode.getSchematicNode(user.id, schemName, 0) + var node = SchematicNode.getSchematicNode(user.id, schemName, null as Int?) if (node == null) { - node = SchematicNode.createSchematic(user.id, schemName, 0) + node = SchematicNode.createSchematic(user.id, schemName, null) } try { val content = Base64.getDecoder().decode(file.content) - var schem = nbt.fromStream(DataInputStream(BufferedInputStream(GZIPInputStream(ByteArrayInputStream(content))))) + var schem = nbt.fromStream(DataInputStream(BufferedInputStream(GZIPInputStream(content.inputStream())))) if (schem.size() == 1) schem = schem.first() as CompoundTag From 3fadeb77519984103fda39073da32bb930a7995b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Jan 2025 19:09:29 +0100 Subject: [PATCH 085/106] Disable Logs --- WebsiteBackend/src/de/steamwar/plugins/Auth.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WebsiteBackend/src/de/steamwar/plugins/Auth.kt b/WebsiteBackend/src/de/steamwar/plugins/Auth.kt index cc5c0822..eeca85ee 100644 --- a/WebsiteBackend/src/de/steamwar/plugins/Auth.kt +++ b/WebsiteBackend/src/de/steamwar/plugins/Auth.kt @@ -104,6 +104,7 @@ Message: ${cause.message} call.response.headers.append("X-Caught", "1") } + /* onCallRespond { call -> if ((call.response.status() ?: HttpStatusCode.OK).isSuccess()) { return@onCallRespond @@ -125,5 +126,5 @@ Message: ${cause.message} """.trimIndent() SWException.log(msg, stack) - } + }*/ } \ No newline at end of file From 7f7f84a4c48757b3fc0fd79f3fc9201464e05a3c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 21 Jan 2025 00:03:39 +0100 Subject: [PATCH 086/106] Fix CouncilChannel, unloading issues --- .../src/de/steamwar/velocitycore/VelocityCore.java | 12 +++++++++++- .../de/steamwar/velocitycore/discord/DiscordBot.java | 2 +- .../discord/channels/CouncilChannel.java | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 5e6dca1d..3cec098b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -252,7 +252,17 @@ public class VelocityCore implements ReloadablePlugin { @Override public void onProxyShutdown(ProxyShutdownEvent event) { try { - DiscordBot.withBot(bot -> bot.getJda().shutdownNow()); + DiscordBot.withBot(bot -> { + bot.getJda().shutdownNow(); + bot.getJda().getHttpClient().connectionPool().evictAll(); + bot.getJda().getHttpClient().dispatcher().executorService().shutdown(); + try { + if(!bot.getJda().awaitShutdown(1, TimeUnit.SECONDS)) + logger.log(Level.SEVERE, "Could not await discord bot shutdown"); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }); } catch (Throwable e) { logger.log(Level.SEVERE, "Could not shutdown discord bot", e); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 89167565..d2f7419a 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -97,7 +97,7 @@ public class DiscordBot { .createDefault(config.getToken()) .setStatus(OnlineStatus.ONLINE) .setMemberCachePolicy(MemberCachePolicy.ONLINE) - .enableIntents(GatewayIntent.MESSAGE_CONTENT) + .enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.MESSAGE_CONTENT) .build(); instance = this; diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java index 6a949d0b..7c86c1b0 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -48,7 +48,7 @@ public class CouncilChannel extends StaticMessageChannel { MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder(); messageCreateBuilder.setContent("# Ratsmitglieder"); - for (Member member : DiscordBot.getGuild().getMembersWithRoles(role)) { + for (Member member : DiscordBot.getGuild().findMembersWithRoles(role).get()) { SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); if (steamwarUser == null) continue; From 364911e4496e382174132ea910f9a027803aef51 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 21 Jan 2025 08:09:11 +0100 Subject: [PATCH 087/106] Fix CouncilChannel URL --- .../steamwar/velocitycore/discord/channels/CouncilChannel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java index 7c86c1b0..c4af706f 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -55,7 +55,7 @@ public class CouncilChannel extends StaticMessageChannel { messageCreateBuilder.addEmbeds(new EmbedBuilder() .setTitle(steamwarUser.getUserName()) - .setImage("api.steamwar.de/data/skin/" + steamwarUser.getUUID().toString()) + .setImage("https://api.steamwar.de/data/skin/" + steamwarUser.getUUID().toString()) .build()); } From 6541c34cc896406af0687f56d382d544a9daa121 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 21 Jan 2025 16:53:17 +0100 Subject: [PATCH 088/106] Update CouncilChannel --- .../discord/channels/CouncilChannel.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java index c4af706f..7ac28228 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -21,15 +21,15 @@ package de.steamwar.velocitycore.discord.channels; import de.steamwar.sql.SteamwarUser; import de.steamwar.velocitycore.discord.DiscordBot; +import it.unimi.dsi.fastutil.Pair; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; public class CouncilChannel extends StaticMessageChannel { @@ -48,16 +48,21 @@ public class CouncilChannel extends StaticMessageChannel { MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder(); messageCreateBuilder.setContent("# Ratsmitglieder"); - for (Member member : DiscordBot.getGuild().findMembersWithRoles(role).get()) { - SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); - if (steamwarUser == null) - continue; - - messageCreateBuilder.addEmbeds(new EmbedBuilder() - .setTitle(steamwarUser.getUserName()) - .setImage("https://api.steamwar.de/data/skin/" + steamwarUser.getUUID().toString()) - .build()); - } + DiscordBot.getGuild().findMembersWithRoles(role).get() + .stream() + .map(member -> { + SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); + String name = steamwarUser == null ? member.getEffectiveName() : steamwarUser.getUserName(); + UUID uuid = steamwarUser == null ? null : steamwarUser.getUUID(); + return Pair.of(name, uuid); + }) + .sorted(Comparator.comparing(Pair::key)) + .forEach(pair -> { + messageCreateBuilder.addEmbeds(new EmbedBuilder() + .setTitle(pair.key()) + .setImage(pair.value() == null ? null : "https://api.steamwar.de/data/skin/" + pair.value().toString()) + .build()); + }); return messageCreateBuilder; }, event -> {}); From e83878a49b2ad4df6cd628bd576a430b3e9b745a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 22 Jan 2025 09:29:20 +0100 Subject: [PATCH 089/106] Remove ViaVersion requirement from dev servers --- .../steamwar/velocitycore/ServerVersion.java | 11 +++++++ .../velocitycore/commands/DevCommand.java | 31 ++++++++++++------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index cc7c9d38..a5e08b55 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -86,6 +86,17 @@ public enum ServerVersion { return chatMap.keySet(); } + private static final Map versionMap = new HashMap<>(); + + static { + for(ServerVersion version : values()) + versionMap.put(version.getVersionSuffix(), version); + } + + public static ServerVersion get(int version) { + return versionMap.get(version); + } + private final String serverJar; private final int versionSuffix; private final ProtocolVersion protocolVersion; diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java index e24432cc..71b4427c 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java @@ -21,18 +21,21 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; -import de.steamwar.messages.Chatter; -import de.steamwar.messages.Message; -import de.steamwar.sql.UserPerm; -import de.steamwar.velocitycore.ArenaMode; -import de.steamwar.velocitycore.VelocityCore; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.Message; import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserPerm; +import de.steamwar.velocitycore.ArenaMode; +import de.steamwar.velocitycore.ServerVersion; +import de.steamwar.velocitycore.VelocityCore; import lombok.Getter; import java.io.File; @@ -113,28 +116,32 @@ public class DevCommand extends SWCommand { private void updateDevServers() { String[] serverFiles = devServerDir.list(); - Map devServerFiles = new HashMap<>(); + Map devServerPorts = new HashMap<>(); + Map devServerVersions = new HashMap<>(); if (serverFiles != null) { for (String serverFile : serverFiles) { String[] server = serverFile.split("\\."); - devServerFiles.put(server[0], Integer.parseInt(server[1])); + devServerPorts.put(server[0], Integer.parseInt(server[1])); + devServerVersions.put(server[0], Integer.parseInt(server[2])); } } devServers.entrySet().removeIf(entry -> { - if (!devServerFiles.containsKey(entry.getKey())) { + if (!devServerPorts.containsKey(entry.getKey())) { VelocityCore.getProxy().unregisterServer(entry.getValue().getServerInfo()); return true; } return false; }); - devServerFiles.forEach((key, value) -> { - if (devServers.containsKey(key)) + devServerPorts.forEach((username, value) -> { + if (devServers.containsKey(username)) return; - SteamwarUser user = SteamwarUser.get(key); - devServers.put(user.getUserName().toLowerCase(), VelocityCore.getProxy().registerServer(new ServerInfo("Dev " + user.getUserName(), new InetSocketAddress("127.0.0.1", value)))); + SteamwarUser user = SteamwarUser.get(username); + String name = "Dev " + user.getUserName(); + ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().put(name, ServerVersion.get(devServerVersions.get(username)).getProtocolVersion().getProtocol()); + devServers.put(user.getUserName().toLowerCase(), VelocityCore.getProxy().registerServer(new ServerInfo(name, new InetSocketAddress("127.0.0.1", value)))); }); } } From de591b7a5f7040cc6164fe4dfba20437664478de Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 22 Jan 2025 09:39:10 +0100 Subject: [PATCH 090/106] Update CouncilChannel --- .../discord/channels/CouncilChannel.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java index 7ac28228..16a42be1 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -20,6 +20,7 @@ package de.steamwar.velocitycore.discord.channels; import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.discord.DiscordBot; import it.unimi.dsi.fastutil.Pair; import net.dv8tion.jda.api.EmbedBuilder; @@ -29,6 +30,7 @@ import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; public class CouncilChannel extends StaticMessageChannel { @@ -36,11 +38,12 @@ public class CouncilChannel extends StaticMessageChannel { private static final Map channels = new HashMap<>(); public static void update(List roles) { - for(Role role : roles) { - if (channels.containsKey(role)) { - channels.get(role).update(); - } - } + VelocityCore.schedule(() -> { + roles.stream() + .filter(channels::containsKey) + .map(channels::get) + .forEach(CouncilChannel::update); + }).delay(1, TimeUnit.SECONDS); } public CouncilChannel(Role role, ThreadChannel threadChannel) { From aa5fcd38114d8f79fa62cb427d3d94c2700d78a3 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 22 Jan 2025 19:52:16 +0100 Subject: [PATCH 091/106] Update CouncilChannel every hour --- .../velocitycore/discord/DiscordBot.java | 16 ++++++-- .../discord/channels/CouncilChannel.java | 23 ++++------- .../discord/listeners/RoleListener.java | 38 ------------------- 3 files changed, 21 insertions(+), 56 deletions(-) delete mode 100644 VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index d2f7419a..2dd455ab 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -24,7 +24,10 @@ import de.steamwar.messages.Chatter; import de.steamwar.sql.Event; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.discord.channels.*; -import de.steamwar.velocitycore.discord.listeners.*; +import de.steamwar.velocitycore.discord.listeners.ChannelListener; +import de.steamwar.velocitycore.discord.listeners.DiscordSchemUpload; +import de.steamwar.velocitycore.discord.listeners.DiscordTeamEvent; +import de.steamwar.velocitycore.discord.listeners.DiscordTicketHandler; import de.steamwar.velocitycore.discord.util.AuthManager; import lombok.Getter; import net.dv8tion.jda.api.EmbedBuilder; @@ -183,12 +186,19 @@ public class DiscordBot { } }).repeat(30, TimeUnit.SECONDS).schedule(); + VelocityCore.schedule(() -> { + try { + CouncilChannel.updateAll(); + } catch (ErrorResponseException e) { + //ignored + } + }).repeat(1, TimeUnit.HOURS).schedule(); + jda.addEventListener( new DiscordTicketHandler(), new DiscordTeamEvent(), new ChannelListener(), - new DiscordSchemUpload(), - new RoleListener() + new DiscordSchemUpload() ); commandSetup(jda.retrieveCommands().complete(), jda.updateCommands()); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java index 16a42be1..e5129f24 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -20,30 +20,24 @@ package de.steamwar.velocitycore.discord.channels; import de.steamwar.sql.SteamwarUser; -import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.discord.DiscordBot; import it.unimi.dsi.fastutil.Pair; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; public class CouncilChannel extends StaticMessageChannel { - private static final Map channels = new HashMap<>(); + private static final Set channels = new HashSet<>(); - public static void update(List roles) { - VelocityCore.schedule(() -> { - roles.stream() - .filter(channels::containsKey) - .map(channels::get) - .forEach(CouncilChannel::update); - }).delay(1, TimeUnit.SECONDS); + public static void updateAll() { + channels.forEach(StaticMessageChannel::update); } public CouncilChannel(Role role, ThreadChannel threadChannel) { @@ -70,7 +64,6 @@ public class CouncilChannel extends StaticMessageChannel { return messageCreateBuilder; }, event -> {}); - channels.put(role, this); + channels.add(this); } - } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java deleted file mode 100644 index 75063344..00000000 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java +++ /dev/null @@ -1,38 +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 . - */ - -package de.steamwar.velocitycore.discord.listeners; - -import de.steamwar.velocitycore.discord.channels.CouncilChannel; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent; -import net.dv8tion.jda.api.hooks.ListenerAdapter; -import org.jetbrains.annotations.NotNull; - -public class RoleListener extends ListenerAdapter { - @Override - public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { - CouncilChannel.update(event.getRoles()); - } - - @Override - public void onGuildMemberRoleRemove(@NotNull GuildMemberRoleRemoveEvent event) { - CouncilChannel.update(event.getRoles()); - } -} From aa01fde5a053cbc5c4cc0501caa3938751df71e0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Jan 2025 18:21:44 +0100 Subject: [PATCH 092/106] Fix locale --- CommonCore/SQL/src/de/steamwar/sql/internal/Statement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/internal/Statement.java b/CommonCore/SQL/src/de/steamwar/sql/internal/Statement.java index 3d6a49b2..2621da6b 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/internal/Statement.java +++ b/CommonCore/SQL/src/de/steamwar/sql/internal/Statement.java @@ -62,7 +62,7 @@ public class Statement implements AutoCloseable { String user = properties.getProperty("user"); String password = properties.getProperty("password"); - PRODUCTION_DATABASE = "core".equals(properties.getProperty("database")); + PRODUCTION_DATABASE = "production".equals(properties.getProperty("database")); MAX_CONNECTIONS = SQLConfig.impl.maxConnections(); conProvider = () -> { try { From 4db5c50b0685c4021d6a7fd496da598c3ef0220f Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 24 Jan 2025 08:21:47 +0100 Subject: [PATCH 093/106] Fix PR stuff --- .../src/de/steamwar/velocitycore/discord/DiscordBot.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 2dd455ab..ecdc5a53 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -186,13 +186,7 @@ public class DiscordBot { } }).repeat(30, TimeUnit.SECONDS).schedule(); - VelocityCore.schedule(() -> { - try { - CouncilChannel.updateAll(); - } catch (ErrorResponseException e) { - //ignored - } - }).repeat(1, TimeUnit.HOURS).schedule(); + VelocityCore.schedule(CouncilChannel::updateAll).repeat(1, TimeUnit.HOURS).schedule(); jda.addEventListener( new DiscordTicketHandler(), From 71362bc07916f165475edbd9e6009fd0da37c072 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 26 Jan 2025 00:22:50 +0100 Subject: [PATCH 094/106] Hotfix: API Download is decompressed --- CommonCore/SQL/src/de/steamwar/sql/NodeData.java | 10 +++++++++- WebsiteBackend/src/de/steamwar/routes/Schematic.kt | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java index 0de6c6c5..a8d7c099 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java @@ -65,6 +65,10 @@ public class NodeData { private SchematicFormat nodeFormat; public InputStream schemData() throws IOException { + return schemData(true); + } + + public InputStream schemData(boolean decompress) throws IOException { try { return selSchemData.select(rs -> { rs.next(); @@ -73,7 +77,11 @@ public class NodeData { if(rs.wasNull() || schemData.available() == 0) { throw new SecurityException("SchemData is null"); } - return new GZIPInputStream(schemData); + if (decompress) { + return new GZIPInputStream(schemData); + } else { + return schemData; + } } catch (IOException e) { throw new SecurityException("SchemData is wrong", e); } diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index 02f12243..1beb0f29 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -95,7 +95,7 @@ fun Route.configureSchematic() { } call.response.header("Content-Disposition", "attachment; filename=\"${node.name}${data.nodeFormat.fileEnding}\"") - call.respondBytes(data.schemData().readAllBytes(), contentType = ContentType.Application.OctetStream, status = HttpStatusCode.OK) + call.respondBytes(data.schemData(false).readAllBytes(), contentType = ContentType.Application.OctetStream, status = HttpStatusCode.OK) } get("/info") { val node = call.receiveSchematic() ?: return@get From dbf59df173263f6292304b0bb0b832c52e743abf Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 26 Jan 2025 10:13:36 +0100 Subject: [PATCH 095/106] Fix Gitea Backend --- WebsiteBackend/src/de/steamwar/routes/Page.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebsiteBackend/src/de/steamwar/routes/Page.kt b/WebsiteBackend/src/de/steamwar/routes/Page.kt index 9b28ddd5..6f9a9fc4 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Page.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Page.kt @@ -108,7 +108,7 @@ fun Route.configurePage() { json() } defaultRequest { - url("https://steamwar.de/devlabs/api/v1/") + url("https://git.steamwar.de/api/v1/") header("Authorization", "token " + config.giteaToken) } } From 02b63687bcf6961dfb7a4e111f2fbf8df8969add Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 29 Jan 2025 18:38:38 +0100 Subject: [PATCH 096/106] Fix Event Create --- CommonCore/SQL/src/de/steamwar/sql/Event.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/Event.java b/CommonCore/SQL/src/de/steamwar/sql/Event.java index a92cc9f2..5a4477bf 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/Event.java +++ b/CommonCore/SQL/src/de/steamwar/sql/Event.java @@ -64,7 +64,7 @@ public class Event { } public static Event create(String eventName, Timestamp start, Timestamp end){ - return get(create.insertGetKey(eventName, start, start, end, 5, false, false)); + return get(create.insertGetKey(eventName, start, start, end, 5, false)); } public static Event get(int eventID){ From b3ddc048303b4870fc8bdac4ce0bfd90133af1e9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 29 Jan 2025 19:12:45 +0100 Subject: [PATCH 097/106] Fix Add Referee --- WebsiteBackend/src/de/steamwar/routes/Events.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/WebsiteBackend/src/de/steamwar/routes/Events.kt b/WebsiteBackend/src/de/steamwar/routes/Events.kt index 4b4c6206..d1edcf07 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Events.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Events.kt @@ -32,6 +32,7 @@ import kotlinx.serialization.Serializable import java.lang.StringBuilder import java.sql.Timestamp import java.time.Instant +import java.util.* @Serializable data class ShortEvent(val id: Int, val name: String, val start: Long, val end: Long) { @@ -82,8 +83,8 @@ data class UpdateEvent( val maxTeamMembers: Int? = null, val schemType: String? = null, val publicSchemsOnly: Boolean? = null, - val addReferee: Set? = null, - val removeReferee: Set? = null, + val addReferee: Set? = null, + val removeReferee: Set? = null, ) fun Route.configureEventsRoute() { @@ -204,13 +205,13 @@ fun Route.configureEventsRoute() { if (updateEvent.addReferee != null) { updateEvent.addReferee.forEach { - Referee.add(event.eventID, it) + Referee.add(event.eventID, SteamwarUser.get(UUID.fromString(it)).id) } } if (updateEvent.removeReferee != null) { updateEvent.removeReferee.forEach { - Referee.remove(event.eventID, it) + Referee.remove(event.eventID, SteamwarUser.get(UUID.fromString(it)).id) } } event.update(eventName, deadline, start, end, schemType, maxTeamMembers, publicSchemsOnly) From 3d153d49b52b162fdfacf3d5537d5fe3c433ef8f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 1 Feb 2025 21:50:36 +0100 Subject: [PATCH 098/106] Make TNTLeague Event System Capable --- .../src/de/steamwar/message/Message.java | 7 +- .../src/de/steamwar/message/SubMessage.java | 29 +++++--- .../tntleague/command/InviteCommand.kt | 7 +- .../tntleague/config/TNTLeagueConfig.kt | 33 +++++++++ .../tntleague/config/TNTLeagueWorldConfig.kt | 41 ++---------- .../steamwar/tntleague/config/TeamConfig.kt | 67 +++++++++++++++++++ .../tntleague/events/GlobalListener.kt | 6 +- .../steamwar/tntleague/game/TNTLeagueGame.kt | 30 +++++++-- .../steamwar/tntleague/game/TNTLeagueTeam.kt | 37 +++++----- .../tntleague/util/TNTLeagueScoreboard.kt | 4 +- 10 files changed, 182 insertions(+), 79 deletions(-) create mode 100644 TNTLeague/src/de/steamwar/tntleague/config/TeamConfig.kt diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java index b9ae84b7..f953ce8d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java @@ -72,9 +72,12 @@ public class Message { pattern += fromRB(resourceBundle, message); for (int i = 0; i < params.length; i++) { - if (params[i] instanceof SubMessage) { - SubMessage smsg = (SubMessage) params[i]; + if (params[i] instanceof SubMessage.Translatable) { + SubMessage.Translatable smsg = (SubMessage.Translatable) params[i]; params[i] = parse(smsg.getMessage(), sender, smsg.getParams()); + } else if (params[i] instanceof SubMessage.Literal) { + SubMessage.Literal smsg = (SubMessage.Literal) params[i]; + params[i] = smsg.getMessage(); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java index e40b74a5..4c302689 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java @@ -19,20 +19,33 @@ package de.steamwar.message; +import lombok.AllArgsConstructor; import lombok.Getter; @Getter -public class SubMessage { +@AllArgsConstructor +public abstract class SubMessage { private final String message; - private final Object[] params; - public SubMessage(String message, Object... params) { - this.message = message; - this.params = params; + @Getter + public static class Translatable extends SubMessage { + private final Object[] params; + + public Translatable(String message, Object... params) { + super(message); + this.params = params; + } + + public Translatable(String message) { + super(message); + this.params = new Object[0]; + } } - public SubMessage(String message) { - this.message = message; - this.params = new Object[0]; + @Getter + public static class Literal extends SubMessage { + public Literal(String message) { + super(message); + } } } diff --git a/TNTLeague/src/de/steamwar/tntleague/command/InviteCommand.kt b/TNTLeague/src/de/steamwar/tntleague/command/InviteCommand.kt index 8ecf50cb..e89e3443 100644 --- a/TNTLeague/src/de/steamwar/tntleague/command/InviteCommand.kt +++ b/TNTLeague/src/de/steamwar/tntleague/command/InviteCommand.kt @@ -21,8 +21,8 @@ package de.steamwar.tntleague.command import de.steamwar.command.SWCommand import de.steamwar.command.TypeValidator -import de.steamwar.message.SubMessage import de.steamwar.tntleague.colorByTeam +import de.steamwar.tntleague.config.TNTLeagueConfig import de.steamwar.tntleague.game.TNTLeagueGame import de.steamwar.tntleague.message import net.md_5.bungee.api.chat.ClickEvent @@ -32,6 +32,7 @@ object InviteCommand: SWCommand("invite") { @Register fun invitePlayer(@Validator("isLeader") sender: Player, target: Player) { + if (TNTLeagueConfig.isEvent()) return if (TNTLeagueGame.state != TNTLeagueGame.GameState.LOBBY) return if (TNTLeagueGame.getTeam(target) != null) return @@ -39,8 +40,8 @@ object InviteCommand: SWCommand("invite") { team.invites.add(target) message - .send("INVITED", target, message.parse("INVITED_HOVER", target, SubMessage(team.name)), - ClickEvent(ClickEvent.Action.RUN_COMMAND, "/accept " + sender.name), sender.name.colorByTeam(team), SubMessage(team.name), ) + .send("INVITED", target, message.parse("INVITED_HOVER", target, team.name), + ClickEvent(ClickEvent.Action.RUN_COMMAND, "/accept " + sender.name), sender.name.colorByTeam(team), team.name) message.send("INVITED_PLAYER", sender, target.name) } diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt index e4677a4e..e5bccb08 100644 --- a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt +++ b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt @@ -19,6 +19,10 @@ package de.steamwar.tntleague.config +import de.steamwar.message.SubMessage +import de.steamwar.sql.Event +import de.steamwar.sql.EventFight +import de.steamwar.sql.Team import de.steamwar.tntleague.plugin import org.bukkit.Material import org.bukkit.configuration.ConfigurationSection @@ -36,7 +40,34 @@ data class TNTLeagueConfig( val blueLeader: UUID? = System.getProperty("blueLeader")?.let { UUID.fromString(it) }, val redLeader: UUID? = System.getProperty("redLeader")?.let { UUID.fromString(it) }, + + val eventFightId: Int? = System.getProperty("fightID")?.toInt() ) { + lateinit var eventFight: EventFight + lateinit var event: Event + lateinit var eventTeamBlue: Team + lateinit var eventTeamRed: Team + + val blueTeam: TeamConfig + val redTeam: TeamConfig + + init { + if (eventFightId != null) { + eventFight = EventFight.get(eventFightId) ?: throw IllegalArgumentException("EventFight with ID $eventFightId not found") + + event = Event.get(eventFight.eventID) + + eventTeamBlue = Team.get(eventFight.teamBlue) + eventTeamRed = Team.get(eventFight.teamRed) + + blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage.Literal("§${eventTeamBlue.teamColor}${eventTeamBlue.teamName}"), eventTeamBlue.teamColor[0]) + redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage.Literal("§${eventTeamRed.teamColor}${eventTeamRed.teamName}"), eventTeamRed.teamColor[0]) + } else { + blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage.Translatable("BLUE"), '3') + redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage.Translatable("RED"), 'c') + } + } + companion object { val config: TNTLeagueConfig by lazy { loadConfig(plugin.config) } @@ -55,6 +86,8 @@ data class TNTLeagueConfig( ) }.mapKeys { Material.getMaterial(it.key) ?: Material.BARRIER } } + + fun isEvent() = config.eventFightId != null } data class Price( diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt index df2dd34e..01667abd 100644 --- a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt +++ b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt @@ -54,8 +54,8 @@ object TNTLeagueWorldConfig { ) } - lateinit var blueTeam: TeamConfig - lateinit var redTeam: TeamConfig + lateinit var blueTeam: TeamWorldConfig + lateinit var redTeam: TeamWorldConfig lateinit var lobby: Location var teamsOnSameLine by Delegates.notNull() lateinit var targetMaterial: Material @@ -64,8 +64,8 @@ object TNTLeagueWorldConfig { init { try { - blueTeam = TeamConfig.fromConfig(config.getConfigurationSection("blueTeam")!!) - redTeam = TeamConfig.fromConfig(config.getConfigurationSection("redTeam")!!) + blueTeam = TeamWorldConfig.fromConfig(config.getConfigurationSection("blueTeam")!!) + redTeam = TeamWorldConfig.fromConfig(config.getConfigurationSection("redTeam")!!) teamsOnSameLine = abs(blueTeam.spawnLocation.blockX - redTeam.spawnLocation.blockX) < 20 lobby = config.getWorldLocation("lobby", blueTeam.spawnLocation.clone().add(redTeam.spawnLocation).multiply(0.5)) targetMaterial = Material.matchMaterial(config.getString("targetMaterial", "IRON_BLOCK")!!)!! @@ -76,39 +76,6 @@ object TNTLeagueWorldConfig { Bukkit.shutdown() } } - - @JvmRecord - data class TeamConfig( - val spawnLocation: Location, - val dealerSpawn: Location, - val itemSpawn: Location, - val target: Area - ) { - companion object { - fun fromConfig(config: ConfigurationSection): TeamConfig { - val spawnLocation = config.getWorldLocation("spawn") - val dealerSpawn = config.getWorldLocation("dealerSpawn") - val itemSpawn = config.getWorldLocation("itemSpawn") - val targetPos1 = config.getWorldLocation("targetMin") - val targetPos2 = config.getWorldLocation("targetMax") - - spawnDealer(dealerSpawn) - - return TeamConfig(spawnLocation, dealerSpawn, itemSpawn, Area(targetPos1, targetPos2)) - } - - private fun spawnDealer(loc: Location) = world.spawn(loc, WanderingTrader::class.java) - .apply { - customName(Component.text("Shop")) - isCustomNameVisible = false - isInvulnerable = true - isSilent = true - isCollidable = false - isAware = false - setAI(false) - } - } - } } fun ConfigurationSection.getWorldLocation(s: String, default: Location? = null): Location { diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TeamConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TeamConfig.kt new file mode 100644 index 00000000..61cb3431 --- /dev/null +++ b/TNTLeague/src/de/steamwar/tntleague/config/TeamConfig.kt @@ -0,0 +1,67 @@ +/* + * 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 . + */ + +package de.steamwar.tntleague.config + +import de.steamwar.kotlin.util.Area +import de.steamwar.message.SubMessage +import net.kyori.adventure.text.Component +import org.bukkit.Location +import org.bukkit.configuration.ConfigurationSection +import org.bukkit.entity.WanderingTrader + +data class TeamConfig( + val worldConfig: TeamWorldConfig, + + val name: SubMessage, + val color: Char +) + +@JvmRecord +data class TeamWorldConfig( + val spawnLocation: Location, + val dealerSpawn: Location, + val itemSpawn: Location, + val target: Area +) { + companion object { + fun fromConfig(config: ConfigurationSection): TeamWorldConfig { + val spawnLocation = config.getWorldLocation("spawn") + val dealerSpawn = config.getWorldLocation("dealerSpawn") + val itemSpawn = config.getWorldLocation("itemSpawn") + val targetPos1 = config.getWorldLocation("targetMin") + val targetPos2 = config.getWorldLocation("targetMax") + + spawnDealer(dealerSpawn) + + return TeamWorldConfig(spawnLocation, dealerSpawn, itemSpawn, Area(targetPos1, targetPos2)) + } + + private fun spawnDealer(loc: Location) = world.spawn(loc, WanderingTrader::class.java) + .apply { + customName(Component.text("Shop")) + isCustomNameVisible = false + isInvulnerable = true + isSilent = true + isCollidable = false + isAware = false + setAI(false) + } + } +} diff --git a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt index 77aa9dfb..60f921fc 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt @@ -66,7 +66,7 @@ object GlobalListener: Listener { fun onPlayerMove(e: PlayerMoveEvent) { if (e.to.blockY < TNTLeagueWorldConfig.minHeight) { when (val team = TNTLeagueGame.getTeam(e.player)) { - is TNTLeagueTeam -> e.player.teleport(team.config.spawnLocation) + is TNTLeagueTeam -> e.player.teleport(team.config.worldConfig.spawnLocation) null -> e.player.teleport(TNTLeagueWorldConfig.blueTeam.spawnLocation) } } @@ -87,7 +87,7 @@ object GlobalListener: Listener { @EventHandler fun onPlayerRespawn(e: PlayerRespawnEvent) { when (val team = TNTLeagueGame.getTeam(e.player)) { - is TNTLeagueTeam -> e.respawnLocation = team.config.spawnLocation + is TNTLeagueTeam -> e.respawnLocation = team.config.worldConfig.spawnLocation null -> e.respawnLocation = TNTLeagueWorldConfig.lobby } } @@ -100,7 +100,7 @@ object GlobalListener: Listener { val fightTeam = TNTLeagueGame.getTeam(player) if (fightTeam != null) { - message.broadcastPrefixless("PARTICIPANT_CHAT", SubMessage(fightTeam.name), player.name, msg) + message.broadcastPrefixless("PARTICIPANT_CHAT", fightTeam.name, player.name, msg) } else { message.broadcastPrefixless("SPECTATOR_CHAT", player.name, msg) } diff --git a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt index e064a350..80c86314 100644 --- a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt +++ b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt @@ -64,8 +64,8 @@ object TNTLeagueGame { var gameTimeRemaining: Int = TNTLeagueConfig.config.gameTime - val blueTeam = TNTLeagueTeam(TNTLeagueWorldConfig.blueTeam, TNTLeagueTeam.Team.BLUE) - val redTeam = TNTLeagueTeam(TNTLeagueWorldConfig.redTeam, TNTLeagueTeam.Team.RED) + val blueTeam = TNTLeagueTeam(TNTLeagueConfig.config.blueTeam) + val redTeam = TNTLeagueTeam(TNTLeagueConfig.config.redTeam) private lateinit var start: Timestamp @@ -156,10 +156,18 @@ object TNTLeagueGame { fun getTeam(player: Player) = if (player in blueTeam.members) blueTeam else if (player in redTeam.members) redTeam else null - fun getFreeTeam(player: Player) = if (blueTeam.leader == null && (TNTLeagueConfig.config.blueLeader == null || player.uniqueId == TNTLeagueConfig.config.blueLeader)) blueTeam + fun getFreeTeam(player: Player) = if (TNTLeagueConfig.isEvent()) getEventFreeTeam(player) else getNormalFreeTeam(player) + + private fun getNormalFreeTeam(player: Player) = if (blueTeam.leader == null && (TNTLeagueConfig.config.blueLeader == null || player.uniqueId == TNTLeagueConfig.config.blueLeader)) blueTeam else if (redTeam.leader == null && TNTLeagueConfig.config.redLeader == null || player.uniqueId == TNTLeagueConfig.config.redLeader) redTeam else null + private fun getEventFreeTeam(player: Player) = SteamwarUser.get(player.uniqueId).let { user -> + if (user.team == TNTLeagueConfig.config.eventTeamBlue.teamId && blueTeam.members.size < TNTLeagueConfig.config.event.maximumTeamMembers) blueTeam + else if (user.team == TNTLeagueConfig.config.eventTeamRed.teamId && redTeam.members.size < TNTLeagueConfig.config.event.maximumTeamMembers) redTeam + else null + } + fun checkStart() { if (blueTeam.isReady && redTeam.isReady) { blueTeam.leader?.inventory?.clear() @@ -209,18 +217,26 @@ object TNTLeagueGame { fun win(tntLeagueTeam: TNTLeagueTeam, reason: WinReason) { if (state != GameState.RUNNING) return end() - plugin.server.onlinePlayers.forEach { message.send("TEAM_WIN", it, SubMessage(tntLeagueTeam.name)) } + plugin.server.onlinePlayers.forEach { message.send("TEAM_WIN", it, tntLeagueTeam.name) } explode(tntLeagueTeam.opposite) + + if (TNTLeagueConfig.isEvent()) { + TNTLeagueConfig.config.eventFight.ergebnis = tntLeagueTeam.ergebnisInt + } } fun draw(reason: WinReason) { if (state != GameState.RUNNING) return end() message.broadcast("DRAW") + + if (TNTLeagueConfig.isEvent()) { + TNTLeagueConfig.config.eventFight.ergebnis = 3 + } } fun explode(team: TNTLeagueTeam) { - Area(team.config.spawnLocation.clone().add(20.0, 30.0, 20.0), team.config.spawnLocation.clone().subtract(20.0, 0.0, 20.0).add(0.0, 30.0, 0.0)) + Area(team.config.worldConfig.spawnLocation.clone().add(20.0, 30.0, 20.0), team.config.worldConfig.spawnLocation.clone().subtract(20.0, 0.0, 20.0).add(0.0, 30.0, 0.0)) .locations .filterIndexed { index, _ -> index % 7 == 0 } .forEachIndexed { index, location -> @@ -235,8 +251,8 @@ object TNTLeagueGame { plugin.server.worlds.first().name, "TNTLeague", "", - blueTeam.name.colorByTeam(blueTeam), - redTeam.name.colorByTeam(redTeam), + blueTeam.name.message.colorByTeam(blueTeam), + redTeam.name.message.colorByTeam(redTeam), state.lobbyName, TNTLeagueConfig.config.gameTime - gameTimeRemaining, blueTeam.leader?.let { SteamwarUser.get(it.uniqueId).id } ?: 0, diff --git a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt index 200f457e..773c4a46 100644 --- a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt +++ b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt @@ -22,6 +22,7 @@ package de.steamwar.tntleague.game import de.steamwar.message.SubMessage import de.steamwar.tntleague.colorByTeam import de.steamwar.tntleague.config.TNTLeagueWorldConfig +import de.steamwar.tntleague.config.TeamConfig import de.steamwar.tntleague.config.targetedBlocks import de.steamwar.tntleague.game.TNTLeagueGame.WinReason import de.steamwar.tntleague.game.TNTLeagueGame.updateFightinfo @@ -32,11 +33,10 @@ import net.kyori.adventure.text.Component import org.bukkit.GameMode import org.bukkit.Material import org.bukkit.Sound -import org.bukkit.enchantments.Enchantment import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack -data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private val team: Team) { +data class TNTLeagueTeam(val config: TeamConfig) { var leader: Player? = null set(player) { @@ -52,11 +52,11 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va val members = mutableListOf() val invites = mutableListOf() - val name: String - get() = team.name.uppercase() + val name: SubMessage + get() = config.name val color: Char - get() = team.color + get() = config.color var isReady: Boolean = false set(value) { @@ -64,7 +64,7 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va leader?.inventory?.setItem(4, readyItem()) leader?.let { it.playSound(it.location, Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 1f) } - message.broadcastActionbar(if (value) "IS_READY" else "IS_NOT_READY", SubMessage(name)) + message.broadcastActionbar(if (value) "IS_READY" else "IS_NOT_READY", name) if (value && opposite.isReady) { TNTLeagueGame.checkStart() @@ -82,19 +82,27 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va var coins: Int = 0 val opposite: TNTLeagueTeam - get() = when (team) { - Team.BLUE -> TNTLeagueGame.redTeam - Team.RED -> TNTLeagueGame.blueTeam + get() = when (this) { + TNTLeagueGame.redTeam -> TNTLeagueGame.blueTeam + TNTLeagueGame.blueTeam -> TNTLeagueGame.redTeam + else -> error("Invalid Team") + } + + val ergebnisInt: Int + get() = when (this) { + TNTLeagueGame.redTeam -> 2 + TNTLeagueGame.blueTeam -> 3 + else -> error("Invalid Team") } fun join(player: Player): Boolean { members.add(player) with(player) { - teleport(config.spawnLocation) + teleport(config.worldConfig.spawnLocation) gameMode = GameMode.ADVENTURE inventory.clear() - message.broadcast("JOIN_TEAM", name.colorByTeam(this@TNTLeagueTeam), SubMessage(this@TNTLeagueTeam.name)) + message.broadcast("JOIN_TEAM", name.colorByTeam(this@TNTLeagueTeam), this@TNTLeagueTeam.name) } if (leader == null) { @@ -154,13 +162,8 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va teleport(TNTLeagueWorldConfig.lobby) gameMode = GameMode.SPECTATOR inventory.clear() - message.broadcast("QUIT_TEAM", name.colorByTeam(this@TNTLeagueTeam), SubMessage(this@TNTLeagueTeam.name)) + message.broadcast("QUIT_TEAM", name.colorByTeam(this@TNTLeagueTeam), this@TNTLeagueTeam.name) } updateFightinfo() } - - enum class Team(val color: Char) { - BLUE('3'), - RED('c'); - } } \ No newline at end of file diff --git a/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt b/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt index 77ba1d48..204680d0 100644 --- a/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt +++ b/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt @@ -50,10 +50,10 @@ data class TNTLeagueScoreboard(val p: Player): ScoreboardCallback { lines.add("§3") with(TNTLeagueGame.redTeam) { - lines.add(message.parse("SCOREBOARD_TEAM", p, SubMessage(name), targetedBlocks - damagedBlocks)) + lines.add(message.parse("SCOREBOARD_TEAM", p, name, targetedBlocks - damagedBlocks)) } with(TNTLeagueGame.blueTeam) { - lines.add(message.parse("SCOREBOARD_TEAM", p, SubMessage(name), targetedBlocks - damagedBlocks)) + lines.add(message.parse("SCOREBOARD_TEAM", p, name, targetedBlocks - damagedBlocks)) } lines.add("§4") From 482282f913cceb3011b6e6fd7b258630880d40ef Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 1 Feb 2025 22:00:36 +0100 Subject: [PATCH 099/106] Make TNTLeague Event System Capable --- .../src/de/steamwar/message/Message.java | 7 ++--- .../src/de/steamwar/message/SubMessage.java | 29 +++++-------------- .../steamwar/tntleague/TNTLeague.properties | 1 + .../tntleague/config/TNTLeagueConfig.kt | 8 ++--- 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java index f953ce8d..b9ae84b7 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java @@ -72,12 +72,9 @@ public class Message { pattern += fromRB(resourceBundle, message); for (int i = 0; i < params.length; i++) { - if (params[i] instanceof SubMessage.Translatable) { - SubMessage.Translatable smsg = (SubMessage.Translatable) params[i]; + if (params[i] instanceof SubMessage) { + SubMessage smsg = (SubMessage) params[i]; params[i] = parse(smsg.getMessage(), sender, smsg.getParams()); - } else if (params[i] instanceof SubMessage.Literal) { - SubMessage.Literal smsg = (SubMessage.Literal) params[i]; - params[i] = smsg.getMessage(); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java index 4c302689..e40b74a5 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java @@ -19,33 +19,20 @@ package de.steamwar.message; -import lombok.AllArgsConstructor; import lombok.Getter; @Getter -@AllArgsConstructor -public abstract class SubMessage { +public class SubMessage { private final String message; + private final Object[] params; - @Getter - public static class Translatable extends SubMessage { - private final Object[] params; - - public Translatable(String message, Object... params) { - super(message); - this.params = params; - } - - public Translatable(String message) { - super(message); - this.params = new Object[0]; - } + public SubMessage(String message, Object... params) { + this.message = message; + this.params = params; } - @Getter - public static class Literal extends SubMessage { - public Literal(String message) { - super(message); - } + public SubMessage(String message) { + this.message = message; + this.params = new Object[0]; } } diff --git a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.properties b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.properties index 05d998e2..73e3b416 100644 --- a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.properties +++ b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.properties @@ -18,6 +18,7 @@ # PREFIX=§eTNT§7League§8» +PLAIN_STRING={0} JOIN=§e{0} §7joined the game! JOIN_TEAM={0} §7joined the {1} §7team! QUIT={0} §7left the game! diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt index e5bccb08..7b1e865a 100644 --- a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt +++ b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt @@ -60,11 +60,11 @@ data class TNTLeagueConfig( eventTeamBlue = Team.get(eventFight.teamBlue) eventTeamRed = Team.get(eventFight.teamRed) - blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage.Literal("§${eventTeamBlue.teamColor}${eventTeamBlue.teamName}"), eventTeamBlue.teamColor[0]) - redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage.Literal("§${eventTeamRed.teamColor}${eventTeamRed.teamName}"), eventTeamRed.teamColor[0]) + blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage("PLAIN_STRING", "§${eventTeamBlue.teamColor}${eventTeamBlue.teamName}"), eventTeamBlue.teamColor[0]) + redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage("PLAIN_STRING", "§${eventTeamRed.teamColor}${eventTeamRed.teamName}"), eventTeamRed.teamColor[0]) } else { - blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage.Translatable("BLUE"), '3') - redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage.Translatable("RED"), 'c') + blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage("BLUE"), '3') + redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage("RED"), 'c') } } From 414bd20eb9eaa6d01c0d1678b89278b3a76b690b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 1 Feb 2025 22:58:49 +0100 Subject: [PATCH 100/106] Make TowerRun Event System Capable --- .../src/de/steamwar/towerrun/TowerRun.java | 1 - .../de/steamwar/towerrun/config/Config.java | 33 +++++++++++++++++++ .../steamwar/towerrun/game/TowerRunGame.java | 11 ++++++- .../towerrun/listener/GlobalListener.java | 5 --- .../towerrun/listener/LobbyListener.java | 22 +++++++++++++ 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/TowerRun/src/de/steamwar/towerrun/TowerRun.java b/TowerRun/src/de/steamwar/towerrun/TowerRun.java index 23f00488..7e6df112 100644 --- a/TowerRun/src/de/steamwar/towerrun/TowerRun.java +++ b/TowerRun/src/de/steamwar/towerrun/TowerRun.java @@ -73,7 +73,6 @@ public class TowerRun extends JavaPlugin { new LobbyListener(); new IngameListener(); new GlobalListener(); - new LobbyListener(); new NotLobbyListener(); final LobbyCountdown lobbyCountdown = new LobbyCountdown(); new EndCountdown(lobbyCountdown); diff --git a/TowerRun/src/de/steamwar/towerrun/config/Config.java b/TowerRun/src/de/steamwar/towerrun/config/Config.java index 91fb02b4..fe6acd07 100644 --- a/TowerRun/src/de/steamwar/towerrun/config/Config.java +++ b/TowerRun/src/de/steamwar/towerrun/config/Config.java @@ -19,6 +19,8 @@ package de.steamwar.towerrun.config; +import de.steamwar.sql.Event; +import de.steamwar.sql.EventFight; import de.steamwar.towerrun.TowerRun; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; @@ -41,6 +43,12 @@ public class Config { private static final int EVENT_KAMPF_ID; + // Event + public static final EventFight EVENT_FIGHT; + public static final int EVENT_TEAM_BLUE_ID; + public static final int EVENT_TEAM_RED_ID; + public static final int EVENT_MAXIMUM_TEAM_MEMBERS; + static { File configFile = new File(TowerRun.getInstance().getDataFolder(), "config.yml"); if (!configFile.exists()) { @@ -57,9 +65,34 @@ public class Config { DESTROYABLE_BLOCKS = EnumSet.copyOf(config.getStringList("destroyable").stream().map(Material::valueOf).collect(Collectors.toSet())); EVENT_KAMPF_ID = Integer.parseInt(System.getProperty("fightID", "0")); + + if (event()) { + EVENT_FIGHT = EventFight.get(EVENT_KAMPF_ID); + + if (EVENT_FIGHT == null) { + Bukkit.shutdown(); + throw new IllegalStateException("Event not found"); + } + + Event event = Event.get(EVENT_FIGHT.getEventID()); + + EVENT_TEAM_BLUE_ID = EVENT_FIGHT.getTeamBlue(); + EVENT_TEAM_RED_ID = EVENT_FIGHT.getTeamRed(); + EVENT_MAXIMUM_TEAM_MEMBERS = event.getMaximumTeamMembers(); + } else { + EVENT_FIGHT = null; + + EVENT_TEAM_BLUE_ID = 0; + EVENT_TEAM_RED_ID = 0; + EVENT_MAXIMUM_TEAM_MEMBERS = Integer.MAX_VALUE; + } } public static boolean test() { return EVENT_KAMPF_ID == -1; } + + public static boolean event() { + return EVENT_KAMPF_ID > 0; + } } diff --git a/TowerRun/src/de/steamwar/towerrun/game/TowerRunGame.java b/TowerRun/src/de/steamwar/towerrun/game/TowerRunGame.java index c83138d4..2c014cb5 100644 --- a/TowerRun/src/de/steamwar/towerrun/game/TowerRunGame.java +++ b/TowerRun/src/de/steamwar/towerrun/game/TowerRunGame.java @@ -20,7 +20,9 @@ package de.steamwar.towerrun.game; import de.steamwar.core.CraftbukkitWrapper; +import de.steamwar.sql.SteamwarUser; import de.steamwar.towerrun.TowerRun; +import de.steamwar.towerrun.config.Config; import de.steamwar.towerrun.config.WorldConfig; import de.steamwar.towerrun.state.GameState; import de.steamwar.towerrun.state.GameStates; @@ -64,7 +66,6 @@ public class TowerRunGame { public static void start() { if (GameState.getCurrentState() == GameStates.GENERATING_TOWER) { - PLAYERS_ALIVE.addAll(TowerRunPlayer.getAll()); PLAYERS_ALIVE.forEach(p -> { p.reset(); p.player().setGameMode(GameMode.SURVIVAL); @@ -108,6 +109,10 @@ public class TowerRunGame { PLAYERS_ALIVE.clear(); Bukkit.getOnlinePlayers().forEach(player -> player.sendTitle(TowerRun.getMessage().parse("GAME_TIE", player), "", 10, 70, 20)); GameState.nextState(); + + if (Config.event()) { + Config.EVENT_FIGHT.setErgebnis(3); + } } public static void win(TowerRunPlayer tPlayer) { @@ -120,6 +125,10 @@ public class TowerRunGame { player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 1, 1); }); GameState.nextState(); + + if (Config.event()) { + Config.EVENT_FIGHT.setErgebnis(SteamwarUser.get(tPlayer.player().getUniqueId()).getTeam() == Config.EVENT_TEAM_BLUE_ID ? 1 : 2); + } } public static void reset() { diff --git a/TowerRun/src/de/steamwar/towerrun/listener/GlobalListener.java b/TowerRun/src/de/steamwar/towerrun/listener/GlobalListener.java index 353adc20..b8256d80 100644 --- a/TowerRun/src/de/steamwar/towerrun/listener/GlobalListener.java +++ b/TowerRun/src/de/steamwar/towerrun/listener/GlobalListener.java @@ -38,11 +38,6 @@ public class GlobalListener extends GameStateBukkitListener { super(EnumSet.allOf(GameStates.class)); } - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - TowerRunPlayer.get(event.getPlayer()); - } - @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { if (TowerRunGame.isAlive(TowerRunPlayer.get(event.getPlayer()))) { diff --git a/TowerRun/src/de/steamwar/towerrun/listener/LobbyListener.java b/TowerRun/src/de/steamwar/towerrun/listener/LobbyListener.java index 52d600ca..c93bc4bb 100644 --- a/TowerRun/src/de/steamwar/towerrun/listener/LobbyListener.java +++ b/TowerRun/src/de/steamwar/towerrun/listener/LobbyListener.java @@ -19,8 +19,12 @@ package de.steamwar.towerrun.listener; +import de.steamwar.sql.SteamwarUser; import de.steamwar.towerrun.TowerRun; +import de.steamwar.towerrun.config.Config; import de.steamwar.towerrun.config.WorldConfig; +import de.steamwar.towerrun.game.TowerRunGame; +import de.steamwar.towerrun.game.TowerRunPlayer; import de.steamwar.towerrun.state.GameStateBukkitListener; import de.steamwar.towerrun.state.GameStates; import org.bukkit.GameMode; @@ -34,6 +38,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import java.util.EnumSet; +import java.util.HashMap; public class LobbyListener extends GameStateBukkitListener { public LobbyListener() { @@ -43,6 +48,7 @@ public class LobbyListener extends GameStateBukkitListener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); + if (TowerRun.getTowerGenerator() != null) { player.teleport(TowerRun.getTowerGenerator().getSpawn()); player.setGameMode(GameMode.SPECTATOR); @@ -50,6 +56,22 @@ public class LobbyListener extends GameStateBukkitListener { player.teleport(WorldConfig.SPAWN); player.setGameMode(GameMode.SURVIVAL); } + + if (Config.event()) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + int team = user.getTeam(); + + if (team != Config.EVENT_TEAM_BLUE_ID && team != Config.EVENT_TEAM_RED_ID) { + player.setGameMode(GameMode.SPECTATOR); + return; + } + + if (TowerRunGame.PLAYERS_ALIVE.stream().map(towerRunPlayer -> SteamwarUser.get(towerRunPlayer.player().getUniqueId()).getTeam()).filter(integer -> integer == team).count() < Config.EVENT_MAXIMUM_TEAM_MEMBERS) { + TowerRunGame.PLAYERS_ALIVE.add(TowerRunPlayer.get(player)); + } + } else { + TowerRunGame.PLAYERS_ALIVE.add(TowerRunPlayer.get(player)); + } } @EventHandler From 93ab1a50f32d624dbe90d920b0848dc40d437d2c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 2 Feb 2025 14:12:25 +0100 Subject: [PATCH 101/106] Fix team auto-assign logic in lobby state Replaced `members.add` with `join` to correctly integrate new players into teams during the lobby phase. This ensures proper team setup and adherence to game mechanics. --- TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt index 773c4a46..8b452fca 100644 --- a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt +++ b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt @@ -139,7 +139,7 @@ data class TNTLeagueTeam(val config: TeamConfig) { if (TNTLeagueGame.state == TNTLeagueGame.GameState.LOBBY) { if (members.isEmpty()) { plugin.server.onlinePlayers.firstOrNull { it != player && TNTLeagueGame.getTeam(it) == null }?.run { - members.add(this) + join(this) } } if (leader == player) { From b4baef321fa5c3069fd08af61019830f5ecd01a3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 2 Feb 2025 15:28:33 +0100 Subject: [PATCH 102/106] Trigger rebuild --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ad9f4739..65e4bf0e 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # SteamWar + From e39db5978bd60d6939bb66d6e70a3492cb714541 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 2 Feb 2025 16:06:48 +0100 Subject: [PATCH 103/106] Add server shutdown if less than 2 players after 5 minutes --- TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt | 7 +++++++ .../src/de/steamwar/tntleague/events/LobbyListener.kt | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt index 378dbfc7..d24cdf6f 100644 --- a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt +++ b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt @@ -27,6 +27,8 @@ import de.steamwar.tntleague.command.RemoveCommand import de.steamwar.tntleague.events.GlobalListener import de.steamwar.tntleague.events.LobbyListener import de.steamwar.tntleague.game.TNTLeagueTeam +import net.kyori.adventure.text.Component +import org.bukkit.Bukkit import org.bukkit.plugin.java.JavaPlugin lateinit var plugin: TNTLeague @@ -49,6 +51,11 @@ class TNTLeague : JavaPlugin() { AcceptCommand.register() RemoveCommand.register() LeaveCommand.register() + + plugin.server.scheduler.runTaskLater(plugin, Runnable { + if (server.onlinePlayers.size >= 2) return@Runnable + Bukkit.shutdown() + }, 20 * 60 * 5) } } diff --git a/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt index bb570498..d160498f 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt @@ -23,7 +23,6 @@ import de.steamwar.tntleague.game.TNTLeagueGame import org.bukkit.GameMode import org.bukkit.entity.EntityType import org.bukkit.event.EventHandler -import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.entity.EntityDamageEvent import org.bukkit.event.inventory.InventoryClickEvent From 1715fdccdf717a3b56241d8723cf68c9dd7c86d8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 2 Feb 2025 16:07:24 +0100 Subject: [PATCH 104/106] Remove unused imports in TNTLeague classes --- TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt | 1 - TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt | 2 -- 2 files changed, 3 deletions(-) diff --git a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt index d24cdf6f..ef3b8a81 100644 --- a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt +++ b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt @@ -27,7 +27,6 @@ import de.steamwar.tntleague.command.RemoveCommand import de.steamwar.tntleague.events.GlobalListener import de.steamwar.tntleague.events.LobbyListener import de.steamwar.tntleague.game.TNTLeagueTeam -import net.kyori.adventure.text.Component import org.bukkit.Bukkit import org.bukkit.plugin.java.JavaPlugin diff --git a/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt b/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt index 204680d0..40fb4138 100644 --- a/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt +++ b/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt @@ -19,9 +19,7 @@ package de.steamwar.tntleague.util -import de.steamwar.message.SubMessage import de.steamwar.scoreboard.ScoreboardCallback -import de.steamwar.tntleague.colorByTeam import de.steamwar.tntleague.config.targetedBlocks import de.steamwar.tntleague.game.TNTLeagueGame import de.steamwar.tntleague.game.TNTLeagueTeam From 25cf1ab314dacee4d7479390542b36a2ad5b4720 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 2 Feb 2025 16:11:02 +0100 Subject: [PATCH 105/106] Add ReadyCommand --- .../src/de/steamwar/tntleague/TNTLeague.kt | 6 ++-- .../tntleague/command/ReadyCommand.kt | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 TNTLeague/src/de/steamwar/tntleague/command/ReadyCommand.kt diff --git a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt index 378dbfc7..2c63ae94 100644 --- a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt +++ b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.kt @@ -20,10 +20,7 @@ package de.steamwar.tntleague import de.steamwar.message.Message -import de.steamwar.tntleague.command.AcceptCommand -import de.steamwar.tntleague.command.InviteCommand -import de.steamwar.tntleague.command.LeaveCommand -import de.steamwar.tntleague.command.RemoveCommand +import de.steamwar.tntleague.command.* import de.steamwar.tntleague.events.GlobalListener import de.steamwar.tntleague.events.LobbyListener import de.steamwar.tntleague.game.TNTLeagueTeam @@ -45,6 +42,7 @@ class TNTLeague : JavaPlugin() { logger.info("TNTLeague enabled") + ReadyCommand.register() InviteCommand.register() AcceptCommand.register() RemoveCommand.register() diff --git a/TNTLeague/src/de/steamwar/tntleague/command/ReadyCommand.kt b/TNTLeague/src/de/steamwar/tntleague/command/ReadyCommand.kt new file mode 100644 index 00000000..e53444ce --- /dev/null +++ b/TNTLeague/src/de/steamwar/tntleague/command/ReadyCommand.kt @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +package de.steamwar.tntleague.command + +import de.steamwar.command.SWCommand +import de.steamwar.tntleague.game.TNTLeagueGame +import org.bukkit.entity.Player + +object ReadyCommand: SWCommand("ready") { + + @Register + fun invitePlayer(@Validator("isLeader") sender: Player) { + if (TNTLeagueGame.state != TNTLeagueGame.GameState.LOBBY) return + TNTLeagueGame.getTeam(sender)?.also { it.isReady = it.isReady.not() } + } +} \ No newline at end of file From ec43e7eba8d4ffecd4c44f3670486f4cf2bfae2a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 2 Feb 2025 16:29:10 +0100 Subject: [PATCH 106/106] Trigger rebuild --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 65e4bf0e..ad9f4739 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ # SteamWar -