Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.risenphoenix.jnk.ipcheck.commands;
- import java.util.ArrayList;
- import net.risenphoenix.jnk.ipcheck.IPcheck;
- import net.risenphoenix.jnk.ipcheck.Objects.IPObject;
- import net.risenphoenix.jnk.ipcheck.Objects.UserObject;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.permissions.Permission;
- public class CmdScan extends IpcCommand {
- @Override
- public void execute(CommandSender sender, String commandLabel, String[] args) {
- // Fetch online players and create a place to hold detected players
- if (sender.hasPermission("ipcheck.scan") || sender.isOp()) {
- Player[] online = Bukkit.getOnlinePlayers();
- ArrayList<Player> detected = new ArrayList<Player>();
- // Iterate through the players
- for (int i = 0; i < online.length; i++) {
- // Get the User-Object for this player
- UserObject user = IPcheck.Instance.Database.getIPs(online[i].getName());
- ArrayList<String> unique_names = new ArrayList<String>();
- // If, for some unknown reason, no IPs were found for the user,
- // skip them and move on.
- if (user.getNumberOfIPs() == 0) {
- continue;
- }
- // Fetch IP-Objects
- ArrayList<IPObject> ipos = new ArrayList<IPObject>();
- for (String s:user.getIPs()) {
- // Get alt accounts for the IP Address
- ipos.add(IPcheck.Instance.Database.getAlts(s));
- }
- // Get unique accounts from the IP-Objects
- for (IPObject ipo:ipos) {
- if (ipo.getNumberOfUsers() == 1) {
- if (ipo.getUsers().contains(online[i].getName().toLowerCase())) {
- if (!IPcheck.Instance.Configuration.shouldShowAllIPs) continue;
- }
- }
- // Add each unique account found to arraylist
- for (String account:ipo.getUsers()) {
- if (!account.equalsIgnoreCase(online[i].getName())) {
- if (!unique_names.contains(account.toLowerCase())) {
- unique_names.add(account.toLowerCase());
- }
- }
- }
- }
- // If multiple accounts were found for the user, add them to
- // the detection queue.
- if (unique_names.size() > 0) detected.add(online[i]);
- }
- // Display output to sender
- if (detected.size() > 0) {
- Player[] convert = new Player[detected.size()];
- detected.toArray(convert);
- sender.sendMessage(ChatColor.DARK_GRAY + "------------------------------------------------");
- sender.sendMessage(ChatColor.GOLD + IPcheck.PLUG_NAME + ChatColor.RED + "Player Scan Results");
- sender.sendMessage(ChatColor.DARK_GRAY + "------------------------------------------------");
- sender.sendMessage(ChatColor.GOLD + "The following players were found to have multiple accounts:");
- // Build the list of players
- StringBuilder sb = new StringBuilder();
- // List Formatting
- for (int i = 0; i < convert.length; i++) {
- if (convert.length == 1) {
- sb.append(convert[0].getName());
- break;
- } else if (convert.length == 2) {
- sb.append(convert[0].getName());
- sb.append(" and ");
- sb.append(convert[1].getName());
- break;
- } else if (convert.length > 2) {
- sb.append(convert[i].getName());
- if (i == (convert.length - 2)) {
- sb.append(" and ");
- } else if (i == (convert.length - 1)) {
- sb.append(".");
- } else {
- sb.append(", ");
- }
- }
- }
- // Display detected users
- sender.sendMessage(ChatColor.YELLOW + sb.toString());
- sender.sendMessage(ChatColor.DARK_GRAY + "------------------------------------------------");
- } else {
- sender.sendMessage(ChatColor.GOLD + IPcheck.PLUG_NAME + ChatColor.YELLOW +
- IPcheck.Instance.Translation.getTranslation("SCAN_CLEAN"));
- }
- } else {
- sender.sendMessage(ChatColor.GOLD + IPcheck.PLUG_NAME + ChatColor.YELLOW +
- IPcheck.Instance.Translation.getTranslation("NO_PERM_ERR"));
- }
- };
- @Override
- public String getHelp(){
- return "Scans all players currently logged in to check for any who " +
- "may possess multiple accounts.";
- };
- @Override
- public String getSyntax(){
- return "scan";
- };
- @Override
- public Permission[] getPermissions(){
- Permission perms[] = {
- new Permission("ipcheck.scan")
- };
- return perms;
- };
- @Override
- public String getName(){
- return "Scan";
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement