From aa772ddf1bc4a95333be27dda38dd1b06a3aef28 Mon Sep 17 00:00:00 2001 From: Tux Date: Sun, 21 Sep 2014 13:56:46 -0400 Subject: [PATCH] Reformat source code. --- pom.xml | 13 +++-- .../minecraft/redisbungee/DataManager.java | 22 ++++---- .../minecraft/redisbungee/RedisBungee.java | 25 ++++----- .../minecraft/redisbungee/RedisBungeeAPI.java | 14 ++--- .../redisbungee/RedisBungeeCommands.java | 2 +- .../redisbungee/RedisBungeeListener.java | 2 +- .../redisbungee/util/UUIDFetcher.java | 53 ++++++------------- .../redisbungee/util/UUIDTranslator.java | 10 ++-- 8 files changed, 64 insertions(+), 77 deletions(-) diff --git a/pom.xml b/pom.xml index 558a799..9bec44f 100644 --- a/pom.xml +++ b/pom.xml @@ -7,8 +7,8 @@ as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. --> - 4.0.0 @@ -66,15 +66,18 @@ redis.clients.jedis - com.imaginarycode.minecraft.redisbungee.internal.jedis + com.imaginarycode.minecraft.redisbungee.internal.jedis + redis.clients.util - com.imaginarycode.minecraft.redisbungee.internal.jedisutil + com.imaginarycode.minecraft.redisbungee.internal.jedisutil + org.apache.commons.pool - com.imaginarycode.minecraft.redisbungee.internal.commonspool + com.imaginarycode.minecraft.redisbungee.internal.commonspool + diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/DataManager.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/DataManager.java index 831fee3..74813fb 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/DataManager.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/DataManager.java @@ -25,7 +25,7 @@ import redis.clients.jedis.exceptions.JedisConnectionException; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.*; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.logging.Level; @@ -234,9 +234,10 @@ public class DataManager implements Listener { switch (action) { case JOIN: - final DataManagerMessage message1 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken>() {}.getType()); + final DataManagerMessage message1 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken>() { + }.getType()); proxyCache.put(message1.getTarget(), message1.getSource()); - lastOnlineCache.put(message1.getTarget(), (long)0); + lastOnlineCache.put(message1.getTarget(), (long) 0); ipCache.put(message1.getTarget(), message1.getPayload().getAddress()); plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() { @Override @@ -246,7 +247,8 @@ public class DataManager implements Listener { }); break; case LEAVE: - final DataManagerMessage message2 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken>() {}.getType()); + final DataManagerMessage message2 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken>() { + }.getType()); invalidate(message2.getTarget()); lastOnlineCache.put(message2.getTarget(), message2.getPayload().getTimestamp()); plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() { @@ -257,7 +259,8 @@ public class DataManager implements Listener { }); break; case SERVER_CHANGE: - final DataManagerMessage message3 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken>() {}.getType()); + final DataManagerMessage message3 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken>() { + }.getType()); serverCache.put(message3.getTarget(), message3.getPayload().getServer()); plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() { @Override @@ -272,16 +275,15 @@ public class DataManager implements Listener { @Getter @RequiredArgsConstructor static class DataManagerMessage { + private final UUID target; + private final String source = RedisBungee.getApi().getServerId(); + private final Action action; // for future use! + private final T payload; enum Action { JOIN, LEAVE, SERVER_CHANGE } - - private final UUID target; - private final String source = RedisBungee.getApi().getServerId(); - private final Action action; // for future use! - private final T payload; } @Getter diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java index b77d74e..d2a4fe3 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java @@ -12,7 +12,6 @@ import com.google.common.io.ByteStreams; import com.google.gson.Gson; import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent; import com.imaginarycode.minecraft.redisbungee.util.UUIDTranslator; - import lombok.Getter; import lombok.NonNull; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -20,7 +19,10 @@ import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.YamlConfiguration; -import redis.clients.jedis.*; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; +import redis.clients.jedis.JedisPubSub; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.exceptions.JedisException; @@ -40,20 +42,19 @@ import static com.google.common.base.Preconditions.checkArgument; public final class RedisBungee extends Plugin { private static Configuration configuration; @Getter + private static Gson gson = new Gson(); + private static RedisBungeeAPI api; + private static PubSubListener psl = null; + @Getter private JedisPool pool; @Getter private UUIDTranslator uuidTranslator; @Getter - private static Gson gson = new Gson(); - @Getter private String serverId; @Getter private DataManager dataManager; @Getter private ExecutorService service; - - private static RedisBungeeAPI api; - private static PubSubListener psl = null; private List serverIds; private AtomicInteger nagAboutServers = new AtomicInteger(); @@ -70,6 +71,10 @@ public final class RedisBungee extends Plugin { return configuration; } + static PubSubListener getPubSubListener() { + return psl; + } + final List getServerIds() { return serverIds; } @@ -104,10 +109,6 @@ public final class RedisBungee extends Plugin { } } - static PubSubListener getPubSubListener() { - return psl; - } - final Multimap serversToPlayers() { ImmutableMultimap.Builder multimapBuilder = ImmutableMultimap.builder(); for (UUID p : getPlayers()) { @@ -203,7 +204,7 @@ public final class RedisBungee extends Plugin { pool.returnResource(jedis); } } - + final void sendChannelMessage(String channel, String message) { Jedis jedis = pool.getResource(); try { diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java index 864a1a5..7d7d46a 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java @@ -81,8 +81,8 @@ public class RedisBungeeAPI { * are lazily calculated (but cached, see the contract of {@link #getNameFromUuid(java.util.UUID)}). * * @return a Set with all players found - * @since 0.3 * @see #getNameFromUuid(java.util.UUID) + * @since 0.3 */ public final Collection getHumanPlayersOnline() { return Collections2.transform(getPlayersOnline(), new Function() { @@ -177,9 +177,9 @@ public class RedisBungeeAPI { * @since 0.3.3 */ public final void sendChannelMessage(@NonNull String channel, @NonNull String message) { - plugin.sendChannelMessage(channel, message); + plugin.sendChannelMessage(channel, message); } - + /** * Get the current BungeeCord server ID for this server. * @@ -248,7 +248,7 @@ public class RedisBungeeAPI { *

* If performance is a concern, set {@code expensiveLookups} to false as this will disable lookups via Mojang. * - * @param uuid the UUID to fetch the name for + * @param uuid the UUID to fetch the name for * @param expensiveLookups whether or not to perform potentially expensive lookups * @return the name for the UUID * @since 0.3.2 @@ -263,8 +263,8 @@ public class RedisBungeeAPI { *

* If performance is a concern, see {@link #getUuidFromName(String, boolean)}, which disables the following functions: *

    - *
  • Searching local entries case-insensitively
  • - *
  • Searching Mojang
  • + *
  • Searching local entries case-insensitively
  • + *
  • Searching Mojang
  • *
* * @param name the UUID to fetch the name for @@ -282,7 +282,7 @@ public class RedisBungeeAPI { * If performance is a concern, set {@code expensiveLookups} to false to disable searching Mojang and searching for usernames * case-insensitively. * - * @param name the UUID to fetch the name for + * @param name the UUID to fetch the name for * @param expensiveLookups whether or not to perform potentially expensive lookups * @return the UUID for the name * @since 0.3.2 diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java index 0838fe1..a41fa00 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java @@ -25,7 +25,7 @@ import java.util.UUID; /** * This class contains subclasses that are used for the commands RedisBungee overrides or includes: /glist, /find and /lastseen. - *

+ *

* All classes use the {@link RedisBungeeAPI}. * * @author tuxed diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java index d4ee805..0d9f2e9 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java @@ -29,12 +29,12 @@ import java.util.concurrent.Callable; @AllArgsConstructor public class RedisBungeeListener implements Listener { - private final RedisBungee plugin; private static final BaseComponent[] ALREADY_LOGGED_IN = new ComponentBuilder("You are already logged on to this server.").color(ChatColor.RED) .append("\n\nIf you were disconnected forcefully, please wait up to one minute.\nIf this does not resolve your issue, please contact staff.") .color(ChatColor.GRAY) .create(); + private final RedisBungee plugin; @EventHandler public void onPlayerConnect(final PostLoginEvent event) { diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/util/UUIDFetcher.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/util/UUIDFetcher.java index ee03f3b..738b148 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/util/UUIDFetcher.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/util/UUIDFetcher.java @@ -33,25 +33,6 @@ class UUIDFetcher implements Callable> { this(names, true); } - public Map call() throws Exception { - Map uuidMap = new HashMap<>(); - int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); - for (int i = 0; i < requests; i++) { - HttpURLConnection connection = createConnection(); - String body = RedisBungee.getGson().toJson(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); - writeBody(connection, body); - Profile[] array = RedisBungee.getGson().fromJson(new InputStreamReader(connection.getInputStream()), Profile[].class); - for (Profile profile : array) { - UUID uuid = UUIDFetcher.getUUID(profile.id); - uuidMap.put(profile.name, uuid); - } - if (rateLimiting && i != requests - 1) { - Thread.sleep(100L); // FIXME: This is not how we into concurrency - } - } - return uuidMap; - } - private static void writeBody(HttpURLConnection connection, String body) throws Exception { OutputStream stream = connection.getOutputStream(); stream.write(body.getBytes()); @@ -74,25 +55,23 @@ class UUIDFetcher implements Callable> { return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32)); } - public static byte[] toBytes(UUID uuid) { - ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); - byteBuffer.putLong(uuid.getMostSignificantBits()); - byteBuffer.putLong(uuid.getLeastSignificantBits()); - return byteBuffer.array(); - } - - public static UUID fromBytes(byte[] array) { - if (array.length != 16) { - throw new IllegalArgumentException("Illegal byte array length: " + array.length); + public Map call() throws Exception { + Map uuidMap = new HashMap<>(); + int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); + for (int i = 0; i < requests; i++) { + HttpURLConnection connection = createConnection(); + String body = RedisBungee.getGson().toJson(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); + writeBody(connection, body); + Profile[] array = RedisBungee.getGson().fromJson(new InputStreamReader(connection.getInputStream()), Profile[].class); + for (Profile profile : array) { + UUID uuid = UUIDFetcher.getUUID(profile.id); + uuidMap.put(profile.name, uuid); + } + if (rateLimiting && i != requests - 1) { + Thread.sleep(100L); + } } - ByteBuffer byteBuffer = ByteBuffer.wrap(array); - long mostSignificant = byteBuffer.getLong(); - long leastSignificant = byteBuffer.getLong(); - return new UUID(mostSignificant, leastSignificant); - } - - public static UUID getUUIDOf(String name) throws Exception { - return new UUIDFetcher(Collections.singletonList(name)).call().get(name); + return uuidMap; } private class Profile { diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/util/UUIDTranslator.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/util/UUIDTranslator.java index fa50f59..c72f847 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/util/UUIDTranslator.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/util/UUIDTranslator.java @@ -13,21 +13,23 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.ProxyServer; import redis.clients.jedis.Jedis; -import redis.clients.jedis.Pipeline; import redis.clients.jedis.exceptions.JedisException; -import java.util.*; +import java.util.Calendar; +import java.util.Collections; +import java.util.Map; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.regex.Pattern; @RequiredArgsConstructor public final class UUIDTranslator { + private static final Pattern UUID_PATTERN = Pattern.compile("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"); + private static final Pattern MOJANGIAN_UUID_PATTERN = Pattern.compile("[a-fA-F0-9]{32}"); private final RedisBungee plugin; private final Map nameToUuidMap = new ConcurrentHashMap<>(128, 0.5f, 4); private final Map uuidToNameMap = new ConcurrentHashMap<>(128, 0.5f, 4); - private static final Pattern UUID_PATTERN = Pattern.compile("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"); - private static final Pattern MOJANGIAN_UUID_PATTERN = Pattern.compile("[a-fA-F0-9]{32}"); private void addToMaps(String name, UUID uuid) { // This is why I like LocalDate...