Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jun 12, 2024
1 parent 44b086d commit 273f000
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 21
java-version: 21\

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ dependencies {
modCompileOnly("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
modLocalRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")

modImplementation include("eu.pb4:predicate-api:0.4.0+1.20.5")
modImplementation include("eu.pb4:placeholder-api:2.4.0-pre.1+1.20.5")
modImplementation include("eu.pb4:predicate-api:0.5.1+1.21")
modImplementation include("eu.pb4:placeholder-api:2.4.0-pre.2+1.21")
modImplementation include("me.lucko:fabric-permissions-api:0.3.1")
modImplementation include("eu.pb4:player-data-api:0.4.0+1.20.3")
modImplementation include("eu.pb4:sidebar-api:0.4.0+1.20.5")
modImplementation include("eu.pb4:player-data-api:0.6.0+1.21")
modImplementation include("eu.pb4:sidebar-api:0.5.0+1.21")

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.20.5-rc2
yarn_mappings=1.20.5-rc2+build.1
loader_version=0.15.10
minecraft_version=1.21-rc1
yarn_mappings=1.21-rc1+build.1
loader_version=0.15.11

#Fabric api
fabric_version=0.97.3+1.20.5
fabric_version=0.100.1+1.21

# Mod Properties
mod_version = 1.4.0+1.20.5
mod_version = 1.5.0+1.21
maven_group = eu.pb4
archives_base_name = styled-sidebars

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/styledsidebars/CardboardWarning.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.List;

public class CardboardWarning implements PreLaunchEntrypoint {
public static final String MOD_NAME = "Styled Player List";
public static final String MOD_NAME = "Styled Sidebars";
public static final Logger LOGGER = LogUtils.getLogger();

// Overwrite heavy and generally problematic bukkit implementation
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/eu/pb4/styledsidebars/ModInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ModInit implements ModInitializer {

public static final Map<ServerPlayNetworkHandler, CustomSidebar> SIDEBARS = new HashMap<>();

public static final Identifier STORAGE = new Identifier("styled-sidebars","selected");
public static final Identifier STORAGE = Identifier.of("styled-sidebars","selected");

@Override
public void onInitialize() {
Expand All @@ -36,7 +36,7 @@ public void onInitialize() {
Commands.register();
ServerLifecycleEvents.SERVER_STARTING.register((s) -> {
CardboardWarning.checkAndAnnounce();
ConfigManager.loadConfig();
ConfigManager.loadConfig(s.getRegistryManager());
});

ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
Expand All @@ -58,6 +58,6 @@ public void onInitialize() {
}

public static Identifier id(String path) {
return new Identifier(ID, path);
return Identifier.of(ID, path);
}
}
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/styledsidebars/command/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void register() {
}

private static int reloadConfig(CommandContext<ServerCommandSource> context) {
if (ConfigManager.loadConfig()) {
if (ConfigManager.loadConfig(context.getSource().getRegistryManager())) {
context.getSource().sendFeedback(() -> Text.literal("Reloaded config!"), false);
for (var entry : ModInit.SIDEBARS.entrySet()) {
var type = PlayerDataApi.getGlobalDataFor(entry.getKey().player, ModInit.STORAGE);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/eu/pb4/styledsidebars/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Config {
.quickText()
.staticPreParsing()
.build();
public static final Config DEFAULT = new Config(new ConfigData());

public final ConfigData configData;
public final TextNode switchMessage;
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/eu/pb4/styledsidebars/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import eu.pb4.styledsidebars.ModInit;
import eu.pb4.styledsidebars.config.data.ConfigData;
import eu.pb4.styledsidebars.config.data.SidebarDefinition;
import net.minecraft.registry.RegistryWrapper;

import java.io.BufferedWriter;
import java.io.IOException;
Expand All @@ -20,12 +21,7 @@


public class ConfigManager {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().setLenient()
.registerTypeHierarchyAdapter(MinecraftPredicate.class, GsonPredicateSerializer.INSTANCE)
.registerTypeHierarchyAdapter(SidebarDefinition.Line.class, new SidebarDefinition.Line.Serializer())
.create();

private static Config CONFIG;
private static Config CONFIG = Config.DEFAULT;
private static boolean ENABLED = false;
private static final LinkedHashMap<String, SidebarHandler> STYLES = new LinkedHashMap<>();

Expand All @@ -37,22 +33,26 @@ public static boolean isEnabled() {
return ENABLED;
}

public static boolean loadConfig() {
public static boolean loadConfig(RegistryWrapper.WrapperLookup lookup) {
ENABLED = false;

CONFIG = null;
try {
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().setLenient()
.registerTypeHierarchyAdapter(MinecraftPredicate.class, GsonPredicateSerializer.create(lookup))
.registerTypeHierarchyAdapter(SidebarDefinition.Line.class, new SidebarDefinition.Line.Serializer())
.create();

var configStyle = Paths.get("", "config", "styled-sidebars", "styles");
var configDir = Paths.get("", "config", "styled-sidebars");

if (Files.notExists(configStyle)) {
Files.createDirectories(configStyle);
Files.writeString(configStyle.resolve("default.json"), GSON.toJson(DefaultValues.exampleStyleData()));
Files.writeString(configStyle.resolve("right_text.json"), GSON.toJson(DefaultValues.exampleStyleDataWithRight()));
Files.writeString(configStyle.resolve("scrolling.json"), GSON.toJson(DefaultValues.exampleStyleAnimatedData()));
Files.writeString(configStyle.resolve("pages.json"), GSON.toJson(DefaultValues.examplePagesStyleData()));
Files.writeString(configStyle.resolve("disable.json"), GSON.toJson(DefaultValues.disabledStyleData()));
Files.writeString(configStyle.resolve("default.json"), gson.toJson(DefaultValues.exampleStyleData()));
Files.writeString(configStyle.resolve("right_text.json"), gson.toJson(DefaultValues.exampleStyleDataWithRight()));
Files.writeString(configStyle.resolve("scrolling.json"), gson.toJson(DefaultValues.exampleStyleAnimatedData()));
Files.writeString(configStyle.resolve("pages.json"), gson.toJson(DefaultValues.examplePagesStyleData()));
Files.writeString(configStyle.resolve("disable.json"), gson.toJson(DefaultValues.disabledStyleData()));
}

ConfigData config;
Expand All @@ -61,13 +61,13 @@ public static boolean loadConfig() {


if (Files.exists(configFile)) {
config = GSON.fromJson(new InputStreamReader(Files.newInputStream(configFile), StandardCharsets.UTF_8), ConfigData.class);
config = gson.fromJson(new InputStreamReader(Files.newInputStream(configFile), StandardCharsets.UTF_8), ConfigData.class);
} else {
config = new ConfigData();
}

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(configFile), StandardCharsets.UTF_8));
writer.write(GSON.toJson(config));
writer.write(gson.toJson(config));
writer.close();

STYLES.clear();
Expand All @@ -76,7 +76,7 @@ public static boolean loadConfig() {
Files.list(configStyle).filter((path) -> path.toString().endsWith(".json")).forEach((fileName) -> {
var id = fileName.getFileName().toString();
try {
SidebarHandler style = new SidebarHandler(id.substring(0, id.length() - ".json".length()), GSON.fromJson(Files.readString(fileName, StandardCharsets.UTF_8), SidebarDefinition.class));
SidebarHandler style = new SidebarHandler(id.substring(0, id.length() - ".json".length()), gson.fromJson(Files.readString(fileName, StandardCharsets.UTF_8), SidebarDefinition.class));
STYLES.put(style.id, style);
} catch (IOException e) {
e.printStackTrace();
Expand Down

0 comments on commit 273f000

Please sign in to comment.