Skip to content

Commit

Permalink
make bind code easier to type
Browse files Browse the repository at this point in the history
  • Loading branch information
MCUmbrella committed Sep 22, 2023
1 parent ae90dd6 commit 7bf9e49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
public class BukkitCommandExecutor implements CommandExecutor
{
static final Random r = new Random(); // used to generate random bind code
static final int BIND_CODE_LENGTH = 8;
static final char[] BIND_CODE_CHARS = "1234567890qwertyuiopasdfghjklzxcvbnm".toCharArray();

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
Expand Down Expand Up @@ -62,10 +64,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if(args.length == 1 && args[0].equals("mkbind"))
{
if(!sender.hasPermission("mgbridge.mkbind")) return false;
String code = "";// 10-digit random bind code from ASCII x21(!) to x7E(~)
for(int i = 0; i != 10; i++) code += String.valueOf((char) (r.nextInt(94) + 33));// StringBuilder not needed
if(pendingPlayerMap.containsKey(((Player) sender).getUniqueId())) // remove old bind code if exists
// generate a random bind code
StringBuilder sb = new StringBuilder(BIND_CODE_LENGTH);
for(int i = 0; i != BIND_CODE_LENGTH; i++)
sb.append(BIND_CODE_CHARS[r.nextInt(BIND_CODE_CHARS.length)]);
String code = sb.toString();
// remove old bind code if exists
if(pendingPlayerMap.containsKey(((Player) sender).getUniqueId()))
pendingMap.remove(pendingPlayerMap.get(((Player) sender).getUniqueId()));
// add the player and code to the pending map
pendingMap.put(code, ((Player) sender).getUniqueId());
pendingPlayerMap.put(((Player) sender).getUniqueId(), code);
sender.sendMessage(translate("m-code-requested").replace("%CODE%", code));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean execute(ChatMessage msg, String[] args)
}
else// player not bound?
{
if(pendingMap.containsKey(args[0]))// code matched?
if(pendingMap.containsKey(args[0].toLowerCase()))// code matched?
{// bind!
bindMap.put(msg.getCreatorId(), pendingMap.get(args[0]));
pendingPlayerMap.remove(pendingMap.get(args[0]));
Expand Down

0 comments on commit 7bf9e49

Please sign in to comment.