diff --git a/api/pom.xml b/api/pom.xml index 85991288..5c7d9d19 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -1,30 +1,30 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - com.ruinscraft - panilla - 1.1 - + + com.ruinscraft + panilla + 1.1 + - panilla-api + panilla-api - - - org.bukkit - bukkit - 1.12.2-R0.1-SNAPSHOT - provided - - - - io.netty - netty-all - 4.1.24.Final - provided - - + + + org.bukkit + bukkit + 1.12.2-R0.1-SNAPSHOT + provided + + + + io.netty + netty-all + 4.1.24.Final + provided + + diff --git a/api/src/main/java/com/ruinscraft/panilla/api/EnchantmentCompat.java b/api/src/main/java/com/ruinscraft/panilla/api/EnchantmentCompat.java index 8a3be0e7..338b71a9 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/EnchantmentCompat.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/EnchantmentCompat.java @@ -2,82 +2,89 @@ public enum EnchantmentCompat { - AQUA_AFFINITY("minecraft:aqua_affinity", "WATER_WORKER", 6), - BANE_OF_ARTHROPODS("minecraft:bane_of_arthropods", "DAMAGE_ARTHROPODS", 18), - BINDING_CURSE("minecraft:binding_curse", "BINDING_CURSE", 10), - BLAST_PROTECTION("minecraft:blast_protection", "PROTECTION_EXPLOSIONS", 3), - CHANNELING("minecraft:channeling", "", 68), // 1.13 - DEPTH_STRIDER("minecraft:depth_strider", "DEPTH_STRIDER", 8), - EFFICIENCY("minecraft:efficiency", "DIG_SPEED", 32), - FEATHER_FALLING("minecraft:falling", "PROTECTION_FALL", 2), - FIRE_ASPECT("minecraft:fire_aspect", "FIRE_ASPECT", 20), - FIRE_PROTECTION("minecraft:fire_protection", "PROTECTION_FIRE", 1), - FLAME("minecraft:flame", "ARROW_FIRE", 50), - FORTUNE("minecraft:fortune", "LOOT_BONUS_BLOCKS", 35), - FROST_WALKER("minecraft:frost_walker", "FROST_WALKER", 9), - IMPALING("minecraft:impaling", "", 66), // 1.13 - INFINITY("minecraft:infinity", "ARROW_INFINITE", 51), - KNOCKBACK("minecraft:knockback", "KNOCKBACK", 19), - LOOTING("minecraft:looting", "LOOT_BONUS_MOBS", 21), - LOYALTY("minecraft:loyalty", "", 65), // 1.13 - LUCK_OF_THE_SEA("minecraft:luck_of_the_sea", "LUCK", 61), - LURE("minecraft:lure", "LURE", 62), - MENDING("minecraft:mending", "MENDING", 70), - POWER("minecraft:power", "ARROW_DAMAGE", 48), - PROJECTILE_PROTECTION("minecraft:projectile_protection", "PROTECTION_PROJECTILE", 4), - PROTECTION("minecraft:protection", "PROTECTION_ENVIRONMENTAL", 0), - PUNCH("minecraft:punch", "ARROW_KNOCKBACK", 49), - RESPIRATION("minecraft_respiration", "OXYGEN", 5), - RIPTIDE("minecraft:riptide", "", 67), // 1.13 - SHARPNESS("minecraft:sharpness", "DAMAGE_ALL", 16), - SILK_TOUCH("minecraft:silk_touch", "SILK_TOUCH", 33), - SMITE("minecraft:smite", "DAMAGE_UNDEAD", 17), - SWEEPING("minecraft:sweeping", "SWEEPING_EDGE", 22), - THORNS("minecraft:thorns", "THORNS", 7), - UNBREAKING("minecraft:unbreaking", "DURABILITY", 34), - VANISHING_CURSE("minecraft:vanishing_curse", "VANISHING_CURSE", 71); + AQUA_AFFINITY("minecraft:aqua_affinity", "WATER_WORKER", 6), + BANE_OF_ARTHROPODS("minecraft:bane_of_arthropods", "DAMAGE_ARTHROPODS", 18), + BINDING_CURSE("minecraft:binding_curse", "BINDING_CURSE", 10), + BLAST_PROTECTION("minecraft:blast_protection", "PROTECTION_EXPLOSIONS", 3), + CHANNELING("minecraft:channeling", "", 68), // 1.13 + DEPTH_STRIDER("minecraft:depth_strider", "DEPTH_STRIDER", 8), + EFFICIENCY("minecraft:efficiency", "DIG_SPEED", 32), + FEATHER_FALLING("minecraft:falling", "PROTECTION_FALL", 2), + FIRE_ASPECT("minecraft:fire_aspect", "FIRE_ASPECT", 20), + FIRE_PROTECTION("minecraft:fire_protection", "PROTECTION_FIRE", 1), + FLAME("minecraft:flame", "ARROW_FIRE", 50), + FORTUNE("minecraft:fortune", "LOOT_BONUS_BLOCKS", 35), + FROST_WALKER("minecraft:frost_walker", "FROST_WALKER", 9), + IMPALING("minecraft:impaling", "", 66), // 1.13 + INFINITY("minecraft:infinity", "ARROW_INFINITE", 51), + KNOCKBACK("minecraft:knockback", "KNOCKBACK", 19), + LOOTING("minecraft:looting", "LOOT_BONUS_MOBS", 21), + LOYALTY("minecraft:loyalty", "", 65), // 1.13 + LUCK_OF_THE_SEA("minecraft:luck_of_the_sea", "LUCK", 61), + LURE("minecraft:lure", "LURE", 62), + MENDING("minecraft:mending", "MENDING", 70), + POWER("minecraft:power", "ARROW_DAMAGE", 48), + PROJECTILE_PROTECTION("minecraft:projectile_protection", "PROTECTION_PROJECTILE", 4), + PROTECTION("minecraft:protection", "PROTECTION_ENVIRONMENTAL", 0), + PUNCH("minecraft:punch", "ARROW_KNOCKBACK", 49), + RESPIRATION("minecraft_respiration", "OXYGEN", 5), + RIPTIDE("minecraft:riptide", "", 67), // 1.13 + SHARPNESS("minecraft:sharpness", "DAMAGE_ALL", 16), + SILK_TOUCH("minecraft:silk_touch", "SILK_TOUCH", 33), + SMITE("minecraft:smite", "DAMAGE_UNDEAD", 17), + SWEEPING("minecraft:sweeping", "SWEEPING_EDGE", 22), + THORNS("minecraft:thorns", "THORNS", 7), + UNBREAKING("minecraft:unbreaking", "DURABILITY", 34), + VANISHING_CURSE("minecraft:vanishing_curse", "VANISHING_CURSE", 71), - public final String namedKey; - public final String legacyName; - public final int legacyId; + // 1.14 + MULTISHOT("minecraft:multishot", "", -1), + PIERCING("minecraft:piercing", "", -1), + QUICK_CHARGE("minecraft:quick_charge", "", -1); - private EnchantmentCompat(String namedKey, String legacyName, int legacyId) { - this.namedKey = namedKey; - this.legacyName = legacyName; - this.legacyId = legacyId; - } + public final String namedKey; + public final String legacyName; + public final int legacyId; - public static EnchantmentCompat getByNamedKey(String namedKey) { - for (EnchantmentCompat enchantmentCompat : EnchantmentCompat.values()) { - if (enchantmentCompat.namedKey.equals(namedKey)) { - return enchantmentCompat; - } - } + EnchantmentCompat(String namedKey, String legacyName, int legacyId) { + this.namedKey = namedKey; + this.legacyName = legacyName; + this.legacyId = legacyId; + } - return null; - } + public static EnchantmentCompat getByNamedKey(String namedKey) { + for (EnchantmentCompat enchantmentCompat : EnchantmentCompat.values()) { + if (enchantmentCompat.namedKey.equals(namedKey)) { + return enchantmentCompat; + } + } - public static EnchantmentCompat getByLegacyName(String legacyName) { - if (legacyName.isEmpty()) - return null; + return null; + } - for (EnchantmentCompat enchantmentCompat : EnchantmentCompat.values()) { - if (enchantmentCompat.legacyName.equals(legacyName)) { - return enchantmentCompat; - } - } + @Deprecated + public static EnchantmentCompat getByLegacyName(String legacyName) { + if (legacyName.isEmpty()) + return null; - return null; - } + for (EnchantmentCompat enchantmentCompat : EnchantmentCompat.values()) { + if (enchantmentCompat.legacyName.equals(legacyName)) { + return enchantmentCompat; + } + } - public static EnchantmentCompat getById(int legacyId) { - for (EnchantmentCompat enchantmentCompat : EnchantmentCompat.values()) { - if (enchantmentCompat.legacyId == legacyId) { - return enchantmentCompat; - } - } + return null; + } - return null; - } + @Deprecated + public static EnchantmentCompat getByLegacyId(int legacyId) { + for (EnchantmentCompat enchantmentCompat : EnchantmentCompat.values()) { + if (enchantmentCompat.legacyId == legacyId) { + return enchantmentCompat; + } + } + + return null; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/IContainerCleaner.java b/api/src/main/java/com/ruinscraft/panilla/api/IContainerCleaner.java index 5525a0a4..257c2e23 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/IContainerCleaner.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/IContainerCleaner.java @@ -4,6 +4,6 @@ public interface IContainerCleaner { - void clean(Player player); + void clean(Player player); } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/IProtocolConstants.java b/api/src/main/java/com/ruinscraft/panilla/api/IProtocolConstants.java index 235004ff..2513c06a 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/IProtocolConstants.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/IProtocolConstants.java @@ -2,59 +2,63 @@ /* * Minecraft Constants - * + * * Made up constants should be prefixed with NOT_PROTOCOL_ * and be a reasonable value which would prevent game-breaking things. */ public interface IProtocolConstants { - /* - * Values which could potentially change or have changed in previous versions of - * Minecraft - */ + /* + * Values which could potentially change or have changed in previous versions of + * Minecraft + */ - int maxPacketSizeBytes(); + int maxPacketSizeBytes(); - /* - * Default values that I don't expect to change in future versions of Minecraft - */ + /* + * Default values that I don't expect to change in future versions of Minecraft + */ - default int maxUsernameLength() { - return 16; - } + default int maxUsernameLength() { + return 16; + } - default int maxBookTitleLength() { - return 16; - } + default int maxBookTitleLength() { + return 16; + } - default int maxAnvilRenameChars() { - return 35; - } + default int maxAnvilRenameChars() { + return 35; + } - default int maxSignLineLength() { - return 48; - } + default int maxSignLineLength() { + return 48; + } - default int maxFireworksFlight() { - return 3; - } + default int maxFireworksFlight() { + return 3; + } - default int minFireworksFlight() { - return 1; - } + default int minFireworksFlight() { + return 1; + } - default int maxFireworksExplosions() { - return 8; - } - - default int maxSlimeSize() { - return 3; // large slime - } + default int maxFireworksExplosions() { + return 8; + } - /* Not protocol -- Reasonable values/assumptions */ + default int maxSlimeSize() { + return 3; // large slime + } - default int NOT_PROTOCOL_maxLoreLineLength() { - return 128; - } + /* Not protocol -- Reasonable values/assumptions */ + + default int NOT_PROTOCOL_maxLoreLineLength() { + return 128; + } + + default int NOT_PROTOCOL_maxLoreLines() { + return 64; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/PanillaLogger.java b/api/src/main/java/com/ruinscraft/panilla/api/PanillaLogger.java index 0d6bbd86..8a78b391 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/PanillaLogger.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/PanillaLogger.java @@ -1,8 +1,10 @@ package com.ruinscraft.panilla.api; -import java.io.File; -import java.io.IOException; - +import com.ruinscraft.panilla.api.config.PConfig; +import com.ruinscraft.panilla.api.exception.NbtNotPermittedException; +import com.ruinscraft.panilla.api.exception.OversizedPacketException; +import com.ruinscraft.panilla.api.exception.PacketException; +import com.ruinscraft.panilla.api.exception.SignLineLengthTooLongException; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.InvalidConfigurationException; @@ -11,90 +13,83 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import com.ruinscraft.panilla.api.config.PConfig; -import com.ruinscraft.panilla.api.exception.NbtNotPermittedException; -import com.ruinscraft.panilla.api.exception.OversizedPacketException; -import com.ruinscraft.panilla.api.exception.PacketException; -import com.ruinscraft.panilla.api.exception.SignLineLengthTooLongException; +import java.io.File; +import java.io.IOException; public class PanillaLogger { - private static final String CHAT_PERMISSION = "panilla.log.chat"; - - private final Plugin plugin; - private FileConfiguration locale; - - public PanillaLogger(Plugin plugin) { - this.plugin = plugin; - } + private static final String CHAT_PERMISSION = "panilla.log.chat"; - public void loadLocale(String localeFileName) throws IOException { - File file = new File(plugin.getDataFolder(), localeFileName); + private final Plugin plugin; + private FileConfiguration locale; - if (!file.exists()) { - file.getParentFile().mkdirs(); + public PanillaLogger(Plugin plugin) { + this.plugin = plugin; + } - if (plugin.getResource(localeFileName) == null) { - throw new IOException("Could not locate locale file: " + localeFileName); - } + public void loadLocale(String localeFileName) throws IOException { + File file = new File(plugin.getDataFolder(), localeFileName); - plugin.saveResource(localeFileName, false); - } + if (!file.exists()) { + file.getParentFile().mkdirs(); - locale = new YamlConfiguration(); + if (plugin.getResource(localeFileName) == null) { + throw new IOException("Could not locate locale file: " + localeFileName); + } - try { - locale.load(file); - } catch (InvalidConfigurationException e) { - throw new IOException(e.getMessage()); - } - } + plugin.saveResource(localeFileName, false); + } - public void warn(Player player, PacketException e, IProtocolConstants protocolConstants, PConfig config) { - if (locale == null) { - plugin.getLogger().warning("Locale is not loaded"); - return; - } + locale = new YamlConfiguration(); - String message = locale.getString("prefix"); + try { + locale.load(file); + } catch (InvalidConfigurationException e) { + throw new IOException(e.getMessage()); + } + } - if (e.isFrom()) { - message += String.format(locale.getString("packet-from-dropped"), player.getName(), e.getNmsClass()); - } else { - message += String.format(locale.getString("packet-to-dropped"), player.getName(), e.getNmsClass()); - } + public void warn(Player player, PacketException e, IProtocolConstants protocolConstants, PConfig config) { + if (locale == null) { + plugin.getLogger().warning("Locale is not loaded"); + return; + } - if (e instanceof OversizedPacketException) { - OversizedPacketException oversizedPacketException = (OversizedPacketException) e; + String message = locale.getString("prefix"); - message += " " + String.format(locale.getString("packet-dropped-reason-too-large"), - oversizedPacketException.getSizeBytes(), protocolConstants.maxPacketSizeBytes()); - } + if (e.isFrom()) { + message += String.format(locale.getString("packet-from-dropped"), player.getName(), e.getNmsClass()); + } else { + message += String.format(locale.getString("packet-to-dropped"), player.getName(), e.getNmsClass()); + } - else if (e instanceof NbtNotPermittedException) { - NbtNotPermittedException nbtNotPermittedException = (NbtNotPermittedException) e; + if (e instanceof OversizedPacketException) { + OversizedPacketException oversizedPacketException = (OversizedPacketException) e; - message += " " + String.format(locale.getString("packet-dropped-reason-invalid-nbt"), - nbtNotPermittedException.getTagName()); - } + message += " " + String.format(locale.getString("packet-dropped-reason-too-large"), + oversizedPacketException.getSizeBytes(), protocolConstants.maxPacketSizeBytes()); + } else if (e instanceof NbtNotPermittedException) { + NbtNotPermittedException nbtNotPermittedException = (NbtNotPermittedException) e; - else if (e instanceof SignLineLengthTooLongException) { - message += " " + locale.getString("packet-dropped-reason-sign-length"); - } + message += " " + String.format(locale.getString("packet-dropped-reason-invalid-nbt"), + nbtNotPermittedException.getTagName()); + } else if (e instanceof SignLineLengthTooLongException) { + message += " " + locale.getString("packet-dropped-reason-sign-length"); + } - message = ChatColor.translateAlternateColorCodes('&', message); + message = ChatColor.translateAlternateColorCodes('&', message); - if (config.chatLogging) { - for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { - if (onlinePlayer.hasPermission(CHAT_PERMISSION)) { - onlinePlayer.sendMessage(message); - } - } - } + if (config.chatLogging) { + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + if (onlinePlayer.hasPermission(CHAT_PERMISSION)) { + onlinePlayer.sendMessage(message); + } + } + } - if (config.consoleLogging) { - plugin.getLogger().info(message); - } - } + if (config.consoleLogging) { + plugin.getLogger().info(message); + } + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/config/PConfig.java b/api/src/main/java/com/ruinscraft/panilla/api/config/PConfig.java index 80cc9819..ebb3ea37 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/config/PConfig.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/config/PConfig.java @@ -5,11 +5,12 @@ public class PConfig { - // defaults - public String localeFile = "en_US.yml"; - public boolean consoleLogging = true; - public boolean chatLogging = false; - public PStrictness strictness = PStrictness.AVERAGE; - public List nbtWhitelist = new ArrayList<>(); + // defaults + public String localeFile = "en_US.yml"; + public boolean consoleLogging = true; + public boolean chatLogging = false; + public PStrictness strictness = PStrictness.AVERAGE; + public List nbtWhitelist = new ArrayList<>(); + public int maxNonMinecraftNbtKeys = 16; } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/config/PStrictness.java b/api/src/main/java/com/ruinscraft/panilla/api/config/PStrictness.java index 277cfc39..701722a2 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/config/PStrictness.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/config/PStrictness.java @@ -2,12 +2,12 @@ public enum PStrictness { - LENIENT(0), AVERAGE(1), STRICT(2); + LENIENT(0), AVERAGE(1), STRICT(2); - public final int lvl; + public final int lvl; - private PStrictness(int lvl) { - this.lvl = lvl; - } + PStrictness(int lvl) { + this.lvl = lvl; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/exception/NbtNotPermittedException.java b/api/src/main/java/com/ruinscraft/panilla/api/exception/NbtNotPermittedException.java index b3faa8e7..b9f5c829 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/exception/NbtNotPermittedException.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/exception/NbtNotPermittedException.java @@ -2,17 +2,17 @@ public class NbtNotPermittedException extends PacketException { - private static final long serialVersionUID = 4005240262520128653L; + private static final long serialVersionUID = 4005240262520128653L; - private final String tagName; + private final String tagName; - public NbtNotPermittedException(String nmsClass, boolean from, String tagName) { - super(nmsClass, from); - this.tagName = tagName; - } + public NbtNotPermittedException(String nmsClass, boolean from, String tagName) { + super(nmsClass, from); + this.tagName = tagName; + } - public String getTagName() { - return tagName; - } + public String getTagName() { + return tagName; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/exception/OversizedPacketException.java b/api/src/main/java/com/ruinscraft/panilla/api/exception/OversizedPacketException.java index b0ce6109..460ad862 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/exception/OversizedPacketException.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/exception/OversizedPacketException.java @@ -2,17 +2,17 @@ public class OversizedPacketException extends PacketException { - private static final long serialVersionUID = -4128984869675949399L; + private static final long serialVersionUID = -4128984869675949399L; - private final int sizeBytes; + private final int sizeBytes; - public OversizedPacketException(String nmsClass, boolean from, int sizeBytes) { - super(nmsClass, from); - this.sizeBytes = sizeBytes; - } + public OversizedPacketException(String nmsClass, boolean from, int sizeBytes) { + super(nmsClass, from); + this.sizeBytes = sizeBytes; + } - public int getSizeBytes() { - return sizeBytes; - } + public int getSizeBytes() { + return sizeBytes; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/exception/PacketException.java b/api/src/main/java/com/ruinscraft/panilla/api/exception/PacketException.java index 8266b3a7..f3acd0f9 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/exception/PacketException.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/exception/PacketException.java @@ -2,23 +2,23 @@ public class PacketException extends Exception { - private static final long serialVersionUID = 3839488734683711733L; + private static final long serialVersionUID = 3839488734683711733L; - private final String nmsClass; - private final boolean from; + private final String nmsClass; + private final boolean from; - public PacketException(String nmsClass, boolean from) { - this.nmsClass = nmsClass; - this.from = from; - } + public PacketException(String nmsClass, boolean from) { + this.nmsClass = nmsClass; + this.from = from; + } - public String getNmsClass() { - return nmsClass; - } + public String getNmsClass() { + return nmsClass; + } - // is from client - public boolean isFrom() { - return from; - } + // is from client + public boolean isFrom() { + return from; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/exception/SignLineLengthTooLongException.java b/api/src/main/java/com/ruinscraft/panilla/api/exception/SignLineLengthTooLongException.java index 48c7b42f..c28f56ce 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/exception/SignLineLengthTooLongException.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/exception/SignLineLengthTooLongException.java @@ -2,10 +2,10 @@ public class SignLineLengthTooLongException extends PacketException { - private static final long serialVersionUID = -4895566449016462848L; + private static final long serialVersionUID = -4895566449016462848L; - public SignLineLengthTooLongException(String nmsClass, boolean from) { - super(nmsClass, from); - } + public SignLineLengthTooLongException(String nmsClass, boolean from) { + super(nmsClass, from); + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/io/IPacketInspector.java b/api/src/main/java/com/ruinscraft/panilla/api/io/IPacketInspector.java index 787179f2..14c9624e 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/io/IPacketInspector.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/io/IPacketInspector.java @@ -7,26 +7,26 @@ public interface IPacketInspector { - /* all packets */ - void checkSize(Object _packet, boolean from) throws OversizedPacketException; + /* all packets */ + void checkSize(Object _packet, boolean from) throws OversizedPacketException; - /* inbound packets (client->server) */ - void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException; + /* inbound packets (client->server) */ + void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException; - void checkPacketPlayInUpdateSign(Object _packet) throws SignLineLengthTooLongException; + void checkPacketPlayInUpdateSign(Object _packet) throws SignLineLengthTooLongException; - /* outbound packets (server->client) */ - void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException; + /* outbound packets (server->client) */ + void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException; - default void checkPlayIn(Object _packet) throws PacketException { - checkSize(_packet, true); - checkPacketPlayInSetCreativeSlot(_packet); - checkPacketPlayInUpdateSign(_packet); - } + default void checkPlayIn(Object _packet) throws PacketException { + checkSize(_packet, true); + checkPacketPlayInSetCreativeSlot(_packet); + checkPacketPlayInUpdateSign(_packet); + } - default void checkPlayOut(Object _packet) throws PacketException { - checkSize(_packet, false); - checkPacketPlayOutSetSlot(_packet); - } + default void checkPlayOut(Object _packet) throws PacketException { + checkSize(_packet, false); + checkPacketPlayOutSetSlot(_packet); + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/io/IPlayerInjector.java b/api/src/main/java/com/ruinscraft/panilla/api/io/IPlayerInjector.java index 7930689a..387b2f2f 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/io/IPlayerInjector.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/io/IPlayerInjector.java @@ -4,12 +4,12 @@ public interface IPlayerInjector { - static String MINECRAFT_CHANNEL_DPLX = "packet_handler"; - static String PANILLA_CHANNEL_IN = "panilla_in"; - static String PANILLA_CHANNEL_OUT = "panilla_out"; + String MINECRAFT_CHANNEL_DPLX = "packet_handler"; + String PANILLA_CHANNEL_IN = "panilla_in"; + String PANILLA_CHANNEL_OUT = "panilla_out"; - void register(final Player player); + void register(final Player player); - void unregister(final Player player); + void unregister(final Player player); } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/io/PlayerInbound.java b/api/src/main/java/com/ruinscraft/panilla/api/io/PlayerInbound.java index 1f845861..40308c32 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/io/PlayerInbound.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/io/PlayerInbound.java @@ -1,49 +1,47 @@ package com.ruinscraft.panilla.api.io; -import org.bukkit.entity.Player; - import com.ruinscraft.panilla.api.IContainerCleaner; import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.PanillaLogger; import com.ruinscraft.panilla.api.config.PConfig; import com.ruinscraft.panilla.api.exception.PacketException; - import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; +import org.bukkit.entity.Player; public class PlayerInbound extends ChannelInboundHandlerAdapter { - private final Player player; - private final IPacketInspector packetInspector; - private final IContainerCleaner containerCleaner; - private final IProtocolConstants protocolConstants; - private final PConfig config; - private final PanillaLogger panillaLogger; - - public PlayerInbound(Player player, IPacketInspector packetInspector, IContainerCleaner containerCleaner, - IProtocolConstants protocolConstants, PConfig config, PanillaLogger panillaLogger) { - this.player = player; - this.packetInspector = packetInspector; - this.containerCleaner = containerCleaner; - this.protocolConstants = protocolConstants; - this.config = config; - this.panillaLogger = panillaLogger; - } - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - try { - packetInspector.checkPlayIn(msg); - } catch (PacketException e) { - containerCleaner.clean(player); - panillaLogger.warn(player, e, protocolConstants, config); - - return; // drop the packet - } catch (Exception e) { - e.printStackTrace(); - } - - super.channelRead(ctx, msg); - } + private final Player player; + private final IPacketInspector packetInspector; + private final IContainerCleaner containerCleaner; + private final IProtocolConstants protocolConstants; + private final PConfig config; + private final PanillaLogger panillaLogger; + + public PlayerInbound(Player player, IPacketInspector packetInspector, IContainerCleaner containerCleaner, + IProtocolConstants protocolConstants, PConfig config, PanillaLogger panillaLogger) { + this.player = player; + this.packetInspector = packetInspector; + this.containerCleaner = containerCleaner; + this.protocolConstants = protocolConstants; + this.config = config; + this.panillaLogger = panillaLogger; + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + try { + packetInspector.checkPlayIn(msg); + } catch (PacketException e) { + containerCleaner.clean(player); + panillaLogger.warn(player, e, protocolConstants, config); + + return; // drop the packet + } catch (Exception e) { + e.printStackTrace(); + } + + super.channelRead(ctx, msg); + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/io/PlayerOutbound.java b/api/src/main/java/com/ruinscraft/panilla/api/io/PlayerOutbound.java index 7ba32311..a1a7070f 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/io/PlayerOutbound.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/io/PlayerOutbound.java @@ -1,50 +1,48 @@ package com.ruinscraft.panilla.api.io; -import org.bukkit.entity.Player; - import com.ruinscraft.panilla.api.IContainerCleaner; import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.PanillaLogger; import com.ruinscraft.panilla.api.config.PConfig; import com.ruinscraft.panilla.api.exception.PacketException; - import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; +import org.bukkit.entity.Player; public class PlayerOutbound extends ChannelOutboundHandlerAdapter { - private final Player player; - private final IPacketInspector packetInspector; - private final IContainerCleaner containerCleaner; - private final IProtocolConstants protocolConstants; - private final PConfig config; - private final PanillaLogger panillaLogger; - - public PlayerOutbound(Player player, IPacketInspector packetInspector, IContainerCleaner containerCleaner, - IProtocolConstants protocolConstants, PConfig config, PanillaLogger panillaLogger) { - this.player = player; - this.packetInspector = packetInspector; - this.containerCleaner = containerCleaner; - this.protocolConstants = protocolConstants; - this.config = config; - this.panillaLogger = panillaLogger; - } - - @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { - try { - packetInspector.checkPlayOut(msg); - } catch (PacketException e) { - containerCleaner.clean(player); - panillaLogger.warn(player, e, protocolConstants, config); - - return; // drop the packet - } catch (Exception e) { - e.printStackTrace(); - } - - super.write(ctx, msg, promise); - } + private final Player player; + private final IPacketInspector packetInspector; + private final IContainerCleaner containerCleaner; + private final IProtocolConstants protocolConstants; + private final PConfig config; + private final PanillaLogger panillaLogger; + + public PlayerOutbound(Player player, IPacketInspector packetInspector, IContainerCleaner containerCleaner, + IProtocolConstants protocolConstants, PConfig config, PanillaLogger panillaLogger) { + this.player = player; + this.packetInspector = packetInspector; + this.containerCleaner = containerCleaner; + this.protocolConstants = protocolConstants; + this.config = config; + this.panillaLogger = panillaLogger; + } + + @Override + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + try { + packetInspector.checkPlayOut(msg); + } catch (PacketException e) { + containerCleaner.clean(player); + panillaLogger.warn(player, e, protocolConstants, config); + + return; // drop the packet + } catch (Exception e) { + e.printStackTrace(); + } + + super.write(ctx, msg, promise); + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/INbtTagCompound.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/INbtTagCompound.java index dbfa8bef..b74ed5f8 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/INbtTagCompound.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/INbtTagCompound.java @@ -4,20 +4,20 @@ public interface INbtTagCompound { - boolean hasKey(String key); + boolean hasKey(String key); - boolean hasKeyOfType(String key, NbtDataType nbtDataType); + boolean hasKeyOfType(String key, NbtDataType nbtDataType); - Set getKeys(); + Set getKeys(); - int getInt(String key); + int getInt(String key); - short getShort(String key); + short getShort(String key); - String getString(String key); + String getString(String key); - INbtTagList getList(String key, NbtDataType nbtDataType); + INbtTagList getList(String key, NbtDataType nbtDataType); - INbtTagCompound getCompound(String key); + INbtTagCompound getCompound(String key); } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/INbtTagList.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/INbtTagList.java index bb1c182c..ccacd664 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/INbtTagList.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/INbtTagList.java @@ -2,8 +2,8 @@ public interface INbtTagList { - INbtTagCompound get(int index); + INbtTagCompound get(int index); - int size(); + int size(); } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/NbtDataType.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/NbtDataType.java index 801578fc..01666bcf 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/NbtDataType.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/NbtDataType.java @@ -2,13 +2,13 @@ public enum NbtDataType { - END(0x0), BYTE(0x1), SHORT(0x2), INT(0x3), LONG(0x4), FLOAT(0x5), DOUBLE(0x6), BYTE_ARRAY(0x7), - STRING(0x8), LIST(0x9), COMPOUND(0xA), INT_ARRAY(0xB); + END(0x0), BYTE(0x1), SHORT(0x2), INT(0x3), LONG(0x4), FLOAT(0x5), DOUBLE(0x6), BYTE_ARRAY(0x7), + STRING(0x8), LIST(0x9), COMPOUND(0xA), INT_ARRAY(0xB); - public final int id; + public final int id; - NbtDataType(int id) { - this.id = id; - } + NbtDataType(int id) { + this.id = id; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck.java index f7a7f1f9..0a612ac4 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck.java @@ -7,28 +7,28 @@ public abstract class NbtCheck { - private final String name; - private final PStrictness tolerance; - private final String[] aliases; + private final String name; + private final PStrictness tolerance; + private final String[] aliases; - public NbtCheck(String name, PStrictness tolerance, String... aliases) { - this.name = name; - this.tolerance = tolerance; - this.aliases = aliases; - } + public NbtCheck(String name, PStrictness tolerance, String... aliases) { + this.name = name; + this.tolerance = tolerance; + this.aliases = aliases; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public PStrictness getTolerance() { - return tolerance; - } + public PStrictness getTolerance() { + return tolerance; + } - public String[] getAliases() { - return aliases; - } + public String[] getAliases() { + return aliases; + } - public abstract boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config); + public abstract boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config); } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_AttributeModifiers.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_AttributeModifiers.java index 41f93525..dcb3af83 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_AttributeModifiers.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_AttributeModifiers.java @@ -7,13 +7,13 @@ public class NbtCheck_AttributeModifiers extends NbtCheck { - public NbtCheck_AttributeModifiers() { - super("AttributeModifiers", PStrictness.AVERAGE); - } + public NbtCheck_AttributeModifiers() { + super("AttributeModifiers", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return false; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return false; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BlockEntityTag.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BlockEntityTag.java index 3c4fcaed..ebea4e79 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BlockEntityTag.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BlockEntityTag.java @@ -9,44 +9,44 @@ public class NbtCheck_BlockEntityTag extends NbtCheck { - public NbtCheck_BlockEntityTag() { - super("BlockEntityTag", PStrictness.LENIENT); - } - - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - INbtTagCompound blockEntityTag = tag.getCompound(getName()); - -// // locked chests -// if (strictness == PStrictness.STRICT && blockEntityTag.hasKey("Lock")) { -// return false; -// } - - // signs with text - if (blockEntityTag.hasKey("Text1") || blockEntityTag.hasKey("Text2") || blockEntityTag.hasKey("Text3") - || blockEntityTag.hasKey("Text4")) { - return false; - } - - if (blockEntityTag.hasKey("Items")) { - if (nmsItemClassName == null || !nmsItemClassName.equals("ItemShulkerBox")) { - return false; - } - - INbtTagList items = blockEntityTag.getList("Items", NbtDataType.COMPOUND); - - for (int i = 0; i < items.size(); i++) { - INbtTagCompound item = items.get(i); - - if (item.hasKey("tag")) { - String failedNbt = NbtChecks.checkAll(item.getCompound("tag"), nmsItemClassName, protocolConstants, config); - - if (failedNbt != null) return false; - } - } - } - - return true; - } + public NbtCheck_BlockEntityTag() { + super("BlockEntityTag", PStrictness.LENIENT); + } + + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + INbtTagCompound blockEntityTag = tag.getCompound(getName()); + + // locked chests + if (config.strictness == PStrictness.STRICT && blockEntityTag.hasKey("Lock")) { + return false; + } + + // signs with text + if (blockEntityTag.hasKey("Text1") || blockEntityTag.hasKey("Text2") || blockEntityTag.hasKey("Text3") + || blockEntityTag.hasKey("Text4")) { + return false; + } + + if (blockEntityTag.hasKey("Items")) { + if (nmsItemClassName == null || !nmsItemClassName.equals("ItemShulkerBox")) { + return false; + } + + INbtTagList items = blockEntityTag.getList("Items", NbtDataType.COMPOUND); + + for (int i = 0; i < items.size(); i++) { + INbtTagCompound item = items.get(i); + + if (item.hasKey("tag")) { + String failedNbt = NbtChecks.checkAll(item.getCompound("tag"), nmsItemClassName, protocolConstants, config); + + if (failedNbt != null) return false; + } + } + } + + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BlockStateTag.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BlockStateTag.java index 0c3354da..6a915ee5 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BlockStateTag.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BlockStateTag.java @@ -7,13 +7,14 @@ public class NbtCheck_BlockStateTag extends NbtCheck { - public NbtCheck_BlockStateTag() { - super("BlockStateTag", PStrictness.AVERAGE); - } + // introduced in 1.14 + public NbtCheck_BlockStateTag() { + super("BlockStateTag", PStrictness.STRICT); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return false; // TODO: test variations of BlockStateTag to see what is potentially malicious + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BucketVariantTag.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BucketVariantTag.java index 66ac03d5..b8663f69 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BucketVariantTag.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_BucketVariantTag.java @@ -7,13 +7,13 @@ public class NbtCheck_BucketVariantTag extends NbtCheck { - public NbtCheck_BucketVariantTag() { - super("BucketVariantTag", PStrictness.AVERAGE); - } + public NbtCheck_BucketVariantTag() { + super("BucketVariantTag", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CanDestroy.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CanDestroy.java index e69619f3..67cd7312 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CanDestroy.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CanDestroy.java @@ -7,13 +7,13 @@ public class NbtCheck_CanDestroy extends NbtCheck { - public NbtCheck_CanDestroy() { - super("CanDestroy", PStrictness.STRICT); - } + public NbtCheck_CanDestroy() { + super("CanDestroy", PStrictness.STRICT); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return false; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return false; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CanPlaceOn.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CanPlaceOn.java index 5f5359e8..e127af5a 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CanPlaceOn.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CanPlaceOn.java @@ -7,13 +7,13 @@ public class NbtCheck_CanPlaceOn extends NbtCheck { - public NbtCheck_CanPlaceOn() { - super("CanPlaceOn", PStrictness.STRICT); - } + public NbtCheck_CanPlaceOn() { + super("CanPlaceOn", PStrictness.STRICT); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return false; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return false; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomModelData.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomModelData.java new file mode 100644 index 00000000..bf366e06 --- /dev/null +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomModelData.java @@ -0,0 +1,20 @@ +package com.ruinscraft.panilla.api.nbt.checks; + +import com.ruinscraft.panilla.api.IProtocolConstants; +import com.ruinscraft.panilla.api.config.PConfig; +import com.ruinscraft.panilla.api.config.PStrictness; +import com.ruinscraft.panilla.api.nbt.INbtTagCompound; + +public class NbtCheck_CustomModelData extends NbtCheck { + + // introduced in 1.14 + public NbtCheck_CustomModelData() { + super("CustomModelData", PStrictness.AVERAGE); + } + + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return false; + } + +} diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomPotionColor.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomPotionColor.java index a68ae773..0420a31c 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomPotionColor.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomPotionColor.java @@ -1,29 +1,28 @@ package com.ruinscraft.panilla.api.nbt.checks; -import org.bukkit.Color; - import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.config.PConfig; import com.ruinscraft.panilla.api.config.PStrictness; import com.ruinscraft.panilla.api.nbt.INbtTagCompound; +import org.bukkit.Color; public class NbtCheck_CustomPotionColor extends NbtCheck { - public NbtCheck_CustomPotionColor() { - super("CustomPotionColor", PStrictness.LENIENT); - } + public NbtCheck_CustomPotionColor() { + super("CustomPotionColor", PStrictness.LENIENT); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - int bgr = tag.getInt(getName()); + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + int bgr = tag.getInt(getName()); - try { - Color.fromBGR(bgr); - } catch (IllegalArgumentException e) { - return false; - } + try { + Color.fromBGR(bgr); + } catch (IllegalArgumentException e) { + return false; + } - return true; - } + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomPotionEffects.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomPotionEffects.java index 8aee51fd..6546fd8a 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomPotionEffects.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_CustomPotionEffects.java @@ -7,13 +7,13 @@ public class NbtCheck_CustomPotionEffects extends NbtCheck { - public NbtCheck_CustomPotionEffects() { - super("CustomPotionEffects", PStrictness.AVERAGE); - } + public NbtCheck_CustomPotionEffects() { + super("CustomPotionEffects", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return false; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return false; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Decorations.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Decorations.java index 22839421..613643cc 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Decorations.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Decorations.java @@ -7,13 +7,13 @@ public class NbtCheck_Decorations extends NbtCheck { - public NbtCheck_Decorations() { - super("Decorations", PStrictness.AVERAGE); - } + public NbtCheck_Decorations() { + super("Decorations", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Effects.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Effects.java index 9c995606..df6b1785 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Effects.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Effects.java @@ -7,13 +7,13 @@ public class NbtCheck_Effects extends NbtCheck { - public NbtCheck_Effects() { - super("Effects", PStrictness.AVERAGE); - } + public NbtCheck_Effects() { + super("Effects", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Enchantments.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Enchantments.java index 3417afed..3251b6be 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Enchantments.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Enchantments.java @@ -2,9 +2,9 @@ public class NbtCheck_Enchantments extends NbtCheck_ench { - @Override - public String getName() { - return "Enchantments"; - } + @Override + public String getName() { + return "Enchantments"; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_EntityTag.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_EntityTag.java index a1a27962..811cfe83 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_EntityTag.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_EntityTag.java @@ -9,67 +9,67 @@ public class NbtCheck_EntityTag extends NbtCheck { - public NbtCheck_EntityTag() { - super("EntityTag", PStrictness.AVERAGE); - } - - private static final String[] ARMOR_STAND_TAGS = new String[] {"NoGravity", "ShowArms", "NoBasePlate", "Small", "Rotation", "Marker", "Pose", "Invisible"}; - - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - INbtTagCompound entityTag = tag.getCompound(getName()); - - if (config.strictness == PStrictness.STRICT) { - for (String armorStandTag : ARMOR_STAND_TAGS) { - if (entityTag.hasKey(armorStandTag)) return false; - } - } - - if (entityTag.hasKey("Invulnerable")) { - return false; - } - - if (entityTag.hasKey("Motion")) { - return false; - } - - if (entityTag.hasKey("Size")) { - if (entityTag.getInt("Size") > protocolConstants.maxSlimeSize()) { - return false; - } - } - - if (entityTag.hasKey("ArmorItems")) { - INbtTagList items = entityTag.getList("ArmorItems", NbtDataType.COMPOUND); - - if (!checkItems(items, nmsItemClassName, protocolConstants, config)) { - return false; - } - } - - if (entityTag.hasKey("HandItems")) { - INbtTagList items = entityTag.getList("HandItems", NbtDataType.COMPOUND); - - if (!checkItems(items, nmsItemClassName, protocolConstants, config)) { - return false; - } - } - - return true; - } - - private static boolean checkItems(INbtTagList items, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - for (int i = 0; i < items.size(); i++) { - INbtTagCompound item = items.get(i); - - if (item.hasKey("tag")) { - String failedNbt = NbtChecks.checkAll(item.getCompound("tag"), nmsItemClassName, protocolConstants, config); - - if (failedNbt != null) return false; - } - } - - return true; - } + public NbtCheck_EntityTag() { + super("EntityTag", PStrictness.AVERAGE); + } + + private static final String[] ARMOR_STAND_TAGS = new String[]{"NoGravity", "ShowArms", "NoBasePlate", "Small", "Rotation", "Marker", "Pose", "Invisible"}; + + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + INbtTagCompound entityTag = tag.getCompound(getName()); + + if (config.strictness == PStrictness.STRICT) { + for (String armorStandTag : ARMOR_STAND_TAGS) { + if (entityTag.hasKey(armorStandTag)) return false; + } + } + + if (entityTag.hasKey("Invulnerable")) { + return false; + } + + if (entityTag.hasKey("Motion")) { + return false; + } + + if (entityTag.hasKey("Size")) { + if (entityTag.getInt("Size") > protocolConstants.maxSlimeSize()) { + return false; + } + } + + if (entityTag.hasKey("ArmorItems")) { + INbtTagList items = entityTag.getList("ArmorItems", NbtDataType.COMPOUND); + + if (!checkItems(items, nmsItemClassName, protocolConstants, config)) { + return false; + } + } + + if (entityTag.hasKey("HandItems")) { + INbtTagList items = entityTag.getList("HandItems", NbtDataType.COMPOUND); + + if (!checkItems(items, nmsItemClassName, protocolConstants, config)) { + return false; + } + } + + return true; + } + + private static boolean checkItems(INbtTagList items, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + for (int i = 0; i < items.size(); i++) { + INbtTagCompound item = items.get(i); + + if (item.hasKey("tag")) { + String failedNbt = NbtChecks.checkAll(item.getCompound("tag"), nmsItemClassName, protocolConstants, config); + + if (failedNbt != null) return false; + } + } + + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Explosion.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Explosion.java index c1c34e23..27436e99 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Explosion.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Explosion.java @@ -7,13 +7,13 @@ public class NbtCheck_Explosion extends NbtCheck { - public NbtCheck_Explosion() { - super("Explosion", PStrictness.AVERAGE); - } + public NbtCheck_Explosion() { + super("Explosion", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Fireworks.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Fireworks.java index 3993363c..0857f2d1 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Fireworks.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Fireworks.java @@ -9,27 +9,27 @@ public class NbtCheck_Fireworks extends NbtCheck { - public NbtCheck_Fireworks() { - super("Fireworks", PStrictness.AVERAGE); - } + public NbtCheck_Fireworks() { + super("Fireworks", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - INbtTagCompound fireworks = tag.getCompound("Fireworks"); + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + INbtTagCompound fireworks = tag.getCompound("Fireworks"); - int flight = fireworks.getInt("Flight"); + int flight = fireworks.getInt("Flight"); - if (flight > protocolConstants.maxFireworksFlight() || flight < protocolConstants.minFireworksFlight()) { - return false; - } + if (flight > protocolConstants.maxFireworksFlight() || flight < protocolConstants.minFireworksFlight()) { + return false; + } - INbtTagList explosions = fireworks.getList("Explosions", NbtDataType.COMPOUND); + INbtTagList explosions = fireworks.getList("Explosions", NbtDataType.COMPOUND); - if (explosions != null && explosions.size() > protocolConstants.maxFireworksExplosions()) { - return false; - } + if (explosions != null && explosions.size() > protocolConstants.maxFireworksExplosions()) { + return false; + } - return true; - } + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_HideFlags.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_HideFlags.java index 283bc668..b725c01a 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_HideFlags.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_HideFlags.java @@ -7,13 +7,13 @@ public class NbtCheck_HideFlags extends NbtCheck { - public NbtCheck_HideFlags() { - super("HideFlags", PStrictness.AVERAGE); - } + public NbtCheck_HideFlags() { + super("HideFlags", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return false; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return false; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Potion.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Potion.java index 43b98ca7..145566ca 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Potion.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Potion.java @@ -7,13 +7,13 @@ public class NbtCheck_Potion extends NbtCheck { - public NbtCheck_Potion() { - super("Potion", PStrictness.AVERAGE); - } + public NbtCheck_Potion() { + super("Potion", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_RepairCost.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_RepairCost.java index 7100b8d7..67776486 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_RepairCost.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_RepairCost.java @@ -7,13 +7,13 @@ public class NbtCheck_RepairCost extends NbtCheck { - public NbtCheck_RepairCost() { - super("RepairCost", PStrictness.AVERAGE); - } + public NbtCheck_RepairCost() { + super("RepairCost", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_SkullOwner.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_SkullOwner.java index 63782658..96bdaacb 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_SkullOwner.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_SkullOwner.java @@ -7,13 +7,13 @@ public class NbtCheck_SkullOwner extends NbtCheck { - public NbtCheck_SkullOwner() { - super("SkullOwner", PStrictness.AVERAGE); - } + public NbtCheck_SkullOwner() { + super("SkullOwner", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_StoredEnchantments.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_StoredEnchantments.java index 4d15a181..0bdd8e3d 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_StoredEnchantments.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_StoredEnchantments.java @@ -2,9 +2,9 @@ public class NbtCheck_StoredEnchantments extends NbtCheck_ench { - @Override - public String getName() { - return "StoredEnchantments"; - } + @Override + public String getName() { + return "StoredEnchantments"; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Unbreakable.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Unbreakable.java index c8b40430..d20c7042 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Unbreakable.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_Unbreakable.java @@ -7,13 +7,13 @@ public class NbtCheck_Unbreakable extends NbtCheck { - public NbtCheck_Unbreakable() { - super("Unbreakable", PStrictness.LENIENT); - } + public NbtCheck_Unbreakable() { + super("Unbreakable", PStrictness.LENIENT); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return false; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return false; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_author.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_author.java index bd38a164..ba3f4652 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_author.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_author.java @@ -7,19 +7,19 @@ public class NbtCheck_author extends NbtCheck { - public NbtCheck_author() { - super("author", PStrictness.AVERAGE); - } + public NbtCheck_author() { + super("author", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - int authorLength = tag.getString("author").length(); + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + int authorLength = tag.getString("author").length(); - if (authorLength > protocolConstants.maxUsernameLength()) { - return false; - } + if (authorLength > protocolConstants.maxUsernameLength()) { + return false; + } - return true; - } + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_display.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_display.java index 0c0d5a4f..95fa39e1 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_display.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_display.java @@ -4,24 +4,32 @@ import com.ruinscraft.panilla.api.config.PConfig; import com.ruinscraft.panilla.api.config.PStrictness; import com.ruinscraft.panilla.api.nbt.INbtTagCompound; +import com.ruinscraft.panilla.api.nbt.INbtTagList; +import com.ruinscraft.panilla.api.nbt.NbtDataType; public class NbtCheck_display extends NbtCheck { - public NbtCheck_display() { - super("display", PStrictness.AVERAGE); - } + public NbtCheck_display() { + super("display", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - INbtTagCompound display = tag.getCompound(getName()); + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + INbtTagCompound display = tag.getCompound(getName()); - String name = display.getString("name"); + String name = display.getString("Name"); - if (name != null && name.length() > protocolConstants.maxAnvilRenameChars()) { - return false; - } + if (name != null && name.length() > protocolConstants.maxAnvilRenameChars()) { + return false; + } - return true; - } + INbtTagList lore = display.getList("Lore", NbtDataType.LIST); + + if (lore.size() > protocolConstants.NOT_PROTOCOL_maxLoreLines()) { + return false; + } + + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_ench.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_ench.java index 1b1226c9..5cf81d12 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_ench.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_ench.java @@ -1,8 +1,5 @@ package com.ruinscraft.panilla.api.nbt.checks; -import org.bukkit.NamespacedKey; -import org.bukkit.enchantments.Enchantment; - import com.ruinscraft.panilla.api.EnchantmentCompat; import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.config.PConfig; @@ -10,98 +7,98 @@ import com.ruinscraft.panilla.api.nbt.INbtTagCompound; import com.ruinscraft.panilla.api.nbt.INbtTagList; import com.ruinscraft.panilla.api.nbt.NbtDataType; +import org.bukkit.NamespacedKey; +import org.bukkit.enchantments.Enchantment; public class NbtCheck_ench extends NbtCheck { - public NbtCheck_ench() { - super("ench", PStrictness.AVERAGE, "Enchantments", "StoredEnchantments"); - } - - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - String using = null; - - if (tag.hasKey(getName())) { - using = getName(); - } else { - for (String alias : getAliases()) { - if (tag.hasKey(alias)) { - using = alias; - } - } - } - - INbtTagList enchantments = tag.getList(using, NbtDataType.COMPOUND); - - for (int i = 0; i < enchantments.size(); i++) { - INbtTagCompound enchantment = enchantments.get(i); - Enchantment bukkitEnchantment = getEnchantment(enchantment); - - if (bukkitEnchantment == null) { - continue; - } - - int lvl = 0xFFFF & enchantments.get(i).getShort("lvl"); - - if (lvl > bukkitEnchantment.getMaxLevel()) { - return false; - } - - if (lvl < bukkitEnchantment.getStartLevel()) { - return false; - } - - for (int j = 0; j < enchantments.size(); j++) { - INbtTagCompound otherEnchantment = enchantments.get(j); - Enchantment otherBukkitEnchantment = getEnchantment(otherEnchantment); - - if (bukkitEnchantment != otherBukkitEnchantment - && bukkitEnchantment.conflictsWith(otherBukkitEnchantment)) { - return false; - } - } - } - - return true; - } - - private static Enchantment getEnchantment(INbtTagCompound enchantment) { - if (enchantment.hasKeyOfType("id", NbtDataType.INT) || enchantment.hasKeyOfType("id", NbtDataType.SHORT)) { - final int id = enchantment.getInt("id"); - - try { - // 1.12 - return (Enchantment) Enchantment.class.getMethod("getById", int.class).invoke(null, id); - } catch (Exception e1) { - // 1.13 - try { - return (Enchantment) Enchantment.class.getMethod("getByName", String.class) - .invoke(null, EnchantmentCompat.getById(id).legacyName); - } catch (Exception e2) { - return null; - } - } - } - - else if (enchantment.hasKeyOfType("id", NbtDataType.STRING)) { - final String namedKey = enchantment.getString("id"); - - try { - // 1.13 - return (Enchantment) Enchantment.class.getMethod("getByKey", NamespacedKey.class) - .invoke(null, NamespacedKey.minecraft(namedKey)); - } catch (Exception e1) { - // 1.12 - try { - return (Enchantment) Enchantment.class.getMethod("getByName", String.class) - .invoke(null, EnchantmentCompat.getByNamedKey(namedKey).legacyName); - } catch (Exception e2) { - return null; - } - } - } - - return null; - } + public NbtCheck_ench() { + super("ench", PStrictness.AVERAGE, "Enchantments", "StoredEnchantments"); + } + + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + String using = null; + + if (tag.hasKey(getName())) { + using = getName(); + } else { + for (String alias : getAliases()) { + if (tag.hasKey(alias)) { + using = alias; + } + } + } + + INbtTagList enchantments = tag.getList(using, NbtDataType.COMPOUND); + + for (int i = 0; i < enchantments.size(); i++) { + INbtTagCompound enchantment = enchantments.get(i); + Enchantment bukkitEnchantment = getEnchantment(enchantment); + + if (bukkitEnchantment == null) { + continue; + } + + int lvl = 0xFFFF & enchantments.get(i).getShort("lvl"); + + if (lvl > bukkitEnchantment.getMaxLevel()) { + return false; + } + + if (lvl < bukkitEnchantment.getStartLevel()) { + return false; + } + + for (int j = 0; j < enchantments.size(); j++) { + INbtTagCompound otherEnchantment = enchantments.get(j); + Enchantment otherBukkitEnchantment = getEnchantment(otherEnchantment); + + if (bukkitEnchantment != otherBukkitEnchantment + && bukkitEnchantment.conflictsWith(otherBukkitEnchantment)) { + return false; + } + } + } + + return true; + } + + private static Enchantment getEnchantment(INbtTagCompound enchantment) { + if (enchantment.hasKeyOfType("id", NbtDataType.INT) || enchantment.hasKeyOfType("id", NbtDataType.SHORT)) { + final int id = enchantment.getInt("id"); + + try { + // 1.12 + return (Enchantment) Enchantment.class.getMethod("getById", int.class).invoke(null, id); + } catch (Exception e1) { + // 1.13 + try { + return (Enchantment) Enchantment.class.getMethod("getByName", String.class) + .invoke(null, EnchantmentCompat.getByLegacyId(id).legacyName); + } catch (Exception e2) { + return null; + } + } + } else if (enchantment.hasKeyOfType("id", NbtDataType.STRING)) { + final String namedKey = enchantment.getString("id"); + + try { + // 1.13 + return (Enchantment) Enchantment.class.getMethod("getByKey", NamespacedKey.class) + .invoke(null, NamespacedKey.minecraft(namedKey)); + } catch (Exception e1) { + // 1.12 + try { + return (Enchantment) Enchantment.class.getMethod("getByName", String.class) + .invoke(null, EnchantmentCompat.getByNamedKey(namedKey).legacyName); + } catch (Exception e2) { + return null; + } + } + } + + return null; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_generation.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_generation.java index e2c1c1d8..0090cfbc 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_generation.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_generation.java @@ -7,13 +7,13 @@ public class NbtCheck_generation extends NbtCheck { - public NbtCheck_generation() { - super("generation", PStrictness.AVERAGE); - } + public NbtCheck_generation() { + super("generation", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_map.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_map.java index 12181ce7..86475c3f 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_map.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_map.java @@ -7,13 +7,13 @@ public class NbtCheck_map extends NbtCheck { - public NbtCheck_map() { - super("map", PStrictness.AVERAGE); - } + public NbtCheck_map() { + super("map", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_map_scale_direction.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_map_scale_direction.java index ac09462c..aab77e86 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_map_scale_direction.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_map_scale_direction.java @@ -7,13 +7,13 @@ public class NbtCheck_map_scale_direction extends NbtCheck { - public NbtCheck_map_scale_direction() { - super("map_scale_direction", PStrictness.AVERAGE); - } + public NbtCheck_map_scale_direction() { + super("map_scale_direction", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_pages.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_pages.java index b00e2d0e..0841d520 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_pages.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_pages.java @@ -7,13 +7,13 @@ public class NbtCheck_pages extends NbtCheck { - public NbtCheck_pages() { - super("pages", PStrictness.AVERAGE); - } + public NbtCheck_pages() { + super("pages", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_resolved.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_resolved.java index b1c220e4..1b67b2d9 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_resolved.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_resolved.java @@ -7,13 +7,13 @@ public class NbtCheck_resolved extends NbtCheck { - public NbtCheck_resolved() { - super("resolved", PStrictness.AVERAGE); - } + public NbtCheck_resolved() { + super("resolved", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - return true; - } + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_title.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_title.java index f5de81aa..1425fb06 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_title.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtCheck_title.java @@ -7,19 +7,19 @@ public class NbtCheck_title extends NbtCheck { - public NbtCheck_title() { - super("title", PStrictness.AVERAGE); - } + public NbtCheck_title() { + super("title", PStrictness.AVERAGE); + } - @Override - public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { - int titleLength = tag.getString("title").length(); + @Override + public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) { + int titleLength = tag.getString("title").length(); - if (titleLength > protocolConstants.maxBookTitleLength()) { - return false; - } + if (titleLength > protocolConstants.maxBookTitleLength()) { + return false; + } - return true; - } + return true; + } } diff --git a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtChecks.java b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtChecks.java index cd15a437..b10c04ff 100644 --- a/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtChecks.java +++ b/api/src/main/java/com/ruinscraft/panilla/api/nbt/checks/NbtChecks.java @@ -1,116 +1,116 @@ package com.ruinscraft.panilla.api.nbt.checks; -import java.util.HashMap; -import java.util.Map; - import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.config.PConfig; import com.ruinscraft.panilla.api.exception.NbtNotPermittedException; import com.ruinscraft.panilla.api.nbt.INbtTagCompound; +import java.util.HashMap; +import java.util.Map; + public final class NbtChecks { - private static final int MAX_NON_MINECRAFT_KEYS = 16; - private static final Map checks = new HashMap<>(); - - static { - register(new NbtCheck_Unbreakable()); - register(new NbtCheck_CanDestroy()); - register(new NbtCheck_CanPlaceOn()); - register(new NbtCheck_BlockEntityTag()); - register(new NbtCheck_BlockStateTag()); - register(new NbtCheck_ench()); - register(new NbtCheck_Enchantments()); - register(new NbtCheck_StoredEnchantments()); - register(new NbtCheck_RepairCost()); - register(new NbtCheck_AttributeModifiers()); - register(new NbtCheck_CustomPotionEffects()); - register(new NbtCheck_Potion()); - register(new NbtCheck_CustomPotionColor()); - register(new NbtCheck_display()); - register(new NbtCheck_HideFlags()); - register(new NbtCheck_resolved()); - register(new NbtCheck_generation()); - register(new NbtCheck_author()); - register(new NbtCheck_title()); - register(new NbtCheck_pages()); - register(new NbtCheck_SkullOwner()); - register(new NbtCheck_Explosion()); - register(new NbtCheck_Fireworks()); - register(new NbtCheck_EntityTag()); - register(new NbtCheck_BucketVariantTag()); - register(new NbtCheck_map()); - register(new NbtCheck_map_scale_direction()); - register(new NbtCheck_Decorations()); - register(new NbtCheck_Effects()); - } - - public static void register(NbtCheck check) { - checks.put(check.getName(), check); - } - - public static NbtCheck get(String tag) { - return checks.get(tag); - } - - public static boolean exists(String tag) { - return checks.containsKey(tag); - } - - public static void checkPacketPlayIn(INbtTagCompound tag, String nmsItemClassName, String nmsPacketClassName, - IProtocolConstants protocolConstants, PConfig config) throws NbtNotPermittedException { - - String failedNbt = checkAll(tag, nmsItemClassName, protocolConstants, config); - - if (failedNbt != null) { - throw new NbtNotPermittedException(nmsPacketClassName, true, failedNbt); - } - } - - public static void checkPacketPlayOut(INbtTagCompound tag, String nmsItemClassName, String nmsPacketClassName, - IProtocolConstants protocolConstants, PConfig config) throws NbtNotPermittedException { - - String failedNbt = checkAll(tag, nmsItemClassName, protocolConstants, config); - - if (failedNbt != null) { - throw new NbtNotPermittedException(nmsPacketClassName, false, failedNbt); - } - } - - public static String checkAll(INbtTagCompound tag, String nmsItemClassName, - IProtocolConstants protocolConstants, PConfig config) { - int nonMinecraftKeys = 0; - - for (String key : tag.getKeys()) { - if (config.nbtWhitelist.contains(key)) { - continue; - } - - NbtCheck check = checks.get(key); - - if (check == null) { - nonMinecraftKeys++; - continue; - } - - if (check.getTolerance().lvl > config.strictness.lvl) { - continue; - } - - if (!check.check(tag, nmsItemClassName, protocolConstants, config)) { - return key; - } - } - - if (nonMinecraftKeys > MAX_NON_MINECRAFT_KEYS) { - for (String key : tag.getKeys()) { - if (checks.get(key) == null) { - return key; - } - } - } - - return null; - } + private static final Map checks = new HashMap<>(); + + static { + register(new NbtCheck_Unbreakable()); + register(new NbtCheck_CanDestroy()); + register(new NbtCheck_CanPlaceOn()); + register(new NbtCheck_BlockEntityTag()); + register(new NbtCheck_BlockStateTag()); + register(new NbtCheck_ench()); + register(new NbtCheck_Enchantments()); + register(new NbtCheck_StoredEnchantments()); + register(new NbtCheck_RepairCost()); + register(new NbtCheck_AttributeModifiers()); + register(new NbtCheck_CustomPotionEffects()); + register(new NbtCheck_Potion()); + register(new NbtCheck_CustomPotionColor()); + register(new NbtCheck_display()); + register(new NbtCheck_HideFlags()); + register(new NbtCheck_resolved()); + register(new NbtCheck_generation()); + register(new NbtCheck_author()); + register(new NbtCheck_title()); + register(new NbtCheck_pages()); + register(new NbtCheck_SkullOwner()); + register(new NbtCheck_Explosion()); + register(new NbtCheck_Fireworks()); + register(new NbtCheck_EntityTag()); + register(new NbtCheck_BucketVariantTag()); + register(new NbtCheck_map()); + register(new NbtCheck_map_scale_direction()); + register(new NbtCheck_Decorations()); + register(new NbtCheck_Effects()); + register(new NbtCheck_CustomModelData()); + } + + public static void register(NbtCheck check) { + checks.put(check.getName(), check); + } + + public static NbtCheck get(String tag) { + return checks.get(tag); + } + + public static boolean exists(String tag) { + return checks.containsKey(tag); + } + + public static void checkPacketPlayIn(INbtTagCompound tag, String nmsItemClassName, String nmsPacketClassName, + IProtocolConstants protocolConstants, PConfig config) throws NbtNotPermittedException { + + String failedNbt = checkAll(tag, nmsItemClassName, protocolConstants, config); + + if (failedNbt != null) { + throw new NbtNotPermittedException(nmsPacketClassName, true, failedNbt); + } + } + + public static void checkPacketPlayOut(INbtTagCompound tag, String nmsItemClassName, String nmsPacketClassName, + IProtocolConstants protocolConstants, PConfig config) throws NbtNotPermittedException { + + String failedNbt = checkAll(tag, nmsItemClassName, protocolConstants, config); + + if (failedNbt != null) { + throw new NbtNotPermittedException(nmsPacketClassName, false, failedNbt); + } + } + + public static String checkAll(INbtTagCompound tag, String nmsItemClassName, + IProtocolConstants protocolConstants, PConfig config) { + int nonMinecraftKeys = 0; + + for (String key : tag.getKeys()) { + if (config.nbtWhitelist.contains(key)) { + continue; + } + + NbtCheck check = checks.get(key); + + if (check == null) { + nonMinecraftKeys++; + continue; + } + + if (check.getTolerance().lvl > config.strictness.lvl) { + continue; + } + + if (!check.check(tag, nmsItemClassName, protocolConstants, config)) { + return key; + } + } + + if (nonMinecraftKeys > config.maxNonMinecraftNbtKeys) { + for (String key : tag.getKeys()) { + if (checks.get(key) == null) { + return key; + } + } + } + + return null; + } } diff --git a/plugin/pom.xml b/plugin/pom.xml index 11cdfccf..4edacfd7 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -1,83 +1,89 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - com.ruinscraft - panilla - 1.1 - + + com.ruinscraft + panilla + 1.1 + - panilla-plugin + panilla-plugin - Panilla + Panilla - - com.ruinscraft.panilla.plugin.PanillaPlugin - + + com.ruinscraft.panilla.plugin.PanillaPlugin + - - - org.bukkit - bukkit - 1.12.2-R0.1-SNAPSHOT - provided - - - com.ruinscraft - panilla-api - 1.1 - compile - - - com.ruinscraft - panilla-v1_12_R1 - 1.1 - compile - - - com.ruinscraft - panilla-v1_13_R2 - 1.1 - compile - - + + + org.bukkit + bukkit + 1.12.2-R0.1-SNAPSHOT + provided + + + com.ruinscraft + panilla-api + 1.1 + compile + + + com.ruinscraft + panilla-v1_12_R1 + 1.1 + compile + + + com.ruinscraft + panilla-v1_13_R2 + 1.1 + compile + + + com.ruinscraft + panilla-v1_14_R1 + 1.1 + compile + + - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.1 - - - package - - shade - - - - - - - - src/main/resources - true - - plugin.yml - - - - src/main/resources - false - - **/*.java - plugin.yml - - - - ${name} - + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.1 + + + package + + shade + + + + + + + + src/main/resources + true + + plugin.yml + + + + src/main/resources + false + + **/*.java + plugin.yml + + + + ${name} + diff --git a/plugin/src/main/java/com/ruinscraft/panilla/plugin/JoinQuitListener.java b/plugin/src/main/java/com/ruinscraft/panilla/plugin/JoinQuitListener.java index f889c334..e8bd13ab 100644 --- a/plugin/src/main/java/com/ruinscraft/panilla/plugin/JoinQuitListener.java +++ b/plugin/src/main/java/com/ruinscraft/panilla/plugin/JoinQuitListener.java @@ -8,18 +8,18 @@ public class JoinQuitListener implements Listener { - @EventHandler - public void onJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); + @EventHandler + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); - PanillaPlugin.get().getPlayerInjector().register(player); - } + PanillaPlugin.get().getPlayerInjector().register(player); + } - @EventHandler - public void onQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); + @EventHandler + public void onQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); - PanillaPlugin.get().getPlayerInjector().unregister(player); - } + PanillaPlugin.get().getPlayerInjector().unregister(player); + } } diff --git a/plugin/src/main/java/com/ruinscraft/panilla/plugin/PanillaCommand.java b/plugin/src/main/java/com/ruinscraft/panilla/plugin/PanillaCommand.java index 7cd5dcb6..1f267481 100644 --- a/plugin/src/main/java/com/ruinscraft/panilla/plugin/PanillaCommand.java +++ b/plugin/src/main/java/com/ruinscraft/panilla/plugin/PanillaCommand.java @@ -1,22 +1,22 @@ package com.ruinscraft.panilla.plugin; -import java.util.List; - import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import java.util.List; + public class PanillaCommand implements CommandExecutor { - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - final String version = PanillaPlugin.get().getDescription().getVersion(); - final List authors = PanillaPlugin.get().getDescription().getAuthors(); + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + final String version = PanillaPlugin.get().getDescription().getVersion(); + final List authors = PanillaPlugin.get().getDescription().getAuthors(); - sender.sendMessage(ChatColor.GOLD + "Running Panilla version: " + version + " by " + String.join(", ", authors)); + sender.sendMessage(ChatColor.GOLD + "Running Panilla version: " + version + " by " + String.join(", ", authors)); - return true; - } + return true; + } } diff --git a/plugin/src/main/java/com/ruinscraft/panilla/plugin/PanillaPlugin.java b/plugin/src/main/java/com/ruinscraft/panilla/plugin/PanillaPlugin.java index f00584ba..426241b3 100644 --- a/plugin/src/main/java/com/ruinscraft/panilla/plugin/PanillaPlugin.java +++ b/plugin/src/main/java/com/ruinscraft/panilla/plugin/PanillaPlugin.java @@ -1,11 +1,5 @@ package com.ruinscraft.panilla.plugin; -import java.io.IOException; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - import com.ruinscraft.panilla.api.IContainerCleaner; import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.PanillaLogger; @@ -13,120 +7,135 @@ import com.ruinscraft.panilla.api.config.PStrictness; import com.ruinscraft.panilla.api.io.IPacketInspector; import com.ruinscraft.panilla.api.io.IPlayerInjector; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.IOException; public class PanillaPlugin extends JavaPlugin { - private PConfig panillaConfig; - private IProtocolConstants protocolConstants; - private IContainerCleaner containerCleaner; - private IPacketInspector packetInspector; - private IPlayerInjector playerInjector; - - public PConfig getPanillaConfig() { - return panillaConfig; - } - - public IProtocolConstants getProtocolConstants() { - return protocolConstants; - } - - public IContainerCleaner getContainerCleaner() { - return containerCleaner; - } - - public IPacketInspector getPacketInspector() { - return packetInspector; - } - - public IPlayerInjector getPlayerInjector() { - return playerInjector; - } - - private synchronized void loadConfig() { - saveDefaultConfig(); - - panillaConfig = new PConfig(); - - panillaConfig.localeFile = getConfig().getString("locale-file"); - panillaConfig.consoleLogging = getConfig().getBoolean("logging.console"); - panillaConfig.chatLogging = getConfig().getBoolean("logging.chat"); - panillaConfig.strictness = PStrictness.valueOf(getConfig().getString("strictness").toUpperCase()); - panillaConfig.nbtWhitelist = getConfig().getStringList("nbt-whitelist"); - } - - private String v_Version() { - return getServer().getClass().getPackage().getName().substring("org.bukkit.craftbukkit.".length()); - } - - @Override - public void onEnable() { - singleton = this; - - loadConfig(); - - PanillaLogger panillaLogger = new PanillaLogger(this); - - try { - panillaLogger.loadLocale(panillaConfig.localeFile); - } catch (IOException e) { - getLogger().severe(e.getMessage()); - getServer().getPluginManager().disablePlugin(this); - return; - } - - final String v_Version = v_Version(); - - switch (v_Version) { - case "v1_12_R1": - protocolConstants = new com.ruinscraft.panilla.v1_12_R1.ProtocolConstants(); - containerCleaner = new com.ruinscraft.panilla.v1_12_R1.ContainerCleaner(panillaConfig, - protocolConstants); - packetInspector = new com.ruinscraft.panilla.v1_12_R1.io.PacketInspector(panillaConfig, - protocolConstants); - playerInjector = new com.ruinscraft.panilla.v1_12_R1.io.PlayerInjector(packetInspector, containerCleaner, - protocolConstants, panillaConfig, panillaLogger); - break; - case "v1_13_R2": - protocolConstants = new com.ruinscraft.panilla.v1_13_R2.ProtocolConstants(); - containerCleaner = new com.ruinscraft.panilla.v1_13_R2.ContainerCleaner(panillaConfig, - protocolConstants); - packetInspector = new com.ruinscraft.panilla.v1_13_R2.io.PacketInspector(panillaConfig, - protocolConstants); - playerInjector = new com.ruinscraft.panilla.v1_13_R2.io.PlayerInjector(packetInspector, containerCleaner, - protocolConstants, panillaConfig, panillaLogger); - break; - default: - getLogger().severe("Minecraft version " + v_Version + " is not supported."); - getServer().getPluginManager().disablePlugin(this); - return; - } - - /* Register listeners */ - getServer().getPluginManager().registerEvents(new JoinQuitListener(), this); - - /* Register commands */ - getCommand("panilla").setExecutor(new PanillaCommand()); - - for (Player player : Bukkit.getOnlinePlayers()) { - playerInjector.register(player); - } - } - - @Override - public void onDisable() { - for (Player player : Bukkit.getOnlinePlayers()) { - playerInjector.unregister(player); - } - - singleton = null; - } - - /* singleton ========================================== */ - private static PanillaPlugin singleton; - - public static PanillaPlugin get() { - return singleton; - } - /* singleton ========================================== */ + private PConfig config; + private IProtocolConstants protocolConstants; + private IContainerCleaner containerCleaner; + private IPacketInspector packetInspector; + private IPlayerInjector playerInjector; + + public PConfig getPanillaConfig() { + return config; + } + + public IProtocolConstants getProtocolConstants() { + return protocolConstants; + } + + public IContainerCleaner getContainerCleaner() { + return containerCleaner; + } + + public IPacketInspector getPacketInspector() { + return packetInspector; + } + + public IPlayerInjector getPlayerInjector() { + return playerInjector; + } + + private synchronized void loadConfig() { + saveDefaultConfig(); + + config = new PConfig(); + + config.localeFile = getConfig().getString("locale-file", config.localeFile); + config.consoleLogging = getConfig().getBoolean("logging.console"); + config.chatLogging = getConfig().getBoolean("logging.chat"); + config.strictness = PStrictness.valueOf(getConfig().getString("strictness", config.strictness.name()).toUpperCase()); + config.nbtWhitelist = getConfig().getStringList("nbt-whitelist"); + config.maxNonMinecraftNbtKeys = getConfig().getInt("max-non-minecraft-nbt-keys", config.maxNonMinecraftNbtKeys); + } + + private String v_Version() { + return getServer().getClass().getPackage().getName().substring("org.bukkit.craftbukkit.".length()); + } + + @Override + public void onEnable() { + singleton = this; + + loadConfig(); + + PanillaLogger panillaLogger = new PanillaLogger(this); + + try { + panillaLogger.loadLocale(config.localeFile); + } catch (IOException e) { + getLogger().severe(e.getMessage()); + getServer().getPluginManager().disablePlugin(this); + return; + } + + final String v_Version = v_Version(); + + switch (v_Version) { + case "v1_12_R1": + protocolConstants = new com.ruinscraft.panilla.v1_12_R1.ProtocolConstants(); + containerCleaner = new com.ruinscraft.panilla.v1_12_R1.ContainerCleaner(config, + protocolConstants); + packetInspector = new com.ruinscraft.panilla.v1_12_R1.io.PacketInspector(config, + protocolConstants); + playerInjector = new com.ruinscraft.panilla.v1_12_R1.io.PlayerInjector(packetInspector, containerCleaner, + protocolConstants, config, panillaLogger); + break; + case "v1_13_R2": + protocolConstants = new com.ruinscraft.panilla.v1_13_R2.ProtocolConstants(); + containerCleaner = new com.ruinscraft.panilla.v1_13_R2.ContainerCleaner(config, + protocolConstants); + packetInspector = new com.ruinscraft.panilla.v1_13_R2.io.PacketInspector(config, + protocolConstants); + playerInjector = new com.ruinscraft.panilla.v1_13_R2.io.PlayerInjector(packetInspector, containerCleaner, + protocolConstants, config, panillaLogger); + break; + case "v1_14_R1": + protocolConstants = new com.ruinscraft.panilla.v1_14_R1.ProtocolConstants(); + containerCleaner = new com.ruinscraft.panilla.v1_14_R1.ContainerCleaner(config, + protocolConstants); + packetInspector = new com.ruinscraft.panilla.v1_14_R1.io.PacketInspector(config, + protocolConstants); + playerInjector = new com.ruinscraft.panilla.v1_14_R1.io.PlayerInjector(packetInspector, containerCleaner, + protocolConstants, config, panillaLogger); + break; + default: + getLogger().severe("Minecraft version " + v_Version + " is not supported."); + getServer().getPluginManager().disablePlugin(this); + return; + } + + /* Register listeners */ + getServer().getPluginManager().registerEvents(new JoinQuitListener(), this); + + /* Register commands */ + getCommand("panilla").setExecutor(new PanillaCommand()); + + for (Player player : Bukkit.getOnlinePlayers()) { + playerInjector.register(player); + } + } + + @Override + public void onDisable() { + for (Player player : Bukkit.getOnlinePlayers()) { + playerInjector.unregister(player); + } + + singleton = null; + } + + /* singleton ========================================== */ + private static PanillaPlugin singleton; + + public static PanillaPlugin get() { + return singleton; + } + /* singleton ========================================== */ } diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index aa8c25fb..af9e834e 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -18,5 +18,14 @@ strictness: average # Whitelist NBT tags from being checked nbt-whitelist: -# - Enchantments # 1.13 format +# - Enchantments # 1.13+ format # - ench # 1.12 format + +# You shouldn't have to touch this. +# +# If you have plugins which use an excessive amount of +# custom NBT keys, then you can raise it as high as you like. +# +# This is to prevent crash items which have an excessive +# amount of NBT keys. +max-non-minecraft-nbt-keys: 16 diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index e3146c0f..3d53d12c 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -2,7 +2,7 @@ name: ${name} version: ${version} main: ${mainClass} # Panilla is built on the 1.12 Bukkit API. -# Since it does not use any incompatible/deprecated API with 1.13, it is safe to not specify the api-version. +# Since it does not use any incompatible/deprecated API with 1.13/1.14, it is safe to not specify the api-version. # api-version: 1.13 description: Prevent abusive NBT and harmful packets authors: [royalkingkb] diff --git a/pom.xml b/pom.xml index 967bd74e..de981ef8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,23 +1,24 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - com.ruinscraft - panilla - 1.1 - pom + com.ruinscraft + panilla + 1.1 + pom - - api - plugin - v1_12_R1 - v1_13_R2 - + + api + plugin + v1_12_R1 + v1_13_R2 + v1_14_R1 + - - 1.8 - 1.8 - + + 1.8 + 1.8 + diff --git a/v1_12_R1/pom.xml b/v1_12_R1/pom.xml index 7b01402e..2ad69681 100644 --- a/v1_12_R1/pom.xml +++ b/v1_12_R1/pom.xml @@ -1,36 +1,36 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - com.ruinscraft - panilla - 1.1 - + + com.ruinscraft + panilla + 1.1 + - panilla-v1_12_R1 + panilla-v1_12_R1 - - - org.bukkit - craftbukkit - 1.12.2-R0.1-SNAPSHOT - provided - - - - io.netty - netty-all - 4.1.24.Final - provided - - - com.ruinscraft - panilla-api - 1.1 - provided - - + + + org.bukkit + craftbukkit + 1.12.2-R0.1-SNAPSHOT + provided + + + + io.netty + netty-all + 4.1.24.Final + provided + + + com.ruinscraft + panilla-api + 1.1 + provided + + diff --git a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/ContainerCleaner.java b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/ContainerCleaner.java index 06da7864..39c67253 100644 --- a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/ContainerCleaner.java +++ b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/ContainerCleaner.java @@ -1,48 +1,46 @@ package com.ruinscraft.panilla.v1_12_R1; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - import com.ruinscraft.panilla.api.IContainerCleaner; import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.config.PConfig; import com.ruinscraft.panilla.api.nbt.checks.NbtChecks; import com.ruinscraft.panilla.v1_12_R1.nbt.NbtTagCompound; - import net.minecraft.server.v1_12_R1.Container; import net.minecraft.server.v1_12_R1.ItemStack; import net.minecraft.server.v1_12_R1.NBTTagCompound; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; public class ContainerCleaner implements IContainerCleaner { - private final PConfig config; - private final IProtocolConstants protocolConstants; - - public ContainerCleaner(PConfig config, IProtocolConstants protocolConstants) { - this.config = config; - this.protocolConstants = protocolConstants; - } - - @Override - public void clean(Player player) { - CraftPlayer craftPlayer = (CraftPlayer) player; - Container container = craftPlayer.getHandle().activeContainer; - - for (int slot = 0; slot < container.slots.size(); slot++) { - ItemStack itemStack = container.getSlot(slot).getItem(); - - if (itemStack == null || !itemStack.hasTag()) continue; - - NBTTagCompound tag = itemStack.getTag(); - - String failedNbt = NbtChecks.checkAll(new NbtTagCompound(tag), - itemStack.getItem().getClass().getSimpleName(), protocolConstants, config); - - if (failedNbt != null) { - tag.remove(failedNbt); - container.getSlot(slot).getItem().setTag(tag); - } - } - } + private final PConfig config; + private final IProtocolConstants protocolConstants; + + public ContainerCleaner(PConfig config, IProtocolConstants protocolConstants) { + this.config = config; + this.protocolConstants = protocolConstants; + } + + @Override + public void clean(Player player) { + CraftPlayer craftPlayer = (CraftPlayer) player; + Container container = craftPlayer.getHandle().activeContainer; + + for (int slot = 0; slot < container.slots.size(); slot++) { + ItemStack itemStack = container.getSlot(slot).getItem(); + + if (itemStack == null || !itemStack.hasTag()) continue; + + NBTTagCompound tag = itemStack.getTag(); + + String failedNbt = NbtChecks.checkAll(new NbtTagCompound(tag), + itemStack.getItem().getClass().getSimpleName(), protocolConstants, config); + + if (failedNbt != null) { + tag.remove(failedNbt); + container.getSlot(slot).getItem().setTag(tag); + } + } + } } diff --git a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/ProtocolConstants.java b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/ProtocolConstants.java index 613f07cf..83b61c09 100644 --- a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/ProtocolConstants.java +++ b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/ProtocolConstants.java @@ -4,9 +4,9 @@ public class ProtocolConstants implements IProtocolConstants { - @Override - public int maxPacketSizeBytes() { - return 2097152; // net.minecraft.server.PacketDecompressor L33 - } + @Override + public int maxPacketSizeBytes() { + return 2097152; // net.minecraft.server.PacketDecompressor L33 + } } diff --git a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/io/PacketInspector.java b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/io/PacketInspector.java index 9df25c74..856b20ae 100644 --- a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/io/PacketInspector.java +++ b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/io/PacketInspector.java @@ -1,8 +1,5 @@ package com.ruinscraft.panilla.v1_12_R1.io; -import java.io.IOException; -import java.lang.reflect.Field; - import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.config.PConfig; import com.ruinscraft.panilla.api.exception.NbtNotPermittedException; @@ -11,105 +8,100 @@ import com.ruinscraft.panilla.api.io.IPacketInspector; import com.ruinscraft.panilla.api.nbt.checks.NbtChecks; import com.ruinscraft.panilla.v1_12_R1.nbt.NbtTagCompound; - import io.netty.buffer.UnpooledByteBufAllocator; -import net.minecraft.server.v1_12_R1.ItemStack; -import net.minecraft.server.v1_12_R1.Packet; -import net.minecraft.server.v1_12_R1.PacketDataSerializer; -import net.minecraft.server.v1_12_R1.PacketPlayInCustomPayload; -import net.minecraft.server.v1_12_R1.PacketPlayInSetCreativeSlot; -import net.minecraft.server.v1_12_R1.PacketPlayInUpdateSign; -import net.minecraft.server.v1_12_R1.PacketPlayOutCustomPayload; -import net.minecraft.server.v1_12_R1.PacketPlayOutSetSlot; +import net.minecraft.server.v1_12_R1.*; + +import java.io.IOException; +import java.lang.reflect.Field; public class PacketInspector implements IPacketInspector { - private final PConfig config; - private final IProtocolConstants protocolConstants; - - public PacketInspector(PConfig config, IProtocolConstants protocolConstants) { - this.config = config; - this.protocolConstants = protocolConstants; - } - - @Override - public void checkSize(Object _packet, boolean from) throws OversizedPacketException { - if (_packet instanceof Packet) { - Packet packet = (Packet) _packet; - PacketDataSerializer dataSerializer = new PacketDataSerializer(UnpooledByteBufAllocator.DEFAULT.buffer()); - - int sizeBytes = 0; - - try { - packet.b(dataSerializer); - - sizeBytes = dataSerializer.readableBytes(); - - // https://github.com/aadnk/ProtocolLib/commit/5ec87c9d7650ae21faca9b7b3cc7ac1629870d24 - if (packet instanceof PacketPlayInCustomPayload || packet instanceof PacketPlayOutCustomPayload) { - packet.a(dataSerializer); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - dataSerializer.release(); - } - - if (sizeBytes > protocolConstants.maxPacketSizeBytes()) { - throw new OversizedPacketException(packet.getClass().getSimpleName(), from, sizeBytes); - } - } - } - - @Override - public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException { - if (_packet instanceof PacketPlayInSetCreativeSlot) { - PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet; - - ItemStack itemStack = packet.getItemStack(); - - if (itemStack == null || !itemStack.hasTag()) return; - - NbtChecks.checkPacketPlayIn(new NbtTagCompound(itemStack.getTag()), - itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), - protocolConstants, config); - } - } - - @Override - public void checkPacketPlayInUpdateSign(Object _packet) throws SignLineLengthTooLongException { - if (_packet instanceof PacketPlayInUpdateSign) { - PacketPlayInUpdateSign packet = (PacketPlayInUpdateSign) _packet; - - for (String line : packet.b()) { - if (line.length() > protocolConstants.maxSignLineLength()) { - throw new SignLineLengthTooLongException(packet.getClass().getSimpleName(), true); - } - } - } - } - - @Override - public void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException { - if (_packet instanceof PacketPlayOutSetSlot) { - PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) _packet; - - try { - Field itemStackField = packet.getClass().getDeclaredField("c"); - - itemStackField.setAccessible(true); - - ItemStack itemStack = (ItemStack) itemStackField.get(packet); - - if (itemStack == null || !itemStack.hasTag()) return; - - NbtChecks.checkPacketPlayOut(new NbtTagCompound(itemStack.getTag()), - itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), - protocolConstants, config); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - } - } - } + private final PConfig config; + private final IProtocolConstants protocolConstants; + + public PacketInspector(PConfig config, IProtocolConstants protocolConstants) { + this.config = config; + this.protocolConstants = protocolConstants; + } + + @Override + public void checkSize(Object _packet, boolean from) throws OversizedPacketException { + if (_packet instanceof Packet) { + Packet packet = (Packet) _packet; + PacketDataSerializer dataSerializer = new PacketDataSerializer(UnpooledByteBufAllocator.DEFAULT.buffer()); + + int sizeBytes = 0; + + try { + packet.b(dataSerializer); + + sizeBytes = dataSerializer.readableBytes(); + + // https://github.com/aadnk/ProtocolLib/commit/5ec87c9d7650ae21faca9b7b3cc7ac1629870d24 + if (packet instanceof PacketPlayInCustomPayload || packet instanceof PacketPlayOutCustomPayload) { + packet.a(dataSerializer); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + dataSerializer.release(); + } + + if (sizeBytes > protocolConstants.maxPacketSizeBytes()) { + throw new OversizedPacketException(packet.getClass().getSimpleName(), from, sizeBytes); + } + } + } + + @Override + public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException { + if (_packet instanceof PacketPlayInSetCreativeSlot) { + PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet; + + ItemStack itemStack = packet.getItemStack(); + + if (itemStack == null || !itemStack.hasTag()) return; + + NbtChecks.checkPacketPlayIn(new NbtTagCompound(itemStack.getTag()), + itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), + protocolConstants, config); + } + } + + @Override + public void checkPacketPlayInUpdateSign(Object _packet) throws SignLineLengthTooLongException { + if (_packet instanceof PacketPlayInUpdateSign) { + PacketPlayInUpdateSign packet = (PacketPlayInUpdateSign) _packet; + + for (String line : packet.b()) { + if (line.length() > protocolConstants.maxSignLineLength()) { + throw new SignLineLengthTooLongException(packet.getClass().getSimpleName(), true); + } + } + } + } + + @Override + public void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException { + if (_packet instanceof PacketPlayOutSetSlot) { + PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) _packet; + + try { + Field itemStackField = packet.getClass().getDeclaredField("c"); + + itemStackField.setAccessible(true); + + ItemStack itemStack = (ItemStack) itemStackField.get(packet); + + if (itemStack == null || !itemStack.hasTag()) return; + + NbtChecks.checkPacketPlayOut(new NbtTagCompound(itemStack.getTag()), + itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), + protocolConstants, config); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + } + } } diff --git a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/io/PlayerInjector.java b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/io/PlayerInjector.java index 5c8c2071..cefbc001 100644 --- a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/io/PlayerInjector.java +++ b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/io/PlayerInjector.java @@ -1,8 +1,5 @@ package com.ruinscraft.panilla.v1_12_R1.io; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - import com.ruinscraft.panilla.api.IContainerCleaner; import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.PanillaLogger; @@ -11,66 +8,67 @@ import com.ruinscraft.panilla.api.io.IPlayerInjector; import com.ruinscraft.panilla.api.io.PlayerInbound; import com.ruinscraft.panilla.api.io.PlayerOutbound; - import io.netty.channel.Channel; import net.minecraft.server.v1_12_R1.EntityPlayer; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; public class PlayerInjector implements IPlayerInjector { - private final IPacketInspector packetInspector; - private final IContainerCleaner containerCleaner; - private final IProtocolConstants protocolConstants; - private final PConfig config; - private final PanillaLogger panillaLogger; + private final IPacketInspector packetInspector; + private final IContainerCleaner containerCleaner; + private final IProtocolConstants protocolConstants; + private final PConfig config; + private final PanillaLogger panillaLogger; - public PlayerInjector(IPacketInspector packetInspector, IContainerCleaner containerCleaner, - IProtocolConstants protocolConstants, PConfig config, PanillaLogger panillaLogger) { - this.packetInspector = packetInspector; - this.containerCleaner = containerCleaner; - this.protocolConstants = protocolConstants; - this.config = config; - this.panillaLogger = panillaLogger; - } + public PlayerInjector(IPacketInspector packetInspector, IContainerCleaner containerCleaner, + IProtocolConstants protocolConstants, PConfig config, PanillaLogger panillaLogger) { + this.packetInspector = packetInspector; + this.containerCleaner = containerCleaner; + this.protocolConstants = protocolConstants; + this.config = config; + this.panillaLogger = panillaLogger; + } - private static Channel getPlayerChannel(Player player) throws IllegalArgumentException { - CraftPlayer craftPlayer = (CraftPlayer) player; - EntityPlayer entityPlayer = craftPlayer.getHandle(); + private static Channel getPlayerChannel(Player player) throws IllegalArgumentException { + CraftPlayer craftPlayer = (CraftPlayer) player; + EntityPlayer entityPlayer = craftPlayer.getHandle(); - return entityPlayer.playerConnection.networkManager.channel; - } + return entityPlayer.playerConnection.networkManager.channel; + } - @Override - public void register(final Player player) { - Channel channel = getPlayerChannel(player); + @Override + public void register(final Player player) { + Channel channel = getPlayerChannel(player); - /* Register inbound */ - if (channel.pipeline().get(PANILLA_CHANNEL_IN) == null) { - PlayerInbound inbound = new PlayerInbound(player, packetInspector, containerCleaner, - protocolConstants, config, panillaLogger); - channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_IN, inbound); - } + /* Register inbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_IN) == null) { + PlayerInbound inbound = new PlayerInbound(player, packetInspector, containerCleaner, + protocolConstants, config, panillaLogger); + channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_IN, inbound); + } - /* Register outbound */ - if (channel.pipeline().get(PANILLA_CHANNEL_OUT) == null) { - PlayerOutbound outbound = new PlayerOutbound(player, packetInspector, containerCleaner, - protocolConstants, config, panillaLogger); - channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_OUT, outbound); - } - } + /* Register outbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_OUT) == null) { + PlayerOutbound outbound = new PlayerOutbound(player, packetInspector, containerCleaner, + protocolConstants, config, panillaLogger); + channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_OUT, outbound); + } + } - @Override - public void unregister(final Player player) { - Channel channel = getPlayerChannel(player); + @Override + public void unregister(final Player player) { + Channel channel = getPlayerChannel(player); - /* Unregister inbound */ - if (channel.pipeline().get(PANILLA_CHANNEL_IN) != null) { - channel.pipeline().remove(PANILLA_CHANNEL_IN); - } + /* Unregister inbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_IN) != null) { + channel.pipeline().remove(PANILLA_CHANNEL_IN); + } - /* Unregister outbound */ - if (channel.pipeline().get(PANILLA_CHANNEL_OUT) != null) { - channel.pipeline().remove(PANILLA_CHANNEL_OUT); - } - } + /* Unregister outbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_OUT) != null) { + channel.pipeline().remove(PANILLA_CHANNEL_OUT); + } + } } diff --git a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/nbt/NbtTagCompound.java b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/nbt/NbtTagCompound.java index 5a10300a..9e5935c7 100644 --- a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/nbt/NbtTagCompound.java +++ b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/nbt/NbtTagCompound.java @@ -1,59 +1,58 @@ package com.ruinscraft.panilla.v1_12_R1.nbt; -import java.util.Set; - import com.ruinscraft.panilla.api.nbt.INbtTagCompound; import com.ruinscraft.panilla.api.nbt.INbtTagList; import com.ruinscraft.panilla.api.nbt.NbtDataType; - import net.minecraft.server.v1_12_R1.NBTTagCompound; +import java.util.Set; + public class NbtTagCompound implements INbtTagCompound { - private final NBTTagCompound handle; - - public NbtTagCompound(NBTTagCompound handle) { - this.handle = handle; - } - - @Override - public boolean hasKey(String key) { - return handle.hasKey(key); - } - - @Override - public boolean hasKeyOfType(String key, NbtDataType nbtDataType) { - return handle.hasKeyOfType(key, nbtDataType.id); - } - - @Override - public Set getKeys() { - return handle.c(); - } - - @Override - public int getInt(String key) { - return handle.getInt(key); - } - - @Override - public short getShort(String key) { - return handle.getShort(key); - } - - @Override - public String getString(String key) { - return handle.getString(key); - } - - @Override - public INbtTagList getList(String key, NbtDataType nbtDataType) { - return new NbtTagList(handle.getList(key, nbtDataType.id)); - } - - @Override - public INbtTagCompound getCompound(String key) { - return new NbtTagCompound(handle.getCompound(key)); - } + private final NBTTagCompound handle; + + public NbtTagCompound(NBTTagCompound handle) { + this.handle = handle; + } + + @Override + public boolean hasKey(String key) { + return handle.hasKey(key); + } + + @Override + public boolean hasKeyOfType(String key, NbtDataType nbtDataType) { + return handle.hasKeyOfType(key, nbtDataType.id); + } + + @Override + public Set getKeys() { + return handle.c(); + } + + @Override + public int getInt(String key) { + return handle.getInt(key); + } + + @Override + public short getShort(String key) { + return handle.getShort(key); + } + + @Override + public String getString(String key) { + return handle.getString(key); + } + + @Override + public INbtTagList getList(String key, NbtDataType nbtDataType) { + return new NbtTagList(handle.getList(key, nbtDataType.id)); + } + + @Override + public INbtTagCompound getCompound(String key) { + return new NbtTagCompound(handle.getCompound(key)); + } } diff --git a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/nbt/NbtTagList.java b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/nbt/NbtTagList.java index a7658755..4e3e54d6 100644 --- a/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/nbt/NbtTagList.java +++ b/v1_12_R1/src/main/java/com/ruinscraft/panilla/v1_12_R1/nbt/NbtTagList.java @@ -2,25 +2,24 @@ import com.ruinscraft.panilla.api.nbt.INbtTagCompound; import com.ruinscraft.panilla.api.nbt.INbtTagList; - import net.minecraft.server.v1_12_R1.NBTTagList; public class NbtTagList implements INbtTagList { - private final NBTTagList handle; + private final NBTTagList handle; - public NbtTagList(NBTTagList handle) { - this.handle = handle; - } + public NbtTagList(NBTTagList handle) { + this.handle = handle; + } - @Override - public INbtTagCompound get(int index) { - return new NbtTagCompound(handle.get(index)); - } + @Override + public INbtTagCompound get(int index) { + return new NbtTagCompound(handle.get(index)); + } - @Override - public int size() { - return handle.size(); - } + @Override + public int size() { + return handle.size(); + } } diff --git a/v1_13_R2/pom.xml b/v1_13_R2/pom.xml index b2805ef0..ff2823aa 100644 --- a/v1_13_R2/pom.xml +++ b/v1_13_R2/pom.xml @@ -1,36 +1,36 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - com.ruinscraft - panilla - 1.1 - + + com.ruinscraft + panilla + 1.1 + - panilla-v1_13_R2 + panilla-v1_13_R2 - - - org.bukkit - craftbukkit - 1.13.2-R0.1-SNAPSHOT - provided - - - - io.netty - netty-all - 4.1.25.Final - provided - - - com.ruinscraft - panilla-api - 1.1 - provided - - + + + org.bukkit + craftbukkit + 1.13.2-R0.1-SNAPSHOT + provided + + + + io.netty + netty-all + 4.1.25.Final + provided + + + com.ruinscraft + panilla-api + 1.1 + provided + + diff --git a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/ContainerCleaner.java b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/ContainerCleaner.java index 5d7e24b9..91487f55 100644 --- a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/ContainerCleaner.java +++ b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/ContainerCleaner.java @@ -1,48 +1,46 @@ package com.ruinscraft.panilla.v1_13_R2; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - import com.ruinscraft.panilla.api.IContainerCleaner; import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.config.PConfig; import com.ruinscraft.panilla.api.nbt.checks.NbtChecks; import com.ruinscraft.panilla.v1_13_R2.nbt.NbtTagCompound; - import net.minecraft.server.v1_13_R2.Container; import net.minecraft.server.v1_13_R2.ItemStack; import net.minecraft.server.v1_13_R2.NBTTagCompound; +import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; +import org.bukkit.entity.Player; public class ContainerCleaner implements IContainerCleaner { - private final PConfig config; - private final IProtocolConstants protocolConstants; - - public ContainerCleaner(PConfig config, IProtocolConstants protocolConstants) { - this.config = config; - this.protocolConstants = protocolConstants; - } - - @Override - public void clean(Player player) { - CraftPlayer craftPlayer = (CraftPlayer) player; - Container container = craftPlayer.getHandle().activeContainer; - - for (int slot = 0; slot < container.slots.size(); slot++) { - ItemStack itemStack = container.getSlot(slot).getItem(); - - if (itemStack == null || !itemStack.hasTag()) continue; - - NBTTagCompound tag = itemStack.getTag(); - - String failedNbt = NbtChecks.checkAll(new NbtTagCompound(tag), - itemStack.getItem().getClass().getSimpleName(), protocolConstants, config); - - if (failedNbt != null) { - tag.remove(failedNbt); - container.getSlot(slot).getItem().setTag(tag); - } - } - } + private final PConfig config; + private final IProtocolConstants protocolConstants; + + public ContainerCleaner(PConfig config, IProtocolConstants protocolConstants) { + this.config = config; + this.protocolConstants = protocolConstants; + } + + @Override + public void clean(Player player) { + CraftPlayer craftPlayer = (CraftPlayer) player; + Container container = craftPlayer.getHandle().activeContainer; + + for (int slot = 0; slot < container.slots.size(); slot++) { + ItemStack itemStack = container.getSlot(slot).getItem(); + + if (itemStack == null || !itemStack.hasTag()) continue; + + NBTTagCompound tag = itemStack.getTag(); + + String failedNbt = NbtChecks.checkAll(new NbtTagCompound(tag), + itemStack.getItem().getClass().getSimpleName(), protocolConstants, config); + + if (failedNbt != null) { + tag.remove(failedNbt); + container.getSlot(slot).getItem().setTag(tag); + } + } + } } diff --git a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/ProtocolConstants.java b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/ProtocolConstants.java index b66d24f3..75ea8543 100644 --- a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/ProtocolConstants.java +++ b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/ProtocolConstants.java @@ -4,9 +4,9 @@ public class ProtocolConstants implements IProtocolConstants { - @Override - public int maxPacketSizeBytes() { - return 2097152; // net.minecraft.server.PacketDecompressor L33 - } + @Override + public int maxPacketSizeBytes() { + return 2097152; // net.minecraft.server.PacketDecompressor L33 + } } diff --git a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/io/PacketInspector.java b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/io/PacketInspector.java index f6a5de8c..91accef1 100644 --- a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/io/PacketInspector.java +++ b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/io/PacketInspector.java @@ -1,8 +1,5 @@ package com.ruinscraft.panilla.v1_13_R2.io; -import java.io.IOException; -import java.lang.reflect.Field; - import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.config.PConfig; import com.ruinscraft.panilla.api.exception.NbtNotPermittedException; @@ -11,105 +8,100 @@ import com.ruinscraft.panilla.api.io.IPacketInspector; import com.ruinscraft.panilla.api.nbt.checks.NbtChecks; import com.ruinscraft.panilla.v1_13_R2.nbt.NbtTagCompound; - import io.netty.buffer.UnpooledByteBufAllocator; -import net.minecraft.server.v1_13_R2.ItemStack; -import net.minecraft.server.v1_13_R2.Packet; -import net.minecraft.server.v1_13_R2.PacketDataSerializer; -import net.minecraft.server.v1_13_R2.PacketPlayInCustomPayload; -import net.minecraft.server.v1_13_R2.PacketPlayInSetCreativeSlot; -import net.minecraft.server.v1_13_R2.PacketPlayInUpdateSign; -import net.minecraft.server.v1_13_R2.PacketPlayOutCustomPayload; -import net.minecraft.server.v1_13_R2.PacketPlayOutSetSlot; +import net.minecraft.server.v1_13_R2.*; + +import java.io.IOException; +import java.lang.reflect.Field; public class PacketInspector implements IPacketInspector { - private final PConfig config; - private final IProtocolConstants protocolConstants; - - public PacketInspector(PConfig config, IProtocolConstants protocolConstants) { - this.config = config; - this.protocolConstants = protocolConstants; - } - - @Override - public void checkSize(Object _packet, boolean from) throws OversizedPacketException { - if (_packet instanceof Packet) { - Packet packet = (Packet) _packet; - PacketDataSerializer dataSerializer = new PacketDataSerializer(UnpooledByteBufAllocator.DEFAULT.buffer()); - - int sizeBytes = 0; - - try { - packet.b(dataSerializer); - - sizeBytes = dataSerializer.readableBytes(); - - // https://github.com/aadnk/ProtocolLib/commit/5ec87c9d7650ae21faca9b7b3cc7ac1629870d24 - if (packet instanceof PacketPlayInCustomPayload || packet instanceof PacketPlayOutCustomPayload) { - packet.a(dataSerializer); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - dataSerializer.release(); - } - - if (sizeBytes > protocolConstants.maxPacketSizeBytes()) { - throw new OversizedPacketException(packet.getClass().getSimpleName(), from, sizeBytes); - } - } - } - - @Override - public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException { - if (_packet instanceof PacketPlayInSetCreativeSlot) { - PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet; - - ItemStack itemStack = packet.getItemStack(); - - if (itemStack == null || !itemStack.hasTag()) return; - - NbtChecks.checkPacketPlayIn(new NbtTagCompound(itemStack.getTag()), - itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), - protocolConstants, config); - } - } - - @Override - public void checkPacketPlayInUpdateSign(Object _packet) throws SignLineLengthTooLongException { - if (_packet instanceof PacketPlayInUpdateSign) { - PacketPlayInUpdateSign packet = (PacketPlayInUpdateSign) _packet; - - for (String line : packet.c()) { - if (line.length() > protocolConstants.maxSignLineLength()) { - throw new SignLineLengthTooLongException(packet.getClass().getSimpleName(), true); - } - } - } - } - - @Override - public void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException { - if (_packet instanceof PacketPlayOutSetSlot) { - PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) _packet; - - try { - Field itemStackField = packet.getClass().getDeclaredField("c"); - - itemStackField.setAccessible(true); - - ItemStack itemStack = (ItemStack) itemStackField.get(packet); - - if (itemStack == null || !itemStack.hasTag()) return; - - NbtChecks.checkPacketPlayOut(new NbtTagCompound(itemStack.getTag()), - itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), - protocolConstants, config); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - } - } - } + private final PConfig config; + private final IProtocolConstants protocolConstants; + + public PacketInspector(PConfig config, IProtocolConstants protocolConstants) { + this.config = config; + this.protocolConstants = protocolConstants; + } + + @Override + public void checkSize(Object _packet, boolean from) throws OversizedPacketException { + if (_packet instanceof Packet) { + Packet packet = (Packet) _packet; + PacketDataSerializer dataSerializer = new PacketDataSerializer(UnpooledByteBufAllocator.DEFAULT.buffer()); + + int sizeBytes = 0; + + try { + packet.b(dataSerializer); + + sizeBytes = dataSerializer.readableBytes(); + + // https://github.com/aadnk/ProtocolLib/commit/5ec87c9d7650ae21faca9b7b3cc7ac1629870d24 + if (packet instanceof PacketPlayInCustomPayload || packet instanceof PacketPlayOutCustomPayload) { + packet.a(dataSerializer); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + dataSerializer.release(); + } + + if (sizeBytes > protocolConstants.maxPacketSizeBytes()) { + throw new OversizedPacketException(packet.getClass().getSimpleName(), from, sizeBytes); + } + } + } + + @Override + public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException { + if (_packet instanceof PacketPlayInSetCreativeSlot) { + PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet; + + ItemStack itemStack = packet.getItemStack(); + + if (itemStack == null || !itemStack.hasTag()) return; + + NbtChecks.checkPacketPlayIn(new NbtTagCompound(itemStack.getTag()), + itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), + protocolConstants, config); + } + } + + @Override + public void checkPacketPlayInUpdateSign(Object _packet) throws SignLineLengthTooLongException { + if (_packet instanceof PacketPlayInUpdateSign) { + PacketPlayInUpdateSign packet = (PacketPlayInUpdateSign) _packet; + + for (String line : packet.c()) { + if (line.length() > protocolConstants.maxSignLineLength()) { + throw new SignLineLengthTooLongException(packet.getClass().getSimpleName(), true); + } + } + } + } + + @Override + public void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException { + if (_packet instanceof PacketPlayOutSetSlot) { + PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) _packet; + + try { + Field itemStackField = packet.getClass().getDeclaredField("c"); + + itemStackField.setAccessible(true); + + ItemStack itemStack = (ItemStack) itemStackField.get(packet); + + if (itemStack == null || !itemStack.hasTag()) return; + + NbtChecks.checkPacketPlayOut(new NbtTagCompound(itemStack.getTag()), + itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), + protocolConstants, config); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + } + } } diff --git a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/io/PlayerInjector.java b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/io/PlayerInjector.java index 207f8860..2770fea8 100644 --- a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/io/PlayerInjector.java +++ b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/io/PlayerInjector.java @@ -1,8 +1,5 @@ package com.ruinscraft.panilla.v1_13_R2.io; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - import com.ruinscraft.panilla.api.IContainerCleaner; import com.ruinscraft.panilla.api.IProtocolConstants; import com.ruinscraft.panilla.api.PanillaLogger; @@ -11,66 +8,67 @@ import com.ruinscraft.panilla.api.io.IPlayerInjector; import com.ruinscraft.panilla.api.io.PlayerInbound; import com.ruinscraft.panilla.api.io.PlayerOutbound; - import io.netty.channel.Channel; import net.minecraft.server.v1_13_R2.EntityPlayer; +import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; +import org.bukkit.entity.Player; public class PlayerInjector implements IPlayerInjector { - private final IPacketInspector packetInspector; - private final IContainerCleaner containerCleaner; - private final IProtocolConstants protocolConstants; - private final PConfig config; - private final PanillaLogger panillaLogger; + private final IPacketInspector packetInspector; + private final IContainerCleaner containerCleaner; + private final IProtocolConstants protocolConstants; + private final PConfig config; + private final PanillaLogger panillaLogger; - public PlayerInjector(IPacketInspector packetInspector, IContainerCleaner containerCleaner, - IProtocolConstants protocolConstants, PConfig config, PanillaLogger panillaLogger) { - this.packetInspector = packetInspector; - this.containerCleaner = containerCleaner; - this.protocolConstants = protocolConstants; - this.config = config; - this.panillaLogger = panillaLogger; - } + public PlayerInjector(IPacketInspector packetInspector, IContainerCleaner containerCleaner, + IProtocolConstants protocolConstants, PConfig config, PanillaLogger panillaLogger) { + this.packetInspector = packetInspector; + this.containerCleaner = containerCleaner; + this.protocolConstants = protocolConstants; + this.config = config; + this.panillaLogger = panillaLogger; + } - private static Channel getPlayerChannel(final Player player) throws IllegalArgumentException { - CraftPlayer craftPlayer = (CraftPlayer) player; - EntityPlayer entityPlayer = craftPlayer.getHandle(); + private static Channel getPlayerChannel(final Player player) throws IllegalArgumentException { + CraftPlayer craftPlayer = (CraftPlayer) player; + EntityPlayer entityPlayer = craftPlayer.getHandle(); - return entityPlayer.playerConnection.networkManager.channel; - } + return entityPlayer.playerConnection.networkManager.channel; + } - @Override - public void register(final Player player) { - Channel channel = getPlayerChannel(player); + @Override + public void register(final Player player) { + Channel channel = getPlayerChannel(player); - /* Register inbound */ - if (channel.pipeline().get(PANILLA_CHANNEL_IN) == null) { - PlayerInbound inbound = new PlayerInbound(player, packetInspector, containerCleaner, - protocolConstants, config, panillaLogger); - channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_IN, inbound); - } + /* Register inbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_IN) == null) { + PlayerInbound inbound = new PlayerInbound(player, packetInspector, containerCleaner, + protocolConstants, config, panillaLogger); + channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_IN, inbound); + } - /* Register outbound */ - if (channel.pipeline().get(PANILLA_CHANNEL_OUT) == null) { - PlayerOutbound outbound = new PlayerOutbound(player, packetInspector, containerCleaner, - protocolConstants, config, panillaLogger); - channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_OUT, outbound); - } - } + /* Register outbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_OUT) == null) { + PlayerOutbound outbound = new PlayerOutbound(player, packetInspector, containerCleaner, + protocolConstants, config, panillaLogger); + channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_OUT, outbound); + } + } - @Override - public void unregister(final Player player) { - Channel channel = getPlayerChannel(player); + @Override + public void unregister(final Player player) { + Channel channel = getPlayerChannel(player); - /* Unregister inbound */ - if (channel.pipeline().get(PANILLA_CHANNEL_IN) != null) { - channel.pipeline().remove(PANILLA_CHANNEL_IN); - } + /* Unregister inbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_IN) != null) { + channel.pipeline().remove(PANILLA_CHANNEL_IN); + } - /* Unregister outbound */ - if (channel.pipeline().get(PANILLA_CHANNEL_OUT) != null) { - channel.pipeline().remove(PANILLA_CHANNEL_OUT); - } - } + /* Unregister outbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_OUT) != null) { + channel.pipeline().remove(PANILLA_CHANNEL_OUT); + } + } } diff --git a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/nbt/NbtTagCompound.java b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/nbt/NbtTagCompound.java index 7a7f3949..96786b4c 100644 --- a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/nbt/NbtTagCompound.java +++ b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/nbt/NbtTagCompound.java @@ -1,59 +1,58 @@ package com.ruinscraft.panilla.v1_13_R2.nbt; -import java.util.Set; - import com.ruinscraft.panilla.api.nbt.INbtTagCompound; import com.ruinscraft.panilla.api.nbt.INbtTagList; import com.ruinscraft.panilla.api.nbt.NbtDataType; - import net.minecraft.server.v1_13_R2.NBTTagCompound; +import java.util.Set; + public class NbtTagCompound implements INbtTagCompound { - private final NBTTagCompound handle; - - public NbtTagCompound(NBTTagCompound handle) { - this.handle = handle; - } - - @Override - public boolean hasKey(String key) { - return handle.hasKey(key); - } - - @Override - public boolean hasKeyOfType(String key, NbtDataType nbtDataType) { - return handle.hasKeyOfType(key, nbtDataType.id); - } - - @Override - public Set getKeys() { - return handle.getKeys(); - } - - @Override - public int getInt(String key) { - return handle.getInt(key); - } - - @Override - public short getShort(String key) { - return handle.getShort(key); - } - - @Override - public String getString(String key) { - return handle.getString(key); - } - - @Override - public INbtTagList getList(String key, NbtDataType nbtDataType) { - return new NbtTagList(handle.getList(key, nbtDataType.id)); - } - - @Override - public INbtTagCompound getCompound(String key) { - return new NbtTagCompound(handle.getCompound(key)); - } + private final NBTTagCompound handle; + + public NbtTagCompound(NBTTagCompound handle) { + this.handle = handle; + } + + @Override + public boolean hasKey(String key) { + return handle.hasKey(key); + } + + @Override + public boolean hasKeyOfType(String key, NbtDataType nbtDataType) { + return handle.hasKeyOfType(key, nbtDataType.id); + } + + @Override + public Set getKeys() { + return handle.getKeys(); + } + + @Override + public int getInt(String key) { + return handle.getInt(key); + } + + @Override + public short getShort(String key) { + return handle.getShort(key); + } + + @Override + public String getString(String key) { + return handle.getString(key); + } + + @Override + public INbtTagList getList(String key, NbtDataType nbtDataType) { + return new NbtTagList(handle.getList(key, nbtDataType.id)); + } + + @Override + public INbtTagCompound getCompound(String key) { + return new NbtTagCompound(handle.getCompound(key)); + } } diff --git a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/nbt/NbtTagList.java b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/nbt/NbtTagList.java index eac35c4c..22fc1230 100644 --- a/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/nbt/NbtTagList.java +++ b/v1_13_R2/src/main/java/com/ruinscraft/panilla/v1_13_R2/nbt/NbtTagList.java @@ -2,25 +2,24 @@ import com.ruinscraft.panilla.api.nbt.INbtTagCompound; import com.ruinscraft.panilla.api.nbt.INbtTagList; - import net.minecraft.server.v1_13_R2.NBTTagList; public class NbtTagList implements INbtTagList { - private final NBTTagList handle; + private final NBTTagList handle; - public NbtTagList(NBTTagList handle) { - this.handle = handle; - } + public NbtTagList(NBTTagList handle) { + this.handle = handle; + } - @Override - public INbtTagCompound get(int index) { - return new NbtTagCompound(handle.getCompound(index)); - } + @Override + public INbtTagCompound get(int index) { + return new NbtTagCompound(handle.getCompound(index)); + } - @Override - public int size() { - return handle.size(); - } + @Override + public int size() { + return handle.size(); + } } diff --git a/v1_14_R1/pom.xml b/v1_14_R1/pom.xml new file mode 100644 index 00000000..5832186b --- /dev/null +++ b/v1_14_R1/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + + com.ruinscraft + panilla + 1.1 + + + panilla-v1_14_R1 + + + + org.bukkit + craftbukkit + 1.14-R0.1-SNAPSHOT + provided + + + + io.netty + netty-all + 4.1.25.Final + provided + + + com.ruinscraft + panilla-api + 1.1 + provided + + + + \ No newline at end of file diff --git a/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/ContainerCleaner.java b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/ContainerCleaner.java new file mode 100644 index 00000000..b7bf5ed0 --- /dev/null +++ b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/ContainerCleaner.java @@ -0,0 +1,46 @@ +package com.ruinscraft.panilla.v1_14_R1; + +import com.ruinscraft.panilla.api.IContainerCleaner; +import com.ruinscraft.panilla.api.IProtocolConstants; +import com.ruinscraft.panilla.api.config.PConfig; +import com.ruinscraft.panilla.api.nbt.checks.NbtChecks; +import com.ruinscraft.panilla.v1_14_R1.nbt.NbtTagCompound; +import net.minecraft.server.v1_14_R1.Container; +import net.minecraft.server.v1_14_R1.ItemStack; +import net.minecraft.server.v1_14_R1.NBTTagCompound; +import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class ContainerCleaner implements IContainerCleaner { + + private final PConfig config; + private final IProtocolConstants protocolConstants; + + public ContainerCleaner(PConfig config, IProtocolConstants protocolConstants) { + this.config = config; + this.protocolConstants = protocolConstants; + } + + @Override + public void clean(Player player) { + CraftPlayer craftPlayer = (CraftPlayer) player; + Container container = craftPlayer.getHandle().activeContainer; + + for (int slot = 0; slot < container.slots.size(); slot++) { + ItemStack itemStack = container.getSlot(slot).getItem(); + + if (itemStack == null || !itemStack.hasTag()) continue; + + NBTTagCompound tag = itemStack.getTag(); + + String failedNbt = NbtChecks.checkAll(new NbtTagCompound(tag), + itemStack.getItem().getClass().getSimpleName(), protocolConstants, config); + + if (failedNbt != null) { + tag.remove(failedNbt); + container.getSlot(slot).getItem().setTag(tag); + } + } + } + +} diff --git a/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/ProtocolConstants.java b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/ProtocolConstants.java new file mode 100644 index 00000000..fa97df06 --- /dev/null +++ b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/ProtocolConstants.java @@ -0,0 +1,12 @@ +package com.ruinscraft.panilla.v1_14_R1; + +import com.ruinscraft.panilla.api.IProtocolConstants; + +public class ProtocolConstants implements IProtocolConstants { + + @Override + public int maxPacketSizeBytes() { + return 2097152; // net.minecraft.server.PacketDecompressor L33 + } + +} diff --git a/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/io/PacketInspector.java b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/io/PacketInspector.java new file mode 100644 index 00000000..b6040580 --- /dev/null +++ b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/io/PacketInspector.java @@ -0,0 +1,107 @@ +package com.ruinscraft.panilla.v1_14_R1.io; + +import com.ruinscraft.panilla.api.IProtocolConstants; +import com.ruinscraft.panilla.api.config.PConfig; +import com.ruinscraft.panilla.api.exception.NbtNotPermittedException; +import com.ruinscraft.panilla.api.exception.OversizedPacketException; +import com.ruinscraft.panilla.api.exception.SignLineLengthTooLongException; +import com.ruinscraft.panilla.api.io.IPacketInspector; +import com.ruinscraft.panilla.api.nbt.checks.NbtChecks; +import com.ruinscraft.panilla.v1_14_R1.nbt.NbtTagCompound; +import io.netty.buffer.UnpooledByteBufAllocator; +import net.minecraft.server.v1_14_R1.*; + +import java.io.IOException; +import java.lang.reflect.Field; + +public class PacketInspector implements IPacketInspector { + + private final PConfig config; + private final IProtocolConstants protocolConstants; + + public PacketInspector(PConfig config, IProtocolConstants protocolConstants) { + this.config = config; + this.protocolConstants = protocolConstants; + } + + @Override + public void checkSize(Object _packet, boolean from) throws OversizedPacketException { + if (_packet instanceof Packet) { + Packet packet = (Packet) _packet; + PacketDataSerializer dataSerializer = new PacketDataSerializer(UnpooledByteBufAllocator.DEFAULT.buffer()); + + int sizeBytes = 0; + + try { + packet.b(dataSerializer); + + sizeBytes = dataSerializer.readableBytes(); + + // https://github.com/aadnk/ProtocolLib/commit/5ec87c9d7650ae21faca9b7b3cc7ac1629870d24 + if (packet instanceof PacketPlayInCustomPayload || packet instanceof PacketPlayOutCustomPayload) { + packet.a(dataSerializer); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + dataSerializer.release(); + } + + if (sizeBytes > protocolConstants.maxPacketSizeBytes()) { + throw new OversizedPacketException(packet.getClass().getSimpleName(), from, sizeBytes); + } + } + } + + @Override + public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException { + if (_packet instanceof PacketPlayInSetCreativeSlot) { + PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet; + + ItemStack itemStack = packet.getItemStack(); + + if (itemStack == null || !itemStack.hasTag()) return; + + NbtChecks.checkPacketPlayIn(new NbtTagCompound(itemStack.getTag()), + itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), + protocolConstants, config); + } + } + + @Override + public void checkPacketPlayInUpdateSign(Object _packet) throws SignLineLengthTooLongException { + if (_packet instanceof PacketPlayInUpdateSign) { + PacketPlayInUpdateSign packet = (PacketPlayInUpdateSign) _packet; + + for (String line : packet.c()) { + if (line.length() > protocolConstants.maxSignLineLength()) { + throw new SignLineLengthTooLongException(packet.getClass().getSimpleName(), true); + } + } + } + } + + @Override + public void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException { + if (_packet instanceof PacketPlayOutSetSlot) { + PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) _packet; + + try { + Field itemStackField = packet.getClass().getDeclaredField("c"); + + itemStackField.setAccessible(true); + + ItemStack itemStack = (ItemStack) itemStackField.get(packet); + + if (itemStack == null || !itemStack.hasTag()) return; + + NbtChecks.checkPacketPlayOut(new NbtTagCompound(itemStack.getTag()), + itemStack.getItem().getClass().getSimpleName(), packet.getClass().getSimpleName(), + protocolConstants, config); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/io/PlayerInjector.java b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/io/PlayerInjector.java new file mode 100644 index 00000000..40e063f5 --- /dev/null +++ b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/io/PlayerInjector.java @@ -0,0 +1,74 @@ +package com.ruinscraft.panilla.v1_14_R1.io; + +import com.ruinscraft.panilla.api.IContainerCleaner; +import com.ruinscraft.panilla.api.IProtocolConstants; +import com.ruinscraft.panilla.api.PanillaLogger; +import com.ruinscraft.panilla.api.config.PConfig; +import com.ruinscraft.panilla.api.io.IPacketInspector; +import com.ruinscraft.panilla.api.io.IPlayerInjector; +import com.ruinscraft.panilla.api.io.PlayerInbound; +import com.ruinscraft.panilla.api.io.PlayerOutbound; +import io.netty.channel.Channel; +import net.minecraft.server.v1_14_R1.EntityPlayer; +import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class PlayerInjector implements IPlayerInjector { + + private final IPacketInspector packetInspector; + private final IContainerCleaner containerCleaner; + private final IProtocolConstants protocolConstants; + private final PConfig config; + private final PanillaLogger panillaLogger; + + public PlayerInjector(IPacketInspector packetInspector, IContainerCleaner containerCleaner, + IProtocolConstants protocolConstants, PConfig config, PanillaLogger panillaLogger) { + this.packetInspector = packetInspector; + this.containerCleaner = containerCleaner; + this.protocolConstants = protocolConstants; + this.config = config; + this.panillaLogger = panillaLogger; + } + + private static Channel getPlayerChannel(Player player) throws IllegalArgumentException { + CraftPlayer craftPlayer = (CraftPlayer) player; + EntityPlayer entityPlayer = craftPlayer.getHandle(); + + return entityPlayer.playerConnection.networkManager.channel; + } + + @Override + public void register(final Player player) { + Channel channel = getPlayerChannel(player); + + /* Register inbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_IN) == null) { + PlayerInbound inbound = new PlayerInbound(player, packetInspector, containerCleaner, + protocolConstants, config, panillaLogger); + channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_IN, inbound); + } + + /* Register outbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_OUT) == null) { + PlayerOutbound outbound = new PlayerOutbound(player, packetInspector, containerCleaner, + protocolConstants, config, panillaLogger); + channel.pipeline().addBefore(MINECRAFT_CHANNEL_DPLX, PANILLA_CHANNEL_OUT, outbound); + } + } + + @Override + public void unregister(final Player player) { + Channel channel = getPlayerChannel(player); + + /* Unregister inbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_IN) != null) { + channel.pipeline().remove(PANILLA_CHANNEL_IN); + } + + /* Unregister outbound */ + if (channel.pipeline().get(PANILLA_CHANNEL_OUT) != null) { + channel.pipeline().remove(PANILLA_CHANNEL_OUT); + } + } + +} diff --git a/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/nbt/NbtTagCompound.java b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/nbt/NbtTagCompound.java new file mode 100644 index 00000000..84fea2ff --- /dev/null +++ b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/nbt/NbtTagCompound.java @@ -0,0 +1,58 @@ +package com.ruinscraft.panilla.v1_14_R1.nbt; + +import com.ruinscraft.panilla.api.nbt.INbtTagCompound; +import com.ruinscraft.panilla.api.nbt.INbtTagList; +import com.ruinscraft.panilla.api.nbt.NbtDataType; +import net.minecraft.server.v1_14_R1.NBTTagCompound; + +import java.util.Set; + +public class NbtTagCompound implements INbtTagCompound { + + private final NBTTagCompound handle; + + public NbtTagCompound(NBTTagCompound handle) { + this.handle = handle; + } + + @Override + public boolean hasKey(String key) { + return handle.hasKey(key); + } + + @Override + public boolean hasKeyOfType(String key, NbtDataType nbtDataType) { + return handle.hasKeyOfType(key, nbtDataType.id); + } + + @Override + public Set getKeys() { + return handle.getKeys(); + } + + @Override + public int getInt(String key) { + return handle.getInt(key); + } + + @Override + public short getShort(String key) { + return handle.getShort(key); + } + + @Override + public String getString(String key) { + return handle.getString(key); + } + + @Override + public INbtTagList getList(String key, NbtDataType nbtDataType) { + return new NbtTagList(handle.getList(key, nbtDataType.id)); + } + + @Override + public INbtTagCompound getCompound(String key) { + return new NbtTagCompound(handle.getCompound(key)); + } + +} diff --git a/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/nbt/NbtTagList.java b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/nbt/NbtTagList.java new file mode 100644 index 00000000..21054fd8 --- /dev/null +++ b/v1_14_R1/src/main/java/com/ruinscraft/panilla/v1_14_R1/nbt/NbtTagList.java @@ -0,0 +1,25 @@ +package com.ruinscraft.panilla.v1_14_R1.nbt; + +import com.ruinscraft.panilla.api.nbt.INbtTagCompound; +import com.ruinscraft.panilla.api.nbt.INbtTagList; +import net.minecraft.server.v1_14_R1.NBTTagList; + +public class NbtTagList implements INbtTagList { + + private final NBTTagList handle; + + public NbtTagList(NBTTagList handle) { + this.handle = handle; + } + + @Override + public INbtTagCompound get(int index) { + return new NbtTagCompound(handle.getCompound(index)); + } + + @Override + public int size() { + return handle.size(); + } + +}