mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-10-31 07:39:42 +01:00
#1368 Improve the look of /authme debug
- Add a colored title for each command execution within /authme debug - Fit more texts on one line
This commit is contained in:
parent
c6fbc1187f
commit
20ca4f9dc9
@ -42,6 +42,7 @@ class CountryLookup implements DebugSection {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> arguments) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe country lookup");
|
||||
if (arguments.isEmpty()) {
|
||||
sender.sendMessage("Check player: /authme debug cty Bobby");
|
||||
sender.sendMessage("Check IP address: /authme debug cty 127.123.45.67");
|
||||
|
@ -10,6 +10,7 @@ import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.initialization.factory.SingletonStore;
|
||||
import fr.xephi.authme.permission.DebugSectionPermissions;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -47,6 +48,7 @@ class DataStatistics implements DebugSection {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> arguments) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe statistics");
|
||||
sender.sendMessage("LimboPlayers in memory: " + applyToLimboPlayersMap(limboService, Map::size));
|
||||
sender.sendMessage("PlayerCache size: " + playerCache.getLogged() + " (= logged in players)");
|
||||
|
||||
@ -68,11 +70,10 @@ class DataStatistics implements DebugSection {
|
||||
}
|
||||
|
||||
private void outputInjectorStats(CommandSender sender) {
|
||||
sender.sendMessage(
|
||||
String.format("Singleton Java classes: %d (Reloadable: %d / SettingsDependent: %d / HasCleanup: %d)",
|
||||
singletonStore.retrieveAllOfType().size(),
|
||||
singletonStore.retrieveAllOfType(Reloadable.class).size(),
|
||||
singletonStore.retrieveAllOfType(SettingsDependent.class).size(),
|
||||
singletonStore.retrieveAllOfType(HasCleanup.class).size()));
|
||||
sender.sendMessage("Singleton Java classes: " + singletonStore.retrieveAllOfType().size());
|
||||
sender.sendMessage(String.format("(Reloadable: %d / SettingsDependent: %d / HasCleanup: %d)",
|
||||
singletonStore.retrieveAllOfType(Reloadable.class).size(),
|
||||
singletonStore.retrieveAllOfType(SettingsDependent.class).size(),
|
||||
singletonStore.retrieveAllOfType(HasCleanup.class).size()));
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ public class DebugCommand implements ExecutableCommand {
|
||||
}
|
||||
|
||||
private void sendAvailableSections(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe debug utils");
|
||||
sender.sendMessage("Sections available to you:");
|
||||
long availableSections = getSections().values().stream()
|
||||
.filter(section -> permissionsManager.hasPermission(sender, section.getRequiredPermission()))
|
||||
|
@ -42,11 +42,12 @@ class HasPermissionChecker implements DebugSection {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Checks if player has given permission: /authme debug perm bobby my.perm";
|
||||
return "Checks if a player has a given permission";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> arguments) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe permission check");
|
||||
if (arguments.size() < 2) {
|
||||
sender.sendMessage("Check if a player has permission:");
|
||||
sender.sendMessage("Example: /authme debug perm bobby my.perm.node");
|
||||
|
@ -40,7 +40,7 @@ class InputValidator implements DebugSection {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Check if email / password is valid according to your settings";
|
||||
return "Checks if your config.yml allows a password / email";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,16 +68,18 @@ class InputValidator implements DebugSection {
|
||||
}
|
||||
|
||||
private void displayUsageHint(CommandSender sender) {
|
||||
sender.sendMessage("You can define forbidden emails and passwords in your config.yml");
|
||||
sender.sendMessage("This command allows you to test some of the values:");
|
||||
sender.sendMessage("/authme debug valid pass test1234 -- test if 'test1234' is allowed password");
|
||||
sender.sendMessage("/authme debug valid mail t@t.tld -- test if 't@t.tld' is allowed email");
|
||||
sender.sendMessage("/authme debug valid name bobby1 -- test if 'bobby1' is allowed username");
|
||||
sender.sendMessage(ChatColor.BLUE + "Validation tests");
|
||||
sender.sendMessage("You can define forbidden emails and passwords in your config.yml."
|
||||
+ " You can test your settings with this command.");
|
||||
final String command = ChatColor.GOLD + "/authme debug valid";
|
||||
sender.sendMessage(" Use " + command + " pass <pass>" + ChatColor.RESET + " to check a password");
|
||||
sender.sendMessage(" Use " + command + " mail <mail>" + ChatColor.RESET + " to check an email");
|
||||
sender.sendMessage(" Use " + command + " name <name>" + ChatColor.RESET + " to check a username");
|
||||
}
|
||||
|
||||
private void validatePassword(CommandSender sender, String password) {
|
||||
ValidationResult validationResult = validationService.validatePassword(password, "");
|
||||
sender.sendMessage("Validation of password '" + password + "' returned:");
|
||||
sender.sendMessage(ChatColor.BLUE + "Validation of password '" + password + "'");
|
||||
if (validationResult.hasError()) {
|
||||
messages.send(sender, validationResult.getMessageKey(), validationResult.getArgs());
|
||||
} else {
|
||||
@ -87,7 +89,7 @@ class InputValidator implements DebugSection {
|
||||
|
||||
private void validateEmail(CommandSender sender, String email) {
|
||||
boolean isValidEmail = validationService.validateEmail(email);
|
||||
sender.sendMessage("Validation of email '" + email + "' returned:");
|
||||
sender.sendMessage(ChatColor.BLUE + "Validation of email '" + email + "'");
|
||||
if (isValidEmail) {
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Valid email!");
|
||||
} else {
|
||||
@ -96,7 +98,7 @@ class InputValidator implements DebugSection {
|
||||
}
|
||||
|
||||
private void validateUsername(CommandSender sender, String username) {
|
||||
sender.sendMessage("Validation of username '" + username + "' returned:");
|
||||
sender.sendMessage(ChatColor.BLUE + "Validation of username '" + username + "'");
|
||||
try {
|
||||
onJoinVerifier.checkIsValidName(username);
|
||||
sender.sendMessage("Valid username!");
|
||||
|
@ -50,6 +50,7 @@ class LimboPlayerViewer implements DebugSection {
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> arguments) {
|
||||
if (arguments.isEmpty()) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe limbo viewer");
|
||||
sender.sendMessage("/authme debug limbo <player>: show a player's limbo info");
|
||||
sender.sendMessage("Available limbo records: " + applyToLimboPlayersMap(limboService, Map::keySet));
|
||||
return;
|
||||
@ -59,11 +60,12 @@ class LimboPlayerViewer implements DebugSection {
|
||||
Player player = bukkitService.getPlayerExact(arguments.get(0));
|
||||
LimboPlayer diskLimbo = player != null ? limboPersistence.getLimboPlayer(player) : null;
|
||||
if (memoryLimbo == null && player == null) {
|
||||
sender.sendMessage("No limbo info and no player online with name '" + arguments.get(0) + "'");
|
||||
sender.sendMessage(ChatColor.BLUE + "No AuthMe limbo data");
|
||||
sender.sendMessage("No limbo data and no player online with name '" + arguments.get(0) + "'");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GOLD + "Showing player / limbo / disk limbo info for '" + arguments.get(0) + "'");
|
||||
sender.sendMessage(ChatColor.BLUE + "Player / limbo / disk limbo info for '" + arguments.get(0) + "'");
|
||||
new InfoDisplayer(sender, player, memoryLimbo, diskLimbo)
|
||||
.sendEntry("Is op", Player::isOp, LimboPlayer::isOperator)
|
||||
.sendEntry("Walk speed", Player::getWalkSpeed, LimboPlayer::getWalkSpeed)
|
||||
|
@ -63,7 +63,7 @@ class MySqlDefaultChanger implements DebugSection {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Add or remove the default value of a column for MySQL";
|
||||
return "Add or remove the default value of MySQL columns";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,6 +85,7 @@ class MySqlDefaultChanger implements DebugSection {
|
||||
} else if (operation == null || column == null) {
|
||||
displayUsageHints(sender);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.BLUE + "[AuthMe] MySQL change '" + column + "'");
|
||||
try (Connection con = getConnection(mySql)) {
|
||||
switch (operation) {
|
||||
case ADD:
|
||||
@ -172,6 +173,7 @@ class MySqlDefaultChanger implements DebugSection {
|
||||
}
|
||||
|
||||
private void showColumnDetails(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.BLUE + "MySQL column details");
|
||||
final String tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
|
||||
try (Connection con = getConnection(mySql)) {
|
||||
final DatabaseMetaData metaData = con.getMetaData();
|
||||
@ -196,6 +198,7 @@ class MySqlDefaultChanger implements DebugSection {
|
||||
* @param sender the sender issuing the command
|
||||
*/
|
||||
private void displayUsageHints(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.BLUE + "MySQL column changer");
|
||||
sender.sendMessage("Adds or removes a NOT NULL constraint for a column.");
|
||||
sender.sendMessage("Examples: add a NOT NULL constraint with");
|
||||
sender.sendMessage(" /authme debug mysqldef add <column>");
|
||||
|
@ -4,6 +4,7 @@ import fr.xephi.authme.permission.DebugSectionPermissions;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -30,6 +31,7 @@ class PermissionGroups implements DebugSection {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> arguments) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe permission groups");
|
||||
String name = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if (player == null) {
|
||||
|
@ -39,6 +39,7 @@ class PlayerAuthViewer implements DebugSection {
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> arguments) {
|
||||
if (arguments.isEmpty()) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe database viewer");
|
||||
sender.sendMessage("Enter player name to view his data in the database.");
|
||||
sender.sendMessage("Example: /authme debug db Bobby");
|
||||
return;
|
||||
@ -46,6 +47,7 @@ class PlayerAuthViewer implements DebugSection {
|
||||
|
||||
PlayerAuth auth = dataSource.getAuth(arguments.get(0));
|
||||
if (auth == null) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe database viewer");
|
||||
sender.sendMessage("No record exists for '" + arguments.get(0) + "'");
|
||||
} else {
|
||||
displayAuthToSender(auth, sender);
|
||||
@ -64,7 +66,7 @@ class PlayerAuthViewer implements DebugSection {
|
||||
* @param sender the sender to send the messages to
|
||||
*/
|
||||
private void displayAuthToSender(PlayerAuth auth, CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.GOLD + "[AuthMe] Player " + auth.getNickname() + " / " + auth.getRealName());
|
||||
sender.sendMessage(ChatColor.BLUE + "[AuthMe] Player " + auth.getNickname() + " / " + auth.getRealName());
|
||||
sender.sendMessage("Email: " + auth.getEmail() + ". IP: " + auth.getLastIp() + ". Group: " + auth.getGroupId());
|
||||
sender.sendMessage("Quit location: "
|
||||
+ formatLocation(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld()));
|
||||
|
@ -6,6 +6,7 @@ import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -42,6 +43,7 @@ class SpawnLocationViewer implements DebugSection {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> arguments) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe spawn location viewer");
|
||||
if (arguments.isEmpty()) {
|
||||
showGeneralInfo(sender);
|
||||
} else if ("?".equals(arguments.get(0))) {
|
||||
|
@ -44,6 +44,7 @@ class TestEmailSender implements DebugSection {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> arguments) {
|
||||
sender.sendMessage(ChatColor.BLUE + "AuthMe test email sender");
|
||||
if (!sendMailSsl.hasAllInformation()) {
|
||||
sender.sendMessage(ChatColor.RED + "You haven't set all required configurations in config.yml "
|
||||
+ "for sending emails. Please check your config.yml");
|
||||
|
@ -12,6 +12,7 @@ import fr.xephi.authme.initialization.HasCleanup;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.initialization.factory.SingletonStore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -80,7 +81,9 @@ public class DataStatisticsTest {
|
||||
ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sender, atLeastOnce()).sendMessage(stringCaptor.capture());
|
||||
assertThat(stringCaptor.getAllValues(), containsInAnyOrder(
|
||||
"Singleton Java classes: 7 (Reloadable: 4 / SettingsDependent: 3 / HasCleanup: 2)",
|
||||
ChatColor.BLUE + "AuthMe statistics",
|
||||
"Singleton Java classes: 7",
|
||||
"(Reloadable: 4 / SettingsDependent: 3 / HasCleanup: 2)",
|
||||
"LimboPlayers in memory: 1",
|
||||
"Total players in DB: 219",
|
||||
"PlayerCache size: 12 (= logged in players)"));
|
||||
|
@ -4,6 +4,7 @@ import fr.xephi.authme.initialization.factory.Factory;
|
||||
import fr.xephi.authme.permission.DebugSectionPermissions;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -85,11 +86,12 @@ public class DebugCommandTest {
|
||||
verify(permissionsManager, atLeast(MIN_DEBUG_SECTIONS)).hasPermission(eq(sender), any(DebugSectionPermissions.class));
|
||||
|
||||
ArgumentCaptor<String> strCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sender, times(3)).sendMessage(strCaptor.capture());
|
||||
verify(sender, times(4)).sendMessage(strCaptor.capture());
|
||||
assertThat(strCaptor.getAllValues(), contains(
|
||||
containsString("Sections available to you"),
|
||||
equalTo(ChatColor.BLUE + "AuthMe debug utils"),
|
||||
equalTo("Sections available to you:"),
|
||||
containsString("stats: Outputs general data statistics"),
|
||||
containsString("valid: Check if email / password is valid")));
|
||||
containsString("valid: Checks if your config.yml allows a password / email")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -106,8 +108,9 @@ public class DebugCommandTest {
|
||||
verify(permissionsManager, atLeast(MIN_DEBUG_SECTIONS)).hasPermission(eq(sender), any(DebugSectionPermissions.class));
|
||||
|
||||
ArgumentCaptor<String> strCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sender, times(2)).sendMessage(strCaptor.capture());
|
||||
verify(sender, times(3)).sendMessage(strCaptor.capture());
|
||||
assertThat(strCaptor.getAllValues(), contains(
|
||||
equalTo(ChatColor.BLUE + "AuthMe debug utils"),
|
||||
equalTo("Sections available to you:"),
|
||||
containsString("You don't have permission to view any debug section")));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user