From 83b689216daf35d3da8f33be9a62c46403a577e5 Mon Sep 17 00:00:00 2001 From: Keuin Date: Tue, 4 Jan 2022 19:09:33 +0800 Subject: Make it compile for Minecraft 1.18. --- build.gradle | 52 ++--- gradle.properties | 8 +- gradle/wrapper/gradle-wrapper.jar | Bin 59203 -> 59536 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 257 ++++++++++++--------- .../kbackupfabric/backup/BackupFilesystemUtil.java | 2 +- .../suggestion/BackupNameSuggestionProvider.java | 2 +- .../notification/DistinctNotifiable.java | 3 +- .../notification/NotificationManager.java | 4 +- .../kbackupfabric/operation/BackupOperation.java | 4 +- .../kbackupfabric/operation/DeleteOperation.java | 4 +- .../kbackupfabric/operation/RestoreOperation.java | 2 +- .../com/keuin/kbackupfabric/ui/KBCommands.java | 6 +- .../com/keuin/kbackupfabric/util/PrintUtil.java | 36 +-- .../java/com/keuin/kbackupfabric/util/ZipUtil.java | 3 - src/main/resources/fabric.mod.json | 2 +- 16 files changed, 213 insertions(+), 174 deletions(-) diff --git a/build.gradle b/build.gradle index eff7f20..c71ec07 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'fabric-loom' version '0.5-SNAPSHOT' + id 'fabric-loom' version '0.10-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 archivesBaseName = project.archives_base_name version = project.mod_version + "_mc" + project.minecraft_version @@ -28,52 +28,42 @@ dependencies { processResources { inputs.property "version", project.version - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" + filesMatching("fabric.mod.json") { expand "version": project.version } - - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" - } } -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" +tasks.withType(JavaCompile).configureEach { + // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. + it.options.release = 17 } -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" - from sourceSets.main.allSource +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() } jar { - from "LICENSE" + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } } // configure the maven publication publishing { publications { mavenJava(MavenPublication) { - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } + from components.java } } - // select the repositories you want to publish to + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. repositories { - // uncomment to publish to the local maven - // mavenLocal() + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. } } diff --git a/gradle.properties b/gradle.properties index 02a9f95..08de13e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.14.4 -yarn_mappings=1.14.4+build.18 -loader_version=0.11.0 +minecraft_version=1.18.1 +yarn_mappings=1.18.1+build.17 +loader_version=0.12.12 # Mod Properties mod_version=1.6.7 maven_group=com.keuin.kbackupfabric archives_base_name=kbackup-fabric # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api -fabric_version=0.28.4+1.14 +fabric_version=0.45.1+1.18 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..7454180 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4d9ca16..ffed3a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0..1b6c787 100644 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/src/main/java/com/keuin/kbackupfabric/backup/BackupFilesystemUtil.java b/src/main/java/com/keuin/kbackupfabric/backup/BackupFilesystemUtil.java index eac7ce9..49fe6a0 100644 --- a/src/main/java/com/keuin/kbackupfabric/backup/BackupFilesystemUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/backup/BackupFilesystemUtil.java @@ -53,7 +53,7 @@ public final class BackupFilesystemUtil { public static String getLevelPath(MinecraftServer server) throws IOException { if (!(server instanceof MinecraftDedicatedServer)) throw new IllegalStateException("This plugin is server-side only."); - String path = (new File(server.getRunDirectory().getCanonicalPath(), server.getLevelName())).getAbsolutePath(); + String path = (new File(server.getRunDirectory().getCanonicalPath(), ((MinecraftDedicatedServer) server).getLevelName())).getAbsolutePath(); Logger.getLogger("getLevelPath").info(String.format("Level path: %s", path)); assert (new File(path)).exists(); return path; diff --git a/src/main/java/com/keuin/kbackupfabric/backup/suggestion/BackupNameSuggestionProvider.java b/src/main/java/com/keuin/kbackupfabric/backup/suggestion/BackupNameSuggestionProvider.java index 9c0c1c2..3a5108e 100644 --- a/src/main/java/com/keuin/kbackupfabric/backup/suggestion/BackupNameSuggestionProvider.java +++ b/src/main/java/com/keuin/kbackupfabric/backup/suggestion/BackupNameSuggestionProvider.java @@ -1,7 +1,7 @@ package com.keuin.kbackupfabric.backup.suggestion; import com.mojang.brigadier.suggestion.SuggestionProvider; -import net.minecraft.server.command.CommandSource; +import net.minecraft.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; import java.io.File; diff --git a/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java b/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java index b44bfce..4a01227 100644 --- a/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java +++ b/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java @@ -3,6 +3,7 @@ package com.keuin.kbackupfabric.notification; import net.minecraft.network.MessageType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; +import net.minecraft.util.Util; /** * Decouple from ServerPlayerEntity, in case further migration to other APIs. @@ -33,7 +34,7 @@ public interface DistinctNotifiable { @Override public void notify(Text text) { - serverPlayerEntity.sendChatMessage(text, MessageType.SYSTEM); + serverPlayerEntity.sendMessage(text, MessageType.SYSTEM, Util.NIL_UUID); } @Override diff --git a/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java b/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java index 5536a1a..92c119b 100644 --- a/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java +++ b/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java @@ -38,9 +38,9 @@ public class NotificationManager { BackupMetadata backup = MetadataHolder.getMetadata(); notifiable.notify( new LiteralText("The world has been restored to backup ") - .append(new LiteralText("[" + backup.getBackupName() + "]").setStyle(new Style().setColor(Formatting.GREEN))) + .append(new LiteralText("[" + backup.getBackupName() + "]").setStyle(Style.EMPTY.withColor(Formatting.GREEN))) .append(new LiteralText(" (created at ")) - .append(new LiteralText("[" + DateUtil.fromEpochMillis(backup.getBackupTime()) + "]").setStyle(new Style().setColor(Formatting.GREEN))) + .append(new LiteralText("[" + DateUtil.fromEpochMillis(backup.getBackupTime()) + "]").setStyle(Style.EMPTY.withColor(Formatting.GREEN))) .append(new LiteralText(")")) ); } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java index 1798fb7..75977a0 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java @@ -32,7 +32,7 @@ public class BackupOperation extends InvokableAsyncBlockingOperation { @Override protected void async() { String backupSaveDirectory = ""; - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); boolean success = false; // only success when everything is done try { //// Do our main backup logic @@ -72,7 +72,7 @@ public class BackupOperation extends InvokableAsyncBlockingOperation { PrintUtil.broadcast("Making backup, please wait ..."); // Get server - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); // Save old auto-save switch state for restoration after finished oldWorldsSavingDisabled.clear(); diff --git a/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java index 7bfb0b7..9428592 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java @@ -48,7 +48,7 @@ public class DeleteOperation extends InvokableAsyncBlockingOperation { private void delete() { try { - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); PrintUtil.info("Deleting backup file " + this.backupFileName); File backupFile = new File(getBackupSaveDirectory(server), backupFileName); SavedIncrementalBackup incrementalBackup = null; @@ -82,7 +82,7 @@ public class DeleteOperation extends InvokableAsyncBlockingOperation { new IncrementalBackupStorageManager(getIncrementalBackupBaseDirectory(server).toPath()); Iterable backups = ObjectCollectionSerializer .fromDirectory(BackupFilesystemUtil - .getBackupSaveDirectory(context.getSource().getMinecraftServer())); + .getBackupSaveDirectory(context.getSource().getServer())); int deleted = manager.deleteObjectCollection(incrementalBackup.getObjectCollection(), backups); PrintUtil.info("Deleted " + deleted + " unused file(s)."); } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java index e18f3c8..999e39a 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java @@ -19,7 +19,7 @@ public class RestoreOperation extends InvokableBlockingOperation { private final ConfiguredBackupMethod configuredBackupMethod; public RestoreOperation(CommandContext context, ConfiguredBackupMethod configuredBackupMethod) { - server = Objects.requireNonNull(context.getSource().getMinecraftServer()); + server = Objects.requireNonNull(context.getSource().getServer()); this.serverThread = Objects.requireNonNull(server.getThread()); this.context = Objects.requireNonNull(context); this.configuredBackupMethod = Objects.requireNonNull(configuredBackupMethod); diff --git a/src/main/java/com/keuin/kbackupfabric/ui/KBCommands.java b/src/main/java/com/keuin/kbackupfabric/ui/KBCommands.java index e148f24..784cd65 100644 --- a/src/main/java/com/keuin/kbackupfabric/ui/KBCommands.java +++ b/src/main/java/com/keuin/kbackupfabric/ui/KBCommands.java @@ -255,7 +255,7 @@ public final class KBCommands { public static int delete(CommandContext context) { String backupFileName = parseBackupFileName(context, StringArgumentType.getString(context, "backupName")); - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); if (backupFileName == null) return list(context); // Show the list and return @@ -286,7 +286,7 @@ public final class KBCommands { public static int restore(CommandContext context) { try { //KBMain.restore("name") - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); String backupFileName = parseBackupFileName(context, StringArgumentType.getString(context, "backupName")); // backupFileName = parseBackupFileName(context, backupFileName); @@ -344,7 +344,7 @@ public final class KBCommands { PrintUtil.info("Start backup..."); // configure backup method - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); ConfiguredBackupMethod method = !incremental ? new ConfiguredPrimitiveBackupMethod( PrimitiveBackupFileNameEncoder.INSTANCE.encode(customBackupName, LocalDateTime.now()), getLevelPath(server), diff --git a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java index 34b548a..640794e 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java @@ -1,6 +1,7 @@ package com.keuin.kbackupfabric.util; import com.mojang.brigadier.context.CommandContext; +import net.minecraft.network.MessageType; import net.minecraft.server.PlayerManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; @@ -13,24 +14,26 @@ import org.jetbrains.annotations.Nullable; import java.util.Optional; +import java.util.UUID; + public final class PrintUtil { private static final Object syncMessage = new Object(); private static final Object syncBroadcast = new Object(); - private static final Style broadcastStyle = new Style().setColor(Formatting.AQUA); - private static final Style infoStyle = new Style().setColor(Formatting.WHITE); - private static final Style stressStyle = new Style().setColor(Formatting.AQUA); - private static final Style warnStyle = new Style().setColor(Formatting.YELLOW); - private static final Style errorStyle = new Style().setColor(Formatting.DARK_RED); + private static final Style broadcastStyle = Style.EMPTY.withColor(Formatting.AQUA); + private static final Style infoStyle = Style.EMPTY.withColor(Formatting.WHITE); + private static final Style stressStyle = Style.EMPTY.withColor(Formatting.AQUA); + private static final Style warnStyle = Style.EMPTY.withColor(Formatting.YELLOW); + private static final Style errorStyle = Style.EMPTY.withColor(Formatting.DARK_RED); private static final Logger LOGGER = LogManager.getLogger(); - private static PlayerManager playerManager = null; + private static PlayerManager fuckingPlayerManager = null; public static void setPlayerManager(PlayerManager playerManager) { - if (PrintUtil.playerManager == null) - PrintUtil.playerManager = playerManager; + if (fuckingPlayerManager == null) + fuckingPlayerManager = playerManager; } public static void broadcast(String message) { @@ -39,9 +42,11 @@ public final class PrintUtil { public static void broadcast(String message, Style style) { synchronized (syncBroadcast) { - Optional.ofNullable(playerManager) - .ifPresent(pm -> - pm.sendToAll(new LiteralText(message).setStyle(style))); + if (fuckingPlayerManager != null) +// fuckingPlayerManager.sendToAll(new LiteralText(message).setStyle(broadcastStyle)); + fuckingPlayerManager.broadcast(new LiteralText(message).setStyle(broadcastStyle), MessageType.GAME_INFO, UUID.randomUUID()); + else + PrintUtil.error("Error in PrintUtil.broadcast: PlayerManager is not initialized."); } } @@ -77,19 +82,16 @@ public final class PrintUtil { return message(context, messageText, broadcastToOps, errorStyle); } - private static CommandContext message(@Nullable CommandContext context, String messageText, boolean broadcastToOps, Style style) { + private static CommandContext message(CommandContext context, String messageText, boolean broadcastToOps, Style style) { if (context != null) { synchronized (syncMessage) { - Text text = new LiteralText(messageText); - text.setStyle(style); + Text text = new LiteralText(messageText).setStyle(style); context.getSource().sendFeedback(text, broadcastToOps); } - return context; } else { - // if context is null, then `broadcastToOps` will be ignored for simplicity broadcast(messageText, style); - return null; } + return context; } /** diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java index eea1148..3497f20 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java @@ -208,9 +208,6 @@ public final class ZipUtil { // 创建解压文件 entryFile = new File(entryFilePath); if (entryFile.exists()) { - // 检测文件是否允许删除,如果不允许删除,将会抛出SecurityException - SecurityManager securityManager = new SecurityManager(); - securityManager.checkDelete(entryFilePath); // 删除已存在的目标文件 if (!entryFile.delete()) throw new IOException(String.format("Failed to delete existing file %s", entryFile.toString())); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5996e4b..4517b45 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -25,7 +25,7 @@ "depends": { "fabricloader": ">=0.7.4", "fabric": "*", - "minecraft": "1.14.x" + "minecraft": "1.18.x" }, "suggests": { "flamingo": "*" -- cgit v1.2.3