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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<artifactId>CoreProtect</artifactId>
<version>23.1</version>
<properties>
<project.branch></project.branch>
<project.branch>development</project.branch>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/net/coreprotect/command/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,20 @@ protected static List<String> parseUsers(String[] inputArguments) {
return UserParser.parseUsers(inputArguments);
}

/**
* Parse message filter from command arguments (m:, msg:, message:)
*
* @param inputArguments
* The command arguments
* @return The message filter string, or empty string if not present
*/
protected static String parseMessageFilter(String[] inputArguments) {
return ActionParser.parseMessageFilter(inputArguments);
}

/**
* Helper method for formatting BigDecimal values
*
*
* @param input
* The BigDecimal value to format
* @return The formatted string
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/net/coreprotect/command/LookupCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,598 +28,607 @@
import net.coreprotect.utility.WorldUtils;

public class LookupCommand {
public static void runCommand(CommandSender player, Command command, boolean permission, String[] args) {
int resultc = args.length;
args = CommandParser.parsePage(args);
Location lo = CommandParser.parseLocation(player, args);
// List<String> arg_uuids = new ArrayList<String>();
List<String> argUsers = CommandParser.parseUsers(args);
Integer[] argRadius = CommandParser.parseRadius(args, player, lo);
int argNoisy = CommandParser.parseNoisy(args);
List<Integer> argAction = CommandParser.parseAction(args);
List<Object> argBlocks = CommandParser.parseRestricted(player, args, argAction);
Map<Object, Boolean> argExclude = CommandParser.parseExcluded(player, args, argAction);
List<String> argExcludeUsers = CommandParser.parseExcludedUsers(player, args);
String ts = CommandParser.parseTimeString(args);
long[] argTime = CommandParser.parseTime(args);
long startTime = argTime[0];
long endTime = argTime[1];
int argWid = CommandParser.parseWorld(args, true, true);
int parseRows = CommandParser.parseRows(args);
boolean count = CommandParser.parseCount(args);
boolean worldedit = CommandParser.parseWorldEdit(args);
boolean forceglobal = CommandParser.parseForceGlobal(args);
String messageFilter = CommandParser.parseMessageFilter(args);
boolean pageLookup = false;

if (argBlocks == null || argExclude == null || argExcludeUsers == null) {
return;
}

if (args[0].toLowerCase(Locale.ROOT).equals("page") && (args.length != 2 || !args[1].equals(args[1].replaceAll("[^0-9]", "")))) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, Color.WHITE, "/co page <page>"));
return;
}

int argExcluded = argExclude.size();
int argRestricted = argBlocks.size();

/* check for invalid block/entity combinations (include) */
boolean hasBlock = false;
boolean hasEntity = false;
for (Object arg : argBlocks) {
if (arg instanceof Material) {
hasBlock = true;
}
else if (arg instanceof EntityType) {
hasEntity = true;
if (argAction.size() == 0) {
argAction.add(3);
}
else if (!argAction.contains(3)) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_INCLUDE_COMBO));
return;
}
}
}

/* check for invalid block/entity combinations (exclude) */
for (Object arg : argExclude.keySet()) {
if (arg instanceof Material) {
hasBlock = true;
}
else if (arg instanceof EntityType) {
hasEntity = true;
if (argAction.size() == 0) {
argAction.add(3);
}
else if (!argAction.contains(3)) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_INCLUDE_COMBO));
return;
}
}
}

if (hasBlock && hasEntity) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_INCLUDE_COMBO));
return;
}

if (argWid == -1) {
String worldName = CommandParser.parseWorldName(args, true);
Chat.sendMessage(player, new ChatMessage(Phrase.build(Phrase.WORLD_NOT_FOUND, worldName)).build());
return;
}

int type = 0;
if (ConfigHandler.lookupType.get(player.getName()) != null) {
type = ConfigHandler.lookupType.get(player.getName());
}
if (type == 0 && resultc > 1) {
type = 4;
}
else if (resultc > 2) {
type = 4;
}
else if (resultc > 1) {
pageLookup = true;
String dat = args[1];
if (dat.contains(":")) {
String[] split = dat.split(":");
String check1 = split[0].replaceAll("[^a-zA-Z_]", "");
String check2 = "";
if (split.length > 1) {
check2 = split[1].replaceAll("[^a-zA-Z_]", "");
}
if (check1.length() > 0 || check2.length() > 0) {
type = 4;
pageLookup = false;
}
}
else {
String check1 = dat.replaceAll("[^a-zA-Z_]", "");
if (check1.length() > 0) {
type = 4;
pageLookup = false;
}
}
}
if (argAction.contains(6) || argAction.contains(7) || argAction.contains(8) || argAction.contains(9) || argAction.contains(10)) {
pageLookup = true;
}

if (!permission) {
if (!pageLookup || !player.hasPermission("coreprotect.inspect")) {
Chat.sendMessage(player, new ChatMessage(Phrase.build(Phrase.NO_PERMISSION)).build());
return;
}
}
if (ConfigHandler.converterRunning) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.UPGRADE_IN_PROGRESS));
return;
}
if (ConfigHandler.purgeRunning) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.PURGE_IN_PROGRESS));
return;
}
if (resultc < 2) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, "/co l <params>"));
return;
}
if (argAction.contains(-1)) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_ACTION));
return;
}
if (worldedit && argRadius == null) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_SELECTION, "WorldEdit"));
return;
}
if (argRadius != null && argRadius[0] == -1) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_RADIUS));
return;
}
if (ConfigHandler.lookupThrottle.get(player.getName()) != null) {
Object[] lookupThrottle = ConfigHandler.lookupThrottle.get(player.getName());
if ((boolean) lookupThrottle[0] || ((System.currentTimeMillis() - (long) lookupThrottle[1])) < 50) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY));
return;
}
}
boolean allPermission = false;
if (args[0].equals("near") && player.hasPermission("coreprotect.lookup.near")) {
allPermission = true;
}
if (!allPermission) {
if (!pageLookup && (argAction.size() == 0 || (argAction.size() == 1 && (argAction.contains(0) || argAction.contains(1)))) && !player.hasPermission("coreprotect.lookup.block")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(2) && !player.hasPermission("coreprotect.lookup.click")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(3) && !player.hasPermission("coreprotect.lookup.kill")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(4) && !argAction.contains(11) && !player.hasPermission("coreprotect.lookup.container")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(6) && !player.hasPermission("coreprotect.lookup.chat")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(7) && !player.hasPermission("coreprotect.lookup.command")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(8) && !player.hasPermission("coreprotect.lookup.session")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(9) && !player.hasPermission("coreprotect.lookup.username")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(10) && !player.hasPermission("coreprotect.lookup.sign")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(11) && !argAction.contains(4) && !player.hasPermission("coreprotect.lookup.item")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
if (argAction.contains(4) && argAction.contains(11) && !player.hasPermission("coreprotect.lookup.inventory")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
}
if (argAction.contains(6) || argAction.contains(7) || argAction.contains(8) || argAction.contains(9) || argAction.contains(10)) {
if (argAction.contains(9) && (argRadius != null || argWid > 0 || worldedit)) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INCOMPATIBLE_ACTION, "r:"));
return;
}
if (argBlocks.size() > 0) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INCOMPATIBLE_ACTION, "i:"));
return;
}
if (argExclude.size() > 0) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INCOMPATIBLE_ACTION, "e:"));
return;
}
}

if (messageFilter.length() > 0 && !argAction.contains(6) && !argAction.contains(7)) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INCOMPATIBLE_ACTION, "m:"));
return;
}

if (startTime <= 0 && !pageLookup && type == 4 && (argBlocks.size() > 0 || argUsers.size() > 0)) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_LOOKUP_TIME, Selector.FIRST));
return;
}

if (argAction.contains(4) && argAction.contains(11)) { // a:inventory
if (argUsers.size() == 0) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_ACTION_USER));
return;
}

argExclude.put(Material.FIRE, false);
argExclude.put(Material.WATER, false);
argExclude.put(Material.FARMLAND, false);
argExcludeUsers.add("#hopper");
}

if (type == 1) {
boolean defaultRe = true;
int p = 0;
int re = 7;
if (parseRows > 0) {
re = parseRows;
}
if (resultc > 1) {
String pages = args[1];
if (pages.contains(":")) {
String[] data = pages.split(":");
pages = data[0];
String results = "";
if (data.length > 1) {
results = data[1];
}
results = results.replaceAll("[^0-9]", "");
if (results.length() > 0 && results.length() < 10) {
int r = Integer.parseInt(results);
if (r > 0) {
re = r;
defaultRe = false;
}
}
}
pages = pages.replaceAll("[^0-9]", "");
if (pages.length() > 0 && pages.length() < 10) {
int pa = Integer.parseInt(pages);
if (pa > 0) {
p = pa;
}
}
}

if (re > 1000) {
re = 1000;
}
if (re > 100 && !(player instanceof ConsoleCommandSender)) {
re = 100;
}

if (p <= 0) {
p = 1;
}
String lcommand = ConfigHandler.lookupCommand.get(player.getName());
String[] data = lcommand.split("\\.");
int x = Integer.parseInt(data[0]);
int y = Integer.parseInt(data[1]);
int z = Integer.parseInt(data[2]);
int wid = Integer.parseInt(data[3]);
int x2 = Integer.parseInt(data[4]);
int y2 = Integer.parseInt(data[5]);
int z2 = Integer.parseInt(data[6]);
if (defaultRe) {
re = Integer.parseInt(data[7]);
}

String bc = x + "." + y + "." + z + "." + wid + "." + x2 + "." + y2 + "." + z2 + "." + re;
ConfigHandler.lookupCommand.put(player.getName(), bc);

String world = WorldUtils.getWorldName(wid);
double dx = 0.5 * (x + x2);
double dy = 0.5 * (y + y2);
double dz = 0.5 * (z + z2);
final Location location = new Location(Bukkit.getServer().getWorld(world), dx, dy, dz);

Runnable runnable = new ChestTransactionLookupThread(player, command, location, p, re);
Thread thread = new Thread(runnable);
thread.start();
}
else if (type == 2 || type == 3 || type == 7 || type == 8) {
boolean defaultRe = true;
int page = 1;
int re = 7;
if (parseRows > 0) {
re = parseRows;
}
if (resultc > 1) {
String pages = args[1];
if (pages.contains(":")) {
String[] data = pages.split(":");
pages = data[0];
String results = "";
if (data.length > 1) {
results = data[1];
}
results = results.replaceAll("[^0-9]", "");
if (results.length() > 0 && results.length() < 10) {
int r = Integer.parseInt(results);
if (r > 0) {
re = r;
defaultRe = false;
}
}
}
pages = pages.replaceAll("[^0-9]", "");
if (pages.length() > 0 && pages.length() < 10) {
int p = Integer.parseInt(pages);
if (p > 0) {
page = p;
}
}
}

if (re > 1000) {
re = 1000;
}
if (re > 100 && !(player instanceof ConsoleCommandSender)) {
re = 100;
}

// String bc = x+"."+y+"."+z+"."+wid+"."+rstring+"."+lookup_user;
String lcommand = ConfigHandler.lookupCommand.get(player.getName());
String[] data = lcommand.split("\\.");
int x = Integer.parseInt(data[0]);
int y = Integer.parseInt(data[1]);
int z = Integer.parseInt(data[2]);
int wid = Integer.parseInt(data[3]);
int lookupType = Integer.parseInt(data[4]);
if (defaultRe) {
re = Integer.parseInt(data[5]);
}

String bc = x + "." + y + "." + z + "." + wid + "." + lookupType + "." + re;
ConfigHandler.lookupCommand.put(player.getName(), bc);

String world = WorldUtils.getWorldName(wid);
final Block block = Bukkit.getServer().getWorld(world).getBlockAt(x, y, z);
final BlockState blockState = block.getState();

Runnable runnable = new BlockLookupThread(player, command, block, blockState, page, re, type);
Thread thread = new Thread(runnable);
thread.start();
}
else if (type == 4 || type == 5) {
boolean defaultRe = true;
int pa = 1;
int re = 4;
if (argAction.contains(6) || argAction.contains(7) || argAction.contains(9) || (argAction.contains(4) && argAction.contains(11))) {
re = 7;
}
if (parseRows > 0) {
re = parseRows;
}
if (type == 5) {
if (resultc > 1) {
String pages = args[1];
if (pages.contains(":")) {
String[] data = pages.split(":");
pages = data[0];
String results = "";
if (data.length > 1) {
results = data[1];
}
results = results.replaceAll("[^0-9]", "");
if (results.length() > 0 && results.length() < 10) {
int r = Integer.parseInt(results);
if (r > 0) {
re = r;
defaultRe = false;
}
}
}
pages = pages.replaceAll("[^0-9]", "");
if (pages.length() > 0 && pages.length() < 10) {
int p = Integer.parseInt(pages);
if (p > 0) {
pa = p;
}
}
}
}

if (re > 1000) {
re = 1000;
}
if (re > 100 && !(player instanceof ConsoleCommandSender)) {
re = 100;
}

int g = 1;
if (argUsers.contains("#global")) {
if (argRadius == null) {
g = 0;
}
}

if (g == 1 && (pageLookup || argBlocks.size() > 0 || argUsers.size() > 0 || (argUsers.size() == 0 && argRadius != null))) {
Integer MAX_RADIUS = Config.getGlobal().MAX_RADIUS;
if (argRadius != null) {
int radiusValue = argRadius[0];
if (radiusValue > MAX_RADIUS && MAX_RADIUS > 0) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MAXIMUM_RADIUS, MAX_RADIUS.toString(), Selector.FIRST));
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.GLOBAL_LOOKUP));
return;
}
}

if (argUsers.size() == 0) {
argUsers.add("#global");
}
List<String> rollbackusers = argUsers;
int c = 0;
for (String ruser : rollbackusers) {
if (Bukkit.getServer() != null) {
List<Player> players = Bukkit.getServer().matchPlayer(ruser);
for (Player p : players) {
if (p.getName().equalsIgnoreCase(ruser)) {
rollbackusers.set(c, p.getName());
}
}
}
c++;

if (argAction.contains(4) && argAction.contains(11)) {
if (ruser.startsWith("#")) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_USERNAME, ruser));
return;
}
}
}

long timeStart = -1;
long timeEnd = 0;
int x = 0;
int y = 0;
int z = 0;
int wid = 0;

if (type == 5) {
String lcommand = ConfigHandler.lookupCommand.get(player.getName());
String[] data = lcommand.split("\\.");
x = Integer.parseInt(data[0]);
y = Integer.parseInt(data[1]);
z = Integer.parseInt(data[2]);
wid = Integer.parseInt(data[3]);
timeStart = Long.parseLong(data[4]);
timeEnd = Long.parseLong(data[5]);
argNoisy = Integer.parseInt(data[6]);
argExcluded = Integer.parseInt(data[7]);
argRestricted = Integer.parseInt(data[8]);
argWid = Integer.parseInt(data[9]);
if (defaultRe) {
re = Integer.parseInt(data[10]);
}

rollbackusers = ConfigHandler.lookupUlist.get(player.getName());
argBlocks = ConfigHandler.lookupBlist.get(player.getName());
argExclude = ConfigHandler.lookupElist.get(player.getName());
argExcludeUsers = ConfigHandler.lookupEUserlist.get(player.getName());
argAction = ConfigHandler.lookupAlist.get(player.getName());
argRadius = ConfigHandler.lookupRadius.get(player.getName());
ts = ConfigHandler.lookupTime.get(player.getName());
if (ConfigHandler.lookupMessageFilter.get(player.getName()) != null) {
messageFilter = ConfigHandler.lookupMessageFilter.get(player.getName());
}
startTime = 1;
endTime = 0;
}
else {
if (lo != null) {
x = lo.getBlockX();
z = lo.getBlockZ();
if (lo.getWorld() != null) {
wid = WorldUtils.getWorldId(lo.getWorld().getName());
}
}

if (rollbackusers.size() == 1 && rollbackusers.contains("#global") && argAction.contains(9)) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, "/co l a:username u:<user>"));
return;
}

if (rollbackusers.contains("#container")) {
if (argAction.contains(6) || argAction.contains(7) || argAction.contains(8) || argAction.contains(9) || argAction.contains(10) || argAction.contains(11)) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_USERNAME, "#container"));
return;
}

boolean valid = false;
if (ConfigHandler.lookupType.get(player.getName()) != null) {
int lookupType = ConfigHandler.lookupType.get(player.getName());
if (lookupType == 1) {
valid = true;
}
else if (lookupType == 5) {
if (ConfigHandler.lookupUlist.get(player.getName()).contains("#container")) {
valid = true;
}
}
}

if (valid) {
if (!player.hasPermission("coreprotect.lookup.container") && !allPermission) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION));
return;
}
String lcommand = ConfigHandler.lookupCommand.get(player.getName());
String[] data = lcommand.split("\\.");
x = Integer.parseInt(data[0]);
y = Integer.parseInt(data[1]);
z = Integer.parseInt(data[2]);
wid = Integer.parseInt(data[3]);
argAction.add(5);
argRadius = null;
argWid = 0;
}
else {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_CONTAINER));
return;
}
}
}

try {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Color.ITALIC + Phrase.build(Phrase.LOOKUP_SEARCHING));

if (timeStart == -1) {
if (startTime <= 0) {
timeStart = 0;
}
else {
timeStart = (System.currentTimeMillis() / 1000L) - startTime;
}
if (endTime <= 0) {
timeEnd = 0;
}
else {
timeEnd = (System.currentTimeMillis() / 1000L) - endTime;
}
}

Runnable runnable = new StandardLookupThread(player, command, rollbackusers, argBlocks, argExclude, argExcludeUsers, argAction, argRadius, lo, x, y, z, wid, argWid, timeStart, timeEnd, argNoisy, argExcluded, argRestricted, pa, re, type, ts, count);
Runnable runnable = new StandardLookupThread(player, command, rollbackusers, argBlocks, argExclude, argExcludeUsers, argAction, argRadius, lo, x, y, z, wid, argWid, timeStart, timeEnd, argNoisy, argExcluded, argRestricted, pa, re, type, ts, count, messageFilter);
Thread thread = new Thread(runnable);
thread.start();
}
catch (Exception e) {
e.printStackTrace();
}
}
else {
// Functions.sendMessage(player, ChatColors.RED + "You did not specify a lookup radius.");
if (argUsers.size() == 0 && argBlocks.size() == 0 && (argWid > 0 || forceglobal)) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_LOOKUP_USER, Selector.FIRST));
return;
}
else if (argUsers.size() == 0 && argBlocks.size() == 0 && argRadius == null) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_LOOKUP_USER, Selector.SECOND));
return;
}
else {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, "/co l <params>"));
}
}
}
else {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, "/co l <params>"));
}
}

Check failure on line 633 in src/main/java/net/coreprotect/command/LookupCommand.java

View check run for this annotation

codefactor.io / CodeFactor

src/main/java/net/coreprotect/command/LookupCommand.java#L31-L633

Very Complex Method
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@
private final int typeLookup;
private final String rtime;
private final boolean count;
private final String messageFilter;

public StandardLookupThread(CommandSender player, Command command, List<String> rollbackUsers, List<Object> blockList, Map<Object, Boolean> excludedBlocks, List<String> excludedUsers, List<Integer> actions, Integer[] radius, Location location, int x, int y, int z, int worldId, int argWorldId, long timeStart, long timeEnd, int noisy, int excluded, int restricted, int page, int displayResults, int typeLookup, String rtime, boolean count) {
this(player, command, rollbackUsers, blockList, excludedBlocks, excludedUsers, actions, radius, location, x, y, z, worldId, argWorldId, timeStart, timeEnd, noisy, excluded, restricted, page, displayResults, typeLookup, rtime, count, "");
}

public StandardLookupThread(CommandSender player, Command command, List<String> rollbackUsers, List<Object> blockList, Map<Object, Boolean> excludedBlocks, List<String> excludedUsers, List<Integer> actions, Integer[] radius, Location location, int x, int y, int z, int worldId, int argWorldId, long timeStart, long timeEnd, int noisy, int excluded, int restricted, int page, int displayResults, int typeLookup, String rtime, boolean count, String messageFilter) {
this.player = player;
this.command = command;
this.rollbackUsers = rollbackUsers;
Expand All @@ -87,384 +92,386 @@
this.typeLookup = typeLookup;
this.rtime = rtime;
this.count = count;
this.messageFilter = messageFilter;
}

@Override
public void run() {
try (Connection connection = Database.getConnection(true)) {
ConfigHandler.lookupThrottle.put(player.getName(), new Object[] { true, System.currentTimeMillis() });

List<String> uuidList = new ArrayList<>();
Location finalLocation = location;
boolean exists = false;
String bc = x + "." + y + "." + z + "." + worldId + "." + timeStart + "." + timeEnd + "." + noisy + "." + excluded + "." + restricted + "." + argWorldId + "." + displayResults;
ConfigHandler.lookupCommand.put(player.getName(), bc);
ConfigHandler.lookupPage.put(player.getName(), page);
ConfigHandler.lookupTime.put(player.getName(), rtime);
ConfigHandler.lookupMessageFilter.put(player.getName(), messageFilter);
ConfigHandler.lookupType.put(player.getName(), 5);
ConfigHandler.lookupElist.put(player.getName(), excludedBlocks);
ConfigHandler.lookupEUserlist.put(player.getName(), excludedUsers);
ConfigHandler.lookupBlist.put(player.getName(), blockList);
ConfigHandler.lookupUlist.put(player.getName(), rollbackUsers);
ConfigHandler.lookupAlist.put(player.getName(), actions);
ConfigHandler.lookupRadius.put(player.getName(), radius);

if (connection != null) {
Statement statement = connection.createStatement();
String baduser = "";
for (String check : rollbackUsers) {
if ((!check.equals("#global") && !check.equals("#container")) || actions.contains(9)) {
exists = PlayerLookup.playerExists(connection, check);
if (!exists) {
baduser = check;
break;
}
else if (actions.contains(9)) {
if (ConfigHandler.uuidCache.get(check.toLowerCase(Locale.ROOT)) != null) {
String uuid = ConfigHandler.uuidCache.get(check.toLowerCase(Locale.ROOT));
uuidList.add(uuid);
}
}
}
else {
exists = true;
}
}
if (exists) {
for (String check : excludedUsers) {
if (!check.equals("#global") && !check.equals("#hopper")) {
exists = PlayerLookup.playerExists(connection, check);
if (!exists) {
baduser = check;
break;
}
}
else if (check.equals("#global")) {
baduser = "#global";
exists = false;
}
}
}

if (exists) {
List<String> userList = new ArrayList<>();
if (!actions.contains(9)) {
userList = rollbackUsers;
}

int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
boolean restrict_world = false;
if (radius != null) {
restrict_world = true;
}
if (finalLocation == null) {
restrict_world = false;
}
if (argWorldId > 0) {
restrict_world = true;
finalLocation = new Location(Bukkit.getServer().getWorld(WorldUtils.getWorldName(argWorldId)), x, y, z);
}
else if (finalLocation != null) {
finalLocation = new Location(Bukkit.getServer().getWorld(WorldUtils.getWorldName(worldId)), x, y, z);
}

Long[] rowData = new Long[] { 0L, 0L, 0L, 0L };
long rowMax = (long) page * displayResults;
long pageStart = rowMax - displayResults;
long rows = 0L;
boolean checkRows = true;

if (typeLookup == 5 && page > 1) {
rowData = ConfigHandler.lookupRows.get(player.getName());
rows = rowData[3];

if (pageStart < rows) {
checkRows = false;
}
}

if (checkRows) {
rows = Lookup.countLookupRows(statement, player, uuidList, userList, blockList, excludedBlocks, excludedUsers, actions, finalLocation, radius, rowData, timeStart, timeEnd, restrict_world, true);
rows = Lookup.countLookupRows(statement, player, uuidList, userList, blockList, excludedBlocks, excludedUsers, actions, finalLocation, radius, rowData, timeStart, timeEnd, restrict_world, true, messageFilter);
rowData[3] = rows;
ConfigHandler.lookupRows.put(player.getName(), rowData);
}
if (count) {
String row_format = NumberFormat.getInstance().format(rows);
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.LOOKUP_ROWS_FOUND, row_format, (rows == 1 ? Selector.FIRST : Selector.SECOND)));
}
else if (pageStart < rows) {
List<String[]> lookupList = Lookup.performPartialLookup(statement, player, uuidList, userList, blockList, excludedBlocks, excludedUsers, actions, finalLocation, radius, rowData, timeStart, timeEnd, (int) pageStart, displayResults, restrict_world, true);
List<String[]> lookupList = Lookup.performPartialLookup(statement, player, uuidList, userList, blockList, excludedBlocks, excludedUsers, actions, finalLocation, radius, rowData, timeStart, timeEnd, (int) pageStart, displayResults, restrict_world, true, messageFilter);

Chat.sendMessage(player, Color.WHITE + "----- " + Color.DARK_AQUA + Phrase.build(Phrase.LOOKUP_HEADER, "CoreProtect" + Color.WHITE + " | " + Color.DARK_AQUA) + Color.WHITE + " -----");
if (actions.contains(6) || actions.contains(7)) { // Chat/command
for (String[] data : lookupList) {
String time = data[0];
String dplayer = data[1];
String message = data[2];
String timeago = ChatUtils.getTimeSince(Integer.parseInt(time), unixtimestamp, true);
Chat.sendComponent(player, timeago + " " + Color.WHITE + "- " + Color.DARK_AQUA + dplayer + ": " + Color.WHITE, message);
if (PluginChannelHandshakeListener.getInstance().isPluginChannelPlayer(player)) {
int wid = Integer.parseInt(data[3]);
int dataX = Integer.parseInt(data[4]);
int dataY = Integer.parseInt(data[5]);
int dataZ = Integer.parseInt(data[6]);
PluginChannelListener.getInstance().sendMessageData(player, Integer.parseInt(time), dplayer, message, false, dataX, dataY, dataZ, wid);
}
}
}
else if (actions.contains(8)) { // login/logouts
for (String[] data : lookupList) {
String time = data[0];
String dplayer = data[1];
int wid = Integer.parseInt(data[2]);
int dataX = Integer.parseInt(data[3]);
int dataY = Integer.parseInt(data[4]);
int dataZ = Integer.parseInt(data[5]);
int action = Integer.parseInt(data[6]);
String timeago = ChatUtils.getTimeSince(Integer.parseInt(time), unixtimestamp, true);
int timeLength = 50 + (ChatUtils.getTimeSince(Integer.parseInt(time), unixtimestamp, false).replaceAll("[^0-9]", "").length() * 6);
String leftPadding = Color.BOLD + Strings.padStart("", 10, ' ');
if (timeLength % 4 == 0) {
leftPadding = Strings.padStart("", timeLength / 4, ' ');
}
else {
leftPadding = leftPadding + Color.WHITE + Strings.padStart("", (timeLength - 50) / 4, ' ');
}

String tag = (action != 0 ? Color.GREEN + "+" : Color.RED + "-");
Chat.sendComponent(player, timeago + " " + tag + " " + Color.DARK_AQUA + Phrase.build(Phrase.LOOKUP_LOGIN, Color.DARK_AQUA + dplayer + Color.WHITE, (action != 0 ? Selector.FIRST : Selector.SECOND)));
Chat.sendComponent(player, Color.WHITE + leftPadding + Color.GREY + "^ " + ChatUtils.getCoordinates(command.getName(), wid, dataX, dataY, dataZ, true, true) + "");
PluginChannelListener.getInstance().sendInfoData(player, Integer.parseInt(time), Phrase.LOOKUP_LOGIN, (action != 0 ? Selector.FIRST : Selector.SECOND), dplayer, -1, dataX, dataY, dataZ, wid);
}
}
else if (actions.contains(9)) { // username-changes
for (String[] data : lookupList) {
String time = data[0];
String user = ConfigHandler.uuidCacheReversed.get(data[1]);
String username = data[2];
String timeago = ChatUtils.getTimeSince(Integer.parseInt(time), unixtimestamp, true);
Chat.sendComponent(player, timeago + " " + Color.WHITE + "- " + Phrase.build(Phrase.LOOKUP_USERNAME, Color.DARK_AQUA + user + Color.WHITE, Color.DARK_AQUA + username + Color.WHITE));
PluginChannelListener.getInstance().sendUsernameData(player, Integer.parseInt(time), user, username);
}
}
else if (actions.contains(10)) { // sign messages
for (String[] data : lookupList) {
String time = data[0];
String dplayer = data[1];
int wid = Integer.parseInt(data[2]);
int dataX = Integer.parseInt(data[3]);
int dataY = Integer.parseInt(data[4]);
int dataZ = Integer.parseInt(data[5]);
String message = data[6];
String timeago = ChatUtils.getTimeSince(Integer.parseInt(time), unixtimestamp, true);
int timeLength = 50 + (ChatUtils.getTimeSince(Integer.parseInt(time), unixtimestamp, false).replaceAll("[^0-9]", "").length() * 6);
String leftPadding = Color.BOLD + Strings.padStart("", 10, ' ');
if (timeLength % 4 == 0) {
leftPadding = Strings.padStart("", timeLength / 4, ' ');
}
else {
leftPadding = leftPadding + Color.WHITE + Strings.padStart("", (timeLength - 50) / 4, ' ');
}

Chat.sendComponent(player, timeago + " " + Color.WHITE + "- " + Color.DARK_AQUA + dplayer + ": " + Color.WHITE, message);
Chat.sendComponent(player, Color.WHITE + leftPadding + Color.GREY + "^ " + ChatUtils.getCoordinates(command.getName(), wid, dataX, dataY, dataZ, true, true) + "");
PluginChannelListener.getInstance().sendMessageData(player, Integer.parseInt(time), dplayer, message, true, dataX, dataY, dataZ, wid);
}
}
else if (actions.contains(4) && actions.contains(11)) { // inventory transactions
for (String[] data : lookupList) {
String time = data[0];
String dplayer = data[1];
int dtype = Integer.parseInt(data[5]);
int ddata = Integer.parseInt(data[6]);
int daction = Integer.parseInt(data[7]);
int amount = Integer.parseInt(data[10]);
int wid = Integer.parseInt(data[9]);
int dataX = Integer.parseInt(data[2]);
int dataY = Integer.parseInt(data[3]);
int dataZ = Integer.parseInt(data[4]);
String rbd = ((Integer.parseInt(data[8]) == 2 || Integer.parseInt(data[8]) == 3) ? Color.STRIKETHROUGH : "");
String timeago = ChatUtils.getTimeSince(Integer.parseInt(time), unixtimestamp, true);
Material blockType = ItemUtils.itemFilter(MaterialUtils.getType(dtype), (Integer.parseInt(data[13]) == 0));
String dname = StringUtils.nameFilter(blockType.name().toLowerCase(Locale.ROOT), ddata);
byte[] metadata = data[11] == null ? null : data[11].getBytes(StandardCharsets.ISO_8859_1);
String tooltip = ItemUtils.getEnchantments(metadata, dtype, amount);

String selector = Selector.FIRST;
String tag = Color.WHITE + "-";
if (daction == 2 || daction == 3) { // LOOKUP_ITEM
selector = (daction != 2 ? Selector.FIRST : Selector.SECOND);
tag = (daction != 2 ? Color.GREEN + "+" : Color.RED + "-");
}
else if (daction == 4 || daction == 5) { // LOOKUP_STORAGE
selector = (daction == 4 ? Selector.FIRST : Selector.SECOND);
tag = (daction == 4 ? Color.GREEN + "+" : Color.RED + "-");
}
else if (daction == 6 || daction == 7) { // LOOKUP_PROJECTILE
selector = Selector.SECOND;
tag = Color.RED + "-";
}
else if (daction == ItemLogger.ITEM_BREAK || daction == ItemLogger.ITEM_DESTROY || daction == ItemLogger.ITEM_CREATE) {
selector = (daction == ItemLogger.ITEM_CREATE ? Selector.FIRST : Selector.SECOND);
tag = (daction == ItemLogger.ITEM_CREATE ? Color.GREEN + "+" : Color.RED + "-");
}
else if (daction == ItemLogger.ITEM_SELL || daction == ItemLogger.ITEM_BUY) { // LOOKUP_TRADE
selector = (daction == ItemLogger.ITEM_BUY ? Selector.FIRST : Selector.SECOND);
tag = (daction == ItemLogger.ITEM_BUY ? Color.GREEN + "+" : Color.RED + "-");
}
else { // LOOKUP_CONTAINER
selector = (daction == 0 ? Selector.FIRST : Selector.SECOND);
tag = (daction == 0 ? Color.GREEN + "+" : Color.RED + "-");
}

Chat.sendComponent(player, timeago + " " + tag + " " + Phrase.build(Phrase.LOOKUP_CONTAINER, Color.DARK_AQUA + rbd + dplayer + Color.WHITE + rbd, "x" + amount, ChatUtils.createTooltip(Color.DARK_AQUA + rbd + dname, tooltip) + Color.WHITE, selector));
PluginChannelListener.getInstance().sendData(player, Integer.parseInt(time), Phrase.LOOKUP_CONTAINER, selector, dplayer, dname, amount, dataX, dataY, dataZ, wid, rbd, true, tag.contains("+"));
}
}
else {
for (String[] data : lookupList) {
int drb = Integer.parseInt(data[8]);
String rbd = "";
if (drb == 1 || drb == 3) {
rbd = Color.STRIKETHROUGH;
}

String time = data[0];
String dplayer = data[1];
int dataX = Integer.parseInt(data[2]);
int dataY = Integer.parseInt(data[3]);
int dataZ = Integer.parseInt(data[4]);
int dtype = Integer.parseInt(data[5]);
int ddata = Integer.parseInt(data[6]);
int daction = Integer.parseInt(data[7]);
int wid = Integer.parseInt(data[9]);
int amount = Integer.parseInt(data[10]);
String tag = Color.WHITE + "-";

String timeago = ChatUtils.getTimeSince(Integer.parseInt(time), unixtimestamp, true);
int timeLength = 50 + (ChatUtils.getTimeSince(Integer.parseInt(time), unixtimestamp, false).replaceAll("[^0-9]", "").length() * 6);
String leftPadding = Color.BOLD + Strings.padStart("", 10, ' ');
if (timeLength % 4 == 0) {
leftPadding = Strings.padStart("", timeLength / 4, ' ');
}
else {
leftPadding = leftPadding + Color.WHITE + Strings.padStart("", (timeLength - 50) / 4, ' ');
}

String dname = "";
boolean isPlayer = false;
if (daction == 3 && !actions.contains(11) && amount == -1) {
if (dtype == 0) {
if (ConfigHandler.playerIdCacheReversed.get(ddata) == null) {
UserStatement.loadName(connection, ddata);
}
dname = ConfigHandler.playerIdCacheReversed.get(ddata);
isPlayer = true;
}
else {
dname = EntityUtils.getEntityType(dtype).name();
}
}
else {
dname = MaterialUtils.getType(dtype).name().toLowerCase(Locale.ROOT);
dname = StringUtils.nameFilter(dname, ddata);
}
if (dname.length() > 0 && !isPlayer) {
dname = "minecraft:" + dname.toLowerCase(Locale.ROOT) + "";
}

// Hide "minecraft:" for now.
if (dname.contains("minecraft:")) {
String[] blockNameSplit = dname.split(":");
dname = blockNameSplit[1];
}

// Functions.sendMessage(player2, timeago+" " + ChatColors.WHITE + "- " + ChatColors.DARK_AQUA+rbd+""+dplayer+" " + ChatColors.WHITE+rbd+""+a+" " + ChatColors.DARK_AQUA+rbd+"#"+dtype+ChatColors.WHITE + ". " + ChatColors.GREY + "(x"+x+"/y"+y+"/z"+z+")");

Phrase phrase = Phrase.LOOKUP_BLOCK;
String selector = Selector.FIRST;
String action = "a:block";
if (actions.contains(4) || actions.contains(5) || actions.contains(11) || amount > -1) {
byte[] metadata = data[11] == null ? null : data[11].getBytes(StandardCharsets.ISO_8859_1);
String tooltip = ItemUtils.getEnchantments(metadata, dtype, amount);

if (daction == 2 || daction == 3) {
phrase = Phrase.LOOKUP_ITEM; // {picked up|dropped}
selector = (daction != 2 ? Selector.FIRST : Selector.SECOND);
tag = (daction != 2 ? Color.GREEN + "+" : Color.RED + "-");
action = "a:item";
}
else if (daction == 4 || daction == 5) {
phrase = Phrase.LOOKUP_STORAGE; // {deposited|withdrew}
selector = (daction != 4 ? Selector.FIRST : Selector.SECOND);
tag = (daction != 4 ? Color.RED + "-" : Color.GREEN + "+");
action = "a:item";
}
else if (daction == 6 || daction == 7) {
phrase = Phrase.LOOKUP_PROJECTILE; // {threw|shot}
selector = (daction != 7 ? Selector.FIRST : Selector.SECOND);
tag = Color.RED + "-";
action = "a:item";
}
else {
phrase = Phrase.LOOKUP_CONTAINER; // {added|removed}
selector = (daction != 0 ? Selector.FIRST : Selector.SECOND);
tag = (daction != 0 ? Color.GREEN + "+" : Color.RED + "-");
action = "a:container";
}

Chat.sendComponent(player, timeago + " " + tag + " " + Phrase.build(phrase, Color.DARK_AQUA + rbd + dplayer + Color.WHITE + rbd, "x" + amount, ChatUtils.createTooltip(Color.DARK_AQUA + rbd + dname, tooltip) + Color.WHITE, selector));
PluginChannelListener.getInstance().sendData(player, Integer.parseInt(time), phrase, selector, dplayer, dname, (tag.contains("+") ? 1 : -1), dataX, dataY, dataZ, wid, rbd, action.contains("container"), tag.contains("+"));
}
else {
if (daction == 2 || daction == 3) {
phrase = Phrase.LOOKUP_INTERACTION; // {clicked|killed}
selector = (daction != 3 ? Selector.FIRST : Selector.SECOND);
tag = (daction != 3 ? Color.WHITE + "-" : Color.RED + "-");
action = (daction == 2 ? "a:click" : "a:kill");
}
else {
phrase = Phrase.LOOKUP_BLOCK; // {placed|broke}
selector = (daction != 0 ? Selector.FIRST : Selector.SECOND);
tag = (daction != 0 ? Color.GREEN + "+" : Color.RED + "-");
}

Chat.sendComponent(player, timeago + " " + tag + " " + Phrase.build(phrase, Color.DARK_AQUA + rbd + dplayer + Color.WHITE + rbd, Color.DARK_AQUA + rbd + dname + Color.WHITE, selector));
PluginChannelListener.getInstance().sendData(player, Integer.parseInt(time), phrase, selector, dplayer, dname, (tag.contains("+") ? 1 : -1), dataX, dataY, dataZ, wid, rbd, false, tag.contains("+"));
}

action = (actions.size() == 0 ? " (" + action + ")" : "");
Chat.sendComponent(player, Color.WHITE + leftPadding + Color.GREY + "^ " + ChatUtils.getCoordinates(command.getName(), wid, dataX, dataY, dataZ, true, true) + Color.GREY + Color.ITALIC + action);
}
}
if (rows > displayResults) {
int total_pages = (int) Math.ceil(rows / (displayResults + 0.0));
if (actions.contains(6) || actions.contains(7) || actions.contains(9) || (actions.contains(4) && actions.contains(11))) {
Chat.sendMessage(player, "-----");
}
Chat.sendComponent(player, ChatUtils.getPageNavigation(command.getName(), page, total_pages));
}
}
else if (rows > 0) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_RESULTS_PAGE, Selector.FIRST));
}
else {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_RESULTS));
}
}
else {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.USER_NOT_FOUND, baduser));
}
statement.close();
}
else {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY));
}
}
catch (Exception e) {
e.printStackTrace();
}

ConfigHandler.lookupThrottle.put(player.getName(), new Object[] { false, System.currentTimeMillis() });
}

Check warning on line 476 in src/main/java/net/coreprotect/command/lookup/StandardLookupThread.java

View check run for this annotation

codefactor.io / CodeFactor

src/main/java/net/coreprotect/command/lookup/StandardLookupThread.java#L98-L476

Very Complex Method
}
31 changes: 30 additions & 1 deletion src/main/java/net/coreprotect/command/parser/ActionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,123 +31,123 @@
* The command arguments
* @return A list of action integers
*/
public static List<Integer> parseAction(String[] inputArguments) {
String[] argumentArray = inputArguments.clone();
List<Integer> result = new ArrayList<>();
int count = 0;
int next = 0;
for (String argument : argumentArray) {
if (count > 0) {
argument = argument.trim().toLowerCase(Locale.ROOT);
argument = argument.replaceAll("\\\\", "");
argument = argument.replaceAll("'", "");

if (argument.equals("a:") || argument.equals("action:")) {
next = 1;
}
else if (next == 1 || argument.startsWith("a:") || argument.startsWith("action:")) {
result.clear();
argument = argument.replaceAll("action:", "");
argument = argument.replaceAll("a:", "");
if (argument.startsWith("#")) {
argument = argument.replaceFirst("#", "");
}
if (argument.equals("broke") || argument.equals("break") || argument.equals("remove") || argument.equals("destroy") || argument.equals("block-break") || argument.equals("block-remove") || argument.equals("-block") || argument.equals("-blocks") || argument.equals("block-")) {
result.add(0);
}
else if (argument.equals("placed") || argument.equals("place") || argument.equals("block-place") || argument.equals("+block") || argument.equals("+blocks") || argument.equals("block+")) {
result.add(1);
}
else if (argument.equals("block") || argument.equals("blocks") || argument.equals("block-change") || argument.equals("change") || argument.equals("changes")) {
result.add(0);
result.add(1);
}
else if (argument.equals("click") || argument.equals("clicks") || argument.equals("interact") || argument.equals("interaction") || argument.equals("player-interact") || argument.equals("player-interaction") || argument.equals("player-click")) {
result.add(2);
}
else if (argument.equals("death") || argument.equals("deaths") || argument.equals("entity-death") || argument.equals("entity-deaths") || argument.equals("kill") || argument.equals("kills") || argument.equals("entity-kill") || argument.equals("entity-kills")) {
result.add(3);
}
else if (argument.equals("container") || argument.equals("container-change") || argument.equals("containers") || argument.equals("chest") || argument.equals("transaction") || argument.equals("transactions")) {
result.add(4);
}
else if (argument.equals("-container") || argument.equals("container-") || argument.equals("remove-container")) {
result.add(4);
result.add(0);
}
else if (argument.equals("+container") || argument.equals("container+") || argument.equals("container-add") || argument.equals("add-container")) {
result.add(4);
result.add(1);
}
else if (argument.equals("chat") || argument.equals("chats")) {
result.add(6);
}
else if (argument.equals("command") || argument.equals("commands")) {
result.add(7);
}
else if (argument.equals("logins") || argument.equals("login") || argument.equals("+session") || argument.equals("+sessions") || argument.equals("session+") || argument.equals("+connection") || argument.equals("connection+")) {
result.add(8);
result.add(1);
}
else if (argument.equals("logout") || argument.equals("logouts") || argument.equals("-session") || argument.equals("-sessions") || argument.equals("session-") || argument.equals("-connection") || argument.equals("connection-")) {
result.add(8);
result.add(0);
}
else if (argument.equals("session") || argument.equals("sessions") || argument.equals("connection") || argument.equals("connections")) {
result.add(8);
}
else if (argument.equals("username") || argument.equals("usernames") || argument.equals("user") || argument.equals("users") || argument.equals("name") || argument.equals("names") || argument.equals("uuid") || argument.equals("uuids") || argument.equals("username-change") || argument.equals("username-changes") || argument.equals("name-change") || argument.equals("name-changes")) {
result.add(9);
}
else if (argument.equals("sign") || argument.equals("signs")) {
result.add(10);
}
else if (argument.equals("inv") || argument.equals("inventory") || argument.equals("inventories")) {
result.add(4); // container
result.add(11); // item
}
else if (argument.equals("-inv") || argument.equals("inv-") || argument.equals("-inventory") || argument.equals("inventory-") || argument.equals("-inventories")) {
result.add(4);
result.add(11);
result.add(1);
}
else if (argument.equals("+inv") || argument.equals("inv+") || argument.equals("+inventory") || argument.equals("inventory+") || argument.equals("+inventories")) {
result.add(4);
result.add(11);
result.add(0);
}
else if (argument.equals("item") || argument.equals("items")) {
result.add(11);
}
else if (argument.equals("-item") || argument.equals("item-") || argument.equals("-items") || argument.equals("items-") || argument.equals("drop") || argument.equals("drops") || argument.equals("deposit") || argument.equals("deposits") || argument.equals("deposited")) {
result.add(11);
result.add(0);
}
else if (argument.equals("+item") || argument.equals("item+") || argument.equals("+items") || argument.equals("items+") || argument.equals("pickup") || argument.equals("pickups") || argument.equals("withdraw") || argument.equals("withdraws") || argument.equals("withdrew")) {
result.add(11);
result.add(1);
}
else {
result.add(-1);
}
next = 0;
}
else {
next = 0;
}
}
count++;
}
return result;
}

/**
* Parse count flag from command arguments
*
* @param inputArguments
* The command arguments
* @return true if the count flag is present
*/

Check notice on line 150 in src/main/java/net/coreprotect/command/parser/ActionParser.java

View check run for this annotation

codefactor.io / CodeFactor

src/main/java/net/coreprotect/command/parser/ActionParser.java#L34-L150

Complex Method
public static boolean parseCount(String[] inputArguments) {
String[] argumentArray = inputArguments.clone();
boolean result = false;
Expand Down Expand Up @@ -199,9 +199,38 @@
return noisy;
}

/**
* Parse message filter from command arguments (m:, msg:, message:)
*
* @param inputArguments
* The command arguments
* @return The message filter string, or empty string if not present
*/
public static String parseMessageFilter(String[] inputArguments) {
String[] argumentArray = inputArguments.clone();
String result = "";
int count = 0;
for (String argument : argumentArray) {
if (count > 0) {
argument = argument.trim();
String lower = argument.toLowerCase(Locale.ROOT);
if (lower.startsWith("message:") || lower.startsWith("msg:") || lower.startsWith("m:")) {
String filter = argument.replaceAll("(?i)^message:", "").replaceAll("(?i)^msg:", "").replaceAll("(?i)^m:", "");
filter = filter.replaceAll("\\\\", "");
filter = filter.replaceAll("'", "");
if (filter.length() > 0) {
result = filter;
}
}
}
count++;
}
return result;
}

/**
* Parse preview flag from command arguments
*
*
* @param inputArguments
* The command arguments
* @return 1 for preview, 2 for preview cancel, 0 otherwise
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/coreprotect/config/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private static <K, V> Map<K, V> syncMap() {
public static Map<String, List<Integer>> lookupAlist = syncMap();
public static Map<String, Integer[]> lookupRadius = syncMap();
public static Map<String, String> lookupTime = syncMap();
public static Map<String, String> lookupMessageFilter = syncMap();
public static Map<String, Long[]> lookupRows = syncMap();
public static Map<String, String> uuidCache = syncMap();
public static Map<String, String> uuidCacheReversed = syncMap();
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/net/coreprotect/database/Lookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
public class Lookup extends Queue {

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) {
return countLookupRows(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, startTime, endTime, restrictWorld, 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, String messageFilter) {
Long rows = 0L;

try {
Expand All @@ -25,7 +29,7 @@ public static long countLookupRows(Statement statement, CommandSender user, List
}
Consumer.isPaused = true;

ResultSet results = LookupRaw.rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, null, startTime, endTime, -1, -1, restrictWorld, lookup, true);
ResultSet results = LookupRaw.rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, null, startTime, endTime, -1, -1, restrictWorld, lookup, messageFilter, true);
while (results.next()) {
int resultTable = results.getInt("tbl");
long count = results.getLong("count");
Expand Down Expand Up @@ -58,10 +62,14 @@ public static List<String[]> performLookup(Statement statement, CommandSender us
}

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) {
return performPartialLookup(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, startTime, endTime, limitOffset, limitCount, restrictWorld, 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, String messageFilter) {
List<String[]> newList = new ArrayList<>();

try {
List<Object[]> lookupList = LookupRaw.performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, startTime, endTime, limitOffset, limitCount, restrictWorld, lookup);
List<Object[]> lookupList = LookupRaw.performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, startTime, endTime, limitOffset, limitCount, restrictWorld, lookup, messageFilter);
newList = LookupConverter.convertRawLookup(statement, lookupList);
}
catch (Exception e) {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/net/coreprotect/database/LookupRaw.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,658 +28,670 @@
public class LookupRaw extends Queue {

protected 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) {
return performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, startTime, endTime, limitOffset, limitCount, restrictWorld, lookup, "");
}

protected 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, String messageFilter) {
List<Object[]> list = new ArrayList<>();
List<Integer> invalidRollbackActions = new ArrayList<>();
invalidRollbackActions.add(2);

if (!Config.getGlobal().ROLLBACK_ENTITIES && !actionList.contains(3)) {
invalidRollbackActions.add(3);
}

if (actionList.contains(4) && actionList.contains(11)) {
invalidRollbackActions.clear();
}

try {
while (Consumer.isPaused) {
Thread.sleep(1);
}

Consumer.isPaused = true;

ResultSet results = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, startTime, endTime, limitOffset, limitCount, restrictWorld, lookup, false);
ResultSet results = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, startTime, endTime, limitOffset, limitCount, restrictWorld, lookup, messageFilter, false);

while (results.next()) {
if (actionList.contains(6) || actionList.contains(7)) {
long resultId = results.getLong("id");
int resultTime = results.getInt("time");
int resultUserId = results.getInt("user");
String resultMessage = results.getString("message");

Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultMessage };
if (PluginChannelHandshakeListener.getInstance().isPluginChannelPlayer(user)) {
int resultWorldId = results.getInt("wid");
int resultX = results.getInt("x");
int resultY = results.getInt("y");
int resultZ = results.getInt("z");
dataArray = new Object[] { resultId, resultTime, resultUserId, resultMessage, resultWorldId, resultX, resultY, resultZ };
}
list.add(dataArray);
}
else if (actionList.contains(8)) {
long resultId = results.getLong("id");
int resultTime = results.getInt("time");
int resultUserId = results.getInt("user");
int resultWorldId = results.getInt("wid");
int resultX = results.getInt("x");
int resultY = results.getInt("y");
int resultZ = results.getInt("z");
int resultAction = results.getInt("action");

Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultWorldId, resultX, resultY, resultZ, resultAction };
list.add(dataArray);
}
else if (actionList.contains(9)) {
long resultId = results.getLong("id");
int resultTime = results.getInt("time");
String resultUuid = results.getString("uuid");
String resultUser = results.getString("user");

Object[] dataArray = new Object[] { resultId, resultTime, resultUuid, resultUser };
list.add(dataArray);
}
else if (actionList.contains(10)) {
long resultId = results.getLong("id");
int resultTime = results.getInt("time");
int resultUserId = results.getInt("user");
int resultWorldId = results.getInt("wid");
int resultX = results.getInt("x");
int resultY = results.getInt("y");
int resultZ = results.getInt("z");
boolean isFront = results.getInt("face") == 0;
String line1 = results.getString("line_1");
String line2 = results.getString("line_2");
String line3 = results.getString("line_3");
String line4 = results.getString("line_4");
String line5 = results.getString("line_5");
String line6 = results.getString("line_6");
String line7 = results.getString("line_7");
String line8 = results.getString("line_8");

StringBuilder message = new StringBuilder();
if (isFront && line1 != null && line1.length() > 0) {
message.append(line1);
if (!line1.endsWith(" ")) {
message.append(" ");
}
}
if (isFront && line2 != null && line2.length() > 0) {
message.append(line2);
if (!line2.endsWith(" ")) {
message.append(" ");
}
}
if (isFront && line3 != null && line3.length() > 0) {
message.append(line3);
if (!line3.endsWith(" ")) {
message.append(" ");
}
}
if (isFront && line4 != null && line4.length() > 0) {
message.append(line4);
if (!line4.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line5 != null && line5.length() > 0) {
message.append(line5);
if (!line5.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line6 != null && line6.length() > 0) {
message.append(line6);
if (!line6.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line7 != null && line7.length() > 0) {
message.append(line7);
if (!line7.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line8 != null && line8.length() > 0) {
message.append(line8);
if (!line8.endsWith(" ")) {
message.append(" ");
}
}

Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultWorldId, resultX, resultY, resultZ, message.toString() };
list.add(dataArray);
}
else {
int resultData = 0;
int resultAmount = -1;
int resultTable = 0;
byte[] resultMeta = null;
byte[] resultBlockData = null;
long resultId = results.getLong("id");
int resultUserId = results.getInt("user");
int resultAction = results.getInt("action");
int resultRolledBack = results.getInt("rolled_back");
int resultType = results.getInt("type");
int resultTime = results.getInt("time");
int resultX = results.getInt("x");
int resultY = results.getInt("y");
int resultZ = results.getInt("z");
int resultWorldId = results.getInt("wid");

boolean hasTbl = false;
if ((lookup && actionList.size() == 0) || actionList.contains(4) || actionList.contains(5) || actionList.contains(11)) {
resultData = results.getInt("data");
resultAmount = results.getInt("amount");
resultMeta = results.getBytes("metadata");
resultTable = results.getInt("tbl");
hasTbl = true;
}
else {
resultData = results.getInt("data");
resultMeta = results.getBytes("meta");
resultBlockData = results.getBytes("blockdata");
}

boolean valid = true;
if (!lookup) {
if (invalidRollbackActions.contains(resultAction)) {
valid = false;
}
}

if (valid) {
if (hasTbl) {
Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultX, resultY, resultZ, resultType, resultData, resultAction, resultRolledBack, resultWorldId, resultAmount, resultMeta, resultBlockData, resultTable };
list.add(dataArray);
}
else {
Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultX, resultY, resultZ, resultType, resultData, resultAction, resultRolledBack, resultWorldId, resultAmount, resultMeta, resultBlockData };
list.add(dataArray);
}
}
}
}
results.close();
}
catch (Exception e) {
e.printStackTrace();
}

Consumer.isPaused = false;
return list;
}

Check notice on line 225 in src/main/java/net/coreprotect/database/LookupRaw.java

View check run for this annotation

codefactor.io / CodeFactor

src/main/java/net/coreprotect/database/LookupRaw.java#L34-L225

Complex Method
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) {
return rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, startTime, endTime, limitOffset, limitCount, restrictWorld, lookup, "", count);
}

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, String messageFilter, boolean count) {
ResultSet results = null;

try {
List<Integer> validActions = Arrays.asList(0, 1, 2, 3);
if (radius != null) {
restrictWorld = true;
}

boolean inventoryQuery = (actionList.contains(4) && actionList.contains(11));
boolean validAction = false;
String queryBlock = "";
String queryEntity = "";
String queryLimit = "";
String queryTable = "block";
String action = "";
String actionExclude = "";
String includeBlock = "";
String includeEntity = "";
String excludeBlock = "";
String excludeEntity = "";
String users = "";
String uuids = "";
String excludeUsers = "";
String unionLimit = "";
String index = "";
String query = "";

if (checkUuids.size() > 0) {
String list = "";

for (String value : checkUuids) {
if (list.length() == 0) {
list = "'" + value + "'";
}
else {
list = list + ",'" + value + "'";
}
}

uuids = list;
}

if (!checkUsers.contains("#global")) {
StringBuilder checkUserText = new StringBuilder();

for (String checkUser : checkUsers) {
if (!checkUser.equals("#container")) {
if (ConfigHandler.playerIdCache.get(checkUser.toLowerCase(Locale.ROOT)) == null) {
UserStatement.loadId(statement.getConnection(), checkUser, null);
}

int userId = ConfigHandler.playerIdCache.get(checkUser.toLowerCase(Locale.ROOT));
if (checkUserText.length() == 0) {
checkUserText = checkUserText.append(userId);
}
else {
checkUserText.append(",").append(userId);
}
}
}
users = checkUserText.toString();
}

if (restrictList.size() > 0) {
StringBuilder includeListMaterial = new StringBuilder();
StringBuilder includeListEntity = new StringBuilder();

for (Object restrictTarget : restrictList) {
String targetName = "";

if (restrictTarget instanceof Material) {
targetName = ((Material) restrictTarget).name();
if (includeListMaterial.length() == 0) {
includeListMaterial = includeListMaterial.append(MaterialUtils.getBlockId(targetName, false));
}
else {
includeListMaterial.append(",").append(MaterialUtils.getBlockId(targetName, false));
}

/* Include legacy IDs */
int legacyId = BukkitAdapter.ADAPTER.getLegacyBlockId((Material) restrictTarget);
if (legacyId > 0) {
includeListMaterial.append(",").append(legacyId);
}
}
else if (restrictTarget instanceof EntityType) {
targetName = ((EntityType) restrictTarget).name();
if (includeListEntity.length() == 0) {
includeListEntity = includeListEntity.append(EntityUtils.getEntityId(targetName, false));
}
else {
includeListEntity.append(",").append(EntityUtils.getEntityId(targetName, false));
}
}
}

includeBlock = includeListMaterial.toString();
includeEntity = includeListEntity.toString();
}

if (excludeList.size() > 0) {
StringBuilder excludeListMaterial = new StringBuilder();
StringBuilder excludeListEntity = new StringBuilder();

for (Object restrictTarget : excludeList.keySet()) {
String targetName = "";

if (restrictTarget instanceof Material) {
targetName = ((Material) restrictTarget).name();
if (excludeListMaterial.length() == 0) {
excludeListMaterial = excludeListMaterial.append(MaterialUtils.getBlockId(targetName, false));
}
else {
excludeListMaterial.append(",").append(MaterialUtils.getBlockId(targetName, false));
}

/* Include legacy IDs */
int legacyId = BukkitAdapter.ADAPTER.getLegacyBlockId((Material) restrictTarget);
if (legacyId > 0) {
excludeListMaterial.append(",").append(legacyId);
}
}
else if (restrictTarget instanceof EntityType) {
targetName = ((EntityType) restrictTarget).name();
if (excludeListEntity.length() == 0) {
excludeListEntity = excludeListEntity.append(EntityUtils.getEntityId(targetName, false));
}
else {
excludeListEntity.append(",").append(EntityUtils.getEntityId(targetName, false));
}
}
}

excludeBlock = excludeListMaterial.toString();
excludeEntity = excludeListEntity.toString();
}

if (excludeUserList.size() > 0) {
StringBuilder excludeUserText = new StringBuilder();

for (String excludeTarget : excludeUserList) {
if (ConfigHandler.playerIdCache.get(excludeTarget.toLowerCase(Locale.ROOT)) == null) {
UserStatement.loadId(statement.getConnection(), excludeTarget, null);
}

int userId = ConfigHandler.playerIdCache.get(excludeTarget.toLowerCase(Locale.ROOT));
if (excludeUserText.length() == 0) {
excludeUserText = excludeUserText.append(userId);
}
else {
excludeUserText.append(",").append(userId);
}
}

excludeUsers = excludeUserText.toString();
}

// Specify actions to exclude from a:item
if ((lookup && actionList.size() == 0) || (actionList.contains(11) && actionList.size() == 1)) {
StringBuilder actionText = new StringBuilder();
actionText = actionText.append(ItemLogger.ITEM_BREAK);
actionText.append(",").append(ItemLogger.ITEM_DESTROY);
actionText.append(",").append(ItemLogger.ITEM_CREATE);
actionText.append(",").append(ItemLogger.ITEM_SELL);
actionText.append(",").append(ItemLogger.ITEM_BUY);
actionExclude = actionText.toString();
}

if (!actionList.isEmpty()) {
StringBuilder actionText = new StringBuilder();
for (Integer actionTarget : actionList) {
if (validActions.contains(actionTarget)) {
// If just looking up drops/pickups, remap the actions to the correct values
if (actionList.contains(11) && !actionList.contains(4)) {
if (actionTarget == ItemLogger.ITEM_REMOVE && !actionList.contains(ItemLogger.ITEM_DROP)) {
actionTarget = ItemLogger.ITEM_DROP;
}
else if (actionTarget == ItemLogger.ITEM_ADD && !actionList.contains(ItemLogger.ITEM_PICKUP)) {
actionTarget = ItemLogger.ITEM_PICKUP;
}
}

if (actionText.length() == 0) {
actionText = actionText.append(actionTarget);
}
else {
actionText.append(",").append(actionTarget);
}

// If selecting from co_item & co_container, add in actions for both transaction types
if (actionList.contains(11) && actionList.contains(4)) {
if (actionTarget == ItemLogger.ITEM_REMOVE) {
actionText.append(",").append(ItemLogger.ITEM_PICKUP);
actionText.append(",").append(ItemLogger.ITEM_REMOVE_ENDER);
actionText.append(",").append(ItemLogger.ITEM_CREATE);
actionText.append(",").append(ItemLogger.ITEM_BUY);
}
if (actionTarget == ItemLogger.ITEM_ADD) {
actionText.append(",").append(ItemLogger.ITEM_DROP);
actionText.append(",").append(ItemLogger.ITEM_ADD_ENDER);
actionText.append(",").append(ItemLogger.ITEM_THROW);
actionText.append(",").append(ItemLogger.ITEM_SHOOT);
actionText.append(",").append(ItemLogger.ITEM_BREAK);
actionText.append(",").append(ItemLogger.ITEM_DESTROY);
actionText.append(",").append(ItemLogger.ITEM_SELL);
}
}
// If just looking up drops/pickups, include ender chest transactions
else if (actionList.contains(11) && !actionList.contains(4)) {
if (actionTarget == ItemLogger.ITEM_DROP) {
actionText.append(",").append(ItemLogger.ITEM_ADD_ENDER);
actionText.append(",").append(ItemLogger.ITEM_THROW);
actionText.append(",").append(ItemLogger.ITEM_SHOOT);
}
if (actionTarget == ItemLogger.ITEM_PICKUP) {
actionText.append(",").append(ItemLogger.ITEM_REMOVE_ENDER);
}
}
}
}

action = actionText.toString();
}

for (Integer value : actionList) {
if (validActions.contains(value)) {
validAction = true;
}
}

if (restrictWorld) {
int wid = WorldUtils.getWorldId(location.getWorld().getName());
queryBlock = queryBlock + " wid=" + wid + " AND";
}

if (radius != null) {
Integer xmin = radius[1];
Integer xmax = radius[2];
Integer ymin = radius[3];
Integer ymax = radius[4];
Integer zmin = radius[5];
Integer zmax = radius[6];
String queryY = "";

if (ymin != null && ymax != null) {
queryY = " y >= '" + ymin + "' AND y <= '" + ymax + "' AND";
}

queryBlock = queryBlock + " x >= '" + xmin + "' AND x <= '" + xmax + "' AND z >= '" + zmin + "' AND z <= '" + zmax + "' AND" + queryY;
}
else if (actionList.contains(5)) {
int worldId = WorldUtils.getWorldId(location.getWorld().getName());
int x = (int) Math.floor(location.getX());
int z = (int) Math.floor(location.getZ());
int x2 = (int) Math.ceil(location.getX());
int z2 = (int) Math.ceil(location.getZ());

queryBlock = queryBlock + " wid=" + worldId + " AND (x = '" + x + "' OR x = '" + x2 + "') AND (z = '" + z + "' OR z = '" + z2 + "') AND y = '" + location.getBlockY() + "' AND";
}

if (validAction) {
queryBlock = queryBlock + " action IN(" + action + ") AND";
}
else if (inventoryQuery || actionExclude.length() > 0 || includeBlock.length() > 0 || includeEntity.length() > 0 || excludeBlock.length() > 0 || excludeEntity.length() > 0) {
queryBlock = queryBlock + " action NOT IN(-1) AND";
}

if (includeBlock.length() > 0 || includeEntity.length() > 0) {
queryBlock = queryBlock + " type IN(" + (includeBlock.length() > 0 ? includeBlock : "0") + ") AND";
}

if (excludeBlock.length() > 0 || excludeEntity.length() > 0) {
queryBlock = queryBlock + " type NOT IN(" + (excludeBlock.length() > 0 ? excludeBlock : "0") + ") AND";
}

if (uuids.length() > 0) {
queryBlock = queryBlock + " uuid IN(" + uuids + ") AND";
}

if (users.length() > 0) {
queryBlock = queryBlock + " user IN(" + users + ") AND";
}

if (excludeUsers.length() > 0) {
queryBlock = queryBlock + " user NOT IN(" + excludeUsers + ") AND";
}

if (startTime > 0) {
queryBlock = queryBlock + " time > '" + startTime + "' AND";
}

if (endTime > 0) {
queryBlock = queryBlock + " time <= '" + endTime + "' AND";
}

if (actionList.contains(10)) {
queryBlock = queryBlock + " action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0 OR LENGTH(line_5) > 0 OR LENGTH(line_6) > 0 OR LENGTH(line_7) > 0 OR LENGTH(line_8) > 0) AND";
}

if (messageFilter != null && messageFilter.length() > 0 && (actionList.contains(6) || actionList.contains(7))) {
queryBlock = queryBlock + " message LIKE '%" + messageFilter + "%' AND";
}

if (queryBlock.length() > 0) {
queryBlock = queryBlock.substring(0, queryBlock.length() - 4);
}

if (queryBlock.length() == 0) {
queryBlock = " 1";
}

queryEntity = queryBlock;
if (includeBlock.length() > 0 || includeEntity.length() > 0) {
queryEntity = queryEntity.replace("type IN(" + (includeBlock.length() > 0 ? includeBlock : "0") + ")", "type IN(" + (includeEntity.length() > 0 ? includeEntity : "0") + ")");
}
if (excludeBlock.length() > 0 || excludeEntity.length() > 0) {
queryEntity = queryEntity.replace("type NOT IN(" + (excludeBlock.length() > 0 ? excludeBlock : "0") + ")", "type NOT IN(" + (excludeEntity.length() > 0 ? excludeEntity : "0") + ")");
}

String baseQuery = ((!includeEntity.isEmpty() || !excludeEntity.isEmpty()) ? queryEntity : queryBlock);
if (limitOffset > -1 && limitCount > -1) {
queryLimit = " LIMIT " + limitOffset + ", " + limitCount + "";
unionLimit = " ORDER BY time DESC, id DESC LIMIT " + (limitOffset + limitCount) + "";
}

String rows = "rowid as id,time,user,wid,x,y,z,action,type,data,meta,blockdata,rolled_back";
String queryOrder = " ORDER BY rowid DESC";

if (actionList.contains(4) || actionList.contains(5)) {
queryTable = "container";
rows = "rowid as id,time,user,wid,x,y,z,action,type,data,rolled_back,amount,metadata";
}
else if (actionList.contains(6) || actionList.contains(7)) {
queryTable = "chat";
rows = "rowid as id,time,user,message";
if (PluginChannelHandshakeListener.getInstance().isPluginChannelPlayer(user)) {
rows += ",wid,x,y,z";
}

if (actionList.contains(7)) {
queryTable = "command";
}
}
else if (actionList.contains(8)) {
queryTable = "session";
rows = "rowid as id,time,user,wid,x,y,z,action";
}
else if (actionList.contains(9)) {
queryTable = "username_log";
rows = "rowid as id,time,uuid,user";
}
else if (actionList.contains(10)) {
queryTable = "sign";
rows = "rowid as id,time,user,wid,x,y,z,face,line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8";
}
else if (actionList.contains(11)) {
queryTable = "item";
rows = "rowid as id,time,user,wid,x,y,z,type,data as metadata,0 as data,amount,action,0 as rolled_back";
}

if (count) {
rows = "COUNT(*) as count";
queryLimit = " LIMIT 0, 3";
queryOrder = "";
unionLimit = "";
}

String unionSelect = "SELECT * FROM (";
if (Config.getGlobal().MYSQL) {
if (queryTable.equals("block")) {
if (includeBlock.length() > 0 || includeEntity.length() > 0) {
index = "USE INDEX(type) IGNORE INDEX(user,wid) ";
}
if (users.length() > 0) {
index = "USE INDEX(user) IGNORE INDEX(type,wid) ";
}
if (radius != null && (radius[2] - radius[1]) <= 50 && (radius[6] - radius[5]) <= 50) {
index = "USE INDEX(wid) IGNORE INDEX(type,user) ";
}
if ((restrictWorld && (users.length() > 0 || includeBlock.length() > 0 || includeEntity.length() > 0))) {
index = "IGNORE INDEX(PRIMARY) ";
}
}

unionSelect = "(";
}
else {
if (queryTable.equals("block")) {
if (includeBlock.length() > 0 || includeEntity.length() > 0) {
index = "INDEXED BY block_type_index ";
}
if (users.length() > 0) {
index = "INDEXED BY block_user_index ";
}
if (radius != null && (radius[2] - radius[1]) <= 50 && (radius[6] - radius[5]) <= 50) {
index = "INDEXED BY block_index ";
}
if ((restrictWorld && (users.length() > 0 || includeBlock.length() > 0 || includeEntity.length() > 0))) {
index = "";
}
}
}

boolean itemLookup = inventoryQuery;
if ((lookup && actionList.size() == 0) || (itemLookup && !actionList.contains(0))) {
if (!count) {
rows = "rowid as id,time,user,wid,x,y,z,type,meta as metadata,data,-1 as amount,action,rolled_back";
}

if (inventoryQuery) {
if (validAction) {
baseQuery = baseQuery.replace("action IN(" + action + ")", "action IN(1)");
}
else {
baseQuery = baseQuery.replace("action NOT IN(-1)", "action IN(1)");
}

if (!count) {
rows = "rowid as id,time,user,wid,x,y,z,type,meta as metadata,data,1 as amount,action,rolled_back";
}
}

if (includeBlock.length() > 0 || excludeBlock.length() > 0) {
baseQuery = baseQuery.replace("action NOT IN(-1)", "action NOT IN(3)"); // if block specified for include/exclude, filter out entity data
}

query = unionSelect + "SELECT " + "'0' as tbl," + rows + " FROM " + ConfigHandler.prefix + "block " + index + "WHERE" + baseQuery + unionLimit + ") UNION ALL ";
itemLookup = true;
}

if (itemLookup) {
if (!count) {
rows = "rowid as id,time,user,wid,x,y,z,type,metadata,data,amount,action,rolled_back";
}
query = query + unionSelect + "SELECT " + "'1' as tbl," + rows + " FROM " + ConfigHandler.prefix + "container WHERE" + queryBlock + unionLimit + ") UNION ALL ";

if (!count) {
rows = "rowid as id,time,user,wid,x,y,z,type,data as metadata,0 as data,amount,action,rolled_back";
queryOrder = " ORDER BY time DESC, tbl DESC, id DESC";
}

if (actionExclude.length() > 0) {
queryBlock = queryBlock.replace("action NOT IN(-1)", "action NOT IN(" + actionExclude + ")");
}

query = query + unionSelect + "SELECT " + "'2' as tbl," + rows + " FROM " + ConfigHandler.prefix + "item WHERE" + queryBlock + unionLimit + ")";
}

if (query.length() == 0) {
if (actionExclude.length() > 0) {
baseQuery = baseQuery.replace("action NOT IN(-1)", "action NOT IN(" + actionExclude + ")");
}

query = "SELECT " + "'0' as tbl," + rows + " FROM " + ConfigHandler.prefix + queryTable + " " + index + "WHERE" + baseQuery;
}

query = query + queryOrder + queryLimit + "";
results = statement.executeQuery(query);
}
catch (Exception e) {
e.printStackTrace();
}

return results;
}

Check failure on line 696 in src/main/java/net/coreprotect/database/LookupRaw.java

View check run for this annotation

codefactor.io / CodeFactor

src/main/java/net/coreprotect/database/LookupRaw.java#L230-L696

Very Complex Method
}