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>
|
<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>
|
||||||
|
@ -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() {
|
||||||
Jedis rsc = pool.getResource();
|
while (true) {
|
||||||
try {
|
ProxiedPlayer pp = player.get();
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "server", event.getPlayer().getServer().getInfo().getName());
|
if (pp == null)
|
||||||
} finally {
|
break;
|
||||||
pool.returnResource(rsc);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(150);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1750, TimeUnit.MILLISECONDS);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user