Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5064ac5903 | |||
| 55881630bc | |||
|
|
4cd24ad467 | ||
| db3649a2f5 | |||
| fec5f78cbc |
16
.gitea/workflows/build.yml
Normal file
16
.gitea/workflows/build.yml
Normal 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
19
.gitea/workflows/demo.yml
Normal 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 }}."
|
||||
@@ -41,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;
|
||||
@@ -50,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);
|
||||
@@ -70,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;
|
||||
}
|
||||
}
|
||||
@@ -90,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() {
|
||||
@@ -131,16 +193,22 @@ 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.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=?");
|
||||
@@ -191,6 +259,10 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
EVENT LISTENERS
|
||||
*/
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
// Block break alerts
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
@@ -336,7 +408,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;
|
||||
@@ -370,7 +442,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;
|
||||
@@ -398,6 +470,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;
|
||||
@@ -423,6 +496,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;
|
||||
@@ -584,57 +658,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) {
|
||||
@@ -662,7 +685,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;
|
||||
@@ -698,6 +721,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;
|
||||
@@ -760,7 +784,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
//stripping logs
|
||||
// Log stripping alerts
|
||||
@EventHandler
|
||||
public void onLogStrip(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
@@ -811,6 +835,10 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
/*
|
||||
CoreProtect API
|
||||
*/
|
||||
|
||||
private CoreProtectAPI getCoreProtect() {
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin("CoreProtect");
|
||||
|
||||
|
||||
@@ -25,4 +25,4 @@ public class GriefAlertEvent extends Event {
|
||||
public String getAlert() {
|
||||
return this.alert;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package net.ardakaz.griefalert;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
//EssentialsX import
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.events.JailStatusChangeEvent;
|
||||
|
||||
|
||||
public class JailListener implements Listener{
|
||||
|
||||
@EventHandler
|
||||
//if someone gets jailed/unjailed this triggers
|
||||
public void onJailToggle(JailStatusChangeEvent event){
|
||||
//getValue = boolean jailed getAffected = gets user
|
||||
boolean jailed = event.getValue();
|
||||
IUser player = event.getAffected();
|
||||
|
||||
//if someone is jailed
|
||||
if(jailed){
|
||||
System.out.println(player + "got Jailed");
|
||||
//else
|
||||
} else{
|
||||
System.out.println(player + "got unjailed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
# Ignore all stealing?
|
||||
allow-stealing: false
|
||||
|
||||
jdbc-url: ""
|
||||
|
||||
# Breaking these blocks don't cause alerts. (Material)
|
||||
excluded-blocks:
|
||||
- WHEAT
|
||||
|
||||
Reference in New Issue
Block a user