Upload files to "src/net/ardakaz/griefalert"

This commit is contained in:
Kleedje30 2025-06-02 10:36:23 +00:00
parent 42c934f5ae
commit 3994257aed

View File

@ -10,6 +10,7 @@ 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;
@ -32,7 +33,7 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class GriefAlert extends JavaPlugin implements Listener {
public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
private static CoreProtectAPI coreProtectAPI;
private Integer identicalAlerts = 1;
@ -143,21 +144,6 @@ public class GriefAlert extends JavaPlugin implements Listener {
return false;
}
}
private void listIgnoredLocations(CommandSender sender) {
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT x, y, z, world FROM ignored_locations");
sender.sendMessage(ChatColor.YELLOW + "Ignored Locations:");
while (rs.next()) {
sender.sendMessage(ChatColor.GRAY + "- " + rs.getInt("x") + ", " + rs.getInt("y") + ", " + rs.getInt("z") + " in " + rs.getString("world"));
}
rs.close();
stmt.close();
} catch (SQLException e) {
sender.sendMessage(ChatColor.RED + "DB error: " + e.getMessage());
}
}
@EventHandler (ignoreCancelled = true)
// Block break alerts
@ -250,27 +236,43 @@ public class GriefAlert extends JavaPlugin implements Listener {
sender.sendMessage(ChatColor.RED + "You do not have permission.");
return true;
}
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 = ((Player)sender).getWorld().getName();
boolean result = addIgnoredLocation(x, y, z, world);
if (result) {
sender.sendMessage(ChatColor.GREEN + "Location ignored.");
} else {
sender.sendMessage(ChatColor.YELLOW + "Location was already ignored.");
String world;
int x, y, z;
if (args.length == 4) {
// /griefalert ignore x y z (use sender's world)
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
return true;
}
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Coordinates must be numbers.");
world = ((Player)sender).getWorld().getName();
try {
x = Integer.parseInt(args[1]);
y = Integer.parseInt(args[2]);
z = Integer.parseInt(args[3]);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Coordinates must be numbers.");
return true;
}
} else if (args.length == 5) {
// /griefalert ignore world x y z
world = args[1];
try {
x = Integer.parseInt(args[2]);
y = Integer.parseInt(args[3]);
z = Integer.parseInt(args[4]);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Coordinates must be numbers.");
return true;
}
} else {
sender.sendMessage(ChatColor.RED + "Usage: /griefalert ignore <world> <x> <y> <z> or /griefalert ignore <x> <y> <z>");
return true;
}
boolean result = addIgnoredLocation(x, y, z, world);
if (result) {
sender.sendMessage(ChatColor.GREEN + "Location ignored.");
} else {
sender.sendMessage(ChatColor.YELLOW + "Location was already ignored.");
}
return true;
} else if (sub.equals("unignore")) {
@ -278,38 +280,88 @@ public class GriefAlert extends JavaPlugin implements Listener {
sender.sendMessage(ChatColor.RED + "You do not have permission.");
return true;
}
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 = ((Player)sender).getWorld().getName();
boolean result = removeIgnoredLocation(x, y, z, world);
if (result) {
sender.sendMessage(ChatColor.GREEN + "Location unignored.");
} else {
sender.sendMessage(ChatColor.YELLOW + "Location was not ignored.");
String world;
int x, y, z;
if (args.length == 4) {
// /griefalert unignore x y z (use sender's world)
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
return true;
}
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Coordinates must be numbers.");
world = ((Player)sender).getWorld().getName();
try {
x = Integer.parseInt(args[1]);
y = Integer.parseInt(args[2]);
z = Integer.parseInt(args[3]);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Coordinates must be valid.");
return true;
}
} else if (args.length == 5) {
// /griefalert unignore world x y z
world = args[1];
try {
x = Integer.parseInt(args[2]);
y = Integer.parseInt(args[3]);
z = Integer.parseInt(args[4]);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Coordinates must be numbers.");
return true;
}
} else {
sender.sendMessage(ChatColor.RED + "Usage: /griefalert unignore <world> <x> <y> <z> or /griefalert unignore <x> <y> <z>");
return true;
}
boolean result = removeIgnoredLocation(x, y, z, world);
if (result) {
sender.sendMessage(ChatColor.GREEN + "Location unignored.");
} else {
sender.sendMessage(ChatColor.YELLOW + "Location was not ignored.");
}
return true;
} else if (sub.equals("list")) {
if (!sender.hasPermission("griefalert.staff.list")) {
sender.sendMessage(ChatColor.RED + "You do not have permission.");
} else if (sub.equals("check")) {
// /griefalert check <world> <x> <y> <z> or /griefalert check <x> <y> <z>
String world;
int x, y, z;
if (args.length == 4) {
// /griefalert check x y z (use sender's world)
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
return true;
}
world = ((Player)sender).getWorld().getName();
try {
x = Integer.parseInt(args[1]);
y = Integer.parseInt(args[2]);
z = Integer.parseInt(args[3]);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Coordinates must be numbers.");
return true;
}
} else if (args.length == 5) {
// /griefalert check world x y z
world = args[1];
try {
x = Integer.parseInt(args[2]);
y = Integer.parseInt(args[3]);
z = Integer.parseInt(args[4]);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Coordinates must be numbers.");
return true;
}
} else {
sender.sendMessage(ChatColor.RED + "Usage: /griefalert check <world>(optional) <x> <y> <z> ");
return true;
}
listIgnoredLocations(sender);
boolean ignored = isLocationIgnored(x, y, z, world);
if (ignored) {
sender.sendMessage(ChatColor.YELLOW + "GriefAlert is DISABLED at " + x + ", " + y + ", " + z + " in " + world + ".");
} else {
sender.sendMessage(ChatColor.GREEN + "GriefAlert is ENABLED at " + x + ", " + y + ", " + z + " in " + world + ".");
}
return true;
}
sender.sendMessage(ChatColor.RED + "Unknown subcommand. Use: ignore, unignore, list");
sender.sendMessage(ChatColor.RED + "Unknown subcommand. Use: ignore, unignore, check");
return false;
}
@ -318,13 +370,20 @@ public class GriefAlert extends JavaPlugin implements Listener {
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");
java.util.List<String> subs = java.util.Arrays.asList("ignore", "unignore", "check");
for (String s : subs) {
if (s.startsWith(args[0].toLowerCase())) completions.add(s);
}
return completions;
}
// No world argument needed anymore
if (args.length == 2 && (args[0].equalsIgnoreCase("ignore") || args[0].equalsIgnoreCase("unignore") || args[0].equalsIgnoreCase("check"))) {
// Suggest world names for the 2nd argument
for (org.bukkit.World world : org.bukkit.Bukkit.getWorlds()) {
completions.add(world.getName());
}
return completions;
}
// Optionally, you could add number tab completion for coordinates, but it's not necessary
return null;
}