Divided command classes into sub-packages

2.x-1.16
szymon 2020-08-04 17:29:45 +02:00
parent 227faef84c
commit 695ae7964e
8 changed files with 54 additions and 34 deletions

View File

@ -26,7 +26,12 @@ import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.szum123321.textile_backup.commands.*; import net.szum123321.textile_backup.commands.create.CleanupCommand;
import net.szum123321.textile_backup.commands.create.StartBackupCommand;
import net.szum123321.textile_backup.commands.permission.BlacklistCommand;
import net.szum123321.textile_backup.commands.permission.WhitelistCommand;
import net.szum123321.textile_backup.commands.restore.ListBackupsCommand;
import net.szum123321.textile_backup.commands.restore.RestoreBackupCommand;
import net.szum123321.textile_backup.core.create.BackupScheduler; import net.szum123321.textile_backup.core.create.BackupScheduler;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View File

@ -1,28 +0,0 @@
package net.szum123321.textile_backup.commands;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.szum123321.textile_backup.core.Utilities;
import java.util.Arrays;
public class ListBackupsCommand {
public static LiteralArgumentBuilder<ServerCommandSource> register() {
return CommandManager.literal("list")
.executes(ctx -> {
StringBuilder builder = new StringBuilder();
builder.append("Available backups: ");
Arrays.stream(Utilities.getBackupRootPath(Utilities.getLevelName(ctx.getSource().getMinecraftServer()))
.listFiles())
.forEach(file -> builder.append(file.getName()).append(", "));
ctx.getSource().sendFeedback(new LiteralText(builder.toString()), false);
return 1;
});
}
}

View File

@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.szum123321.textile_backup.commands; package net.szum123321.textile_backup.commands.create;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;

View File

@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.szum123321.textile_backup.commands; package net.szum123321.textile_backup.commands.create;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;

View File

@ -1,4 +1,4 @@
package net.szum123321.textile_backup.commands; package net.szum123321.textile_backup.commands.permission;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;

View File

@ -1,4 +1,4 @@
package net.szum123321.textile_backup.commands; package net.szum123321.textile_backup.commands.permission;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;

View File

@ -0,0 +1,43 @@
package net.szum123321.textile_backup.commands.restore;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.szum123321.textile_backup.core.Utilities;
import java.io.File;
import java.util.Arrays;
import java.util.Iterator;
public class ListBackupsCommand {
public static LiteralArgumentBuilder<ServerCommandSource> register() {
return CommandManager.literal("list")
.executes(ctx -> {
StringBuilder builder = new StringBuilder();
File[] files = Utilities.getBackupRootPath(Utilities.getLevelName(ctx.getSource().getMinecraftServer())).listFiles();
if(files.length == 0) {
builder.append("There a no backups available for this world.");
} else if(files.length == 1) {
builder.append("There is only one backup available: ");
builder.append(files[0].getName());
} else {
Iterator<File> iterator = Arrays.stream(files).iterator();
builder.append("Available backups: ");
builder.append(iterator.next());
while(iterator.hasNext()) {
builder.append("\n");
builder.append(iterator.next());
}
}
ctx.getSource().sendFeedback(new LiteralText(builder.toString()), false);
return 1;
});
}
}

View File

@ -1,4 +1,4 @@
package net.szum123321.textile_backup.commands; package net.szum123321.textile_backup.commands.restore;
import com.mojang.brigadier.LiteralMessage; import com.mojang.brigadier.LiteralMessage;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;