diff --git a/ViaFabricPlus-Visual/src/main/java/de/florianmichael/viafabricplus_visual/ViaFabricPlusVisual.java b/ViaFabricPlus-Visual/src/main/java/de/florianmichael/viafabricplus_visual/ViaFabricPlusVisual.java index 146cb8e6..3b23f4ba 100644 --- a/ViaFabricPlus-Visual/src/main/java/de/florianmichael/viafabricplus_visual/ViaFabricPlusVisual.java +++ b/ViaFabricPlus-Visual/src/main/java/de/florianmichael/viafabricplus_visual/ViaFabricPlusVisual.java @@ -34,12 +34,15 @@ public class ViaFabricPlusVisual implements ViaFabricPlusAddon { @Override public void onPostLoad() { + System.out.println("Test"); ArmorPointsDefinition.load(); ClassicItemSelectionScreen.create(InternalProtocolList.fromProtocolVersion(LegacyProtocolVersion.c0_28toc0_30)); } @Override public void onChangeVersion(ComparableProtocolVersion protocolVersion) { - ClassicItemSelectionScreen.INSTANCE.reload(protocolVersion); + if (ClassicItemSelectionScreen.INSTANCE != null) { + ClassicItemSelectionScreen.INSTANCE.reload(protocolVersion); + } } } diff --git a/build.gradle b/build.gradle index d086e6cc..82576ae4 100644 --- a/build.gradle +++ b/build.gradle @@ -82,7 +82,6 @@ jar { } } - tasks.register("installAddons") { group archivesBaseName dependsOn "build" diff --git a/gradle.properties b/gradle.properties index 3cd2ed3f..92a2c07e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,13 +5,14 @@ minecraft_version=1.19.3 yarn_mappings=1.19.3+build.5 loader_version=0.14.14 -mod_version=1.2.1 +mod_version=1.2.2 maven_group=de.florianmichael archives_base_name=viafabricplus -vialoadingbase_version=15f55e6b3e +vialoadingbase_version=f8468a707c viaversion_version=4.6.0-23w07a-SNAPSHOT viabackwards_version=4.6.0-23w07a-SNAPSHOT vialegacy_version=29a7082d7f viaaprilfools_version=cd4d0a2973 + mcstructs_text_version=2.2.0 diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java index 64faee83..8e7df348 100644 --- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java +++ b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java @@ -12,7 +12,7 @@ import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgume import de.florianmichael.viafabricplus.platform.ViaAprilFoolsPlatformImpl; import de.florianmichael.viafabricplus.platform.ViaLegacyPlatformImpl; import de.florianmichael.viafabricplus.provider.*; -import de.florianmichael.viafabricplus.value.ValueHolder; +import de.florianmichael.viafabricplus.util.SavingSystem; import de.florianmichael.vialoadingbase.ViaLoadingBase; import de.florianmichael.vialoadingbase.api.SubPlatform; import io.netty.channel.DefaultEventLoop; @@ -22,9 +22,7 @@ import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.metadata.Person; import net.minecraft.SharedConstants; import net.minecraft.client.MinecraftClient; -import net.minecraft.item.Item; import net.minecraft.network.ClientConnection; -import net.minecraft.registry.Registries; import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion; import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider; @@ -50,7 +48,7 @@ public class ViaFabricPlus { Collections.reverse(legacyProtocols); legacyProtocols.remove(LegacyProtocolVersion.c0_30cpe); final int c0_28toc0_30Index = legacyProtocols.indexOf(LegacyProtocolVersion.c0_28toc0_30); - legacyProtocols.set(c0_28toc0_30Index - 1, LegacyProtocolVersion.c0_30cpe); + legacyProtocols.add(c0_28toc0_30Index + 1, LegacyProtocolVersion.c0_30cpe); protocolVersions.addAll(legacyProtocols); }); private final SubPlatform SUB_PLATFORM_VIA_APRIL_FOOLS = new SubPlatform("ViaAprilFools", () -> true, ViaAprilFoolsPlatformImpl::new, protocolVersions -> { @@ -58,13 +56,11 @@ public class ViaFabricPlus { final int v1_16Index = protocolVersions.indexOf(ProtocolVersion.v1_16); final int v1_16_2Index = protocolVersions.indexOf(ProtocolVersion.v1_16_2); - protocolVersions.add(v1_14Index - 1,AprilFoolsProtocolVersion.s3d_shareware); - protocolVersions.add(v1_16Index - 1, AprilFoolsProtocolVersion.s20w14infinite); - protocolVersions.add(v1_16_2Index - 1, AprilFoolsProtocolVersion.sCombatTest8c); + protocolVersions.add(v1_14Index + 1,AprilFoolsProtocolVersion.s3d_shareware); + protocolVersions.add(v1_16Index + 1, AprilFoolsProtocolVersion.s20w14infinite); + protocolVersions.add(v1_16_2Index + 1, AprilFoolsProtocolVersion.sCombatTest8c); }); - private final List availableItemsInTargetVersion = new ArrayList<>(); - public void preLoad() { ViaLoadingBase.ViaLoadingBaseBuilder builder = ViaLoadingBase.ViaLoadingBaseBuilder.create(); @@ -73,7 +69,11 @@ public class ViaFabricPlus { builder = builder.runDirectory(RUN_DIRECTORY); builder = builder.nativeVersion(SharedConstants.getProtocolVersion()); - builder = builder.singlePlayerProvider(() -> MinecraftClient.getInstance().isInSingleplayer()); + builder = builder.singlePlayerProvider(() -> { + if (MinecraftClient.getInstance() == null) return true; + + return MinecraftClient.getInstance().isInSingleplayer(); + }); builder = builder.eventLoop(new DefaultEventLoop()); builder = builder.dumpCreator(() -> { final JsonObject parentNode = new JsonObject(); @@ -118,8 +118,7 @@ public class ViaFabricPlus { }); builder = builder.protocolReloader(protocolVersion -> { FabricLoader.getInstance().getEntrypoints("viafabricplus", ViaFabricPlusAddon.class).forEach(viaFabricPlusAddon -> viaFabricPlusAddon.onChangeVersion(protocolVersion)); - availableItemsInTargetVersion.clear(); - availableItemsInTargetVersion.addAll(Registries.ITEM.stream().filter(item -> ItemReleaseVersionDefinition.contains(item, protocolVersion)).toList()); + ItemReleaseVersionDefinition.reload(protocolVersion); }); builder.build(); @@ -127,7 +126,7 @@ public class ViaFabricPlus { } public void postLoad() throws Exception { - ValueHolder.setup(); + SavingSystem.setup(); PackFormatsDefinition.load(); ItemReleaseVersionDefinition.load(); @@ -144,11 +143,7 @@ public class ViaFabricPlus { } public void close() throws Exception { - ValueHolder.save(); - } - - public List getAvailableItemsInTargetVersion() { - return availableItemsInTargetVersion; + SavingSystem.save(); } public static ViaFabricPlus getClassWrapper() { diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/ItemReleaseVersionDefinition.java b/src/main/java/de/florianmichael/viafabricplus/definition/ItemReleaseVersionDefinition.java index 23e27cc5..c74ef0ce 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/ItemReleaseVersionDefinition.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/ItemReleaseVersionDefinition.java @@ -5,11 +5,10 @@ import de.florianmichael.viafabricplus.platform.ProtocolRange; import de.florianmichael.vialoadingbase.api.version.ComparableProtocolVersion; import net.minecraft.item.Item; import net.minecraft.item.Items; +import net.minecraft.registry.Registries; import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * Assigns to each Minecraft version the version in which the respective block or item was added @@ -18,11 +17,17 @@ import java.util.Map; */ public class ItemReleaseVersionDefinition { private final static Map itemMap = new HashMap<>(); + private final static List currentMap = new ArrayList<>(); - public static boolean contains(final Item item, final ComparableProtocolVersion version) { + public static void reload(final ComparableProtocolVersion protocolVersion) { + currentMap.clear(); + currentMap.addAll(Registries.ITEM.stream().filter(item -> ItemReleaseVersionDefinition.contains(item, protocolVersion)).toList()); + } + + public static boolean contains(final Item item, final ComparableProtocolVersion protocolVersion) { if (!itemMap.containsKey(item)) return true; - return Arrays.stream(itemMap.get(item)).anyMatch(protocolRange -> protocolRange.contains(version)); + return Arrays.stream(itemMap.get(item)).anyMatch(protocolRange -> protocolRange.contains(protocolVersion)); } public static void load() { @@ -1285,4 +1290,8 @@ public class ItemReleaseVersionDefinition { private static void register(final Item item, final ProtocolRange... ranges) { itemMap.put(item, ranges); } + + public static List getCurrentMap() { + return currentMap; + } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/item/MixinItemGroup_EntriesImpl.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/item/MixinItemGroup_EntriesImpl.java index ab86c5d1..0dba5cd6 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/item/MixinItemGroup_EntriesImpl.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/item/MixinItemGroup_EntriesImpl.java @@ -1,6 +1,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.item; import de.florianmichael.viafabricplus.ViaFabricPlus; +import de.florianmichael.viafabricplus.definition.ItemReleaseVersionDefinition; import de.florianmichael.viafabricplus.value.ValueHolder; import net.minecraft.client.MinecraftClient; import net.minecraft.item.Item; @@ -14,7 +15,7 @@ public class MixinItemGroup_EntriesImpl { @Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isEnabled(Lnet/minecraft/resource/featuretoggle/FeatureSet;)Z")) public boolean removeUnknownItems(Item instance, FeatureSet featureSet) { - if ((ViaFabricPlus.getClassWrapper().getAvailableItemsInTargetVersion().contains(instance) && ValueHolder.removeNotAvailableItemsFromCreativeTab.getValue()) || MinecraftClient.getInstance().isInSingleplayer()) { + if ((ItemReleaseVersionDefinition.getCurrentMap().contains(instance) && ValueHolder.removeNotAvailableItemsFromCreativeTab.getValue()) || MinecraftClient.getInstance().isInSingleplayer()) { return instance.isEnabled(featureSet); } return false; diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/ProtocolSelectionScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/ProtocolSelectionScreen.java index 6d8ac3b8..b440f2aa 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/ProtocolSelectionScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/ProtocolSelectionScreen.java @@ -12,6 +12,7 @@ import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import java.awt.*; @@ -34,6 +35,7 @@ public class ProtocolSelectionScreen extends Screen { super.init(); this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, height + 5, textRenderer.fontHeight + 4)); + this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(0, height - 20).size(20, 20).build()); this.addDrawableChild(ButtonWidget.builder(Text.literal("Values"), button -> ValuesScreen.open(this)).position(0, 0).size(98, 20).build()); } @@ -46,10 +48,7 @@ public class ProtocolSelectionScreen extends Screen { matrices.scale(2F, 2F, 2F); drawCenteredText(matrices, textRenderer, "ViaFabricPlus", width / 4, 3, Color.ORANGE.getRGB()); matrices.pop(); - drawCenteredText(matrices, textRenderer, "https://github.com/FlorianMichael/ViaFabricPlus", width / 2, (textRenderer.fontHeight + 2) * 2 + 3, Color.GREEN.getRGB()); - - final String authorString = "by EnZaXD/FlorianMichael"; - drawStringWithShadow(matrices, textRenderer, authorString, width - textRenderer.getWidth(authorString), 0, Color.GREEN.getRGB()); + drawCenteredText(matrices, textRenderer, "https://github.com/FlorianMichael/ViaFabricPlus", width / 2, (textRenderer.fontHeight + 2) * 2 + 3, -1); } @Override @@ -92,7 +91,7 @@ public class ProtocolSelectionScreen extends Screen { matrices.push(); matrices.translate(x, y - 1, 0); final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; - drawCenteredText(matrices, textRenderer, this.protocolVersion.getName(), entryWidth / 2, entryHeight / 2 - textRenderer.fontHeight / 2, isSelected ? Color.GREEN.getRGB() : Color.RED.getRGB()); + drawCenteredText(matrices, textRenderer, (isSelected ? Formatting.UNDERLINE : "") + this.protocolVersion.getName(), entryWidth / 2, entryHeight / 2 - textRenderer.fontHeight / 2, isSelected ? Color.GREEN.getRGB() : Color.RED.getRGB()); matrices.pop(); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/ValuesScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/ValuesScreen.java index 7e614929..11596829 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/ValuesScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/ValuesScreen.java @@ -1,5 +1,6 @@ package de.florianmichael.viafabricplus.screen; +import de.florianmichael.viafabricplus.util.ScreenUtil; import de.florianmichael.viafabricplus.value.AbstractValue; import de.florianmichael.viafabricplus.value.ValueHolder; import de.florianmichael.viafabricplus.value.impl.BooleanValue; @@ -8,10 +9,10 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; -import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import org.lwjgl.glfw.GLFW; import java.awt.*; @@ -35,20 +36,16 @@ public class ValuesScreen extends Screen { super.init(); this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, height + 5, (textRenderer.fontHeight + 2) * 2)); + this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(0, height - 20).size(20, 20).build()); } @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { super.render(matrices, mouseX, mouseY, delta); - matrices.push(); - matrices.scale(2F, 2F, 2F); - drawCenteredText(matrices, textRenderer, "ViaFabricPlus", width / 4, 3, Color.ORANGE.getRGB()); - matrices.pop(); - drawCenteredText(matrices, textRenderer, "https://github.com/FlorianMichael/ViaFabricPlus", width / 2, (textRenderer.fontHeight + 2) * 2 + 3, Color.GREEN.getRGB()); - - final String authorString = "by EnZaXD/FlorianMichael"; - drawStringWithShadow(matrices, textRenderer, authorString, width - textRenderer.getWidth(authorString), 0, Color.GREEN.getRGB()); + drawCenteredText(matrices, textRenderer, "Press right mouse button for toggling protocol sync", width / 2, 3, -1); + drawCenteredText(matrices, textRenderer, "Press left mouse button for normal toggling", width / 2, textRenderer.fontHeight + 2 + 3, -1); + drawCenteredText(matrices, textRenderer, "Values that have sync enabled will be toggled depending on the target version.", width / 2, (textRenderer.fontHeight + 2) * 2 + 3, -1); } @Override @@ -63,6 +60,16 @@ public class ValuesScreen extends Screen { ValueHolder.values.stream().map(ValueSlot::new).forEach(this::addEntry); } + + @Override + public int getRowWidth() { + return super.getRowWidth() + 140; + } + + @Override + protected int getScrollbarPositionX() { + return this.width - 5; + } } public static class ValueSlot extends AlwaysSelectedEntryListWidget.Entry { @@ -79,12 +86,20 @@ public class ValuesScreen extends Screen { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (value instanceof BooleanValue booleanValue) booleanValue.setValue(!booleanValue.getValue()); - if (value instanceof ProtocolSyncBooleanValue protocolSyncBooleanValue) { - if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) protocolSyncBooleanValue.setValue(!protocolSyncBooleanValue.getValue()); - if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) protocolSyncBooleanValue.setSyncWithProtocol(!protocolSyncBooleanValue.isSyncWithProtocol()); + if (value instanceof BooleanValue booleanValue) { + booleanValue.setValue(!booleanValue.getValue()); + ScreenUtil.playClickSound(); + } + if (value instanceof ProtocolSyncBooleanValue protocolSyncBooleanValue) { + if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) { + protocolSyncBooleanValue.setSyncWithProtocol(!protocolSyncBooleanValue.isSyncWithProtocol()); + ScreenUtil.playClickSound(); + } + if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && !protocolSyncBooleanValue.isSyncWithProtocol()) { + protocolSyncBooleanValue.setValue(!protocolSyncBooleanValue.getValue()); + ScreenUtil.playClickSound(); + } } - MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); return super.mouseClicked(mouseX, mouseY, button); } @@ -92,13 +107,19 @@ public class ValuesScreen extends Screen { public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { matrices.push(); matrices.translate(x, y, 0); + fill(matrices, 0, 0, entryWidth, entryHeight, Integer.MIN_VALUE); final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; if (value instanceof BooleanValue booleanValue) { final boolean isEnabled = booleanValue.getValue(); - drawCenteredText(matrices, textRenderer, booleanValue.getName(), entryWidth / 2, entryHeight / 2 - textRenderer.fontHeight / 2, isEnabled ? Color.GREEN.getRGB() : Color.RED.getRGB()); + drawCenteredText(matrices, textRenderer, (isEnabled ? Formatting.UNDERLINE : "") + booleanValue.getName(), entryWidth / 2, entryHeight / 2 - textRenderer.fontHeight / 2, isEnabled ? Color.GREEN.getRGB() : Color.RED.getRGB()); } else if (value instanceof ProtocolSyncBooleanValue protocolSyncBooleanValue) { - final boolean isEnabled = protocolSyncBooleanValue.getValue(); - drawCenteredText(matrices, textRenderer, protocolSyncBooleanValue.getName(), entryWidth / 2, entryHeight / 2 - textRenderer.fontHeight / 2, protocolSyncBooleanValue.isSyncWithProtocol() ? Color.ORANGE.getRGB() : isEnabled ? Color.GREEN.getRGB() : Color.RED.getRGB()); + final boolean isEnabled = protocolSyncBooleanValue.value; + Color color = isEnabled ? Color.GREEN : Color.RED; + if (protocolSyncBooleanValue.isSyncWithProtocol()) { + drawStringWithShadow(matrices, textRenderer, "Sync", entryWidth - textRenderer.getWidth("Sync") - 3, entryHeight / 2 - textRenderer.fontHeight / 2, Color.ORANGE.getRGB()); + color = color.darker().darker(); + } + drawStringWithShadow(matrices, textRenderer, (isEnabled ? Formatting.UNDERLINE.toString() : "") + protocolSyncBooleanValue.getName(), 3, entryHeight / 2 - textRenderer.fontHeight / 2, color.getRGB()); } matrices.pop(); } diff --git a/src/main/java/de/florianmichael/viafabricplus/util/SavingSystem.java b/src/main/java/de/florianmichael/viafabricplus/util/SavingSystem.java new file mode 100644 index 00000000..27948049 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/util/SavingSystem.java @@ -0,0 +1,44 @@ +package de.florianmichael.viafabricplus.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import de.florianmichael.viafabricplus.ViaFabricPlus; +import de.florianmichael.viafabricplus.value.AbstractValue; +import de.florianmichael.viafabricplus.value.ValueHolder; +import de.florianmichael.vialoadingbase.ViaLoadingBase; +import de.florianmichael.vialoadingbase.api.version.InternalProtocolList; + +import java.io.*; + +public class SavingSystem { + public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + public final static File CONFIG_FILE = new File(ViaFabricPlus.RUN_DIRECTORY, "settings.json"); + + public static void setup() throws FileNotFoundException { + if (CONFIG_FILE.exists()) { + final JsonObject parentNode = GSON.fromJson(new FileReader(CONFIG_FILE), JsonObject.class).getAsJsonObject(); + if (parentNode.has("protocol")) { + ViaLoadingBase.getClassWrapper().reload(InternalProtocolList.fromProtocolId(parentNode.get("protocol").getAsInt())); + } + for (AbstractValue value : ValueHolder.values) { + value.read(parentNode); + } + } + } + + public static void save() throws IOException { + CONFIG_FILE.delete(); + CONFIG_FILE.createNewFile(); + + try (final FileWriter fw = new FileWriter(CONFIG_FILE)) { + final JsonObject parentNode = new JsonObject(); + parentNode.addProperty("protocol", ViaLoadingBase.getTargetVersion().getVersion()); + for (AbstractValue value : ValueHolder.values) { + value.write(parentNode); + } + fw.write(GSON.toJson(parentNode)); + fw.flush(); + } + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/util/ScreenUtil.java b/src/main/java/de/florianmichael/viafabricplus/util/ScreenUtil.java new file mode 100644 index 00000000..e4a3eaa0 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/util/ScreenUtil.java @@ -0,0 +1,12 @@ +package de.florianmichael.viafabricplus.util; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; + +public class ScreenUtil { + + public static void playClickSound() { + MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/value/AbstractValue.java b/src/main/java/de/florianmichael/viafabricplus/value/AbstractValue.java index 8a276bdb..3bde3bd6 100644 --- a/src/main/java/de/florianmichael/viafabricplus/value/AbstractValue.java +++ b/src/main/java/de/florianmichael/viafabricplus/value/AbstractValue.java @@ -6,7 +6,7 @@ public abstract class AbstractValue { private final String name; private final T defaultValue; - private T value; + public T value; public AbstractValue(final String name, final T defaultValue) { this.name = name; diff --git a/src/main/java/de/florianmichael/viafabricplus/value/ValueHolder.java b/src/main/java/de/florianmichael/viafabricplus/value/ValueHolder.java index 39c898b0..1a94f647 100644 --- a/src/main/java/de/florianmichael/viafabricplus/value/ValueHolder.java +++ b/src/main/java/de/florianmichael/viafabricplus/value/ValueHolder.java @@ -1,23 +1,15 @@ package de.florianmichael.viafabricplus.value; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.platform.ProtocolRange; import de.florianmichael.viafabricplus.value.impl.BooleanValue; import de.florianmichael.viafabricplus.value.impl.ProtocolSyncBooleanValue; import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import java.io.*; import java.util.ArrayList; import java.util.List; public class ValueHolder { - public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - public final static File CONFIG_FILE = new File(ViaFabricPlus.RUN_DIRECTORY, "settings.json"); - public final static List> values = new ArrayList<>(); // General settings @@ -43,27 +35,4 @@ public class ValueHolder { // a1_0_15 -> c0_28toc0_30 public static final ProtocolSyncBooleanValue useBetaCraftAuthentication = new ProtocolSyncBooleanValue("Use BetaCraft authentication", ProtocolRange.andOlder(LegacyProtocolVersion.c0_28toc0_30)); - - public static void setup() throws FileNotFoundException { - if (CONFIG_FILE.exists()) { - final JsonObject parentNode = GSON.fromJson(new FileReader(CONFIG_FILE), JsonObject.class).getAsJsonObject(); - for (AbstractValue value : values) { - value.read(parentNode); - } - } - } - - public static void save() throws IOException { - CONFIG_FILE.delete(); - CONFIG_FILE.createNewFile(); - - try (final FileWriter fw = new FileWriter(CONFIG_FILE)) { - final JsonObject parentNode = new JsonObject(); - for (AbstractValue value : values) { - value.write(parentNode); - } - fw.write(GSON.toJson(parentNode)); - fw.flush(); - } - } }