diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java index c992bc9..ea1775a 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java @@ -25,15 +25,8 @@ public class ValidateCommand extends Command { final String hash = fullArgs[0]; - if ( - hash.equals(bot.hashing.getHash(context.splitInput[0], context.sender, true)) || - hash.equals(bot.hashing.getHash(context.splitInput[0], context.sender, false)) - ) return Component.text("Valid hash").color(NamedTextColor.GREEN); - - else if ( - hash.equals(bot.hashing.getOwnerHash(context.splitInput[0], context.sender, true)) || - hash.equals(bot.hashing.getOwnerHash(context.splitInput[0], context.sender, false)) - ) return Component.text("Valid OwnerHash").color(NamedTextColor.GREEN); + if (bot.hashing.isCorrectHash(hash, context.splitInput[0], context.sender)) return Component.text("Valid hash").color(NamedTextColor.GREEN); + else if (bot.hashing.isCorrectOwnerHash(hash, context.splitInput[0], context.sender)) return Component.text("Valid OwnerHash").color(NamedTextColor.GREEN); return null; } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java index 46d1feb..f6e380a 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java @@ -143,11 +143,8 @@ public class CommandHandlerPlugin { } else { if ( command.trustLevel == TrustLevel.TRUSTED && - // mess? - !userHash.equals(bot.hashing.getHash(splitInput[0], context.sender, true)) && - !userHash.equals(bot.hashing.getOwnerHash(splitInput[0], context.sender, true)) && - !userHash.equals(bot.hashing.getHash(splitInput[0], context.sender, false)) && - !userHash.equals(bot.hashing.getOwnerHash(splitInput[0], context.sender, false)) + !bot.hashing.isCorrectHash(userHash, splitInput[0], context.sender) && + !bot.hashing.isCorrectOwnerHash(userHash, splitInput[0], context.sender) ) return Component.text("Invalid hash").color(NamedTextColor.RED); if ( diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/HashingPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/HashingPlugin.java index 498e8ff..b5a8cf9 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/HashingPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/HashingPlugin.java @@ -55,4 +55,20 @@ public class HashingPlugin { ) : hash; } + + public boolean isCorrectHash (String hash, String prefix, PlayerEntry sender) { + // removes reset section sign + if (hash.length() == (16 * 2 /* <-- don't forget, we have the section signs */) + 2 && hash.endsWith("§r")) hash = hash.substring(0, hash.length() - 2); + + return hash.equals(getHash(prefix, sender, true)) || + hash.equals(getHash(prefix, sender, false)); + } + + public boolean isCorrectOwnerHash (String hash, String prefix, PlayerEntry sender) { + // removes reset section sign + if (hash.length() == (16 * 2 /* <-- don't forget, we have the section signs */) + 2 && hash.endsWith("§r")) hash = hash.substring(0, hash.length() - 2); + + return hash.equals(getOwnerHash(prefix, sender, true)) || + hash.equals(getOwnerHash(prefix, sender, false)); + } }