mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28:01 +00:00
Major changes.
* Some events are now handled asynchronously. * There is now support for a connection limit. * Fixed build under JDK8. * Player count is now cached again. Hopefully this means an increase in performance.
This commit is contained in:
parent
4edfabfe98
commit
8b1ea2f7df
4
pom.xml
4
pom.xml
@ -126,9 +126,9 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.heartsavior</groupId>
|
<groupId>redis.clients</groupId>
|
||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
<version>2.2.1.1</version>
|
<version>2.4.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
|
@ -43,7 +43,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The RedisBungee plugin.
|
* The RedisBungee plugin.
|
||||||
* <p/>
|
* <p>
|
||||||
* The only function of interest is {@link #getApi()}, which exposes some functions in this class.
|
* The only function of interest is {@link #getApi()}, which exposes some functions in this class.
|
||||||
*/
|
*/
|
||||||
public final class RedisBungee extends Plugin implements Listener {
|
public final class RedisBungee extends Plugin implements Listener {
|
||||||
@ -52,6 +52,7 @@ public final class RedisBungee extends Plugin implements Listener {
|
|||||||
private static RedisBungeeAPI api;
|
private static RedisBungeeAPI api;
|
||||||
private PubSubListener psl = null;
|
private PubSubListener psl = null;
|
||||||
private static List<String> serverIds;
|
private static List<String> serverIds;
|
||||||
|
private int globalCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the {@link RedisBungeeAPI} object created on plugin start.
|
* Fetch the {@link RedisBungeeAPI} object created on plugin start.
|
||||||
@ -81,6 +82,10 @@ public final class RedisBungee extends Plugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final int getCount() {
|
final int getCount() {
|
||||||
|
return globalCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int getCurrentCount() {
|
||||||
int c = getProxy().getOnlineCount();
|
int c = getProxy().getOnlineCount();
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis rsc = pool.getResource();
|
Jedis rsc = pool.getResource();
|
||||||
@ -274,6 +279,7 @@ public final class RedisBungee extends Plugin implements Listener {
|
|||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
}
|
}
|
||||||
|
globalCount = getCurrentCount();
|
||||||
getProxy().getScheduler().schedule(this, new Runnable() {
|
getProxy().getScheduler().schedule(this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -287,8 +293,9 @@ public final class RedisBungee extends Plugin implements Listener {
|
|||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(rsc);
|
pool.returnResource(rsc);
|
||||||
}
|
}
|
||||||
|
globalCount = getCurrentCount();
|
||||||
}
|
}
|
||||||
}, 1, 3, TimeUnit.SECONDS);
|
}, 0, 3, TimeUnit.SECONDS);
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.GlistCommand());
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.GlistCommand());
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.FindCommand());
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.FindCommand());
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.LastSeenCommand());
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.LastSeenCommand());
|
||||||
@ -392,7 +399,9 @@ public final class RedisBungee extends Plugin implements Listener {
|
|||||||
|
|
||||||
if (redisServer != null) {
|
if (redisServer != null) {
|
||||||
if (!redisServer.equals("")) {
|
if (!redisServer.equals("")) {
|
||||||
pool = new JedisPool(new JedisPoolConfig(), redisServer, redisPort, 0, redisPassword);
|
JedisPoolConfig config = new JedisPoolConfig();
|
||||||
|
config.setMaxTotal(configuration.getInt("max-redis-connections", -1));
|
||||||
|
pool = new JedisPool(config, redisServer, redisPort, 0, redisPassword);
|
||||||
// Test the connection
|
// Test the connection
|
||||||
Jedis rsc = null;
|
Jedis rsc = null;
|
||||||
try {
|
try {
|
||||||
@ -450,14 +459,19 @@ public final class RedisBungee extends Plugin implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerConnect(final PostLoginEvent event) {
|
public void onPlayerConnect(final PostLoginEvent event) {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis rsc = pool.getResource();
|
getProxy().getScheduler().runAsync(RedisBungee.this, new Runnable() {
|
||||||
try {
|
@Override
|
||||||
rsc.sadd("server:" + configuration.getString("server-id", "") + ":usersOnline", event.getPlayer().getName());
|
public void run() {
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "online", "0");
|
Jedis rsc = pool.getResource();
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "ip", event.getPlayer().getAddress().getAddress().getHostAddress());
|
try {
|
||||||
} finally {
|
rsc.sadd("server:" + configuration.getString("server-id", "") + ":usersOnline", event.getPlayer().getName());
|
||||||
pool.returnResource(rsc);
|
rsc.hset("player:" + event.getPlayer().getName(), "online", "0");
|
||||||
}
|
rsc.hset("player:" + event.getPlayer().getName(), "ip", event.getPlayer().getAddress().getAddress().getHostAddress());
|
||||||
|
} finally {
|
||||||
|
pool.returnResource(rsc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// I used to have a task that eagerly waited for the user to be connected.
|
// I used to have a task that eagerly waited for the user to be connected.
|
||||||
// Well, upon further inspection of BungeeCord's source code, this turned
|
// Well, upon further inspection of BungeeCord's source code, this turned
|
||||||
@ -467,25 +481,35 @@ public final class RedisBungee extends Plugin implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDisconnect(final PlayerDisconnectEvent event) {
|
public void onPlayerDisconnect(final PlayerDisconnectEvent event) {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis rsc = pool.getResource();
|
getProxy().getScheduler().runAsync(RedisBungee.this, new Runnable() {
|
||||||
try {
|
@Override
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "online", String.valueOf(System.currentTimeMillis()));
|
public void run() {
|
||||||
cleanUpPlayer(event.getPlayer().getName(), rsc);
|
Jedis rsc = pool.getResource();
|
||||||
} finally {
|
try {
|
||||||
pool.returnResource(rsc);
|
rsc.hset("player:" + event.getPlayer().getName(), "online", String.valueOf(System.currentTimeMillis()));
|
||||||
}
|
cleanUpPlayer(event.getPlayer().getName(), rsc);
|
||||||
|
} finally {
|
||||||
|
pool.returnResource(rsc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onServerChange(final ServerConnectedEvent event) {
|
public void onServerChange(final ServerConnectedEvent event) {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis rsc = pool.getResource();
|
getProxy().getScheduler().runAsync(RedisBungee.this, new Runnable() {
|
||||||
try {
|
@Override
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "server", event.getServer().getInfo().getName());
|
public void run() {
|
||||||
} finally {
|
Jedis rsc = pool.getResource();
|
||||||
pool.returnResource(rsc);
|
try {
|
||||||
}
|
rsc.hset("player:" + event.getPlayer().getName(), "server", event.getServer().getInfo().getName());
|
||||||
|
} finally {
|
||||||
|
pool.returnResource(rsc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,7 +565,7 @@ public final class RedisBungee extends Plugin implements Listener {
|
|||||||
type = in.readUTF();
|
type = in.readUTF();
|
||||||
if (type.equals("ALL")) {
|
if (type.equals("ALL")) {
|
||||||
out.writeUTF("ALL");
|
out.writeUTF("ALL");
|
||||||
out.writeInt(getCount());
|
out.writeInt(getCurrentCount());
|
||||||
} else {
|
} else {
|
||||||
out.writeUTF(type);
|
out.writeUTF(type);
|
||||||
try {
|
try {
|
||||||
@ -550,7 +574,7 @@ public final class RedisBungee extends Plugin implements Listener {
|
|||||||
out.writeInt(0);
|
out.writeInt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.writeInt(getCount());
|
out.writeInt(getCurrentCount());
|
||||||
break;
|
break;
|
||||||
case "LastOnline":
|
case "LastOnline":
|
||||||
String user = in.readUTF();
|
String user = in.readUTF();
|
||||||
|
@ -60,7 +60,7 @@ public class RedisBungeeAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a combined list of players on this network.
|
* Get a combined list of players on this network.
|
||||||
* <p/>
|
* <p>
|
||||||
* <strong>Note that this function returns an immutable {@link java.util.Set}.</strong>
|
* <strong>Note that this function returns an immutable {@link java.util.Set}.</strong>
|
||||||
*
|
*
|
||||||
* @return a Set with all players found
|
* @return a Set with all players found
|
||||||
@ -100,6 +100,7 @@ public class RedisBungeeAPI {
|
|||||||
/**
|
/**
|
||||||
* Get the {@link java.net.InetAddress} associated with this player.
|
* Get the {@link java.net.InetAddress} associated with this player.
|
||||||
*
|
*
|
||||||
|
* @param player the player to fetch the IP for
|
||||||
* @return an {@link java.net.InetAddress} if the player is online, null otherwise
|
* @return an {@link java.net.InetAddress} if the player is online, null otherwise
|
||||||
* @since 0.2.4
|
* @since 0.2.4
|
||||||
*/
|
*/
|
||||||
|
@ -16,7 +16,7 @@ import java.util.Collections;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is the CommandSender that RedisBungee uses to dispatch commands to BungeeCord.
|
* This class is the CommandSender that RedisBungee uses to dispatch commands to BungeeCord.
|
||||||
* <p/>
|
* <p>
|
||||||
* It inherits all permissions of the console command sender. Sending messages and modifying permissions are no-ops.
|
* It inherits all permissions of the console command sender. Sending messages and modifying permissions are no-ops.
|
||||||
*
|
*
|
||||||
* @author tuxed
|
* @author tuxed
|
||||||
|
@ -7,6 +7,10 @@ redis-server: 127.0.0.1
|
|||||||
redis-port: 6379
|
redis-port: 6379
|
||||||
# OPTIONAL: If your Redis server uses AUTH, set the password required.
|
# OPTIONAL: If your Redis server uses AUTH, set the password required.
|
||||||
redis-password: ""
|
redis-password: ""
|
||||||
|
# Maximum connections that will be maintained to the Redis server.
|
||||||
|
# The default is an unlimited number of connections.
|
||||||
|
# You may need to lower this value in some setups.
|
||||||
|
max-redis-connections: -1
|
||||||
|
|
||||||
# An identifier for this BungeeCord instance.
|
# An identifier for this BungeeCord instance.
|
||||||
server-id: iluvbungee
|
server-id: iluvbungee
|
||||||
|
Loading…
Reference in New Issue
Block a user