Advertisement
Jnk1296

new report function

May 25th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.47 KB | None | 0 0
  1. package net.risenphoenix.jnk.ipcheck;
  2.  
  3. import java.util.ArrayList;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.OfflinePlayer;
  7. import org.bukkit.command.CommandSender;
  8.  
  9. public class Report {
  10.    
  11.     private static final String PLUG_NAME = "[IP-Check] ";
  12.     private static final String NO_FIND = "The player or IP specified could not be found. Additionally, there were no similar results.";
  13.  
  14.     public void execute(CommandSender sender, String arg) {
  15.         ArrayList<String> IPs; // For use with player check
  16.         ArrayList<StringBuilder> SBs = new ArrayList<StringBuilder>(); // For use with player check
  17.  
  18.         ArrayList<String> singleAlts = new ArrayList<String>(); // For use with IP check
  19.        
  20.         OfflinePlayer player = null;
  21.  
  22.         boolean forPlayer = true;
  23.  
  24.         String ip_filter = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}";
  25.         //Command Instructions here
  26.         if (arg.toLowerCase().matches(ip_filter.toLowerCase())) {
  27.             forPlayer = false;
  28.         }
  29.  
  30.         if (forPlayer) {
  31.             player = Bukkit.getOfflinePlayer(arg);
  32.         }
  33.        
  34.         // Get all alt accounts linked to the player
  35.         if (forPlayer) {
  36.             IPs = IPcheck.backend.getIPs(arg); // Load list of IPs from backend
  37.  
  38.             for (String s:IPs) {
  39.                 ArrayList<String> altAccounts;
  40.  
  41.                 // Get alt accounts for the IP Address
  42.                 if (s.contains("-lastknown")) {
  43.                     altAccounts = IPcheck.backend.getAlts(s.replace("-lastknown", ""));
  44.                 } else {
  45.                     altAccounts = IPcheck.backend.getAlts(s);
  46.                 }
  47.  
  48.                 // Create New String Builder
  49.                 StringBuilder sb = new StringBuilder();
  50.  
  51.                 // Append the leading IP-Address, plus a splitter character '|'
  52.                 sb.append(s + "|");
  53.  
  54.                 // Append each account, plus punctuation to the string builder
  55.                 for (String account:altAccounts) {
  56.                     sb.append(account + ", ");
  57.                 }
  58.  
  59.                 // Add the string builder to the holder arraylist
  60.                 SBs.add(sb);
  61.             }
  62.         } else {
  63.             singleAlts = IPcheck.backend.getAlts(arg);
  64.         }
  65.  
  66.         //### OUTPUT MESSAGE ###//
  67.         //### HEADER ###//
  68.         sender.sendMessage(ChatColor.DARK_GRAY + "---------------------------------------------");
  69.         if (!forPlayer) {
  70.             if (sender.hasPermission("ipcheck.showip") || sender.isOp()) {
  71.                 sender.sendMessage(ChatColor.GOLD + "Total Accounts found for: " + arg + " ... " + singleAlts.size());
  72.             } else {
  73.                 sender.sendMessage(ChatColor.GOLD + "Total Accounts found: " + singleAlts.size());
  74.             }
  75.         } else if (forPlayer) {
  76.             int accounts = 0;
  77.             for (StringBuilder sb:SBs) {
  78.                 String string = sb.toString();
  79.  
  80.                 for (int i = 0; i < string.length(); i++) {
  81.                     if (string.charAt(i) == ',') {
  82.                         accounts++;
  83.                     }
  84.                 }
  85.             }
  86.  
  87.             sender.sendMessage(ChatColor.GOLD + "Total Accounts found for: " + arg + " ... " + accounts);
  88.         }
  89.         sender.sendMessage(ChatColor.DARK_GRAY + "---------------------------------------------");
  90.         //### END HEADER ###//
  91.  
  92.         //### BODY ###//
  93.         if (!forPlayer) {
  94.             StringBuilder sb = new StringBuilder();
  95.  
  96.             for (String string:singleAlts) {
  97.                 sb.append(string + ", ");
  98.             }
  99.  
  100.             if (sender.hasPermission("ipcheck.showip") || sender.isOp()) {
  101.                     sender.sendMessage(ChatColor.LIGHT_PURPLE + "The following players connect with the above IP address: " + ChatColor.YELLOW + sb);
  102.             } else {
  103.                     sender.sendMessage(ChatColor.LIGHT_PURPLE + "The following players connect using the same IP address: " + ChatColor.YELLOW + sb);
  104.             }
  105.             sender.sendMessage("");
  106.         } else if (forPlayer) {
  107.             sender.sendMessage(ChatColor.LIGHT_PURPLE + "The following players and IPs are associated with the search term: ");
  108.  
  109.             if (sender.hasPermission("ipcheck.showip") || sender.isOp()) {
  110.                 for (StringBuilder sb:SBs) {
  111.                     String full = sb.toString();
  112.                     StringBuilder ipAddress = new StringBuilder();
  113.  
  114.                     for (int i = 0; i < full.length(); i ++) {
  115.                         if (full.charAt(i) != '|') {
  116.                             ipAddress.append(full.charAt(i));
  117.                         } else {
  118.                             break;
  119.                         }
  120.                     }
  121.  
  122.                     full = full.replace(ipAddress.toString() + "|", "");
  123.  
  124.                     sender.sendMessage(ChatColor.RED + ipAddress.toString() + ":");
  125.                     sender.sendMessage(ChatColor.YELLOW + full);
  126.  
  127.                     sender.sendMessage("");
  128.                 }    
  129.             } else {
  130.                 for (StringBuilder sb:SBs) {
  131.                     String full = sb.toString();
  132.                     StringBuilder ipAddress = new StringBuilder();
  133.  
  134.                     for (int i = 0; i < full.length(); i ++) {
  135.                         if (full.charAt(i) != '|') {
  136.                             ipAddress.append(full.charAt(i));
  137.                         } else {
  138.                             break;
  139.                         }
  140.                     }
  141.  
  142.                     full = full.replace(ipAddress.toString() + "|", "");
  143.  
  144.                     sender.sendMessage(ChatColor.RED + "####:");
  145.                     sender.sendMessage(ChatColor.YELLOW + full);
  146.  
  147.                     sender.sendMessage("");
  148.                 }    
  149.             }
  150.            
  151.             sender.sendMessage(ChatColor.DARK_GRAY + "---------------------------------------------");
  152.            
  153.             //### END BODY ###//
  154.            
  155.             //### FOOTER ###//
  156.            
  157.             if (forPlayer) {
  158.                 if (player != null) {
  159.                         sender.sendMessage(ChatColor.LIGHT_PURPLE + "More Information about: " + ChatColor.YELLOW + player.getName());
  160.                         if (player.isBanned()) {
  161.                                 sender.sendMessage(ChatColor.LIGHT_PURPLE + "Player Banned: " + ChatColor.RED + "True");
  162.                         } else {
  163.                                 sender.sendMessage(ChatColor.LIGHT_PURPLE + "Player Banned: " + ChatColor.GREEN + "False");
  164.                         }
  165.                 } else {
  166.                         sender.sendMessage(ChatColor.RED + "ERROR: " + ChatColor.GOLD + "Player object returned was NULL");
  167.                 }
  168.  
  169.                 if (Configuration.isExemptPlayer(player.getName())) {
  170.                         sender.sendMessage(ChatColor.LIGHT_PURPLE + "Player Exempt: " + ChatColor.GREEN + "True");
  171.                 } else {
  172.                         sender.sendMessage(ChatColor.LIGHT_PURPLE + "Player Exempt: " + ChatColor.RED + "False");
  173.                 }
  174.             }
  175.        
  176.             if (!forPlayer) {
  177.                 if (IPcheck.backend.isBannedIP(arg)) {
  178.                         sender.sendMessage(ChatColor.LIGHT_PURPLE + "IP Banned: " + ChatColor.RED + "True");
  179.                 } else {
  180.                         sender.sendMessage(ChatColor.LIGHT_PURPLE + "IP Banned: " + ChatColor.GREEN + "False");
  181.                 }
  182.  
  183.                 if (Configuration.isExemptIp(arg)) {
  184.                         sender.sendMessage(ChatColor.LIGHT_PURPLE + "IP Exempt: " + ChatColor.GREEN + "True");
  185.                 } else {
  186.                         sender.sendMessage(ChatColor.LIGHT_PURPLE + "IP Exempt: " + ChatColor.RED + "False");
  187.                 }
  188.             }
  189.  
  190.             if (forPlayer) {
  191.                 if (sender.hasPermission("ipcheck.showbanreason")) {
  192.                     if (player != null) {
  193.                         if (player.isBanned()) {
  194.                             sender.sendMessage("");
  195.                             sender.sendMessage(ChatColor.LIGHT_PURPLE + "Banned Reason: " + ChatColor.YELLOW + Configuration.getBannedReason(player.getName()));
  196.                         }
  197.                     }
  198.                 }
  199.             }
  200.             ///### END FOOTER ###//
  201.            
  202.             sender.sendMessage(ChatColor.DARK_GRAY + "---------------------------------------------");
  203.            
  204.             //### END OUTPUT MESSAGE ###//
  205.     }
  206.     }  
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement