feat: add IP/domain detection task

This commit is contained in:
ColdDev 2022-10-24 16:37:59 +01:00
parent 98ee42ad48
commit 80f7df8eb4
2 changed files with 42 additions and 0 deletions

View File

@ -1,6 +1,11 @@
package uranium.tasks;
import org.bukkit.entity.Player;
import uranium.Main;
import uranium.user.UserManager;
import uranium.util.Util;
import java.util.List;
public class IPCheck implements Runnable {
@ -11,7 +16,30 @@ public class IPCheck implements Runnable {
}
public void run() {
UserManager.getUsers().forEach((user) -> {
if (user.getIP() == null || user.getDomain() == null) {
Player player = user.getPlayer();
user.onJoin();
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
if (UserManager.getUser(player) == null) return;
if (!plugin.getConfig().getBoolean("suspicious-domains.enabled")) return;
List<String> trustedDomains = plugin.getConfig().getStringList("suspicious-domains.trusted-domains");
String prefix = plugin.getConfig().getString("prefix");
boolean offlineDownload = plugin.getConfig().getBoolean("suspicious-domains.offline-download");
boolean debugRuntime = plugin.getConfig().getBoolean("suspicious-domains.debug-runtime");
if (user.getDomain() == null) return;
if (trustedDomains.contains(user.getDomain())) return;
if (offlineDownload && user.getDomain().equalsIgnoreCase("null"))
Util.sendStaff(prefix + "&c" + user.getName() + "&7 joined using an offline download.");
else if (debugRuntime && user.getDomain().equalsIgnoreCase(""))
Util.sendStaff(prefix + "&c" + user.getName() + "&7 joined using the debug runtime.");
else
Util.sendStaff(prefix + "&c" + user.getName() + "&7 joined using a strange domain: &c" + user.getDomain());
});
}
});
}
}

View File

@ -20,4 +20,18 @@ public class Util {
Bukkit.getConsoleSender().sendMessage(StringUtil.cc(message));
}
public static void sendStaff(String message) {
UserManager.getUsers().forEach((user) -> {
if (user.hasPermission("uranium.notify")) user.sendMessage(message);
});
Bukkit.getConsoleSender().sendMessage(StringUtil.cc(message));
}
public static void sendStaff(String message, String permission) {
UserManager.getUsers().forEach((user) -> {
if (user.hasPermission(permission)) user.sendMessage(message);
});
Bukkit.getConsoleSender().sendMessage(StringUtil.cc(message));
}
}