4 Commits
0.6 ... ban

Author SHA1 Message Date
ThePindabaas
5d09b0ac13 add essentialsx 2026-07-03 17:21:59 +02:00
urtypicalblahajlunatic
8edf94d96b Ban Listener 2026-07-03 16:48:37 +02:00
urtypicalblahajlunatic
1ada53c51e did a quicky mute thingamahig 2026-07-02 14:50:50 +02:00
urtypicalblahajlunatic
17aacd7ee7 i think this update should add jail Listenerthat works? 2026-07-02 00:00:06 +02:00
10 changed files with 206 additions and 127 deletions

View File

@@ -1,16 +0,0 @@
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

View File

@@ -1,19 +0,0 @@
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

@@ -16,11 +16,16 @@ repositories{
name = "core-protect" name = "core-protect"
url = "https://maven.playpro.com/" url = "https://maven.playpro.com/"
} }
maven {
name = "essentialsX"
url = "https://repo.essentialsx.net/releases/"
}
} }
dependencies { dependencies {
compileOnly "io.papermc.paper:paper-api:26.1.2.build.72-stable" compileOnly "io.papermc.paper:paper-api:26.1.2.build.72-stable"
compileOnly "net.coreprotect:coreprotect:23.2" compileOnly "net.coreprotect:coreprotect:23.2"
compileOnly "net.essentialsx:EssentialsX:2.21.2"
testImplementation(platform('org.junit:junit-bom:5.10.5')) testImplementation(platform('org.junit:junit-bom:5.10.5'))
testImplementation('org.junit.jupiter:junit-jupiter') testImplementation('org.junit.jupiter:junit-jupiter')

View File

@@ -41,6 +41,7 @@ import java.util.stream.Collectors;
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;
@@ -49,10 +50,6 @@ public class GriefAlert extends JavaPlugin implements Listener {
private Boolean ALLOW_STEALING; private Boolean ALLOW_STEALING;
private Connection connection; private Connection connection;
/*
UTILITY FUNCTIONS
*/
// Block inspector: only the most recent placement counts for ownership. // Block inspector: only the most recent placement counts for ownership.
private static String inspectBlock(Block block, Player player) { private static String inspectBlock(Block block, Player player) {
List<String[]> lookup = coreProtectAPI.blockLookup(block, 50000000); List<String[]> lookup = coreProtectAPI.blockLookup(block, 50000000);
@@ -73,7 +70,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
} }
} }
// If we see a break before a placement, stop (block is gone) // If we see a break before a placement, stop (block is gone)
if (parseResult.getActionId() == 0 && !parseResult.isRolledBack()) { if (parseResult.getActionId() == 0) {
break; break;
} }
} }
@@ -93,69 +90,9 @@ public class GriefAlert extends JavaPlugin implements Listener {
return world; 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 // 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.");
@@ -164,6 +101,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
} }
getServer().getPluginManager().registerEvents(this, this); getServer().getPluginManager().registerEvents(this, this);
getServer().getPluginManager().registerEvents(new GriefAlertBan(), this);
// Config // Config
saveDefaultConfig(); saveDefaultConfig();
@@ -193,22 +131,16 @@ public class GriefAlert extends JavaPlugin implements Listener {
} }
private void setupDatabase() { private void setupDatabase() {
String jdbcUrl = getConfig().getString("jdbc-url");
try { try {
connection = DriverManager.getConnection(jdbcUrl); connection = DriverManager.getConnection("jdbc:sqlite:" + getDataFolder().getAbsolutePath() + "/" + DB_FILE);
Statement stmt = connection.createStatement(); 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("CREATE TABLE IF NOT EXISTS ignored_locations (x INTEGER, y INTEGER, z INTEGER, world TEXT, PRIMARY KEY (x, y, z, world))");
stmt.close(); stmt.close();
getLogger().info("Connected to "+jdbcUrl);
} catch (SQLException e) { } catch (SQLException e) {
getLogger().severe("Could not set up SQLite database: " + e.getMessage()); getLogger().severe("Could not set up SQLite database: " + e.getMessage());
} }
} }
/*
LOCATION IGNORING
*/
private boolean isLocationIgnored(int x, int y, int z, String world) { private boolean isLocationIgnored(int x, int y, int z, String world) {
try { try {
PreparedStatement ps = connection.prepareStatement("SELECT 1 FROM ignored_locations WHERE x=? AND y=? AND z=? AND world=?"); PreparedStatement ps = connection.prepareStatement("SELECT 1 FROM ignored_locations WHERE x=? AND y=? AND z=? AND world=?");
@@ -259,10 +191,6 @@ public class GriefAlert extends JavaPlugin implements Listener {
} }
} }
/*
EVENT LISTENERS
*/
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
// Block break alerts // Block break alerts
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
@@ -408,7 +336,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
} }
} }
// Placing item to an item frame //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;
@@ -442,7 +370,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
} }
} }
// Item frame stealing alerts // 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;
@@ -470,7 +398,6 @@ 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);
} }
// Item frame breaking alerts
@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;
@@ -496,7 +423,6 @@ public class GriefAlert extends JavaPlugin implements Listener {
} }
// Command handler
@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;
@@ -658,6 +584,57 @@ public class GriefAlert extends JavaPlugin implements Listener {
return null; 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) //pet alert(dog and cat only)
@EventHandler @EventHandler
public void onPetKill(EntityDeathEvent event) { public void onPetKill(EntityDeathEvent event) {
@@ -685,7 +662,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
} }
// Mob killing alerts //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;
@@ -721,7 +698,6 @@ public class GriefAlert extends JavaPlugin implements Listener {
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 */
// Waxing/unwaxing alerts
@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;
@@ -784,7 +760,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
}, 1L); }, 1L);
} }
// Log stripping alerts //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;
@@ -835,10 +811,6 @@ public class GriefAlert extends JavaPlugin implements Listener {
}, 1L); }, 1L);
} }
/*
CoreProtect API
*/
private CoreProtectAPI getCoreProtect() { private CoreProtectAPI getCoreProtect() {
Plugin plugin = getServer().getPluginManager().getPlugin("CoreProtect"); Plugin plugin = getServer().getPluginManager().getPlugin("CoreProtect");

View File

@@ -0,0 +1,76 @@
package net.ardakaz.griefalert;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.*;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.plugin.java.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import java.util.Arrays;
public class GriefAlertBan extends JavaPlugin implements Listener {
@EventHandler
public void onBanCommand(PlayerCommandPreprocessEvent event){
String message = event.getMessage();
String[] syl = message.split(" ");
String Banner = event.getPlayer().getName();
if(syl.length >=2 && syl[0].equalsIgnoreCase("/ban")){
String BannedPlayer = syl[1];
String BanReason = String.join(" ", Arrays.copyOfRange(syl, 2, syl.length));
System.out.println(Banner + " banned" + BannedPlayer + " for " + BanReason);
//player must be online for /ipban to actualy do stuff but whatever
} else if(syl.length >= 3 && syl[0].equalsIgnoreCase("/tempban")){
String BannedPlayer = syl[1];
String time = syl[2];
String BanReason = String.join(" ", Arrays.copyOfRange(syl, 3, syl.length));
System.out.println(Banner + " banned " + BannedPlayer + " for " + time + " for " + BanReason);
}else if(syl.length >= 2 && syl[0].equalsIgnoreCase("/ipban")){
String BannedPlayer = syl[1];
Player player = Bukkit.getPlayerExact(BannedPlayer);
String BanReason = String.join(" ", Arrays.copyOfRange(syl, 2, syl.length));
if(!(player == null)){
String ip = player.getAddress().getAddress().getHostAddress();
System.out.println(Banner + " banned " + ip + " for " + BanReason);
} else System.out.println("unexpected error, ip maybe not finded? ");
}
}
@EventHandler
public void onConsoleCommand(ServerCommandEvent event){
String message = event.getCommand();
String[] syl = message.split(" ");
if(syl.length >=2 && syl[0].equalsIgnoreCase("/ban")){
String BannedPlayer = syl[1];
String BanReason = String.join(" ", Arrays.copyOfRange(syl, 2, syl.length));
System.out.println("console " + " banned" + BannedPlayer + " for " + BanReason);
//player must be online for /ipban to actualy do stuff but whatever
} else if(syl.length >= 3 && syl[0].equalsIgnoreCase("/tempban")){
String BannedPlayer = syl[1];
String time = syl[2];
String banReason = String.join(" ", Arrays.copyOfRange(syl, 3, syl.length));
System.out.println("console " + " banned " + BannedPlayer + " for " + time + " for " + banReason);
}else if(syl.length >= 2 && syl[0].equalsIgnoreCase("/ipban")){
String BannedPlayer = syl[1];
Player player = Bukkit.getPlayerExact(BannedPlayer);
if(!(player == null)){
String ip = player.getAddress().getAddress().getHostAddress();
}
}
}
}

View File

@@ -0,0 +1,30 @@
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");
}
}
}

View File

@@ -0,0 +1,23 @@
package net.ardakaz.griefalert;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import net.ess3.api.IUser;
import net.ess3.api.events.MuteStatusChangeEvent;
public class MuteListener {
@EventHandler
public void onMuteChange(MuteStatusChangeEvent event){
boolean muted = event.getValue();
IUser player = event.getAffected();
if(muted){
System.out.println("blergh");
} else{
System.out.println("not blergh");
}
}
}

View File

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

View File

@@ -2,7 +2,7 @@ name: GriefAlert
main: net.ardakaz.griefalert.GriefAlert main: net.ardakaz.griefalert.GriefAlert
version: 0.6 version: 0.6
api-version: 1.21 api-version: 1.21
depends: [CoreProtect] depends: [CoreProtect] [EssentialsX]
softdepend: [DiscordSRV] softdepend: [DiscordSRV]
description: A simple grief alert plugin using the CoreProtect API. description: A simple grief alert plugin using the CoreProtect API.
authors: [Ardakaz, kleedje30] authors: [Ardakaz, kleedje30]
@@ -12,3 +12,13 @@ commands:
usage: /griefalert <ignore|unignore|check> usage: /griefalert <ignore|unignore|check>
permission: griefalert.staff permission: griefalert.staff
permission-message: You do not have permission to use this command. permission-message: You do not have permission to use this command.
ban:
description: GriefAlert Ban command
usage: /ban <user> <reason>
permission: griefalert.staff
permission-message: you do not have authority to use this command.
tempban:
description: temporary /ban
usage: /tempban <user> <time> <reason>
permission: griefalert.staff
permission-message: you do not have the authority to use this command.