#923 Create /authme purgeplayer command

- Create command to purge a specific player name
- Update docs
This commit is contained in:
ljacqu
2017-04-29 18:31:37 +02:00
parent 88d839cab4
commit 578f63b944
13 changed files with 211 additions and 27 deletions
@@ -16,6 +16,7 @@ import fr.xephi.authme.command.executable.authme.MessagesCommand;
import fr.xephi.authme.command.executable.authme.PurgeBannedPlayersCommand;
import fr.xephi.authme.command.executable.authme.PurgeCommand;
import fr.xephi.authme.command.executable.authme.PurgeLastPositionCommand;
import fr.xephi.authme.command.executable.authme.PurgePlayerCommand;
import fr.xephi.authme.command.executable.authme.RegisterAdminCommand;
import fr.xephi.authme.command.executable.authme.ReloadCommand;
import fr.xephi.authme.command.executable.authme.SetEmailCommand;
@@ -234,6 +235,18 @@ public class CommandInitializer {
.executableCommand(PurgeCommand.class)
.register();
// Purge player command
CommandDescription.builder()
.parent(AUTHME_BASE)
.labels("purgeplayer")
.description("Purges the data of one player")
.detailedDescription("Purges data of the given player.")
.withArgument("player", "The player to purge", false)
.withArgument("options", "'force' to run without checking if player is registered", true)
.permission(AdminPermission.PURGE_PLAYER)
.executableCommand(PurgePlayerCommand.class)
.register();
// Backup command
CommandDescription.builder()
.parent(AUTHME_BASE)
@@ -0,0 +1,46 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.task.purge.PurgeExecutor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import java.util.List;
import static java.util.Collections.singletonList;
/**
* Command to purge a player.
*/
public class PurgePlayerCommand implements ExecutableCommand {
@Inject
private PurgeExecutor purgeExecutor;
@Inject
private BukkitService bukkitService;
@Inject
private DataSource dataSource;
@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
String option = arguments.size() > 1 ? arguments.get(1) : null;
bukkitService.runTaskOptionallyAsync(
() -> executeCommand(sender, arguments.get(0), option));
}
private void executeCommand(CommandSender sender, String name, String option) {
if ("force".equals(option) || !dataSource.isAuthAvailable(name)) {
OfflinePlayer offlinePlayer = bukkitService.getOfflinePlayer(name);
purgeExecutor.executePurge(singletonList(offlinePlayer), singletonList(name.toLowerCase()));
sender.sendMessage("Purged data for player " + name);
} else {
sender.sendMessage("This player is still registered! Are you sure you want to proceed? "
+ "Use '/authme purgeplayer " + name + " force' to run the command anyway");
}
}
}
@@ -85,6 +85,11 @@ public enum AdminPermission implements PermissionNode {
*/
PURGE_BANNED_PLAYERS("authme.admin.purgebannedplayers"),
/**
* Administrator command to purge a given player.
*/
PURGE_PLAYER("authme.admin.purgeplayer"),
/**
* Administrator command to toggle the AntiBot protection status.
*/
@@ -198,6 +198,23 @@ public class BukkitService implements SettingsDependent {
return authMe.getServer().getPlayerExact(name);
}
/**
* Gets the player by the given name, regardless if they are offline or
* online.
* <p>
* This method may involve a blocking web request to get the UUID for the
* given name.
* <p>
* This will return an object even if the player does not exist. To this
* method, all players will exist.
*
* @param name the name the player to retrieve
* @return an offline player
*/
public OfflinePlayer getOfflinePlayer(String name) {
return authMe.getServer().getOfflinePlayer(name);
}
/**
* Gets a set containing all banned players.
*
@@ -24,7 +24,7 @@ public final class PurgeSettings implements SettingsHolder {
public static final Property<Boolean> REMOVE_ESSENTIALS_FILES =
newProperty("Purge.removeEssentialsFile", false);
@Comment("World where are players.dat stores")
@Comment("World in which the players.dat are stored")
public static final Property<String> DEFAULT_WORLD =
newProperty("Purge.defaultWorld", "world");
@@ -21,7 +21,7 @@ import static fr.xephi.authme.util.FileUtils.makePath;
/**
* Executes the purge operations.
*/
class PurgeExecutor {
public class PurgeExecutor {
@Inject
private Settings settings;
+5 -1
View File
@@ -17,7 +17,7 @@ softdepend:
commands:
authme:
description: AuthMe op commands
usage: /authme register|unregister|forcelogin|password|lastlogin|accounts|email|setemail|getip|spawn|setspawn|firstspawn|setfirstspawn|purge|backup|resetpos|purgebannedplayers|switchantibot|reload|version|converter|messages|debug
usage: /authme register|unregister|forcelogin|password|lastlogin|accounts|email|setemail|getip|spawn|setspawn|firstspawn|setfirstspawn|purge|purgeplayer|backup|resetpos|purgebannedplayers|switchantibot|reload|version|converter|messages|debug
login:
description: Login command
usage: /login <password>
@@ -67,6 +67,7 @@ permissions:
authme.admin.purge: true
authme.admin.purgebannedplayers: true
authme.admin.purgelastpos: true
authme.admin.purgeplayer: true
authme.admin.register: true
authme.admin.reload: true
authme.admin.seeotheraccounts: true
@@ -118,6 +119,9 @@ permissions:
authme.admin.purgelastpos:
description: Administrator command to purge the last position of a user.
default: op
authme.admin.purgeplayer:
description: Administrator command to purge a given player.
default: op
authme.admin.register:
description: Administrator command to register a new user.
default: op