Compare commits

...

32 Commits
0.2.1 ... main

Author SHA1 Message Date
8ed5841160 Removed the null from "Same behavior continues." 2025-06-27 09:35:17 +00:00
f1877e38a4 Some little styling 2025-06-27 09:11:58 +00:00
2837e8f471 Reverted the buggy 1.21.5 behavior 2025-06-27 09:07:48 +00:00
e3da66b37e Updating the version number 2025-06-27 07:04:10 +00:00
b034787328 Upload files to "src/net/ardakaz/griefalert" 2025-06-23 11:37:00 +00:00
349a3d2c5f Delete src/net/ardakaz/griefalert/GriefAlert.jar 2025-06-23 11:33:58 +00:00
5b069aca76 Upload files to "src/net/ardakaz/griefalert" 2025-06-23 11:32:47 +00:00
4d9ba74c42 Upload files to "src/net/ardakaz/griefalert"
should fix armor stands and item frames
2025-06-20 19:53:39 +00:00
ed05bf48ef Reimplemented the Discord integration to work with 1.21.5. 2025-06-12 07:23:47 +00:00
9a124598ee Oops 2025-06-12 07:23:27 +00:00
f71e6e2fa1 Oops 2025-06-12 07:23:19 +00:00
2d04fe1b77 Reimplemented the Discord integration to work with 1.21.5. 2025-06-12 07:22:48 +00:00
3994257aed Upload files to "src/net/ardakaz/griefalert" 2025-06-02 10:36:23 +00:00
42c934f5ae Upload files to "/" 2025-06-02 10:35:46 +00:00
0ee14339b7 Upload files to "src/net/ardakaz/griefalert"
removed debug
changed needed to input world into options for ignore
2025-05-28 20:31:34 +00:00
2bfe822fb1 revert 9549c1854635ec5fcfbbba1801c80cc80cc64a9e
revert Upload files to "/"

removed debug
changed needed to input world
2025-05-28 20:30:39 +00:00
9549c18546 Upload files to "/"
removed debug
changed needed to input world
2025-05-28 20:29:16 +00:00
3e0818bef9 No need 2025-05-28 18:41:03 +00:00
7725974444 Update plugin.yml 2025-05-28 18:24:56 +00:00
38df0f7e82 Moving to the right place 2025-05-28 18:22:33 +00:00
4b4820bf17 Moving to the right place 2025-05-28 18:21:56 +00:00
c9ad3dd3a4 Moving to the right place 2025-05-28 18:21:35 +00:00
618d737203 Upload files to "/" 2025-05-28 18:18:52 +00:00
a288d261c1 Quick fix 2025-05-24 04:12:44 +00:00
b2284bbcef Updated version & website 2025-05-24 04:07:11 +00:00
41ef9d6d0d Update src/net/ardakaz/griefalert/AlertsLogic.java 2025-05-23 21:44:34 +00:00
14a655478f Add src/net/ardakaz/griefalert/AlertsLogic.java 2025-05-23 21:39:42 +00:00
594523fb38 Update src/net/ardakaz/griefalert/GriefAlert.java 2025-05-23 21:38:41 +00:00
3bc045e799 Update plugin.yml 2025-05-23 21:36:04 +00:00
af1fb5fd62 Update plugin.yml 2025-05-23 21:07:47 +00:00
fe413d59ea Update plugin.yml
"authors" instead "author"
2025-05-23 21:01:01 +00:00
07d60ee5b6 Update plugin.yml 2025-05-23 20:59:45 +00:00
4 changed files with 718 additions and 289 deletions

0
config.yml Executable file → Normal file
View File

13
plugin.yml Executable file → Normal file
View File

@ -1,7 +1,14 @@
name: GriefAlert
main: net.ardakaz.griefalert.GriefAlert
version: 0.2.1
version: 0.4
api-version: 1.21
depends: [CoreProtect]
description: A simple grief alert plugin using CoreProtect API.
author: Ardakaz
softdepend: [DiscordSRV]
description: A simple grief alert plugin using the CoreProtect API.
authors: [Ardakaz, kleedje30]
commands:
griefalert:
description: GriefAlert staff commands
usage: /griefalert <ignore|unignore|check>
permission: griefalert.staff
permission-message: You do not have permission to use this command.

579
src/net/ardakaz/griefalert/GriefAlert.java Executable file → Normal file
View File

@ -6,26 +6,44 @@ import net.coreprotect.CoreProtectAPI.ParseResult;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
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;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.entity.ArmorStand;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.entity.ItemFrame;
public class GriefAlert extends JavaPlugin implements Listener {
public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
private static CoreProtectAPI coreProtectAPI;
private Integer identicalAlerts = 1;
@ -36,6 +54,9 @@ public class GriefAlert extends JavaPlugin implements Listener {
private String MAP_LINK;
private Boolean ALLOW_STEALING;
private Connection connection;
private final String DB_FILE = "ignored_locations.db";
// Init GriefAlert
@Override
public void onEnable() {
@ -58,12 +79,80 @@ public class GriefAlert extends JavaPlugin implements Listener {
MAP_LINK = getConfig().getString("map-link");
ALLOW_STEALING = getConfig().getBoolean("allow-stealing");
setupDatabase();
getCommand("griefalert").setTabCompleter(this);
getLogger().info("GriefAlert has been enabled.");
}
@Override
public void onDisable() {
getLogger().info("GriefAlert has been disabled.");
if (connection != null) {
try { connection.close(); } catch (SQLException ignored) {}
}
}
private void setupDatabase() {
try {
connection = DriverManager.getConnection("jdbc:sqlite:" + getDataFolder().getAbsolutePath() + "/" + DB_FILE);
Statement stmt = connection.createStatement();
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ignored_locations (x INTEGER, y INTEGER, z INTEGER, world TEXT, PRIMARY KEY (x, y, z, world))");
stmt.close();
} catch (SQLException e) {
getLogger().severe("Could not set up SQLite database: " + e.getMessage());
}
}
private boolean isLocationIgnored(int x, int y, int z, String world) {
try {
PreparedStatement ps = connection.prepareStatement("SELECT 1 FROM ignored_locations WHERE x=? AND y=? AND z=? AND world=?");
ps.setInt(1, x);
ps.setInt(2, y);
ps.setInt(3, z);
ps.setString(4, world);
ResultSet rs = ps.executeQuery();
boolean exists = rs.next();
rs.close();
ps.close();
return exists;
} catch (SQLException e) {
getLogger().warning("DB error: " + e.getMessage());
return false;
}
}
private boolean addIgnoredLocation(int x, int y, int z, String world) {
try {
PreparedStatement ps = connection.prepareStatement("INSERT OR IGNORE INTO ignored_locations (x, y, z, world) VALUES (?, ?, ?, ?)");
ps.setInt(1, x);
ps.setInt(2, y);
ps.setInt(3, z);
ps.setString(4, world);
int updated = ps.executeUpdate();
ps.close();
return updated > 0;
} catch (SQLException e) {
getLogger().warning("DB error: " + e.getMessage());
return false;
}
}
private boolean removeIgnoredLocation(int x, int y, int z, String world) {
try {
PreparedStatement ps = connection.prepareStatement("DELETE FROM ignored_locations WHERE x=? AND y=? AND z=? AND world=?");
ps.setInt(1, x);
ps.setInt(2, y);
ps.setInt(3, z);
ps.setString(4, world);
int updated = ps.executeUpdate();
ps.close();
return updated > 0;
} catch (SQLException e) {
getLogger().warning("DB error: " + e.getMessage());
return false;
}
}
@EventHandler (ignoreCancelled = true)
@ -85,9 +174,8 @@ public class GriefAlert extends JavaPlugin implements Listener {
// Check if grief
String target = inspectBlock(event.getBlock(), event.getPlayer());
if (target != null) {
// Alert
String message = ChatColor.GRAY + playerName + " broke " + blockType + " placed by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
}
}
@ -138,97 +226,430 @@ public class GriefAlert extends JavaPlugin implements Listener {
int y = inventory.getLocation().getBlockY();
int z = inventory.getLocation().getBlockZ();
String worldName = inventory.getLocation().getWorld().getName();
if (stealing) {
// Stealing
String message = ChatColor.GRAY + playerName + " took " + amount + " " + itemName + " from " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
String message = ChatColor.GRAY + playerName + " took " + amount + " " + itemName + " from " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
} else {
// Putting back
String message = ChatColor.GRAY + playerName + " put " + amount + " " + itemName + " into " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
String message = ChatColor.GRAY + playerName + " put " + amount + " " + itemName + " into " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
}
}
}
// Armor Stand break alerts
@EventHandler(ignoreCancelled = true)
public void onArmorStandBreak(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof ArmorStand)) return;
if (!(event.getDamager() instanceof Player)) return;
Player player = (Player) event.getDamager();
ArmorStand armorStand = (ArmorStand) event.getEntity();
int x = armorStand.getLocation().getBlockX();
int y = armorStand.getLocation().getBlockY();
int z = armorStand.getLocation().getBlockZ();
String worldName = armorStand.getWorld().getName();
if (isLocationIgnored(x, y, z, worldName)) {
event.setCancelled(true);
return;
}
String playerName = player.getName();
String target = inspectBlock(armorStand.getLocation().getBlock(), player);
if (target != null) {
String message = ChatColor.GRAY + playerName + " broke an armor stand placed by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
}
}
// Armor Stand item interaction alerts
@EventHandler(ignoreCancelled = true)
public void onArmorStandInteract(PlayerInteractAtEntityEvent event) {
if (!(event.getRightClicked() instanceof ArmorStand)) return;
Player player = event.getPlayer();
ArmorStand armorStand = (ArmorStand) event.getRightClicked();
int x = armorStand.getLocation().getBlockX();
int y = armorStand.getLocation().getBlockY();
int z = armorStand.getLocation().getBlockZ();
String worldName = armorStand.getWorld().getName();
if (isLocationIgnored(x, y, z, worldName)) {
event.setCancelled(true);
return;
}
String target = inspectBlock(armorStand.getLocation().getBlock(), player);
if (target != null) {
String playerName = player.getName();
ItemStack handItem = player.getInventory().getItemInMainHand();
// Determine which slot is being interacted with
//org.bukkit.inventory.EquipmentSlot slot = event.getHand();
EntityEquipment equipment = armorStand.getEquipment();
ItemStack armorItem = null;
if (event.getClickedPosition() != null) {
// Approximate slot by Y position (not perfect, but Bukkit API is limited so it is what it is :3)
double yPos = event.getClickedPosition().getY();
if (yPos > 1.6) armorItem = equipment.getHelmet();
else if (yPos > 1.2) armorItem = equipment.getChestplate();
else if (yPos > 0.8) armorItem = equipment.getLeggings();
else if (yPos > 0.1) armorItem = equipment.getBoots();
else armorItem = equipment.getItemInMainHand();
} else {
armorItem = equipment.getItemInMainHand();
}
boolean handEmpty = handItem == null || handItem.getType() == Material.AIR;
boolean armorEmpty = armorItem == null || armorItem.getType() == Material.AIR;
String action;
//this works at the instance of interaction before items get moved around
if (handEmpty && !armorEmpty) {
action = "took " + armorItem.getType().toString();
} else if (!handEmpty && armorEmpty) {
action = "added " + handItem.getType().toString();
} else if (!handEmpty && !armorEmpty) {
action = "swapped " + armorItem.getType().toString() + " with " + handItem.getType().toString();
} else {
action = "interacted with";
}
String message = ChatColor.GRAY + playerName + " " + action + " on an armor stand owned by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
}
}
//event handler for item frames
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event){
if(!(event.getRightClicked() instanceof ItemFrame)) return;
Player player = event.getPlayer();
ItemFrame frame = (ItemFrame) event.getRightClicked();
int x = frame.getLocation().getBlockX();
int y = frame.getLocation().getBlockY();
int z = frame.getLocation().getBlockZ();
String worldName = frame.getWorld().getName();
if (isLocationIgnored(x, y, z, worldName)) {
event.setCancelled(true);
return;
}
String target = inspectBlock(frame.getLocation().getBlock(), player);
if(target !=null){
ItemStack itemInFrame = frame.getItem();
ItemStack handItem = player.getInventory().getItemInMainHand();
boolean handEmpty = handItem ==null || handItem.getType() == Material.AIR;
boolean frameEmpty = itemInFrame ==null || itemInFrame.getType() == Material.AIR;
String playerName = player.getName();
String action;
if (!handEmpty && frameEmpty) {
action = "added " + handItem.getType();
}
else {
return;
}
String message = ChatColor.GRAY + playerName + " " + action + " an item to an item frame owned by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
}
}
//breaking item frame item (uses a different event then placing an item)
@EventHandler (ignoreCancelled = true)
public void onItemFrameDamage(EntityDamageByEntityEvent event){
if (!(event.getEntity() instanceof ItemFrame)) return;
if (!(event.getDamager() instanceof Player)) return;
ItemFrame frame = (ItemFrame) event.getEntity();
Player player = (Player) event.getDamager();
ItemStack item = frame.getItem();
String playerName = player.getName();
int x = frame.getLocation().getBlockX();
int y = frame.getLocation().getBlockY();
int z = frame.getLocation().getBlockZ();
String worldName = frame.getWorld().getName();
if (isLocationIgnored(x, y, z, worldName)) {
event.setCancelled(true);
return;
}
String target = inspectBlock(frame.getLocation().getBlock(), player);
if (target == null || target.equals(player.getName())) return;
if (item == null || item.getType() == Material.AIR) return;
// At this point, the player is removing the item
String action = "took " + item.getType();
String message = ChatColor.GRAY + playerName + " " + action + " from item frame owned by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
}
@EventHandler(ignoreCancelled = true)
public void onItemFrameBreak(HangingBreakByEntityEvent event){
if (!(event.getEntity() instanceof ItemFrame)) return;
if (!(event.getRemover() instanceof Player)) return;
ItemFrame frame = (ItemFrame) event.getEntity();
Player player = (Player) event.getRemover();
String playerName = player.getName();
Location loc = frame.getLocation();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
String worldName = loc.getWorld().getName();
if (isLocationIgnored(x, y, z, worldName)) {
event.setCancelled(true);
return;
}
String target = inspectBlock(loc.getBlock(), player);
if (target ==null || target.equals(player.getName())) return;
String action = "broke an item frame";
String message = ChatColor.GRAY + playerName + " " + action + " owned by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!command.getName().equalsIgnoreCase("griefalert")) return false;
if (args.length == 0) return false;
String sub = args[0].toLowerCase();
if (sub.equals("ignore")) {
if (!sender.hasPermission("griefalert.staff.ignore")) {
sender.sendMessage(ChatColor.RED + "You do not have permission.");
return true;
}
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;
}
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")) {
if (!sender.hasPermission("griefalert.staff.UnIgnore")) {
sender.sendMessage(ChatColor.RED + "You do not have permission.");
return true;
}
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;
}
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("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;
}
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, check");
return false;
}
@Override
public java.util.List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
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", "check");
for (String s : subs) {
if (s.startsWith(args[0].toLowerCase())) completions.add(s);
}
return completions;
}
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;
}
// Sends the alert (or cancels it)
private void alert(String message, String playerName, String mapLink, String target) {
// Exclude trusted people
Player griefer = Bukkit.getPlayer(playerName);
if (griefer.hasPermission("griefalert.exclude") || griefer.hasPermission("griefalert.exclude." + target)) {
return;
}
// Spam limiter
String realAlertMessage = message;
String[] alert1 = null;
if (lastAlert != null) {
alert1 = lastAlert.split(" ");
}
String[] alert2 = message.split(" ");
if (alert1 != null) {
if (alert1[2].equals(alert2[2]) && alert1[5].equals(alert2[5]) && alert1[1].equals("broke") && alert2[1].equals("broke")) {
identicalAlerts += 1;
}
else if (Arrays.equals(alert1, alert2)) {
identicalAlerts += 1;
}
else {
identicalAlerts = 1;
}
}
if (identicalAlerts == 4) {
message = ChatColor.GRAY + "Same behavior continues.";
mapLink = null;
}
if (identicalAlerts > 4) {
return;
}
// Send an event for external hooks
GriefAlertEvent griefalert_event;
if (mapLink != null && !mapLink.isEmpty()) {
griefalert_event = new GriefAlertEvent(message + " (" + mapLink + ")");
}
else {
griefalert_event = new GriefAlertEvent(message);
}
getServer().getPluginManager().callEvent(griefalert_event);
// Notify staff ingame
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.hasPermission("griefalert.notify")) {
player.sendMessage(message);
private void alert(String message, String playerName, String mapLink, String target, int x, int y, int z, String world) {
// Exclude trusted people
Player griefer = Bukkit.getPlayer(playerName);
if (griefer.hasPermission("griefalert.exclude") || griefer.hasPermission("griefalert.exclude." + target)) {
return;
}
// Spam limiter
String realAlertMessage = message;
String[] alert1 = null;
if (lastAlert != null) {
alert1 = lastAlert.split(" ");
}
String[] alert2 = message.split(" ");
if (alert1 != null) {
if (alert1[2].equals(alert2[2]) && alert1[5].equals(alert2[5]) && alert1[1].equals("broke") && alert2[1].equals("broke")) {
identicalAlerts += 1;
} else if (Arrays.equals(alert1, alert2)) {
identicalAlerts += 1;
} else {
identicalAlerts = 1;
}
}
if (identicalAlerts == 4) {
message = ChatColor.GRAY + "Same behavior continues.";
mapLink = null;
}
if (identicalAlerts > 4) {
return;
}
// Use direct location check
if (world != null && isLocationIgnored(x, y, z, world)) {
return; // Do not alert if location is ignored
}
// Send an event for external hooks
GriefAlertEvent griefalert_event;
if (MAP_LINK != null && !MAP_LINK.isEmpty() && mapLink != null) {
griefalert_event = new GriefAlertEvent(message + " (" + mapLink + ")");
} else {
griefalert_event = new GriefAlertEvent(message);
}
getServer().getPluginManager().callEvent(griefalert_event);
// Notify staff ingame
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.hasPermission("griefalert.notify")) {
player.sendMessage(message);
}
}
lastAlert = realAlertMessage;
}
// Block inspector: if the block was placed by another player, returns their name.
// Block inspector: only the most recent placement counts for ownership.
private static String inspectBlock(Block block, Player player) {
List<String[]> lookup = coreProtectAPI.blockLookup(block, 50000000);
if (lookup == null || lookup.size() <= 0) {
// Natural block
return null;
}
String[] result = lookup.get(0);
ParseResult parseResult = coreProtectAPI.parseResult(result);
if (parseResult.isRolledBack() && lookup.size() != 1) {
result = lookup.get(1);
parseResult = coreProtectAPI.parseResult(result);
}
if (result == null || parseResult == null || parseResult.getPlayer().startsWith("#") || parseResult.getPlayer().equals(player.getName())) {
// Placed by breaker or natural event
if (lookup == null || lookup.size() == 0) {
// Natural block
return null;
}
return parseResult.getPlayer();
// Find the most recent placement event only
for (String[] result : lookup) {
ParseResult parseResult = coreProtectAPI.parseResult(result);
if (parseResult == null) continue;
if (parseResult.getActionId() == 1 && !parseResult.isRolledBack() && !parseResult.getPlayer().startsWith("#")) {
// If the current player placed it, it's theirs (no alert)
if (parseResult.getPlayer().equals(player.getName())) {
return null;
} else {
return parseResult.getPlayer();
}
}
// If we see a break before a placement, stop (block is gone)
if (parseResult.getActionId() == 0) {
break;
}
}
// No valid placement found
return null;
}
private static String getHumanWorldName(String worldName) {

1
src/net/ardakaz/griefalert/GriefAlertEvent.java Executable file → Normal file
View File

@ -2,6 +2,7 @@
package net.ardakaz.griefalert;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;