whitelist progress

This commit is contained in:
ajgeiss0702
2021-08-08 19:50:07 -07:00
parent 4353341881
commit c4f06b0d77
13 changed files with 151 additions and 69 deletions
@@ -1,59 +0,0 @@
package us.ajg0702.queue.spigot;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
public class Config {
final File f;
final YamlConfiguration yml;
final JavaPlugin pl;
public boolean getBoolean(String key) {
return yml.getBoolean(key);
}
public Config(JavaPlugin pl) {
this.pl = pl;
f = new File(pl.getDataFolder(), "config.yml");
if(!f.exists()) {
if(!Files.exists(pl.getDataFolder().toPath())) {
try {
Files.createDirectory(pl.getDataFolder().toPath());
} catch (IOException e) {
e.printStackTrace();
}
}
try {
PrintWriter writer = new PrintWriter(pl.getDataFolder()+File.separator+"config.yml", "UTF-8");
String[] lines = getDefaultConfig().split("\n");
for(String line : lines) {
writer.println(line);
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
yml = YamlConfiguration.loadConfiguration(f);
}
public String getDefaultConfig() {
return "# This is the config for the spigot side.\n"
+ "# You can find more settings in the config of bungee.\n"
+ "\n\n"
+ "# Should we send queue requests from commands in batches?\n"
+ "# Enable this if you have issues with players sometimes not executing commands correctly\n"
+ "# Note though that it could delay queue commands by up to 1 second!\n"
+ "send-queue-commands-in-batches: false";
}
}
@@ -4,14 +4,19 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
import us.ajg0702.utils.common.ConfigFile;
import java.io.File;
import java.util.HashMap;
@SuppressWarnings("UnstableApiUsage")
@@ -20,7 +25,7 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
boolean papi = false;
Placeholders placeholders;
Config config;
ConfigFile config;
@SuppressWarnings("ConstantConditions")
public void onEnable() {
@@ -53,9 +58,20 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
queuebatch.clear();
sendMessage("massqueue", msg.toString());
}, 2*20, 20);
config = new Config(this);
File oldConfig = new File(getDataFolder(), "config.yml");
if(oldConfig.exists()) {
//noinspection ResultOfMethodCallIgnored
oldConfig.renameTo(new File(getDataFolder(), "spigot-config.yml"));
}
try {
config = new ConfigFile(getDataFolder(), getLogger(), "spigot-config.yml");
} catch (Exception e) {
getLogger().severe("Unable to read config:");
e.printStackTrace();
}
getLogger().info("Spigot side enabled! v"+getDescription().getVersion());
}
@@ -163,4 +179,19 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
if(!papi) return;
placeholders.cleanCache();
}
@EventHandler(priority = EventPriority.HIGH)
public void onServerPing(ServerListPingEvent e) {
if(!config.getBoolean("take-over-motd-for-whitelist")) return;
if(!Bukkit.hasWhitelist()) return;
StringBuilder whitelist = new StringBuilder();
for(OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
whitelist.append(player.getUniqueId()).append(",");
}
if(whitelist.length() > 1) {
whitelist.deleteCharAt(whitelist.length()-1);
}
e.setMotd("ajQueue;whitelisted="+whitelist);
}
}
@@ -0,0 +1,18 @@
# This is the config for the spigot side.
# You can find more settings in the config of bungee.
# Should we send queue requests from commands in batches?
# Enable this if you have issues with players sometimes not executing commands correctly
# Note though that it could delay queue commands by up to 1 second!
send-queue-commands-in-batches: false
# Should we take over the server MOTD to tell the proxy if the server is whitelisted?
# If you disable this, ajQueue will not be able to tell if the server is whitelisted!
take-over-motd-for-whitelist: true
# Dont touch this
config-version: 2