2013-11-15 22:05:29 +00:00
|
|
|
/**
|
|
|
|
* Copyright © 2013 tuxed <write@imaginarycode.com>
|
|
|
|
* This work is free. You can redistribute it and/or modify it under the
|
|
|
|
* terms of the Do What The Fuck You Want To Public License, Version 2,
|
|
|
|
* as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
|
|
|
|
*/
|
|
|
|
package com.imaginarycode.minecraft.redisbungee;
|
|
|
|
|
|
|
|
import net.md_5.bungee.api.config.ServerInfo;
|
|
|
|
|
2013-12-13 21:32:55 +00:00
|
|
|
import java.net.InetAddress;
|
2013-11-15 22:05:29 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
2013-12-13 21:32:55 +00:00
|
|
|
import lombok.NonNull;
|
|
|
|
|
2013-11-15 22:05:29 +00:00
|
|
|
/**
|
|
|
|
* This class exposes some internal RedisBungee functions. You obtain an instance of this object by invoking {@link RedisBungee#getApi()}.
|
|
|
|
*
|
|
|
|
* @author tuxed
|
|
|
|
* @since 0.2.3
|
|
|
|
*/
|
|
|
|
public class RedisBungeeAPI {
|
|
|
|
private RedisBungee plugin;
|
|
|
|
|
|
|
|
protected RedisBungeeAPI(RedisBungee plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a combined count of all players on this network.
|
|
|
|
*
|
|
|
|
* @return a count of all players found
|
|
|
|
*/
|
2013-12-13 21:32:55 +00:00
|
|
|
public final int getPlayerCount() {
|
2013-11-15 22:05:29 +00:00
|
|
|
return plugin.getCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the last time a player was on. If the player is currently online, this will return 0. If the player has not been recorded,
|
|
|
|
* this will return -1. Otherwise it will return a value in seconds.
|
|
|
|
*
|
|
|
|
* @param player a player name
|
|
|
|
* @return the last time a player was on, if online returns a 0
|
|
|
|
*/
|
2013-12-13 21:32:55 +00:00
|
|
|
public final long getLastOnline(@NonNull String player) {
|
2013-11-15 22:05:29 +00:00
|
|
|
return plugin.getLastOnline(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the server where the specified player is playing. This function also deals with the case of local players
|
|
|
|
* as well, and will return local information on them.
|
|
|
|
*
|
|
|
|
* @param player a player name
|
|
|
|
* @return a {@link net.md_5.bungee.api.config.ServerInfo} for the server the player is on.
|
|
|
|
*/
|
2013-12-13 21:32:55 +00:00
|
|
|
public final ServerInfo getServerFor(@NonNull String player) {
|
2013-11-15 22:05:29 +00:00
|
|
|
return plugin.getServerFor(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a combined list of players on this network.
|
|
|
|
* <p/>
|
2013-12-13 21:32:55 +00:00
|
|
|
* <strong>Note that this function returns an immutable {@link java.util.Set}.</strong>
|
2013-11-15 22:05:29 +00:00
|
|
|
*
|
|
|
|
* @return a Set with all players found
|
|
|
|
*/
|
2013-12-13 21:32:55 +00:00
|
|
|
public final Set<String> getPlayersOnline() {
|
2013-11-15 22:05:29 +00:00
|
|
|
return plugin.getPlayers();
|
|
|
|
}
|
2013-11-15 22:55:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method: Checks if the specified player is online.
|
|
|
|
*
|
|
|
|
* @param player a player name
|
|
|
|
* @return if the server is online
|
|
|
|
*/
|
2013-12-13 21:32:55 +00:00
|
|
|
public final boolean isPlayerOnline(@NonNull String player) {
|
2013-11-15 22:55:57 +00:00
|
|
|
return getLastOnline(player) == 0;
|
|
|
|
}
|
2013-12-13 21:32:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2013-11-15 22:05:29 +00:00
|
|
|
}
|