From 95209dfd8250d1f02a4955b29c4570ed7cecb0e7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 23 Apr 2022 22:31:16 +0200 Subject: [PATCH] Fix stuff --- src/config.yml | 4 ++++ src/de/steamwar/ConfigSystem.java | 17 ++++++++++++++++- src/de/steamwar/SteamWarBungeeTeamserver.java | 1 + .../listener/SteamwarConnectionListener.java | 9 ++++----- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/config.yml b/src/config.yml index 06da249..4ae90eb 100644 --- a/src/config.yml +++ b/src/config.yml @@ -7,6 +7,10 @@ plugin-enabled: true # Set this to 'true' to force the joining coming from SteamWar. force-only-steamwar-join: false +# Set this to a message to be displayed to the joinind player whilst not joining from SteamWar. +# This will only be sent if 'force-only-steamwar-join' is set to 'true'. +not-from-steamwar-message: "You are not allowed to join this server." + # Set this to 'true' to enable the TeamServer-Integration whitelist. # This will not affect normal connections, only those coming from SteamWar. whitelist-enabled: false diff --git a/src/de/steamwar/ConfigSystem.java b/src/de/steamwar/ConfigSystem.java index b24df69..e21f328 100644 --- a/src/de/steamwar/ConfigSystem.java +++ b/src/de/steamwar/ConfigSystem.java @@ -28,6 +28,7 @@ public class ConfigSystem { configFile = new File(SteamWarBungeeTeamserver.plugin.getDataFolder(), "config.yml"); if (!configFile.exists()) { try { + configFile.getParentFile().mkdirs(); configFile.createNewFile(); FileOutputStream fileOutputStream = new FileOutputStream(configFile); InputStream inputStream = SteamWarBungeeTeamserver.plugin.getResourceAsStream("config.yml"); @@ -40,11 +41,17 @@ public class ConfigSystem { inputStream.close(); enabled = true; } catch (Exception e) { - + // ignored } + } else { + enabled = true; } } + void init() { + + } + private synchronized void load() { if (!enabled) return; if (lastModified >= configFile.lastModified()) return; @@ -73,6 +80,14 @@ public class ConfigSystem { return false; } + public String getNotFromSteamWarMessage() { + load(); + if (config != null) { + return config.getString("not-from-steamwar-message", ""); + } + return "You are not allowed to join this server."; + } + public boolean isWhitelistEnabled() { load(); if (config != null) { diff --git a/src/de/steamwar/SteamWarBungeeTeamserver.java b/src/de/steamwar/SteamWarBungeeTeamserver.java index 07480cd..002c8b6 100644 --- a/src/de/steamwar/SteamWarBungeeTeamserver.java +++ b/src/de/steamwar/SteamWarBungeeTeamserver.java @@ -10,6 +10,7 @@ public final class SteamWarBungeeTeamserver extends Plugin { @Override public void onEnable() { plugin = this; + ConfigSystem.init(); getProxy().getPluginManager().registerListener(this, new SteamwarConnectionListener()); } diff --git a/src/de/steamwar/listener/SteamwarConnectionListener.java b/src/de/steamwar/listener/SteamwarConnectionListener.java index ff73666..ef91b81 100644 --- a/src/de/steamwar/listener/SteamwarConnectionListener.java +++ b/src/de/steamwar/listener/SteamwarConnectionListener.java @@ -2,6 +2,7 @@ package de.steamwar.listener; import de.steamwar.ConfigSystem; import io.netty.buffer.ByteBuf; +import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.event.PreLoginEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.connection.InitialHandler; @@ -86,12 +87,9 @@ public class SteamwarConnectionListener implements Listener { if (ConfigSystem.isWhitelistEnabled()) { Set whitelist = ConfigSystem.getWhitelist(); - if (!whitelist.contains(uuidStringBuilder.toString())) { - preLoginEvent.setCancelled(true); - return; - } - if (!whitelist.contains(preLoginEvent.getConnection().getName())) { + if (!whitelist.contains(uuidStringBuilder.toString()) && !whitelist.contains(preLoginEvent.getConnection().getName())) { preLoginEvent.setCancelled(true); + preLoginEvent.setCancelReason(new TextComponent()); return; } } @@ -110,6 +108,7 @@ public class SteamwarConnectionListener implements Listener { initialHandler.setUniqueId(UUID.fromString(uuidStringBuilder.toString())); } else if (ConfigSystem.isOnlySteamWarJoin()) { preLoginEvent.setCancelled(true); + preLoginEvent.setCancelReason(ConfigSystem.getNotFromSteamWarMessage()); } } }