mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
* Don't shade in commons-lang anymore, replaced with SimpleDateFormat instead.
* Add IP address logging support. * Add /ip command with permission node redisbungee.command.ip. * Mark some stuff as final so that the JVM can optimize things a little more.
This commit is contained in:
parent
14aba0ffb3
commit
cacea73f2e
11
pom.xml
11
pom.xml
@ -68,7 +68,6 @@
|
|||||||
<includes>
|
<includes>
|
||||||
<include>redis.clients:jedis</include>
|
<include>redis.clients:jedis</include>
|
||||||
<include>commons-pool:commons-pool</include>
|
<include>commons-pool:commons-pool</include>
|
||||||
<include>org.apache.commons:commons-lang3</include>
|
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
<relocations>
|
<relocations>
|
||||||
@ -82,11 +81,6 @@
|
|||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil
|
||||||
</shadedPattern>
|
</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
|
||||||
<pattern>org.apache.commons</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commons
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
@ -140,11 +134,6 @@
|
|||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>3.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
@ -22,6 +22,8 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
|
|||||||
import redis.clients.jedis.exceptions.JedisException;
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -31,7 +33,7 @@ import java.util.logging.Level;
|
|||||||
* <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 class RedisBungee extends Plugin implements Listener {
|
public final class RedisBungee extends Plugin implements Listener {
|
||||||
private static final ServerPing.PlayerInfo[] EMPTY_PLAYERINFO = new ServerPing.PlayerInfo[]{};
|
private static final ServerPing.PlayerInfo[] EMPTY_PLAYERINFO = new ServerPing.PlayerInfo[]{};
|
||||||
private RedisBungeeCommandSender commandSender = new RedisBungeeCommandSender();
|
private RedisBungeeCommandSender commandSender = new RedisBungeeCommandSender();
|
||||||
private static RedisBungeeConfiguration configuration = new RedisBungeeConfiguration();
|
private static RedisBungeeConfiguration configuration = new RedisBungeeConfiguration();
|
||||||
@ -53,7 +55,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
protected final int getCount() {
|
||||||
int c = plugin.getProxy().getOnlineCount();
|
int c = plugin.getProxy().getOnlineCount();
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis rsc = pool.getResource();
|
Jedis rsc = pool.getResource();
|
||||||
@ -70,7 +72,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getPlayers() {
|
protected final Set<String> getPlayers() {
|
||||||
Set<String> players = new HashSet<>();
|
Set<String> players = new HashSet<>();
|
||||||
for (ProxiedPlayer pp : plugin.getProxy().getPlayers()) {
|
for (ProxiedPlayer pp : plugin.getProxy().getPlayers()) {
|
||||||
players.add(pp.getName());
|
players.add(pp.getName());
|
||||||
@ -89,7 +91,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
return ImmutableSet.copyOf(players);
|
return ImmutableSet.copyOf(players);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerInfo getServerFor(String name) {
|
protected final ServerInfo getServerFor(String name) {
|
||||||
ServerInfo server = null;
|
ServerInfo server = null;
|
||||||
if (plugin.getProxy().getPlayer(name) != null) return plugin.getProxy().getPlayer(name).getServer().getInfo();
|
if (plugin.getProxy().getPlayer(name) != null) return plugin.getProxy().getPlayer(name).getServer().getInfo();
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
@ -108,7 +110,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
return TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
|
return TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastOnline(String name) {
|
protected final long getLastOnline(String name) {
|
||||||
long time = -1L;
|
long time = -1L;
|
||||||
if (plugin.getProxy().getPlayer(name) != null) return 0;
|
if (plugin.getProxy().getPlayer(name) != null) return 0;
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
@ -123,6 +125,24 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final InetAddress getIpAddress(String name) {
|
||||||
|
if (plugin.getProxy().getPlayer(name) != null)
|
||||||
|
return plugin.getProxy().getPlayer(name).getAddress().getAddress();
|
||||||
|
InetAddress ia = null;
|
||||||
|
if (pool != null) {
|
||||||
|
Jedis tmpRsc = pool.getResource();
|
||||||
|
try {
|
||||||
|
if (tmpRsc.hexists("player:" + name, "ip"))
|
||||||
|
ia = InetAddress.getByName(tmpRsc.hget("player:" + name, "ip"));
|
||||||
|
} catch (UnknownHostException ignored) {
|
||||||
|
// Best to just return null
|
||||||
|
} finally {
|
||||||
|
pool.returnResource(tmpRsc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ia;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
@ -158,6 +178,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
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());
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.IpCommand());
|
||||||
getProxy().getPluginManager().registerListener(this, this);
|
getProxy().getPluginManager().registerListener(this, this);
|
||||||
api = new RedisBungeeAPI(this);
|
api = new RedisBungeeAPI(this);
|
||||||
psl = new PubSubListener();
|
psl = new PubSubListener();
|
||||||
@ -298,6 +319,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
try {
|
try {
|
||||||
rsc.sadd("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
|
rsc.sadd("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "online", "0");
|
rsc.hset("player:" + event.getPlayer().getName(), "online", "0");
|
||||||
|
rsc.hset("player:" + event.getPlayer().getName(), "ip", event.getPlayer().getAddress().getAddress().getHostAddress());
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(rsc);
|
pool.returnResource(rsc);
|
||||||
}
|
}
|
||||||
@ -315,6 +337,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
rsc.srem("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
|
rsc.srem("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "online", String.valueOf(getUnixTimestamp()));
|
rsc.hset("player:" + event.getPlayer().getName(), "online", String.valueOf(getUnixTimestamp()));
|
||||||
rsc.hdel("player:" + event.getPlayer().getName(), "server");
|
rsc.hdel("player:" + event.getPlayer().getName(), "server");
|
||||||
|
rsc.hdel("player:" + event.getPlayer().getName(), "ip");
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(rsc);
|
pool.returnResource(rsc);
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,11 @@ package com.imaginarycode.minecraft.redisbungee;
|
|||||||
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.util.Set;
|
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()}.
|
* This class exposes some internal RedisBungee functions. You obtain an instance of this object by invoking {@link RedisBungee#getApi()}.
|
||||||
*
|
*
|
||||||
@ -28,7 +31,7 @@ public class RedisBungeeAPI {
|
|||||||
*
|
*
|
||||||
* @return a count of all players found
|
* @return a count of all players found
|
||||||
*/
|
*/
|
||||||
public int getPlayerCount() {
|
public final int getPlayerCount() {
|
||||||
return plugin.getCount();
|
return plugin.getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +42,7 @@ public class RedisBungeeAPI {
|
|||||||
* @param player a player name
|
* @param player a player name
|
||||||
* @return the last time a player was on, if online returns a 0
|
* @return the last time a player was on, if online returns a 0
|
||||||
*/
|
*/
|
||||||
public long getLastOnline(String player) {
|
public final long getLastOnline(@NonNull String player) {
|
||||||
return plugin.getLastOnline(player);
|
return plugin.getLastOnline(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,18 +53,18 @@ public class RedisBungeeAPI {
|
|||||||
* @param player a player name
|
* @param player a player name
|
||||||
* @return a {@link net.md_5.bungee.api.config.ServerInfo} for the server the player is on.
|
* @return a {@link net.md_5.bungee.api.config.ServerInfo} for the server the player is on.
|
||||||
*/
|
*/
|
||||||
public ServerInfo getServerFor(String player) {
|
public final ServerInfo getServerFor(@NonNull String player) {
|
||||||
return plugin.getServerFor(player);
|
return plugin.getServerFor(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a combined list of players on this network.
|
* Get a combined list of players on this network.
|
||||||
* <p/>
|
* <p/>
|
||||||
* Note that this function returns an immutable {@link java.util.Set}.
|
* <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
|
||||||
*/
|
*/
|
||||||
public Set<String> getPlayersOnline() {
|
public final Set<String> getPlayersOnline() {
|
||||||
return plugin.getPlayers();
|
return plugin.getPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +74,16 @@ public class RedisBungeeAPI {
|
|||||||
* @param player a player name
|
* @param player a player name
|
||||||
* @return if the server is online
|
* @return if the server is online
|
||||||
*/
|
*/
|
||||||
public boolean isPlayerOnline(String player) {
|
public final boolean isPlayerOnline(@NonNull String player) {
|
||||||
return getLastOnline(player) == 0;
|
return getLastOnline(player) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link java.net.InetAddress} associated with this player.
|
||||||
|
*
|
||||||
|
* @return an {@link java.net.InetAddress} if the player is online, null otherwise
|
||||||
|
*/
|
||||||
|
public final InetAddress getPlayerIp(@NonNull String player) {
|
||||||
|
return plugin.getIpAddress(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,9 @@ import net.md_5.bungee.api.ChatColor;
|
|||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import org.apache.commons.lang3.time.FastDateFormat;
|
|
||||||
|
|
||||||
import java.util.Set;
|
import java.net.InetAddress;
|
||||||
import java.util.TreeSet;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,8 +81,6 @@ public class RedisBungeeCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class LastSeenCommand extends Command {
|
public static class LastSeenCommand extends Command {
|
||||||
FastDateFormat format = FastDateFormat.getInstance();
|
|
||||||
|
|
||||||
protected LastSeenCommand() {
|
protected LastSeenCommand() {
|
||||||
super("lastseen", "redisbungee.command.lastseen");
|
super("lastseen", "redisbungee.command.lastseen");
|
||||||
}
|
}
|
||||||
@ -95,7 +92,7 @@ public class RedisBungeeCommands {
|
|||||||
if (secs == 0) {
|
if (secs == 0) {
|
||||||
sender.sendMessage(ChatColor.GREEN + args[0] + " is currently online.");
|
sender.sendMessage(ChatColor.GREEN + args[0] + " is currently online.");
|
||||||
} else if (secs != -1) {
|
} else if (secs != -1) {
|
||||||
sender.sendMessage(ChatColor.BLUE + args[0] + " was last online on " + format.format(TimeUnit.SECONDS.toMillis(secs)) + ".");
|
sender.sendMessage(ChatColor.BLUE + args[0] + " was last online on " + new SimpleDateFormat().format(TimeUnit.SECONDS.toMillis(secs)) + ".");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + args[0] + " has never been online.");
|
sender.sendMessage(ChatColor.RED + args[0] + " has never been online.");
|
||||||
}
|
}
|
||||||
@ -104,4 +101,24 @@ public class RedisBungeeCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class IpCommand extends Command {
|
||||||
|
protected IpCommand() {
|
||||||
|
super("ip", "redisbungee.command.ip", "playerip");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
if (args.length > 0) {
|
||||||
|
InetAddress ia = RedisBungee.getApi().getPlayerIp(args[0]);
|
||||||
|
if (ia != null) {
|
||||||
|
sender.sendMessage(ChatColor.GREEN + args[0] + " is connected from " + ia.toString() + ".");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "No such player found.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You must specify a player name.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user