mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
Reformat source code.
This commit is contained in:
parent
e0ee2ada21
commit
aa772ddf1b
13
pom.xml
13
pom.xml
@ -7,8 +7,8 @@
|
||||
as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -66,15 +66,18 @@
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>redis.clients.jedis</pattern>
|
||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis</shadedPattern>
|
||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis
|
||||
</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>redis.clients.util</pattern>
|
||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil</shadedPattern>
|
||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil
|
||||
</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.apache.commons.pool</pattern>
|
||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool</shadedPattern>
|
||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool
|
||||
</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
|
@ -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<LoginPayload> message1 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken<DataManagerMessage<LoginPayload>>() {}.getType());
|
||||
final DataManagerMessage<LoginPayload> message1 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken<DataManagerMessage<LoginPayload>>() {
|
||||
}.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<LogoutPayload> message2 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken<DataManagerMessage<LogoutPayload>>() {}.getType());
|
||||
final DataManagerMessage<LogoutPayload> message2 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken<DataManagerMessage<LogoutPayload>>() {
|
||||
}.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<ServerChangePayload> message3 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken<DataManagerMessage<ServerChangePayload>>() {}.getType());
|
||||
final DataManagerMessage<ServerChangePayload> message3 = RedisBungee.getGson().fromJson(jsonObject, new TypeToken<DataManagerMessage<ServerChangePayload>>() {
|
||||
}.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<T> {
|
||||
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
|
||||
|
@ -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<String> 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<String> getServerIds() {
|
||||
return serverIds;
|
||||
}
|
||||
@ -104,10 +109,6 @@ public final class RedisBungee extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
static PubSubListener getPubSubListener() {
|
||||
return psl;
|
||||
}
|
||||
|
||||
final Multimap<String, UUID> serversToPlayers() {
|
||||
ImmutableMultimap.Builder<String, UUID> 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 {
|
||||
|
@ -81,8 +81,8 @@ public class RedisBungeeAPI {
|
||||
* are lazily calculated (but cached, see the contract of {@link #getNameFromUuid(java.util.UUID)}).</strong>
|
||||
*
|
||||
* @return a Set with all players found
|
||||
* @since 0.3
|
||||
* @see #getNameFromUuid(java.util.UUID)
|
||||
* @since 0.3
|
||||
*/
|
||||
public final Collection<String> getHumanPlayersOnline() {
|
||||
return Collections2.transform(getPlayersOnline(), new Function<UUID, String>() {
|
||||
@ -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 {
|
||||
* <p>
|
||||
* 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 {
|
||||
* <p>
|
||||
* If performance is a concern, see {@link #getUuidFromName(String, boolean)}, which disables the following functions:
|
||||
* <ul>
|
||||
* <li>Searching local entries case-insensitively</li>
|
||||
* <li>Searching Mojang</li>
|
||||
* <li>Searching local entries case-insensitively</li>
|
||||
* <li>Searching Mojang</li>
|
||||
* </ul>
|
||||
*
|
||||
* @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
|
||||
|
@ -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.
|
||||
* <p/>
|
||||
* <p>
|
||||
* All classes use the {@link RedisBungeeAPI}.
|
||||
*
|
||||
* @author tuxed
|
||||
|
@ -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) {
|
||||
|
@ -33,25 +33,6 @@ class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||
this(names, true);
|
||||
}
|
||||
|
||||
public Map<String, UUID> call() throws Exception {
|
||||
Map<String, UUID> 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<Map<String, UUID>> {
|
||||
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<String, UUID> call() throws Exception {
|
||||
Map<String, UUID> 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 {
|
||||
|
@ -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<String, CachedUUIDEntry> nameToUuidMap = new ConcurrentHashMap<>(128, 0.5f, 4);
|
||||
private final Map<UUID, CachedUUIDEntry> 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...
|
||||
|
Loading…
Reference in New Issue
Block a user