Add SpigotCore module

This commit is contained in:
2024-08-04 21:37:50 +02:00
parent aeef0f6e49
commit b97890fe7a
110 changed files with 11957 additions and 1 deletions
+60
View File
@@ -0,0 +1,60 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
plugins {
id("java")
id("base")
}
group = "de.steamwar"
version = ""
tasks.compileJava {
options.encoding = "UTF-8"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
sourceSets {
main {
java {
srcDirs("src/")
}
resources {
srcDirs("src/")
exclude("**/*.java", "**/*.kt")
}
}
}
dependencies {
compileOnly("org.projectlombok:lombok:1.18.32")
annotationProcessor("org.projectlombok:lombok:1.18.32")
compileOnly(project(":SpigotCore:SpigotCore_Main"))
compileOnly(project(":SpigotCore:SpigotCore_8"))
compileOnly(project(":SpigotCore:SpigotCore_9"))
compileOnly(project(":CommonCore"))
compileOnly("de.steamwar:spigot:1.14")
compileOnly("de.steamwar:worldedit:1.15")
}
@@ -0,0 +1,361 @@
/*
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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper {
private static final Map<String, Material> renamedLegacy = new HashMap<>();
static{
renamedLegacy.put("WOOD", Material.OAK_WOOD);
renamedLegacy.put("SAPLING", Material.OAK_SAPLING);
renamedLegacy.put("STATIONARY_WATER", Material.WATER);
renamedLegacy.put("STATIONARY_LAVA", Material.LAVA);
renamedLegacy.put("LOG", Material.OAK_LOG);
renamedLegacy.put("LEAVES", Material.OAK_LEAVES);
renamedLegacy.put("BED_BLOCK", Material.RED_BED);
renamedLegacy.put("BED", Material.RED_BED);
renamedLegacy.put("PISTON_STICKY_BASE", Material.STICKY_PISTON);
renamedLegacy.put("WEB", Material.COBWEB);
renamedLegacy.put("LONG_GRASS", Material.TALL_GRASS);
renamedLegacy.put("PISTON_BASE", Material.PISTON);
renamedLegacy.put("PISTON_EXTENSION", Material.PISTON_HEAD);
renamedLegacy.put("WOOL", Material.WHITE_WOOL);
renamedLegacy.put("PISTON_MOVING_PIECE", Material.MOVING_PISTON);
renamedLegacy.put("YELLOW_FLOWER", Material.DANDELION);
renamedLegacy.put("RED_ROSE", Material.POPPY);
renamedLegacy.put("DOUBLE_STEP", Material.SMOOTH_STONE);
renamedLegacy.put("STEP", Material.SMOOTH_STONE_SLAB);
renamedLegacy.put("MOB_SPAWNER", Material.SPAWNER);
renamedLegacy.put("WOOD_STAIRS", Material.OAK_STAIRS);
renamedLegacy.put("WORKBENCH", Material.CRAFTING_TABLE);
renamedLegacy.put("CROPS", Material.WHEAT_SEEDS);
renamedLegacy.put("SEEDS", Material.WHEAT_SEEDS);
renamedLegacy.put("SOIL", Material.FARMLAND);
renamedLegacy.put("BURNING_FURNACE", Material.FURNACE);
renamedLegacy.put("SIGN_POST", Material.OAK_SIGN);
renamedLegacy.put("SIGN", Material.OAK_SIGN);
renamedLegacy.put("WOODEN_DOOR", Material.OAK_DOOR);
renamedLegacy.put("WOOD_DOOR", Material.OAK_DOOR);
renamedLegacy.put("RAILS", Material.RAIL);
renamedLegacy.put("WALL_SIGN", Material.OAK_WALL_SIGN);
renamedLegacy.put("STONE_PLATE", Material.STONE_PRESSURE_PLATE);
renamedLegacy.put("WOOD_PLATE", Material.OAK_PRESSURE_PLATE);
renamedLegacy.put("GLOWING_REDSTONE_ORE", Material.REDSTONE_ORE);
renamedLegacy.put("REDSTONE_TORCH_OFF", Material.REDSTONE_TORCH);
renamedLegacy.put("REDSTONE_TORCH_ON", Material.REDSTONE_TORCH);
renamedLegacy.put("IRON_DOOR_BLOCK", Material.IRON_DOOR);
renamedLegacy.put("SUGAR_CANE_BLOCK", Material.SUGAR_CANE);
renamedLegacy.put("CAKE_BLOCK", Material.CAKE);
renamedLegacy.put("MELON_BLOCK", Material.MELON);
renamedLegacy.put("BEETROOT_BLOCK", Material.BEETROOT);
renamedLegacy.put("FENCE", Material.OAK_FENCE);
renamedLegacy.put("PORTAL", Material.NETHER_PORTAL);
renamedLegacy.put("DIODE_BLOCK_OFF", Material.REPEATER);
renamedLegacy.put("DIODE_BLOCK_ON", Material.REPEATER);
renamedLegacy.put("DIODE", Material.REPEATER);
renamedLegacy.put("STAINED_GLASS", Material.WHITE_STAINED_GLASS);
renamedLegacy.put("TRAP_DOOR", Material.OAK_TRAPDOOR);
renamedLegacy.put("MONSTER_EGGS", Material.SKELETON_SPAWN_EGG);
renamedLegacy.put("MONSTER_EGG", Material.SKELETON_SPAWN_EGG);
renamedLegacy.put("SMOOTH_BRICK", Material.STONE_BRICKS);
renamedLegacy.put("HUGE_MUSHROOM_1", Material.MUSHROOM_STEM);
renamedLegacy.put("HUGE_MUSHROOM_2", Material.RED_MUSHROOM);
renamedLegacy.put("IRON_FENCE", Material.IRON_BARS);
renamedLegacy.put("THIN_GLASS", Material.GLASS_PANE);
renamedLegacy.put("FENCE_GATE", Material.OAK_FENCE_GATE);
renamedLegacy.put("SMOOTH_STAIRS", Material.STONE_BRICK_STAIRS);
renamedLegacy.put("MYCEL", Material.MYCELIUM);
renamedLegacy.put("WATER_LILY", Material.LILY_PAD);
renamedLegacy.put("NETHER_FENCE", Material.NETHER_BRICK_FENCE);
renamedLegacy.put("NETHER_WARTS", Material.NETHER_WART);
renamedLegacy.put("NETHER_STALK", Material.NETHER_WART);
renamedLegacy.put("ENCHANTMENT_TABLE", Material.ENCHANTING_TABLE);
renamedLegacy.put("ENDER_PORTAL", Material.END_PORTAL);
renamedLegacy.put("ENDER_PORTAL_FRAME", Material.END_PORTAL_FRAME);
renamedLegacy.put("ENDER_STONE", Material.END_STONE);
renamedLegacy.put("REDSTONE_LAMP_OFF", Material.REDSTONE_LAMP);
renamedLegacy.put("REDSTONE_LAMP_ON", Material.REDSTONE_LAMP);
renamedLegacy.put("WOOD_DOUBLE_STEP", Material.OAK_SLAB);
renamedLegacy.put("WOOD_STEP", Material.OAK_SLAB);
renamedLegacy.put("SPRUCE_WOOD_STAIRS", Material.SPRUCE_STAIRS);
renamedLegacy.put("BIRCH_WOOD_STAIRS", Material.BIRCH_STAIRS);
renamedLegacy.put("JUNGLE_WOOD_STAIRS", Material.JUNGLE_STAIRS);
renamedLegacy.put("COMMAND", Material.COMMAND_BLOCK);
renamedLegacy.put("COBBLE_WALL", Material.COBBLESTONE_WALL);
renamedLegacy.put("WOOD_BUTTON", Material.OAK_BUTTON);
renamedLegacy.put("SKULL", Material.SKELETON_SKULL);
renamedLegacy.put("SKULL_ITEM", Material.SKELETON_SKULL);
renamedLegacy.put("GOLD_PLATE", Material.LIGHT_WEIGHTED_PRESSURE_PLATE);
renamedLegacy.put("IRON_PLATE", Material.HEAVY_WEIGHTED_PRESSURE_PLATE);
renamedLegacy.put("REDSTONE_COMPARATOR_OFF", Material.COMPARATOR);
renamedLegacy.put("REDSTONE_COMPARATOR_ON", Material.COMPARATOR);
renamedLegacy.put("REDSTONE_COMPARATOR", Material.COMPARATOR);
renamedLegacy.put("QUARTZ_ORE", Material.QUARTZ);
renamedLegacy.put("STAINED_CLAY", Material.WHITE_TERRACOTTA);
renamedLegacy.put("STAINED_GLASS_PANE", Material.WHITE_STAINED_GLASS_PANE);
renamedLegacy.put("LEAVES_2", Material.ACACIA_LEAVES);
renamedLegacy.put("LOG_2", Material.ACACIA_LOG);
renamedLegacy.put("CARPET", Material.WHITE_CARPET);
renamedLegacy.put("HARD_CLAY", Material.TERRACOTTA);
renamedLegacy.put("DOUBLE_PLANT", Material.SUNFLOWER);
renamedLegacy.put("STANDING_BANNER", Material.WHITE_BANNER);
renamedLegacy.put("BANNER", Material.WHITE_BANNER);
renamedLegacy.put("WALL_BANNER", Material.WHITE_WALL_BANNER);
renamedLegacy.put("DAYLIGHT_DETECTOR_INVERTED", Material.DAYLIGHT_DETECTOR);
renamedLegacy.put("DOUBLE_STONE_SLAB2", Material.RED_SANDSTONE_SLAB);
renamedLegacy.put("STONE_SLAB2", Material.RED_SANDSTONE_SLAB);
renamedLegacy.put("PURPUR_DOUBLE_SLAB", Material.PURPUR_SLAB);
renamedLegacy.put("END_BRICKS", Material.END_STONE_BRICKS);
renamedLegacy.put("COMMAND_REPEATING", Material.REPEATING_COMMAND_BLOCK);
renamedLegacy.put("COMMAND_CHAIN", Material.CHAIN_COMMAND_BLOCK);
renamedLegacy.put("MAGMA", Material.MAGMA_BLOCK);
renamedLegacy.put("RED_NETHER_BRICK", Material.RED_NETHER_BRICKS);
renamedLegacy.put("SILVER_SHULKER_BOX", Material.LIGHT_GRAY_SHULKER_BOX);
renamedLegacy.put("SILVER_GLAZED_TERRACOTTA", Material.LIGHT_GRAY_TERRACOTTA);
renamedLegacy.put("CONCRETE", Material.WHITE_CONCRETE);
renamedLegacy.put("CONCRETE_POWDER", Material.WHITE_CONCRETE_POWDER);
renamedLegacy.put("IRON_SPADE", Material.IRON_SHOVEL);
renamedLegacy.put("WOOD_SWORD", Material.WOODEN_SWORD);
renamedLegacy.put("WOOD_SPADE", Material.WOODEN_SHOVEL);
renamedLegacy.put("WOOD_PICKAXE", Material.WOODEN_PICKAXE);
renamedLegacy.put("WOOD_AXE", Material.WOODEN_AXE);
renamedLegacy.put("STONE_SPADE", Material.STONE_SHOVEL);
renamedLegacy.put("DIAMOND_SPADE", Material.DIAMOND_SHOVEL);
renamedLegacy.put("MUSHROOM_SOUP", Material.MUSHROOM_STEW);
renamedLegacy.put("GOLD_SWORD", Material.GOLDEN_SWORD);
renamedLegacy.put("GOLD_SPADE", Material.GOLDEN_SHOVEL);
renamedLegacy.put("GOLD_PICKAXE", Material.GOLDEN_PICKAXE);
renamedLegacy.put("GOLD_AXE", Material.GOLDEN_AXE);
renamedLegacy.put("SULPHUR", Material.GUNPOWDER);
renamedLegacy.put("WOOD_HOE", Material.WOODEN_HOE);
renamedLegacy.put("GOLD_HOE", Material.GOLDEN_HOE);
renamedLegacy.put("GOLD_HELMET", Material.GOLDEN_HELMET);
renamedLegacy.put("GOLD_CHESTPLATE", Material.GOLDEN_CHESTPLATE);
renamedLegacy.put("GOLD_LEGGINGS", Material.GOLDEN_LEGGINGS);
renamedLegacy.put("GOLD_BOOTS", Material.GOLDEN_BOOTS);
renamedLegacy.put("PORK", Material.PORKCHOP);
renamedLegacy.put("GRILLED_PORK", Material.COOKED_PORKCHOP);
renamedLegacy.put("SNOW_BALL", Material.SNOWBALL);
renamedLegacy.put("BOAT", Material.OAK_BOAT);
renamedLegacy.put("CLAY_BRICK", Material.BRICKS);
renamedLegacy.put("STORAGE_MINECART", Material.CHEST_MINECART);
renamedLegacy.put("POWERED_MINECART", Material.FURNACE_MINECART);
renamedLegacy.put("WATCH", Material.CLOCK);
renamedLegacy.put("RAW_FISH", Material.SALMON);
renamedLegacy.put("COOKED_FISH", Material.COOKED_SALMON);
renamedLegacy.put("INK_SACK", Material.INK_SAC);
renamedLegacy.put("RAW_BEEF", Material.BEEF);
renamedLegacy.put("RAW_CHICKEN", Material.CHICKEN);
renamedLegacy.put("EYE_OF_ENDER", Material.ENDER_EYE);
renamedLegacy.put("SPECKLED_MELON", Material.GLISTERING_MELON_SLICE);
renamedLegacy.put("EXP_BOTTLE", Material.EXPERIENCE_BOTTLE);
renamedLegacy.put("FIREBALL", Material.FIRE_CHARGE);
renamedLegacy.put("BOOK_AND_QUILL", Material.WRITABLE_BOOK);
renamedLegacy.put("FLOWER_POT_ITEM", Material.FLOWER_POT);
renamedLegacy.put("EMPTY_MAP", Material.MAP);
renamedLegacy.put("BREWING_STAND_ITEM", Material.BREWING_STAND);
renamedLegacy.put("CAULDRON_ITEM", Material.CAULDRON);
renamedLegacy.put("CARROT_ITEM", Material.CARROT);
renamedLegacy.put("POTATO_ITEM", Material.POTATO);
renamedLegacy.put("SPRUCE_DOOR_ITEM", Material.SPRUCE_DOOR);
renamedLegacy.put("BIRCH_DOOR_ITEM", Material.BIRCH_DOOR);
renamedLegacy.put("JUNGLE_DOOR_ITEM", Material.JUNGLE_DOOR);
renamedLegacy.put("ACACIA_DOOR_ITEM", Material.ACACIA_DOOR);
renamedLegacy.put("DARK_OAK_DOOR_ITEM", Material.DARK_OAK_DOOR);
renamedLegacy.put("CARROT_STICK", Material.CARROT_ON_A_STICK);
renamedLegacy.put("FIREWORK", Material.FIREWORK_ROCKET);
renamedLegacy.put("FIREWORK_CHARGE", Material.FIREWORK_STAR);
renamedLegacy.put("NETHER_BRICK_ITEM", Material.NETHER_BRICKS);
renamedLegacy.put("EXPLOSIVE_MINECART", Material.TNT_MINECART);
renamedLegacy.put("IRON_BARDING", Material.IRON_HORSE_ARMOR);
renamedLegacy.put("GOLD_BARDING", Material.GOLDEN_HORSE_ARMOR);
renamedLegacy.put("DIAMOND_BARDING", Material.DIAMOND_HORSE_ARMOR);
renamedLegacy.put("LEASH", Material.LEAD);
renamedLegacy.put("COMMAND_MINECART", Material.COMMAND_BLOCK_MINECART);
renamedLegacy.put("CHORUS_FRUIT_POPPED", Material.POPPED_CHORUS_FRUIT);
renamedLegacy.put("DRAGONS_BREATH", Material.DRAGON_BREATH);
renamedLegacy.put("BOAT_SPRUCE", Material.SPRUCE_BOAT);
renamedLegacy.put("BOAT_BIRCH", Material.BIRCH_BOAT);
renamedLegacy.put("BOAT_JUNGLE", Material.JUNGLE_BOAT);
renamedLegacy.put("BOAT_ACACIA", Material.ACACIA_BOAT);
renamedLegacy.put("BOAT_DARK_OAK", Material.DARK_OAK_BOAT);
renamedLegacy.put("TOTEM", Material.TOTEM_OF_UNDYING);
renamedLegacy.put("GOLD_RECORD", Material.MUSIC_DISC_13);
renamedLegacy.put("GREEN_RECORD", Material.MUSIC_DISC_CAT);
renamedLegacy.put("RECORD_3", Material.MUSIC_DISC_BLOCKS);
renamedLegacy.put("RECORD_4", Material.MUSIC_DISC_CHIRP);
renamedLegacy.put("RECORD_5", Material.MUSIC_DISC_FAR);
renamedLegacy.put("RECORD_6", Material.MUSIC_DISC_MALL);
renamedLegacy.put("RECORD_7", Material.MUSIC_DISC_MELLOHI);
renamedLegacy.put("RECORD_8", Material.MUSIC_DISC_STAL);
renamedLegacy.put("RECORD_9", Material.MUSIC_DISC_STRAD);
renamedLegacy.put("RECORD_10", Material.MUSIC_DISC_WARD);
renamedLegacy.put("RECORD_11", Material.MUSIC_DISC_11);
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);
@Override
public void setScoreboardTitle(Object packet, String title) {
scoreboardName.set(packet, ChatWrapper.impl.stringToChatComponent(title));
}
private static final Class<?> scoreActionEnum = Reflection.getClass("{nms.server}.ScoreboardServer$Action");
private static final Reflection.FieldAccessor<?> scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0);
private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0];
@Override
public void setScoreAction(Object packet) {
scoreAction.set(packet, scoreActionChange);
}
@Override
public Material getMaterial(String material) {
try{
return Material.valueOf(material);
}catch(IllegalArgumentException e){
return renamedLegacy.get(material);
}
}
@Override
public Material getDye(int colorCode) {
switch(colorCode){
case 1:
return Material.RED_DYE;
case 2:
return Material.GREEN_DYE;
case 3:
return Material.BROWN_DYE;
case 4:
return Material.LAPIS_LAZULI;
case 5:
return Material.PURPLE_DYE;
case 6:
return Material.CYAN_DYE;
case 7:
return Material.LIGHT_GRAY_DYE;
case 8:
return Material.GRAY_DYE;
case 9:
return Material.PINK_DYE;
case 10:
return Material.LIME_DYE;
case 11:
return Material.YELLOW_DYE;
case 12:
return Material.LIGHT_BLUE_DYE;
case 13:
return Material.MAGENTA_DYE;
case 14:
return Material.ORANGE_DYE;
case 15:
return Material.WHITE_DYE;
default:
return Material.BLACK_DYE;
}
}
@SuppressWarnings("deprecation")
@Override
public ItemStack setSkullOwner(String player) {
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta headmeta = (SkullMeta) head.getItemMeta();
assert headmeta != null;
headmeta.setOwningPlayer(Bukkit.getOfflinePlayer(player.startsWith(".") ? player.substring(1) : player));
headmeta.setDisplayName(player);
head.setItemMeta(headmeta);
return head;
}
private static final Class<?> entityPose = Reflection.getClass("{nms.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];
@Override
public Object getPose(FlatteningWrapper.EntityPose pose) {
switch (pose) {
case SNEAKING:
return sneaking;
case SWIMMING:
return swimming;
case NORMAL:
default:
return standing;
}
}
@Override
public void setNamedSpawnPacketDataWatcher(Object packet) {
// field not present
}
@Override
public Object formatDisplayName(String displayName) {
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.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 Map<EntityType, Object> types = new HashMap<>();
static {
types.put(EntityType.ARMOR_STAND, 1);
}
@Override
public void setSpawnPacketType(Object packet, EntityType type) {
if(type.isAlive()) {
spawnLivingType.set(packet, Core.getVersion() > 18 ? get.invoke(entityTypesRegistry, toMinecraft.invoke(null, type.getKey())) : types.get(type));
} else {
spawnType.set(packet, get.invoke(entityTypesRegistry, toMinecraft.invoke(null, type.getKey())));
}
}
@Override
public int getViewDistance(Player player) {
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);
@Override
public void syncSave(World world) {
save.invoke(getHandle.invoke(world), null, true, false);
}
}
@@ -0,0 +1,30 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.core;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerRecipeDiscoverEvent;
public class RecipeDiscoverWrapper14 implements RecipeDiscoverWrapper {
@EventHandler
public void onRecipeDiscover(PlayerRecipeDiscoverEvent e) {
e.setCancelled(true);
}
}
@@ -0,0 +1,610 @@
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;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
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.*;
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.*;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.DataFixer;
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 org.bukkit.entity.Player;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
private static final ClipboardFormat SCHEMATIC = ClipboardFormats.findByAlias("schematic");
private static final ClipboardFormat SCHEM = ClipboardFormats.findByAlias("schem");
@Override
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
ClipboardHolder clipboardHolder;
try {
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
} catch (EmptyClipboardException e) {
throw new NoClipboardException();
}
Clipboard clipboard = clipboardHolder.getClipboard();
if(clipboard == null)
throw new NoClipboardException();
PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream inputStream;
try {
inputStream = new PipedInputStream(outputStream, 4096);
}catch(NullPointerException e){
throw new RuntimeException(e.getMessage(), new IOException(e));
} catch (IOException e) {
throw new SecurityException("Could not init piped input stream", e);
}
new Thread(() -> {
try{
if(schemFormat){
ClipboardWriter writer = SCHEM.getWriter(outputStream);
writer.write(clipboard);
writer.close();
}else{
SCHEMATIC.getWriter(outputStream).write(clipboard);
}
}catch(NullPointerException | IOException e) {
Core.getInstance().getLogger().log(Level.SEVERE, "Could not write schematic", e);
}
try {
outputStream.close();
} catch (IOException e) {
Core.getInstance().getLogger().log(Level.SEVERE, "Could not close schem writer", e);
}
}, "SchemWriter").start();
return inputStream;
}
@Override
public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) {
Clipboard clipboard = null;
try {
clipboard = getClipboard(is, schemFormat);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (clipboard == null)
throw new NoClipboardException();
Actor actor = WorldEditWrapper.getWorldEditPlugin().wrapCommandSender(player);
WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard));
}
@Override
public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
try {
if(schemFormat){
return new SpongeSchematicReader(new NBTInputStream(is)).read();
}else{
return new MCEditSchematicReader(new NBTInputStream(is)).read();
}
} catch (NullPointerException e) {
throw new NoClipboardException();
}
}
private static class MCEditSchematicReader extends NBTSchematicReader {
private final NBTInputStream inputStream;
private final DataFixer fixer;
private boolean faweSchem = false;
private static final ImmutableList<NBTCompatibilityHandler> COMPATIBILITY_HANDLERS
= ImmutableList.of(
new SignCompatibilityHandler(),
new FlowerPotCompatibilityHandler(),
new NoteBlockCompatibilityHandler(),
new SkullBlockCompatibilityHandler()
);
/**
* Create a new instance.
*
* @param inputStream the input stream to read from
*/
MCEditSchematicReader(NBTInputStream inputStream) {
checkNotNull(inputStream);
this.inputStream = inputStream;
this.fixer = null;
}
@Override
public Clipboard read() throws IOException {
// Schematic tag
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
Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Blocks")) {
throw new IOException("Schematic file is missing a 'Blocks' tag");
}
// Check type of Schematic
String materials = requireTag(schematic, "Materials", StringTag.class).getValue();
if (!materials.equals("Alpha")) {
throw new IOException("Schematic file is not an Alpha schematic");
}
// ====================================================================
// Metadata
// ====================================================================
BlockVector3 origin;
Region region;
// Get information
short width = requireTag(schematic, "Width", ShortTag.class).getValue();
short height = requireTag(schematic, "Height", ShortTag.class).getValue();
short length = requireTag(schematic, "Length", ShortTag.class).getValue();
int originX = 0;
int originY = 0;
int originZ = 0;
try {
originX = requireTag(schematic, "WEOriginX", IntTag.class).getValue();
originY = requireTag(schematic, "WEOriginY", IntTag.class).getValue();
originZ = requireTag(schematic, "WEOriginZ", IntTag.class).getValue();
BlockVector3 min = BlockVector3.at(originX, originY, originZ);
int offsetX = requireTag(schematic, "WEOffsetX", IntTag.class).getValue();
int offsetY = requireTag(schematic, "WEOffsetY", IntTag.class).getValue();
int offsetZ = requireTag(schematic, "WEOffsetZ", IntTag.class).getValue();
BlockVector3 offset = BlockVector3.at(offsetX, offsetY, offsetZ);
origin = min.subtract(offset);
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
} catch (IOException ignored) {
origin = BlockVector3.ZERO;
region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
}
// ====================================================================
// Blocks
// ====================================================================
// Get blocks
byte[] blockId = requireTag(schematic, "Blocks", ByteArrayTag.class).getValue();
byte[] blockData = requireTag(schematic, "Data", ByteArrayTag.class).getValue();
byte[] addId = new byte[0];
short[] blocks = new short[blockId.length]; // Have to later combine IDs
// We support 4096 block IDs using the same method as vanilla Minecraft, where
// the highest 4 bits are stored in a separate byte array.
if (schematic.containsKey("AddBlocks")) {
addId = requireTag(schematic, "AddBlocks", ByteArrayTag.class).getValue();
}
// Combine the AddBlocks data with the first 8-bit block ID
for (int index = 0; index < blockId.length; index++) {
if ((index >> 1) >= addId.length) { // No corresponding AddBlocks index
blocks[index] = (short) (blockId[index] & 0xFF);
} else {
if ((index & 1) == 0) {
blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF));
} else {
blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF));
}
}
}
// Need to pull out tile entities
final ListTag tileEntityTag = getTag(schematic, "TileEntities", ListTag.class);
List<Tag> tileEntities = tileEntityTag == null ? new ArrayList<>() : tileEntityTag.getValue();
Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
Map<BlockVector3, BlockState> blockStates = new HashMap<>();
for (Tag tag : tileEntities) {
if (!(tag instanceof CompoundTag)) continue;
CompoundTag t = (CompoundTag) tag;
int x = t.getInt("x");
int y = t.getInt("y");
int z = t.getInt("z");
int index = y * width * length + z * width + x;
if(index < 0 || index >= blocks.length)
faweSchem = true;
}
for (Tag tag : tileEntities) {
if (!(tag instanceof CompoundTag)) continue;
CompoundTag t = (CompoundTag) tag;
Map<String, Tag> values = new HashMap<>(t.getValue());
String id = t.getString("id");
values.put("id", new StringTag(convertBlockEntityId(id)));
int x = t.getInt("x");
int y = t.getInt("y");
int z = t.getInt("z");
if(faweSchem){
x -= originX;
y -= originY;
z -= originZ;
}
int index = y * width * length + z * width + x;
try{
BlockState block = getBlockState(blocks[index], blockData[index]);
BlockState newBlock = block;
if (newBlock != null) {
for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) {
if (handler.isAffectedBlock(newBlock)) {
newBlock = handler.updateNBT(block, values);
if (newBlock == null || values.isEmpty()) {
break;
}
}
}
}
if (values.isEmpty()) {
t = null;
} else {
t = new CompoundTag(values);
}
if (fixer != null && t != null) {
t = fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, t, -1);
}
BlockVector3 vec = BlockVector3.at(x, y, z);
if (t != null) {
tileEntitiesMap.put(vec, t.getValue());
}
blockStates.put(vec, newBlock);
}catch(ArrayIndexOutOfBoundsException e){
//ignored
}
}
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
clipboard.setOrigin(origin);
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x;
BlockVector3 pt = BlockVector3.at(x, y, z);
BlockState state = blockStates.computeIfAbsent(pt, p -> getBlockState(blocks[index], blockData[index]));
try {
if (state != null) {
if (tileEntitiesMap.containsKey(pt)) {
clipboard.setBlock(region.getMinimumPoint().add(pt), state.toBaseBlock(new CompoundTag(tileEntitiesMap.get(pt))));
} else {
clipboard.setBlock(region.getMinimumPoint().add(pt), state);
}
}
} catch (WorldEditException ignored) { // BlockArrayClipboard won't throw this
}
}
}
}
return clipboard;
}
private String convertBlockEntityId(String id) {
switch (id) {
case "Cauldron":
return "brewing_stand";
case "Control":
return "command_block";
case "DLDetector":
return "daylight_detector";
case "Trap":
return "dispenser";
case "EnchantTable":
return "enchanting_table";
case "EndGateway":
return "end_gateway";
case "AirPortal":
return "end_portal";
case "EnderChest":
return "ender_chest";
case "FlowerPot":
return "flower_pot";
case "RecordPlayer":
return "jukebox";
case "MobSpawner":
return "mob_spawner";
case "Music":
case "noteblock":
return "note_block";
case "Structure":
return "structure_block";
case "Chest":
return "chest";
case "Sign":
return "sign";
case "Banner":
return "banner";
case "Beacon":
return "beacon";
case "Comparator":
return "comparator";
case "Dropper":
return "dropper";
case "Furnace":
return "furnace";
case "Hopper":
return "hopper";
case "Skull":
return "skull";
default:
return id;
}
}
private BlockState getBlockState(int id, int data) {
return LegacyMapper.getInstance().getBlockFromLegacy(id, data);
}
@Override
public void close() throws IOException {
inputStream.close();
}
}
private static class SpongeSchematicReader extends NBTSchematicReader {
private final NBTInputStream inputStream;
private DataFixer fixer = null;
private int schematicVersion = -1;
private int dataVersion = -1;
private boolean faweSchem = false;
/**
* Create a new instance.
*
* @param inputStream the input stream to read from
*/
public SpongeSchematicReader(NBTInputStream inputStream) {
checkNotNull(inputStream);
this.inputStream = inputStream;
}
@Override
public Clipboard read() throws IOException {
CompoundTag schematicTag = getBaseTag();
Map<String, Tag> schematic = schematicTag.getValue();
final Platform platform = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.WORLD_EDITING);
int liveDataVersion = platform.getDataVersion();
if (schematicVersion == 1) {
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) {
dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue();
if (dataVersion < liveDataVersion) {
fixer = platform.getDataFixer();
}
return readVersion1(schematicTag);
}
throw new IOException("This schematic version is currently not supported");
}
@Override
public OptionalInt getDataVersion() {
try {
CompoundTag schematicTag = getBaseTag();
Map<String, Tag> schematic = schematicTag.getValue();
if (schematicVersion == 1) {
return OptionalInt.of(1631);
} else if (schematicVersion == 2) {
return OptionalInt.of(requireTag(schematic, "DataVersion", IntTag.class).getValue());
}
return OptionalInt.empty();
} catch (IOException e) {
return OptionalInt.empty();
}
}
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
Map<String, Tag> schematic = schematicTag.getValue();
schematicVersion = requireTag(schematic, "Version", IntTag.class).getValue();
return schematicTag;
}
private BlockArrayClipboard readVersion1(CompoundTag schematicTag) throws IOException {
BlockVector3 origin;
Region region;
Map<String, Tag> schematic = schematicTag.getValue();
int width = requireTag(schematic, "Width", ShortTag.class).getValue();
int height = requireTag(schematic, "Height", ShortTag.class).getValue();
int length = requireTag(schematic, "Length", ShortTag.class).getValue();
IntArrayTag offsetTag = getTag(schematic, "Offset", IntArrayTag.class);
int[] offsetParts;
if (offsetTag != null) {
offsetParts = offsetTag.getValue();
if (offsetParts.length != 3) {
throw new IOException("Invalid offset specified in schematic.");
}
} else {
offsetParts = new int[] {0, 0, 0};
}
BlockVector3 min = BlockVector3.at(offsetParts[0], offsetParts[1], offsetParts[2]);
CompoundTag metadataTag = getTag(schematic, "Metadata", CompoundTag.class);
int offsetX = 0;
int offsetY = 0;
int offsetZ = 0;
if (metadataTag != null && metadataTag.containsKey("WEOffsetX")) {
// We appear to have WorldEdit Metadata
Map<String, Tag> metadata = metadataTag.getValue();
offsetX = requireTag(metadata, "WEOffsetX", IntTag.class).getValue();
offsetY = requireTag(metadata, "WEOffsetY", IntTag.class).getValue();
offsetZ = requireTag(metadata, "WEOffsetZ", IntTag.class).getValue();
BlockVector3 offset = BlockVector3.at(offsetX, offsetY, offsetZ);
origin = min.subtract(offset);
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
} else {
origin = min;
region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
}
IntTag paletteMaxTag = getTag(schematic, "PaletteMax", IntTag.class);
Map<String, Tag> 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<Integer, BlockState> palette = new HashMap<>();
ParserContext parserContext = new ParserContext();
parserContext.setRestricted(false);
parserContext.setTryLegacy(false);
parserContext.setPreferringWildcard(false);
for (String palettePart : paletteObject.keySet()) {
int id = requireTag(paletteObject, palettePart, IntTag.class).getValue();
if (fixer != null) {
palettePart = fixer.fixUp(DataFixer.FixTypes.BLOCK_STATE, palettePart, dataVersion);
}
BlockState state;
try {
state = WorldEdit.getInstance().getBlockFactory().parseFromInput(palettePart, parserContext).toImmutableState();
} catch (InputParseException e) {
state = BlockTypes.AIR.getDefaultState();
}
palette.put(id, state);
}
byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue();
Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
ListTag tileEntities = getTag(schematic, "BlockEntities", ListTag.class);
if (tileEntities == null) {
tileEntities = getTag(schematic, "TileEntities", ListTag.class);
}
if (tileEntities != null) {
List<Map<String, Tag>> tileEntityTags = tileEntities.getValue().stream()
.map(tag -> (CompoundTag) tag)
.map(CompoundTag::getValue)
.collect(Collectors.toList());
for (Map<String, Tag> tileEntity : tileEntityTags) {
int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
if(pos[0] < 0 || pos[0] >= width || pos[1] < 0 || pos[1] >= height || pos[2] < 0 || pos[2] >= length)
faweSchem = true;
}
for (Map<String, Tag> tileEntity : tileEntityTags) {
int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
final BlockVector3 pt = BlockVector3.at(pos[0], pos[1], pos[2]);
Map<String, Tag> values = Maps.newHashMap(tileEntity);
if(faweSchem){
values.put("x", new IntTag(pt.getBlockX() - offsetX));
values.put("y", new IntTag(pt.getBlockY() - offsetY));
values.put("z", new IntTag(pt.getBlockZ() - offsetZ));
}else{
values.put("x", new IntTag(pt.getBlockX()));
values.put("y", new IntTag(pt.getBlockY()));
values.put("z", new IntTag(pt.getBlockZ()));
}
values.put("id", values.get("Id"));
values.remove("Id");
values.remove("Pos");
if (fixer != null) {
tileEntity = fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values), dataVersion).getValue();
} else {
tileEntity = values;
}
tileEntitiesMap.put(pt, tileEntity);
}
}
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
clipboard.setOrigin(origin);
int index = 0;
int i = 0;
int value;
int varintLength;
while (i < blocks.length) {
value = 0;
varintLength = 0;
while (true) {
value |= (blocks[i] & 127) << (varintLength++ * 7);
if (varintLength > 5) {
throw new IOException("VarInt too big (probably corrupted data)");
}
if ((blocks[i] & 128) != 128) {
i++;
break;
}
i++;
}
// index = (y * length * width) + (z * width) + x
int y = index / (width * length);
int z = (index % (width * length)) / width;
int x = (index % (width * length)) % width;
BlockState state = palette.get(value);
BlockVector3 pt = BlockVector3.at(x, y, z);
try {
if (tileEntitiesMap.containsKey(pt)) {
clipboard.setBlock(clipboard.getMinimumPoint().add(pt), state.toBaseBlock(new CompoundTag(tileEntitiesMap.get(pt))));
} else {
clipboard.setBlock(clipboard.getMinimumPoint().add(pt), state);
}
} catch (WorldEditException e) {
throw new IOException("Failed to load a block in the schematic");
}
index++;
}
return clipboard;
}
@Override
public void close() throws IOException {
inputStream.close();
}
}
}
@@ -0,0 +1,73 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.techhider;
import com.comphenix.tinyprotocol.Reflection;
import com.google.common.collect.ImmutableList;
import org.bukkit.Material;
import java.util.HashSet;
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 Reflection.MethodInvoker 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 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);
@Override
public Set<Integer> materialToAllIds(Material material) {
Set<Integer> ids = new HashSet<>();
for(Object data : (ImmutableList<?>) getStateList.invoke(getStates.invoke(getBlock(material)))) {
ids.add(getCombinedId(data));
}
if(material == Material.WATER) {
for(Object data : registryBlockId) {
if(getFluid.invoke(data) == water) {
ids.add(getCombinedId(data));
}
}
}
return ids;
}
private static final Reflection.MethodInvoker 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 int getCombinedId(Object blockData) {
return (int) getCombinedId.invoke(null, blockData);
}
}
@@ -0,0 +1,42 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.techhider;
import io.netty.buffer.ByteBuf;
import java.util.Collections;
import java.util.Set;
public class ChunkHider14 extends ChunkHider9 {
@Override
protected void dataHider(PosEvaluator locationEvaluator, int obfuscationTarget, Set<Integer> obfuscate, ByteBuf in, ByteBuf out, boolean skip, boolean blockPrecise) {
out.writeShort(in.readShort()); // Block count
byte bitsPerBlock = in.readByte();
out.writeByte(bitsPerBlock);
if(bitsPerBlock < 9) {
obfuscationTarget = ChunkHider.processPalette(obfuscationTarget, obfuscate, in, out);
obfuscate = Collections.emptySet();
}
processDataArray(locationEvaluator, obfuscationTarget, obfuscate, in, out, bitsPerBlock, skip || (!blockPrecise && bitsPerBlock < 9));
}
}
@@ -0,0 +1,52 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.techhider;
import com.comphenix.tinyprotocol.Reflection;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.UnaryOperator;
public class ProtocolWrapper14 extends ProtocolWrapper8 {
@Override
public BiFunction<Player, Object, Object> blockBreakHiderGenerator(Class<?> blockBreakPacket, Object obfuscationTarget, Set<Material> obfuscate, TechHider.LocationEvaluator locationEvaluator) {
UnaryOperator<Object> blockBreakCloner = ProtocolUtils.shallowCloneGenerator(blockBreakPacket);
Reflection.FieldAccessor<?> blockBreakPosition = Reflection.getField(blockBreakPacket, TechHider.blockPosition, 0);
Reflection.FieldAccessor<?> blockBreakBlockData = Reflection.getField(blockBreakPacket, TechHider.iBlockData, 0);
return (p, packet) -> {
switch (locationEvaluator.checkBlockPos(p, blockBreakPosition.get(packet))) {
case SKIP:
return packet;
case CHECK:
if(!TechHider.iBlockDataHidden(obfuscate, blockBreakBlockData.get(packet)))
return packet;
default:
packet = blockBreakCloner.apply(packet);
blockBreakBlockData.set(packet, obfuscationTarget);
return packet;
}
};
}
}