Remove console only commands - closes #137

This commit is contained in:
Luck 2017-01-19 20:39:09 +00:00
parent a152cc47c7
commit 2e16844141
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
15 changed files with 173 additions and 130 deletions

View File

@ -29,7 +29,6 @@ import de.bananaco.bpermissions.api.Permission;
import de.bananaco.bpermissions.api.World;
import de.bananaco.bpermissions.api.WorldManager;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
@ -37,6 +36,7 @@ import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.core.model.PermissionHolder;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.data.LogEntry;
@ -50,6 +50,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import static me.lucko.luckperms.common.constants.Permission.MIGRATION;
@ -177,31 +178,35 @@ public class MigrationBPermissions extends SubCommand<Object> {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
Consumer<String> log = s -> {
Message.MIGRATION_LOG.send(sender, s);
Message.MIGRATION_LOG.send(plugin.getConsoleSender(), s);
};
log.accept("Starting bPermissions migration.");
WorldManager worldManager = WorldManager.getInstance();
if (worldManager == null) {
log.severe("bPermissions Migration: Error -> bPermissions is not loaded.");
log.accept("Error -> bPermissions is not loaded.");
return CommandResult.STATE_ERROR;
}
log.info("bPermissions Migration: Forcing the plugin to load all data. This could take a while.");
log.accept("Forcing the plugin to load all data. This could take a while.");
for (World world : worldManager.getAllWorlds()) {
Set<String> users = getUsers(world);
if (users == null) {
log.severe("bPermissions Migration: Couldn't get a list of users.");
log.accept("Couldn't get a list of users.");
return CommandResult.FAILURE;
}
users.forEach(s -> world.loadOne(s, CalculableType.USER));
}
// Migrate one world at a time.
log.info("bPermissions Migration: Starting world migration.");
log.accept("Starting world migration.");
for (World world : worldManager.getAllWorlds()) {
log.info("bPermissions Migration: Migrating world: " + world.getName());
log.accept("Migrating world: " + world.getName());
// Migrate all groups
log.info("bPermissions Migration: Starting group migration in world " + world.getName() + ".");
log.accept("Starting group migration in world " + world.getName() + ".");
int groupCount = 0;
for (Calculable group : world.getAll(CalculableType.GROUP)) {
groupCount++;
@ -225,10 +230,10 @@ public class MigrationBPermissions extends SubCommand<Object> {
migrateHolder(plugin, world, group, lpGroup);
plugin.getStorage().saveGroup(lpGroup);
}
log.info("bPermissions Migration: Migrated " + groupCount + " groups in world " + world.getName() + ".");
log.accept("Migrated " + groupCount + " groups in world " + world.getName() + ".");
// Migrate all users
log.info("bPermissions Migration: Starting user migration in world " + world.getName() + ".");
log.accept("Starting user migration in world " + world.getName() + ".");
int userCount = 0;
for (Calculable user : world.getAll(CalculableType.USER)) {
userCount++;
@ -242,7 +247,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
}
if (uuid == null) {
log.info("bPermissions Migration: Unable to migrate user " + user.getName() + ". Unable to get UUID.");
log.accept("Unable to migrate user " + user.getName() + ". Unable to get UUID.");
continue;
}
@ -256,10 +261,10 @@ public class MigrationBPermissions extends SubCommand<Object> {
plugin.getUserManager().cleanup(lpUser);
}
log.info("bPermissions Migration: Migrated " + userCount + " users in world " + world.getName() + ".");
log.accept("Migrated " + userCount + " users in world " + world.getName() + ".");
}
log.info("bPermissions Migration: Success! Completed without any errors.");
log.accept("Success! Completed without any errors.");
return CommandResult.SUCCESS;
}
}

View File

@ -22,7 +22,6 @@
package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
@ -30,6 +29,7 @@ import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
import me.lucko.luckperms.common.data.LogEntry;
@ -49,6 +49,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class MigrationGroupManager extends SubCommand<Object> {
@ -60,9 +61,14 @@ public class MigrationGroupManager extends SubCommand<Object> {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
Consumer<String> log = s -> {
Message.MIGRATION_LOG.send(sender, s);
Message.MIGRATION_LOG.send(plugin.getConsoleSender(), s);
};
log.accept("Starting GroupManager migration.");
if (!plugin.isPluginLoaded("GroupManager")) {
log.severe("GroupManager Migration: Error -> GroupManager is not loaded.");
log.accept("Error -> GroupManager is not loaded.");
return CommandResult.STATE_ERROR;
}
@ -73,7 +79,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
GroupManager gm = (GroupManager) plugin.getPlugin("GroupManager");
// Migrate Global Groups
log.info("GroupManager Migration: Starting Global Group migration.");
log.accept("Starting Global Group migration.");
GlobalGroups gg = GroupManager.getGlobalGroups();
for (Group g : gg.getGroupList()) {
@ -135,7 +141,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
WorldsHolder wh = gm.getWorldsHolder();
// Collect data for all users and groups.
log.info("GroupManager Migration: Starting user and group migration.");
log.accept("Starting user and group migration.");
for (String world : worlds) {
world = world.toLowerCase();
@ -196,8 +202,8 @@ public class MigrationGroupManager extends SubCommand<Object> {
}
log.info("GroupManager Migration: All existing GroupManager data has been processed. Now beginning the import process.");
log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups.");
log.accept("All existing GroupManager data has been processed. Now beginning the import process.");
log.accept("Found a total of " + users.size() + " users and " + groups.size() + " groups.");
for (Map.Entry<String, Map<Map.Entry<String, String>, Boolean>> e : groups.entrySet()) {
plugin.getStorage().createAndLoadGroup(e.getKey()).join();
@ -290,7 +296,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
plugin.getUserManager().cleanup(user);
}
log.info("GroupManager Migration: Success! Completed without any errors.");
log.accept("Success! Completed without any errors.");
return CommandResult.SUCCESS;
}
}

View File

@ -22,7 +22,6 @@
package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.PlatformType;
import me.lucko.luckperms.common.LuckPermsPlugin;
@ -32,6 +31,7 @@ import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.User;
@ -48,6 +48,7 @@ import ru.tehkode.permissions.bukkit.PermissionsEx;
import java.lang.reflect.Field;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class MigrationPermissionsEx extends SubCommand<Object> {
@ -60,15 +61,20 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
@SuppressWarnings("deprecation")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
Consumer<String> log = s -> {
Message.MIGRATION_LOG.send(sender, s);
Message.MIGRATION_LOG.send(plugin.getConsoleSender(), s);
};
log.accept("Starting PermissionsEx migration.");
if (!plugin.isPluginLoaded("PermissionsEx")) {
log.severe("PermissionsEx Migration: Error -> PermissionsEx is not loaded.");
log.accept("Error -> PermissionsEx is not loaded.");
return CommandResult.STATE_ERROR;
}
if (plugin.getType() != PlatformType.BUKKIT) {
// Sponge uses a completely different version of PEX.
log.severe("PEX import is not supported on this platform.");
log.accept("PEX import is not supported on this platform.");
return CommandResult.STATE_ERROR;
}
@ -90,7 +96,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
}
// Migrate all groups.
log.info("PermissionsEx Migration: Starting group migration.");
log.accept("Starting group migration.");
int maxGroupWeight = 0;
int groupCount = 0;
@ -229,10 +235,10 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
}
log.info("PermissionsEx Migration: Migrated " + groupCount + " groups");
log.accept("Migrated " + groupCount + " groups");
// Migrate all users
log.info("PermissionsEx Migration: Starting user migration.");
log.accept("Starting user migration.");
int userCount = 0;
maxGroupWeight++;
for (PermissionUser user : manager.getUsers()) {
@ -248,7 +254,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
}
if (u == null) {
log.severe("Unable to get a UUID for user identifier: " + user.getIdentifier());
log.accept("Unable to get a UUID for user identifier: " + user.getIdentifier());
continue;
}
@ -390,8 +396,8 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
plugin.getStorage().saveUser(lpUser);
}
log.info("PermissionsEx Migration: Migrated " + userCount + " users.");
log.info("PermissionsEx Migration: Success! Completed without any errors.");
log.accept("Migrated " + userCount + " users.");
log.accept("Success! Completed without any errors.");
return CommandResult.SUCCESS;
}
}

View File

@ -33,7 +33,6 @@ import com.github.cheesesoftware.PowerfulPermsAPI.ResultRunnable;
import com.google.common.util.concurrent.ListenableFuture;
import com.zaxxer.hikari.HikariDataSource;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.bukkit.migration.utils.LPResultRunnable;
import me.lucko.luckperms.common.LuckPermsPlugin;
@ -43,6 +42,7 @@ import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.core.model.PermissionHolder;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.data.LogEntry;
@ -64,6 +64,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import static me.lucko.luckperms.common.constants.Permission.MIGRATION;
@ -187,17 +188,22 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
try {
return run(plugin, args);
return run(plugin, sender, args);
} catch (Throwable t) {
t.printStackTrace();
return CommandResult.FAILURE;
}
}
private CommandResult run(LuckPermsPlugin plugin, List<String> args) {
final Logger log = plugin.getLog();
private CommandResult run(LuckPermsPlugin plugin, Sender sender, List<String> args) {
Consumer<String> log = s -> {
Message.MIGRATION_LOG.send(sender, s);
Message.MIGRATION_LOG.send(plugin.getConsoleSender(), s);
};
log.accept("Starting PowerfulPerms migration.");
if (!plugin.isPluginLoaded("PowerfulPerms")) {
log.severe("PowerfulPerms Migration: Error -> PowerfulPerms is not loaded.");
log.accept("Error -> PowerfulPerms is not loaded.");
return CommandResult.STATE_ERROR;
}
@ -208,7 +214,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
final String dbTable = args.get(4);
// Find a list of UUIDs
log.info("PowerfulPerms Migration: Getting a list of UUIDs to migrate.");
log.accept("Getting a list of UUIDs to migrate.");
@Cleanup HikariDataSource hikari = new HikariDataSource();
hikari.setMaximumPoolSize(2);
@ -227,7 +233,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
@Cleanup ResultSet tables = meta.getTables(null, null, dbTable, null);
if (!tables.next()) {
log.severe("PowerfulPerms Migration: Error - Couldn't find table.");
log.accept("Error - Couldn't find table.");
return CommandResult.FAILURE;
} else {
@ -235,9 +241,9 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
columnPs.setString(1, dbTable);
@Cleanup ResultSet columnRs = columnPs.executeQuery();
log.info("Found table: " + dbTable);
log.accept("Found table: " + dbTable);
while (columnRs.next()) {
log.info("" + columnRs.getString("COLUMN_NAME") + " - " + columnRs.getString("COLUMN_TYPE"));
log.accept("" + columnRs.getString("COLUMN_NAME") + " - " + columnRs.getString("COLUMN_TYPE"));
}
@Cleanup PreparedStatement preparedStatement = connection.prepareStatement("SELECT `uuid` FROM " + dbTable);
@ -254,17 +260,17 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
}
if (uuids.isEmpty()) {
log.severe("PowerfulPerms Migration: Error - Unable to find any UUIDs to migrate.");
log.accept("Error - Unable to find any UUIDs to migrate.");
return CommandResult.FAILURE;
}
log.info("PowerfulPerms Migration: Found " + uuids.size() + " uuids. Starting migration.");
log.accept("Found " + uuids.size() + " uuids. Starting migration.");
PowerfulPermsPlugin ppPlugin = (PowerfulPermsPlugin) plugin.getPlugin("PowerfulPerms");
PermissionManager pm = ppPlugin.getPermissionManager();
// Groups first.
log.info("PowerfulPerms Migration: Starting group migration.");
log.accept("Starting group migration.");
Map<Integer, Group> groups = pm.getGroups(); // All versions
for (Group g : groups.values()) {
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase()).join();
@ -298,10 +304,10 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
plugin.getStorage().saveGroup(group);
}
log.info("PowerfulPerms Migration: Group migration complete.");
log.accept("Group migration complete.");
// Now users.
log.info("PowerfulPerms Migration: Starting user migration.");
log.accept("Starting user migration.");
final Map<UUID, CountDownLatch> progress = new HashMap<>();
// Migrate all users and their groups
@ -468,7 +474,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
e.printStackTrace();
}
} catch (IllegalAccessException | InvocationTargetException e) {
log.info("PowerfulPerms Migration: Error");
log.accept("Error");
e.printStackTrace();
}
} else {
@ -480,7 +486,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
}
});
} catch (IllegalAccessException | InvocationTargetException e) {
log.info("PowerfulPerms Migration: Error");
log.accept("Error");
e.printStackTrace();
}
}
@ -488,7 +494,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
// All groups are migrated, but there may still be some users being migrated.
// This block will wait for all users to be completed.
log.info("PowerfulPerms Migration: Waiting for user migration to complete. This may take some time");
log.accept("Waiting for user migration to complete. This may take some time");
boolean sleep = true;
while (sleep) {
sleep = false;
@ -511,7 +517,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
}
// We done.
log.info("PowerfulPerms Migration: Success! Completed without any errors.");
log.accept("Success! Completed without any errors.");
return CommandResult.SUCCESS;
}

View File

@ -22,12 +22,12 @@
package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
import me.lucko.luckperms.common.core.model.Group;
@ -48,24 +48,29 @@ import org.tyrannyofheaven.bukkit.zPermissions.model.PermissionEntity;
import java.lang.reflect.Field;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
public class MigrationZPermissions extends SubCommand<Object> {
public MigrationZPermissions() {
super("zpermissions", "Migration from zPermissions", Permission.MIGRATION, Predicates.alwaysFalse(), null);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
Consumer<String> log = s -> {
Message.MIGRATION_LOG.send(sender, s);
Message.MIGRATION_LOG.send(plugin.getConsoleSender(), s);
};
log.accept("Starting zPermissions migration.");
if (!plugin.isPluginLoaded("zPermissions")) {
log.severe("zPermissions Migration: Error -> zPermissions is not loaded.");
log.accept("Error -> zPermissions is not loaded.");
return CommandResult.STATE_ERROR;
}
ZPermissionsService service = (ZPermissionsService) plugin.getService(ZPermissionsService.class);
if (service == null) {
log.severe("zPermissions Migration: Error -> zPermissions is not loaded.");
log.accept("Error -> zPermissions is not loaded.");
return CommandResult.STATE_ERROR;
}
@ -81,7 +86,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
}
// Migrate all groups
log.info("zPermissions Migration: Starting group migration.");
log.accept("Starting group migration.");
for (String g : service.getAllGroups()) {
plugin.getStorage().createAndLoadGroup(g.toLowerCase()).join();
Group group = plugin.getGroupManager().getIfLoaded(g.toLowerCase());
@ -93,7 +98,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
}
// Migrate all tracks
log.info("zPermissions Migration: Starting track migration.");
log.accept("Starting track migration.");
for (String t : service.getAllTracks()) {
plugin.getStorage().createAndLoadTrack(t.toLowerCase()).join();
Track track = plugin.getTrackManager().getIfLoaded(t.toLowerCase());
@ -102,7 +107,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
}
// Migrate all users.
log.info("zPermissions Migration: Starting user migration.");
log.accept("Starting user migration.");
for (UUID u : service.getAllPlayersUUID()) {
plugin.getStorage().loadUser(u, "null").join();
User user = plugin.getUserManager().get(u);
@ -120,7 +125,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
plugin.getStorage().saveUser(user);
}
log.info("zPermissions Migration: Success! Completed without any errors.");
log.accept("Success! Completed without any errors.");
return CommandResult.SUCCESS;
}

View File

@ -22,7 +22,6 @@
package me.lucko.luckperms.bungee.migration;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
@ -30,6 +29,7 @@ import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.utils.Predicates;
@ -43,6 +43,7 @@ import net.alpenblock.bungeeperms.World;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
/**
* BungeePerms is actually pretty nice. huh.
@ -54,16 +55,20 @@ public class MigrationBungeePerms extends SubCommand<Object> {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
Consumer<String> log = s -> {
Message.MIGRATION_LOG.send(sender, s);
Message.MIGRATION_LOG.send(plugin.getConsoleSender(), s);
};
log.accept("Starting BungeePerms migration.");
BungeePerms bp = BungeePerms.getInstance();
if (bp == null) {
log.severe("BungeePerms Migration: Error -> BungeePerms is not loaded.");
log.accept("Error -> BungeePerms is not loaded.");
return CommandResult.STATE_ERROR;
}
// Migrate all groups.
log.info("BungeePerms Migration: Starting group migration.");
log.accept("Starting group migration.");
int groupCount = 0;
for (Group g : bp.getPermissionsManager().getBackEnd().loadGroups()) {
groupCount++;
@ -182,10 +187,10 @@ public class MigrationBungeePerms extends SubCommand<Object> {
plugin.getStorage().saveGroup(group);
}
log.info("BungeePerms Migration: Migrated " + groupCount + " groups");
log.accept("Migrated " + groupCount + " groups");
// Migrate all users.
log.info("BungeePerms Migration: Starting user migration.");
log.accept("Starting user migration.");
int userCount = 0;
for (User u : bp.getPermissionsManager().getBackEnd().loadUsers()) {
if (u.getUUID() == null) continue;
@ -298,8 +303,8 @@ public class MigrationBungeePerms extends SubCommand<Object> {
plugin.getUserManager().cleanup(user);
}
log.info("BungeePerms Migration: Migrated " + userCount + " users.");
log.info("BungeePerms Migration: Success! Completed without any errors.");
log.accept("Migrated " + userCount + " users.");
log.accept("Success! Completed without any errors.");
return CommandResult.SUCCESS;
}
}

View File

@ -35,4 +35,8 @@ public abstract class BaseCommand<T, S> extends Command<T, S> {
public abstract String getUsage();
public boolean shouldDisplay() {
return true;
}
}

View File

@ -214,6 +214,10 @@ public class CommandManager {
mainCommands.stream()
.filter(c -> c.isAuthorized(sender))
.forEach(c -> {
if (!c.shouldDisplay()) {
return;
}
@SuppressWarnings("unchecked")
String permission = (String) c.getPermission().map(p -> ((Permission) p).getExample()).orElse("None");
FancyMessage msg = new FancyMessage("> ").color(ChatColor.getByChar('3')).then().text(String.format(c.getUsage(), label)).color(ChatColor.getByChar('a'))

View File

@ -149,12 +149,6 @@ public abstract class MainCommand<T> extends BaseCommand<Void, T> {
@Override
public void sendUsage(Sender sender, String label) {
/*
if (getSubCommands().isEmpty()) {
Util.sendPluginMessage(sender, "&3> &a" + String.format(getUsage(), label));
return;
*/
List<Command> subs = getSubCommands().stream()
.filter(s -> s.isAuthorized(sender))
.collect(Collectors.toList());

View File

@ -29,8 +29,8 @@ import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.MainCommand;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.ArrayList;
import java.util.Collections;
@ -95,6 +95,7 @@ public class MigrationMainCommand extends MainCommand<Object> {
}
private List<Command<Object, ?>> commands = null;
private boolean display = true;
public MigrationMainCommand() {
super("Migration", "Migration commands", "/%s migration", 1, null);
@ -106,6 +107,17 @@ public class MigrationMainCommand extends MainCommand<Object> {
public synchronized Optional<List<Command<Object, ?>>> getChildren() {
if (commands == null) {
commands = getAvailableCommands();
// Add dummy command to show in the list.
if (commands.isEmpty()) {
display = false;
commands.add(new SubCommand<Object>("No available plugins to migrate from", "No available plugins to migrate from.", Permission.MIGRATION, Predicates.alwaysFalse(), null) {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
return CommandResult.SUCCESS;
}
});
}
}
return Optional.of(commands);
@ -118,17 +130,13 @@ public class MigrationMainCommand extends MainCommand<Object> {
@Override
public boolean isAuthorized(Sender sender) {
return sender.getUuid().equals(Constants.CONSOLE_UUID);
return sender.hasPermission(Permission.MIGRATION);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) throws CommandException {
if (!sender.getUuid().equals(Constants.CONSOLE_UUID)) {
Message.MIGRATION_NOT_CONSOLE.send(sender);
return CommandResult.NO_PERMISSION;
}
return super.execute(plugin, sender, v, args, label);
public boolean shouldDisplay() {
getSubCommands();
return display;
}
@Override

View File

@ -22,14 +22,12 @@
package me.lucko.luckperms.common.commands.misc;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.model.Group;
@ -46,6 +44,7 @@ import java.nio.file.Files;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
public class ExportCommand extends SingleCommand {
private static void write(BufferedWriter writer, String s) {
@ -102,7 +101,7 @@ public class ExportCommand extends SingleCommand {
}
public ExportCommand() {
super("Export", "Export data to a file", "/%s export <file>", Permission.MIGRATION, Predicates.not(1),
super("Export", "Export data to a file", "/%s export <file>", Permission.EXPORT, Predicates.not(1),
Arg.list(
Arg.create("file", true, "the file to export to")
)
@ -111,12 +110,7 @@ public class ExportCommand extends SingleCommand {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
final Logger log = plugin.getLog();
if (!sender.getUuid().equals(Constants.CONSOLE_UUID)) {
Message.MIGRATION_NOT_CONSOLE.send(sender);
return CommandResult.NO_PERMISSION;
}
Consumer<String> log = s -> Message.EXPORT_LOG.send(sender, s);
File f = new File(plugin.getMainDir(), args.get(0));
if (f.exists()) {
@ -138,10 +132,10 @@ public class ExportCommand extends SingleCommand {
}
try (FileWriter fWriter = new FileWriter(f, true); BufferedWriter writer = new BufferedWriter(fWriter)) {
log.info("Export: Starting export process.");
log.accept("Starting export process.");
// Export Groups
log.info("Export: Exporting all groups.");
log.accept("Exporting all groups.");
// Create the groups first
for (Group group : plugin.getGroupManager().getAll().values()) {
@ -155,10 +149,10 @@ public class ExportCommand extends SingleCommand {
write(writer, nodeToString(node, group.getName(), true));
}
}
log.info("Export: Exported " + groupCount + " groups.");
log.accept("Exported " + groupCount + " groups.");
// Export tracks
log.info("Export: Exporting all tracks.");
log.accept("Exporting all tracks.");
// Create the tracks first
for (Track track : plugin.getTrackManager().getAll().values()) {
@ -172,13 +166,13 @@ public class ExportCommand extends SingleCommand {
write(writer, "/luckperms track " + track.getName() + " append " + group);
}
}
log.info("Export: Exported " + trackCount + " tracks.");
log.accept("Exported " + trackCount + " tracks.");
// Export users
log.info("Export: Exporting all users. Finding a list of unique users to export.");
log.accept("Exporting all users. Finding a list of unique users to export.");
Storage ds = plugin.getStorage();
Set<UUID> users = ds.getUniqueUsers().join();
log.info("Export: Found " + users.size() + " unique users to export.");
log.accept("Found " + users.size() + " unique users to export.");
int userCount = 0;
for (UUID uuid : users) {
@ -206,7 +200,7 @@ public class ExportCommand extends SingleCommand {
plugin.getUserManager().cleanup(user);
}
log.info("Export: Exported " + userCount + " users.");
log.accept("Exported " + userCount + " users.");
try {
writer.flush();
@ -222,9 +216,4 @@ public class ExportCommand extends SingleCommand {
}
}
@Override
public boolean isAuthorized(Sender sender) {
return sender.getUuid().equals(Constants.CONSOLE_UUID);
}
}

View File

@ -48,6 +48,8 @@ public enum Message {
OP_DISABLED("&bThe vanilla OP system is disabled on this server.", false),
OP_DISABLED_SPONGE("&2Server Operator status has no effect when a permission plugin is installed. Please edit user data directly.", true),
LOG("&3LOG &3&l> {0}", true),
EXPORT_LOG("&3EXPORT &3&l> &f{0}", true),
MIGRATION_LOG("&3MIGRATION &3&l> &f{0}", true),
COMMAND_NOT_RECOGNISED("Command not recognised.", true),
COMMAND_NO_PERMISSION("You do not have permission to use this command!", true),
@ -413,9 +415,7 @@ public enum Message {
),
IMPORT_END_ERROR_CONTENT("&b(Import) &b-> &c{0}", true),
IMPORT_END_ERROR_FOOTER("&b(Import) &7<------------------------------------------>", true),
MIGRATION_NOT_CONSOLE("Migration must be performed from the Console.", true);
IMPORT_END_ERROR_FOOTER("&b(Import) &7<------------------------------------------>", true);
private static String format(String s, Object... objects) {
for (int i = 0, objsLength = objects.length; i < objsLength; i++) {

View File

@ -40,6 +40,8 @@ public enum Permission {
SEARCH(list("search"), Type.NONE),
VERBOSE(list("verbose"), Type.NONE),
IMPORT(list("import"), Type.NONE),
EXPORT(list("export"), Type.NONE),
MIGRATION(list("migration"), Type.NONE),
CREATE_GROUP(list("creategroup"), Type.NONE),
DELETE_GROUP(list("deletegroup"), Type.NONE),
@ -148,9 +150,7 @@ public enum Permission {
SPONGE_OPTION_INFO(list("option.info"), Type.SPONGE),
SPONGE_OPTION_SET(list("option.set"), Type.SPONGE),
SPONGE_OPTION_UNSET(list("option.unset"), Type.SPONGE),
SPONGE_OPTION_CLEAR(list("option.clear"), Type.SPONGE),
MIGRATION(list("migration"), Type.NONE);
SPONGE_OPTION_CLEAR(list("option.clear"), Type.SPONGE);
private static final String IDENTIFIER = "luckperms.";

View File

@ -22,13 +22,13 @@
package me.lucko.luckperms.sponge.migration;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.User;
@ -44,6 +44,7 @@ import java.lang.reflect.Method;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
import static me.lucko.luckperms.sponge.migration.MigrationUtils.migrateSubject;
@ -54,11 +55,15 @@ public class MigrationPermissionManager extends SubCommand<Object> {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
Consumer<String> log = s -> {
Message.MIGRATION_LOG.send(sender, s);
Message.MIGRATION_LOG.send(plugin.getConsoleSender(), s);
};
log.accept("Starting PermissionManager migration.");
Optional<PluginContainer> pm = Sponge.getPluginManager().getPlugin("permissionmanager");
if (!pm.isPresent()) {
log.severe("PermissionManager Migration: Error -> PermissionManager is not loaded.");
log.accept("Error -> PermissionManager is not loaded.");
return CommandResult.STATE_ERROR;
}
@ -75,7 +80,7 @@ public class MigrationPermissionManager extends SubCommand<Object> {
}
// Migrate groups
log.info("PermissionManager Migration: Starting group migration.");
log.accept("Starting group migration.");
// Forcefully load all groups.
try {
@ -97,10 +102,10 @@ public class MigrationPermissionManager extends SubCommand<Object> {
migrateSubject(pmGroup, group);
plugin.getStorage().saveGroup(group);
}
log.info("PermissionManager Migration: Migrated " + groupCount + " groups");
log.accept("Migrated " + groupCount + " groups");
// Migrate users
log.info("PermissionManager Migration: Starting user migration.");
log.accept("Starting user migration.");
// Forcefully load all users.
try {
@ -115,7 +120,7 @@ public class MigrationPermissionManager extends SubCommand<Object> {
userCount++;
UUID uuid = Util.parseUuid(pmUser.getIdentifier());
if (uuid == null) {
log.severe("PermissionManager Migration: Error -> Could not parse UUID for user: " + pmUser.getIdentifier());
log.accept("Error -> Could not parse UUID for user: " + pmUser.getIdentifier());
continue;
}
@ -127,8 +132,8 @@ public class MigrationPermissionManager extends SubCommand<Object> {
plugin.getUserManager().cleanup(user);
}
log.info("PermissionManager Migration: Migrated " + userCount + " users.");
log.info("PermissionManager Migration: Success! Completed without any errors.");
log.accept("Migrated " + userCount + " users.");
log.accept("Success! Completed without any errors.");
return CommandResult.SUCCESS;
}
}

View File

@ -22,13 +22,13 @@
package me.lucko.luckperms.sponge.migration;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.Track;
@ -51,6 +51,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.UUID;
import java.util.function.Consumer;
import static me.lucko.luckperms.sponge.migration.MigrationUtils.migrateSubject;
@ -61,12 +62,17 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
final Logger log = plugin.getLog();
Consumer<String> log = s -> {
Message.MIGRATION_LOG.send(sender, s);
Message.MIGRATION_LOG.send(plugin.getConsoleSender(), s);
};
log.accept("Starting PermissionsEx migration.");
final LuckPermsService lpService = ((LPSpongePlugin) plugin).getService();
Optional<PluginContainer> pex = Sponge.getPluginManager().getPlugin("permissionsex");
if (!pex.isPresent()) {
log.severe("PermissionsEx Migration: Error -> PermissionsEx is not loaded.");
log.accept("Error -> PermissionsEx is not loaded.");
return CommandResult.STATE_ERROR;
}
@ -86,7 +92,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
Map<String, TreeMap<Integer, String>> tracks = new HashMap<>();
// Migrate groups
log.info("PermissionsEx Migration: Starting group migration.");
log.accept("Starting group migration.");
int groupCount = 0;
for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) {
groupCount++;
@ -115,10 +121,10 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
}
}
log.info("PermissionsEx Migration: Migrated " + groupCount + " groups");
log.accept("Migrated " + groupCount + " groups");
// Migrate tracks
log.info("PermissionsEx Migration: Starting track migration.");
log.accept("Starting track migration.");
for (Map.Entry<String, TreeMap<Integer, String>> e : tracks.entrySet()) {
plugin.getStorage().createAndLoadTrack(e.getKey()).join();
Track track = plugin.getTrackManager().getIfLoaded(e.getKey());
@ -131,16 +137,16 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
}
}
}
log.info("PermissionsEx Migration: Migrated " + tracks.size() + " tracks");
log.accept("Migrated " + tracks.size() + " tracks");
// Migrate users
log.info("PermissionsEx Migration: Starting user migration.");
log.accept("Starting user migration.");
int userCount = 0;
for (Subject pexUser : pexService.getUserSubjects().getAllSubjects()) {
userCount++;
UUID uuid = Util.parseUuid(pexUser.getIdentifier());
if (uuid == null) {
log.severe("PermissionsEx Migration: Error -> Could not parse UUID for user: " + pexUser.getIdentifier());
log.accept("Error -> Could not parse UUID for user: " + pexUser.getIdentifier());
continue;
}
@ -152,8 +158,8 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
plugin.getUserManager().cleanup(user);
}
log.info("PermissionsEx Migration: Migrated " + userCount + " users.");
log.info("PermissionsEx Migration: Success! Completed without any errors.");
log.accept("Migrated " + userCount + " users.");
log.accept("Success! Completed without any errors.");
return CommandResult.SUCCESS;
}
}