diff --git a/gradle.properties b/gradle.properties index 8bb6f61..4b62c74 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,6 @@ loader_version=0.8.2+build.194 fabric_version=0.5.10+build.320-1.16 # Mod Properties - mod_version = 1.3.3 + mod_version = 1.4.0 maven_group = org.samo_lego archives_base_name = simpleauth diff --git a/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java index 9e9db89..a137c4e 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java @@ -3,6 +3,7 @@ package org.samo_lego.simpleauth.commands; import com.google.gson.JsonObject; import com.mojang.brigadier.CommandDispatcher; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; @@ -82,7 +83,7 @@ public class AuthCommand { SimpleAuth.config = AuthConfig.load(new File("./mods/SimpleAuth/config.json")); if(sender != null) - sender.sendMessage(configurationReloaded); + ((PlayerEntity) sender).sendMessage(configurationReloaded, false); else LOGGER.info(SimpleAuth.config.lang.configurationReloaded); return 1; @@ -98,7 +99,7 @@ public class AuthCommand { SimpleAuth.config.save(new File("./mods/SimpleAuth/config.json")); if(sender != null) - sender.sendMessage(globalPasswordSet); + sender.sendSystemMessage(globalPasswordSet); else LOGGER.info(SimpleAuth.config.lang.globalPasswordSet); return 1; @@ -111,7 +112,7 @@ public class AuthCommand { SimpleAuth.deauthenticatedUsers.put(uuid, new PlayerCache(uuid, "")); if(sender != null) - sender.sendMessage(userdataDeleted); + ((PlayerEntity) sender).sendMessage(userdataDeleted, false); else LOGGER.info(SimpleAuth.config.lang.userdataDeleted); return 1; // Success @@ -129,7 +130,7 @@ public class AuthCommand { if(SimpleAuth.db.registerUser(uuid, playerdata.toString())) { if(sender != null) - sender.sendMessage(userdataUpdated); + ((PlayerEntity) sender).sendMessage(userdataUpdated, false); else LOGGER.info(SimpleAuth.config.lang.userdataUpdated); return 1; @@ -149,9 +150,10 @@ public class AuthCommand { SimpleAuth.db.updateUserData(uuid, playerdata.toString()); if(sender != null) - sender.sendMessage(userdataUpdated); + ((PlayerEntity) sender).sendMessage(userdataUpdated, false); else LOGGER.info(SimpleAuth.config.lang.userdataUpdated); return 1; } + // todo PlayerEntity.getOfflinePlayerUuid("") } 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 0f1d17d..1e8db0f 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java @@ -26,12 +26,12 @@ public class ChangepwCommand { // Registering the "/changepw" command dispatcher.register(literal("changepw") .executes(ctx -> { - ctx.getSource().getPlayer().sendMessage(enterPassword); + ctx.getSource().getPlayer().sendMessage(enterPassword, false); return 1; }) .then(argument("oldPassword", word()) .executes(ctx -> { - ctx.getSource().getPlayer().sendMessage(enterNewPassword); + ctx.getSource().getPlayer().sendMessage(enterNewPassword, false); return 1; }) .then(argument("newPassword", word()) @@ -52,20 +52,20 @@ public class ChangepwCommand { ServerPlayerEntity player = source.getPlayer(); if (SimpleAuth.config.main.enableGlobalPassword) { - player.sendMessage(cannotChangePassword); + player.sendMessage(cannotChangePassword, false); return 0; } else if (AuthHelper.checkPass(player.getUuidAsString(), oldPass.toCharArray()) == 1) { if(newPass.length() < SimpleAuth.config.main.minPasswordChars) { player.sendMessage(new LiteralText( String.format(SimpleAuth.config.lang.minPasswordChars, SimpleAuth.config.main.minPasswordChars) - )); + ), false); return 0; } else if(newPass.length() > SimpleAuth.config.main.maxPasswordChars && SimpleAuth.config.main.maxPasswordChars != -1) { player.sendMessage(new LiteralText( String.format(SimpleAuth.config.lang.maxPasswordChars, SimpleAuth.config.main.maxPasswordChars) - )); + ), false); return 0; } // JSON object holding password (may hold some other info in the future) @@ -74,10 +74,10 @@ public class ChangepwCommand { playerdata.addProperty("password", hash); SimpleAuth.db.updateUserData(player.getUuidAsString(), playerdata.toString()); - player.sendMessage(passwordUpdated); + player.sendMessage(passwordUpdated, false); return 1; } - player.sendMessage(wrongPassword); + player.sendMessage(wrongPassword, false); return 0; } } diff --git a/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java index 96a7ce7..3828810 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java @@ -30,7 +30,7 @@ public class LoginCommand { .executes(ctx -> login(ctx.getSource(), getString(ctx, "password")) // Tries to authenticate user )) .executes(ctx -> { - ctx.getSource().getPlayer().sendMessage(enterPassword); + ctx.getSource().getPlayer().sendMessage(enterPassword, false); return 0; })); } @@ -43,7 +43,7 @@ public class LoginCommand { int passwordResult = AuthHelper.checkPass(uuid, pass.toCharArray()); if(SimpleAuth.isAuthenticated(player)) { - player.sendMessage(alreadyAuthenticated); + player.sendMessage(alreadyAuthenticated, false); return 0; } else if(SimpleAuth.deauthenticatedUsers.get(uuid).loginTries >= maxLoginTries && maxLoginTries != -1) { @@ -55,7 +55,7 @@ public class LoginCommand { return 1; } else if(passwordResult == -1) { - player.sendMessage(notRegistered); + player.sendMessage(notRegistered, false); return 0; } // Kicking the player out @@ -64,7 +64,7 @@ public class LoginCommand { return 0; } // Sending wrong pass message - player.sendMessage(wrongPassword); + player.sendMessage(wrongPassword, false); // ++ the login tries SimpleAuth.deauthenticatedUsers.get(uuid).loginTries += 1; return 0; diff --git a/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java index 20a1972..0774414 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java @@ -23,7 +23,7 @@ public class LogoutCommand { private static int logout(ServerCommandSource serverCommandSource) throws CommandSyntaxException { ServerPlayerEntity player = serverCommandSource.getPlayer(); SimpleAuth.deauthenticatePlayer(player); - player.sendMessage(successfulLogout); + player.sendMessage(successfulLogout, false); return 1; } } diff --git a/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java index 1b55a45..058ec91 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java @@ -33,7 +33,7 @@ public class RegisterCommand { .executes( ctx -> register(ctx.getSource(), getString(ctx, "password"), getString(ctx, "passwordAgain"))) )) .executes(ctx -> { - ctx.getSource().getPlayer().sendMessage(enterPassword); + ctx.getSource().getPlayer().sendMessage(enterPassword, false); return 0; })); } @@ -42,24 +42,24 @@ public class RegisterCommand { private static int register(ServerCommandSource source, String pass1, String pass2) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); if(SimpleAuth.config.main.enableGlobalPassword) { - player.sendMessage(loginRequired); + player.sendMessage(loginRequired, false); return 0; } else if(SimpleAuth.isAuthenticated(player)) { - player.sendMessage(alreadyAuthenticated); + player.sendMessage(alreadyAuthenticated, false); return 0; } else if(pass1.equals(pass2)) { if(pass1.length() < SimpleAuth.config.main.minPasswordChars) { player.sendMessage(new LiteralText( String.format(SimpleAuth.config.lang.minPasswordChars, SimpleAuth.config.main.minPasswordChars) - )); + ), false); return 0; } else if(pass1.length() > SimpleAuth.config.main.maxPasswordChars && SimpleAuth.config.main.maxPasswordChars != -1) { player.sendMessage(new LiteralText( String.format(SimpleAuth.config.lang.maxPasswordChars, SimpleAuth.config.main.maxPasswordChars) - )); + ), false); return 0; } String hash = AuthHelper.hashPass(pass1.toCharArray()); @@ -71,10 +71,10 @@ public class RegisterCommand { SimpleAuth.authenticatePlayer(player, registerSuccess); return 1; } - player.sendMessage(alreadyRegistered); + player.sendMessage(alreadyRegistered, false); return 0; } - player.sendMessage(matchPass); + player.sendMessage(matchPass, false); return 0; } } 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 6fc65c8..b90ad5c 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/UnregisterCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/UnregisterCommand.java @@ -24,7 +24,7 @@ public class UnregisterCommand { // Registering the "/unregister" command dispatcher.register(literal("unregister") .executes(ctx -> { - ctx.getSource().getPlayer().sendMessage(enterPassword); + ctx.getSource().getPlayer().sendMessage(enterPassword, false); return 1; }) .then(argument("password", word()) @@ -42,16 +42,16 @@ public class UnregisterCommand { // Getting the player who send the command ServerPlayerEntity player = source.getPlayer(); if (SimpleAuth.config.main.enableGlobalPassword) { - player.sendMessage(cannotUnregister); + player.sendMessage(cannotUnregister, false); return 0; } else if (AuthHelper.checkPass(player.getUuidAsString(), pass.toCharArray()) == 1) { SimpleAuth.deauthenticatePlayer(player); SimpleAuth.db.deleteUserData(player.getUuidAsString()); - player.sendMessage(accountDeleted); + player.sendMessage(accountDeleted, false); return 1; } - player.sendMessage(wrongPassword); + player.sendMessage(wrongPassword, false); return 0; } } diff --git a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java index 89608d9..f8efcec 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -46,6 +46,7 @@ public class AuthEventHandler { player.networkHandler.disconnect(new LiteralText(String.format(config.lang.disallowedUsername, regex))); return; } + // Checking if session is still valid String uuid = player.getUuidAsString(); PlayerCache playerCache = deauthenticatedUsers.getOrDefault(uuid, null); @@ -126,7 +127,7 @@ public class AuthEventHandler { } if(wasSuccessful) { player.teleport(x, y, z); - player.sendMessage(successfulPortalRescue); + player.sendMessage(successfulPortalRescue, false); } } } @@ -154,9 +155,9 @@ public class AuthEventHandler { !isAuthenticated((ServerPlayerEntity) player) && !msg.startsWith("/login") && !msg.startsWith("/register") && - (!config.main.allowChat || msg.startsWith("/")) + (!config.experimental.allowChat || msg.startsWith("/")) ) { - player.sendMessage(notAuthenticated()); + player.sendMessage(notAuthenticated(), false); return ActionResult.FAIL; } return ActionResult.PASS; @@ -164,7 +165,7 @@ public class AuthEventHandler { // Player movement public static ActionResult onPlayerMove(PlayerEntity player) { - if(!isAuthenticated((ServerPlayerEntity) player) && !config.main.allowMovement) { + if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowMovement) { return ActionResult.FAIL; } return ActionResult.PASS; @@ -172,8 +173,8 @@ public class AuthEventHandler { // Using a block (right-click function) public static ActionResult onUseBlock(PlayerEntity player) { - if(!isAuthenticated((ServerPlayerEntity) player) && !config.main.allowBlockUse) { - player.sendMessage(notAuthenticated()); + if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowBlockUse) { + player.sendMessage(notAuthenticated(), false); return ActionResult.FAIL; } return ActionResult.PASS; @@ -181,8 +182,8 @@ public class AuthEventHandler { // Punching a block public static ActionResult onAttackBlock(PlayerEntity player) { - if(!isAuthenticated((ServerPlayerEntity) player) && !config.main.allowBlockPunch) { - player.sendMessage(notAuthenticated()); + if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowBlockPunch) { + player.sendMessage(notAuthenticated(), false); return ActionResult.FAIL; } return ActionResult.PASS; @@ -190,8 +191,8 @@ public class AuthEventHandler { // Using an item public static TypedActionResult onUseItem(PlayerEntity player) { - if(!isAuthenticated((ServerPlayerEntity) player) && !config.main.allowItemUse) { - player.sendMessage(notAuthenticated()); + if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowItemUse) { + player.sendMessage(notAuthenticated(), false); return TypedActionResult.fail(ItemStack.EMPTY); } @@ -199,16 +200,16 @@ public class AuthEventHandler { } // Dropping an item public static ActionResult onDropItem(PlayerEntity player) { - if(!isAuthenticated((ServerPlayerEntity) player) && !config.main.allowItemDrop) { - player.sendMessage(notAuthenticated()); + if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowItemDrop) { + player.sendMessage(notAuthenticated(), false); return ActionResult.FAIL; } return ActionResult.PASS; } // Changing inventory (item moving etc.) public static ActionResult onTakeItem(PlayerEntity player) { - if(!isAuthenticated((ServerPlayerEntity) player) && !config.main.allowItemMoving) { - player.sendMessage(notAuthenticated()); + if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowItemMoving) { + player.sendMessage(notAuthenticated(), false); return ActionResult.FAIL; } @@ -216,8 +217,8 @@ public class AuthEventHandler { } // Attacking an entity public static ActionResult onAttackEntity(PlayerEntity player) { - if(!isAuthenticated((ServerPlayerEntity) player) && !config.main.allowEntityPunch) { - player.sendMessage(notAuthenticated()); + if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowEntityPunch) { + player.sendMessage(notAuthenticated(), false); return ActionResult.FAIL; } @@ -226,7 +227,7 @@ public class AuthEventHandler { // Interacting with entity public static ActionResult onUseEntity(PlayerEntity player) { if(!isAuthenticated((ServerPlayerEntity) player) && !config.main.allowEntityInteract) { - player.sendMessage(notAuthenticated()); + player.sendMessage(notAuthenticated(), false); return ActionResult.FAIL; } diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java index 5c6f72a..9426cec 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java @@ -1,6 +1,8 @@ package org.samo_lego.simpleauth.mixin; -import net.minecraft.network.packet.c2s.play.*; +import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; +import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; @@ -31,7 +33,7 @@ public abstract class MixinServerPlayNetworkHandler { cancellable = true ) private void onChatMessage(ChatMessageC2SPacket chatMessageC2SPacket, CallbackInfo ci) { - ActionResult result = ChatCallback.EVENT.invoker().onPlayerChat(player, chatMessageC2SPacket); + ActionResult result = ChatCallback.EVENT.invoker().onPlayerChat(this.player, chatMessageC2SPacket); if (result == ActionResult.FAIL) { ci.cancel(); } @@ -48,7 +50,7 @@ public abstract class MixinServerPlayNetworkHandler { ) private void onPlayerAction(PlayerActionC2SPacket packet, CallbackInfo ci) { if(packet.getAction() == SWAP_HELD_ITEMS) { - ActionResult result = TakeItemCallback.EVENT.invoker().onTakeItem(player); + ActionResult result = TakeItemCallback.EVENT.invoker().onTakeItem(this.player); if (result == ActionResult.FAIL) { ci.cancel(); } @@ -65,10 +67,10 @@ public abstract class MixinServerPlayNetworkHandler { cancellable = true ) private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket, CallbackInfo ci) { - ActionResult result = PlayerMoveCallback.EVENT.invoker().onPlayerMove(player); + ActionResult result = PlayerMoveCallback.EVENT.invoker().onPlayerMove(this.player); if (result == ActionResult.FAIL) { // A bit ugly, I know. (we need to update player position) - player.requestTeleport(player.getX(), player.getY(), player.getZ()); + this.player.requestTeleport(this.player.getX(), this.player.getY(), this.player.getZ()); ci.cancel(); } }