Divided command classes into sub-packages
parent
227faef84c
commit
695ae7964e
|
@ -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.ServerTickEvents;
|
||||
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 org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
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 net.minecraft.server.command.CommandManager;
|
|
@ -16,7 +16,7 @@
|
|||
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.builder.LiteralArgumentBuilder;
|
|
@ -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.context.CommandContext;
|
|
@ -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.context.CommandContext;
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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.arguments.StringArgumentType;
|
Loading…
Reference in New Issue