FlevasGR

Reporter

Jan 5th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. package flevasgr.rainbow.Reporter;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12.  
  13. public class Reporter extends JavaPlugin
  14. {
  15. String user;
  16. String pass;
  17. String url;
  18.  
  19. public void onEnable()
  20. {
  21.   getConfig().options().copyDefaults(true);
  22.   this.user = getConfig().getString("DB.user");
  23.   this.pass = getConfig().getString("DB.pass");
  24.   this.url = getConfig().getString("DB.url");
  25.   saveConfig();
  26.   System.out.println(this + " was enabled successfully!");
  27. }
  28.  
  29. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
  30. {
  31.   if (cmd.getName().equalsIgnoreCase("r-help"))
  32.   {
  33.     if (!(sender instanceof Player)) {
  34.       sender.sendMessage(ChatColor.BLUE + "You must be a player!");
  35.     }
  36.     sender.sendMessage(ChatColor.GOLD + "======== RFS reports ========");
  37.     sender.sendMessage(ChatColor.AQUA + "You can your the RFS Reporter to report player, check below for the commands!");
  38.     sender.sendMessage(ChatColor.AQUA + "Type /report <player> <reason> to report the player");
  39.     return true;
  40.   }
  41.   if ((cmd.getName().equalsIgnoreCase("r-clear")) &&
  42.     (sender.isOp())) {
  43.     try
  44.     {
  45.       Connection conn = DriverManager.getConnection(this.url, this.user, this.pass);
  46.       PreparedStatement query = conn.prepareStatement("DELETE FROM reports");
  47.       query.executeUpdate();
  48.       sender.sendMessage(ChatColor.GOLD + "Reports Cleared");
  49.       query.close();
  50.       conn.close();
  51.     }
  52.     catch (SQLException e)
  53.     {
  54.       e.printStackTrace();
  55.     }
  56.   }
  57.   if (cmd.getName().equalsIgnoreCase("r"))
  58.   {
  59.     sender.sendMessage(ChatColor.GOLD + "You just sent a report. An Operator will view it shortly.");
  60.     Player target = getServer().getPlayer(args[0]);
  61.     if (target == null)
  62.     {
  63.       sender.sendMessage(ChatColor.RED + "That person doesn't exist! Online players only!");
  64.       return true;
  65.     }
  66.     Player[] arrayOfPlayer;
  67.     if ((arrayOfPlayer = getServer().getOnlinePlayers()).length != 0)
  68.     {
  69.       Player p = arrayOfPlayer[0];
  70.       if (p.isOp())
  71.       {
  72.         try
  73.         {
  74.           Connection conn = DriverManager.getConnection(this.url, this.user, this.pass);
  75.           PreparedStatement query = conn.prepareStatement("INSERT INTO reports (id, user, reportuser, report, time) VALUES ('0', '" + sender.getName() + "', '" + target.getName() + "', '" + grabStringFromInt(1, args) + "', NOW())");
  76.           query.executeUpdate();
  77.           query.close();
  78.           conn.close();
  79.         }
  80.         catch (SQLException e)
  81.         {
  82.           e.printStackTrace();
  83.         }
  84.         p.sendMessage(ChatColor.DARK_GREEN + sender.getName() + ChatColor.WHITE + " has reported " + ChatColor.DARK_BLUE + target.getName() + ChatColor.WHITE + " for" + ChatColor.DARK_RED + grabStringFromInt(1, args));
  85.         return true;
  86.       }
  87.       return true;
  88.     }
  89.     return true;
  90.   }
  91.   return true;
  92. }
  93.  
  94. public String grabStringFromInt(int start, String[] args)
  95. {
  96.   String answer = " ";
  97.   for (int x = start; x < args.length; x++) {
  98.     answer = answer + args[x] + " ";
  99.   }
  100.   return answer;
  101. }
  102.  
  103. public void onDisable()
  104. {
  105.   System.out.println(this + " was disabled successfully!");
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment