Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.fissionstudios;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Reporter extends JavaPlugin {
- /*
- *
- * @author madcrazydrumma
- * Copyright 2012 - Madcrazydrumma & Fission Studios
- *
- */
- String user = getConfig().getString("DB.user");
- String pass = getConfig().getString("DB.pass");
- String url = getConfig().getString("DB.url"); //localhost: Your MySQL host, 3306: Your MySQL port (3306 is the main), database: Your MySQL database
- public void onEnable() {
- this.getConfig().options().copyDefaults(true);
- saveConfig();
- System.out.println(this + " was enabled successfully!");
- }
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
- if(cmd.getName().equalsIgnoreCase("r-help")) {
- if(!(sender instanceof Player)) {
- sender.sendMessage(ChatColor.BLUE + "You must be a player!");
- }
- sender.sendMessage(ChatColor.GOLD + "== Reporter Help ==");
- sender.sendMessage(ChatColor.GOLD + "== Type /r-help | for help ==");
- sender.sendMessage(ChatColor.GOLD + "== Type /r <player> <reason> | to report player to OP ==");
- sender.sendMessage(ChatColor.GOLD + "== Type /r-clear | to clear the reports (OP Only)");
- return true;
- }
- if(cmd.getName().equalsIgnoreCase("r-clear")) {
- if(sender.isOp()) {
- try {
- Connection conn = DriverManager.getConnection(url, user, pass); //Creates the connection
- PreparedStatement query = conn.prepareStatement("DELETE FROM reports"); //Deletes table data
- query.executeUpdate(); //Executes the query
- sender.sendMessage(ChatColor.GOLD + "Reports Cleared");
- query.close(); //Closes the query
- conn.close(); //Closes the connection
- } catch(SQLException e) {
- e.printStackTrace();
- }
- }
- }
- if(cmd.getName().equalsIgnoreCase("r")) {
- sender.sendMessage(ChatColor.GOLD + "You just sent a report. An Operator will view it shortly.");
- Player target = getServer().getPlayer(args[0]);
- if (target==null){
- sender.sendMessage(ChatColor.RED + "That person doesn't exist! Online players only!");
- return true;
- }
- for(Player p: getServer().getOnlinePlayers()) {
- if(p.isOp()) {
- try {
- Connection conn = DriverManager.getConnection(url, user, pass); //Creates the connection
- PreparedStatement query = conn.prepareStatement("INSERT INTO reports (id, user, reportuser, report, time) VALUES ('0', '"+sender.getName()+"', '"+target.getName()+"', '"+grabStringFromInt(1, args)+"', NOW())");
- query.executeUpdate(); //Executes the query
- query.close(); //Closes the query
- conn.close(); //Closes the connection
- } catch(SQLException e) {
- e.printStackTrace();
- }
- 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));
- return true;
- }
- return true;
- }
- return true;
- }
- return true;
- }
- public String grabStringFromInt(int start, String args[]) {
- String answer = " ";
- for(int x = start; x < args.length; x++) {
- answer = answer + args[x] + " ";
- }
- return answer;
- }
- public void onDisable() {
- saveConfig();
- System.out.println(this + " was disabled successfully!");
- }
- }
Add Comment
Please, Sign In to add comment