diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ceeec0..a95bb94f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +######1.1 + +* Make the configuration options also work under BungeeCord (premiumUUID, forwardSkin) + ######1.0 * Massive refactor to handle errors on force actions safely diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 8728060e..3a6b3725 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ com.github.games647 fastlogin - 1.0 + 1.1 ../pom.xml diff --git a/bungee/pom.xml b/bungee/pom.xml index 0968786c..212799e9 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ com.github.games647 fastlogin - 1.0 + 1.1 ../pom.xml diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index 04c6f34d..3047ab75 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -13,8 +13,9 @@ import java.util.UUID; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import net.md_5.bungee.api.connection.PendingConnection; +import net.md_5.bungee.Util; +import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; @@ -25,17 +26,13 @@ import net.md_5.bungee.config.YamlConfiguration; */ public class FastLoginBungee extends Plugin { - public static UUID parseId(String withoutDashes) { - return UUID.fromString(withoutDashes.substring(0, 8) - + "-" + withoutDashes.substring(8, 12) - + "-" + withoutDashes.substring(12, 16) - + "-" + withoutDashes.substring(16, 20) - + "-" + withoutDashes.substring(20, 32)); - } - private static final char[] CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" .toCharArray(); + public static UUID parseId(String withoutDashes) { + return Util.getUUID(withoutDashes); + } + private BungeeAuthPlugin bungeeAuthPlugin; private final MojangApiConnector mojangApiConnector = new MojangApiConnector(this); private Storage storage; diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/ForceLoginTask.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/ForceLoginTask.java index d31f5d02..ceb4b2d9 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/ForceLoginTask.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/ForceLoginTask.java @@ -30,7 +30,7 @@ public class ForceLoginTask implements Runnable { BungeeAuthPlugin authPlugin = plugin.getBungeeAuthPlugin(); if (authPlugin == null) { sendBukkitLoginNotification(autoRegister); - } else { + } else if (player.isConnected()) { if (autoRegister) { String password = plugin.generateStringPassword(); if (authPlugin.forceRegister(player, password)) { @@ -66,6 +66,8 @@ public class ForceLoginTask implements Runnable { dataOutput.writeLong(proxyId.getLeastSignificantBits()); Server server = player.getServer(); - server.sendData(plugin.getDescription().getName(), dataOutput.toByteArray()); + if (server != null) { + server.sendData(plugin.getDescription().getName(), dataOutput.toByteArray()); + } } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java index bbee4ceb..10a89b47 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java @@ -1,8 +1,10 @@ package com.github.games647.fastlogin.bungee; import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin; +import com.google.common.base.Charsets; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; +import java.lang.reflect.Field; import java.util.UUID; import java.util.logging.Level; @@ -14,9 +16,13 @@ import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.event.PreLoginEvent; import net.md_5.bungee.api.event.ServerConnectedEvent; import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.connection.InitialHandler; +import net.md_5.bungee.connection.LoginResult; +import net.md_5.bungee.connection.LoginResult.Property; import net.md_5.bungee.event.EventHandler; /** @@ -74,6 +80,42 @@ public class PlayerConnectionListener implements Listener { }); } + @EventHandler + public void onLogin(PostLoginEvent loginEvent) { + ProxiedPlayer player = loginEvent.getPlayer(); + PendingConnection connection = player.getPendingConnection(); + String username = connection.getName(); + if (connection.isOnlineMode()) { + PlayerProfile playerProfile = plugin.getStorage().getProfile(player.getName(), false); + playerProfile.setUuid(player.getUniqueId()); + + //bungeecord will do this automatically so override it on disabled option + InitialHandler initialHandler = (InitialHandler) connection; + if (!plugin.getConfiguration().getBoolean("premiumUuid")) { + try { + UUID offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(Charsets.UTF_8)); + + Field idField = initialHandler.getClass().getDeclaredField("uniqueId"); + idField.setAccessible(true); + idField.set(connection, offlineUUID); + + //bungeecord doesn't support overriding the premium uuid +// connection.setUniqueId(offlineUUID); + } catch (NoSuchFieldException | IllegalAccessException ex) { + plugin.getLogger().log(Level.SEVERE, "Failed to set offline uuid", ex); + } + } + + if (!plugin.getConfiguration().getBoolean("forwardSkin")) { + //this is null on offline mode + LoginResult loginProfile = initialHandler.getLoginProfile(); + if (loginProfile != null) { + loginProfile.setProperties(new Property[]{}); + } + } + } + } + @EventHandler public void onServerConnected(ServerConnectedEvent serverConnectedEvent) { ProxiedPlayer player = serverConnectedEvent.getPlayer(); @@ -145,7 +187,8 @@ public class PlayerConnectionListener implements Listener { //update only on success to prevent corrupt data PlayerProfile playerProfile = plugin.getStorage().getProfile(forPlayer.getName(), false); playerProfile.setPremium(true); - playerProfile.setUuid(forPlayer.getUniqueId()); + //we override this in the loginevent +// playerProfile.setUuid(forPlayer.getUniqueId()); plugin.getStorage().save(playerProfile); } } diff --git a/pom.xml b/pom.xml index 13f6efea..4c2014c2 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ pom FastLogin - 1.0 + 1.1 2015 https://www.spigotmc.org/resources/fastlogin.14153/ diff --git a/universal/pom.xml b/universal/pom.xml index a5e6747e..105b4d75 100644 --- a/universal/pom.xml +++ b/universal/pom.xml @@ -5,7 +5,7 @@ com.github.games647 fastlogin - 1.0 + 1.1 ../pom.xml