Upload files to "src/net/ardakaz/griefalert"
removed debug changed needed to input world into options for ignore
This commit is contained in:
parent
2bfe822fb1
commit
0ee14339b7
77
src/net/ardakaz/griefalert/GriefAlert.java
Executable file → Normal file
77
src/net/ardakaz/griefalert/GriefAlert.java
Executable file → Normal file
@ -10,7 +10,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -22,8 +21,6 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
@ -35,7 +32,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
|
||||
public class GriefAlert extends JavaPlugin implements Listener {
|
||||
|
||||
private static CoreProtectAPI coreProtectAPI;
|
||||
private Integer identicalAlerts = 1;
|
||||
@ -147,16 +144,6 @@ public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
|
||||
}
|
||||
}
|
||||
|
||||
private void clearIgnoredLocations() {
|
||||
try {
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.executeUpdate("DELETE FROM ignored_locations");
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
getLogger().warning("DB error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void listIgnoredLocations(CommandSender sender) {
|
||||
try {
|
||||
Statement stmt = connection.createStatement();
|
||||
@ -259,90 +246,70 @@ public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
|
||||
if (args.length == 0) return false;
|
||||
String sub = args[0].toLowerCase();
|
||||
if (sub.equals("ignore")) {
|
||||
getLogger().info("[DEBUG] /griefalert ignore called by " + sender.getName() + " with args: " + String.join(" ", args));
|
||||
if (!sender.hasPermission("griefalert.staff.ignore")) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission.");
|
||||
getLogger().info("[DEBUG] Permission denied for ignore");
|
||||
return true;
|
||||
}
|
||||
if (args.length != 5) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /griefalert ignore <x> <y> <z> <world>");
|
||||
getLogger().info("[DEBUG] Incorrect number of arguments for ignore: " + args.length);
|
||||
if (args.length != 4) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /griefalert ignore <x> <y> <z>");
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
int x = Integer.parseInt(args[1]);
|
||||
int y = Integer.parseInt(args[2]);
|
||||
int z = Integer.parseInt(args[3]);
|
||||
String world = args[4];
|
||||
String world = ((Player)sender).getWorld().getName();
|
||||
boolean result = addIgnoredLocation(x, y, z, world);
|
||||
if (result) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Location ignored.");
|
||||
getLogger().info("[DEBUG] Location ignored: " + x + "," + y + "," + z + "," + world);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Location was already ignored.");
|
||||
getLogger().info("[DEBUG] Location already ignored: " + x + "," + y + "," + z + "," + world);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Coordinates must be numbers.");
|
||||
getLogger().info("[DEBUG] Invalid coordinates for ignore");
|
||||
}
|
||||
return true;
|
||||
} else if (sub.equals("unignore")) {
|
||||
getLogger().info("[DEBUG] /griefalert unignore called by " + sender.getName() + " with args: " + String.join(" ", args));
|
||||
if (!sender.hasPermission("griefalert.staff.UnIgnore")) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission.");
|
||||
getLogger().info("[DEBUG] Permission denied for unignore");
|
||||
return true;
|
||||
}
|
||||
if (args.length != 5) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /griefalert unignore <x> <y> <z> <world>");
|
||||
getLogger().info("[DEBUG] Incorrect number of arguments for unignore: " + args.length);
|
||||
if (args.length != 4) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /griefalert unignore <x> <y> <z>");
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
int x = Integer.parseInt(args[1]);
|
||||
int y = Integer.parseInt(args[2]);
|
||||
int z = Integer.parseInt(args[3]);
|
||||
String world = args[4];
|
||||
String world = ((Player)sender).getWorld().getName();
|
||||
boolean result = removeIgnoredLocation(x, y, z, world);
|
||||
if (result) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Location unignored.");
|
||||
getLogger().info("[DEBUG] Location unignored: " + x + "," + y + "," + z + "," + world);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Location was not ignored.");
|
||||
getLogger().info("[DEBUG] Location was not ignored: " + x + "," + y + "," + z + "," + world);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Coordinates must be numbers.");
|
||||
getLogger().info("[DEBUG] Invalid coordinates for unignore");
|
||||
}
|
||||
return true;
|
||||
} else if (sub.equals("list")) {
|
||||
getLogger().info("[DEBUG] /griefalert list called by " + sender.getName());
|
||||
if (!sender.hasPermission("griefalert.staff.list")) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission.");
|
||||
getLogger().info("[DEBUG] Permission denied for list");
|
||||
return true;
|
||||
}
|
||||
listIgnoredLocations(sender);
|
||||
sender.sendMessage(ChatColor.GRAY + "[DEBUG] Ignored locations listed in chat and console.");
|
||||
getLogger().info("[DEBUG] Ignored locations listed for " + sender.getName());
|
||||
return true;
|
||||
} else if (sub.equals("clear")) {
|
||||
getLogger().info("[DEBUG] /griefalert clear called by " + sender.getName());
|
||||
if (!sender.hasPermission("griefalert.staff.clear")) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission.");
|
||||
getLogger().info("[DEBUG] Permission denied for clear");
|
||||
return true;
|
||||
}
|
||||
clearIgnoredLocations();
|
||||
sender.sendMessage(ChatColor.GREEN + "All ignored locations cleared.");
|
||||
getLogger().info("[DEBUG] All ignored locations cleared by " + sender.getName());
|
||||
return true;
|
||||
}
|
||||
getLogger().info("[DEBUG] Unknown subcommand: " + sub);
|
||||
sender.sendMessage(ChatColor.RED + "Unknown subcommand. Use: ignore, unignore, list, clear");
|
||||
sender.sendMessage(ChatColor.RED + "Unknown subcommand. Use: ignore, unignore, list");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -351,21 +318,13 @@ public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
|
||||
if (!command.getName().equalsIgnoreCase("griefalert")) return null;
|
||||
java.util.List<String> completions = new java.util.ArrayList<>();
|
||||
if (args.length == 1) {
|
||||
java.util.List<String> subs = java.util.Arrays.asList("ignore", "unignore", "list", "clear");
|
||||
java.util.List<String> subs = java.util.Arrays.asList("ignore", "unignore", "list");
|
||||
for (String s : subs) {
|
||||
if (s.startsWith(args[0].toLowerCase())) completions.add(s);
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
if ((args[0].equalsIgnoreCase("ignore") || args[0].equalsIgnoreCase("unignore")) && args.length == 5) {
|
||||
// Suggest world names for the 5th argument
|
||||
for (World world : getServer().getWorlds()) {
|
||||
if (world.getName().toLowerCase().startsWith(args[4].toLowerCase())) {
|
||||
completions.add(world.getName());
|
||||
}
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
// No world argument needed anymore
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user