diff --git a/README.md b/README.md
index 59d3a21..d71db8f 100644
--- a/README.md
+++ b/README.md
@@ -7,9 +7,6 @@ Allows you to quickly copy your in-game coordinates to send to your friends!
When in-game, press the `Copy Coordinates` key (` by default) and the coordinates will be copied to your keyboard.
## Config
-```json5
-{
- // The format of the string that gets copied. Use $x, $y and $z as placeholders.
- "format": "Coordinates: $x, $y, $z"
-}
+```yaml
+format=$x, $y, $z
```
diff --git a/build.gradle b/build.gradle
index 6ae6857..e7f0873 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,5 @@
plugins {
- id 'fabric-loom' version '0.12-SNAPSHOT'
+ id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
}
@@ -11,7 +11,6 @@ version = project.mod_version
group = project.maven_group
repositories {
- maven { url "https://maven.shedaniel.me/" }
}
dependencies {
@@ -22,10 +21,6 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
-
- modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
- exclude(group: "net.fabricmc.fabric-api")
- }
}
processResources {
diff --git a/gradle.properties b/gradle.properties
index ba1fa2f..05f0058 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/develop
- minecraft_version=1.19.2
- yarn_mappings=1.19.2+build.1
- loader_version=0.14.8
+ minecraft_version=1.20.1
+ yarn_mappings=1.20.1+build.10
+ loader_version=0.14.21
# Mod Properties
mod_version = 1.0.0
@@ -13,5 +13,4 @@ org.gradle.jvmargs=-Xmx1G
archives_base_name = quickcoordscopy
# Dependencies
- fabric_version=0.58.6+1.19.2
- cloth_config_version=8.0.75
+ fabric_version=0.86.0+1.20.1
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 7454180..033e24c 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 41dfb87..9f4197d 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index c53aefa..fcb6fca 100755
--- a/gradlew
+++ b/gradlew
@@ -1,7 +1,7 @@
#!/bin/sh
#
-# Copyright © 2015-2021 the original 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.
@@ -32,10 +32,10 @@
# 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».
+# * 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:
#
@@ -55,7 +55,7 @@
# 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
+# https://github.com/gradle/gradle/blob/HEAD/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/.
@@ -80,13 +80,10 @@ do
esac
done
-APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
-
-APP_NAME="Gradle"
+# This is normally unused
+# shellcheck disable=SC2034
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"'
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -133,22 +130,29 @@ location of your Java installation."
fi
else
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.
+ if ! command -v java >/dev/null 2>&1
+ then
+ 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
location of your Java installation."
+ fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi
+
+# 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"'
+
# 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
@@ -205,6 +213,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
diff --git a/gradlew.bat b/gradlew.bat
index 107acd3..93e3f59 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -14,7 +14,7 @@
@rem limitations under the License.
@rem
-@if "%DEBUG%" == "" @echo off
+@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto execute
+if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
+if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
diff --git a/src/main/java/io/github/simplexdev/quickcoordscopy/QuickCoordsCopy.java b/src/main/java/io/github/simplexdev/quickcoordscopy/QuickCoordsCopy.java
deleted file mode 100644
index 5ee37d5..0000000
--- a/src/main/java/io/github/simplexdev/quickcoordscopy/QuickCoordsCopy.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package io.github.simplexdev.quickcoordscopy;
-
-import io.github.simplexdev.quickcoordscopy.config.QuickCoordsCopyConfig;
-import me.shedaniel.autoconfig.AutoConfig;
-import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
-import net.fabricmc.api.ModInitializer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class QuickCoordsCopy implements ModInitializer {
- public static final Logger LOGGER = LoggerFactory.getLogger("quickcoordscopy");
-
- @Override
- public void onInitialize() {
- AutoConfig.register(QuickCoordsCopyConfig.class, JanksonConfigSerializer::new);
- LOGGER.info("Consider your taters tinied.");
- }
-}
diff --git a/src/main/java/io/github/simplexdev/quickcoordscopy/QuickCoordsCopyClient.java b/src/main/java/io/github/simplexdev/quickcoordscopy/QuickCoordsCopyClient.java
index 3db7556..5ea33e0 100644
--- a/src/main/java/io/github/simplexdev/quickcoordscopy/QuickCoordsCopyClient.java
+++ b/src/main/java/io/github/simplexdev/quickcoordscopy/QuickCoordsCopyClient.java
@@ -1,35 +1,44 @@
package io.github.simplexdev.quickcoordscopy;
-import io.github.simplexdev.quickcoordscopy.config.QuickCoordsCopyConfig;
-import me.shedaniel.autoconfig.AutoConfig;
+import org.lwjgl.glfw.GLFW;
+
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Text;
-import org.lwjgl.glfw.GLFW;
public class QuickCoordsCopyClient implements ClientModInitializer {
+ final String DEFAULT_COORDS_FORMAT = "$x, $y, $z";
+ final String COORDS_FORMAT_KEY = "formatting";
+ final String DEFAULT_CONFIG = COORDS_FORMAT_KEY + "=" + DEFAULT_COORDS_FORMAT;
- QuickCoordsCopyConfig config = AutoConfig.getConfigHolder(QuickCoordsCopyConfig.class).getConfig();
+ SimpleConfig config = SimpleConfig
+ .of("quickcoordscopy")
+ .provider((namespace) -> DEFAULT_CONFIG)
+ .request();
- private static final KeyBinding copyCoordsKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
- "key.quickcoordscopy.copy",
- InputUtil.Type.KEYSYM,
- GLFW.GLFW_KEY_GRAVE_ACCENT,
- "category.quickcoordscopy.main"
- ));
+ private static final KeyBinding copyCoordsKey = KeyBindingHelper
+ .registerKeyBinding(
+ new KeyBinding(
+ "key.quickcoordscopy.copy",
+ InputUtil.Type.KEYSYM,
+ GLFW.GLFW_KEY_GRAVE_ACCENT,
+ "category.quickcoordscopy.main"));
@Override
public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (copyCoordsKey.wasPressed()) {
if (client.player != null) {
- var coords = config.format;
- coords = coords.replace("$x", String.valueOf(Math.round(client.player.getX())));
- coords = coords.replace("$y", String.valueOf(Math.round(client.player.getY())));
- coords = coords.replace("$z", String.valueOf(Math.round(client.player.getZ())));
+ final var format = config.getOrDefault(COORDS_FORMAT_KEY, DEFAULT_COORDS_FORMAT);
+
+ final var coords = format
+ .replace("$x", String.valueOf(Math.round(client.player.getX())))
+ .replace("$y", String.valueOf(Math.round(client.player.getY())))
+ .replace("$z", String.valueOf(Math.round(client.player.getZ())));
+
client.keyboard.setClipboard(coords);
client.player.sendMessage(Text.literal("Copied coordinates to keyboard!"));
}
diff --git a/src/main/java/io/github/simplexdev/quickcoordscopy/SimpleConfig.java b/src/main/java/io/github/simplexdev/quickcoordscopy/SimpleConfig.java
new file mode 100644
index 0000000..7cedd2a
--- /dev/null
+++ b/src/main/java/io/github/simplexdev/quickcoordscopy/SimpleConfig.java
@@ -0,0 +1,253 @@
+package io.github.simplexdev.quickcoordscopy;
+
+/*
+ * Copyright (c) 2021 magistermaks
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Scanner;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import net.fabricmc.loader.api.FabricLoader;
+
+public class SimpleConfig {
+
+ private static final Logger LOGGER = LogManager.getLogger("SimpleConfig");
+ private final HashMap config = new HashMap<>();
+ private final ConfigRequest request;
+ private boolean broken = false;
+
+ public interface DefaultConfig {
+ String get(String namespace);
+
+ static String empty(String namespace) {
+ return "";
+ }
+ }
+
+ public static class ConfigRequest {
+
+ private final File file;
+ private final String filename;
+ private DefaultConfig provider;
+
+ private ConfigRequest(File file, String filename) {
+ this.file = file;
+ this.filename = filename;
+ this.provider = DefaultConfig::empty;
+ }
+
+ /**
+ * Sets the default config provider, used to generate the
+ * config if it's missing.
+ *
+ * @param provider default config provider
+ * @return current config request object
+ * @see DefaultConfig
+ */
+ public ConfigRequest provider(DefaultConfig provider) {
+ this.provider = provider;
+ return this;
+ }
+
+ /**
+ * Loads the config from the filesystem.
+ *
+ * @return config object
+ * @see SimpleConfig
+ */
+ public SimpleConfig request() {
+ return new SimpleConfig(this);
+ }
+
+ private String getConfig() {
+ return provider.get(filename) + "\n";
+ }
+
+ }
+
+ /**
+ * Creates new config request object, ideally `namespace`
+ * should be the name of the mod id of the requesting mod
+ *
+ * @param filename - name of the config file
+ * @return new config request object
+ */
+ public static ConfigRequest of(String filename) {
+ Path path = FabricLoader.getInstance().getConfigDir();
+ return new ConfigRequest(path.resolve(filename + ".properties").toFile(), filename);
+ }
+
+ private void createConfig() throws IOException {
+
+ // try creating missing files
+ request.file.getParentFile().mkdirs();
+ Files.createFile(request.file.toPath());
+
+ // write default config data
+ PrintWriter writer = new PrintWriter(request.file, "UTF-8");
+ writer.write(request.getConfig());
+ writer.close();
+
+ }
+
+ private void loadConfig() throws IOException {
+ try (final var reader = new Scanner(request.file)) {
+ for (int line = 1; reader.hasNextLine(); line++) {
+ parseConfigEntry(reader.nextLine(), line);
+ }
+ }
+ }
+
+ private void parseConfigEntry(String entry, int line) {
+ if (!entry.isEmpty() && !entry.startsWith("#")) {
+ String[] parts = entry.split("=", 2);
+ if (parts.length == 2) {
+ config.put(parts[0], parts[1]);
+ } else {
+ throw new RuntimeException("Syntax error in config file on line " + line + "!");
+ }
+ }
+ }
+
+ private SimpleConfig(ConfigRequest request) {
+ this.request = request;
+ String identifier = "Config '" + request.filename + "'";
+
+ if (!request.file.exists()) {
+ LOGGER.info(identifier + " is missing, generating default one...");
+
+ try {
+ createConfig();
+ } catch (IOException e) {
+ LOGGER.error(identifier + " failed to generate!");
+ LOGGER.trace(e);
+ broken = true;
+ }
+ }
+
+ if (!broken) {
+ try {
+ loadConfig();
+ } catch (Exception e) {
+ LOGGER.error(identifier + " failed to load!");
+ LOGGER.trace(e);
+ broken = true;
+ }
+ }
+
+ }
+
+ /**
+ * Queries a value from config, returns `null` if the
+ * key does not exist.
+ *
+ * @return value corresponding to the given key
+ * @see SimpleConfig#getOrDefault
+ */
+ @Deprecated
+ public String get(String key) {
+ return config.get(key);
+ }
+
+ /**
+ * Returns string value from config corresponding to the given
+ * key, or the default string if the key is missing.
+ *
+ * @return value corresponding to the given key, or the default value
+ */
+ public String getOrDefault(String key, String def) {
+ String val = get(key);
+ return val == null ? def : val;
+ }
+
+ /**
+ * Returns integer value from config corresponding to the given
+ * key, or the default integer if the key is missing or invalid.
+ *
+ * @return value corresponding to the given key, or the default value
+ */
+ public int getOrDefault(String key, int def) {
+ try {
+ return Integer.parseInt(get(key));
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Returns boolean value from config corresponding to the given
+ * key, or the default boolean if the key is missing.
+ *
+ * @return value corresponding to the given key, or the default value
+ */
+ public boolean getOrDefault(String key, boolean def) {
+ String val = get(key);
+ if (val != null) {
+ return val.equalsIgnoreCase("true");
+ }
+
+ return def;
+ }
+
+ /**
+ * Returns double value from config corresponding to the given
+ * key, or the default string if the key is missing or invalid.
+ *
+ * @return value corresponding to the given key, or the default value
+ */
+ public double getOrDefault(String key, double def) {
+ try {
+ return Double.parseDouble(get(key));
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * If any error occurred during loading or reading from the config
+ * a 'broken' flag is set, indicating that the config's state
+ * is undefined and should be discarded using `delete()`
+ *
+ * @return the 'broken' flag of the configuration
+ */
+ public boolean isBroken() {
+ return broken;
+ }
+
+ /**
+ * deletes the config file from the filesystem
+ *
+ * @return true if the operation was successful
+ */
+ public boolean delete() {
+ LOGGER.warn("Config '" + request.filename + "' was removed from existence! Restart the game to regenerate it.");
+ return request.file.delete();
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/simplexdev/quickcoordscopy/config/QuickCoordsCopyConfig.java b/src/main/java/io/github/simplexdev/quickcoordscopy/config/QuickCoordsCopyConfig.java
deleted file mode 100644
index 8d48465..0000000
--- a/src/main/java/io/github/simplexdev/quickcoordscopy/config/QuickCoordsCopyConfig.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package io.github.simplexdev.quickcoordscopy.config;
-
-import me.shedaniel.autoconfig.ConfigData;
-import me.shedaniel.autoconfig.annotation.Config;
-import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment;
-
-@Config(name = "quickcoordscopy")
-public class QuickCoordsCopyConfig implements ConfigData {
- @Comment("The format of the string that gets copied. Use $x, $y and $z as placeholders.")
- public String format = "Coordinates: $x, $y, $z";
-}
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index f2f79a7..99a7916 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -2,7 +2,6 @@
"schemaVersion": 1,
"id": "quickcoordscopy",
"version": "${version}",
-
"name": "Quick Coordinates Copy",
"description": "Easily copy your in-game coordinates to share with friends.",
"authors": [
@@ -12,22 +11,17 @@
"homepage": "https://bs3k.xyz/",
"sources": "https://github.com/Simplex-Dev/quickcoordscopy"
},
-
"license": "LGPL",
"icon": "assets/quickcoordscopy/icon.png",
-
"environment": "*",
"entrypoints": {
- "main": [
- "io.github.simplexdev.quickcoordscopy.QuickCoordsCopy"
- ],
"client": [
"io.github.simplexdev.quickcoordscopy.QuickCoordsCopyClient"
]
},
-
"depends": {
- "minecraft": "~1.19",
+ "fabric": "*",
+ "minecraft": "1.20.x",
"java": ">=17"
}
-}
+}
\ No newline at end of file