diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/internal/AbstractRedisBungeeListener.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/internal/AbstractRedisBungeeListener.java index d755aa4..716a4f7 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/internal/AbstractRedisBungeeListener.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/internal/AbstractRedisBungeeListener.java @@ -11,7 +11,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; -public abstract class AbstractRedisBungeeListener { +public abstract class AbstractRedisBungeeListener { protected static final String ALREADY_LOGGED_IN = "§cYou are already logged on to this server. \n\nIt may help to try logging in again in a few minutes.\nIf this does not resolve your issue, please contact staff."; @@ -28,9 +28,6 @@ public abstract class AbstractRedisBungeeListener implements Listener { +public class RedisBungeeListener extends AbstractRedisBungeeListener implements Listener { public RedisBungeeListener(RedisBungeePlugin plugin, List exemptAddresses) { diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RBUtils.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RBUtils.java index 4c9c9d1..9eed0f7 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RBUtils.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RBUtils.java @@ -13,6 +13,7 @@ import java.util.Optional; public class RBUtils { + public static final String VERSION = "0.8.x-idk-how"; private static final Gson gson = new Gson(); protected static void createPlayer(Player player, Pipeline pipeline, boolean fireEvent) { diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java index 16e2443..efae24d 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java @@ -26,14 +26,13 @@ import redis.clients.jedis.Pipeline; import java.net.InetAddress; import java.util.*; -public class RedisBungeeListener extends AbstractRedisBungeeListener { +public class RedisBungeeListener extends AbstractRedisBungeeListener { public RedisBungeeListener(RedisBungeePlugin plugin, List exemptAddresses) { super(plugin, exemptAddresses); } - @Override @Subscribe public void onLogin(LoginEvent event, Continuation continuation) { plugin.executeAsync(new RedisCallable(plugin) { diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityPlugin.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityPlugin.java index db90793..e319cc1 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityPlugin.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityPlugin.java @@ -7,9 +7,9 @@ import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import com.google.common.io.ByteStreams; +import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.google.inject.Inject; -import com.imaginarycode.minecraft.redisbungee.commands.RedisBungeeCommands; import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent; @@ -26,16 +26,21 @@ import com.squareup.okhttp.OkHttpClient; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; +import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.scheduler.ScheduledTask; +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; +import ninja.leaping.configurate.yaml.YAMLConfigurationLoader; import org.slf4j.Logger; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.Pipeline; import redis.clients.jedis.exceptions.JedisConnectionException; +import static com.google.common.base.Preconditions.checkArgument; import java.io.*; import java.net.InetAddress; @@ -44,10 +49,8 @@ import java.nio.file.Path; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; - -import static com.google.common.base.Preconditions.checkArgument; +@Plugin(id = "redisbungee", name = "RedisBungee", version = RBUtils.VERSION, url = "https://github.com/ProxioDev/RedisBungee", authors = "ProxioDev") public class RedisBungeeVelocityPlugin implements RedisBungeePlugin { private static final Gson gson = new Gson(); @@ -408,7 +411,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin { getProxy().getEventManager().register(this, dataManager); psl = new PubSubListener(this); getProxy().getScheduler().buildTask(this, psl).schedule(); - integrityCheck = getProxy().getScheduler().buildTask(null,new Runnable() { + integrityCheck = getProxy().getScheduler().buildTask(this,new Runnable() { @Override public void run() { try (Jedis tmpRsc = requestJedis()) { @@ -526,9 +529,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin { if (!getDataFolder().exists()) { getDataFolder().mkdir(); } - File file = new File(getDataFolder(), "config.yml"); - if (!file.exists()) { file.createNewFile(); try (InputStream in = getResourceAsStream("example_config.yml"); @@ -537,21 +538,22 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin { } } - final Configuration yamlConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); + final YAMLConfigurationLoader yamlConfiguration = YAMLConfigurationLoader.builder().setFile(file).build(); - final String redisServer = yamlConfiguration.getString("redis-server", "localhost"); - final int redisPort = yamlConfiguration.getInt("redis-port", 6379); - final boolean useSSL = yamlConfiguration.getBoolean("useSSL", false); - String redisPassword = yamlConfiguration.getString("redis-password", ""); - String serverId = yamlConfiguration.getString("server-id"); + ConfigurationNode node = yamlConfiguration.load(); + final String redisServer = node.getNode("redis-server").getString(); + final int redisPort = node.getNode("redis-port").getInt(); + final boolean useSSL = node.getNode("useSSL").getBoolean(); + String redisPassword = node.getNode("redis-password").getString(); + String serverId = node.getNode("server-id").getString(); // check redis password if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) { redisPassword = null; - getLogger().warning("INSECURE setup was detected Please set password for your redis instance."); + getLogger().warn("INSECURE setup was detected Please set password for your redis instance."); } if (!useSSL) { - getLogger().warning("INSECURE setup was detected Please setup ssl for your redis instance."); + getLogger().warn("INSECURE setup was detected Please setup ssl for your redis instance."); } // Configuration sanity checks. if (serverId == null || serverId.isEmpty()) { @@ -561,18 +563,22 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin { */ String genId = UUID.randomUUID().toString(); getLogger().info("Generated server id " + genId + " and saving it to config."); - yamlConfiguration.set("server-id", genId); - ConfigurationProvider.getProvider(YamlConfiguration.class).save(yamlConfiguration, new File(getDataFolder(), "config.yml")); + node.getNode("server-id").setValue(genId); + yamlConfiguration.save(node); getLogger().info("Server id was generated: " + serverId); } else { getLogger().info("Loaded server id " + serverId + '.'); } - this.configuration = new RedisBungeeConfiguration(serverId, yamlConfiguration.getStringList("exempt-ip-addresses"), yamlConfiguration.getBoolean("register-bungee-commands", true)); + try { + this.configuration = new RedisBungeeConfiguration(serverId, node.getNode("exempt-ip-addresses").getList(TypeToken.of(String.class)), node.getNode("register-bungee-commands").getBoolean()); + } catch (ObjectMappingException e) { + throw new RuntimeException(e); + } if (redisServer != null && !redisServer.isEmpty()) { try { JedisPoolConfig config = new JedisPoolConfig(); - config.setMaxTotal(yamlConfiguration.getInt("max-redis-connections", 8)); + config.setMaxTotal(node.getNode("max-redis-connections").getInt()); this.jedisSummoner = new SinglePoolJedisSummoner(new JedisPool(config, redisServer, redisPort, 0, redisPassword, useSSL)); } catch (JedisConnectionException e) { @@ -591,7 +597,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin { long value = Long.parseLong(rsc.hget("heartbeats", serverId)); long redisTime = getRedisTime(rsc.time()); if (redisTime < value + 20) { - getLogger().error("You have launched a possible impostor BungeeCord instance. Another instance is already running."); + getLogger().error("You have launched a possible impostor Velocity / Bungeecord instance. Another instance is already running."); getLogger().error("For data consistency reasons, RedisBungee will now disable itself."); getLogger().error("If this instance is coming up from a crash, create a file in your RedisBungee plugins directory with the name 'restarted_from_crash.txt' and RedisBungee will not perform this check."); throw new RuntimeException("Possible impostor instance!");