Removed Condition class

This commit is contained in:
Rsl1122 2018-05-25 10:18:56 +03:00
parent ef781723b3
commit e8b412762b
22 changed files with 147 additions and 219 deletions

View File

@ -7,10 +7,10 @@ package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.utilities.Verify;
/**
* Command used for testing functions that are too difficult to unit test.
@ -27,17 +27,10 @@ public class DevCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String cmd, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return;
}
Verify.isTrue(args.length >= 1, () -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
String feature = args[0];
switch (feature) {
case "connection":
if (!Condition.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
break;
}
sender.sendMessage("[Plan] No implementation.");
break;
case "web":
ConnectionSystem connectionSystem = ConnectionSystem.getInstance();
String accessAddress = connectionSystem.getMainAddress();

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
@ -41,6 +42,7 @@ public class InfoCommand extends CommandNode {
ball + mColor + " Version: " + sColor + plugin.getVersion(),
ball + mColor + " Up to date: " + sColor + upToDate,
ball + mColor + " Active Database: " + tColor + Database.getActive().getConfigName(),
ball + mColor + " Connected to Bungee: " + tColor + (ConnectionSystem.getInstance().isServerAvailable() ? "Yes" : "No"),
Locale.get(Msg.CMD_CONSTANT_FOOTER).toString()
};
sender.sendMessage(messages);

View File

@ -9,7 +9,6 @@ import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
import com.djrapitops.plugin.api.utility.log.Log;
@ -19,7 +18,6 @@ import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import org.bukkit.ChatColor;
import java.util.UUID;
@ -51,14 +49,18 @@ public class InspectCommand extends CommandNode {
@Override
public void run() {
try {
Database activeDB = Database.getActive();
UUID uuid = UUIDUtility.getUUIDOf(playerName);
if (!Condition.isTrue(Verify.notNull(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString(), sender)) {
if (uuid == null) {
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString());
return;
}
if (!Condition.isTrue(activeDB.check().isPlayerRegistered(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString(), sender)) {
Database activeDB = Database.getActive();
if (!activeDB.check().isPlayerRegistered(uuid)) {
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString());
return;
}
if (CommandUtils.isPlayer(sender) && WebServer.getInstance().isAuthRequired()) {
boolean senderHasWebUser = activeDB.check().doesWebUserExists(sender.getName());

View File

@ -8,7 +8,6 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
@ -20,7 +19,6 @@ import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.settings.DefaultMessages;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import java.util.UUID;
@ -61,18 +59,20 @@ public class QInspectCommand extends CommandNode {
public void run() {
try {
UUID uuid = UUIDUtility.getUUIDOf(playerName);
if (!Condition.isTrue(Verify.notNull(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString(), sender)) {
if (uuid == null) {
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString());
return;
}
Database database = Database.getActive();
if (!Condition.isTrue(database.check().isPlayerRegistered(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString(), sender)) {
if (!database.check().isPlayerRegistered(uuid)) {
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString());
return;
}
PlayerProfile playerProfile = database.fetch().getPlayerProfile(uuid);
sendMessages(sender, playerProfile);
} catch (DBException ex) {
Log.toLog(this.getClass(), ex);
} finally {
@ -97,7 +97,7 @@ public class QInspectCommand extends CommandNode {
ActivityIndex activityIndex = profile.getActivityIndex(now);
sender.sendMessage(colT + ball + " " + colM + " Activity Index: " + colS + activityIndex.getFormattedValue() + " | " + activityIndex.getColor());
sender.sendMessage(colT + ball + " " + colM + " Activity Index: " + colS + activityIndex.getFormattedValue() + " | " + activityIndex.getGroup());
sender.sendMessage(colT + ball + " " + colM + " Registered: " + colS + FormatUtils.formatTimeStampYear(profile.getRegistered()));
sender.sendMessage(colT + ball + " " + colM + " Last Seen: " + colS + FormatUtils.formatTimeStampYear(profile.getLastSeen()));
sender.sendMessage(colT + ball + " " + colM + " Logged in from: " + colS + profile.getMostRecentGeoInfo().getGeolocation());

View File

@ -5,7 +5,6 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plan.utilities.PassEncryptUtil;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
@ -15,6 +14,7 @@ import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import java.util.Arrays;
@ -31,6 +31,10 @@ import java.util.Arrays;
*/
public class RegisterCommand extends CommandNode {
private final String notEnoughArgsMsg;
private final String hashErrorMsg;
private final String permLvlErrorMsg;
public RegisterCommand() {
// No Permission Requirement
super("register", "", CommandType.PLAYER_OR_ARGS);
@ -40,13 +44,14 @@ public class RegisterCommand extends CommandNode {
if (Check.isBukkitAvailable()) {
setupFilter();
}
notEnoughArgsMsg = Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse("(3) " + Arrays.toString(getArguments()));
hashErrorMsg = "§cPassword hash error.";
permLvlErrorMsg = "§cIncorrect perm level, not a number: ";
}
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
String notEnoughArgsMsg = Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse("(3) " + Arrays.toString(getArguments()));
String hashErrorMsg = "§cPassword hash error.";
String permLvlErrorMsg = "§cIncorrect perm level, not a number: ";
try {
if (CommandUtils.isPlayer(sender)) {
Log.info(sender.getName() + " issued WebUser register command.");
@ -58,23 +63,23 @@ public class RegisterCommand extends CommandNode {
Log.toLog(this.getClass().getSimpleName(), e);
sender.sendMessage(hashErrorMsg);
} catch (NumberFormatException e) {
sender.sendMessage(permLvlErrorMsg + args[2]);
throw new NumberFormatException(args[2]);
} catch (Exception e) {
Log.toLog(this.getClass().getSimpleName(), e);
}
}
private void consoleRegister(String[] args, ISender sender, String notEnoughArgsMsg) throws PassEncryptUtil.CannotPerformOperationException {
if (Condition.isTrue(args.length >= 3, notEnoughArgsMsg, sender)) {
int permLevel;
permLevel = Integer.parseInt(args[2]);
String passHash = PassEncryptUtil.createHash(args[0]);
registerUser(new WebUser(args[1], passHash, permLevel), sender);
}
Verify.isTrue(args.length >= 3, () -> new IllegalArgumentException(notEnoughArgsMsg));
int permLevel;
permLevel = Integer.parseInt(args[2]);
String passHash = PassEncryptUtil.createHash(args[0]);
registerUser(new WebUser(args[1], passHash, permLevel), sender);
}
private void playerRegister(String[] args, ISender sender) throws PassEncryptUtil.CannotPerformOperationException {
final String notEnoughArgsMsg = Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse("(1 or 3) " + super.getArguments());
final String notEnoughArgsMsg = Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse("(1 or 3) " + Arrays.toString(this.getArguments()));
boolean registerSenderAsUser = args.length == 1;
if (registerSenderAsUser) {
String user = sender.getName();
@ -114,7 +119,8 @@ public class RegisterCommand extends CommandNode {
try {
Database database = Database.getActive();
boolean userExists = database.check().doesWebUserExists(userName);
if (!Condition.isTrue(!userExists, existsMsg, sender)) {
if (userExists) {
sender.sendMessage(existsMsg);
return;
}
database.save().webUser(webUser);

View File

@ -3,7 +3,6 @@ package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
@ -33,9 +32,8 @@ public class SearchCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return;
}
Verify.isTrue(args.length >= 1, () -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
sender.sendMessage(Locale.get(Msg.CMD_INFO_SEARCHING).toString());
runSearchTask(args, sender);

View File

@ -6,7 +6,6 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plan.utilities.ManageUtils;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
@ -16,6 +15,8 @@ import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import java.util.Arrays;
/**
* This manage subcommand is used to backup a database to a .db file.
*
@ -34,44 +35,39 @@ public class ManageBackupCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
try {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
return;
}
String dbName = args[0].toLowerCase();
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
return;
}
final Database database = DBSystem.getActiveDatabaseByName(dbName);
boolean isCorrectDB = Verify.equalsOne(dbName, "sqlite", "mysql");
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName));
Database database = DBSystem.getActiveDatabaseByName(dbName);
Verify.nullCheck(database, NullPointerException::new);
// If DB is null return
if (!Condition.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
Log.error(dbName + " was null!");
return;
}
Log.debug("Backup", "Start");
runBackupTask(sender, args, database);
} catch (DBInitException | NullPointerException e) {
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
} finally {
Log.logDebug("Backup");
}
}
private void runBackupTask(ISender sender, String[] args, final Database database) {
private void runBackupTask(ISender sender, String[] args, Database database) {
RunnableFactory.createNew(new AbsRunnable("BackupTask") {
@Override
public void run() {
try {
Log.debug("Backup", "Start");
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
ManageUtils.backup(args[0], database);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
} catch (Exception e) {
Log.toLog(this.getClass(), e);
Log.toLog(ManageBackupCommand.class, e);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
} finally {
Log.logDebug("Backup");
this.cancel();
}
}

View File

@ -9,7 +9,6 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
@ -39,18 +38,17 @@ public class ManageClearCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return;
}
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
String dbName = args[0].toLowerCase();
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName));
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
return;
}
if (!Condition.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[0])), sender)) {
if (!Verify.contains("-a", args)) {
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[0])));
return;
}

View File

@ -4,10 +4,12 @@ import com.djrapitops.plan.system.listeners.bukkit.PlayerOnlineListener;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.utilities.Verify;
import java.util.Arrays;
/**
* This manage SubCommand is used to disable some features of the plugin temporarily.
@ -27,9 +29,9 @@ public class ManageDisableCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
return;
}
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
switch (args[0].toLowerCase()) {
case "kickcount":
PlayerOnlineListener.setCountKicks(false);

View File

@ -7,7 +7,6 @@ import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
@ -36,32 +35,29 @@ public class ManageHotSwapCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return;
}
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
String dbName = args[0].toLowerCase();
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
return;
}
boolean isCorrectDB = Verify.equalsOne(dbName, "sqlite", "mysql");
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName));
if (Condition.isTrue(dbName.equals(Database.getActive().getConfigName()), Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString(), sender)) {
return;
}
Verify.isFalse(dbName.equals(Database.getActive().getConfigName()),
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString()));
try {
final Database database = DBSystem.getActiveDatabaseByName(dbName);
// If DB is null return
if (!Condition.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
Log.error(dbName + " was null!");
return;
}
Verify.nullCheck(database, NullPointerException::new);
if (!database.isOpen()) {
return;
}
} catch (NullPointerException e) {
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
return;
} catch (Exception e) {
Log.toLog(this.getClass(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());

View File

@ -5,12 +5,12 @@ import com.djrapitops.plan.system.processing.importing.importers.Importer;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import java.util.Arrays;
@ -31,9 +31,8 @@ public class ManageImportCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG) + " " + Arrays.toString(this.getArguments()), sender)) {
return;
}
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
String importArg = args[0];

View File

@ -5,7 +5,6 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plan.utilities.ManageUtils;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
@ -15,6 +14,8 @@ import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import java.util.Arrays;
/**
* This manage SubCommand is used to move all data from one database to another.
* <p>
@ -33,29 +34,24 @@ public class ManageMoveCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
return;
}
Verify.isTrue(args.length >= 2,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
String fromDB = args[0].toLowerCase();
boolean isCorrectDB = "sqlite".equals(fromDB) || "mysql".equals(fromDB);
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + fromDB, sender)) {
return;
}
boolean isCorrectDB = Verify.equalsOne(fromDB, "sqlite", "mysql");
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + fromDB));
String toDB = args[1].toLowerCase();
isCorrectDB = "sqlite".equals(toDB) || "mysql".equals(toDB);
isCorrectDB = Verify.equalsOne(toDB, "sqlite", "mysql");
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + fromDB));
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + toDB, sender)) {
return;
}
Verify.isFalse(fromDB.equalsIgnoreCase(toDB),
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString()));
if (!Condition.isTrue(!Verify.equalsIgnoreCase(fromDB, toDB), Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString(), sender)) {
return;
}
if (!Condition.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[1])), sender)) {
if (!Verify.contains("-a", args)) {
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_OVERWRITE).parse(args[0])));
return;
}
@ -77,9 +73,13 @@ public class ManageMoveCommand extends CommandNode {
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
ManageUtils.clearAndCopy(toDatabase, fromDatabase);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_MOVE_SUCCESS).toString());
boolean movedToCurrentDatabase = Verify.equalsIgnoreCase(toDatabase.getConfigName(), Database.getActive().getConfigName());
Condition.isTrue(!movedToCurrentDatabase, Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString(), sender);
boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(Database.getActive().getConfigName());
if (movingToCurrentDB) {
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString());
}
} catch (Exception e) {
Log.toLog(this.getClass(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());

View File

@ -5,7 +5,6 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
import com.djrapitops.plugin.api.utility.log.Log;
@ -35,9 +34,8 @@ public class ManageRemoveCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return;
}
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.MANAGE);
@ -50,20 +48,20 @@ public class ManageRemoveCommand extends CommandNode {
public void run() {
try {
UUID uuid = UUIDUtility.getUUIDOf(playerName);
String message = Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString();
if (!Condition.isTrue(Verify.notNull(uuid), message, sender)) {
if (uuid == null) {
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString());
return;
}
message = Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString();
Database database = Database.getActive();
if (!Condition.isTrue(database.check().isPlayerRegistered(uuid), message, sender)) {
if (!database.check().isPlayerRegistered(uuid)) {
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString());
return;
}
message = Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(Database.getActive().getConfigName()));
if (!Condition.isTrue(Verify.contains("-a", args), message, sender)) {
if (!Verify.contains("-a", args)) {
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(database.getName())));
return;
}

View File

@ -7,7 +7,6 @@ import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plan.utilities.ManageUtils;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
@ -40,18 +39,16 @@ public class ManageRestoreCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments())), sender)) {
return;
}
Verify.isTrue(args.length >= 2,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
String db = args[1].toLowerCase();
boolean isCorrectDB = "sqlite".equals(db) || "mysql".equals(db);
boolean isCorrectDB = Verify.equalsOne(db, "sqlite", "mysql");
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB).toString()));
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + db, sender)) {
return;
}
if (!Condition.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REWRITE).parse(args[1])), sender)) {
if (!Verify.contains("-a", args)) {
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REWRITE).parse(args[1])));
return;
}
@ -73,7 +70,9 @@ public class ManageRestoreCommand extends CommandNode {
boolean containsDBFileExtension = backupDBName.endsWith(".db");
File backupDBFile = new File(plugin.getDataFolder(), backupDBName + (containsDBFileExtension ? "" : ".db"));
if (!Condition.isTrue(Verify.exists(backupDBFile), Locale.get(Msg.MANAGE_FAIL_FILE_NOT_FOUND) + " " + args[0], sender)) {
if (!backupDBFile.exists()) {
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FILE_NOT_FOUND) + " " + args[0]);
return;
}

View File

@ -8,11 +8,11 @@ import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.system.webserver.WebServerSystem;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.utilities.Verify;
/**
* This manage SubCommand is used to request settings from Bungee so that connection can be established.
@ -31,9 +31,9 @@ public class ManageSetupCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return;
}
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
if (!WebServerSystem.isWebServerEnabled()) {
sender.sendMessage("§cWebServer is not enabled on this server! Make sure it enables on boot!");
return;

View File

@ -5,14 +5,15 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import org.bukkit.ChatColor;
import com.djrapitops.plugin.utilities.Verify;
import java.util.Arrays;
/**
* Subcommand for checking WebUser permission level.
@ -30,9 +31,9 @@ public class WebCheckCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
return;
}
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
Database database = Database.getActive();
String user = args[0];
@ -40,7 +41,8 @@ public class WebCheckCommand extends CommandNode {
@Override
public void run() {
try {
if (!Condition.isTrue(database.check().doesWebUserExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
if (!database.check().doesWebUserExists(user)) {
sender.sendMessage("§c[Plan] User Doesn't exist.");
return;
}
WebUser info = database.fetch().getWebUser(user);

View File

@ -4,14 +4,15 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import net.md_5.bungee.api.ChatColor;
import com.djrapitops.plugin.utilities.Verify;
import java.util.Arrays;
/**
* Subcommand for deleting a WebUser.
@ -29,9 +30,9 @@ public class WebDeleteCommand extends CommandNode {
@Override
public void onCommand(ISender sender, String commandLabel, String[] args) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
return;
}
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
Database database = Database.getActive();
String user = args[0];
@ -39,7 +40,8 @@ public class WebDeleteCommand extends CommandNode {
@Override
public void run() {
try {
if (!Condition.isTrue(database.check().doesWebUserExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
if (!database.check().doesWebUserExists(user)) {
sender.sendMessage("§c[Plan] User Doesn't exist.");
return;
}
database.remove().webUser(user);

View File

@ -172,7 +172,7 @@ public class Session {
* Used to get the ID of the session in the Database.
*
* @return ID if present.
* @throws NullPointerException if Session was not fetched from DB. Condition using {@code isFetchedFromDB}
* @throws NullPointerException if Session was not fetched from DB. Check {@code isFetchedFromDB} first.
*/
public int getSessionID() {
return sessionID != null ? sessionID : -1;

View File

@ -98,7 +98,7 @@ public class SessionCache {
}
/**
* Condition if a session is player's first session on the server.
* Check if a session is player's first session on the server.
*
* @param uuid UUID of the player
* @return true / false

View File

@ -1,63 +0,0 @@
package com.djrapitops.plan.utilities;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.ISender;
/**
* Class containing static check methods with message sending capabilities if
* the check is false.
*
* @author Rsl1122
*/
public class Condition {
/**
* Constructor used to hide the public constructor
*/
private Condition() {
throw new IllegalStateException("Utility class");
}
/**
* If check is false, send message.
*
* @param condition Condition.
* @param message Message to send if Condition is false
* @return Condition
*/
public static boolean isTrue(boolean condition, String message) {
if (!condition) {
Log.infoColor(message);
}
return condition;
}
/**
* If check is false, send message to sender.
*
* @param condition Condition.
* @param message Message to send if Condition is false
* @param sender Sender to send message to
* @return Condition
*/
public static boolean isTrue(boolean condition, String message, ISender sender) {
if (!condition) {
sender.sendMessage(message);
}
return condition;
}
/**
* If check is false, send error message.
*
* @param condition Condition.
* @param message Message to send if Condition is false
* @return Condition
*/
public static boolean errorIfFalse(boolean condition, String message) {
if (!condition) {
Log.error(message);
}
return condition;
}
}

View File

@ -14,8 +14,10 @@ import com.djrapitops.plugin.command.ISender;
import java.io.Closeable;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;
/**
* Utility method class containing various static methods.
@ -96,10 +98,6 @@ public class MiscUtils {
return matches;
}
public static <T> List<T> flatMap(Collection<? extends Collection<T>> coll) {
return coll.stream().flatMap(Collection::stream).collect(Collectors.toList());
}
public static void close(Closeable... close) {
for (Closeable c : close) {
if (c != null) {

View File

@ -110,7 +110,7 @@ public class AnalysisUtils {
day.setTimeInMillis(start);
int hourOfDay = day.get(Calendar.HOUR_OF_DAY); // 0 AM is 0
int dayOfWeek = day.get(Calendar.DAY_OF_WEEK) - 2; // Monday is 0, Sunday is -1
if (hourOfDay == 24) { // Condition if hour is 24 (Should be impossible but.)
if (hourOfDay == 24) { // If hour is 24 (Should be impossible but.)
hourOfDay = 0;
dayOfWeek += 1;
}