Skip to content

Commit

Permalink
Finishing touches for 0.5.1. Optimization task improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstaeding committed Sep 9, 2019
1 parent c8f972a commit a637f01
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 99 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Do you run a multi server network where every server needs to share inventories

### Look no further

_MSDataSync_ is an advanced player data backup plugin that let's you store, manage, edit and rollback player data!
_MSDataSync_ is an advanced player data backup plugin that lets you store, manage, edit and rollback player data!

(Compatible with forge and vanilla)

Expand Down
2 changes: 1 addition & 1 deletion sponge/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
modGroup=rocks.milspecsg
modVersion=0.5.1-SNAPSHOT
modVersion=0.5.1
modBaseName=MSDataSync
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public final class MSDataSyncPluginInfo implements SpongePluginInfo {
public static final String id = "msdatasync";
public static final String name = "MSDataSync";
public static final String version = "0.5.1-SNAPSHOT";
public static final String version = "0.5.1";
public static final String description = "A plugin to synchronize player inventories with a database";
public static final String url = "https://milspecsg.rocks";
public static final String authors = "Cableguy20";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package rocks.milspecsg.msdatasync;

public abstract class PluginPermissions {

public static final String MANUAL_OPTIMIZATION = "msdatasync.command.optimize.base";
public static final String MANUAL_OPTIMIZATION_ALL = "msdatasync.command.optimize.all";
public static final String EDIT_SNAPSHOTS = "msdatasync.command.snapshot.edit";
public static final String VIEW_SNAPSHOTS = "msdatasync.command.snapshot.base";
public static final String LOCK_COMMAND = "msdatasync.command.lock";
public static final String RELOAD_COMMAND = "msdatasync.command.reload";
public static final String MANUAL_SYNC_COMMAND = "msdatasync.command.sync";
public static final String LOCK_COMMAND = "msdatasync.lock";
public static final String RELOAD_COMMAND = "msdatasync.reload";
public static final String SNAPSHOT_BASE = "msdatasync.snapshot.base";
public static final String SNAPSHOT_CREATE = "msdatasync.snapshot.create";
public static final String SNAPSHOT_DELETE = "msdatasync.snapshot.delete";
public static final String SNAPSHOT_RESTORE = "msdatasync.snapshot.restore";
public static final String SNAPSHOT_VIEW_EDIT = "msdatasync.snapshot.view.edit";
public static final String SNAPSHOT_VIEW_BASE = "msdatasync.snapshot.view.base";
public static final String MANUAL_OPTIMIZATION_ALL = "msdatasync.optimize.all";
public static final String MANUAL_OPTIMIZATION_BASE = "msdatasync.optimize.base";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class SyncCommandManager implements CommandManager {
@Inject
SyncHelpCommand syncHelpCommand;

@Inject
SyncInfoCommand syncInfoCommand;

@Inject
UploadStartCommand uploadStartCommand;

Expand All @@ -37,9 +40,6 @@ public class SyncCommandManager implements CommandManager {
@Inject
SnapshotHelpCommand snapshotHelpCommand;

@Inject
SnapshotEditCommand snapshotEditCommand;

@Inject
SnapshotInfoCommand snapshotInfoCommand;

Expand All @@ -49,6 +49,9 @@ public class SyncCommandManager implements CommandManager {
@Inject
SnapshotRestoreCommand snapshotRestoreCommand;

@Inject
SnapshotViewCommand snapshotViewCommand;

@Inject
OptimizeHelpCommand optimizeHelpCommand;

Expand All @@ -73,7 +76,7 @@ public void register(Object plugin) {

snapshotSubCommands.put(Arrays.asList("create", "c", "upload", "up"), CommandSpec.builder()
.description(Text.of("Creates a manual snapshot for user and uploads it to DB."))
.permission(PluginPermissions.MANUAL_SYNC_COMMAND)
.permission(PluginPermissions.SNAPSHOT_CREATE)
.arguments(
GenericArguments.onlyOne(GenericArguments.user(Text.of("user")))
)
Expand All @@ -83,7 +86,7 @@ public void register(Object plugin) {

snapshotSubCommands.put(Collections.singletonList("delete"), CommandSpec.builder()
.description(Text.of("Deletes snapshot for user."))
.permission(PluginPermissions.EDIT_SNAPSHOTS)
.permission(PluginPermissions.SNAPSHOT_DELETE)
.arguments(
GenericArguments.onlyOne(GenericArguments.user(Text.of("user"))),
GenericArguments.string(Text.of("date"))
Expand All @@ -94,25 +97,25 @@ public void register(Object plugin) {

snapshotSubCommands.put(Arrays.asList("edit", "e", "view"), CommandSpec.builder()
.description(Text.of("Edit/view snapshot for user from DB. If no date is provided, latest snapshot is selected."))
.permission(PluginPermissions.VIEW_SNAPSHOTS)
.permission(PluginPermissions.SNAPSHOT_VIEW_BASE)
.arguments(
GenericArguments.onlyOne(GenericArguments.user(Text.of("user"))),
GenericArguments.optional(GenericArguments.string(Text.of("date")))
)
.executor(snapshotEditCommand)
.executor(snapshotViewCommand)
.build()
);

snapshotSubCommands.put(Collections.singletonList("help"), CommandSpec.builder()
.description(Text.of("Shows this help page."))
.permission(PluginPermissions.MANUAL_SYNC_COMMAND)
.permission(PluginPermissions.SNAPSHOT_BASE)
.executor(snapshotHelpCommand)
.build()
);

snapshotSubCommands.put(Arrays.asList("info", "i"), CommandSpec.builder()
.description(Text.of("More info for snapshot for user from DB. If no date is provided, latest snapshot is selected."))
.permission(PluginPermissions.MANUAL_SYNC_COMMAND)
.permission(PluginPermissions.SNAPSHOT_BASE)
.arguments(
GenericArguments.onlyOne(GenericArguments.user(Text.of("user"))),
GenericArguments.optional(GenericArguments.string(Text.of("date")))
Expand All @@ -123,7 +126,7 @@ public void register(Object plugin) {

snapshotSubCommands.put(Arrays.asList("list", "l"), CommandSpec.builder()
.description(Text.of("Lists available snapshots for user."))
.permission(PluginPermissions.MANUAL_SYNC_COMMAND)
.permission(PluginPermissions.SNAPSHOT_BASE)
.arguments(
GenericArguments.onlyOne(GenericArguments.user(Text.of("user")))
)
Expand All @@ -133,7 +136,7 @@ public void register(Object plugin) {

snapshotSubCommands.put(Arrays.asList("restore", "r", "download", "down"), CommandSpec.builder()
.description(Text.of("Manually restores snapshot from DB. If no date is selected, latest snapshot is restored."))
.permission(PluginPermissions.MANUAL_SYNC_COMMAND)
.permission(PluginPermissions.SNAPSHOT_RESTORE)
.arguments(
GenericArguments.onlyOne(GenericArguments.user(Text.of("user"))),
GenericArguments.optional(GenericArguments.string(Text.of("date")))
Expand All @@ -144,7 +147,7 @@ public void register(Object plugin) {

subCommands.put(Arrays.asList("snapshot", "snap", "s"), CommandSpec.builder()
.description(Text.of("Snapshot base command."))
.permission(PluginPermissions.MANUAL_SYNC_COMMAND)
.permission(PluginPermissions.SNAPSHOT_BASE)
.executor(snapshotHelpCommand)
.children(snapshotSubCommands)
.build());
Expand All @@ -156,7 +159,7 @@ public void register(Object plugin) {

optimizeSubCommands.put(Arrays.asList("start", "s"), CommandSpec.builder()
.description(Text.of("Starts manual optimization, deletes old snapshots."))
.permission(PluginPermissions.MANUAL_OPTIMIZATION)
.permission(PluginPermissions.MANUAL_OPTIMIZATION_BASE)
.arguments(
GenericArguments.choices(Text.of("mode"), optimizeStartChoices),
GenericArguments.optional(GenericArguments.user(Text.of("user")))
Expand All @@ -166,25 +169,25 @@ public void register(Object plugin) {

optimizeSubCommands.put(Arrays.asList("info", "i"), CommandSpec.builder()
.description(Text.of("Gets info on current manual optimization."))
.permission(PluginPermissions.MANUAL_OPTIMIZATION)
.permission(PluginPermissions.MANUAL_OPTIMIZATION_BASE)
.executor(optimizeInfoCommand)
.build());

optimizeSubCommands.put(Collections.singletonList("stop"), CommandSpec.builder()
.description(Text.of("Stops current manual optimization."))
.permission(PluginPermissions.MANUAL_OPTIMIZATION)
.permission(PluginPermissions.MANUAL_OPTIMIZATION_BASE)
.executor(optimizeStopCommand)
.build());

optimizeSubCommands.put(Collections.singletonList("help"), CommandSpec.builder()
.description(Text.of("Shows this help page."))
.permission(PluginPermissions.MANUAL_OPTIMIZATION)
.permission(PluginPermissions.MANUAL_OPTIMIZATION_BASE)
.executor(optimizeHelpCommand)
.build());

subCommands.put(Arrays.asList("optimize", "opt", "o"), CommandSpec.builder()
.description(Text.of("Optimize base command. (To delete old snapshots)"))
.permission(PluginPermissions.MANUAL_OPTIMIZATION)
.permission(PluginPermissions.MANUAL_OPTIMIZATION_BASE)
.executor(optimizeHelpCommand)
.children(optimizeSubCommands)
.build());
Expand All @@ -211,20 +214,23 @@ public void register(Object plugin) {

subCommands.put(Arrays.asList("upload", "up"), CommandSpec.builder()
.description(Text.of("Uploads all players on server."))
.permission(PluginPermissions.MANUAL_SYNC_COMMAND)
.permission(PluginPermissions.SNAPSHOT_CREATE)
.executor(uploadStartCommand)
.build());

subCommands.put(Collections.singletonList("help"), CommandSpec.builder()
.description(Text.of("Shows this help page."))
.permission(PluginPermissions.MANUAL_SYNC_COMMAND)
.executor(syncHelpCommand)
.build());

subCommands.put(Collections.singletonList("info"), CommandSpec.builder()
.description(Text.of("Shows plugin info."))
.executor(syncInfoCommand)
.build());

//Build all commands
CommandSpec mainCommand = CommandSpec.builder()
.description(Text.of("Displays all available sync subcommands."))
.description(Text.of("Displays all available sync sub commands."))
.executor(syncHelpCommand)
.children(subCommands)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.pagination.PaginationList;
import org.spongepowered.api.service.pagination.PaginationService;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.action.TextActions;
import org.spongepowered.api.text.format.TextColors;
import rocks.milspecsg.msdatasync.MSDataSyncPluginInfo;
import rocks.milspecsg.msdatasync.PluginPermissions;
import rocks.milspecsg.msdatasync.misc.CommandUtils;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -26,6 +32,16 @@ public class SyncHelpCommand implements CommandExecutor {

@Override
public CommandResult execute(CommandSource source, CommandContext context) {

if (source instanceof Player && !source.hasPermission(PluginPermissions.SNAPSHOT_BASE)
&& !source.hasPermission(PluginPermissions.MANUAL_OPTIMIZATION_BASE)
&& !source.hasPermission(PluginPermissions.LOCK_COMMAND)
&& !source.hasPermission(PluginPermissions.RELOAD_COMMAND)) {
commandUtils.createInfoPage(source);
source.sendMessage(Text.of(TextColors.RED, "You do not have permission for any sub commands"));
return CommandResult.success();
}

commandUtils.createHelpPage(source, SyncCommandManager.subCommands, "");
return CommandResult.success();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package rocks.milspecsg.msdatasync.commands;

import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.action.TextActions;
import org.spongepowered.api.text.format.TextColors;
import rocks.milspecsg.msdatasync.MSDataSyncPluginInfo;
import rocks.milspecsg.msdatasync.misc.CommandUtils;

import javax.inject.Inject;
import java.net.MalformedURLException;
import java.net.URL;

public class SyncInfoCommand implements CommandExecutor {

@Inject
CommandUtils commandUtils;
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException {
commandUtils.createInfoPage(source);
return CommandResult.success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
import rocks.milspecsg.msdatasync.misc.SnapshotOptimizationService;

import javax.inject.Inject;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class OptimizeInfoCommand implements CommandExecutor {

@Inject
SnapshotOptimizationService snapshotOptimizationService;

private static NumberFormat formatter = new DecimalFormat("#0.00");

@Override
public CommandResult execute(CommandSource source, CommandContext context) {

int deleted = snapshotOptimizationService.getSnapshotsDeleted();
int completed = snapshotOptimizationService.getMembersCompleted();
int total = snapshotOptimizationService.getTotalMembers();

Expand All @@ -27,9 +32,12 @@ public CommandResult execute(CommandSource source, CommandContext context) {
source.sendMessage(
Text.of(
MSDataSyncPluginInfo.pluginPrefix, TextColors.YELLOW,
"Optimization task: Completed ", completed,
" out of ", total, " ", TextColors.GOLD,
"( ", (completed * 100) / total, "% )"));
"Optimization task:\n",
TextColors.GRAY, "Snapshots deleted: ", TextColors.YELLOW, deleted, "\n",
TextColors.GRAY, "Members processed: ", TextColors.YELLOW, completed, "/", total, "\n",
TextColors.GRAY, "Progress: ", TextColors.YELLOW, formatter.format((double) completed * 100d / (double) total), "%"
)
);
} else {
source.sendMessage(Text.of(MSDataSyncPluginInfo.pluginPrefix, TextColors.YELLOW, "There is currently no optimization task running"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ public CommandResult execute(CommandSource source, CommandContext context) throw

if (optionalMode.get().equals("all")) {
if (!source.hasPermission(PluginPermissions.MANUAL_OPTIMIZATION_ALL)) {
source.sendMessage(Text.of(MSDataSyncPluginInfo.pluginPrefix, TextColors.RED, "You do not have permission to start optimization task: all"));
}
if (snapshotOptimizationService.startOptimizeAll(source)) {
throw new CommandException(Text.of(MSDataSyncPluginInfo.pluginPrefix, "You do not have permission to start optimization task: all"));
} else if (snapshotOptimizationService.startOptimizeAll(source)) {
source.sendMessage(Text.of(MSDataSyncPluginInfo.pluginPrefix, TextColors.YELLOW, "Successfully started optimization task: all"));
} else {
throw new CommandException(Text.of(MSDataSyncPluginInfo.pluginPrefix, "Optimizer already running! Use /sync optimize info"));
}
snapshotOptimizationService.startOptimizeAll(source);
} else {
if (!users.isEmpty()) {
if (users.isEmpty()) {
throw new CommandException(Text.of(MSDataSyncPluginInfo.pluginPrefix, "No users were selected by your query"));
} else if (snapshotOptimizationService.optimize(users, source, "Manual")) {
source.sendMessage(Text.of(MSDataSyncPluginInfo.pluginPrefix, TextColors.YELLOW, "Successfully started optimization task: user"));
} else {
throw new CommandException(Text.of(MSDataSyncPluginInfo.pluginPrefix, "No users were affected"));
throw new CommandException(Text.of(MSDataSyncPluginInfo.pluginPrefix, "Optimizer already running! Use /sync optimize info"));
}
snapshotOptimizationService.optimize(users, source, "Manual");
}

return CommandResult.success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.Optional;
import java.util.function.Consumer;

public class SnapshotEditCommand implements CommandExecutor {
public class SnapshotViewCommand implements CommandExecutor {

@Inject
SnapshotRepository<Snapshot, Key> snapshotRepository;
Expand Down Expand Up @@ -80,7 +80,7 @@ public CommandResult execute(CommandSource source, CommandContext context) throw
Snapshot snapshot = optionalSnapshot.get();
source.sendMessage(Text.of(MSDataSyncPluginInfo.pluginPrefix, TextColors.YELLOW, "Editing snapshot ", TextColors.GOLD, dateFormatService.format(optionalSnapshot.get().getId().getDate())));
final boolean[] closeData = new boolean[]{false};
final boolean permissionToEdit = player.hasPermission(PluginPermissions.EDIT_SNAPSHOTS);
final boolean permissionToEdit = player.hasPermission(PluginPermissions.SNAPSHOT_VIEW_EDIT);
Inventory inventory = Inventory.builder().of(inventoryArchetype).listener(InteractInventoryEvent.Close.class, e -> {
if (closeData[0] || !permissionToEdit) {
source.sendMessage(
Expand Down
Loading

0 comments on commit a637f01

Please sign in to comment.