Cleaning up
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
name: GriefAlert
|
name: GriefAlert
|
||||||
main: net.ardakaz.griefalert.GriefAlert
|
main: net.ardakaz.griefalert.GriefAlert
|
||||||
version: 0.5
|
version: 0.6
|
||||||
api-version: 1.21
|
api-version: 1.21
|
||||||
depends: [CoreProtect]
|
depends: [CoreProtect]
|
||||||
softdepend: [DiscordSRV]
|
softdepend: [DiscordSRV]
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package net.ardakaz.griefalert;
|
|||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
import net.coreprotect.CoreProtectAPI;
|
import net.coreprotect.CoreProtectAPI;
|
||||||
import net.coreprotect.CoreProtectAPI.ParseResult;
|
import net.coreprotect.CoreProtectAPI.ParseResult;
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -12,57 +10,90 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.event.*;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.event.inventory.InventoryAction;
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
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.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class GriefAlert extends JavaPlugin implements Listener {
|
public class GriefAlert extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
private static CoreProtectAPI coreProtectAPI;
|
private static CoreProtectAPI coreProtectAPI;
|
||||||
|
private final String DB_FILE = "ignored_locations.db";
|
||||||
private Integer identicalAlerts = 1;
|
private Integer identicalAlerts = 1;
|
||||||
private String lastAlert;
|
private String lastAlert;
|
||||||
|
|
||||||
private Set<Material> EXCLUDED_BLOCKS;
|
private Set<Material> EXCLUDED_BLOCKS;
|
||||||
private Set<InventoryType> VALID_CONTAINERS;
|
private Set<InventoryType> VALID_CONTAINERS;
|
||||||
private String MAP_LINK;
|
private String MAP_LINK;
|
||||||
private Boolean ALLOW_STEALING;
|
private Boolean ALLOW_STEALING;
|
||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private final String DB_FILE = "ignored_locations.db";
|
|
||||||
|
// 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.isEmpty()) {
|
||||||
|
// Natural block
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 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) {
|
||||||
|
String world = "";
|
||||||
|
|
||||||
|
if (worldName.endsWith("_nether")) {
|
||||||
|
world = " in the Nether";
|
||||||
|
} else if (worldName.endsWith("_the_end")) {
|
||||||
|
world = " in the End";
|
||||||
|
}
|
||||||
|
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
// Init GriefAlert
|
// Init GriefAlert
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
coreProtectAPI = getCoreProtect();
|
coreProtectAPI = getCoreProtect();
|
||||||
if (coreProtectAPI == null) {
|
if (coreProtectAPI == null) {
|
||||||
getLogger().severe("CoreProtect not found! Disabling plugin.");
|
getLogger().severe("CoreProtect not found! Disabling plugin.");
|
||||||
@@ -71,7 +102,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
List<String> excludedBlocks = getConfig().getStringList("excluded-blocks");
|
List<String> excludedBlocks = getConfig().getStringList("excluded-blocks");
|
||||||
@@ -80,9 +111,9 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
VALID_CONTAINERS = validContainers.stream().map(InventoryType::valueOf).collect(Collectors.toSet());
|
VALID_CONTAINERS = validContainers.stream().map(InventoryType::valueOf).collect(Collectors.toSet());
|
||||||
MAP_LINK = getConfig().getString("map-link");
|
MAP_LINK = getConfig().getString("map-link");
|
||||||
ALLOW_STEALING = getConfig().getBoolean("allow-stealing");
|
ALLOW_STEALING = getConfig().getBoolean("allow-stealing");
|
||||||
|
|
||||||
setupDatabase();
|
setupDatabase();
|
||||||
|
|
||||||
getCommand("griefalert").setTabCompleter(this);
|
getCommand("griefalert").setTabCompleter(this);
|
||||||
|
|
||||||
getLogger().info("GriefAlert has been enabled.");
|
getLogger().info("GriefAlert has been enabled.");
|
||||||
@@ -92,7 +123,10 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getLogger().info("GriefAlert has been disabled.");
|
getLogger().info("GriefAlert has been disabled.");
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
try { connection.close(); } catch (SQLException ignored) {}
|
try {
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,14 +190,14 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler (ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
// Block break alerts
|
// Block break alerts
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
// Exclusion list
|
// Exclusion list
|
||||||
if (EXCLUDED_BLOCKS.contains(event.getBlock().getType())) {
|
if (EXCLUDED_BLOCKS.contains(event.getBlock().getType())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event parser
|
// Event parser
|
||||||
String playerName = event.getPlayer().getName();
|
String playerName = event.getPlayer().getName();
|
||||||
@@ -180,47 +214,46 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
|
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stealing alerts
|
// Stealing alerts
|
||||||
@EventHandler (ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
if (ALLOW_STEALING) {
|
if (ALLOW_STEALING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean stealing;
|
boolean stealing;
|
||||||
|
|
||||||
// Event parser for inv
|
// Event parser for inv
|
||||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
if (!(event.getWhoClicked() instanceof Player player)) return;
|
||||||
Player player = (Player) event.getWhoClicked();
|
|
||||||
Inventory inventory = event.getInventory();
|
Inventory inventory = event.getInventory();
|
||||||
Inventory clickedInventory = event.getClickedInventory();
|
Inventory clickedInventory = event.getClickedInventory();
|
||||||
ItemStack item = event.getCurrentItem();
|
ItemStack item = event.getCurrentItem();
|
||||||
|
|
||||||
if (item == null || inventory.getLocation() == null || item.getType() == Material.AIR) {
|
if (item == null || inventory.getLocation() == null || item.getType() == Material.AIR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exclusion list
|
// Exclusion list
|
||||||
if (!VALID_CONTAINERS.contains(inventory.getType())) {
|
if (!VALID_CONTAINERS.contains(inventory.getType())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inv actions (needs fixing)
|
// Inv actions (needs fixing)
|
||||||
InventoryAction action = event.getAction();
|
InventoryAction action = event.getAction();
|
||||||
if ((action == InventoryAction.PICKUP_ALL || action == InventoryAction.PICKUP_HALF ||
|
if ((action == InventoryAction.PICKUP_ALL || action == InventoryAction.PICKUP_HALF ||
|
||||||
action == InventoryAction.PICKUP_ONE || action == InventoryAction.PICKUP_SOME ||
|
action == InventoryAction.PICKUP_ONE || action == InventoryAction.PICKUP_SOME ||
|
||||||
action == InventoryAction.MOVE_TO_OTHER_INVENTORY) && clickedInventory == inventory) {
|
action == InventoryAction.MOVE_TO_OTHER_INVENTORY) && clickedInventory == inventory) {
|
||||||
stealing = true;
|
stealing = true;
|
||||||
} else if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_SOME || action == InventoryAction.PLACE_ONE || action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
} else if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_SOME || action == InventoryAction.PLACE_ONE || action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
||||||
stealing = false;
|
stealing = false;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event parser for container + check if grief
|
// Event parser for container + check if grief
|
||||||
String target = inspectBlock(inventory.getLocation().getBlock(), player);
|
String target = inspectBlock(inventory.getLocation().getBlock(), player);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
String itemName = item.getType().toString();
|
String itemName = item.getType().toString();
|
||||||
int amount = item.getAmount();
|
int amount = item.getAmount();
|
||||||
int x = inventory.getLocation().getBlockX();
|
int x = inventory.getLocation().getBlockX();
|
||||||
@@ -291,11 +324,11 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
String action;
|
String action;
|
||||||
//this works at the instance of interaction before items get moved around
|
//this works at the instance of interaction before items get moved around
|
||||||
if (handEmpty && !armorEmpty) {
|
if (handEmpty && !armorEmpty) {
|
||||||
action = "took " + armorItem.getType().toString();
|
action = "took " + armorItem.getType();
|
||||||
} else if (!handEmpty && armorEmpty) {
|
} else if (!handEmpty && armorEmpty) {
|
||||||
action = "added " + handItem.getType().toString();
|
action = "added " + handItem.getType();
|
||||||
} else if (!handEmpty) {
|
} else if (!handEmpty) {
|
||||||
action = "swapped " + armorItem.getType().toString() + " with " + handItem.getType().toString();
|
action = "swapped " + armorItem.getType() + " with " + handItem.getType();
|
||||||
} else {
|
} else {
|
||||||
action = "interacted with";
|
action = "interacted with";
|
||||||
}
|
}
|
||||||
@@ -303,11 +336,12 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, 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
|
//event handler for item frames
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event){
|
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||||
if(!(event.getRightClicked() instanceof ItemFrame frame)) return;
|
if (!(event.getRightClicked() instanceof ItemFrame frame)) return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
int x = frame.getLocation().getBlockX();
|
int x = frame.getLocation().getBlockX();
|
||||||
int y = frame.getLocation().getBlockY();
|
int y = frame.getLocation().getBlockY();
|
||||||
@@ -318,31 +352,28 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String target = inspectBlock(frame.getLocation().getBlock(), player);
|
String target = inspectBlock(frame.getLocation().getBlock(), player);
|
||||||
if(target !=null){
|
if (target != null) {
|
||||||
ItemStack itemInFrame = frame.getItem();
|
ItemStack itemInFrame = frame.getItem();
|
||||||
ItemStack handItem = player.getInventory().getItemInMainHand();
|
ItemStack handItem = player.getInventory().getItemInMainHand();
|
||||||
boolean handEmpty = handItem ==null || handItem.getType() == Material.AIR;
|
boolean handEmpty = handItem == null || handItem.getType() == Material.AIR;
|
||||||
boolean frameEmpty = itemInFrame ==null || itemInFrame.getType() == Material.AIR;
|
boolean frameEmpty = itemInFrame == null || itemInFrame.getType() == Material.AIR;
|
||||||
String playerName = player.getName();
|
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);
|
String action;
|
||||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
|
if (!handEmpty && frameEmpty) {
|
||||||
|
action = "added " + handItem.getType();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = ChatColor.GRAY + playerName + " " + action + " an item to an item frame 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Breaking item frame item (uses a different event then placing an item)
|
// Breaking item frame item (uses a different event then placing an item)
|
||||||
@EventHandler (ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onItemFrameDamage(EntityDamageByEntityEvent event) {
|
public void onItemFrameDamage(EntityDamageByEntityEvent event) {
|
||||||
if (!(event.getEntity() instanceof ItemFrame frame)) return;
|
if (!(event.getEntity() instanceof ItemFrame frame)) return;
|
||||||
if (!(event.getDamager() instanceof Player player)) return;
|
if (!(event.getDamager() instanceof Player player)) return;
|
||||||
@@ -366,13 +397,12 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
if (item.getType() == Material.AIR) return;
|
if (item.getType() == Material.AIR) return;
|
||||||
// At this point, the player is removing the item
|
// At this point, the player is removing the item
|
||||||
String action = "took " + item.getType();
|
String action = "took " + item.getType();
|
||||||
String message = ChatColor.GRAY + playerName + " " + action + " from item frame owned by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
String message = ChatColor.GRAY + playerName + " " + action + " from an item frame 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);
|
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)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onItemFrameBreak(HangingBreakByEntityEvent event){
|
public void onItemFrameBreak(HangingBreakByEntityEvent event) {
|
||||||
if (!(event.getEntity() instanceof ItemFrame frame)) return;
|
if (!(event.getEntity() instanceof ItemFrame frame)) return;
|
||||||
if (!(event.getRemover() instanceof Player player)) return;
|
if (!(event.getRemover() instanceof Player player)) return;
|
||||||
|
|
||||||
@@ -389,7 +419,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String target = inspectBlock(loc.getBlock(), player);
|
String target = inspectBlock(loc.getBlock(), player);
|
||||||
if (target ==null || target.equals(player.getName())) return;
|
if (target == null || target.equals(player.getName())) return;
|
||||||
|
|
||||||
String action = "broke an item frame";
|
String action = "broke an item frame";
|
||||||
String message = ChatColor.GRAY + playerName + " " + action + " placed by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
String message = ChatColor.GRAY + playerName + " " + action + " placed by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||||
@@ -397,9 +427,6 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (!command.getName().equalsIgnoreCase("griefalert")) return false;
|
if (!command.getName().equalsIgnoreCase("griefalert")) return false;
|
||||||
@@ -418,7 +445,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
|
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
world = ((Player)sender).getWorld().getName();
|
world = ((Player) sender).getWorld().getName();
|
||||||
try {
|
try {
|
||||||
x = Integer.parseInt(args[1]);
|
x = Integer.parseInt(args[1]);
|
||||||
y = Integer.parseInt(args[2]);
|
y = Integer.parseInt(args[2]);
|
||||||
@@ -462,7 +489,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
|
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
world = ((Player)sender).getWorld().getName();
|
world = ((Player) sender).getWorld().getName();
|
||||||
try {
|
try {
|
||||||
x = Integer.parseInt(args[1]);
|
x = Integer.parseInt(args[1]);
|
||||||
y = Integer.parseInt(args[2]);
|
y = Integer.parseInt(args[2]);
|
||||||
@@ -503,7 +530,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
|
sender.sendMessage(ChatColor.RED + "Only players can use this command without specifying a world.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
world = ((Player)sender).getWorld().getName();
|
world = ((Player) sender).getWorld().getName();
|
||||||
try {
|
try {
|
||||||
x = Integer.parseInt(args[1]);
|
x = Integer.parseInt(args[1]);
|
||||||
y = Integer.parseInt(args[2]);
|
y = Integer.parseInt(args[2]);
|
||||||
@@ -597,7 +624,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
// Send an event for external hooks
|
// Send an event for external hooks
|
||||||
GriefAlertEvent griefalert_event;
|
GriefAlertEvent griefalert_event;
|
||||||
if (MAP_LINK != null && !MAP_LINK.isEmpty() && mapLink != null) {
|
if (MAP_LINK != null && !MAP_LINK.isEmpty() && mapLink != null) {
|
||||||
griefalert_event = new GriefAlertEvent(message + " (" + mapLink + ")");
|
griefalert_event = new GriefAlertEvent(message + " (" + mapLink + ")");
|
||||||
} else {
|
} else {
|
||||||
griefalert_event = new GriefAlertEvent(message);
|
griefalert_event = new GriefAlertEvent(message);
|
||||||
@@ -611,74 +638,47 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
lastAlert = realAlertMessage;
|
lastAlert = realAlertMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.isEmpty()) {
|
|
||||||
// Natural block
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//pet alert(dog and cat only)
|
//pet alert(dog and cat only)
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPetKill(EntityDeathEvent event){
|
public void onPetKill(EntityDeathEvent event) {
|
||||||
if (!(event.getEntity() instanceof Tameable tameable)) return;
|
if (!(event.getEntity() instanceof Tameable tameable)) return;
|
||||||
if (!tameable.isTamed()) return;
|
if (!tameable.isTamed()) return;
|
||||||
|
|
||||||
//checks if wolf or cat or not
|
//checks if wolf or cat or not
|
||||||
if (!(event.getEntity() instanceof Wolf) && !(event.getEntity()instanceof Cat)) return;
|
if (!(event.getEntity() instanceof Wolf) && !(event.getEntity() instanceof Cat)) return;
|
||||||
|
|
||||||
|
|
||||||
AnimalTamer Owner = tameable.getOwner();
|
AnimalTamer Owner = tameable.getOwner();
|
||||||
if (Owner == null) return;
|
if (Owner == null) return;
|
||||||
if (!(event.getEntity().getKiller() instanceof Player killer)) return;
|
if (!(event.getEntity().getKiller() instanceof Player killer)) return;
|
||||||
//if owner kills nothing happens
|
//if owner kills nothing happens
|
||||||
if (killer.getUniqueId().equals(Owner.getUniqueId())) return;
|
if (killer.getUniqueId().equals(Owner.getUniqueId())) return;
|
||||||
|
|
||||||
int x = event.getEntity().getLocation().getBlockX();
|
int x = event.getEntity().getLocation().getBlockX();
|
||||||
int y = event.getEntity().getLocation().getBlockY();
|
int y = event.getEntity().getLocation().getBlockY();
|
||||||
int z = event.getEntity().getLocation().getBlockZ();
|
int z = event.getEntity().getLocation().getBlockZ();
|
||||||
String worldName = event.getEntity().getWorld().getName();
|
String worldName = event.getEntity().getWorld().getName();
|
||||||
String pet = event.getEntity().getType().name();
|
String pet = event.getEntity().getType().name();
|
||||||
|
|
||||||
String message = ChatColor.GRAY + killer.getName() + " killed" +" " + pet + " in " + Owner.getName() + "'s build at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
String message = ChatColor.GRAY + killer.getName() + " killed" + " " + pet + " in " + Owner.getName() + "'s build at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||||
alert(message, killer.getName(), "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", Owner.getName(), x, y, z, worldName);
|
alert(message, killer.getName(), "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", Owner.getName(), x, y, z, worldName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//farm animal handler
|
//farm animal handler
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFarmAnimalDeath(EntityDeathEvent event){
|
public void onFarmAnimalDeath(EntityDeathEvent event) {
|
||||||
if(!(event.getEntity().getKiller() instanceof Player killer)) return;
|
if (!(event.getEntity().getKiller() instanceof Player killer)) return;
|
||||||
List<String> alertanimals = getConfig().getStringList("triggered-animals");
|
List<String> alertanimals = getConfig().getStringList("triggered-animals");
|
||||||
String typeName = event.getEntityType().name();
|
String typeName = event.getEntityType().name();
|
||||||
|
|
||||||
|
|
||||||
if(! alertanimals.contains(typeName)) return;
|
|
||||||
|
if (!alertanimals.contains(typeName)) return;
|
||||||
|
|
||||||
Block blockBelow = event.getEntity().getLocation().subtract(0, 1, 0).getBlock();
|
Block blockBelow = event.getEntity().getLocation().subtract(0, 1, 0).getBlock();
|
||||||
String animalOwner = inspectBlock(blockBelow, killer);
|
String animalOwner = inspectBlock(blockBelow, killer);
|
||||||
|
|
||||||
if (animalOwner == null) return;
|
if (animalOwner == null) return;
|
||||||
|
|
||||||
if (animalOwner.equals(killer.getName())) return;
|
if (animalOwner.equals(killer.getName())) return;
|
||||||
@@ -688,21 +688,22 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
int y = event.getEntity().getLocation().getBlockY();
|
int y = event.getEntity().getLocation().getBlockY();
|
||||||
int z = event.getEntity().getLocation().getBlockZ();
|
int z = event.getEntity().getLocation().getBlockZ();
|
||||||
String worldName = event.getEntity().getWorld().getName();
|
String worldName = event.getEntity().getWorld().getName();
|
||||||
|
|
||||||
|
|
||||||
String message = ChatColor.GRAY + killer.getName() + " killed" +" " + typeName + "in " + animalOwner + "'s build at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
|
||||||
|
String message = ChatColor.GRAY + killer.getName() + " killed" + " " + typeName + "in " + animalOwner + "'s build at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||||
|
|
||||||
alert(message, killer.getName(), "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", animalOwner, x, y, z, worldName);
|
alert(message, killer.getName(), "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", animalOwner, x, y, z, worldName);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*code i hope for copper waxing/unwaxing theres no proper onwax() or onUnWax()
|
/*code i hope for copper waxing/unwaxing theres no proper onwax() or onUnWax()
|
||||||
so im kinda gonna try to just check a situation like, if ur holding an axe, left clicking a copper block
|
so im kinda gonna try to just check a situation like, if ur holding an axe, left clicking a copper block
|
||||||
and its waxed, ill assume ur unwaxing, and therefor sending an alert
|
and its waxed, ill assume ur unwaxing, and therefor sending an alert
|
||||||
but some of this code was written at 1am so idk how and why im why and howing */
|
but some of this code was written at 1am so idk how and why im why and howing */
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockClick(PlayerInteractEvent event) {
|
public void onBlockClick(PlayerInteractEvent event) {
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
@@ -712,31 +713,31 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
if (block == null || item == null) return;
|
if (block == null || item == null) return;
|
||||||
|
|
||||||
Material before = block.getType();
|
Material before = block.getType();
|
||||||
|
|
||||||
|
|
||||||
int x = block.getX();
|
int x = block.getX();
|
||||||
int y = block.getY();
|
int y = block.getY();
|
||||||
int z = block.getZ();
|
int z = block.getZ();
|
||||||
String world = block.getWorld().getName();
|
String world = block.getWorld().getName();
|
||||||
|
|
||||||
|
|
||||||
if (isLocationIgnored(x, y, z, world)){
|
|
||||||
|
if (isLocationIgnored(x, y, z, world)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isCopper = before.name().contains("COPPER");
|
boolean isCopper = before.name().contains("COPPER");
|
||||||
//if aint copper it can no copper and means no copper affected
|
//if aint copper it can no copper and means no copper affected
|
||||||
if (!isCopper) return;
|
if (!isCopper) return;
|
||||||
//for waxing logic might not even be needed
|
//for waxing logic might not even be needed
|
||||||
//boolean isHoneycomb = item.getType() == Material.HONEYCOMB;
|
//boolean isHoneycomb = item.getType() == Material.HONEYCOMB;
|
||||||
|
|
||||||
//for unwax logic and also might not be needed
|
//for unwax logic and also might not be needed
|
||||||
//boolean isAxe = item.getType().toString().endsWith("_AXE");
|
//boolean isAxe = item.getType().toString().endsWith("_AXE");
|
||||||
|
|
||||||
String target = inspectBlock(block, player);
|
String target = inspectBlock(block, player);
|
||||||
if(target == player.getName()) return;
|
if (Objects.equals(target, player.getName())) return;
|
||||||
if(target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||||
String action;
|
String action;
|
||||||
Material after = block.getType();
|
Material after = block.getType();
|
||||||
@@ -745,37 +746,32 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
boolean wasWaxed = before.name().startsWith("WAXED_");
|
boolean wasWaxed = before.name().startsWith("WAXED_");
|
||||||
boolean isWaxed = after.name().startsWith("WAXED_");
|
boolean isWaxed = after.name().startsWith("WAXED_");
|
||||||
|
|
||||||
if(wasWaxed && !isWaxed){
|
if (wasWaxed && !isWaxed) {
|
||||||
action = "Unwaxed";
|
action = "Unwaxed";
|
||||||
} else if(!wasWaxed && isWaxed) {
|
} else if (!wasWaxed && isWaxed) {
|
||||||
action = "Waxed";
|
action = "Waxed";
|
||||||
} else if (item !=null && item.getType().name().endsWith("_AXE")) {
|
} else if (item != null && item.getType().name().endsWith("_AXE")) {
|
||||||
action = "undusted";
|
action = "undusted";
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
action = "error 404 check with kleedje30";
|
action = "error 404 check with kleedje30";
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = ChatColor.GRAY + player.getName() + action + " Copper " + " at " + x + " " + y + " " + z + getHumanWorldName(world);
|
String message = ChatColor.GRAY + player.getName() + action + " Copper " + " at " + x + " " + y + " " + z + getHumanWorldName(world);
|
||||||
alert(message, player.getName(), "[Map Link](" + MAP_LINK + "/?worldname=" + world + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")",target, x, y, z, world);
|
alert(message, player.getName(), "[Map Link](" + MAP_LINK + "/?worldname=" + world + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, world);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}, 1L);
|
}, 1L);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//stripping logs
|
//stripping logs
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLogStrip(PlayerInteractEvent event){
|
public void onLogStrip(PlayerInteractEvent event) {
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
|
|
||||||
if (block == null || item == null) return;
|
if (block == null || item == null) return;
|
||||||
|
|
||||||
@@ -788,51 +784,37 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
boolean isWood = before.name().contains("LOG");
|
boolean isWood = before.name().contains("LOG");
|
||||||
|
|
||||||
if(!isWood) return;
|
if (!isWood) return;
|
||||||
|
|
||||||
|
|
||||||
if (isLocationIgnored(x, y, z, world)){
|
|
||||||
|
if (isLocationIgnored(x, y, z, world)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String target = inspectBlock(block, player);
|
String target = inspectBlock(block, player);
|
||||||
if(target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
if(target == player.getName()) return;
|
if (target.equals(player.getName())) return;
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||||
String action;
|
String action;
|
||||||
Material after = block.getType();
|
Material after = block.getType();
|
||||||
if(before == after) return;
|
if (before == after) return;
|
||||||
|
|
||||||
if(!before.name().contains("STRIPPED") && after.name().contains("STRIPPED")){
|
if (!before.name().contains("STRIPPED") && after.name().contains("STRIPPED")) {
|
||||||
action = "Stripped";
|
action = "Stripped";
|
||||||
} else{return;}
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
String message = ChatColor.GRAY + player.getName() + action + " a(n) " + before + " at " + x + " " + y + " " + z + getHumanWorldName(world);
|
String message = ChatColor.GRAY + player.getName() + action + " a(n) " + before + " at " + x + " " + y + " " + z + getHumanWorldName(world);
|
||||||
alert(message, player.getName(), "[Map Link](" + MAP_LINK + "/?worldname=" + world + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")",target, x, y, z, world);
|
alert(message, player.getName(), "[Map Link](" + MAP_LINK + "/?worldname=" + world + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, world);
|
||||||
|
|
||||||
|
|
||||||
|
}, 1L);
|
||||||
}, 1L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static String getHumanWorldName(String worldName) {
|
|
||||||
String world = "";
|
|
||||||
|
|
||||||
if (worldName.endsWith("_nether")) {
|
|
||||||
world = " in the Nether";
|
|
||||||
}
|
|
||||||
else if (worldName.endsWith("_the_end")) {
|
|
||||||
world = " in the End";
|
|
||||||
}
|
|
||||||
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CoreProtectAPI getCoreProtect() {
|
private CoreProtectAPI getCoreProtect() {
|
||||||
Plugin plugin = getServer().getPluginManager().getPlugin("CoreProtect");
|
Plugin plugin = getServer().getPluginManager().getPlugin("CoreProtect");
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
public class GriefAlertEvent extends Event {
|
public class GriefAlertEvent extends Event {
|
||||||
private static final HandlerList HANDLERS = new HandlerList();
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
private String alert = "";
|
private String alert = "";
|
||||||
|
|
||||||
public GriefAlertEvent(String alert) {
|
public GriefAlertEvent(String alert) {
|
||||||
this.alert = alert;
|
this.alert = alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user