From f476c091bbb2269aa931ba7458b848d1999795fb Mon Sep 17 00:00:00 2001 From: games647 Date: Thu, 5 Apr 2018 17:33:32 +0200 Subject: [PATCH] Fix default message loading, because default values are ignored by .getKeys() --- README.md | 21 +++++++++++-------- bukkit/pom.xml | 2 +- .../fastlogin/bukkit/BukkitLoginSession.java | 8 +++---- .../protocollib/SkinApplyListener.java | 8 +++---- .../protocollib/VerifyResponseTask.java | 4 ++-- core/pom.xml | 2 +- .../fastlogin/core/shared/FastLoginCore.java | 18 +++++++++++++--- 7 files changed, 39 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 20f42607..fa3a70a7 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Checks if a Minecraft player has a paid account (premium). If so, they can skip offline authentication (auth plugins). So they don't need to enter passwords. This is also called auto login (auto-login). -### Features: +## Features * Detect paid accounts from others * Automatically login paid accounts (premium) @@ -36,18 +36,21 @@ https://ci.codemc.org/job/Games647/job/FastLogin/changes *** -### Commands: +## Commands + /premium [player] Label the invoker or the argument as paid account /cracked [player] Label the invoker or the argument as cracked account -### Permissions: +## Permissions + fastlogin.bukkit.command.premium fastlogin.bukkit.command.cracked fastlogin.command.premium.other fastlogin.command.cracked.other fastlogin.command.import -### Requirements: +## Requirements + * Plugin: * [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/) or * [ProtocolSupport](https://www.spigotmc.org/resources/protocolsupport.7201/) @@ -56,7 +59,7 @@ https://ci.codemc.org/job/Games647/job/FastLogin/changes * Run Spigot and/or BungeeCord/Waterfall in offline mode (see server.properties or config.yml) * An auth plugin. Supported plugins -#### Bukkit/Spigot/Paper +### Bukkit/Spigot/Paper * [AuthMe (5.X)](https://dev.bukkit.org/bukkit-plugins/authme-reloaded/) * [xAuth](https://dev.bukkit.org/bukkit-plugins/xauth/) @@ -66,21 +69,21 @@ https://ci.codemc.org/job/Games647/job/FastLogin/changes * [LoginSecurity](https://dev.bukkit.org/bukkit-plugins/loginsecurity/) * [UltraAuth](https://dev.bukkit.org/bukkit-plugins/ultraauth-aa/) -#### BungeeCord/Waterfall +### BungeeCord/Waterfall * [BungeeAuth](https://www.spigotmc.org/resources/bungeeauth.493/) *** -### How to install +## How to install -#### Bukkit/Spigot/Paper +### Bukkit/Spigot/Paper 1. Download and install ProtocolLib/ProtocolSupport 2. Download and install FastLogin (or FastLoginBukkit for newer versions) 3. Set your server in offline mode by setting the value onlinemode in your server.properties to false -#### BungeeCord/Waterfall +### BungeeCord/Waterfall 1. Activate BungeeCord in the Spigot configuration 2. Restart your server diff --git a/bukkit/pom.xml b/bukkit/pom.xml index c3368768..f95fc672 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -130,7 +130,7 @@ me.clip placeholderapi - 2.8.4 + 2.8.5 provided true diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java index dc458373..b8e70835 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java @@ -1,6 +1,6 @@ package com.github.games647.fastlogin.bukkit; -import com.github.games647.craftapi.model.skin.SkinProperty; +import com.github.games647.craftapi.model.skin.Property; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.shared.LoginSession; @@ -20,7 +20,7 @@ public class BukkitLoginSession extends LoginSession { private boolean verified; - private SkinProperty skinProperty; + private Property skinProperty; public BukkitLoginSession(String username, String serverId, byte[] verifyToken, boolean registered , StoredProfile profile) { @@ -54,7 +54,7 @@ public class BukkitLoginSession extends LoginSession { /** * @return premium skin if available */ - public synchronized Optional getSkin() { + public synchronized Optional getSkin() { return Optional.ofNullable(skinProperty); } @@ -62,7 +62,7 @@ public class BukkitLoginSession extends LoginSession { * Sets the premium skin property which was retrieved by the session server * @param skinProperty premium skin */ - public synchronized void setSkinProperty(SkinProperty skinProperty) { + public synchronized void setSkinProperty(Property skinProperty) { this.skinProperty = skinProperty; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/SkinApplyListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/SkinApplyListener.java index fa146d04..0de8bed4 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/SkinApplyListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/SkinApplyListener.java @@ -6,7 +6,7 @@ import com.comphenix.protocol.reflect.accessors.MethodAccessor; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedSignedProperty; -import com.github.games647.craftapi.model.skin.SkinProperty; +import com.github.games647.craftapi.model.skin.Property; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; @@ -54,14 +54,14 @@ public class SkinApplyListener implements Listener { private void applySkin(Player player, String skinData, String signature) { WrappedGameProfile gameProfile = WrappedGameProfile.fromPlayer(player); - WrappedSignedProperty skin = WrappedSignedProperty.fromValues(SkinProperty.TEXTURE_KEY, skinData, signature); + WrappedSignedProperty skin = WrappedSignedProperty.fromValues(Property.TEXTURE_KEY, skinData, signature); try { - gameProfile.getProperties().put(SkinProperty.TEXTURE_KEY, skin); + gameProfile.getProperties().put(Property.TEXTURE_KEY, skin); } catch (ClassCastException castException) { //Cauldron, MCPC, Thermos, ... Object map = GET_PROPERTIES.invoke(gameProfile.getHandle()); try { - MethodUtils.invokeMethod(map, "put", new Object[]{SkinProperty.TEXTURE_KEY, skin.getHandle()}); + MethodUtils.invokeMethod(map, "put", new Object[]{Property.TEXTURE_KEY, skin.getHandle()}); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { plugin.getLog().error("Error setting premium skin of: {}", player, ex); } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java index 784fdc4c..b6bb0dad 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java @@ -9,7 +9,7 @@ import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.github.games647.craftapi.model.auth.Verification; -import com.github.games647.craftapi.model.skin.SkinProperty; +import com.github.games647.craftapi.model.skin.Property; import com.github.games647.craftapi.resolver.MojangResolver; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.EncryptionUtil; @@ -108,7 +108,7 @@ public class VerifyResponseTask implements Runnable { if (response.isPresent()) { plugin.getLog().info("GameProfile {} has a verified premium account", username); - SkinProperty[] properties = response.get().getProperties(); + Property[] properties = response.get().getProperties(); if (properties.length > 0) { session.setSkinProperty(properties[0]); } diff --git a/core/pom.xml b/core/pom.xml index 4f6de23e..fdb81815 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -33,7 +33,7 @@ com.zaxxer HikariCP - 2.7.8 + 3.0.0 diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java index 3c345e18..7828a66a 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java @@ -11,6 +11,7 @@ import com.google.common.net.HostAndPort; import java.io.IOException; import java.io.InputStream; +import java.io.Reader; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Proxy; @@ -103,15 +104,26 @@ public class FastLoginCore

> { } private Configuration loadFile(String fileName) throws IOException { - Configuration defaults; - ConfigurationProvider configProvider = ConfigurationProvider.getProvider(YamlConfiguration.class); + + Configuration defaults; try (InputStream defaultStream = getClass().getClassLoader().getResourceAsStream(fileName)) { defaults = configProvider.load(defaultStream); } Path file = plugin.getPluginFolder().resolve(fileName); - return configProvider.load(Files.newBufferedReader(file), defaults); + + Configuration config; + try (Reader reader = Files.newBufferedReader(file)) { + config = configProvider.load(reader); + } + + //explicitly add keys here, because Configuration.getKeys doesn't return the keys from the default configuration + for (String key : defaults.getKeys()) { + config.set(key, defaults.get(key)); + } + + return config; } public MojangResolver getResolver() {