修改了配置文件config.yml以及多个Java文件ElementOriginLib.java, OriginLibConfig.java, RedisBungeeUtil.java的相关内容。
This commit is contained in:
		
							parent
							
								
									f240371292
								
							
						
					
					
						commit
						bc82dbb170
					
				|  | @ -1,5 +1,6 @@ | |||
| package com.io.yutian.elementoriginlib; | ||||
| 
 | ||||
| import com.io.yutian.elementoriginlib.config.OriginLibConfig; | ||||
| import com.io.yutian.elementoriginlib.lang.Lang; | ||||
| import com.io.yutian.elementoriginlib.listener.GuiHandlerListener; | ||||
| import com.io.yutian.elementoriginlib.listener.PlayerChatInputListener; | ||||
|  | @ -9,6 +10,7 @@ import com.io.yutian.elementoriginlib.redis.RedisIO; | |||
| import net.byteflux.libby.*; | ||||
| import net.byteflux.libby.logging.LogLevel; | ||||
| import org.bukkit.plugin.java.JavaPlugin; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
| import org.slf4j.LoggerFactory; | ||||
| 
 | ||||
| public final class ElementOriginLib extends JavaPlugin { | ||||
|  | @ -20,6 +22,8 @@ public final class ElementOriginLib extends JavaPlugin { | |||
| 
 | ||||
|     private RedisIO redisIO; | ||||
| 
 | ||||
|     private OriginLibConfig config; | ||||
| 
 | ||||
|     @Override | ||||
|     public void onEnable() { | ||||
|         instance = this; | ||||
|  | @ -59,10 +63,18 @@ public final class ElementOriginLib extends JavaPlugin { | |||
|     } | ||||
| 
 | ||||
|     public void reload() { | ||||
|         config = new OriginLibConfig(); | ||||
|         saveDefaultConfig(); | ||||
|         reloadConfig(); | ||||
|         config.load(getConfig()); | ||||
|         Lang.registerLangFile(this); | ||||
|         Lang.reload(); | ||||
|     } | ||||
| 
 | ||||
|     public OriginLibConfig getLibConfig() { | ||||
|         return config; | ||||
|     } | ||||
| 
 | ||||
|     public RedisIO getRedisIO() { | ||||
|         return redisIO; | ||||
|     } | ||||
|  |  | |||
|  | @ -0,0 +1,23 @@ | |||
| package com.io.yutian.elementoriginlib.config; | ||||
| 
 | ||||
| import org.bukkit.configuration.file.FileConfiguration; | ||||
| 
 | ||||
| public class OriginLibConfig { | ||||
| 
 | ||||
|     private String redisBungeeNetworkId; | ||||
|     private String redisBungeeProxyId; | ||||
| 
 | ||||
|     public void load(FileConfiguration config) { | ||||
|         redisBungeeNetworkId = config.getString("redisBungeeNetworkId"); | ||||
|         redisBungeeProxyId = config.getString("redisBungeeProxyId"); | ||||
|     } | ||||
| 
 | ||||
|     public String getRedisBungeeNetworkId() { | ||||
|         return redisBungeeNetworkId; | ||||
|     } | ||||
| 
 | ||||
|     public String getRedisBungeeProxyId() { | ||||
|         return redisBungeeProxyId; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,65 @@ | |||
| package com.io.yutian.elementoriginlib.redis; | ||||
| 
 | ||||
| import com.google.common.net.InetAddresses; | ||||
| import com.io.yutian.elementoriginlib.ElementOriginLib; | ||||
| import redis.clients.jedis.Jedis; | ||||
| 
 | ||||
| import java.net.InetAddress; | ||||
| import java.util.HashSet; | ||||
| import java.util.Set; | ||||
| import java.util.UUID; | ||||
| 
 | ||||
| public class RedisBungeeUtil { | ||||
| 
 | ||||
|     public static String getProxyFromRedis(UUID uuid) { | ||||
|         try (Jedis jedis = ElementOriginLib.inst().getRedisIO().getJedisPool().getResource()) { | ||||
|             return jedis.hget("redis-bungee::" + ElementOriginLib.inst().getLibConfig().getRedisBungeeNetworkId() + "::player::" + uuid + "::data", "proxy"); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static String getServerFromRedis(UUID uuid) { | ||||
|         try (Jedis jedis = ElementOriginLib.inst().getRedisIO().getJedisPool().getResource()) { | ||||
|             return jedis.hget("redis-bungee::" + ElementOriginLib.inst().getLibConfig().getRedisBungeeNetworkId() + "::player::" + uuid + "::data", "server"); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static String getLastServerFromRedis(UUID uuid) { | ||||
|         try (Jedis jedis = ElementOriginLib.inst().getRedisIO().getJedisPool().getResource()) { | ||||
|             return jedis.hget("redis-bungee::" + ElementOriginLib.inst().getLibConfig().getRedisBungeeNetworkId() + "::player::" + uuid + "::data", "last-server"); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static InetAddress getIpAddressFromRedis(UUID uuid) { | ||||
|         try (Jedis jedis = ElementOriginLib.inst().getRedisIO().getJedisPool().getResource()) { | ||||
|             String ip = jedis.hget("redis-bungee::" + ElementOriginLib.inst().getLibConfig().getRedisBungeeNetworkId() + "::player::" + uuid + "::data", "ip"); | ||||
|             if (ip == null) return null; | ||||
|             return InetAddresses.forString(ip); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static long getLastOnlineFromRedis(UUID uuid) { | ||||
|         try (Jedis jedis = ElementOriginLib.inst().getRedisIO().getJedisPool().getResource()) { | ||||
|             String unixString = jedis.hget("redis-bungee::" + ElementOriginLib.inst().getLibConfig().getRedisBungeeNetworkId() + "::player::" + uuid + "::data", "last-online"); | ||||
|             if (unixString == null) return -1; | ||||
|             return Long.parseLong(unixString); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static boolean isPlayerTrulyOnProxy(String proxyId, UUID uuid) { | ||||
|         try (Jedis jedis = ElementOriginLib.inst().getRedisIO().getJedisPool().getResource()) { | ||||
|             return jedis.sismember("redis-bungee::" + ElementOriginLib.inst().getLibConfig().getRedisBungeeNetworkId() + "::proxies::" + proxyId + "::online-players", uuid.toString()); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static Set<UUID> getProxyMembers(String proxyId) { | ||||
|         try (Jedis jedis = ElementOriginLib.inst().getRedisIO().getJedisPool().getResource()) { | ||||
|             Set<String> uuidsStrings = jedis.smembers("redisbungee::" + ElementOriginLib.inst().getLibConfig().getRedisBungeeNetworkId() + "::proxies::" + proxyId + "::online-players"); | ||||
|             HashSet<UUID> uuids = new HashSet<>(); | ||||
|             for (String proxyMember : uuidsStrings) { | ||||
|                 uuids.add(UUID.fromString(proxyMember)); | ||||
|             } | ||||
|             return uuids; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										3
									
								
								src/main/resources/config.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/main/resources/config.yml
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| redis-bungee: | ||||
|   networkId: "main" | ||||
|   proxy-id: "proxy-1" | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user