From a5a30ba3e6b049b1e5c3ad2e5a32b31153c93d10 Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Mon, 17 Feb 2020 19:41:07 +0100 Subject: [PATCH] Disabled changing password / unregistering if global password is enabled. Updated unregitser lang config. --- .../simpleauth/commands/ChangepwCommand.java | 8 ++++++-- .../simpleauth/commands/UnregisterCommand.java | 16 +++++++++++----- .../samo_lego/simpleauth/utils/AuthConfig.java | 3 +++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java index db645d2..fcf12d0 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java @@ -6,7 +6,6 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; -import net.minecraft.text.Text; import org.samo_lego.simpleauth.SimpleAuth; import org.samo_lego.simpleauth.utils.AuthHelper; @@ -20,6 +19,7 @@ public class ChangepwCommand { private static Text enterPassword = new LiteralText(SimpleAuth.config.lang.enterPassword); private static Text wrongPassword = new LiteralText(SimpleAuth.config.lang.wrongPassword); private static Text passwordUpdated = new LiteralText(SimpleAuth.config.lang.passwordUpdated); + private static Text cannotChangePassword = new LiteralText(SimpleAuth.config.lang.cannotChangePassword); public static void registerCommand(CommandDispatcher dispatcher) { // Registering the "/changepw" command @@ -50,7 +50,11 @@ public class ChangepwCommand { // Getting the player who send the command ServerPlayerEntity player = source.getPlayer(); - if (AuthHelper.checkPass(player.getUuidAsString(), oldPass.toCharArray())) { + if (SimpleAuth.config.main.enableGlobalPassword) { + player.sendMessage(cannotChangePassword); + return 0; + } + else if (AuthHelper.checkPass(player.getUuidAsString(), oldPass.toCharArray())) { SimpleAuth.db.update( player.getUuidAsString(), null, diff --git a/src/main/java/org/samo_lego/simpleauth/commands/UnregisterCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/UnregisterCommand.java index d2b8987..696d499 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/UnregisterCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/UnregisterCommand.java @@ -4,7 +4,8 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.TranslatableText; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; import org.samo_lego.simpleauth.SimpleAuth; import org.samo_lego.simpleauth.utils.AuthHelper; @@ -14,9 +15,10 @@ import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class UnregisterCommand { - private static TranslatableText enterPassword = new TranslatableText("§6You need to enter your password!"); - private static TranslatableText wrongPassword = new TranslatableText("§4Wrong password!"); - private static TranslatableText accountDeleted = new TranslatableText("§4Your account was successfully deleted!"); + private static Text enterPassword = new LiteralText(SimpleAuth.config.lang.enterPassword); + private static Text wrongPassword = new LiteralText(SimpleAuth.config.lang.wrongPassword); + private static Text accountDeleted = new LiteralText(SimpleAuth.config.lang.accountDeleted); + private static Text cannotUnregister = new LiteralText(SimpleAuth.config.lang.cannotUnregister); public static void registerCommand(CommandDispatcher dispatcher) { // Registering the "/unregister" command @@ -39,7 +41,11 @@ public class UnregisterCommand { private static int unregister(ServerCommandSource source, String pass) throws CommandSyntaxException { // Getting the player who send the command ServerPlayerEntity player = source.getPlayer(); - if (AuthHelper.checkPass(player.getUuidAsString(), pass.toCharArray())) { + if (SimpleAuth.config.main.enableGlobalPassword) { + player.sendMessage(cannotUnregister); + return 0; + } + else if (AuthHelper.checkPass(player.getUuidAsString(), pass.toCharArray())) { SimpleAuth.db.delete(player.getUuidAsString(), null); player.sendMessage(accountDeleted); return 1; diff --git a/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java b/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java index ee5cb69..264369e 100644 --- a/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java +++ b/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java @@ -68,6 +68,8 @@ public class AuthConfig { public String passwordUpdated = "§4Your password was updated successfully!"; public String loginRequired = "§cYou are not authenticated!\n§6Use /login to authenticate!"; public String globalPasswordSet = "§aGlobal password was successfully set!"; + public String cannotChangePassword = "§aYou cannot change password!"; + public String cannotUnregister = "§aYou cannot unregister this account!"; public String notAuthenticated = "§cYou are not authenticated!\n§6Try with /login or /register."; public String alreadyAuthenticated = "§4You are already authenticated."; public String successfullyAuthenticated = "§aYou are now authenticated."; @@ -76,6 +78,7 @@ public class AuthConfig { public String registerSuccess = "§aYou are now authenticated."; public String userdataDeleted = "§aUserdata deleted."; public String userdataUpdated = "§aUserdata updated."; + public String accountDeleted = "§4Your account was successfully deleted!"; public String configurationReloaded = "§aConfiguration file was reloaded successfully."; }