whitelist progress
This commit is contained in:
@@ -5,6 +5,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
import us.ajg0702.queue.api.commands.ISubCommand;
|
import us.ajg0702.queue.api.commands.ISubCommand;
|
||||||
import us.ajg0702.queue.commands.BaseCommand;
|
import us.ajg0702.queue.commands.BaseCommand;
|
||||||
|
import us.ajg0702.queue.commands.commands.manage.debug.*;
|
||||||
import us.ajg0702.queue.common.QueueMain;
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
import us.ajg0702.utils.common.Messages;
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ public class ManageCommand extends BaseCommand {
|
|||||||
addSubCommand(new QueueList(main));
|
addSubCommand(new QueueList(main));
|
||||||
addSubCommand(new Send(main));
|
addSubCommand(new Send(main));
|
||||||
addSubCommand(new PermissionList(main));
|
addSubCommand(new PermissionList(main));
|
||||||
|
addSubCommand(new Whitelist(main));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package us.ajg0702.queue.commands.commands.manage;
|
package us.ajg0702.queue.commands.commands.manage.debug;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package us.ajg0702.queue.commands.commands.manage;
|
package us.ajg0702.queue.commands.commands.manage.debug;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package us.ajg0702.queue.commands.commands.manage;
|
package us.ajg0702.queue.commands.commands.manage.debug;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package us.ajg0702.queue.commands.commands.manage;
|
package us.ajg0702.queue.commands.commands.manage.debug;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package us.ajg0702.queue.commands.commands.manage.debug;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
|
import us.ajg0702.queue.commands.SubCommand;
|
||||||
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Whitelist extends SubCommand {
|
||||||
|
final QueueMain main;
|
||||||
|
public Whitelist(QueueMain main) {
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "whitelist";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImmutableList<String> getAliases() {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean showInTabComplete() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Messages getMessages() {
|
||||||
|
return main.getMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(ICommandSender sender, String[] args) {
|
||||||
|
if(!checkPermission(sender)) return;
|
||||||
|
if(args.length < 1) {
|
||||||
|
sender.sendMessage(main.getMessages().toComponent("<red>Not enough args!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QueueServer server = main.getQueueManager().findServer(args[0]);
|
||||||
|
if(server == null) {
|
||||||
|
sender.sendMessage(main.getMessages().toComponent("<red>Server not found"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sender.sendMessage(main.getMessages().toComponent("<green>Yours: "+ main.getPlatformMethods().senderToPlayer(sender).getUniqueId().toString()));
|
||||||
|
server.getWhitelistedPlayers().forEach(uuid -> sender.sendMessage(main.getMessages().toComponent("<yellow>"+uuid)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -137,6 +137,7 @@ public class QueueMain {
|
|||||||
d.put("status.offline.full", "full");
|
d.put("status.offline.full", "full");
|
||||||
d.put("status.offline.restricted", "restricted");
|
d.put("status.offline.restricted", "restricted");
|
||||||
d.put("status.offline.paused", "paused");
|
d.put("status.offline.paused", "paused");
|
||||||
|
d.put("status.offline.whitelisted", "whitelisted");
|
||||||
|
|
||||||
d.put("status.online.base", "&7You are in position &f{POS}&7 of &f{LEN}&7. Estimated time: {TIME}");
|
d.put("status.online.base", "&7You are in position &f{POS}&7 of &f{LEN}&7. Estimated time: {TIME}");
|
||||||
d.put("status.left-last-queue", "&aYou left the last queue you were in.");
|
d.put("status.left-last-queue", "&aYou left the last queue you were in.");
|
||||||
|
|||||||
@@ -473,6 +473,8 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
|
|
||||||
if(nextPlayer == null) continue; // None of the players in the queue are online
|
if(nextPlayer == null) continue; // None of the players in the queue are online
|
||||||
|
|
||||||
|
if(server.isWhitelisted() && !server.getWhitelistedPlayers().contains(nextPlayer.getUniqueId())) continue;
|
||||||
|
|
||||||
if(!server.canAccess(nextPlayer)) continue;
|
if(!server.canAccess(nextPlayer)) continue;
|
||||||
|
|
||||||
if(server.isFull() && !nextPlayer.hasPermission("ajqueue.joinfull")) continue;
|
if(server.isFull() && !nextPlayer.hasPermission("ajqueue.joinfull")) continue;
|
||||||
|
|||||||
@@ -105,6 +105,10 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
return msgs.getString("status.offline.paused");
|
return msgs.getString("status.offline.paused");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(p != null && isWhitelisted() && !getWhitelistedPlayers().contains(p.getUniqueId())) {
|
||||||
|
return msgs.getString("status.offline.whitelisted");
|
||||||
|
}
|
||||||
|
|
||||||
if(isFull()) {
|
if(isFull()) {
|
||||||
return msgs.getString("status.offline.full");
|
return msgs.getString("status.offline.full");
|
||||||
}
|
}
|
||||||
@@ -159,6 +163,20 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
if(serverPing == null) {
|
if(serverPing == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(serverPing.getPlainDescription().contains("ajQueue;whitelisted=")) {
|
||||||
|
if(servers.size() > 1) continue;
|
||||||
|
|
||||||
|
setWhitelisted(true);
|
||||||
|
List<UUID> uuids = new ArrayList<>();
|
||||||
|
for(String uuid : serverPing.getPlainDescription().substring(20).split(",")) {
|
||||||
|
if(uuid.isEmpty()) continue;
|
||||||
|
main.getLogger().info("Adding uuid "+uuid+" to whitelist");
|
||||||
|
uuids.add(UUID.fromString(uuid));
|
||||||
|
}
|
||||||
|
setWhitelistedPlayers(uuids);
|
||||||
|
} else {
|
||||||
|
setWhitelisted(false);
|
||||||
|
}
|
||||||
onlineCount++;
|
onlineCount++;
|
||||||
playerCount += serverPing.getPlayerCount();
|
playerCount += serverPing.getPlayerCount();
|
||||||
maxPlayers += serverPing.getMaxPlayers();
|
maxPlayers += serverPing.getMaxPlayers();
|
||||||
@@ -217,8 +235,10 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isJoinable(AdaptedPlayer p) {
|
public boolean isJoinable(AdaptedPlayer p) {
|
||||||
return (!whitelisted || whitelistedUUIDs.contains(p.getUniqueId())) &&
|
if(p != null && isWhitelisted() && !whitelistedUUIDs.contains(p.getUniqueId())) {
|
||||||
this.isOnline() &&
|
return false;
|
||||||
|
}
|
||||||
|
return this.isOnline() &&
|
||||||
this.canAccess(p) &&
|
this.canAccess(p) &&
|
||||||
!this.isFull() &&
|
!this.isFull() &&
|
||||||
!this.isPaused();
|
!this.isPaused();
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ dependencies {
|
|||||||
implementation("net.kyori:adventure-api:4.8.1")
|
implementation("net.kyori:adventure-api:4.8.1")
|
||||||
compileOnly("com.google.guava:guava:30.1.1-jre")
|
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("us.ajg0702:ajUtils:1.1.8")
|
||||||
|
|
||||||
compileOnly(group = "org.spigotmc", name = "spigot", version = "1.16.5-R0.1-SNAPSHOT")
|
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.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.event.server.ServerListPingEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import us.ajg0702.utils.common.ConfigFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
@@ -20,7 +25,7 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
|
|||||||
boolean papi = false;
|
boolean papi = false;
|
||||||
Placeholders placeholders;
|
Placeholders placeholders;
|
||||||
|
|
||||||
Config config;
|
ConfigFile config;
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -53,9 +58,20 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
|
|||||||
queuebatch.clear();
|
queuebatch.clear();
|
||||||
sendMessage("massqueue", msg.toString());
|
sendMessage("massqueue", msg.toString());
|
||||||
}, 2*20, 20);
|
}, 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());
|
getLogger().info("Spigot side enabled! v"+getDescription().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,4 +179,19 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
|
|||||||
if(!papi) return;
|
if(!papi) return;
|
||||||
placeholders.cleanCache();
|
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