Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package flevasgr.rainbow.Reporter;
- 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
- {
- String user;
- String pass;
- String url;
- public void onEnable()
- {
- getConfig().options().copyDefaults(true);
- this.user = getConfig().getString("DB.user");
- this.pass = getConfig().getString("DB.pass");
- this.url = getConfig().getString("DB.url");
- 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 + "======== RFS reports ========");
- sender.sendMessage(ChatColor.AQUA + "You can your the RFS Reporter to report player, check below for the commands!");
- sender.sendMessage(ChatColor.AQUA + "Type /report <player> <reason> to report the player");
- return true;
- }
- if ((cmd.getName().equalsIgnoreCase("r-clear")) &&
- (sender.isOp())) {
- try
- {
- Connection conn = DriverManager.getConnection(this.url, this.user, this.pass);
- PreparedStatement query = conn.prepareStatement("DELETE FROM reports");
- query.executeUpdate();
- sender.sendMessage(ChatColor.GOLD + "Reports Cleared");
- query.close();
- conn.close();
- }
- 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;
- }
- Player[] arrayOfPlayer;
- if ((arrayOfPlayer = getServer().getOnlinePlayers()).length != 0)
- {
- Player p = arrayOfPlayer[0];
- if (p.isOp())
- {
- try
- {
- Connection conn = DriverManager.getConnection(this.url, this.user, this.pass);
- PreparedStatement query = conn.prepareStatement("INSERT INTO reports (id, user, reportuser, report, time) VALUES ('0', '" + sender.getName() + "', '" + target.getName() + "', '" + grabStringFromInt(1, args) + "', NOW())");
- query.executeUpdate();
- query.close();
- conn.close();
- }
- 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()
- {
- System.out.println(this + " was disabled successfully!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment