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;
|
|
|
|
|
2014-01-02 05:14:58 +00:00
|
|
|
import com.google.common.collect.Multimap;
|
2013-12-27 20:40:58 +00:00
|
|
|
import lombok.NonNull;
|
2013-11-15 22:05:29 +00:00
|
|
|
import net.md_5.bungee.api.config.ServerInfo;
|
|
|
|
|
2013-12-13 21:32:55 +00:00
|
|
|
import java.net.InetAddress;
|
2014-01-28 22:33:53 +00:00
|
|
|
import java.util.List;
|
2013-11-15 22:05:29 +00:00
|
|
|
import java.util.Set;
|
2014-04-20 05:12:28 +00:00
|
|
|
import java.util.UUID;
|
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 {
|
2013-12-24 05:15:06 +00:00
|
|
|
private final RedisBungee plugin;
|
2013-11-15 22:05:29 +00:00
|
|
|
|
2013-12-24 05:15:06 +00:00
|
|
|
RedisBungeeAPI(RedisBungee plugin) {
|
2013-11-15 22:05:29 +00:00
|
|
|
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,
|
2014-01-02 05:14:58 +00:00
|
|
|
* this will return -1. Otherwise it will return a value in milliseconds.
|
2013-11-15 22:05:29 +00:00
|
|
|
*
|
|
|
|
* @param player a player name
|
|
|
|
* @return the last time a player was on, if online returns a 0
|
|
|
|
*/
|
2014-04-20 05:12:28 +00:00
|
|
|
public final long getLastOnline(@NonNull UUID 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.
|
|
|
|
*/
|
2014-04-20 05:12:28 +00:00
|
|
|
public final ServerInfo getServerFor(@NonNull UUID player) {
|
2013-11-15 22:05:29 +00:00
|
|
|
return plugin.getServerFor(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a combined list of players on this network.
|
2014-04-20 05:12:28 +00:00
|
|
|
* <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
|
|
|
|
*/
|
2014-04-20 05:12:28 +00:00
|
|
|
public final Set<UUID> getPlayersOnline() {
|
2013-11-15 22:05:29 +00:00
|
|
|
return plugin.getPlayers();
|
|
|
|
}
|
2013-11-15 22:55:57 +00:00
|
|
|
|
2014-01-02 05:14:58 +00:00
|
|
|
/**
|
|
|
|
* Get a full list of players on all servers.
|
2014-04-20 05:12:28 +00:00
|
|
|
*
|
2014-01-02 05:14:58 +00:00
|
|
|
* @return a immutable Multimap with all players found on this server
|
2014-01-28 22:33:53 +00:00
|
|
|
* @since 0.2.5
|
2014-01-02 05:14:58 +00:00
|
|
|
*/
|
2014-04-20 05:12:28 +00:00
|
|
|
public final Multimap<String, UUID> getServerToPlayers() {
|
2014-01-02 05:14:58 +00:00
|
|
|
return plugin.serversToPlayers();
|
|
|
|
}
|
|
|
|
|
2013-12-27 20:40:58 +00:00
|
|
|
/**
|
|
|
|
* Get a list of players on the server with the given name.
|
2014-04-20 05:12:28 +00:00
|
|
|
*
|
2013-12-27 20:40:58 +00:00
|
|
|
* @param server a server name
|
|
|
|
* @return a Set with all players found on this server
|
|
|
|
*/
|
2014-04-20 05:12:28 +00:00
|
|
|
public final Set<UUID> getPlayersOnServer(@NonNull String server) {
|
2013-12-27 20:40:58 +00:00
|
|
|
return plugin.getPlayersOnServer(server);
|
|
|
|
}
|
|
|
|
|
2013-11-15 22:55:57 +00:00
|
|
|
/**
|
|
|
|
* Convenience method: Checks if the specified player is online.
|
|
|
|
*
|
|
|
|
* @param player a player name
|
2014-01-28 22:33:53 +00:00
|
|
|
* @return if the player is online
|
2013-11-15 22:55:57 +00:00
|
|
|
*/
|
2014-04-20 05:12:28 +00:00
|
|
|
public final boolean isPlayerOnline(@NonNull UUID 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.
|
|
|
|
*
|
2014-03-30 04:31:35 +00:00
|
|
|
* @param player the player to fetch the IP for
|
2013-12-13 21:32:55 +00:00
|
|
|
* @return an {@link java.net.InetAddress} if the player is online, null otherwise
|
2014-01-28 22:33:53 +00:00
|
|
|
* @since 0.2.4
|
2013-12-13 21:32:55 +00:00
|
|
|
*/
|
2014-04-20 05:12:28 +00:00
|
|
|
public final InetAddress getPlayerIp(@NonNull UUID player) {
|
2013-12-13 21:32:55 +00:00
|
|
|
return plugin.getIpAddress(player);
|
|
|
|
}
|
2014-01-02 00:05:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a proxy command to all proxies.
|
2014-04-20 05:12:28 +00:00
|
|
|
*
|
2014-01-02 00:05:55 +00:00
|
|
|
* @param command the command to send and execute
|
2014-02-12 06:26:56 +00:00
|
|
|
* @see #sendProxyCommand(String, String)
|
2014-01-28 22:33:53 +00:00
|
|
|
* @since 0.2.5
|
2014-01-02 00:05:55 +00:00
|
|
|
*/
|
2014-01-02 05:14:58 +00:00
|
|
|
public final void sendProxyCommand(@NonNull String command) {
|
2014-01-02 00:05:55 +00:00
|
|
|
plugin.sendProxyCommand("allservers", command);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-28 22:33:53 +00:00
|
|
|
* Sends a proxy command to the proxy with the given ID. "allservers" means all proxies.
|
2014-04-20 05:12:28 +00:00
|
|
|
*
|
2014-01-02 00:05:55 +00:00
|
|
|
* @param proxyId a proxy ID
|
|
|
|
* @param command the command to send and execute
|
2014-02-12 06:26:56 +00:00
|
|
|
* @see #getServerId()
|
|
|
|
* @see #getAllServers()
|
2014-01-28 22:33:53 +00:00
|
|
|
* @since 0.2.5
|
2014-01-02 00:05:55 +00:00
|
|
|
*/
|
2014-01-02 05:14:58 +00:00
|
|
|
public final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
|
2014-01-02 00:05:55 +00:00
|
|
|
plugin.sendProxyCommand(proxyId, command);
|
|
|
|
}
|
2014-01-17 02:31:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current BungeeCord server ID for this server.
|
2014-04-20 05:12:28 +00:00
|
|
|
*
|
2014-01-17 02:31:57 +00:00
|
|
|
* @return the current server ID
|
2014-02-12 06:26:56 +00:00
|
|
|
* @see #getAllServers()
|
2014-04-20 05:12:28 +00:00
|
|
|
* @since 0.2.5
|
2014-01-17 02:31:57 +00:00
|
|
|
*/
|
|
|
|
public final String getServerId() {
|
|
|
|
return RedisBungee.getConfiguration().getString("server-id");
|
|
|
|
}
|
2014-01-28 22:33:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the linked proxies in this network.
|
2014-04-20 05:12:28 +00:00
|
|
|
*
|
2014-01-28 22:33:53 +00:00
|
|
|
* @return the list of all proxies
|
2014-02-12 06:26:56 +00:00
|
|
|
* @see #getServerId()
|
2014-04-20 05:12:28 +00:00
|
|
|
* @since 0.2.5
|
2014-01-28 22:33:53 +00:00
|
|
|
*/
|
|
|
|
public final List<String> getAllServers() {
|
2014-04-04 03:24:27 +00:00
|
|
|
return plugin.getServerIds();
|
2014-01-28 22:33:53 +00:00
|
|
|
}
|
2014-03-31 15:19:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register (a) PubSub channel(s), so that you may capture {@link com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent} for it.
|
|
|
|
*
|
|
|
|
* @param channels the channels to register
|
|
|
|
* @since 0.2.6
|
|
|
|
*/
|
|
|
|
public final void registerPubSubChannels(String... channels) {
|
|
|
|
RedisBungee.getPubSubListener().addChannel(channels);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister (a) PubSub channel(s).
|
|
|
|
*
|
|
|
|
* @param channels the channels to unregister
|
|
|
|
* @since 0.2.6
|
|
|
|
*/
|
|
|
|
public final void unregisterPubSubChannels(String... channels) {
|
|
|
|
RedisBungee.getPubSubListener().removeChannel(channels);
|
|
|
|
}
|
2014-04-20 05:12:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a name from the specified UUID.
|
|
|
|
*
|
|
|
|
* @param uuid the UUID to fetch the name for
|
|
|
|
* @return the name for the UUID
|
|
|
|
* @since 0.3
|
|
|
|
*/
|
|
|
|
public final String getNameFromUuid(UUID uuid) {
|
|
|
|
return plugin.getUuidTranslator().getNameFromUuid(uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a UUID from the specified name.
|
|
|
|
*
|
|
|
|
* @param name the UUID to fetch the name for
|
|
|
|
* @return the UUID for the name
|
|
|
|
* @since 0.3
|
|
|
|
*/
|
|
|
|
public final UUID getUuidFromName(String name) {
|
|
|
|
return plugin.getUuidTranslator().getTranslatedUuid(name);
|
|
|
|
}
|
2013-11-15 22:05:29 +00:00
|
|
|
}
|