whitelist progress
This commit is contained in:
@@ -20,6 +20,8 @@ dependencies {
|
||||
implementation("net.kyori:adventure-api:4.8.1")
|
||||
compileOnly("com.google.guava:guava:30.1.1-jre")
|
||||
|
||||
compileOnly("org.spongepowered:configurate-yaml:4.0.0")
|
||||
|
||||
compileOnly("us.ajg0702:ajUtils:1.1.8")
|
||||
|
||||
compileOnly(group = "org.spigotmc", name = "spigot", version = "1.16.5-R0.1-SNAPSHOT")
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user