1.17 port of 2.4.0
parent
4fa30024cf
commit
a10dab5f98
|
@ -1,18 +1,18 @@
|
|||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
minecraft_version=1.19
|
||||
yarn_mappings=1.19+build.4
|
||||
minecraft_version=1.17.1
|
||||
yarn_mappings=1.17.1+build.65
|
||||
loader_version=0.14.8
|
||||
|
||||
#Fabric api
|
||||
fabric_version=0.56.1+1.19
|
||||
fabric_version=0.46.1+1.17
|
||||
|
||||
#Cloth Config
|
||||
cloth_version=7.0.72
|
||||
cloth_version=5.0.37
|
||||
|
||||
#ModMenu
|
||||
modmenu_version=4.0.0
|
||||
modmenu_version=2.0.4
|
||||
|
||||
#Lazy DFU for faster dev start
|
||||
lazydfu_version=v0.1.3
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|||
import me.shedaniel.autoconfig.AutoConfig;
|
||||
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
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;
|
||||
|
@ -82,7 +82,7 @@ public class TextileBackup implements ModInitializer {
|
|||
}
|
||||
});
|
||||
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(
|
||||
LiteralArgumentBuilder.<ServerCommandSource>literal("backup")
|
||||
.requires((ctx) -> {
|
||||
try {
|
||||
|
|
|
@ -20,6 +20,7 @@ package net.szum123321.textile_backup;
|
|||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
@ -54,11 +55,11 @@ public class TextileLogger {
|
|||
this.messageFactory = ParameterizedMessageFactory.INSTANCE;
|
||||
this.logger = LogManager.getLogger(StackLocatorUtil.getCallerClass(2), messageFactory);
|
||||
this.prefix = "[" + prefix + "]" + " ";
|
||||
this.prefixText = Text.literal(this.prefix).styled(style -> style.withColor(0x5B23DA));
|
||||
this.prefixText = new LiteralText(this.prefix).styled(style -> style.withColor(0x5B23DA));
|
||||
}
|
||||
|
||||
public MutableText getPrefixText() {
|
||||
return prefixText.copy();
|
||||
return prefixText.shallowCopy();
|
||||
}
|
||||
|
||||
public void log(Level level, String msg, Object... data) {
|
||||
|
@ -94,14 +95,14 @@ public class TextileLogger {
|
|||
}
|
||||
|
||||
boolean sendFeedback(Level level, ServerCommandSource source, String msg, Object... args) {
|
||||
if(source != null && source.isExecutedByPlayer()) {
|
||||
MutableText text = Text.literal(messageFactory.newMessage(msg, args).getFormattedMessage());
|
||||
if(source != null && source.getEntity() instanceof PlayerEntity) {
|
||||
MutableText text = new LiteralText(messageFactory.newMessage(msg, args).getFormattedMessage());
|
||||
|
||||
if(level.intLevel() == Level.TRACE.intLevel()) text.formatted(Formatting.GREEN);
|
||||
else if(level.intLevel() <= Level.WARN.intLevel()) text.formatted(Formatting.RED);
|
||||
else text.formatted(Formatting.WHITE);
|
||||
|
||||
source.sendFeedback(prefixText.copy().append(text), false);
|
||||
source.sendFeedback(prefixText.shallowCopy().append(text), false);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package net.szum123321.textile_backup.commands;
|
||||
|
||||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.MutableText;
|
||||
|
||||
import java.time.format.DateTimeParseException;
|
||||
|
@ -28,7 +28,7 @@ public class CommandExceptions {
|
|||
public static final DynamicCommandExceptionType DATE_TIME_PARSE_COMMAND_EXCEPTION_TYPE = new DynamicCommandExceptionType(o -> {
|
||||
DateTimeParseException e = (DateTimeParseException)o;
|
||||
|
||||
MutableText message = Text.literal("An exception occurred while trying to parse:\n")
|
||||
MutableText message = new LiteralText("An exception occurred while trying to parse:\n")
|
||||
.append(e.getParsedString())
|
||||
.append("\n");
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package net.szum123321.textile_backup.commands.manage;
|
|||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.szum123321.textile_backup.TextileBackup;
|
||||
|
@ -35,7 +36,6 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DeleteCommand {
|
||||
|
@ -69,10 +69,11 @@ public class DeleteCommand {
|
|||
Files.delete(file);
|
||||
log.sendInfo(source, "File {} successfully deleted!", file);
|
||||
|
||||
if(source.isExecutedByPlayer())
|
||||
if(source.getEntity() instanceof PlayerEntity)
|
||||
log.info("Player {} deleted {}.", source.getPlayer().getName(), file);
|
||||
} catch (IOException e) {
|
||||
log.sendError(source, "Something went wrong while deleting file!");
|
||||
} catch (CommandSyntaxException ignored) {
|
||||
}
|
||||
} else {
|
||||
log.sendError(source, "Couldn't delete the file because it's being restored right now.");
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
|
||||
package net.szum123321.textile_backup.core;
|
||||
|
||||
import net.minecraft.network.message.MessageType;
|
||||
import net.minecraft.network.MessageType;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.szum123321.textile_backup.TextileBackup;
|
||||
|
@ -32,7 +32,6 @@ import net.szum123321.textile_backup.config.ConfigPOJO;
|
|||
import net.szum123321.textile_backup.Statics;
|
||||
import net.szum123321.textile_backup.mixin.MinecraftServerSessionAccessor;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.file.SimplePathVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -40,22 +39,28 @@ import java.io.IOException;
|
|||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Utilities {
|
||||
private final static ConfigHelper config = ConfigHelper.INSTANCE;
|
||||
private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME);
|
||||
|
||||
public static void notifyPlayers(@NotNull MinecraftServer server, String msg) {
|
||||
public static void notifyPlayers(@NotNull MinecraftServer server, UUID sender, String msg) {
|
||||
MutableText message = log.getPrefixText();
|
||||
message.append(Text.literal(msg).formatted(Formatting.WHITE));
|
||||
message.append(new LiteralText(msg).formatted(Formatting.WHITE));
|
||||
|
||||
server.getPlayerManager().broadcast(message, MessageType.SYSTEM);
|
||||
server.getPlayerManager().broadcastChatMessage(
|
||||
message,
|
||||
MessageType.SYSTEM,
|
||||
sender
|
||||
);
|
||||
}
|
||||
|
||||
public static String getLevelName(MinecraftServer server) {
|
||||
|
@ -65,7 +70,7 @@ public class Utilities {
|
|||
public static Path getWorldFolder(MinecraftServer server) {
|
||||
return ((MinecraftServerSessionAccessor)server)
|
||||
.getSession()
|
||||
.getWorldDirectory(World.OVERWORLD);
|
||||
.getWorldDirectory(World.OVERWORLD).toPath();
|
||||
}
|
||||
|
||||
public static Path getBackupRootPath(String worldName) {
|
||||
|
@ -83,7 +88,7 @@ public class Utilities {
|
|||
}
|
||||
|
||||
public static void deleteDirectory(Path path) throws IOException {
|
||||
Files.walkFileTree(path, new SimplePathVisitor() {
|
||||
Files.walkFileTree(path, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Files.delete(file);
|
||||
|
|
|
@ -41,6 +41,10 @@ public record BackupContext(@NotNull MinecraftServer server,
|
|||
return save;
|
||||
}
|
||||
|
||||
public UUID getInitiatorUUID() {
|
||||
return initiator.equals(ActionInitiator.Player) && commandSource.getEntity() != null ? commandSource.getEntity().getUuid(): Util.NIL_UUID;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private MinecraftServer server;
|
||||
private ServerCommandSource commandSource;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package net.szum123321.textile_backup.core.create;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.szum123321.textile_backup.Statics;
|
||||
import net.szum123321.textile_backup.TextileBackup;
|
||||
|
@ -42,6 +43,7 @@ public class BackupHelper {
|
|||
public static Runnable create(BackupContext ctx) {
|
||||
if(config.get().broadcastBackupStart) {
|
||||
Utilities.notifyPlayers(ctx.server(),
|
||||
ctx.getInitiatorUUID(),
|
||||
"Warning! Server backup will begin shortly. You may experience some lag."
|
||||
);
|
||||
} else {
|
||||
|
@ -177,7 +179,7 @@ public class BackupHelper {
|
|||
Files.delete(f);
|
||||
log.sendInfoAL(ctx, "Deleting: {}", f);
|
||||
} catch (IOException e) {
|
||||
if(ctx.isExecutedByPlayer()) log.sendError(ctx, "Something went wrong while deleting: {}.", f);
|
||||
if(ctx.getEntity() instanceof PlayerEntity) log.sendError(ctx, "Something went wrong while deleting: {}.", f);
|
||||
log.error("Something went wrong while deleting: {}.", f, e);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ public class MakeBackupRunnable implements Runnable {
|
|||
if(config.get().broadcastBackupDone) {
|
||||
Utilities.notifyPlayers(
|
||||
context.server(),
|
||||
context.getInitiatorUUID(),
|
||||
"Done!"
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -21,15 +21,21 @@ package net.szum123321.textile_backup.core.restore;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.util.Util;
|
||||
import net.szum123321.textile_backup.core.ActionInitiator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public record RestoreContext(RestoreHelper.RestoreableFile restoreableFile,
|
||||
MinecraftServer server,
|
||||
@Nullable String comment,
|
||||
ActionInitiator initiator,
|
||||
ServerCommandSource commandSource) {
|
||||
|
||||
public UUID getInitiatorUUID() {
|
||||
return initiator.equals(ActionInitiator.Player) && commandSource.getEntity() != null ? commandSource.getEntity().getUuid(): Util.NIL_UUID;
|
||||
}
|
||||
public static final class Builder {
|
||||
private RestoreHelper.RestoreableFile file;
|
||||
private MinecraftServer server;
|
||||
|
|
|
@ -67,6 +67,7 @@ public class RestoreHelper {
|
|||
|
||||
Utilities.notifyPlayers(
|
||||
ctx.server(),
|
||||
ctx.getInitiatorUUID(),
|
||||
"Warning! The server is going to shut down in " + config.get().restoreDelay + " seconds!"
|
||||
);
|
||||
|
||||
|
|
|
@ -40,12 +40,11 @@
|
|||
"depends": {
|
||||
"fabricloader": ">=0.14.6",
|
||||
"fabric": "*",
|
||||
"minecraft": "~1.19",
|
||||
"minecraft": "~1.17",
|
||||
"cloth-config2": "*",
|
||||
"java": ">=16"
|
||||
},
|
||||
"recommends": {
|
||||
|
||||
"modmenu": "*"
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue