From 907516eb71947b42b754c817cb4ccab1f38f6b98 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Fri, 22 Nov 2019 22:00:41 +0100 Subject: [PATCH] Hold config values in fields --- .../bukkit/platform/BukkitViaConfig.java | 38 +++- .../bungee/platform/BungeeViaConfig.java | 38 ++-- .../myles/ViaVersion/AbstractViaConfig.java | 199 +++++++++++++----- .../ViaVersion/api/ViaVersionConfig.java | 4 +- .../java/us/myles/ViaVersion/util/Config.java | 2 +- .../sponge/platform/SpongeViaConfig.java | 21 -- .../velocity/platform/VelocityViaConfig.java | 38 ++-- 7 files changed, 215 insertions(+), 125 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java index 49d7cf670..74caf2949 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java @@ -1,7 +1,7 @@ package us.myles.ViaVersion.bukkit.platform; +import org.bukkit.plugin.Plugin; import us.myles.ViaVersion.AbstractViaConfig; -import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.api.Via; import java.io.File; @@ -12,13 +12,25 @@ import java.util.Map; public class BukkitViaConfig extends AbstractViaConfig { private static final List UNSUPPORTED = Arrays.asList("bungee-ping-interval", "bungee-ping-save", "bungee-servers", "velocity-ping-interval", "velocity-ping-save", "velocity-servers"); + private boolean antiXRay; + private boolean quickMoveActionFix; + private boolean hitboxFix1_9; + private boolean hitboxFix1_14; public BukkitViaConfig() { - super(new File(((ViaVersionPlugin) Via.getPlatform()).getDataFolder(), "config.yml")); - // Load config + super(new File(((Plugin) Via.getPlatform()).getDataFolder(), "config.yml")); reloadConfig(); } + @Override + protected void loadFields() { + super.loadFields(); + antiXRay = getBoolean("anti-xray-patch", true); + quickMoveActionFix = getBoolean("quick-move-action-fix", false); + hitboxFix1_9 = getBoolean("change-1_9-hitbox", false); + hitboxFix1_14 = getBoolean("change-1_14-hitbox", false); + } + @Override public URL getDefaultConfigURL() { return BukkitViaConfig.class.getClassLoader().getResource("assets/viaversion/config.yml"); @@ -28,6 +40,26 @@ public class BukkitViaConfig extends AbstractViaConfig { protected void handleConfig(Map config) { } + @Override + public boolean isAntiXRay() { + return antiXRay; + } + + @Override + public boolean is1_12QuickMoveActionFix() { + return quickMoveActionFix; + } + + @Override + public boolean is1_9HitboxFix() { + return hitboxFix1_9; + } + + @Override + public boolean is1_14HitboxFix() { + return hitboxFix1_14; + } + @Override public List getUnsupportedOptions() { return UNSUPPORTED; diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java index 2484e07cf..603a270e7 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java @@ -10,13 +10,23 @@ import java.util.*; public class BungeeViaConfig extends AbstractViaConfig { private static final List UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "anti-xray-patch", "quick-move-action-fix", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", "blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox"); + private int bungeePingInterval; + private boolean bungeePingSave; + private Map bungeeServerProtocols; public BungeeViaConfig(File configFile) { super(new File(configFile, "config.yml")); - // Load config reloadConfig(); } + @Override + protected void loadFields() { + super.loadFields(); + bungeePingInterval = getInt("bungee-ping-interval", 60); + bungeePingSave = getBoolean("bungee-ping-save", true); + bungeeServerProtocols = get("bungee-servers", Map.class, new HashMap<>()); + } + @Override public URL getDefaultConfigURL() { return BungeeViaConfig.class.getClassLoader().getResource("assets/viaversion/config.yml"); @@ -59,11 +69,6 @@ public class BungeeViaConfig extends AbstractViaConfig { return UNSUPPORTED; } - @Override - public boolean isAntiXRay() { - return false; - } - @Override public boolean isItemCache() { return false; @@ -74,26 +79,11 @@ public class BungeeViaConfig extends AbstractViaConfig { return false; } - @Override - public boolean is1_12QuickMoveActionFix() { - return false; - } - @Override public String getBlockConnectionMethod() { return "packet"; } - @Override - public boolean is1_9HitboxFix() { - return false; - } - - @Override - public boolean is1_14HitboxFix() { - return false; - } - /** * What is the interval for checking servers via ping * -1 for disabled @@ -101,7 +91,7 @@ public class BungeeViaConfig extends AbstractViaConfig { * @return Ping interval in seconds */ public int getBungeePingInterval() { - return getInt("bungee-ping-interval", 60); + return bungeePingInterval; } /** @@ -110,7 +100,7 @@ public class BungeeViaConfig extends AbstractViaConfig { * @return True if it should save */ public boolean isBungeePingSave() { - return getBoolean("bungee-ping-save", true); + return bungeePingSave; } /** @@ -120,6 +110,6 @@ public class BungeeViaConfig extends AbstractViaConfig { * @return Map of String, Integer */ public Map getBungeeServerProtocols() { - return get("bungee-servers", Map.class, new HashMap<>()); + return bungeeServerProtocols; } } diff --git a/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java b/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java index 175093948..09caf8007 100644 --- a/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java @@ -4,252 +4,351 @@ import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.util.Config; import java.io.File; -import java.util.List; +import java.util.HashSet; +import java.util.Set; public abstract class AbstractViaConfig extends Config implements ViaVersionConfig { + private boolean checkForUpdates; + private boolean preventCollision; + private boolean useNewEffectIndicator; + private boolean useNewDeathmessages; + private boolean suppressMetadataErrors; + private boolean shieldBlocking; + private boolean hologramPatch; + private boolean pistonAnimationPatch; + private boolean bossbarPatch; + private boolean bossbarAntiFlicker; + private double hologramOffset; + private int maxPPS; + private String maxPPSKickMessage; + private int trackingPeriod; + private int warningPPS; + private int maxPPSWarnings; + private String maxPPSWarningsKickMessage; + private boolean sendSupportedVersions; + private boolean simulatePlayerTick; + private boolean itemCache; + private boolean nmsPlayerTicking; + private boolean replacePistons; + private int pistonReplacementId; + private boolean autoTeam; + private boolean forceJsonTransform; + private boolean nbtArrayFix; + private Set blockedProtocols; + private String blockedDisconnectMessage; + private String reloadDisconnectMessage; + private boolean suppress1_13ConversionErrors; + private boolean disable1_13TabComplete; + private boolean minimizeCooldown; + private boolean teamColourFix; + private boolean serversideBlockConnections; + private String blockConnectionMethod; + private boolean reduceBlockStorageMemory; + private boolean flowerStemWhenBlockAbove; + private boolean snowCollisionFix; + private int tabCompleteDelay; + private boolean truncate1_14Books; + private boolean leftHandedHandling; + private boolean fullBlockLightFix; + private boolean healthNaNFix; + private boolean instantRespawn; + protected AbstractViaConfig(File configFile) { super(configFile); } + @Override + public void reloadConfig() { + super.reloadConfig(); + loadFields(); + } + + protected void loadFields() { + checkForUpdates = getBoolean("checkforupdates", true); + preventCollision = getBoolean("prevent-collision", true); + useNewEffectIndicator = getBoolean("use-new-effect-indicator", true); + useNewDeathmessages = getBoolean("use-new-deathmessages", true); + suppressMetadataErrors = getBoolean("suppress-metadata-errors", false); + shieldBlocking = getBoolean("shield-blocking", true); + hologramPatch = getBoolean("hologram-patch", false); + pistonAnimationPatch = getBoolean("piston-animation-patch", false); + bossbarPatch = getBoolean("bossbar-patch", true); + bossbarAntiFlicker = getBoolean("bossbar-anti-flicker", false); + hologramOffset = getDouble("hologram-y", -0.96D); + maxPPS = getInt("max-pps", 800); + maxPPSKickMessage = getString("max-pps-kick-msg", "Sending packets too fast? lag?"); + trackingPeriod = getInt("tracking-period", 6); + warningPPS = getInt("tracking-warning-pps", 120); + maxPPSWarnings = getInt("tracking-max-warnings", 3); + maxPPSWarningsKickMessage = getString("tracking-max-kick-msg", "You are sending too many packets, :("); + sendSupportedVersions = getBoolean("send-supported-versions", false); + simulatePlayerTick = getBoolean("simulate-pt", true); + itemCache = getBoolean("item-cache", true); + nmsPlayerTicking = getBoolean("nms-player-ticking", true); + replacePistons = getBoolean("replace-pistons", false); + pistonReplacementId = getInt("replacement-piston-id", 0); + autoTeam = getBoolean("auto-team", true); + forceJsonTransform = getBoolean("force-json-transform", false); + nbtArrayFix = getBoolean("chat-nbt-fix", true); + blockedProtocols = new HashSet<>(getIntegerList("block-protocols")); + blockedDisconnectMessage = getString("block-disconnect-msg", "You are using an unsupported Minecraft version!"); + reloadDisconnectMessage = getString("reload-disconnect-msg", "Server reload, please rejoin!"); + suppress1_13ConversionErrors = getBoolean("minimize-cooldown", true); + disable1_13TabComplete = getBoolean("team-colour-fix", true); + minimizeCooldown = getBoolean("suppress-1_13-conversion-errors", false); + teamColourFix = getBoolean("disable-1_13-auto-complete", false); + serversideBlockConnections = getBoolean("serverside-blockconnections", false); + blockConnectionMethod = getString("blockconnection-method", "packet"); + reduceBlockStorageMemory = getBoolean("reduce-blockstorage-memory", false); + flowerStemWhenBlockAbove = getBoolean("flowerstem-when-block-above", false); + snowCollisionFix = getBoolean("fix-low-snow-collision", false); + tabCompleteDelay = getInt("1_13-tab-complete-delay", 0); + truncate1_14Books = getBoolean("truncate-1_14-books", false); + leftHandedHandling = getBoolean("left-handed-handling", true); + fullBlockLightFix = getBoolean("fix-non-full-blocklight", false); + healthNaNFix = getBoolean("fix-1_14-health-nan", true); + instantRespawn = getBoolean("use-1_15-instant-respawn", false); + } + @Override public boolean isCheckForUpdates() { - return getBoolean("checkforupdates", true); + return checkForUpdates; } @Override public boolean isPreventCollision() { - return getBoolean("prevent-collision", true); + return preventCollision; } @Override public boolean isNewEffectIndicator() { - return getBoolean("use-new-effect-indicator", true); + return useNewEffectIndicator; } @Override public boolean isShowNewDeathMessages() { - return getBoolean("use-new-deathmessages", true); + return useNewDeathmessages; } @Override public boolean isSuppressMetadataErrors() { - return getBoolean("suppress-metadata-errors", false); + return suppressMetadataErrors; } @Override public boolean isShieldBlocking() { - return getBoolean("shield-blocking", true); + return shieldBlocking; } @Override public boolean isHologramPatch() { - return getBoolean("hologram-patch", false); + return hologramPatch; } @Override public boolean isPistonAnimationPatch() { - return getBoolean("piston-animation-patch", false); + return pistonAnimationPatch; } @Override public boolean isBossbarPatch() { - return getBoolean("bossbar-patch", true); + return bossbarPatch; } @Override public boolean isBossbarAntiflicker() { - return getBoolean("bossbar-anti-flicker", false); + return bossbarAntiFlicker; } @Override public double getHologramYOffset() { - return getDouble("hologram-y", -0.96D); + return hologramOffset; } @Override public int getMaxPPS() { - return getInt("max-pps", 800); + return maxPPS; } @Override public String getMaxPPSKickMessage() { - return getString("max-pps-kick-msg", "Sending packets too fast? lag?"); + return maxPPSKickMessage; } @Override public int getTrackingPeriod() { - return getInt("tracking-period", 6); + return trackingPeriod; } @Override public int getWarningPPS() { - return getInt("tracking-warning-pps", 120); + return warningPPS; } @Override public int getMaxWarnings() { - return getInt("tracking-max-warnings", 3); + return maxPPSWarnings; } @Override public String getMaxWarningsKickMessage() { - return getString("tracking-max-kick-msg", "You are sending too many packets, :("); + return maxPPSWarningsKickMessage; } @Override public boolean isAntiXRay() { - return getBoolean("anti-xray-patch", true); + return false; } @Override public boolean isSendSupportedVersions() { - return getBoolean("send-supported-versions", false); + return sendSupportedVersions; } @Override public boolean isStimulatePlayerTick() { - return getBoolean("simulate-pt", true); + return simulatePlayerTick; } @Override public boolean isItemCache() { - return getBoolean("item-cache", true); + return itemCache; } @Override public boolean isNMSPlayerTicking() { - return getBoolean("nms-player-ticking", true); + return nmsPlayerTicking; } @Override public boolean isReplacePistons() { - return getBoolean("replace-pistons", false); + return replacePistons; } @Override public int getPistonReplacementId() { - return getInt("replacement-piston-id", 0); + return pistonReplacementId; } @Override public boolean isAutoTeam() { // Collision has to be enabled first - return isPreventCollision() && getBoolean("auto-team", true); + return isPreventCollision() && autoTeam; } @Override public boolean isForceJsonTransform() { - return getBoolean("force-json-transform", false); + return forceJsonTransform; } @Override public boolean is1_12NBTArrayFix() { - return getBoolean("chat-nbt-fix", true); + return nbtArrayFix; } @Override public boolean is1_12QuickMoveActionFix() { - return getBoolean("quick-move-action-fix", false); + return false; } @Override - public List getBlockedProtocols() { - return getIntegerList("block-protocols"); + public Set getBlockedProtocols() { + return blockedProtocols; } @Override public String getBlockedDisconnectMsg() { - return getString("block-disconnect-msg", "You are using an unsupported Minecraft version!"); + return blockedDisconnectMessage; } @Override public String getReloadDisconnectMsg() { - return getString("reload-disconnect-msg", "Server reload, please rejoin!"); + return reloadDisconnectMessage; } @Override public boolean isMinimizeCooldown() { - return getBoolean("minimize-cooldown", true); + return suppress1_13ConversionErrors; } @Override public boolean is1_13TeamColourFix() { - return getBoolean("team-colour-fix", true); + return disable1_13TabComplete; } @Override public boolean isSuppress1_13ConversionErrors() { - return getBoolean("suppress-1_13-conversion-errors", false); + return minimizeCooldown; } @Override public boolean isDisable1_13AutoComplete() { - return getBoolean("disable-1_13-auto-complete", false); + return teamColourFix; } @Override public boolean isServersideBlockConnections() { - return getBoolean("serverside-blockconnections", false); + return serversideBlockConnections; } @Override public String getBlockConnectionMethod() { - return getString("blockconnection-method", "packet"); + return blockConnectionMethod; } @Override public boolean isReduceBlockStorageMemory() { - return getBoolean("reduce-blockstorage-memory", false); + return reduceBlockStorageMemory; } @Override public boolean isStemWhenBlockAbove() { - return getBoolean("flowerstem-when-block-above", false); + return flowerStemWhenBlockAbove; } @Override public boolean isSnowCollisionFix() { - return getBoolean("fix-low-snow-collision", false); + return snowCollisionFix; } @Override public int get1_13TabCompleteDelay() { - return getInt("1_13-tab-complete-delay", 0); + return tabCompleteDelay; } @Override public boolean isTruncate1_14Books() { - return getBoolean("truncate-1_14-books", false); + return truncate1_14Books; } @Override public boolean isLeftHandedHandling() { - return getBoolean("left-handed-handling", true); + return leftHandedHandling; } @Override public boolean is1_9HitboxFix() { - return getBoolean("change-1_9-hitbox", false); + return false; } @Override public boolean is1_14HitboxFix() { - return getBoolean("change-1_14-hitbox", false); + return false; } @Override public boolean isNonFullBlockLightFix() { - return getBoolean("fix-non-full-blocklight", false); + return fullBlockLightFix; } @Override public boolean is1_14HealthNaNFix() { - return getBoolean("fix-1_14-health-nan", true); + return healthNaNFix; } @Override public boolean is1_15InstantRespawn() { - return getBoolean("use-1_15-instant-respawn", false); + return instantRespawn; } } 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 3ef26d04d..b321698bf 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -1,6 +1,6 @@ package us.myles.ViaVersion.api; -import java.util.List; +import java.util.Set; public interface ViaVersionConfig { @@ -213,7 +213,7 @@ public interface ViaVersionConfig { * * @return An Integer list */ - List getBlockedProtocols(); + Set getBlockedProtocols(); /** * Get the custom disconnect message diff --git a/common/src/main/java/us/myles/ViaVersion/util/Config.java b/common/src/main/java/us/myles/ViaVersion/util/Config.java index 0ad123812..522d18cfc 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/Config.java +++ b/common/src/main/java/us/myles/ViaVersion/util/Config.java @@ -24,7 +24,7 @@ public abstract class Config implements ConfigurationProvider { private final CommentStore commentStore = new CommentStore('.', 2); private final File configFile; - private ConcurrentSkipListMap config; + private Map config; /** * Create a new Config instance, this will *not* load the config by default. diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java index 5193ebe3e..1306b754b 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java @@ -18,7 +18,6 @@ public class SpongeViaConfig extends AbstractViaConfig { public SpongeViaConfig(PluginContainer pluginContainer, File configFile) { super(new File(configFile, "config.yml")); this.pluginContainer = pluginContainer; - // Load config reloadConfig(); } @@ -39,24 +38,4 @@ public class SpongeViaConfig extends AbstractViaConfig { public List getUnsupportedOptions() { return UNSUPPORTED; } - - @Override - public boolean isAntiXRay() { - return false; - } - - @Override - public boolean is1_12QuickMoveActionFix() { - return false; - } - - @Override - public boolean is1_9HitboxFix() { - return false; - } - - @Override - public boolean is1_14HitboxFix() { - return false; - } } diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java index ff0489b68..378c00968 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java @@ -9,13 +9,23 @@ import java.util.*; public class VelocityViaConfig extends AbstractViaConfig { private static final List UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "anti-xray-patch", "quick-move-action-fix", "bungee-ping-interval", "bungee-ping-save", "bungee-servers", "blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox"); + private int velocityPingInterval; + private boolean velocityPingSave; + private Map velocityServerProtocols; public VelocityViaConfig(File configFile) { super(new File(configFile, "config.yml")); - // Load config reloadConfig(); } + @Override + protected void loadFields() { + super.loadFields(); + velocityPingInterval = getInt("velocity-ping-interval", 60); + velocityPingSave = getBoolean("velocity-ping-save", true); + velocityServerProtocols = get("velocity-servers", Map.class, new HashMap<>()); + } + @Override public URL getDefaultConfigURL() { return getClass().getClassLoader().getResource("assets/viaversion/config.yml"); @@ -64,11 +74,6 @@ public class VelocityViaConfig extends AbstractViaConfig { return UNSUPPORTED; } - @Override - public boolean isAntiXRay() { - return false; - } - @Override public boolean isItemCache() { return false; @@ -79,26 +84,11 @@ public class VelocityViaConfig extends AbstractViaConfig { return false; } - @Override - public boolean is1_12QuickMoveActionFix() { - return false; - } - @Override public String getBlockConnectionMethod() { return "packet"; } - @Override - public boolean is1_9HitboxFix() { - return false; - } - - @Override - public boolean is1_14HitboxFix() { - return false; - } - /** * What is the interval for checking servers via ping * -1 for disabled @@ -106,7 +96,7 @@ public class VelocityViaConfig extends AbstractViaConfig { * @return Ping interval in seconds */ public int getVelocityPingInterval() { - return getInt("velocity-ping-interval", 60); + return velocityPingInterval; } /** @@ -115,7 +105,7 @@ public class VelocityViaConfig extends AbstractViaConfig { * @return True if it should save */ public boolean isVelocityPingSave() { - return getBoolean("velocity-ping-save", true); + return velocityPingSave; } /** @@ -125,6 +115,6 @@ public class VelocityViaConfig extends AbstractViaConfig { * @return Map of String, Integer */ public Map getVelocityServerProtocols() { - return get("velocity-servers", Map.class, new HashMap<>()); + return velocityServerProtocols; } }