From 2510751fdf2da64e67f21de63c73e7209de244ae Mon Sep 17 00:00:00 2001 From: Myles Date: Tue, 21 Aug 2018 16:26:04 +0100 Subject: [PATCH] Introduce 'suppress-1_13-conversion-errors' option --- .../bukkit/platform/BukkitConfigAPI.java | 5 +++++ .../bungee/platform/BungeeConfigAPI.java | 5 +++++ .../myles/ViaVersion/api/ViaVersionConfig.java | 7 +++++++ .../protocol1_13to1_12_2/MetadataRewriter.java | 1 - .../protocol1_13to1_12_2/data/MappingData.java | 12 +++++++++--- .../packets/InventoryPackets.java | 17 ++++++++++++----- .../packets/WorldPackets.java | 15 ++++++++++----- .../blockentities/FlowerPotHandler.java | 4 +++- .../main/resources/assets/viaversion/config.yml | 2 ++ .../sponge/platform/SpongeConfigAPI.java | 5 +++++ 10 files changed, 58 insertions(+), 15 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java index c55a407ee..c46b0e21d 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java @@ -204,4 +204,9 @@ public class BukkitConfigAPI extends Config implements ViaVersionConfig { public boolean is1_13TeamColourFix() { return getBoolean("team-colour-fix", true); } + + @Override + public boolean isSuppress1_13ConversionErrors() { + return getBoolean("suppress-1_13-conversion-errors", false); + } } diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java index 79ae44916..768dd7887 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java @@ -257,4 +257,9 @@ public class BungeeConfigAPI extends Config implements ViaVersionConfig { public boolean is1_13TeamColourFix() { return getBoolean("team-colour-fix", true); } + + @Override + public boolean isSuppress1_13ConversionErrors() { + return getBoolean("suppress-1_13-conversion-errors", false); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java index 106ad9d40..cfba9fc1c 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -245,4 +245,11 @@ public interface ViaVersionConfig { * @return Disconnect message */ String getReloadDisconnectMsg(); + + /** + * Should we hide errors that occur when trying to converting to 1.13 data? + * + * @return True if enabled + */ + boolean isSuppress1_13ConversionErrors(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java index 38e9e7dcc..54196f66c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java @@ -10,7 +10,6 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import java.util.ArrayList; import java.util.List; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java index 92fd44f30..e73f18c09 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java @@ -63,7 +63,9 @@ public class MappingData { for (Map.Entry entry : oldIdentifiers.entrySet()) { Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); if (value == null) { - Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); + } continue; } output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey())); @@ -74,7 +76,9 @@ public class MappingData { for (Map.Entry entry : oldIdentifiers.entrySet()) { Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); if (value == null) { - Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); + } continue; } output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey()); @@ -97,7 +101,9 @@ public class MappingData { JsonElement v = oldIdentifiers.get(i); Integer index = findIndex(newIdentifiers, v.getAsString()); if (index == null) { - Via.getPlatform().getLogger().warning("No key for " + v + " :( "); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("No key for " + v + " :( "); + } continue; } output[i] = index.shortValue(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 574d6704b..fce53597a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -113,8 +113,11 @@ public class InventoryPackets { flags |= 1; Optional finalSource = SoundSource.findBySource(originalSource); if (!finalSource.isPresent()) { - Via.getPlatform().getLogger().info("Could not handle unknown sound source " + originalSource + " falling back to default: master"); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().info("Could not handle unknown sound source " + originalSource + " falling back to default: master"); + } finalSource = Optional.of(SoundSource.MASTER); + } wrapper.write(Type.VAR_INT, finalSource.get().getId()); @@ -165,7 +168,7 @@ public class InventoryPackets { String rewritten = getNewPluginChannelId(channels[i]); if (rewritten != null) { rewrittenChannels.add(rewritten); - } else { + } else if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Ignoring plugin channel in REGISTER: " + channels[i]); } } @@ -244,7 +247,7 @@ public class InventoryPackets { String rewritten = getOldPluginChannelId(channels[i]); if (rewritten != null) { rewrittenChannels.add(rewritten); - } else { + } else if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Ignoring plugin channel in REGISTER: " + channels[i]); } } @@ -408,7 +411,9 @@ public class InventoryPackets { } else if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) { rawId &= ~0xF; // Remove data } else { - Via.getPlatform().getLogger().warning("Failed to get 1.13 item for " + item.getId()); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("Failed to get 1.13 item for " + item.getId()); + } rawId = 16; // Stone } } @@ -489,7 +494,9 @@ public class InventoryPackets { } if (rawId == null) { - Via.getPlatform().getLogger().warning("Failed to get 1.12 item for " + item.getId()); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("Failed to get 1.12 item for " + item.getId()); + } rawId = 0x10000; // Stone } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index d8378e077..95146d8ed 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -28,7 +28,6 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; public class WorldPackets { @@ -72,7 +71,7 @@ public class WorldPackets { Optional id = provider.getIntByIdentifier(motive); - if (!id.isPresent()) { + if (!id.isPresent() && (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug())) { Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)"); } wrapper.write(Type.VAR_INT, id.or(0)); @@ -277,7 +276,9 @@ public class WorldPackets { if (!validBiomes.contains(biome)) { if (biome != 255 // is it generated naturally? *shrug* && latestBiomeWarn != biome) { - Via.getPlatform().getLogger().warning("Received invalid biome id " + biome); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("Received invalid biome id " + biome); + } latestBiomeWarn = biome; } chunk.getBiomeData()[i] = 1; // Plains @@ -386,10 +387,14 @@ public class WorldPackets { } newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data if (newId != -1) { - Via.getPlatform().getLogger().warning("Missing block " + oldId); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("Missing block " + oldId); + } return newId; } - Via.getPlatform().getLogger().warning("Missing block completely " + oldId); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("Missing block completely " + oldId); + } // Default stone return 1; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java index 1bd406184..244afae94 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java @@ -61,7 +61,9 @@ public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler } else if (flowersNumberId.containsKey(pair)) { return flowersNumberId.get(pair); } else { - Via.getPlatform().getLogger().warning("Could not find flowerpot content " + item + " for " + tag); + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("Could not find flowerpot content " + item + " for " + tag); + } } return -1; diff --git a/common/src/main/resources/assets/viaversion/config.yml b/common/src/main/resources/assets/viaversion/config.yml index c72913019..22df7ea89 100644 --- a/common/src/main/resources/assets/viaversion/config.yml +++ b/common/src/main/resources/assets/viaversion/config.yml @@ -88,6 +88,8 @@ chat-nbt-fix: true quick-move-action-fix: false # Should we use prefix for team colour on 1.13 and above clients team-colour-fix: true +# We warn when there's a error converting from pre-1.13 to 1.13, should we suppress these? (Only suggested if spamming) +suppress-1_13-conversion-errors: false # #----------------------------------------------------------# # 1.9 & 1.10 CLIENTS ON 1.8 SERVERS OPTIONS # diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java index a6088b53f..0acbc44b2 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java @@ -210,4 +210,9 @@ public class SpongeConfigAPI extends Config implements ViaVersionConfig { public boolean is1_13TeamColourFix() { return getBoolean("team-colour-fix", true); } + + @Override + public boolean isSuppress1_13ConversionErrors() { + return getBoolean("suppress-1_13-conversion-errors", false); + } }