Added hidden "exclude-tnt" rollback option to exclude TNT blocks (default: false)

This commit is contained in:
Intelli 2022-03-07 16:39:21 -07:00
parent 2b96daa422
commit 02dcc873d6
9 changed files with 68 additions and 41 deletions

View File

@ -3,8 +3,10 @@ package net.coreprotect;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -147,17 +149,17 @@ public class CoreProtectAPI extends Queue {
}
}
private static List<Object> parseList(List<Object> list) {
List<Object> result = new ArrayList<>();
private static Map<Object, Boolean> parseList(List<Object> list) {
Map<Object, Boolean> result = new HashMap<>();
if (list != null) {
for (Object value : list) {
if (value instanceof Material || value instanceof EntityType) {
result.add(value);
result.put(value, false);
}
else if (value instanceof Integer) {
Material material = Util.getType((Integer) value);
result.add(material);
result.put(material, false);
}
}
}
@ -417,7 +419,7 @@ public class CoreProtectAPI extends Queue {
return null;
}
private List<String[]> processData(int time, int radius, Location location, List<Object> restrictBlocks, List<Object> excludeBlocks, List<String> restrictUsers, List<String> excludeUsers, List<Integer> actionList, int action, int lookup, int offset, int rowCount, boolean useLimit) {
private List<String[]> processData(int time, int radius, Location location, Map<Object, Boolean> restrictBlocksMap, Map<Object, Boolean> excludeBlocks, List<String> restrictUsers, List<String> excludeUsers, List<Integer> actionList, int action, int lookup, int offset, int rowCount, boolean useLimit) {
// You need to either specify time/radius or time/user
List<String[]> result = new ArrayList<>();
List<String> uuids = new ArrayList<>();
@ -434,6 +436,7 @@ public class CoreProtectAPI extends Queue {
actionList = new ArrayList<>();
}
List<Object> restrictBlocks = new ArrayList<>(restrictBlocksMap.keySet());
if (actionList.size() == 0 && restrictBlocks.size() > 0) {
boolean addedMaterial = false;
boolean addedEntity = false;
@ -530,7 +533,7 @@ public class CoreProtectAPI extends Queue {
}
@Deprecated
private List<String[]> processData(String user, int time, int radius, Location location, List<Object> restrictBlocks, List<Object> excludeBlocks, int action, int lookup, int offset, int rowCount, boolean useLimit) {
private List<String[]> processData(String user, int time, int radius, Location location, Map<Object, Boolean> restrictBlocks, Map<Object, Boolean> excludeBlocks, int action, int lookup, int offset, int rowCount, boolean useLimit) {
ArrayList<String> restrictUsers = new ArrayList<>();
if (user != null) {
restrictUsers.add(user);

View File

@ -3,8 +3,10 @@ package net.coreprotect.command;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -255,9 +257,9 @@ public class CommandHandler implements CommandExecutor {
return result;
}
protected static List<Object> parseExcluded(CommandSender player, String[] inputArguments, List<Integer> argAction) {
protected static Map<Object, Boolean> parseExcluded(CommandSender player, String[] inputArguments, List<Integer> argAction) {
String[] argumentArray = inputArguments.clone();
List<Object> excluded = new ArrayList<>();
Map<Object, Boolean> excluded = new HashMap<>();
int count = 0;
int next = 0;
for (String argument : argumentArray) {
@ -276,20 +278,22 @@ public class CommandHandler implements CommandExecutor {
String[] i2 = argument.split(",");
for (String i3 : i2) {
if (i3.equals("#natural")) {
excluded.addAll(naturalBlocks);
for (Material block : naturalBlocks) {
excluded.put(block, false);
}
}
else {
Material i3_material = Util.getType(i3);
if (i3_material != null && (i3_material.isBlock() || argAction.contains(4))) {
excluded.add(i3_material);
excluded.put(i3_material, false);
}
else {
EntityType i3_entity = Util.getEntityType(i3);
if (i3_entity != null) {
excluded.add(i3_entity);
excluded.put(i3_entity, false);
}
else if (i3_material != null) {
excluded.add(i3_material);
excluded.put(i3_material, false);
}
}
}
@ -303,20 +307,22 @@ public class CommandHandler implements CommandExecutor {
}
else {
if (argument.equals("#natural")) {
excluded.addAll(naturalBlocks);
for (Material block : naturalBlocks) {
excluded.put(block, false);
}
}
else {
Material iMaterial = Util.getType(argument);
if (iMaterial != null && (iMaterial.isBlock() || argAction.contains(4))) {
excluded.add(iMaterial);
excluded.put(iMaterial, false);
}
else {
EntityType iEntity = Util.getEntityType(argument);
if (iEntity != null) {
excluded.add(iEntity);
excluded.put(iEntity, false);
}
else if (iMaterial != null) {
excluded.add(iMaterial);
excluded.put(iMaterial, false);
}
}
}

View File

@ -6,6 +6,7 @@ import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -49,7 +50,7 @@ public class LookupCommand {
int argNoisy = CommandHandler.parseNoisy(args);
List<Integer> argAction = CommandHandler.parseAction(args);
List<Object> argBlocks = CommandHandler.parseRestricted(player, args, argAction);
List<Object> argExclude = CommandHandler.parseExcluded(player, args, argAction);
Map<Object, Boolean> argExclude = CommandHandler.parseExcluded(player, args, argAction);
List<String> argExcludeUsers = CommandHandler.parseExcludedUsers(player, args);
String ts = CommandHandler.parseTimeString(args);
long[] argTime = CommandHandler.parseTime(args);
@ -94,7 +95,7 @@ public class LookupCommand {
}
/* check for invalid block/entity combinations (exclude) */
for (Object arg : argExclude) {
for (Object arg : argExclude.keySet()) {
if (arg instanceof Material) {
hasBlock = true;
}
@ -266,9 +267,9 @@ public class LookupCommand {
}
if (argAction.contains(4) && argAction.contains(11)) { // a:inventory
argExclude.add(Material.FIRE);
argExclude.add(Material.WATER);
argExclude.add(Material.FARMLAND);
argExclude.put(Material.FIRE, false);
argExclude.put(Material.WATER, false);
argExclude.put(Material.FARMLAND, false);
argExcludeUsers.add("#hopper");
}
@ -695,7 +696,7 @@ public class LookupCommand {
final int restricted = argRestricted;
// final List<String> uuid_list = arg_uuids;
final List<Object> blist = argBlocks;
final List<Object> elist = argExclude;
final Map<Object, Boolean> elist = argExclude;
final List<String> euserlist = argExcludeUsers;
final int page = pa;
final int displayResults = re;

View File

@ -5,6 +5,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -39,7 +40,7 @@ public class RollbackRestoreCommand {
int argNoisy = CommandHandler.parseNoisy(args);
List<Integer> argAction = CommandHandler.parseAction(args);
List<Object> argBlocks = CommandHandler.parseRestricted(player, args, argAction);
List<Object> argExclude = CommandHandler.parseExcluded(player, args, argAction);
Map<Object, Boolean> argExclude = CommandHandler.parseExcluded(player, args, argAction);
List<String> argExcludeUsers = CommandHandler.parseExcludedUsers(player, args);
String ts = CommandHandler.parseTimeString(args);
long[] argTime = CommandHandler.parseTime(args);
@ -76,7 +77,7 @@ public class RollbackRestoreCommand {
}
/* check for invalid block/entity combinations (exclude) */
for (Object arg : argExclude) {
for (Object arg : argExclude.keySet()) {
if (arg instanceof Material) {
hasBlock = true;
}
@ -186,11 +187,14 @@ public class RollbackRestoreCommand {
return;
}
argExclude.add(Material.FIRE);
argExclude.add(Material.WATER);
argExclude.add(Material.FARMLAND);
argExclude.put(Material.FIRE, false);
argExclude.put(Material.WATER, false);
argExclude.put(Material.FARMLAND, false);
argExcludeUsers.add("#hopper");
}
else if (!argAction.contains(4) && Config.getGlobal().EXCLUDE_TNT && !argExclude.containsKey(Material.TNT) && !argBlocks.contains(Material.TNT)) {
argExclude.put(Material.TNT, true);
}
if (g == 1 && (argUsers.size() > 0 || (argUsers.size() == 0 && argRadius != null))) {
Integer MAX_RADIUS = Config.getGlobal().MAX_RADIUS;
@ -329,7 +333,7 @@ public class RollbackRestoreCommand {
final String rtime = ts;
final List<String> uuidList = argUuids;
final List<Object> blist = argBlocks;
final List<Object> elist = argExclude;
final Map<Object, Boolean> elist = argExclude;
final List<String> euserlist = argExcludeUsers;
final Location locationFinal = lo;
final int finalArgWid = argWid;

View File

@ -46,6 +46,7 @@ public class Config extends Language {
public boolean DATABASE_LOCK;
public boolean LOG_CANCELLED_CHAT;
public boolean HOPPER_FILTER_META;
public boolean EXCLUDE_TNT;
public boolean MYSQL;
public boolean CHECK_UPDATES;
public boolean API_ENABLED;
@ -185,6 +186,7 @@ public class Config extends Language {
this.DATABASE_LOCK = this.getBoolean("database-lock", true);
this.LOG_CANCELLED_CHAT = this.getBoolean("log-cancelled-chat", true);
this.HOPPER_FILTER_META = this.getBoolean("hopper-filter-meta", false);
this.EXCLUDE_TNT = this.getBoolean("exclude-tnt", false);
this.DONATION_KEY = this.getString("donation-key");
this.MYSQL = this.getBoolean("use-mysql");
this.PREFIX = this.getString("table-prefix");

View File

@ -105,7 +105,7 @@ public class ConfigHandler extends Queue {
public static Map<String, Integer> lookupPage = syncMap();
public static Map<String, String> lookupCommand = syncMap();
public static Map<String, List<Object>> lookupBlist = syncMap();
public static Map<String, List<Object>> lookupElist = syncMap();
public static Map<String, Map<Object, Boolean>> lookupElist = syncMap();
public static Map<String, List<String>> lookupEUserlist = syncMap();
public static Map<String, List<String>> lookupUlist = syncMap();
public static Map<String, List<Integer>> lookupAlist = syncMap();

View File

@ -4,6 +4,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -28,7 +29,7 @@ import net.coreprotect.utility.Util;
public class ContainerRollback extends Queue {
public static void performContainerRollbackRestore(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, String timeString, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, final Location location, Integer[] radius, long startTime, long endTime, boolean restrictWorld, boolean lookup, boolean verbose, final int rollbackType) {
public static void performContainerRollbackRestore(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, String timeString, List<Object> restrictList, Map<Object, Boolean> excludeList, List<String> excludeUserList, List<Integer> actionList, final Location location, Integer[] radius, long startTime, long endTime, boolean restrictWorld, boolean lookup, boolean verbose, final int rollbackType) {
try {
long timeStart = System.currentTimeMillis();

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
@ -75,7 +76,7 @@ public class Lookup extends Queue {
return newList;
}
public static long countLookupRows(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long startTime, long endTime, boolean restrictWorld, boolean lookup) {
public static long countLookupRows(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, Map<Object, Boolean> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long startTime, long endTime, boolean restrictWorld, boolean lookup) {
Long rows = 0L;
try {
@ -102,7 +103,7 @@ public class Lookup extends Queue {
return rows;
}
public static List<String[]> performLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long startTime, long endTime, boolean restrictWorld, boolean lookup) {
public static List<String[]> performLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, Map<Object, Boolean> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long startTime, long endTime, boolean restrictWorld, boolean lookup) {
List<String[]> newList = new ArrayList<>();
try {
@ -116,7 +117,7 @@ public class Lookup extends Queue {
return newList;
}
static List<Object[]> performLookupRaw(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long startTime, long endTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
static List<Object[]> performLookupRaw(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, Map<Object, Boolean> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long startTime, long endTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
List<Object[]> list = new ArrayList<>();
List<Integer> invalidRollbackActions = new ArrayList<>();
invalidRollbackActions.add(2);
@ -272,7 +273,7 @@ public class Lookup extends Queue {
return list;
}
public static List<String[]> performPartialLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long startTime, long endTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
public static List<String[]> performPartialLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, Map<Object, Boolean> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long startTime, long endTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
List<String[]> newList = new ArrayList<>();
try {
@ -286,7 +287,7 @@ public class Lookup extends Queue {
return newList;
}
private static ResultSet rawLookupResultSet(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long startTime, long endTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup, boolean count) {
private static ResultSet rawLookupResultSet(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, Map<Object, Boolean> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long startTime, long endTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup, boolean count) {
ResultSet results = null;
try {
@ -391,7 +392,7 @@ public class Lookup extends Queue {
StringBuilder excludeListMaterial = new StringBuilder();
StringBuilder excludeListEntity = new StringBuilder();
for (Object restrictTarget : excludeList) {
for (Object restrictTarget : excludeList.keySet()) {
String targetName = "";
if (restrictTarget instanceof Material) {

View File

@ -95,7 +95,7 @@ import net.coreprotect.utility.entity.HangingUtil;
public class Rollback extends Queue {
public static List<String[]> performRollbackRestore(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, String timeString, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long startTime, long endTime, boolean restrictWorld, boolean lookup, boolean verbose, final int rollbackType, final int preview) {
public static List<String[]> performRollbackRestore(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, String timeString, List<Object> restrictList, Map<Object, Boolean> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long startTime, long endTime, boolean restrictWorld, boolean lookup, boolean verbose, final int rollbackType, final int preview) {
List<String[]> list = new ArrayList<>();
try {
@ -112,12 +112,12 @@ public class Rollback extends Queue {
boolean ROLLBACK_ITEMS = false;
List<Object> itemRestrictList = new ArrayList<>(restrictList);
List<Object> itemExcludeList = new ArrayList<>(excludeList);
Map<Object, Boolean> itemExcludeList = new HashMap<>(excludeList);
if (actionList.contains(1)) {
for (Object target : restrictList) {
if (target instanceof Material) {
if (!excludeList.contains(target)) {
if (!excludeList.containsKey(target)) {
if (BlockGroup.CONTAINERS.contains(target)) {
ROLLBACK_ITEMS = true;
itemRestrictList.clear();
@ -137,6 +137,7 @@ public class Rollback extends Queue {
itemActionList.add(4);
}
itemExcludeList.entrySet().removeIf(entry -> Boolean.TRUE.equals(entry.getValue()));
itemList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, itemRestrictList, itemExcludeList, excludeUserList, itemActionList, location, radius, null, startTime, endTime, -1, -1, restrictWorld, lookup);
}
@ -1277,7 +1278,7 @@ public class Rollback extends Queue {
return null;
}
static void finishRollbackRestore(CommandSender user, Location location, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, String timeString, Integer chunkCount, Double seconds, Integer itemCount, Integer blockCount, Integer entityCount, int rollbackType, Integer[] radius, boolean verbose, boolean restrictWorld, int preview) {
static void finishRollbackRestore(CommandSender user, Location location, List<String> checkUsers, List<Object> restrictList, Map<Object, Boolean> excludeList, List<String> excludeUserList, List<Integer> actionList, String timeString, Integer chunkCount, Double seconds, Integer itemCount, Integer blockCount, Integer entityCount, int rollbackType, Integer[] radius, boolean verbose, boolean restrictWorld, int preview) {
try {
if (preview == 2) {
Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.PREVIEW_CANCELLED));
@ -1418,7 +1419,15 @@ public class Rollback extends Queue {
boolean entity = false;
int excludeCount = 0;
for (Object excludeTarget : excludeList) {
for (Map.Entry<Object, Boolean> entry : excludeList.entrySet()) {
Object excludeTarget = entry.getKey();
Boolean excludeTargetInternal = entry.getValue();
// don't display default block excludes
if (Boolean.TRUE.equals(excludeTargetInternal)) {
continue;
}
// don't display that excluded water/fire/farmland in inventory rollbacks
if (actionList.contains(4) && actionList.contains(11)) {
if (excludeTarget.equals(Material.FIRE) || excludeTarget.equals(Material.WATER) || excludeTarget.equals(Material.FARMLAND)) {