feat: 添加更多工具方法
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package cn.hamster3.mc.plugin.core.common.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import cn.hamster3.mc.plugin.core.common.util.SerializeUtils;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -295,6 +294,6 @@ public class DisplayMessage {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CoreConstantObjects.GSON.toJson(this);
|
||||
return saveToJson().toString();
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@@ -64,10 +65,7 @@ public final class CommonUtils {
|
||||
*/
|
||||
@NotNull
|
||||
public static String replaceColorCode(@Nullable String string, @NotNull String defaultValue) {
|
||||
if (string == null) {
|
||||
return replaceColorCode(defaultValue);
|
||||
}
|
||||
return replaceColorCode(string);
|
||||
return replaceColorCode(Objects.requireNonNullElse(string, defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,10 +1,8 @@
|
||||
package cn.hamster3.mc.plugin.core.common.util;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -46,8 +44,8 @@ public final class SerializeUtils {
|
||||
public static Title deserializeTitle(@NotNull JsonObject object) {
|
||||
if (object.has("times")) {
|
||||
return Title.title(
|
||||
CoreConstantObjects.GSON.fromJson(object.get("title"), Component.class),
|
||||
CoreConstantObjects.GSON.fromJson(object.get("subtitle"), Component.class),
|
||||
GsonComponentSerializer.gson().deserializeFromTree(object.get("title")),
|
||||
GsonComponentSerializer.gson().deserializeFromTree(object.get("subtitle")),
|
||||
deserializeTitleTimes(object.getAsJsonObject("times"))
|
||||
);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user