mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +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:
parent
98077baaa6
commit
345ceac4b7
7
pom.xml
7
pom.xml
@ -47,6 +47,7 @@
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>redis.clients:jedis</include>
|
||||
@ -55,9 +56,13 @@
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>redis.clients</pattern>
|
||||
<pattern>redis.clients.jedis</pattern>
|
||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>redis.clients.util</pattern>
|
||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.apache.commons.pool</pattern>
|
||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool</shadedPattern>
|
||||
|
@ -27,6 +27,7 @@ import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
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") {
|
||||
@Override
|
||||
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 (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()) {
|
||||
ServerInfo si = getServerFor(p);
|
||||
if (si != null)
|
||||
@ -195,11 +197,28 @@ public class RedisBungee extends Plugin implements Listener {
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Players: " + Joiner.on(", ").join(getPlayers()));
|
||||
}
|
||||
sender.sendMessage(ChatColor.YELLOW + String.valueOf(count) + " player(s) are currently online.");
|
||||
} 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.");
|
||||
}
|
||||
}
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -240,7 +259,7 @@ public class RedisBungee extends Plugin implements Listener {
|
||||
}
|
||||
|
||||
Yaml yaml = new Yaml();
|
||||
Map rawYaml;
|
||||
Map<?, ?> rawYaml;
|
||||
|
||||
try (InputStream in = new FileInputStream(file)) {
|
||||
rawYaml = (Map) yaml.load(in);
|
||||
@ -286,17 +305,31 @@ public class RedisBungee extends Plugin implements Listener {
|
||||
} finally {
|
||||
pool.returnResource(rsc);
|
||||
}
|
||||
getProxy().getScheduler().schedule(this, new Runnable() {
|
||||
final WeakReference<ProxiedPlayer> player = new WeakReference<>(event.getPlayer());
|
||||
getProxy().getScheduler().runAsync(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
ProxiedPlayer pp = player.get();
|
||||
if (pp == null)
|
||||
break;
|
||||
|
||||
if (pp.getServer() != null) {
|
||||
Jedis rsc = pool.getResource();
|
||||
try {
|
||||
rsc.hset("player:" + event.getPlayer().getName(), "server", event.getPlayer().getServer().getInfo().getName());
|
||||
} finally {
|
||||
pool.returnResource(rsc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}, 1750, TimeUnit.MILLISECONDS);
|
||||
try {
|
||||
Thread.sleep(150);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
name: RedisBungee
|
||||
main: com.imaginarycode.minecraft.redisbungee.RedisBungee
|
||||
version: 0.2.1
|
||||
version: 0.2.3
|
||||
author: tuxed
|
Loading…
Reference in New Issue
Block a user