9 Commits

Author SHA1 Message Date
c009654c5c fix spaces
All checks were successful
Build / Explore-Gitea-Actions (push) Successful in 47s
2026-07-22 14:38:35 +00:00
ab2c9bf1d6 Add default value to jdbc url (#11)
All checks were successful
Build / Explore-Gitea-Actions (push) Successful in 40s
Co-authored-by: Ardakaz <ardakaz@duck.com>
Reviewed-on: #11
Reviewed-by: Ardakaz <ardakaz@duck.com>
Co-authored-by: ThePindabaas <thepindabaas@noreply.localhost>
Co-committed-by: ThePindabaas <thepindabaas@noreply.localhost>
2026-07-18 18:25:28 +00:00
7aec608825 add new db tables (#13)
Some checks failed
Build / Explore-Gitea-Actions (push) Has been cancelled
Co-authored-by: ThePindabaas <219561634+ThePindabaas@users.noreply.github.com>
Co-authored-by: Ardakaz <ardakaz@duck.com>
Reviewed-on: #13
Reviewed-by: Ardakaz <ardakaz@duck.com>
Co-authored-by: ThePindabaas <thepindabaas@noreply.localhost>
Co-committed-by: ThePindabaas <thepindabaas@noreply.localhost>
2026-07-18 18:24:26 +00:00
e980768210 Fix lack of space after animal type (#12)
All checks were successful
Build / Explore-Gitea-Actions (push) Successful in 44s
Reviewed-on: #12
Reviewed-by: Ardakaz <ardakaz@duck.com>
Co-authored-by: ThePindabaas <thepindabaas@noreply.localhost>
Co-committed-by: ThePindabaas <thepindabaas@noreply.localhost>
2026-07-15 12:13:12 +00:00
5064ac5903 Restrict block break if condition (#10)
All checks were successful
Build / Explore-Gitea-Actions (push) Successful in 51s
Co-authored-by: ThePindabaas <219561634+ThePindabaas@users.noreply.github.com>
Reviewed-on: #10
Reviewed-by: Ardakaz <ardakaz@duck.com>
Co-authored-by: ThePindabaas <thepindabaas@noreply.localhost>
Co-committed-by: ThePindabaas <thepindabaas@noreply.localhost>
2026-07-13 15:12:00 +00:00
55881630bc Set up parameterized jdbc connection (#8)
All checks were successful
Build / Explore-Gitea-Actions (push) Successful in 42s
Co-authored-by: ThePindabaas <219561634+ThePindabaas@users.noreply.github.com>
Reviewed-on: #8
Reviewed-by: Ardakaz <ardakaz@duck.com>
Co-authored-by: ThePindabaas <thepindabaas@noreply.localhost>
Co-committed-by: ThePindabaas <thepindabaas@noreply.localhost>
2026-07-03 11:07:53 +00:00
Ardakaz
4cd24ad467 Just organizing a bit and adding comments
All checks were successful
Build / Explore-Gitea-Actions (push) Successful in 45s
2026-06-29 10:52:24 +03:00
db3649a2f5 add newline at the end of files (#5)
All checks were successful
Build / Explore-Gitea-Actions (push) Successful in 44s
Co-authored-by: ThePindabaas <219561634+ThePindabaas@users.noreply.github.com>
Reviewed-on: #5
Reviewed-by: Ardakaz <ardakaz@duck.com>
Co-authored-by: ThePindabaas <thepindabaas@noreply.localhost>
Co-committed-by: ThePindabaas <thepindabaas@noreply.localhost>
2026-06-28 11:49:23 +00:00
fec5f78cbc Introduce build pipeline (#4)
All checks were successful
Build / Explore-Gitea-Actions (push) Successful in 44s
Co-authored-by: ThePindabaas <219561634+ThePindabaas@users.noreply.github.com>
Reviewed-on: #4
Co-authored-by: ThePindabaas <thepindabaas@noreply.localhost>
Co-committed-by: ThePindabaas <thepindabaas@noreply.localhost>
2026-06-28 11:23:50 +00:00
6 changed files with 198 additions and 110 deletions

View File

@@ -0,0 +1,16 @@
name: Build
run-name: ${{ gitea.ref }} - ${{ gitea.sha }}
on: [push, workflow_dispatch]
jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '25'
- run: ./gradlew assemble
- run: ./gradlew test
- run: ./gradlew jar

19
.gitea/workflows/demo.yml Normal file
View File

@@ -0,0 +1,19 @@
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [workflow_dispatch]
jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."

View File

@@ -29,7 +29,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.projectiles.ProjectileSource;
import java.sql.*;
import java.util.Arrays;
@@ -42,7 +41,6 @@ import java.util.stream.Collectors;
public class GriefAlert extends JavaPlugin implements Listener {
private static CoreProtectAPI coreProtectAPI;
private final String DB_FILE = "ignored_locations.db";
private Integer identicalAlerts = 1;
private String lastAlert;
private Set<Material> EXCLUDED_BLOCKS;
@@ -51,6 +49,10 @@ public class GriefAlert extends JavaPlugin implements Listener {
private Boolean ALLOW_STEALING;
private Connection connection;
/*
UTILITY FUNCTIONS
*/
// 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);
@@ -71,7 +73,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
}
}
// If we see a break before a placement, stop (block is gone)
if (parseResult.getActionId() == 0) {
if (parseResult.getActionId() == 0 && !parseResult.isRolledBack()) {
break;
}
}
@@ -91,6 +93,65 @@ public class GriefAlert extends JavaPlugin implements Listener {
return world;
}
// Sends the alert (or cancels it)
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;
}
/*
INITIALIZATION
*/
// Init GriefAlert
@Override
public void onEnable() {
@@ -132,16 +193,26 @@ public class GriefAlert extends JavaPlugin implements Listener {
}
private void setupDatabase() {
String jdbcUrl = getConfig().getString("jdbc-url");
try {
connection = DriverManager.getConnection("jdbc:sqlite:" + getDataFolder().getAbsolutePath() + "/" + DB_FILE);
connection = DriverManager.getConnection(jdbcUrl);
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.executeUpdate(Migrations.CREATE_TABLE_IGNORED_LOCATIONS);
stmt.executeUpdate(Migrations.CREATE_TABLE_PLAYERS);
stmt.executeUpdate(Migrations.CREATE_TABLE_ACTIONS);
stmt.executeUpdate(Migrations.CREATE_TABLE_ALERTS);
stmt.executeUpdate(Migrations.CREATE_TABLE_REPORTS);
stmt.close();
getLogger().info("Connected to "+jdbcUrl);
} catch (SQLException e) {
getLogger().severe("Could not set up SQLite database: " + e.getMessage());
}
}
/*
LOCATION IGNORING
*/
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=?");
@@ -192,6 +263,10 @@ public class GriefAlert extends JavaPlugin implements Listener {
}
}
/*
EVENT LISTENERS
*/
@EventHandler(ignoreCancelled = true)
// Block break alerts
public void onBlockBreak(BlockBreakEvent event) {
@@ -337,7 +412,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
}
}
//event handler for item frames
// Placing item to an item frame
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!(event.getRightClicked() instanceof ItemFrame frame)) return;
@@ -371,7 +446,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
}
}
// Breaking item frame item (uses a different event then placing an item)
// Item frame stealing alerts
@EventHandler(ignoreCancelled = true)
public void onItemFrameDamage(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof ItemFrame frame)) return;
@@ -399,6 +474,7 @@ 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);
}
// Item frame breaking alerts
@EventHandler(ignoreCancelled = true)
public void onItemFrameBreak(HangingBreakByEntityEvent event) {
if (!(event.getEntity() instanceof ItemFrame frame)) return;
@@ -424,6 +500,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
}
// Command handler
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!command.getName().equalsIgnoreCase("griefalert")) return false;
@@ -585,57 +662,6 @@ public class GriefAlert extends JavaPlugin implements Listener {
return null;
}
// Sends the alert (or cancels it)
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;
}
//pet alert(dog and cat only)
@EventHandler
public void onPetKill(EntityDeathEvent event) {
@@ -663,7 +689,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
}
//farm animal handler
// Mob killing alerts
@EventHandler
public void onFarmAnimalDeath(EntityDeathEvent event) {
if (!(event.getEntity().getKiller() instanceof Player killer)) return;
@@ -699,6 +725,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
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 */
// Waxing/unwaxing alerts
@EventHandler
public void onBlockClick(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
@@ -755,13 +782,13 @@ public class GriefAlert extends JavaPlugin implements Listener {
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);
}, 1L);
}
//stripping logs
// Log stripping alerts
@EventHandler
public void onLogStrip(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
@@ -812,53 +839,9 @@ public class GriefAlert extends JavaPlugin implements Listener {
}, 1L);
}
//Ender Crystal shenanigans
@EventHandler
public void onEndCrystalDeath(EntityDamageByEntityEvent event){
//if its not an endercrystal it should not do logic for enderCrystal
if(!(event.getEntity() instanceof EnderCrystal)) return;
Location loc = event.getEntity().getLocation();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
String world = loc.getWorld().getName();
//Placeholder
Player damager = null;
//if its a Player then its a player (damage is like sword or fist or whatever)
if(event.getDamager() instanceof Player player){
damager = player;
//if its not hit by a player, its from a projectile which we need ownership off
}else if(event.getDamager() instanceof Projectile projectile){
ProjectileSource source = projectile.getShooter();
if(source instanceof Player player){
damager = player;
}
}
if(damager == null){
return; //idk what it is, (i do) but it wasnt a player
}
if (isLocationIgnored(x, y, z, world)) {
return;
}
Block block = loc.getBlock();
String target = inspectBlock(block, damager);
if (target == null) return;
//cuz Blåhaj is cute so if you damage your own stuff u gucci
if (target.equals(damager.getName())) return;
String message = ChatColor.GRAY + damager.getName() + " destroyed an ender crystal owned by " + target + " at " + x + " " + y + " " + z;
alert(message, damager.getName(), "[Map Link](" + MAP_LINK + "/?worldname=" + world + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, world);
}
/*
CoreProtect API
*/
private CoreProtectAPI getCoreProtect() {
Plugin plugin = getServer().getPluginManager().getPlugin("CoreProtect");

View File

@@ -0,0 +1,68 @@
package net.ardakaz.griefalert;
public class Migrations {
public static final String CREATE_TABLE_IGNORED_LOCATIONS =
"CREATE TABLE IF NOT EXISTS ignored_locations (" +
"x INTEGER, " +
"y INTEGER, " +
"z INTEGER, " +
"world TEXT, " +
"PRIMARY KEY (x, y, z, world)" +
")";
public static final String CREATE_TABLE_PLAYERS =
"CREATE TABLE IF NOT EXISTS players (" +
"id TEXT PRIMARY KEY, " +
"names TEXT NOT NULL, " +
"playtime INTEGER NOT NULL DEFAULT 0, " +
"firstseen INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP, " +
"lastseen INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP" +
")";
public static final String CREATE_TABLE_ACTIONS =
"CREATE TABLE IF NOT EXISTS actions (" +
"id INTEGER PRIMARY KEY, " +
"player TEXT NOT NULL, " +
"type TEXT NOT NULL, " +
"moderator TEXT NOT NULL, " +
"reason TEXT, " +
"time TEXT, " +
"timestamp INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP, " +
"FOREIGN KEY(player) REFERENCES players(id)" +
")";
public static final String CREATE_TABLE_ALERTS =
"CREATE TABLE IF NOT EXISTS alerts (" +
"id INTEGER PRIMARY KEY, " +
"player TEXT NOT NULL, " +
"action TEXT NOT NULL, " +
"target TEXT NOT NULL, " +
"target_amount INTEGER, " +
"target_player TEXT NOT NULL, " +
"x INTEGER NOT NULL, " +
"y INTEGER NOT NULL, " +
"z INTEGER NOT NULL, " +
"world TEXT NOT NULL, " +
"is_flagged INTEGER, " +
"flag_text TEXT, " +
"resolved_by TEXT, " +
"state TEXT NOT NULL DEFAULT 'UNRESOLVED', " +
"timestamp INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP, " +
"FOREIGN KEY(player) REFERENCES players(id)" +
")";
public static final String CREATE_TABLE_REPORTS =
"CREATE TABLE IF NOT EXISTS reports (" +
"id INTEGER PRIMARY KEY, " +
"player TEXT NOT NULL, " +
"x INTEGER NOT NULL, " +
"y INTEGER NOT NULL, " +
"z INTEGER NOT NULL, " +
"world TEXT NOT NULL, " +
"text TEXT NOT NULL, " +
"resolved_by TEXT, " +
"timestamp INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP, " +
"state TEXT NOT NULL DEFAULT 'UNRESOLVED'" +
")";
}

View File

@@ -1,6 +1,8 @@
# Ignore all stealing?
allow-stealing: false
jdbc-url: "./plugins/GriefAlert/database.db"
# Breaking these blocks don't cause alerts. (Material)
excluded-blocks:
- WHEAT