Compare commits

..

11 Commits
main ... 0.3.2

Author SHA1 Message Date
110fa1c8cf Manual pull from dev 2025-06-12 07:40:07 +00:00
79408d801b Manual pull from dev 2025-06-12 07:39:37 +00:00
2f6b42fef4 Manual pull from dev 2025-06-12 07:39:05 +00:00
0c21d1b645 Temp thingy 2 2025-06-12 07:35:21 +00:00
4186a1dedf Temp thingy 2025-06-12 07:33:12 +00:00
480e157e1a Correct version 2025-06-05 18:10:25 +00:00
a340441fae Merge pull request 'v0.3.1' (#2) from dev into main
Reviewed-on: #2
2025-06-05 18:09:21 +00:00
c706c8d0f0 Merge pull request 'v0.3' (#1) from dev into main
Reviewed-on: #1
2025-06-02 07:03:25 +00:00
02d9dabda9 Added license 2025-05-24 18:23:30 +00:00
6769c8e57f revert 11383965a8a5c46efeb61682bec006f36246987d
revert Quick fix
2025-05-24 04:12:13 +00:00
11383965a8 Quick fix 2025-05-24 04:10:12 +00:00
4 changed files with 17 additions and 189 deletions

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2025 ArdakazMC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,6 +1,6 @@
name: GriefAlert name: GriefAlert
main: net.ardakaz.griefalert.GriefAlert main: net.ardakaz.griefalert.GriefAlert
version: 0.4 version: 0.3.2
api-version: 1.21 api-version: 1.21
depends: [CoreProtect] depends: [CoreProtect]
softdepend: [DiscordSRV] softdepend: [DiscordSRV]

View File

@ -6,7 +6,6 @@ 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.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -16,18 +15,13 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; 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.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.PlayerInteractEntityEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; 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 org.bukkit.entity.ArmorStand;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -38,10 +32,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.entity.ItemFrame;
public class GriefAlert extends JavaPlugin implements Listener, TabCompleter { public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
@ -236,182 +226,6 @@ public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
} }
} }
// 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 @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;
@ -609,7 +423,7 @@ public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
} }
// 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()) {
griefalert_event = new GriefAlertEvent(message + " (" + mapLink + ")"); griefalert_event = new GriefAlertEvent(message + " (" + mapLink + ")");
} else { } else {
griefalert_event = new GriefAlertEvent(message); griefalert_event = new GriefAlertEvent(message);

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

@ -12,6 +12,11 @@ public class GriefAlertEvent extends Event {
public GriefAlertEvent(String alert) { public GriefAlertEvent(String alert) {
this.alert = alert; this.alert = alert;
// Discord hook for 1.21.5
if (Bukkit.getServer().getPluginManager().getPlugin("DiscordSRV") != null) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "discord broadcast #grief-alerts " + this.getAlert());
}
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {