2.x-1.16
Szum123321 2021-08-04 11:01:25 +02:00
parent cb55d5c9a4
commit be3f32a282
14 changed files with 26 additions and 30 deletions

View File

@ -1,5 +1,5 @@
plugins { plugins {
id 'fabric-loom' version '0.9-SNAPSHOT' id 'fabric-loom' version '0.7-SNAPSHOT'
id 'maven-publish' id 'maven-publish'
} }

View File

@ -1,18 +1,18 @@
# Done to increase the memory available to gradle. # Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
minecraft_version=1.17.1 minecraft_version=1.16.5
yarn_mappings=1.17.1+build.32 yarn_mappings=1.16.5+build.10
loader_version=0.11.6 loader_version=0.11.6
#Fabric api #Fabric api
fabric_version=0.37.0+1.17 fabric_version=0.37.1+1.16
#Cloth Config #Cloth Config
cloth_version=5.0.37 cloth_version=4.11.26
#ModMenu #ModMenu
modmenu_version=2.0.4 modmenu_version=1.16.11
#Lazy DFU for faster dev start #Lazy DFU for faster dev start
lazydfu_version=0.1.2 lazydfu_version=0.1.2

View File

@ -86,7 +86,7 @@ public class TextileBackup implements ModInitializer {
return ((config.get().playerWhitelist.contains(ctx.getEntityOrThrow().getEntityName()) || return ((config.get().playerWhitelist.contains(ctx.getEntityOrThrow().getEntityName()) ||
ctx.hasPermissionLevel(config.get().permissionLevel)) && ctx.hasPermissionLevel(config.get().permissionLevel)) &&
!config.get().playerBlacklist.contains(ctx.getEntityOrThrow().getEntityName())) || !config.get().playerBlacklist.contains(ctx.getEntityOrThrow().getEntityName())) ||
(ctx.getServer().isSinglePlayer() && (ctx.getMinecraftServer().isSinglePlayer() &&
config.get().alwaysSingleplayerAllowed); config.get().alwaysSingleplayerAllowed);
} catch (Exception ignored) { //Command was called from server console. } catch (Exception ignored) { //Command was called from server console.
return true; return true;

View File

@ -22,6 +22,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.szum123321.textile_backup.core.create.BackupContext; import net.szum123321.textile_backup.core.create.BackupContext;
import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Level;
@ -29,7 +30,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.message.MessageFactory;
import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.apache.logging.log4j.message.ParameterizedMessageFactory;
import org.apache.logging.log4j.util.StackLocatorUtil;
/* /*
This is practically just a copy-pate of Cotton's ModLogger with a few changes This is practically just a copy-pate of Cotton's ModLogger with a few changes
@ -43,18 +43,11 @@ public class TextileLogger {
private final String prefix; private final String prefix;
private final MutableText prefixText; private final MutableText prefixText;
/* public TextileLogger(String name, String prefix) {
this.messageFactory = ParameterizedMessageFactory.INSTANCE;
this.logger = LogManager.getLogger(name, messageFactory);
this.prefix = "[" + prefix + "]" + " ";
this.prefixText = new LiteralText(this.prefix).styled(style -> style.withColor(0x5B23DA));
}
*/
public TextileLogger(String prefix) { public TextileLogger(String prefix) {
this.messageFactory = ParameterizedMessageFactory.INSTANCE; this.messageFactory = ParameterizedMessageFactory.INSTANCE;
this.logger = LogManager.getLogger(StackLocatorUtil.getCallerClass(2), messageFactory); this.logger = LogManager.getLogger(getCallerClass(2), messageFactory);
this.prefix = "[" + prefix + "]" + " "; this.prefix = "[" + prefix + "]" + " ";
this.prefixText = new LiteralText(this.prefix).styled(style -> style.withColor(0x5B23DA)); this.prefixText = new LiteralText(this.prefix).styled(style -> style.withColor(TextColor.fromRgb(0x5B23DA)));
} }
public MutableText getPrefixText() { public MutableText getPrefixText() {
@ -151,4 +144,8 @@ public class TextileLogger {
public void sendErrorAL(BackupContext context, String msg, Object... args) { public void sendErrorAL(BackupContext context, String msg, Object... args) {
sendErrorAL(context.getCommandSource(), msg, args); sendErrorAL(context.getCommandSource(), msg, args);
} }
private static String getCallerClass(int depth) {
return new Throwable().getStackTrace()[depth].getClassName();
}
} }

View File

@ -42,7 +42,7 @@ public final class FileSuggestionProvider implements SuggestionProvider<ServerCo
public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> ctx, SuggestionsBuilder builder) throws CommandSyntaxException { public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> ctx, SuggestionsBuilder builder) throws CommandSyntaxException {
String remaining = builder.getRemaining(); String remaining = builder.getRemaining();
for (RestoreHelper.RestoreableFile file : RestoreHelper.getAvailableBackups(ctx.getSource().getServer())) { for (RestoreHelper.RestoreableFile file : RestoreHelper.getAvailableBackups(ctx.getSource().getMinecraftServer())) {
String formattedCreationTime = file.getCreationTime().format(Statics.defaultDateTimeFormatter); String formattedCreationTime = file.getCreationTime().format(Statics.defaultDateTimeFormatter);
if (formattedCreationTime.startsWith(remaining)) { if (formattedCreationTime.startsWith(remaining)) {

View File

@ -38,7 +38,7 @@ public class CleanupCommand {
log.sendInfo( log.sendInfo(
source, source,
"Deleted: {} files.", "Deleted: {} files.",
BackupHelper.executeFileLimit(source, Utilities.getLevelName(source.getServer())) BackupHelper.executeFileLimit(source, Utilities.getLevelName(source.getMinecraftServer()))
); );
return 1; return 1;

View File

@ -92,7 +92,7 @@ public class BlacklistCommand {
builder.append(" successfully."); builder.append(" successfully.");
ctx.getSource().getServer().getCommandManager().sendCommandTree(player); ctx.getSource().getMinecraftServer().getCommandManager().sendCommandTree(player);
log.sendInfo(ctx.getSource(), builder.toString()); log.sendInfo(ctx.getSource(), builder.toString());
} }
@ -109,7 +109,7 @@ public class BlacklistCommand {
config.get().playerBlacklist.remove(player.getEntityName()); config.get().playerBlacklist.remove(player.getEntityName());
config.save(); config.save();
ctx.getSource().getServer().getCommandManager().sendCommandTree(player); ctx.getSource().getMinecraftServer().getCommandManager().sendCommandTree(player);
log.sendInfo(ctx.getSource(), "Player: {} removed from the blacklist successfully.", player.getEntityName()); log.sendInfo(ctx.getSource(), "Player: {} removed from the blacklist successfully.", player.getEntityName());
} }

View File

@ -57,7 +57,7 @@ public class DeleteCommand {
throw CommandExceptions.DATE_TIME_PARSE_COMMAND_EXCEPTION_TYPE.create(e); throw CommandExceptions.DATE_TIME_PARSE_COMMAND_EXCEPTION_TYPE.create(e);
} }
File root = Utilities.getBackupRootPath(Utilities.getLevelName(source.getServer())); File root = Utilities.getBackupRootPath(Utilities.getLevelName(source.getMinecraftServer()));
Optional<File> optionalFile = Arrays.stream(root.listFiles()) Optional<File> optionalFile = Arrays.stream(root.listFiles())
.filter(Utilities::isValidBackup) .filter(Utilities::isValidBackup)

View File

@ -33,7 +33,7 @@ public class ListBackupsCommand {
public static LiteralArgumentBuilder<ServerCommandSource> register() { public static LiteralArgumentBuilder<ServerCommandSource> register() {
return CommandManager.literal("list") return CommandManager.literal("list")
.executes(ctx -> { StringBuilder builder = new StringBuilder(); .executes(ctx -> { StringBuilder builder = new StringBuilder();
List<RestoreHelper.RestoreableFile> backups = RestoreHelper.getAvailableBackups(ctx.getSource().getServer()); List<RestoreHelper.RestoreableFile> backups = RestoreHelper.getAvailableBackups(ctx.getSource().getMinecraftServer());
if(backups.size() == 0) { if(backups.size() == 0) {
builder.append("There a no backups available for this world."); builder.append("There a no backups available for this world.");

View File

@ -92,7 +92,7 @@ public class WhitelistCommand {
builder.append(" successfully."); builder.append(" successfully.");
ctx.getSource().getServer().getCommandManager().sendCommandTree(player); ctx.getSource().getMinecraftServer().getCommandManager().sendCommandTree(player);
log.sendInfo(ctx.getSource(), builder.toString()); log.sendInfo(ctx.getSource(), builder.toString());
} }
@ -109,7 +109,7 @@ public class WhitelistCommand {
config.get().playerWhitelist.remove(player.getEntityName()); config.get().playerWhitelist.remove(player.getEntityName());
config.save(); config.save();
ctx.getSource().getServer().getCommandManager().sendCommandTree(player); ctx.getSource().getMinecraftServer().getCommandManager().sendCommandTree(player);
log.sendInfo(ctx.getSource(), "Player: {} removed from the whitelist successfully.", player.getEntityName()); log.sendInfo(ctx.getSource(), "Player: {} removed from the whitelist successfully.", player.getEntityName());
} }

View File

@ -79,7 +79,7 @@ public class RestoreBackupCommand {
throw CommandExceptions.DATE_TIME_PARSE_COMMAND_EXCEPTION_TYPE.create(e); throw CommandExceptions.DATE_TIME_PARSE_COMMAND_EXCEPTION_TYPE.create(e);
} }
Optional<RestoreHelper.RestoreableFile> backupFile = RestoreHelper.findFileAndLockIfPresent(dateTime, source.getServer()); Optional<RestoreHelper.RestoreableFile> backupFile = RestoreHelper.findFileAndLockIfPresent(dateTime, source.getMinecraftServer());
if(backupFile.isPresent()) { if(backupFile.isPresent()) {
log.info("Found file to restore {}", backupFile.get().getFile().getName()); log.info("Found file to restore {}", backupFile.get().getFile().getName());

View File

@ -115,7 +115,7 @@ public record BackupContext(@NotNull MinecraftServer server,
} }
if (server == null) { if (server == null) {
if (commandSource != null) setServer(commandSource.getServer()); if (commandSource != null) setServer(commandSource.getMinecraftServer());
else else
throw new RuntimeException("Neither MinecraftServer or ServerCommandSource were provided!"); throw new RuntimeException("Neither MinecraftServer or ServerCommandSource were provided!");
} }

View File

@ -86,7 +86,7 @@ public record RestoreContext(RestoreHelper.RestoreableFile file,
} }
public RestoreContext build() { public RestoreContext build() {
if (server == null) server = serverCommandSource.getServer(); if (server == null) server = serverCommandSource.getMinecraftServer();
ActionInitiator initiator = serverCommandSource.getEntity() instanceof PlayerEntity ? ActionInitiator.Player : ActionInitiator.ServerConsole; ActionInitiator initiator = serverCommandSource.getEntity() instanceof PlayerEntity ? ActionInitiator.Player : ActionInitiator.ServerConsole;

View File

@ -39,12 +39,11 @@
"depends": { "depends": {
"fabricloader": ">=0.11", "fabricloader": ">=0.11",
"fabric": "*", "fabric": "*",
"minecraft": "1.17.*", "minecraft": "1.16.*",
"cloth-config2": "*", "cloth-config2": "*",
"java": ">=16" "java": ">=16"
}, },
"recommends": { "recommends": {
"modmenu": "*" "modmenu": "*"
}, },