Guest User

Untitled

a guest
Jul 7th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.58 KB | None | 0 0
  1. package net.fissionstudios;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7.  
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13.  
  14. public class Reporter extends JavaPlugin {
  15.    
  16.     /*
  17.      *
  18.      * @author madcrazydrumma
  19.      * Copyright 2012 - Madcrazydrumma & Fission Studios
  20.      *
  21.      */
  22.    
  23.     String user = getConfig().getString("DB.user");
  24.     String pass = getConfig().getString("DB.pass");
  25.     String url = getConfig().getString("DB.url"); //localhost: Your MySQL host, 3306: Your MySQL port (3306 is the main), database: Your MySQL database
  26.    
  27.     public void onEnable() {
  28.         this.getConfig().options().copyDefaults(true);
  29.         saveConfig();
  30.         System.out.println(this + " was enabled successfully!");
  31.     }
  32.    
  33.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  34.         if(cmd.getName().equalsIgnoreCase("r-help")) {
  35.             if(!(sender instanceof Player)) {
  36.                 sender.sendMessage(ChatColor.BLUE + "You must be a player!");
  37.             }
  38.             sender.sendMessage(ChatColor.GOLD + "== Reporter Help ==");
  39.             sender.sendMessage(ChatColor.GOLD + "== Type /r-help | for help ==");
  40.             sender.sendMessage(ChatColor.GOLD + "== Type /r <player> <reason> | to report player to OP ==");
  41.             sender.sendMessage(ChatColor.GOLD + "== Type /r-clear | to clear the reports (OP Only)");
  42.             return true;
  43.         }
  44.         if(cmd.getName().equalsIgnoreCase("r-clear")) {
  45.             if(sender.isOp()) {
  46.             try {
  47.                 Connection conn = DriverManager.getConnection(url, user, pass); //Creates the connection
  48.                 PreparedStatement query = conn.prepareStatement("DELETE FROM reports"); //Deletes table data
  49.                 query.executeUpdate(); //Executes the query
  50.                 sender.sendMessage(ChatColor.GOLD + "Reports Cleared");
  51.                 query.close(); //Closes the query
  52.                 conn.close(); //Closes the connection
  53.             } catch(SQLException e) {
  54.                 e.printStackTrace();
  55.             }
  56.             }
  57.         }
  58.         if(cmd.getName().equalsIgnoreCase("r")) {
  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.                 sender.sendMessage(ChatColor.RED + "That person doesn't exist! Online players only!");
  63.                 return true;
  64.             }
  65.             for(Player p: getServer().getOnlinePlayers()) {
  66.                 if(p.isOp()) {
  67.                     try {
  68.                         Connection conn = DriverManager.getConnection(url, user, pass); //Creates the connection
  69.                         PreparedStatement query = conn.prepareStatement("INSERT INTO reports (id, user, reportuser, report, time) VALUES ('0', '"+sender.getName()+"', '"+target.getName()+"', '"+grabStringFromInt(1, args)+"', NOW())");
  70.                         query.executeUpdate(); //Executes the query
  71.                         query.close(); //Closes the query
  72.                         conn.close(); //Closes the connection
  73.                     } catch(SQLException e) {
  74.                         e.printStackTrace();
  75.                     }
  76.                     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));
  77.                     return true;
  78.                 }
  79.                 return true;
  80.             }
  81.             return true;
  82.         }
  83.         return true;
  84.     }
  85.    
  86.     public String grabStringFromInt(int start, String args[]) {
  87.         String answer = " ";
  88.         for(int x = start; x < args.length; x++) {
  89.             answer = answer + args[x] + " ";
  90.         }
  91.         return answer;
  92.     }
  93.    
  94.     public void onDisable() {
  95.         saveConfig();
  96.         System.out.println(this + " was disabled successfully!");
  97.     }
  98. }
Add Comment
Please, Sign In to add comment