diff --git a/README.md b/README.md index 3ee3334..6e9270c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![License](https://img.shields.io/badge/License-MIT-brightgreen) [![Curseforge downloads](http://cf.way2muchnoise.eu/full_simpleauth_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/simpleauth) -![Java CI with Gradle](https://github.com/samolego/SimpleAuth/workflows/Java%20CI%20with%20Gradle/badge.svg) +![Gradle Build](https://github.com/samolego/SimpleAuth/workflows/Gradle%20Build/badge.svg) Requires Fabric API. diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java index e9db4f4..5ca1289 100644 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java @@ -21,7 +21,10 @@ import org.samo_lego.simpleauth.storage.PlayerCache; import org.samo_lego.simpleauth.storage.SimpleAuthDatabase; import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.HashMap; +import java.util.Properties; import java.util.Timer; import java.util.TimerTask; @@ -46,6 +49,10 @@ public class SimpleAuth implements DedicatedServerModInitializer { // Getting game directory public static final File gameDirectory = FabricLoader.getInstance().getGameDirectory(); + + // Server properties + public static Properties serverProp = new Properties(); + // Mod config public static AuthConfig config; @@ -65,6 +72,12 @@ public class SimpleAuth implements DedicatedServerModInitializer { // Connecting to db db.openConnection(); + try { + serverProp.load(new FileReader(gameDirectory + "/server.properties")); + } catch (IOException e) { + LOGGER.error("[SimpleAuth] Error while reading server properties: " + e.getMessage()); + } + // Registering the commands CommandRegistry.INSTANCE.register(false, dispatcher -> { diff --git a/src/main/java/org/samo_lego/simpleauth/utils/UuidConverter.java b/src/main/java/org/samo_lego/simpleauth/utils/UuidConverter.java index fbdb004..967afbf 100644 --- a/src/main/java/org/samo_lego/simpleauth/utils/UuidConverter.java +++ b/src/main/java/org/samo_lego/simpleauth/utils/UuidConverter.java @@ -2,6 +2,8 @@ package org.samo_lego.simpleauth.utils; import net.minecraft.entity.player.PlayerEntity; +import static org.samo_lego.simpleauth.SimpleAuth.serverProp; + /** * Converts player uuid, to ensure player with "nAmE" and "NamE" get same uuid * Both players are not allowed to play, since mod mimics Mojang behaviour @@ -9,21 +11,22 @@ import net.minecraft.entity.player.PlayerEntity; */ public class UuidConverter { - /** Converts player UUID to offline mode style. - * - * @param playername name of the player to get UUID for - * @return converted UUID as string - */ - public static String convertUuid(String playername) { - return PlayerEntity.getOfflinePlayerUuid(playername).toString(); - } + private static final boolean isOnline = (boolean) serverProp.getOrDefault("online-mode", false); - /** Converts player UUID to offline mode style. + /** Gets player UUID. * * @param player player to get UUID for * @return converted UUID as string */ public static String convertUuid(PlayerEntity player) { - return convertUuid(player.getName().asString().toLowerCase()); + // If server is in online mode online-mode UUIDs should be used + if(isOnline) + return player.getUuidAsString(); + + /* Lower case is used for Player and PlAyEr to get same UUID + Mimicking Mojang behaviour, where players cannot set their name to + ExAmple if example is already taken.*/ + String playername = player.getName().asString().toLowerCase(); + return PlayerEntity.getOfflinePlayerUuid(playername).toString(); } }