Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,34 @@ Secondary configuration files override the value specified in config.yml. If you
To disable logging for specific users, blocks or commands, simply do the following:

1. In the CoreProtect plugin directory, create a file named `blacklist.txt`.
2. Enter the names of the users (or commands) you'd like to disable logging for (each username on a new line).
2. Enter the names of the users, commands, blocks, or entities you'd like to disable logging for (each usentry ername on a new line).
3. Either restart your server, or type "/co reload" in-game.

This can be used to disable logging for non-player users, such as "#creeper". For example, if you'd like to disable logging for the user "Notch", TNT explosions, stone blocks, and the "/help" command, the blacklist.txt file would look like this:
The blacklist supports disabling logs for:
- Users, which includes Players and non-player users, such as "#creeper"
- Commands, such as `/help`
- Blocks, such as minecraft:stone. Only `block` actions are affected.
- Entities, such as minecraft:creeper. *Note: renamed entities will be logged even if blacklisted.*
- Filters can also be specified for a particular user, by use of the @ symbol after the specific item, block, or entity namespaced ID. The format is `id @ user`. This will filter the `block`, `kill`, `item` and `container` actions.

*Please note that you must include the namespace (e.g. minecraft:) for blocks, entities and items.*

All blacklist entries are case-insensitive and ignore spaces.


An example blacklist.txt file would look like this:

```text
Notch
#tnt
#creeper
/help
minecraft:stone
minecraft:creeper
minecraft:shears@#dispenser
```

*Please note that to disable logging for blocks, CoreProtect v23+ is required, and you must include the namespace. For example, to disable logging for dirt, you must add it as "minecraft:dirt".*
Comments can be added with the `%` at the start of a line.

*Please note that to disable logging for blocks, CoreProtect v23+ is required.*
*To disable logging for item pickups, entities CoreProtect v23.4+ is required.*
*To enable more complex per user filters, CoreProtect v23.4+ is required.*
3 changes: 2 additions & 1 deletion src/main/java/net/coreprotect/CoreProtect.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void onEnable() {
advancedChestsEnabled = getServer().getPluginManager().getPlugin("AdvancedChests") != null;
// Initialize plugin using the initialization service
boolean initialized = PluginInitializationService.initializePlugin(this);

// Initialize blacklist.txt file
this.saveResource("blacklist.txt", false);
// Disable plugin if initialization failed
if (!initialized) {
Chat.console(Phrase.build(Phrase.ENABLE_FAILED, ConfigHandler.EDITION_NAME));
Expand Down
53 changes: 42 additions & 11 deletions src/main/java/net/coreprotect/config/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -100,6 +101,7 @@ private static <K, V> Map<K, V> syncMap() {
public static Map<String, int[]> rollbackHash = syncMap();
public static Map<String, Boolean> inspecting = syncMap();
public static Map<String, Boolean> blacklist = syncMap();
public static Map<String, HashSet<String>> FilteredBlacklist = syncMap();
public static Map<String, Integer> loggingChest = syncMap();
public static Map<String, Integer> loggingItem = syncMap();
public static ConcurrentHashMap<String, List<Object>> transactingChest = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -152,23 +154,52 @@ public static void checkPlayers(Connection connection) {
}
}

public static boolean isBlacklisted(String user){
return ConfigHandler.blacklist.containsKey(user.toLowerCase(Locale.ROOT));
}

public static boolean isBlacklisted(String user, String object){
if (ConfigHandler.blacklist.containsKey(object) || ConfigHandler.blacklist.containsKey(user.toLowerCase(Locale.ROOT))){
return true;
}
return isFilterBlacklisted(user, object);
}

public static boolean isFilterBlacklisted(String user, String object){
HashSet <String> blUserSet = FilteredBlacklist.get(object);
if (blUserSet == null){
return false;
}
return blUserSet.contains(user.toLowerCase(Locale.ROOT));
}

private static void loadBlacklist() {
try {
ConfigHandler.blacklist.clear();
ConfigHandler.FilteredBlacklist.clear();
String blacklist = ConfigHandler.path + "blacklist.txt";
boolean exists = (new File(blacklist)).exists();
if (exists) {
RandomAccessFile blfile = new RandomAccessFile(blacklist, "rw");
long blc = blfile.length();
if (blc > 0) {
while (blfile.getFilePointer() < blfile.length()) {
String blacklistUser = blfile.readLine().replaceAll(" ", "").toLowerCase(Locale.ROOT);
if (blacklistUser.length() > 0) {
ConfigHandler.blacklist.put(blacklistUser, true);
}
if (!(new File(blacklist)).exists()){
return;
}
try (RandomAccessFile blfile = new RandomAccessFile(blacklist, "r")){
if (blfile.length() == 0){
return;
}
String blLine;
while (( blLine = blfile.readLine()) != null ) {
blLine = blLine.replace(" ", "").toLowerCase(Locale.ROOT);
if (blLine.isEmpty() || blLine.startsWith("%")) {
continue;
}
String[] blSplit = blLine.split("@");
if (blSplit.length == 1){
ConfigHandler.blacklist.put(blLine, true);
} else {
ConfigHandler.FilteredBlacklist.
computeIfAbsent(blSplit[0], k-> new HashSet<>())
.add(blSplit[1]);
}
}
blfile.close();
}
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ private BlockBreakLogger() {

public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int type, int data, List<Object> meta, String blockData, String overrideData) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || location == null) {
return;
}

Material checkType = net.coreprotect.utility.MaterialUtils.getType(type);
if (checkType == null) {
return;
Expand All @@ -38,7 +34,7 @@ else if (checkType.equals(Material.AIR) || checkType.equals(Material.CAVE_AIR))
return;
}

if (ConfigHandler.blacklist.get(checkType.getKey().toString()) != null) {
if (ConfigHandler.isBlacklisted(user, checkType.getKey().toString())) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ private BlockPlaceLogger() {

public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block, int replacedType, int replacedData, Material forceType, int forceData, boolean force, List<Object> meta, String blockData, String replaceBlockData) {
try {
if (user == null || ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
return;
}

Material type = block.getType();
if (blockData == null && (forceType == null || (!forceType.equals(Material.WATER)) && (!forceType.equals(Material.LAVA)))) {
blockData = block.getBlockData().getAsString();
Expand All @@ -58,7 +54,7 @@ else if (forceType != null && !type.equals(forceType)) {
return;
}

if (ConfigHandler.blacklist.get(type.getKey().toString()) != null) {
if (ConfigHandler.isBlacklisted(user, type.getKey().toString())){
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private ChatLogger() {

public static void log(PreparedStatement preparedStmt, int batchCount, long time, Location location, String user, String message) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(user)) {
return;
}
int x = location.getBlockX();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ private CommandLogger() {

public static void log(PreparedStatement preparedStmt, int batchCount, long time, Location location, String user, String message) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(user)) {
return;
}
if (ConfigHandler.blacklist.get(((message + " ").split(" "))[0].toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(((message + " ").split(" "))[0])) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ else if (item != null) {

protected static void logTransaction(PreparedStatement preparedStmt, int batchCount, String user, Material type, String faceData, ItemStack[] items, int action, Location location) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(user)) {
return;
}
boolean success = false;
Expand All @@ -218,6 +218,10 @@ protected static void logTransaction(PreparedStatement preparedStmt, int batchCo
if (item != null) {
if (item.getAmount() > 0 && !BlockUtils.isAir(item.getType())) {
// Object[] metadata = new Object[] { slot, item.getItemMeta() };
if (ConfigHandler.isFilterBlacklisted(user, item.getType().getKey().toString())){
continue;
}

List<List<Map<String, Object>>> metadata = ItemMetaHandler.serialize(item, type, faceData, slot);
if (metadata.size() == 0) {
metadata = null;
Expand All @@ -230,7 +234,8 @@ protected static void logTransaction(PreparedStatement preparedStmt, int batchCo

if (event.isCancelled()) {
return;
}
}


int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
Location eventLocation = event.getLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.Locale;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.BlockState;
import org.bukkit.entity.EntityType;

import net.coreprotect.CoreProtect;
import net.coreprotect.config.Config;
Expand All @@ -27,7 +27,18 @@ private EntityKillLogger() {

public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block, List<Object> data, int type) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(user)){
return;
}

EntityType checkType = net.coreprotect.utility.EntityUtils.getEntityType(type);
if (checkType == null) {
return;
}
// Ignore blacklist if the entity has a custom name
// data[4] contains custom name data
if (ConfigHandler.isBlacklisted(user, checkType.getKey().toString()) &&
!(data.size() > 4 && data.get(4) != null)){
return;
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/coreprotect/database/logger/ItemLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private ItemLogger() {

public static void log(PreparedStatement preparedStmt, int batchCount, Location location, int offset, String user) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(user)) {
return;
}

Expand Down Expand Up @@ -124,6 +124,10 @@ protected static void logTransaction(PreparedStatement preparedStmt, int batchCo
for (ItemStack item : items) {
if (item != null && item.getAmount() > 0 && !BlockUtils.isAir(item.getType())) {
// Object[] metadata = new Object[] { slot, item.getItemMeta() };
if (ConfigHandler.isFilterBlacklisted(user, item.getType().getKey().toString())){
continue;
}

List<List<Map<String, Object>>> data = ItemMetaHandler.serialize(item, null, null, 0);
if (data.size() == 0) {
data = null;
Expand All @@ -137,7 +141,7 @@ protected static void logTransaction(PreparedStatement preparedStmt, int batchCo
if (event.isCancelled()) {
return;
}

int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
Location eventLocation = event.getLocation();
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private PlayerInteractLogger() {
public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block, Material blockType) {
try {
int type = MaterialUtils.getBlockId(blockType.name(), true);
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || MaterialUtils.getType(type).equals(Material.AIR) || MaterialUtils.getType(type).equals(Material.CAVE_AIR)) {
if (ConfigHandler.isBlacklisted(user) || MaterialUtils.getType(type).equals(Material.AIR) || MaterialUtils.getType(type).equals(Material.CAVE_AIR)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private PlayerKillLogger() {

public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block, String player) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(user)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private PlayerSessionLogger() {

public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int time, int action) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(user)) {
return;
}
int x = location.getBlockX();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private SignTextLogger() {

public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int action, int color, int colorSecondary, int data, boolean isWaxed, boolean isFront, String line1, String line2, String line3, String line4, String line5, String line6, String line7, String line8, int timeOffset) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(user)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private SkullBreakLogger() {

public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || block == null) {
if (ConfigHandler.isBlacklisted(user) || block == null) {
return;
}
int time = (int) (System.currentTimeMillis() / 1000L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private SkullPlaceLogger() {

public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block, int replaceType, int replaceData) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || block == null) {
if (ConfigHandler.isBlacklisted(user) || block == null) {
return;
}
int time = (int) (System.currentTimeMillis() / 1000L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private UsernameLogger() {

public static void log(Connection connection, String user, String uuid, int configUsernames, int time) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
if (ConfigHandler.isBlacklisted(user)) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/blacklist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
% For more information, visit https://docs.coreprotect.net/config/

% Notch
% #creeper
% /help