diff --git a/paper-server/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/paper-server/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java index 77a75fba915e..8d2406e388a7 100644 --- a/paper-server/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java +++ b/paper-server/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java @@ -373,75 +373,20 @@ public class Obfuscation extends ConfigurationPart { public Items items = new Items(); public class Items extends ConfigurationPart { - public static Set> BASE_OVERRIDERS = Set.of( - DataComponents.MAX_STACK_SIZE, - DataComponents.MAX_DAMAGE, - DataComponents.DAMAGE, - DataComponents.UNBREAKABLE, - DataComponents.CUSTOM_NAME, - DataComponents.ITEM_NAME, - DataComponents.LORE, - DataComponents.RARITY, - DataComponents.ENCHANTMENTS, - DataComponents.CAN_PLACE_ON, - DataComponents.CAN_BREAK, - DataComponents.ATTRIBUTE_MODIFIERS, - DataComponents.HIDE_ADDITIONAL_TOOLTIP, - DataComponents.HIDE_TOOLTIP, - DataComponents.REPAIR_COST, - DataComponents.USE_REMAINDER, - DataComponents.FOOD, - DataComponents.DAMAGE_RESISTANT, // Not important on the player - DataComponents.TOOL, - DataComponents.ENCHANTABLE, - DataComponents.REPAIRABLE, - DataComponents.GLIDER, - DataComponents.TOOLTIP_STYLE, - DataComponents.DEATH_PROTECTION, - DataComponents.STORED_ENCHANTMENTS, - DataComponents.MAP_ID, - DataComponents.POTION_CONTENTS, - DataComponents.SUSPICIOUS_STEW_EFFECTS, - DataComponents.WRITABLE_BOOK_CONTENT, - DataComponents.WRITTEN_BOOK_CONTENT, - DataComponents.CUSTOM_DATA, - DataComponents.ENTITY_DATA, - DataComponents.BUCKET_ENTITY_DATA, - DataComponents.BLOCK_ENTITY_DATA, - DataComponents.INSTRUMENT, - DataComponents.OMINOUS_BOTTLE_AMPLIFIER, - DataComponents.JUKEBOX_PLAYABLE, - DataComponents.LODESTONE_TRACKER, - DataComponents.FIREWORKS, - DataComponents.NOTE_BLOCK_SOUND, - DataComponents.BEES, - DataComponents.LOCK, - DataComponents.CONTAINER_LOOT - ); public boolean enableItemObfuscation = false; - public AssetObfuscationConfiguration allModels = new AssetObfuscationConfiguration(true, + public DataSanitizationUtil.AssetObfuscationConfiguration allModels = new DataSanitizationUtil.AssetObfuscationConfiguration(true, Set.of(DataComponents.LODESTONE_TRACKER), Set.of() ); - public Map modelOverrides = Map.of( - net.minecraft.world.item.Items.ELYTRA.components().get(DataComponents.ITEM_MODEL).toString(), new AssetObfuscationConfiguration(true, + public Map modelOverrides = Map.of( + net.minecraft.world.item.Items.ELYTRA.components().get(DataComponents.ITEM_MODEL).toString(), new DataSanitizationUtil.AssetObfuscationConfiguration(true, Set.of(DataComponents.DAMAGE), Set.of() ) ); - @ConfigSerializable - public record AssetObfuscationConfiguration(@Required boolean sanitizeCount, Set> dontObfuscate, Set> alsoObfuscate) { - public AssetObfuscationConfiguration(final boolean sanitizeCount, final @Nullable Set> dontObfuscate, final @Nullable Set> alsoObfuscate) { - this.sanitizeCount = sanitizeCount; - this.dontObfuscate = Objects.requireNonNullElse(dontObfuscate, Set.of()); - this.alsoObfuscate = Objects.requireNonNullElse(alsoObfuscate, Set.of()); - } - - } - @PostProcess public void computeOverridenTypes() { DataSanitizationUtil.compute(this); diff --git a/paper-server/src/main/java/io/papermc/paper/util/DataSanitizationUtil.java b/paper-server/src/main/java/io/papermc/paper/util/DataSanitizationUtil.java index a1b69b2a3f5c..f2a94e43fb39 100644 --- a/paper-server/src/main/java/io/papermc/paper/util/DataSanitizationUtil.java +++ b/paper-server/src/main/java/io/papermc/paper/util/DataSanitizationUtil.java @@ -2,12 +2,7 @@ import com.google.common.base.Preconditions; import io.papermc.paper.configuration.GlobalConfiguration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.UnaryOperator; @@ -18,12 +13,60 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.framework.qual.DefaultQualifier; +import org.spongepowered.configurate.objectmapping.*; +import org.spongepowered.configurate.objectmapping.meta.*; @DefaultQualifier(NonNull.class) public final class DataSanitizationUtil { static final ThreadLocal DATA_SANITIZER = ThreadLocal.withInitial(DataSanitizer::new); + static Set> BASE_OVERRIDERS = Set.of( + DataComponents.MAX_STACK_SIZE, + DataComponents.MAX_DAMAGE, + DataComponents.DAMAGE, + DataComponents.UNBREAKABLE, + DataComponents.CUSTOM_NAME, + DataComponents.ITEM_NAME, + DataComponents.LORE, + DataComponents.RARITY, + DataComponents.ENCHANTMENTS, + DataComponents.CAN_PLACE_ON, + DataComponents.CAN_BREAK, + DataComponents.ATTRIBUTE_MODIFIERS, + DataComponents.HIDE_ADDITIONAL_TOOLTIP, + DataComponents.HIDE_TOOLTIP, + DataComponents.REPAIR_COST, + DataComponents.USE_REMAINDER, + DataComponents.FOOD, + DataComponents.DAMAGE_RESISTANT, // Not important on the player + DataComponents.TOOL, + DataComponents.ENCHANTABLE, + DataComponents.REPAIRABLE, + DataComponents.GLIDER, + DataComponents.TOOLTIP_STYLE, + DataComponents.DEATH_PROTECTION, + DataComponents.STORED_ENCHANTMENTS, + DataComponents.MAP_ID, + DataComponents.POTION_CONTENTS, + DataComponents.SUSPICIOUS_STEW_EFFECTS, + DataComponents.WRITABLE_BOOK_CONTENT, + DataComponents.WRITTEN_BOOK_CONTENT, + DataComponents.CUSTOM_DATA, + DataComponents.ENTITY_DATA, + DataComponents.BUCKET_ENTITY_DATA, + DataComponents.BLOCK_ENTITY_DATA, + DataComponents.INSTRUMENT, + DataComponents.OMINOUS_BOTTLE_AMPLIFIER, + DataComponents.JUKEBOX_PLAYABLE, + DataComponents.LODESTONE_TRACKER, + DataComponents.FIREWORKS, + DataComponents.NOTE_BLOCK_SOUND, + DataComponents.BEES, + DataComponents.LOCK, + DataComponents.CONTAINER_LOOT + ); + static BoundObfuscationConfiguration BOUND_BASE = null; static Map BOUND_OVERRIDES = new HashMap<>(); // We need to have a special ignore item to indicate this item should not be obfuscated. @@ -33,7 +76,7 @@ public final class DataSanitizationUtil { public static void compute(GlobalConfiguration.Anticheat.Obfuscation.Items items) { // now bind them all BOUND_BASE = bind(items.allModels); - for (Map.Entry entry : items.modelOverrides.entrySet()) { + for (Map.Entry entry : items.modelOverrides.entrySet()) { BOUND_OVERRIDES.put(ResourceLocation.parse(entry.getKey()), bind(entry.getValue())); } BOUND_OVERRIDES.put(IGNORE_OBFUSCATION_ITEM, new BoundObfuscationConfiguration(false, Map.of())); @@ -63,8 +106,13 @@ record Sanitize(UnaryOperator sanitizer) implements MutationType { } } - public static BoundObfuscationConfiguration bind(GlobalConfiguration.Anticheat.Obfuscation.Items.AssetObfuscationConfiguration config) { - Set> base = new HashSet<>(GlobalConfiguration.Anticheat.Obfuscation.Items.BASE_OVERRIDERS); + @org.spongepowered.configurate.objectmapping.ConfigSerializable + public record AssetObfuscationConfiguration(@Required boolean sanitizeCount, Set> dontObfuscate, Set> alsoObfuscate) { + + } + + public static BoundObfuscationConfiguration bind(AssetObfuscationConfiguration config) { + Set> base = new HashSet<>(BASE_OVERRIDERS); base.addAll(config.alsoObfuscate()); base.removeAll(config.dontObfuscate());