mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-12-23 18:48:02 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8b55d8b35b
2
pom.xml
2
pom.xml
@ -14,7 +14,7 @@
|
||||
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<version>0.2.4-SNAPSHOT</version>
|
||||
<version>0.2.5-SNAPSHOT</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
|
@ -6,7 +6,9 @@
|
||||
*/
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -55,6 +57,16 @@ public final class RedisBungee extends Plugin implements Listener {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
static Multimap<String, String> serversToPlayers() {
|
||||
Multimap<String, String> serverToPlayers = HashMultimap.create();
|
||||
for (String p : RedisBungee.getApi().getPlayersOnline()) {
|
||||
ServerInfo si = RedisBungee.getApi().getServerFor(p);
|
||||
if (si != null)
|
||||
serverToPlayers.put(si.getName(), p);
|
||||
}
|
||||
return serverToPlayers;
|
||||
}
|
||||
|
||||
final int getCount() {
|
||||
int c = plugin.getProxy().getOnlineCount();
|
||||
if (pool != null) {
|
||||
@ -91,6 +103,10 @@ public final class RedisBungee extends Plugin implements Listener {
|
||||
return ImmutableSet.copyOf(players);
|
||||
}
|
||||
|
||||
final Set<String> getPlayersOnServer(String server) {
|
||||
return new HashSet<>(serversToPlayers().get(server));
|
||||
}
|
||||
|
||||
final ServerInfo getServerFor(String name) {
|
||||
ServerInfo server = null;
|
||||
if (plugin.getProxy().getPlayer(name) != null) return plugin.getProxy().getPlayer(name).getServer().getInfo();
|
||||
@ -169,7 +185,7 @@ public final class RedisBungee extends Plugin implements Listener {
|
||||
public void run() {
|
||||
Jedis rsc = pool.getResource();
|
||||
try {
|
||||
rsc.set("server:" + configuration.getString("server-id")+ ":playerCount", String.valueOf(getProxy().getOnlineCount()));
|
||||
rsc.set("server:" + configuration.getString("server-id") + ":playerCount", String.valueOf(getProxy().getOnlineCount()));
|
||||
} finally {
|
||||
pool.returnResource(rsc);
|
||||
}
|
||||
|
@ -6,13 +6,12 @@
|
||||
*/
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import lombok.NonNull;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
/**
|
||||
* This class exposes some internal RedisBungee functions. You obtain an instance of this object by invoking {@link RedisBungee#getApi()}.
|
||||
*
|
||||
@ -68,6 +67,15 @@ public class RedisBungeeAPI {
|
||||
return plugin.getPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of players on the server with the given name.
|
||||
* @param server a server name
|
||||
* @return a Set with all players found on this server
|
||||
*/
|
||||
public final Set<String> getPlayersOnServer(@NonNull String server) {
|
||||
return plugin.getPlayersOnServer(server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method: Checks if the specified player is online.
|
||||
*
|
||||
|
@ -7,7 +7,6 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@ -48,12 +47,7 @@ class RedisBungeeCommands {
|
||||
.append(" player(s) are currently online.").create();
|
||||
if (args.length > 0 && args[0].equals("showall")) {
|
||||
if (RedisBungee.getConfiguration().getBoolean("canonical-glist", true)) {
|
||||
Multimap<String, String> serverToPlayers = HashMultimap.create();
|
||||
for (String p : RedisBungee.getApi().getPlayersOnline()) {
|
||||
ServerInfo si = RedisBungee.getApi().getServerFor(p);
|
||||
if (si != null)
|
||||
serverToPlayers.put(si.getName(), p);
|
||||
}
|
||||
Multimap<String, String> serverToPlayers = RedisBungee.serversToPlayers();
|
||||
for (String server : new TreeSet<>(serverToPlayers.keySet())) {
|
||||
TextComponent serverName = new TextComponent();
|
||||
serverName.setColor(ChatColor.GREEN);
|
||||
|
@ -1,4 +1,4 @@
|
||||
name: RedisBungee
|
||||
main: com.imaginarycode.minecraft.redisbungee.RedisBungee
|
||||
version: 0.2.4
|
||||
version: 0.2.5
|
||||
author: tuxed
|
Loading…
Reference in New Issue
Block a user