Compare commits

..

25 commits

Author SHA1 Message Date
Oth3r
6eeb5b3698
Merge branch '1.20.6' into 1.20.4
# Conflicts:
#	gradle.properties
2025-07-08 13:22:15 -05:00
Oth3r
36ca37d8ff
Merge branch '1.21.1' into 1.20.6
# Conflicts:
#	gradle.properties
2025-07-08 13:20:45 -05:00
Oth3r
29cd1eccc1
Merge branch '1.21.4' into 1.21.1
# Conflicts:
#	gradle.properties
2025-07-08 13:18:11 -05:00
Oth3r
22e366bd86
fix version number (v1.2.4.5) 2025-07-08 13:16:30 -05:00
Oth3r
e75151a091
Merge branch '1.20.6' into 1.20.4
# Conflicts:
#	gradle.properties
#	src/main/java/one/oth3r/sit/utl/Events.java
2025-07-08 13:14:51 -05:00
Oth3r
a44362c6cd
Merge branch '1.21.1' into 1.20.6
# Conflicts:
#	gradle.properties
2025-07-08 13:03:57 -05:00
Oth3r
620ff81c37
Merge branch '1.21.4' into 1.21.1
# Conflicts:
#	gradle.properties
#	src/main/java/one/oth3r/sit/SitClient.java
2025-06-27 17:41:29 -05:00
Oth3r
6596ffe1ff
Merge branch '1.21.5' into 1.21.4
# Conflicts:
#	gradle.properties
2025-06-27 17:36:42 -05:00
Oth3r
82ec9b01b6
v1.2.4.5+1.21.5 2025-06-27 17:35:41 -05:00
Oth3r
13ddcbee82
Revert "1.21.6 port"
This reverts commit 34c20ac753.
2025-06-27 17:31:38 -05:00
Oth3r
e4f0625e4c
add devauth and update dependency formatting 2025-06-27 17:28:15 -05:00
Oth3r
9077e8e663
Merge branch 'dev'
# Conflicts:
#	gradle.properties
2025-06-24 14:01:03 -05:00
Oth3r
71eb10a2a0
v1.2.4.5 2025-06-24 14:00:33 -05:00
Oth3r
7a54b0a75a
otterlib 0.2.1.0 port 2025-06-24 13:50:23 -05:00
Oth3r
6dcd99c12a
v1.2.4.4 2025-06-23 17:57:20 -05:00
Oth3r
392d508ef3
update gradle 2025-06-23 17:32:40 -05:00
Oth3r
00c52b26cf
oth3r repo 2025-06-23 17:32:21 -05:00
Oth3r
34c20ac753 1.21.6 port
(cherry picked from commit 7a1f058f6c)
2025-06-21 18:00:22 -05:00
Oth3r
3f9517a1f0 1.21.6 update 2025-06-17 10:34:33 -05:00
Oth3r
7a1f058f6c 1.21.6 port 2025-06-17 10:34:23 -05:00
Oth3r
85cc76a022 otterlib language system 2025-06-16 20:36:32 -05:00
Oth3r
c8902c5138 remove unused utilities 2025-06-16 20:31:42 -05:00
Oth3r
b190792064 switch to otterlib Num utility 2025-06-16 20:30:38 -05:00
Oth3r
c9cc006245 otterlib 0.2 changes 2025-06-16 15:07:37 -05:00
Oth3r
ea7e42f8a5 changelog clarification 2025-06-14 19:13:19 -05:00
19 changed files with 130 additions and 285 deletions

View file

@ -14,8 +14,18 @@ base {
repositories { repositories {
mavenLocal() mavenLocal()
maven { url = "https://maven.terraformersmc.com/releases/" } maven {
maven { url = "https://maven.isxander.dev/releases" } name = "DevAuth"
url = "https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1"
}
maven {
name = "Terraformers"
url = "https://maven.terraformersmc.com/"
}
maven {
name "oth3rMavenSnapshots"
url "https://maven.oth3r.one/snapshots"
}
} }
loom { loom {
@ -27,11 +37,13 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// required dependencies
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
modImplementation "one.oth3r:otterlib:${project.otterlib_version}" modImplementation "one.oth3r:otterlib:${project.otterlib_version}"
// optional dependencies
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
modRuntimeOnly "me.djtheredstoner:DevAuth-fabric:${project.devauth_version}"
} }
processResources { processResources {

View file

@ -1,9 +1,17 @@
# v1.2.4.5
* bumped OtterLib version to `0.2.1.0`
* fixed default languages files not being able to be loaded
# v1.2.4.4
* bumped OtterLib version to `0.2.0.0`
* now relies on OtterLib Language Reader
# v1.2.4.3 # v1.2.4.3
* added a max OtterLib version as the beta will have breaking changes between major versions * added a max OtterLib version as the beta will have breaking changes between major versions
# v1.2.4.2 # v1.2.4.2
* fixed language file not loading (reverted uppercase locales) * fixed language file not loading (reverted uppercase locales)
* fixed block checking having a hardcoded player reach - now uses player reach * fixed block checking having a hardcoded player reach - now uses player reach (1.20.6+)
* fixed block and item tag check logic for cases with only not(!) tags * fixed block and item tag check logic for cases with only not(!) tags
# v1.2.4.1 # v1.2.4.1

View file

@ -10,15 +10,17 @@ minecraft_versions=1.20.4
minecraft_version=1.20.4 minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3 yarn_mappings=1.20.4+build.3
loader_version=0.16.13 loader_version=0.16.14
# Mod Properties # Mod Properties
mod_version=1.2.4.3+1.20.4 mod_version=1.2.4.5+1.20.4
maven_group=one.oth3r maven_group=one.oth3r
file_name=sit! file_name=sit!
# Dependencies # Dependencies
fabric_version=0.97.1+1.20.4 fabric_version=0.97.3+1.20.4
otterlib_version=0.2.1.0+1.20.4-fabric
otterlib_max_version=0.3.0.0+1.20.4-fabric
modmenu_version=9.0.0 modmenu_version=9.0.0
otterlib_version=0.1.2.1+1.20.4-fabric devauth_version=1.2.1
otterlib_max_version=0.2.0.0+1.20.4-fabric

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

25
gradlew vendored
View file

@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# SPDX-License-Identifier: Apache-2.0
#
############################################################################## ##############################################################################
# #
@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@ -83,7 +85,8 @@ done
# This is normally unused # This is normally unused
# shellcheck disable=SC2034 # shellcheck disable=SC2034
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@ -111,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;; NONSTOP* ) nonstop=true ;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH="\\\"\\\""
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
@ -144,7 +147,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #( case $MAX_FD in #(
max*) max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045 # shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) || MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit" warn "Could not query maximum file descriptor limit"
esac esac
@ -152,7 +155,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #( '' | soft) :;; #(
*) *)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045 # shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" || ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD" warn "Could not set maximum file descriptor limit to $MAX_FD"
esac esac
@ -201,16 +204,16 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. # 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"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command; # Collect all arguments for the java command:
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# shell script including quotes and variable substitutions, so put them in # and any embedded shellness will be escaped.
# double quotes to make sure that they get re-expanded; and # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# * put everything else in single quotes, so that it's not re-expanded. # treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \ -classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@" "$@"
# Stop when "xargs" is not available. # Stop when "xargs" is not available.

26
gradlew.bat vendored
View file

@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute if %ERRORLEVEL% equ 0 goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail
@ -57,22 +59,22 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell

View file

@ -7,9 +7,9 @@ import one.oth3r.otterlib.client.screen.ConfigScreen;
import one.oth3r.otterlib.client.screen.utl.CustomImage; import one.oth3r.otterlib.client.screen.utl.CustomImage;
import one.oth3r.otterlib.client.screen.utl.SimpleButton; import one.oth3r.otterlib.client.screen.utl.SimpleButton;
import one.oth3r.sit.file.FileData; import one.oth3r.sit.file.FileData;
import one.oth3r.sit.utl.Chat;
import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Events; import one.oth3r.sit.utl.Events;
import one.oth3r.sit.utl.Utl;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
@ -23,17 +23,17 @@ public class SitClient implements ClientModInitializer {
} }
public static Screen getConfigScreen(Screen parent) { public static Screen getConfigScreen(Screen parent) {
return new ConfigScreen(parent, Utl.lang("sit!.screen.config"), return new ConfigScreen(parent, Chat.lang("sit!.screen.config"),
new CustomImage(Identifier.of(Data.MOD_ID, "textures/gui/banner.png"),128, 72), new CustomImage(Identifier.of(Data.MOD_ID, "textures/gui/banner.png"),128, 72),
List.of( List.of(
SimpleButton.Templates.fileEditor(Utl.lang("config.server"), FileData.getServerConfig(), new CustomImage(Identifier.of(Data.MOD_ID, "textures/gui/sprites/server_button.png"),246,26)).build(), SimpleButton.Templates.fileEditor(Chat.lang("config.server"), FileData.getServerConfig(), new CustomImage(Identifier.of(Data.MOD_ID, "textures/gui/sprites/server_button.png"),246,26)).build(),
SimpleButton.Templates.fileEditor(Utl.lang("config.sitting"), FileData.getSittingConfig(), new CustomImage(Identifier.of(Data.MOD_ID, "textures/gui/sprites/sitting_button.png"), 246, 26)).build() SimpleButton.Templates.fileEditor(Chat.lang("config.sitting"), FileData.getSittingConfig(), new CustomImage(Identifier.of(Data.MOD_ID, "textures/gui/sprites/sitting_button.png"), 246, 26)).build()
), ),
List.of( List.of(
SimpleButton.Templates.warning(Utl.lang("sit!.gui.button.issues")).openLink("https://github.com/Oth3r/Sit/issues").build(), SimpleButton.Templates.warning(Chat.lang("sit!.gui.button.issues")).openLink("https://github.com/Oth3r/Sit/issues").build(),
new SimpleButton.Builder(Utl.lang("sit!.gui.button.website")).openLink("https://modrinth.com/mod/sit!").build(), new SimpleButton.Builder(Chat.lang("sit!.gui.button.website")).openLink("https://modrinth.com/mod/sit!").build(),
SimpleButton.Templates.done(Utl.lang("gui.done")).build(), SimpleButton.Templates.done(Chat.lang("gui.done")).build(),
SimpleButton.Templates.donate(Utl.lang("sit!.gui.button.donate")).openLink(URI.create("https://ko-fi.com/oth3r")).build() SimpleButton.Templates.donate(Chat.lang("sit!.gui.button.donate")).openLink(URI.create("https://ko-fi.com/oth3r")).build()
)); ));
} }
} }

View file

@ -8,8 +8,8 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import one.oth3r.sit.utl.Chat;
import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Logic; import one.oth3r.sit.utl.Logic;
import one.oth3r.sit.utl.Utl; import one.oth3r.sit.utl.Utl;
@ -50,7 +50,7 @@ public class SitCommand {
if (player == null) { if (player == null) {
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
Logic.reload(); Logic.reload();
Data.LOGGER.info(Utl.lang("sit!.chat.reloaded").toString()); Data.LOGGER.info(Chat.lang("sit!.chat.reloaded").toString());
} }
return 1; return 1;
} }
@ -76,7 +76,7 @@ public class SitCommand {
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
Logic.reload(); Logic.reload();
player.sendMessage(Utl.messageTag().append(Utl.lang("sit!.chat.reloaded").color(Color.GREEN)).b()); player.sendMessage(Chat.tag().append(Chat.lang("sit!.chat.reloaded").color(Color.GREEN)).b());
} }
if (args[0].equalsIgnoreCase("purgeChairEntities")) Utl.Entity.purge(player,true); if (args[0].equalsIgnoreCase("purgeChairEntities")) Utl.Entity.purge(player,true);

View file

@ -1,6 +1,9 @@
package one.oth3r.sit.file; package one.oth3r.sit.file;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import one.oth3r.otterlib.file.LanguageReader;
import one.oth3r.otterlib.file.ResourceReader;
import one.oth3r.sit.Sit;
import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Utl; import one.oth3r.sit.utl.Utl;
@ -56,11 +59,22 @@ public class FileData {
return playerSettings.getOrDefault(player, sittingConfig); return playerSettings.getOrDefault(player, sittingConfig);
} }
/// the language / text system for the mod
private static final LanguageReader langReader = new LanguageReader(
new ResourceReader("assets/sit-oth3r/lang/",Sit.class.getClassLoader()),
new ResourceReader(Data.CONFIG_DIR),"en_us","en_us");
public static LanguageReader getLangReader() {
return langReader;
}
/** /**
* loads all config files to memory * loads all config files to memory
*/ */
public static void loadFiles() { public static void loadFiles() {
getServerConfig().load(); getServerConfig().load();
// load the language reader
langReader.updateLanguage(getServerConfig().getLang());
getSittingConfig().load(); getSittingConfig().load();
// if loading file and is on supported server on client, send the new settings over // if loading file and is on supported server on client, send the new settings over

View file

@ -1,124 +0,0 @@
package one.oth3r.sit.file;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import one.oth3r.otterlib.chat.CTxT;
import one.oth3r.sit.Sit;
import one.oth3r.sit.utl.Data;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LangReader {
private static final Map<String, String> defaultLangMap = new HashMap<>();
private static final Map<String, String> languageMap = new HashMap<>();
private final String translationKey;
private final Object[] placeholders;
public LangReader(String translationKey, Object... placeholders) {
this.translationKey = translationKey;
this.placeholders = placeholders;
}
public CTxT getTxT() {
String translated = getLanguageValue(translationKey);
if (placeholders != null && placeholders.length > 0) {
//removed all double \\ and replaces with \
translated = translated.replaceAll("\\\\\\\\", "\\\\");
String regex = "%\\d*\\$?[dfs]";
Matcher anyMatch = Pattern.compile(regex).matcher(translated);
Matcher endMatch = Pattern.compile(regex+"$").matcher(translated);
// Arraylist with all the %(#$)[dfs]
ArrayList<String> matches = new ArrayList<>();
while (anyMatch.find()) {
String match = anyMatch.group();
matches.add(match);
}
//SPLITS the text at each regex and remove the regex
String[] parts = translated.split(regex);
//if the last element of the array ends with regex, remove it and add an empty string to the end of the array
if (endMatch.find()) {
String[] newParts = Arrays.copyOf(parts, parts.length + 1);
newParts[parts.length] = "";
parts = newParts;
}
//if there are placeholders specified, and the split is more than 1, it will replace %(dfs) with the placeholder objects
if (parts.length > 1) {
CTxT txt = new CTxT("");
int i = 0;
for (String match : matches) {
int get = i;
//if the match is numbered, change GET to the number it wants
if (match.contains("$")) {
match = match.substring(1,match.indexOf('$'));
get = Integer.parseInt(match)-1;
}
if (parts.length != i) txt.append(parts[i]);
//convert the obj into txt
txt.append(getTxTFromObj(placeholders[get]));
i++;
}
if (parts.length != i) txt.append(parts[i]);
return new CTxT(txt);
}
}
return new CTxT(translated);
}
private CTxT getTxTFromObj(Object obj) {
if (obj instanceof CTxT) return (((CTxT) obj));
else if (obj instanceof Text) return new CTxT((MutableText) obj);
else return new CTxT(String.valueOf(obj));
}
public static LangReader of(String translationKey, Object... placeholders) {
return new LangReader(translationKey, placeholders);
}
public static void loadLanguageFile() {
Type tToken = new TypeToken<Map<String, String>>(){}.getType();
try {
// load the config language
Reader selectionReader = new InputStreamReader(getInputStream(false), StandardCharsets.UTF_8);
languageMap.putAll(new Gson().fromJson(selectionReader, tToken));
// load the default language as well (fallback)
Reader defaultReader = new InputStreamReader(getInputStream(true), StandardCharsets.UTF_8);
defaultLangMap.putAll(new Gson().fromJson(defaultReader, tToken));
} catch (Exception e) {
Data.LOGGER.info("ERROR WITH LANGUAGE FILE - PLEASE REPORT WITH THE ERROR LOG");
Data.LOGGER.info(e.getMessage());
}
}
private static InputStream getInputStream(boolean english) {
ClassLoader classLoader = Sit.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("assets/sit-oth3r/lang/"+FileData.getServerConfig().getLang()+".json");
// make null if english
if (english) inputStream = null;
// if it cant read (null), try again, but with the english file
if (inputStream == null) inputStream = classLoader.getResourceAsStream("assets/sit-oth3r/lang/"+new ServerConfig().getLang()+".json");
// if null after that, throw an exception
if (inputStream == null) throw new IllegalArgumentException("CANT LOAD THE LANGUAGE FILE. SIT! WILL BREAK.");
return inputStream;
}
public static String getLanguageValue(String key) {
return languageMap.getOrDefault(key, defaultLangMap.getOrDefault(key, key));
}
}

View file

@ -1,15 +1,14 @@
package one.oth3r.sit.file; package one.oth3r.sit.file;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import one.oth3r.otterlib.base.Num;
import one.oth3r.otterlib.file.CustomFile; import one.oth3r.otterlib.file.CustomFile;
import one.oth3r.otterlib.file.FileSettings; import one.oth3r.otterlib.file.FileSettings;
import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Utl;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
@ -264,13 +263,8 @@ public class ServerConfig implements CustomFile<ServerConfig> {
this.interactionBlocks = newFile.interactionBlocks.stream().map(CustomBlock::new).collect(Collectors.toCollection(ArrayList::new)); this.interactionBlocks = newFile.interactionBlocks.stream().map(CustomBlock::new).collect(Collectors.toCollection(ArrayList::new));
} }
/**
* updates the file based on the version number of the current instance
*
* @param json
*/
@Override @Override
public void update(JsonElement json) { public void updateInstance() {
/// update to 2.1, just a new list, nothing to change /// update to 2.1, just a new list, nothing to change
/// update to 2.2, new settings, no changes /// update to 2.2, new settings, no changes
if (version >= 2.0 && version <= 2.1) { if (version >= 2.0 && version <= 2.1) {
@ -341,7 +335,7 @@ public class ServerConfig implements CustomFile<ServerConfig> {
loadVersion(properties,Double.parseDouble(ver)); loadVersion(properties,Double.parseDouble(ver));
} catch (Exception e) { } catch (Exception e) {
Data.LOGGER.error("Error loading legacy config file: {}", e.getMessage()); Data.LOGGER.error("Error loading legacy config file: %s", e.getMessage());
} }
// delete the old file // delete the old file
@ -376,7 +370,7 @@ public class ServerConfig implements CustomFile<ServerConfig> {
// skip if not the right size // skip if not the right size
if (split.length < 3 || split.length > 4) continue; if (split.length < 3 || split.length > 4) continue;
// if the other entries aren't correct, skip // if the other entries aren't correct, skip
if (!Utl.Num.isNum(split[2])) continue; if (!Num.isNum(split[2])) continue;
// make the block states list if possible // make the block states list if possible
ArrayList<String> blockstates = new ArrayList<>(); ArrayList<String> blockstates = new ArrayList<>();
@ -503,7 +497,7 @@ public class ServerConfig implements CustomFile<ServerConfig> {
serverConfig.save(); serverConfig.save();
sittingConfig.save(); sittingConfig.save();
} catch (Exception e) { } catch (Exception e) {
Data.LOGGER.error("Error loading legacy config: {}", e.getMessage()); Data.LOGGER.error("Error loading legacy config: %s", e.getMessage());
} }
} }
} }

View file

@ -101,7 +101,7 @@ public class SittingConfig implements CustomFile<SittingConfig> {
} }
@Override @Override
public void update(JsonElement jsonElement) { public void updateInstance() {
} }

View file

@ -5,10 +5,9 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ReloadCommand; import net.minecraft.server.command.ReloadCommand;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Formatting; import one.oth3r.sit.utl.Chat;
import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Logic; import one.oth3r.sit.utl.Logic;
import one.oth3r.sit.utl.Utl;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@ -29,7 +28,7 @@ public class ReloadCommandMixin {
// send a reloaded message to all players with permissions // send a reloaded message to all players with permissions
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) { for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
if (player.isCreativeLevelTwoOp()) { if (player.isCreativeLevelTwoOp()) {
player.sendMessage(Utl.messageTag().append(Utl.lang("sit!.chat.reloaded").color(Color.GREEN)).b()); player.sendMessage(Chat.tag().append(Chat.lang("sit!.chat.reloaded").color(Color.GREEN)).b());
} }
} }
} }

View file

@ -0,0 +1,16 @@
package one.oth3r.sit.utl;
import one.oth3r.otterlib.chat.CTxT;
import one.oth3r.sit.file.FileData;
import java.awt.*;
public class Chat {
public static CTxT tag() {
return new CTxT("Sit!").btn(true).color(Color.decode("#c400ff")).append(" ");
}
public static CTxT lang(String key, Object... args) {
return FileData.getLangReader().dynamicTranslatable(key, args);
}
}

View file

@ -4,14 +4,13 @@ import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.decoration.DisplayEntity; import net.minecraft.entity.decoration.DisplayEntity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import org.slf4j.Logger; import one.oth3r.otterlib.base.OtterLogger;
import org.slf4j.LoggerFactory;
import java.util.HashMap; import java.util.HashMap;
public class Data { public class Data {
public static final String MOD_ID = "sit-oth3r"; public static final String MOD_ID = "sit-oth3r";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final OtterLogger LOGGER = new OtterLogger(MOD_ID);
public static final String CONFIG_DIR = FabricLoader.getInstance().getConfigDir().toFile()+"/sit!/"; public static final String CONFIG_DIR = FabricLoader.getInstance().getConfigDir().toFile()+"/sit!/";

View file

@ -23,7 +23,6 @@ import net.minecraft.util.Formatting;
import one.oth3r.sit.SitClient; import one.oth3r.sit.SitClient;
import one.oth3r.sit.command.SitCommand; import one.oth3r.sit.command.SitCommand;
import one.oth3r.sit.file.FileData; import one.oth3r.sit.file.FileData;
import one.oth3r.sit.file.LangReader;
import one.oth3r.sit.file.SittingConfig; import one.oth3r.sit.file.SittingConfig;
import one.oth3r.sit.packet.PacketSender; import one.oth3r.sit.packet.PacketSender;
import one.oth3r.sit.packet.PacketType; import one.oth3r.sit.packet.PacketType;
@ -79,7 +78,7 @@ public class Events {
player.networkHandler.sendCommand("sit"); player.networkHandler.sendCommand("sit");
} else { } else {
// unsupported server message if not in a Sit! server // unsupported server message if not in a Sit! server
player.sendMessage(Utl.lang("sit!.chat.unsupported") player.sendMessage(Chat.lang("sit!.chat.unsupported")
.color(Color.RED).b(), true); .color(Color.RED).b(), true);
} }
} }
@ -103,7 +102,7 @@ public class Events {
new PacketSender(PacketType.RESPONSE,PacketType.RESPONSE.getId()).sendToPlayer(player); new PacketSender(PacketType.RESPONSE,PacketType.RESPONSE.getId()).sendToPlayer(player);
// log the receiving of the packet from the player // log the receiving of the packet from the player
Data.LOGGER.info(Utl.lang("sit!.console.player_settings",player.getName().getString()).toString()); Data.LOGGER.info(Chat.lang("sit!.console.player_settings",player.getName().getString()).toString());
}); });
})); }));
} }
@ -116,7 +115,7 @@ public class Events {
client.execute(() -> { client.execute(() -> {
if (!Data.isSupportedServer()) { if (!Data.isSupportedServer()) {
Data.setSupportedServer(true); Data.setSupportedServer(true);
Data.LOGGER.info(Utl.lang("sit!.console.connected",packetData).toString()); Data.LOGGER.info(Chat.lang("sit!.console.connected",packetData).toString());
} }
}); });
})); }));
@ -175,7 +174,6 @@ public class Events {
private static void serverLifecycle() { private static void serverLifecycle() {
ServerLifecycleEvents.SERVER_STARTED.register(s -> { ServerLifecycleEvents.SERVER_STARTED.register(s -> {
Data.setServer(s); Data.setServer(s);
LangReader.loadLanguageFile();
// right click on block event // right click on block event
UseBlockCallback.EVENT.register((pl, world, hand, hitResult) -> { UseBlockCallback.EVENT.register((pl, world, hand, hitResult) -> {
@ -195,7 +193,7 @@ public class Events {
ParseResults<ServerCommandSource> parse = dispatcher.parse("sit", player.getCommandSource()); ParseResults<ServerCommandSource> parse = dispatcher.parse("sit", player.getCommandSource());
dispatcher.execute(parse); dispatcher.execute(parse);
} catch (CommandSyntaxException e) { } catch (CommandSyntaxException e) {
Data.LOGGER.error("Error executing sit command for player {}", player.getName().getString()); Data.LOGGER.error("Error executing sit command for player %s", player.getName().getString());
} }
} }

View file

@ -201,7 +201,6 @@ public class Logic {
public static void reload() { public static void reload() {
FileData.loadFiles(); FileData.loadFiles();
FileData.saveFiles(); FileData.saveFiles();
LangReader.loadLanguageFile();
} }
/** /**
@ -228,11 +227,11 @@ public class Logic {
Formatting messageColor = config.getEnabled()?Formatting.GREEN:Formatting.RED; Formatting messageColor = config.getEnabled()?Formatting.GREEN:Formatting.RED;
// send the player the actionbar message // send the player the actionbar message
return Utl.lang("sit!.chat.toggle_sit", return Chat.lang("sit!.chat.toggle_sit",
Utl.lang(messageKey).color(config.getEnabled()? Color.GREEN : Color.RED)).b(); Chat.lang(messageKey).color(config.getEnabled()? Color.GREEN : Color.RED)).b();
} else { } else {
// unsupported server message if not in a Sit! server // unsupported server message if not in a Sit! server
return Utl.lang("sit!.chat.unsupported") return Chat.lang("sit!.chat.unsupported")
.color(Color.RED).b(); .color(Color.RED).b();
} }
} }

View file

@ -60,46 +60,6 @@ public class Utl {
return Data.getSitEntities().values().stream().noneMatch(entity -> entity.getBlockPos().equals(pos)); return Data.getSitEntities().values().stream().noneMatch(entity -> entity.getBlockPos().equals(pos));
} }
public static class Num {
public static boolean isInt(String string) {
try {
Integer.parseInt(string);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
public static Integer toInt(String s) {
// return an int no matter what
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
try {
return (int) Double.parseDouble(s);
} catch (NumberFormatException e2) {
return 0;
}
}
}
public static boolean isNum(String s) {
// checks if int or a double
try {
Integer.parseInt(s);
return true;
} catch (NumberFormatException e1) {
try {
Double.parseDouble(s);
return true;
} catch (NumberFormatException e2) {
return false;
}
}
}
}
public static final double HALF_BLOCK = 0.5; public static final double HALF_BLOCK = 0.5;
public static final double CARPET = 0.062; public static final double CARPET = 0.062;
@ -321,58 +281,14 @@ public class Utl {
// send a message if needed // send a message if needed
if (message) { if (message) {
player.sendMessage(messageTag() player.sendMessage(Chat.tag()
.append(lang("sit!.chat.purged",lang("sit!.chat.purged.total",count).color(Color.gray).b()).color(Color.GREEN)).b()); .append(Chat.lang("sit!.chat.purged",
Chat.lang("sit!.chat.purged.total",count).color(Color.gray).b()
).color(Color.GREEN)).b());
} }
} }
} }
public static CTxT messageTag() {
return new CTxT("Sit!").btn(true).color(Color.decode("#c400ff")).append(" ");
}
/**
* gets a MutableText using the language key, if on server, using the custom lang reader
*/
public static CTxT lang(String key, Object... args) {
if (Data.isClient()) {
// we have to first convert all the CTxT's to the built version because minecraft lang reader doesn't know how to process it
// make a array with the same size of the args
Object[] fixedArgs = new Object[args.length];
// for every arg, build & add if CTxT or just add if not
for (var i = 0; i < args.length; i++) {
if (args[i] instanceof CTxT) fixedArgs[i] = ((CTxT) args[i]).b();
else fixedArgs[i] = args[i];
}
// return the translated text
return new CTxT(Text.translatable(key,fixedArgs));
}
else return LangReader.of(key, args).getTxT();
}
public static class Enum {
public static <T extends java.lang.Enum<T>> T get(Object enumString, Class<T> enumType) {
return get(enumString,enumType,enumType.getEnumConstants()[0]);
}
/**
* gets an enum from a string without returning null
* @param enumString the string of the enum
* @param enumType the class of enums
* @param defaultEnum the enum to return if a match isn't found
* @return an enum, if there isn't a match, it returns the first enum
*/
public static <T extends java.lang.Enum<T>> T get(Object enumString, Class<T> enumType, T defaultEnum) {
T[] values = enumType.getEnumConstants();
for (T all : values) {
// check if there is a match for any of the enum names
if (enumString.toString().equals(all.name())) return all;
}
// if there's no match return the first entry
return defaultEnum;
}
}
/** /**
* sends the settings packets to the server, if client & in game * sends the settings packets to the server, if client & in game
*/ */