2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-23 04:28:01 +00:00

Rewrite the initial join server logic as a while loop, do actual bump to 0.2.3 and add /find support.

This commit is contained in:
Tux 2013-11-08 18:19:01 -05:00
parent 98077baaa6
commit 345ceac4b7
3 changed files with 50 additions and 12 deletions

View File

@ -47,6 +47,7 @@
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
<configuration> <configuration>
<minimizeJar>true</minimizeJar>
<artifactSet> <artifactSet>
<includes> <includes>
<include>redis.clients:jedis</include> <include>redis.clients:jedis</include>
@ -55,9 +56,13 @@
</artifactSet> </artifactSet>
<relocations> <relocations>
<relocation> <relocation>
<pattern>redis.clients</pattern> <pattern>redis.clients.jedis</pattern>
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis</shadedPattern> <shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>redis.clients.util</pattern>
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil</shadedPattern>
</relocation>
<relocation> <relocation>
<pattern>org.apache.commons.pool</pattern> <pattern>org.apache.commons.pool</pattern>
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool</shadedPattern> <shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool</shadedPattern>

View File

@ -27,6 +27,7 @@ import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisPoolConfig;
import java.io.*; import java.io.*;
import java.lang.ref.WeakReference;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -176,10 +177,11 @@ public class RedisBungee extends Plugin implements Listener {
getProxy().getPluginManager().registerCommand(this, new Command("glist", "bungeecord.command.glist", "redisbungee") { getProxy().getPluginManager().registerCommand(this, new Command("glist", "bungeecord.command.glist", "redisbungee") {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
sender.sendMessage(ChatColor.YELLOW + String.valueOf(getCount()) + " player(s) are currently online."); int count = getCount();
if (args.length > 0 && args[0].equals("showall")) { if (args.length > 0 && args[0].equals("showall")) {
if (canonicalGlist) { if (canonicalGlist) {
Multimap<String, String> serverToPlayers = HashMultimap.create(getProxy().getServers().size(), getCount()); int avgPlayers = count / getProxy().getServers().size();
Multimap<String, String> serverToPlayers = HashMultimap.create(getProxy().getServers().size(), avgPlayers);
for (String p : getPlayers()) { for (String p : getPlayers()) {
ServerInfo si = getServerFor(p); ServerInfo si = getServerFor(p);
if (si != null) if (si != null)
@ -195,11 +197,28 @@ public class RedisBungee extends Plugin implements Listener {
} else { } else {
sender.sendMessage(ChatColor.YELLOW + "Players: " + Joiner.on(", ").join(getPlayers())); sender.sendMessage(ChatColor.YELLOW + "Players: " + Joiner.on(", ").join(getPlayers()));
} }
sender.sendMessage(ChatColor.YELLOW + String.valueOf(count) + " player(s) are currently online.");
} else { } else {
sender.sendMessage(ChatColor.YELLOW + String.valueOf(count) + " player(s) are currently online.");
sender.sendMessage(ChatColor.YELLOW + "To see all players online, use /glist showall."); sender.sendMessage(ChatColor.YELLOW + "To see all players online, use /glist showall.");
} }
} }
}); });
getProxy().getPluginManager().registerCommand(this, new Command("find", "bungeecord.command.find") {
@Override
public void execute(CommandSender sender, String[] args) {
if (args.length > 0) {
ServerInfo si = getServerFor(args[0]);
if (si != null) {
sender.sendMessage(ChatColor.BLUE + args[0] + " is on " + si.getName() + ".");
} else {
sender.sendMessage(ChatColor.RED + "That user is not online.");
}
} else {
sender.sendMessage(ChatColor.RED + "You must specify a player name.");
}
}
});
getProxy().getPluginManager().registerListener(this, this); getProxy().getPluginManager().registerListener(this, this);
} }
} }
@ -240,7 +259,7 @@ public class RedisBungee extends Plugin implements Listener {
} }
Yaml yaml = new Yaml(); Yaml yaml = new Yaml();
Map rawYaml; Map<?, ?> rawYaml;
try (InputStream in = new FileInputStream(file)) { try (InputStream in = new FileInputStream(file)) {
rawYaml = (Map) yaml.load(in); rawYaml = (Map) yaml.load(in);
@ -286,17 +305,31 @@ public class RedisBungee extends Plugin implements Listener {
} finally { } finally {
pool.returnResource(rsc); pool.returnResource(rsc);
} }
getProxy().getScheduler().schedule(this, new Runnable() { final WeakReference<ProxiedPlayer> player = new WeakReference<>(event.getPlayer());
getProxy().getScheduler().runAsync(this, new Runnable() {
@Override @Override
public void run() { public void run() {
while (true) {
ProxiedPlayer pp = player.get();
if (pp == null)
break;
if (pp.getServer() != null) {
Jedis rsc = pool.getResource(); Jedis rsc = pool.getResource();
try { try {
rsc.hset("player:" + event.getPlayer().getName(), "server", event.getPlayer().getServer().getInfo().getName()); rsc.hset("player:" + event.getPlayer().getName(), "server", event.getPlayer().getServer().getInfo().getName());
} finally { } finally {
pool.returnResource(rsc); pool.returnResource(rsc);
} }
break;
} }
}, 1750, TimeUnit.MILLISECONDS); try {
Thread.sleep(150);
} catch (InterruptedException ignored) {
}
}
}
});
} }
} }

View File

@ -1,4 +1,4 @@
name: RedisBungee name: RedisBungee
main: com.imaginarycode.minecraft.redisbungee.RedisBungee main: com.imaginarycode.minecraft.redisbungee.RedisBungee
version: 0.2.1 version: 0.2.3
author: tuxed author: tuxed