com.imaginarycode.minecraft.redisbungee.RedisBungee Java Examples
The following examples show how to use
com.imaginarycode.minecraft.redisbungee.RedisBungee.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UUIDFetcher.java From RedisBungee with Eclipse Public License 1.0 | 6 votes |
public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<>(); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { String body = RedisBungee.getGson().toJson(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); Request request = new Request.Builder().url(PROFILE_URL).post(RequestBody.create(JSON, body)).build(); ResponseBody responseBody = httpClient.newCall(request).execute().body(); String response = responseBody.string(); responseBody.close(); Profile[] array = RedisBungee.getGson().fromJson(response, Profile[].class); for (Profile profile : array) { UUID uuid = UUIDFetcher.getUUID(profile.id); uuidMap.put(profile.name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
Example #2
Source File: NameFetcher.java From RedisBungee with Eclipse Public License 1.0 | 6 votes |
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException { String url = "https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names"; Request request = new Request.Builder().url(url).get().build(); ResponseBody body = httpClient.newCall(request).execute().body(); String response = body.string(); body.close(); Type listType = new TypeToken<List<Name>>() { }.getType(); List<Name> names = RedisBungee.getGson().fromJson(response, listType); List<String> humanNames = new ArrayList<>(); for (Name name : names) { humanNames.add(name.name); } return humanNames; }
Example #3
Source File: RedisPlayerManager.java From BungeeTabListPlus with GNU General Public License v3.0 | 6 votes |
private <T> void updateData(UUID uuid, DataKey<T> key, T value) { try { ByteArrayDataOutput data = ByteStreams.newDataOutput(); DataStreamUtils.writeUUID(data, uuid); DataStreamUtils.writeDataKey(data, key); data.writeBoolean(value == null); if (value != null) { typeRegistry.getTypeAdapter(key.getType()).write(data, value); } RedisBungee.getApi().sendChannelMessage(CHANNEL_DATA_UPDATE, Base64.getEncoder().encodeToString(data.toByteArray())); } catch (RuntimeException ex) { BungeeTabListPlus.getInstance().getLogger().log(Level.WARNING, "RedisBungee Error", ex); } catch (Throwable th) { BungeeTabListPlus.getInstance().getLogger().log(Level.SEVERE, "Failed to send data", th); } }
Example #4
Source File: RedisPlayerManager.java From BungeeTabListPlus with GNU General Public License v3.0 | 6 votes |
public <T> void request(UUID uuid, DataKey<T> key) { try { ByteArrayDataOutput data = ByteStreams.newDataOutput(); DataStreamUtils.writeUUID(data, uuid); DataStreamUtils.writeDataKey(data, key); RedisBungee.getApi().sendChannelMessage(CHANNEL_DATA_REQUEST, Base64.getEncoder().encodeToString(data.toByteArray())); redisBungeeAPIError = false; } catch (RuntimeException ex) { if (!redisBungeeAPIError) { logger.log(Level.WARNING, "Error using RedisBungee API", ex); redisBungeeAPIError = true; } } catch (Throwable th) { BungeeTabListPlus.getInstance().getLogger().log(Level.SEVERE, "Failed to request data", th); } }
Example #5
Source File: Kick.java From BungeeAdminTools with GNU General Public License v3.0 | 6 votes |
public String gKickSQL(final UUID pUUID, final String staff, final String reason) { PreparedStatement statement = null; try (Connection conn = BAT.getConnection()) { if (DataSourceHandler.isSQLite()) { statement = conn.prepareStatement(fr.Alphart.BAT.database.SQLQueries.Kick.SQLite.kickPlayer); } else { statement = conn.prepareStatement(SQLQueries.Kick.kickPlayer); } statement.setString(1, pUUID.toString().replace("-", "")); statement.setString(2, staff); statement.setString(3, reason); statement.setString(4, GLOBAL_SERVER); statement.executeUpdate(); statement.close(); if (BAT.getInstance().getRedis().isRedisEnabled()) { return _("gKickBroadcast", new String[] { RedisBungee.getApi().getNameFromUuid(pUUID), staff, reason }); } else { return _("gKickBroadcast", new String[] { BAT.getInstance().getProxy().getPlayer(pUUID).getName(), staff, reason }); } } catch (final SQLException e) { return DataSourceHandler.handleException(e); } finally { DataSourceHandler.close(statement); } }
Example #6
Source File: DiscordBot.java From DiscordBot with Apache License 2.0 | 5 votes |
private void loadRedis() { if (!DiscordBotCore.getInstance().getConfiguration().isRedisEnabled()) { return; } redisBungee = RedisBungee.getApi(); redisBungee.registerPubSubChannels("DiscordBot"); getProxy().getPluginManager().registerListener(this, new RedisListener()); getLogger().info("Redis Enabled."); }
Example #7
Source File: RedisPlayerManager.java From BungeeTabListPlus with GNU General Public License v3.0 | 5 votes |
public RedisPlayerManager(BungeePlayerProvider bungeePlayerProvider, BungeeTabListPlus plugin, Logger logger) { this.bungeePlayerProvider = bungeePlayerProvider; this.plugin = plugin; this.logger = logger; this.mainThread = plugin.getMainThreadExecutor(); RedisBungee.getApi().registerPubSubChannels(CHANNEL_REQUEST_DATA_OLD, CHANNEL_DATA_OLD); RedisBungee.getApi().registerPubSubChannels(CHANNEL_DATA_REQUEST, CHANNEL_DATA_UPDATE); ProxyServer.getInstance().getScheduler().schedule(BungeeTabListPlus.getInstance().getPlugin(), this::updatePlayers, 5, 5, TimeUnit.SECONDS); ProxyServer.getInstance().getPluginManager().registerListener(BungeeTabListPlus.getInstance().getPlugin(), this); }
Example #8
Source File: DataManager.java From BungeeTabListPlus with GNU General Public License v3.0 | 5 votes |
LocalPlayerDataAccess(Plugin plugin, Logger logger) { super(plugin, logger); addProvider(BTLPBungeeDataKeys.DATA_KEY_GAMEMODE, p -> ((UserConnection) p).getGamemode()); addProvider(BTLPBungeeDataKeys.DATA_KEY_ICON, IconUtil::getIconFromPlayer); addProvider(BTLPBungeeDataKeys.ThirdPartyPlaceholderBungee, (player, dataKey) -> api.resolveCustomPlaceholder(dataKey.getParameter(), player)); addProvider(BTLPBungeeDataKeys.DATA_KEY_IS_HIDDEN_PLAYER_CONFIG, (player, dataKey) -> permanentlyHiddenPlayers.contains(player.getName()) || permanentlyHiddenPlayers.contains(player.getUniqueId().toString())); if (ProxyServer.getInstance().getPluginManager().getPlugin("RedisBungee") != null) { addProvider(BTLPBungeeDataKeys.DATA_KEY_RedisBungee_ServerId, player -> RedisBungee.getApi().getServerId()); } }
Example #9
Source File: Core.java From BungeeAdminTools with GNU General Public License v3.0 | 5 votes |
public static String getPlayerIP(final String pName) { if (BAT.getInstance().getRedis().isRedisEnabled()) { try { final UUID pUUID = RedisBungee.getApi().getUuidFromName(pName, true); if (pUUID != null && RedisBungee.getApi().isPlayerOnline(pUUID)) return RedisBungee.getApi().getPlayerIp(pUUID).getHostAddress(); } catch (Exception exp) { exp.printStackTrace(); } } else { final ProxiedPlayer player = ProxyServer.getInstance().getPlayer(pName); if (player != null) return Utils.getPlayerIP(player); } PreparedStatement statement = null; ResultSet resultSet = null; try (Connection conn = BAT.getConnection()) { statement = conn.prepareStatement(SQLQueries.Core.getIP); statement.setString(1, getUUID(pName)); resultSet = statement.executeQuery(); if (resultSet.next()) { return resultSet.getString("lastip"); } } catch (final SQLException e) { DataSourceHandler.handleException(e); } finally { DataSourceHandler.close(statement, resultSet); } return "0.0.0.0"; }
Example #10
Source File: Ban.java From BungeeAdminTools with GNU General Public License v3.0 | 5 votes |
public String banRedisIP(final UUID pUUID, final String server, final String staff, final long expirationTimestamp, final String reason) { if (BAT.getInstance().getRedis().isRedisEnabled() && RedisBungee.getApi().isPlayerOnline(pUUID)) { ban(RedisBungee.getApi().getPlayerIp(pUUID).getHostAddress(), server, staff, expirationTimestamp, reason); return _("banBroadcast", new String[] { RedisBungee.getApi().getNameFromUuid(pUUID) + "'s IP", staff, server, reason }); } else { return null; } }
Example #11
Source File: RedisUtils.java From BungeeAdminTools with GNU General Public License v3.0 | 5 votes |
void sendMessage(String messageType, String messageBody) { if (!redis) return; if (messageBody.trim().length() == 0) return; final String message = RedisBungee.getApi().getServerId() + split + messageType + split + messageBody; BAT.getInstance().getProxy().getScheduler().runAsync(BAT.getInstance(), new Runnable() { @Override public void run() { RedisBungee.getApi().sendChannelMessage(channel, message); } }); }
Example #12
Source File: RedisUtils.java From BungeeAdminTools with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPubSubMessage(final PubSubMessageEvent e) { if (!e.getChannel().equals(channel)) return; String[] message = e.getMessage().split(split); if (message[0].equalsIgnoreCase(RedisBungee.getApi().getServerId()) || message.length < 3) return; String messageType = message[1]; switch (messageType) { case "gkick": recieveGKickPlayer(message[2], message[3]); break; case "message": recieveMessagePlayer(message[2], message[3]); break; case "broadcast": recieveBroadcast(message[2], message[3]); break; case "muteupdate": recieveMuteUpdatePlayer(message[2], message[3]); break; case "movedefaultserver": recieveMoveDefaultServerPlayer(message[2]); break; default: BAT.getInstance().getLogger().warning("Undeclared BungeeAdminTool redis message recieved: " + messageType); break; } }
Example #13
Source File: RedisUtils.java From BungeeAdminTools with GNU General Public License v3.0 | 5 votes |
public RedisUtils(final boolean enable) { if(enable){ if (BAT.getInstance().getProxy().getPluginManager().getPlugin("RedisBungee") != null && RedisBungee.getApi() != null) { BAT.getInstance().getLogger().info("Detected RedisBungee. Enabling experimental RedisBungee support. This currently only supports RedisBungee 0.3.3 or higher (but not 0.4)."); BAT.getInstance().getProxy().getPluginManager() .registerListener(BAT.getInstance(), this); RedisBungee.getApi().registerPubSubChannels(channel); redis = true; } else { redis = false; } }else{ redis = false; } }
Example #14
Source File: RedisBungeeCalculator.java From LuckPerms with MIT License | 5 votes |
@Override public ContextSet estimatePotentialContexts() { RedisBungeeAPI redisBungee = RedisBungee.getApi(); if (redisBungee == null) { return ImmutableContextSetImpl.EMPTY; } ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (String server : redisBungee.getAllServers()) { builder.add(PROXY_KEY, server); } return builder.build(); }
Example #15
Source File: RedisBungeeCalculator.java From LuckPerms with MIT License | 5 votes |
@Override public void calculate(@NonNull ContextConsumer consumer) { RedisBungeeAPI redisBungee = RedisBungee.getApi(); if (redisBungee != null) { consumer.accept(PROXY_KEY, redisBungee.getServerId()); } }
Example #16
Source File: RedisPlayersOnlineSupplier.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
@Override public int getAsInt() { RedisBungeeAPI api = RedisBungee.getApi(); try { return api != null ? api.getPlayerCount() : -1; } catch (NullPointerException e) { return -1; } }
Example #17
Source File: RedisUtils.java From BungeeAdminTools with GNU General Public License v3.0 | 4 votes |
public void destroy() { if (!redis) return; RedisBungee.getApi().unregisterPubSubChannels("BungeeAdminTools"); BAT.getInstance().getProxy().getPluginManager() .unregisterListener(this); }
Example #18
Source File: BanCommand.java From BungeeAdminTools with GNU General Public License v3.0 | 4 votes |
public static void handleBanCommand(final BATCommand command, final boolean global, final boolean ipBan, final CommandSender sender, final String[] args, final boolean confirmedCmd) { String target = args[0]; String server = IModule.GLOBAL_SERVER; final String staff = sender.getName(); String reason = IModule.NO_REASON; final ProxiedPlayer player = ProxyServer.getInstance().getPlayer(target); UUID pUUID = null; if (BAT.getInstance().getRedis().isRedisEnabled()) { UUID tempUUID = RedisBungee.getApi().getUuidFromName(target, false); if (tempUUID != null && RedisBungee.getApi().isPlayerOnline(tempUUID)) pUUID = tempUUID; } String ip = null; String returnedMsg; if (global) { if (args.length > 1) { reason = Utils.getFinalArg(args, 1); } } else { if (args.length == 1) { checkArgument(sender instanceof ProxiedPlayer, _("specifyServer")); server = ((ProxiedPlayer) sender).getServer().getInfo().getName(); } else { checkArgument(Utils.isServer(args[1]), _("invalidServer")); server = args[1]; reason = (args.length > 2) ? Utils.getFinalArg(args, 2) : IModule.NO_REASON; } } checkArgument( !reason.equalsIgnoreCase(IModule.NO_REASON) || !BAT.getInstance().getConfiguration().isMustGiveReason(), _("noReasonInCommand")); // Check if the target isn't an ip and the player is offline if (!Utils.validIP(target) && player == null && pUUID == null) { ip = Core.getPlayerIP(target); if (ipBan) { checkArgument(!"0.0.0.0".equals(ip), _("ipUnknownPlayer")); } // If ip = 0.0.0.0, it means the player never connects else { if ("0.0.0.0".equals(ip) && !confirmedCmd) { command.mustConfirmCommand(sender, command.getName() + " " + Joiner.on(' ').join(args), _("operationUnknownPlayer", new String[] { target })); return; } // Set the ip to null to avoid checking if the ip is banned ip = null; } } if (!global) { checkArgument(PermissionManager.canExecuteAction((ipBan) ? Action.BANIP : Action.BAN, sender, server), _("noPerm")); } target = (ip == null) ? target : ip; // We just check if the target is exempt from the ban, which means he's // exempt from the full module command checkArgument(!PermissionManager.isExemptFrom(Action.BAN, target), _("isExempt")); checkArgument(!ban.isBan((ip == null) ? target : ip, server), _("alreadyBan")); if (ipBan && player != null) { returnedMsg = ban.banIP(player, server, staff, 0, reason); } else if (ipBan && pUUID != null) { returnedMsg = ban.banRedisIP(pUUID, server, staff, 0, reason); } else { returnedMsg = ban.ban(target, server, staff, 0, reason); } BAT.broadcast(returnedMsg, Action.banBroadcast.getPermission()); }
Example #19
Source File: BanCommand.java From BungeeAdminTools with GNU General Public License v3.0 | 4 votes |
public static void handleTempBanCommand(final BATCommand command, final boolean global, final boolean ipBan, final CommandSender sender, final String[] args, final boolean confirmedCmd) { String target = args[0]; final long expirationTimestamp = Utils.parseDuration(args[1]); String server = IModule.GLOBAL_SERVER; final String staff = sender.getName(); String reason = IModule.NO_REASON; final ProxiedPlayer player = ProxyServer.getInstance().getPlayer(target); UUID pUUID = null; if (BAT.getInstance().getRedis().isRedisEnabled()) { UUID tempUUID = RedisBungee.getApi().getUuidFromName(target, false); if (tempUUID != null && RedisBungee.getApi().isPlayerOnline(tempUUID)) pUUID = tempUUID; } String ip = null; String returnedMsg; if (global) { if (args.length > 2) { reason = Utils.getFinalArg(args, 2); } } else { if (args.length == 2) { checkArgument(sender instanceof ProxiedPlayer, _("specifyServer")); server = ((ProxiedPlayer) sender).getServer().getInfo().getName(); } else { checkArgument(Utils.isServer(args[2]), _("invalidServer")); server = args[2]; reason = (args.length > 3) ? Utils.getFinalArg(args, 3) : IModule.NO_REASON; } } checkArgument( !reason.equalsIgnoreCase(IModule.NO_REASON) || !BAT.getInstance().getConfiguration().isMustGiveReason(), _("noReasonInCommand")); // Check if the target isn't an ip and the player is offline if (!Utils.validIP(target) && player == null && pUUID == null) { ip = Core.getPlayerIP(target); if (ipBan) { checkArgument(!"0.0.0.0".equals(ip), _("ipUnknownPlayer")); } else { // If ip = 0.0.0.0, it means the player never connects if ("0.0.0.0".equals(ip) && !confirmedCmd) { command.mustConfirmCommand(sender, command.getName() + " " + Joiner.on(' ').join(args), _("operationUnknownPlayer", new String[] { target })); return; } // Set the ip to null to avoid checking if the ip is banned ip = null; } } if (!global) { checkArgument( PermissionManager.canExecuteAction((ipBan) ? Action.TEMPBANIP : Action.TEMPBAN, sender, server), _("noPerm")); } target = (ip == null) ? target : ip; checkArgument(!PermissionManager.isExemptFrom(Action.BAN, target), _("isExempt")); checkArgument(!ban.isBan(target, server), _("alreadyBan")); if (ipBan && player != null) { returnedMsg = ban.banIP(player, server, staff, expirationTimestamp, reason); } else if (ipBan && pUUID != null) { returnedMsg = ban.banRedisIP(pUUID, server, staff, expirationTimestamp, reason); } else { returnedMsg = ban.ban(target , server, staff, expirationTimestamp, reason); } BAT.broadcast(returnedMsg, Action.banBroadcast.getPermission()); }
Example #20
Source File: Mute.java From BungeeAdminTools with GNU General Public License v3.0 | 4 votes |
/** * Unmute an entity (player or ip) * * @param mutedEntity * | can be an ip or a player name * @param server * | if equals to (any), unmute from all servers | if equals to * (global), remove global mute * @param staff * @param reason * @param unMuteIP */ public String unMute(final String mutedEntity, final String server, final String staff, final String reason) { PreparedStatement statement = null; try (Connection conn = BAT.getConnection()) { // If the mutedEntity is an ip if (Utils.validIP(mutedEntity)) { final String ip = mutedEntity; if (ANY_SERVER.equals(server)) { statement = (DataSourceHandler.isSQLite()) ? conn.prepareStatement(SQLQueries.Mute.SQLite.unMuteIP) : conn.prepareStatement(SQLQueries.Mute.unMuteIP); statement.setString(1, reason); statement.setString(2, staff); statement.setString(3, ip); } else { statement = (DataSourceHandler.isSQLite()) ? conn .prepareStatement(SQLQueries.Mute.SQLite.unMuteIPServer) : conn .prepareStatement(SQLQueries.Mute.unMuteIPServer); statement.setString(1, reason); statement.setString(2, staff); statement.setString(3, ip); statement.setString(4, server); } statement.executeUpdate(); statement.close(); return _("unmuteBroadcast", new String[] { ip, staff, server, reason }); } // Otherwise it's a player else { final String pName = mutedEntity; if (ANY_SERVER.equals(server)) { statement = (DataSourceHandler.isSQLite()) ? conn.prepareStatement(SQLQueries.Mute.SQLite.unMute) : conn.prepareStatement(SQLQueries.Mute.unMute); statement.setString(1, reason); statement.setString(2, staff); statement.setString(3, Core.getUUID(pName)); } else { statement = (DataSourceHandler.isSQLite()) ? conn .prepareStatement(SQLQueries.Mute.SQLite.unMuteServer) : conn .prepareStatement(SQLQueries.Mute.unMuteServer); statement.setString(1, reason); statement.setString(2, staff); statement.setString(3, Core.getUUID(pName)); statement.setString(4, server); } statement.executeUpdate(); statement.close(); final ProxiedPlayer player = ProxyServer.getInstance().getPlayer(pName); if (player != null) { updateMuteData(player.getName()); if(ANY_SERVER.equals(server) || GLOBAL_SERVER.equals(server) || player.getServer().getInfo().getName().equalsIgnoreCase(server)){ player.sendMessage(__("wasUnmutedNotif", new String[] { reason })); } } else if (BAT.getInstance().getRedis().isRedisEnabled()) { final UUID pUUID = Core.getUUIDfromString(Core.getUUID(pName)); ServerInfo pServer = RedisBungee.getApi().getServerFor(pUUID); if (ANY_SERVER.equals(server) || GLOBAL_SERVER.equals(server) || (pServer != null && pServer.getName().equalsIgnoreCase(server))){ BAT.getInstance().getRedis().sendMuteUpdatePlayer(pUUID, server); BAT.getInstance().getRedis().sendMessagePlayer(pUUID, TextComponent.toLegacyText(__("wasUnmutedNotif", new String[] { reason }))); } } return _("unmuteBroadcast", new String[] { pName, staff, server, reason }); } } catch (final SQLException e) { return DataSourceHandler.handleException(e); } finally { DataSourceHandler.close(statement); } }
Example #21
Source File: RedisBungeeUtil.java From LuckPerms with MIT License | 4 votes |
public static Optional<String> lookupUsername(UUID uuid) { return Optional.ofNullable(RedisBungee.getApi()).map(a -> a.getNameFromUuid(uuid, true)); }
Example #22
Source File: RedisBungeeMessenger.java From LuckPerms with MIT License | 4 votes |
public void init() { this.redisBungee = RedisBungee.getApi(); this.redisBungee.registerPubSubChannels(CHANNEL); this.plugin.getBootstrap().getProxy().getPluginManager().registerListener(this.plugin.getBootstrap(), this); }
Example #23
Source File: UUIDTranslator.java From RedisBungee with Eclipse Public License 1.0 | 4 votes |
public final void persistInfo(String name, UUID uuid, Jedis jedis) { addToMaps(name, uuid); String json = RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)); jedis.hmset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json)); }
Example #24
Source File: UUIDTranslator.java From RedisBungee with Eclipse Public License 1.0 | 4 votes |
public final void persistInfo(String name, UUID uuid, Pipeline jedis) { addToMaps(name, uuid); String json = RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)); jedis.hmset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json)); }
Example #25
Source File: RedisBungeeUtil.java From LuckPerms with MIT License | 2 votes |
/** * Looks up a UUID from username via RedisBungee's uuid cache. * * @param username the username to lookup * @return a uuid, if present */ public static Optional<UUID> lookupUuid(String username) { return Optional.ofNullable(RedisBungee.getApi()).map(a -> a.getUuidFromName(username, true)); }