2013-11-15 22:05:29 +00:00
|
|
|
package com.imaginarycode.minecraft.redisbungee;
|
|
|
|
|
2014-11-02 19:16:41 +00:00
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
import com.google.common.collect.ImmutableList;
|
2016-06-25 06:19:23 +00:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
2014-01-02 05:14:58 +00:00
|
|
|
import com.google.common.collect.Multimap;
|
2022-07-27 13:43:51 +00:00
|
|
|
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
2022-07-16 12:50:09 +00:00
|
|
|
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
2022-07-25 15:13:25 +00:00
|
|
|
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner;
|
2022-07-26 13:47:18 +00:00
|
|
|
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner;
|
2022-07-16 12:50:09 +00:00
|
|
|
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
2022-04-13 13:14:08 +00:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
import redis.clients.jedis.Jedis;
|
2022-07-25 15:13:25 +00:00
|
|
|
import redis.clients.jedis.JedisCluster;
|
2022-07-15 22:58:48 +00:00
|
|
|
import redis.clients.jedis.JedisPool;
|
2013-11-15 22:05:29 +00:00
|
|
|
|
2013-12-13 21:32:55 +00:00
|
|
|
import java.net.InetAddress;
|
2015-07-02 01:06:13 +00:00
|
|
|
import java.util.*;
|
2013-11-15 22:05:29 +00:00
|
|
|
|
|
|
|
/**
|
2022-07-27 13:43:51 +00:00
|
|
|
* This abstract class is extended by platform plugin to provide some platform specific methods.
|
|
|
|
* overall its general contains all methods needed by external usage.
|
2022-04-14 10:16:34 +00:00
|
|
|
*
|
2022-07-27 13:43:51 +00:00
|
|
|
* @author Ham1255
|
|
|
|
* @since 0.8.0
|
2013-11-15 22:05:29 +00:00
|
|
|
*/
|
2021-08-09 10:05:02 +00:00
|
|
|
@SuppressWarnings("unused")
|
2022-07-27 13:43:51 +00:00
|
|
|
public abstract class AbstractRedisBungeeAPI {
|
|
|
|
protected final RedisBungeePlugin<?> plugin;
|
|
|
|
private static AbstractRedisBungeeAPI abstractRedisBungeeAPI;
|
|
|
|
protected final List<String> reservedChannels;
|
2013-11-15 22:05:29 +00:00
|
|
|
|
2022-07-27 13:43:51 +00:00
|
|
|
AbstractRedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
|
|
|
abstractRedisBungeeAPI = this;
|
2013-11-15 22:05:29 +00:00
|
|
|
this.plugin = plugin;
|
2014-11-02 19:16:41 +00:00
|
|
|
this.reservedChannels = ImmutableList.of(
|
|
|
|
"redisbungee-allservers",
|
2022-07-17 11:38:00 +00:00
|
|
|
"redisbungee-" + plugin.getConfiguration().getProxyId(),
|
2014-11-02 19:16:41 +00:00
|
|
|
"redisbungee-data"
|
|
|
|
);
|
2013-11-15 22:05:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2014-08-10 03:16:47 +00:00
|
|
|
return plugin.getDataManager().getLastOnline(player);
|
2013-11-15 22:05:29 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2022-07-27 13:43:51 +00:00
|
|
|
* @param player a player uuid
|
2022-04-13 13:14:08 +00:00
|
|
|
* @return a String name for the server the player is on.
|
2013-11-15 22:05:29 +00:00
|
|
|
*/
|
2022-07-27 13:43:51 +00:00
|
|
|
public final String getServerNameFor(@NonNull UUID player) {
|
2022-04-13 13:14:08 +00:00
|
|
|
return plugin.getDataManager().getServer(player);
|
2013-11-15 22:05:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a combined list of players on this network.
|
2014-05-23 03:37:26 +00:00
|
|
|
* <p>
|
2014-11-01 16:54:23 +00:00
|
|
|
* <strong>Note that this function returns an instance of {@link com.google.common.collect.ImmutableSet}.</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-05-17 00:41:59 +00:00
|
|
|
/**
|
|
|
|
* Get a combined list of players on this network, as a collection of usernames.
|
|
|
|
*
|
|
|
|
* @return a Set with all players found
|
|
|
|
* @see #getNameFromUuid(java.util.UUID)
|
2014-09-21 17:56:46 +00:00
|
|
|
* @since 0.3
|
2014-05-17 00:41:59 +00:00
|
|
|
*/
|
|
|
|
public final Collection<String> getHumanPlayersOnline() {
|
2015-07-02 01:06:13 +00:00
|
|
|
Set<String> names = new HashSet<>();
|
|
|
|
for (UUID uuid : getPlayersOnline()) {
|
|
|
|
names.add(getNameFromUuid(uuid, false));
|
|
|
|
}
|
|
|
|
return names;
|
2014-05-17 00:41:59 +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() {
|
2022-07-26 06:58:00 +00:00
|
|
|
return plugin.serverToPlayersCache();
|
2014-01-02 05:14:58 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2016-06-25 06:19:23 +00:00
|
|
|
return ImmutableSet.copyOf(getServerToPlayers().get(server));
|
2013-12-27 20:40:58 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 10:06:02 +00:00
|
|
|
/**
|
|
|
|
* Get a list of players on the specified proxy.
|
|
|
|
*
|
|
|
|
* @param server a server name
|
|
|
|
* @return a Set with all UUIDs found on this proxy
|
|
|
|
*/
|
|
|
|
public final Set<UUID> getPlayersOnProxy(@NonNull String server) {
|
|
|
|
return plugin.getPlayersOnProxy(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) {
|
2014-08-10 03:16:47 +00:00
|
|
|
return plugin.getDataManager().getIp(player);
|
2013-12-13 21:32:55 +00:00
|
|
|
}
|
2014-01-02 00:05:55 +00:00
|
|
|
|
2014-08-21 01:31:02 +00:00
|
|
|
/**
|
|
|
|
* Get the RedisBungee proxy ID this player is connected to.
|
|
|
|
*
|
|
|
|
* @param player the player to fetch the IP for
|
|
|
|
* @return the proxy the player is connected to, or null if they are offline
|
|
|
|
* @since 0.3.3
|
|
|
|
*/
|
|
|
|
public final String getProxy(@NonNull UUID player) {
|
|
|
|
return plugin.getDataManager().getProxy(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
|
2022-07-17 11:38:00 +00:00
|
|
|
* @see #getProxyId()
|
|
|
|
* @see #getAllProxies()
|
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
|
|
|
|
2014-07-25 23:00:53 +00:00
|
|
|
/**
|
2022-04-14 12:26:33 +00:00
|
|
|
* Sends a message to a PubSub channel. The channel has to be subscribed to on this, or another redisbungee instance for
|
|
|
|
* PubSubMessageEvent to fire.
|
2014-07-25 23:00:53 +00:00
|
|
|
*
|
|
|
|
* @param channel The PubSub channel
|
|
|
|
* @param message the message body to send
|
|
|
|
* @since 0.3.3
|
|
|
|
*/
|
|
|
|
public final void sendChannelMessage(@NonNull String channel, @NonNull String message) {
|
2014-09-21 17:56:46 +00:00
|
|
|
plugin.sendChannelMessage(channel, message);
|
2014-07-25 23:00:53 +00:00
|
|
|
}
|
2014-09-21 17:56:46 +00:00
|
|
|
|
2014-01-17 02:31:57 +00:00
|
|
|
/**
|
2022-07-17 11:38:00 +00:00
|
|
|
* Get the current BungeeCord / Velocity proxy ID for this server.
|
|
|
|
*
|
|
|
|
* @return the current server ID
|
|
|
|
* @see #getAllProxies()
|
|
|
|
* @since 0.8.0
|
|
|
|
*/
|
|
|
|
public final String getProxyId() {
|
|
|
|
return plugin.getConfiguration().getProxyId();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current BungeeCord / Velocity proxy 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
|
2022-07-17 11:38:00 +00:00
|
|
|
* @deprecated to avoid confusion between A server and A proxy see #getProxyId()
|
2014-01-17 02:31:57 +00:00
|
|
|
*/
|
2022-07-17 11:38:00 +00:00
|
|
|
@Deprecated
|
2014-01-17 02:31:57 +00:00
|
|
|
public final String getServerId() {
|
2022-07-17 11:38:00 +00:00
|
|
|
return getProxyId();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the linked proxies in this network.
|
|
|
|
*
|
|
|
|
* @return the list of all proxies
|
|
|
|
* @see #getProxyId()
|
|
|
|
* @since 0.8.0
|
|
|
|
*/
|
|
|
|
public final List<String> getAllProxies() {
|
|
|
|
return plugin.getProxiesIds();
|
2014-01-17 02:31:57 +00:00
|
|
|
}
|
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
|
2022-07-17 11:38:00 +00:00
|
|
|
* @deprecated to avoid confusion between A server and A proxy see see {@link #getAllProxies()}
|
2014-01-28 22:33:53 +00:00
|
|
|
*/
|
2022-07-17 11:38:00 +00:00
|
|
|
@Deprecated
|
2014-01-28 22:33:53 +00:00
|
|
|
public final List<String> getAllServers() {
|
2022-07-17 11:38:00 +00:00
|
|
|
return getAllProxies();
|
2014-01-28 22:33:53 +00:00
|
|
|
}
|
2014-03-31 15:19:33 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-14 12:26:33 +00:00
|
|
|
* Register (a) PubSub channel(s), so that you may handle PubSubMessageEvent for it.
|
2014-03-31 15:19:33 +00:00
|
|
|
*
|
|
|
|
* @param channels the channels to register
|
2014-05-17 00:41:59 +00:00
|
|
|
* @since 0.3
|
2014-03-31 15:19:33 +00:00
|
|
|
*/
|
|
|
|
public final void registerPubSubChannels(String... channels) {
|
2022-04-13 13:14:08 +00:00
|
|
|
plugin.getPubSubListener().addChannel(channels);
|
2014-03-31 15:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister (a) PubSub channel(s).
|
|
|
|
*
|
|
|
|
* @param channels the channels to unregister
|
2014-05-17 00:41:59 +00:00
|
|
|
* @since 0.3
|
2014-03-31 15:19:33 +00:00
|
|
|
*/
|
|
|
|
public final void unregisterPubSubChannels(String... channels) {
|
2014-11-02 19:16:41 +00:00
|
|
|
for (String channel : channels) {
|
|
|
|
Preconditions.checkArgument(!reservedChannels.contains(channel), "attempting to unregister internal channel");
|
|
|
|
}
|
|
|
|
|
2022-07-17 11:38:00 +00:00
|
|
|
plugin.getPubSubListener().removeChannel(channels);
|
2014-03-31 15:19:33 +00:00
|
|
|
}
|
2014-04-20 05:12:28 +00:00
|
|
|
|
|
|
|
/**
|
2014-05-17 00:41:59 +00:00
|
|
|
* Fetch a name from the specified UUID. UUIDs are cached locally and in Redis. This function falls back to Mojang
|
|
|
|
* as a last resort, so calls <strong>may</strong> be blocking.
|
|
|
|
* <p>
|
2015-07-02 01:06:13 +00:00
|
|
|
* For the common use case of translating a list of UUIDs into names, use {@link #getHumanPlayersOnline()} instead.
|
2014-05-31 03:22:31 +00:00
|
|
|
* <p>
|
|
|
|
* If performance is a concern, use {@link #getNameFromUuid(java.util.UUID, boolean)} as this allows you to disable Mojang lookups.
|
2014-04-20 05:12:28 +00:00
|
|
|
*
|
|
|
|
* @param uuid the UUID to fetch the name for
|
|
|
|
* @return the name for the UUID
|
|
|
|
* @since 0.3
|
|
|
|
*/
|
2014-05-28 06:06:17 +00:00
|
|
|
public final String getNameFromUuid(@NonNull UUID uuid) {
|
2014-05-31 03:22:31 +00:00
|
|
|
return getNameFromUuid(uuid, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a name from the specified UUID. UUIDs are cached locally and in Redis. This function can fall back to Mojang
|
|
|
|
* as a last resort if {@code expensiveLookups} is true, so calls <strong>may</strong> be blocking.
|
|
|
|
* <p>
|
2015-07-02 01:06:13 +00:00
|
|
|
* For the common use case of translating the list of online players into names, use {@link #getHumanPlayersOnline()}.
|
2014-05-31 03:22:31 +00:00
|
|
|
* <p>
|
|
|
|
* If performance is a concern, set {@code expensiveLookups} to false as this will disable lookups via Mojang.
|
|
|
|
*
|
2014-09-21 17:56:46 +00:00
|
|
|
* @param uuid the UUID to fetch the name for
|
2014-05-31 03:22:31 +00:00
|
|
|
* @param expensiveLookups whether or not to perform potentially expensive lookups
|
|
|
|
* @return the name for the UUID
|
|
|
|
* @since 0.3.2
|
|
|
|
*/
|
|
|
|
public final String getNameFromUuid(@NonNull UUID uuid, boolean expensiveLookups) {
|
|
|
|
return plugin.getUuidTranslator().getNameFromUuid(uuid, expensiveLookups);
|
2014-04-20 05:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-17 00:41:59 +00:00
|
|
|
* Fetch a UUID from the specified name. Names are cached locally and in Redis. This function falls back to Mojang
|
|
|
|
* as a last resort, so calls <strong>may</strong> be blocking.
|
2014-05-31 03:22:31 +00:00
|
|
|
* <p>
|
|
|
|
* If performance is a concern, see {@link #getUuidFromName(String, boolean)}, which disables the following functions:
|
|
|
|
* <ul>
|
2014-09-21 17:56:46 +00:00
|
|
|
* <li>Searching local entries case-insensitively</li>
|
|
|
|
* <li>Searching Mojang</li>
|
2014-05-31 03:22:31 +00:00
|
|
|
* </ul>
|
2014-04-20 05:12:28 +00:00
|
|
|
*
|
|
|
|
* @param name the UUID to fetch the name for
|
|
|
|
* @return the UUID for the name
|
|
|
|
* @since 0.3
|
|
|
|
*/
|
2014-05-28 06:06:17 +00:00
|
|
|
public final UUID getUuidFromName(@NonNull String name) {
|
2014-05-31 03:22:31 +00:00
|
|
|
return getUuidFromName(name, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a UUID from the specified name. Names are cached locally and in Redis. This function falls back to Mojang
|
|
|
|
* as a last resort if {@code expensiveLookups} is true, so calls <strong>may</strong> be blocking.
|
|
|
|
* <p>
|
|
|
|
* If performance is a concern, set {@code expensiveLookups} to false to disable searching Mojang and searching for usernames
|
|
|
|
* case-insensitively.
|
|
|
|
*
|
2014-09-21 17:56:46 +00:00
|
|
|
* @param name the UUID to fetch the name for
|
2014-05-31 03:22:31 +00:00
|
|
|
* @param expensiveLookups whether or not to perform potentially expensive lookups
|
2022-04-14 10:34:56 +00:00
|
|
|
* @return the {@link UUID} for the name
|
2014-05-31 03:22:31 +00:00
|
|
|
* @since 0.3.2
|
|
|
|
*/
|
|
|
|
public final UUID getUuidFromName(@NonNull String name, boolean expensiveLookups) {
|
|
|
|
return plugin.getUuidTranslator().getTranslatedUuid(name, expensiveLookups);
|
2014-04-20 05:12:28 +00:00
|
|
|
}
|
2021-07-29 22:12:01 +00:00
|
|
|
|
2022-07-19 11:30:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Kicks a player from the network
|
|
|
|
*
|
|
|
|
* @param playerName player name
|
|
|
|
* @param message kick message that player will see on kick
|
|
|
|
* @since 0.8.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void kickPlayer(String playerName, String message) {
|
|
|
|
plugin.kickPlayer(playerName, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kicks a player from the network
|
|
|
|
*
|
|
|
|
* @param playerUUID player name
|
|
|
|
* @param message kick message that player will see on kick
|
|
|
|
* @since 0.8.0
|
|
|
|
*/
|
|
|
|
public void kickPlayer(UUID playerUUID, String message) {
|
|
|
|
plugin.kickPlayer(playerUUID, message);
|
|
|
|
}
|
|
|
|
|
2022-04-14 10:34:56 +00:00
|
|
|
/**
|
|
|
|
* This gives you instance of Jedis
|
2022-07-17 11:38:00 +00:00
|
|
|
*
|
2022-04-14 10:34:56 +00:00
|
|
|
* @return {@link Jedis}
|
2022-04-13 13:14:08 +00:00
|
|
|
* @since 0.7.0
|
2022-07-25 14:49:49 +00:00
|
|
|
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE}
|
2022-07-26 13:47:18 +00:00
|
|
|
* @see #getJedisPool()
|
2021-07-29 22:12:01 +00:00
|
|
|
*/
|
2022-04-14 10:34:56 +00:00
|
|
|
public Jedis requestJedis() {
|
2022-07-16 05:18:33 +00:00
|
|
|
if (getMode() == RedisBungeeMode.SINGLE) {
|
2022-07-26 13:47:18 +00:00
|
|
|
return getJedisPool().getResource();
|
2022-07-16 05:18:33 +00:00
|
|
|
} else {
|
2022-07-23 04:21:36 +00:00
|
|
|
throw new IllegalStateException("Mode is not " + RedisBungeeMode.SINGLE);
|
2022-07-16 05:18:33 +00:00
|
|
|
}
|
2021-07-29 22:12:01 +00:00
|
|
|
}
|
2022-07-17 11:38:00 +00:00
|
|
|
|
2022-07-15 22:58:48 +00:00
|
|
|
/**
|
|
|
|
* This gets Redis Bungee {@link JedisPool}
|
2022-07-17 11:38:00 +00:00
|
|
|
*
|
2022-07-15 22:58:48 +00:00
|
|
|
* @return {@link JedisPool}
|
2022-07-17 11:38:00 +00:00
|
|
|
* @since 0.6.5
|
2022-07-25 14:49:49 +00:00
|
|
|
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE}
|
2022-07-26 13:47:18 +00:00
|
|
|
* @throws IllegalStateException if JedisPool compatibility mode is disabled in the config
|
2022-07-15 22:58:48 +00:00
|
|
|
*/
|
|
|
|
public JedisPool getJedisPool() {
|
2022-07-16 05:18:33 +00:00
|
|
|
if (getMode() == RedisBungeeMode.SINGLE) {
|
2022-07-26 13:47:18 +00:00
|
|
|
JedisPool jedisPool = ((JedisPooledSummoner) this.plugin.getSummoner()).getCompatibilityJedisPool();
|
|
|
|
if (jedisPool == null) {
|
|
|
|
throw new IllegalStateException("JedisPool compatibility mode is disabled");
|
|
|
|
}
|
|
|
|
return jedisPool;
|
2022-07-16 05:18:33 +00:00
|
|
|
} else {
|
2022-07-23 04:21:36 +00:00
|
|
|
throw new IllegalStateException("Mode is not " + RedisBungeeMode.SINGLE);
|
2022-07-16 05:18:33 +00:00
|
|
|
}
|
2022-07-15 22:58:48 +00:00
|
|
|
}
|
|
|
|
|
2022-07-16 05:18:33 +00:00
|
|
|
/**
|
2022-07-26 13:47:18 +00:00
|
|
|
* This gives you instance of JedisCluster
|
2022-07-25 15:13:25 +00:00
|
|
|
* WARNING DO NOT USE {@link JedisCluster#close()} it will break the functionally
|
2022-07-17 11:38:00 +00:00
|
|
|
*
|
2022-07-16 05:18:33 +00:00
|
|
|
* @return {@link redis.clients.jedis.JedisCluster}
|
|
|
|
* @since 0.8.0
|
2022-07-25 14:49:49 +00:00
|
|
|
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#CLUSTER}
|
2022-07-16 05:18:33 +00:00
|
|
|
*/
|
2022-07-25 15:13:25 +00:00
|
|
|
public JedisCluster requestClusterJedis() {
|
2022-07-16 05:18:33 +00:00
|
|
|
if (getMode() == RedisBungeeMode.CLUSTER) {
|
2022-07-25 15:13:25 +00:00
|
|
|
return ((JedisClusterSummoner) this.plugin.getSummoner()).obtainResource();
|
2022-07-16 05:18:33 +00:00
|
|
|
} else {
|
2022-07-23 04:21:36 +00:00
|
|
|
throw new IllegalStateException("Mode is not " + RedisBungeeMode.CLUSTER);
|
2022-07-16 05:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-15 22:58:48 +00:00
|
|
|
|
2022-07-23 04:21:36 +00:00
|
|
|
/**
|
2022-07-26 13:47:18 +00:00
|
|
|
* This gives you instance of JedisPooled
|
|
|
|
* WARNING: DO NOT USE {@link redis.clients.jedis.JedisPooled#close()} it will break the functionally
|
|
|
|
*
|
|
|
|
* @return {@link redis.clients.jedis.JedisPooled}
|
|
|
|
* @since 0.8.0
|
|
|
|
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE}
|
|
|
|
*/
|
|
|
|
public JedisCluster requestJedisPooled() {
|
|
|
|
if (getMode() == RedisBungeeMode.SINGLE) {
|
|
|
|
return ((JedisClusterSummoner) this.plugin.getSummoner()).obtainResource();
|
|
|
|
} else {
|
|
|
|
throw new IllegalStateException("Mode is not " + RedisBungeeMode.SINGLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns Summoner class responsible for Single Jedis {@link redis.clients.jedis.JedisPooled} with {@link JedisPool}, Cluster Jedis {@link redis.clients.jedis.JedisCluster} handling
|
2022-07-23 04:21:36 +00:00
|
|
|
*
|
|
|
|
* @return {@link Summoner}
|
|
|
|
* @since 0.8.0
|
|
|
|
*/
|
|
|
|
public Summoner<?> getSummoner() {
|
|
|
|
return this.plugin.getSummoner();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-29 22:12:01 +00:00
|
|
|
/**
|
2022-07-16 05:18:33 +00:00
|
|
|
* shows what mode is RedisBungee is on
|
2022-07-17 11:38:00 +00:00
|
|
|
*
|
2022-07-16 05:18:33 +00:00
|
|
|
* @return {@link RedisBungeeMode}
|
|
|
|
* @since 0.8.0
|
|
|
|
*/
|
|
|
|
public RedisBungeeMode getMode() {
|
|
|
|
return this.plugin.getRedisBungeeMode();
|
|
|
|
}
|
|
|
|
|
2022-07-27 13:43:51 +00:00
|
|
|
public static AbstractRedisBungeeAPI getAbstractRedisBungeeAPI() {
|
|
|
|
return abstractRedisBungeeAPI;
|
2021-07-29 22:12:01 +00:00
|
|
|
}
|
2013-11-15 22:05:29 +00:00
|
|
|
}
|