From 23e01c8b263e2bf92c12f25d5ef38a0fdd2edd08 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Tue, 1 Dec 2015 12:19:13 +0700 Subject: [PATCH 1/3] Create builder for PlayerAuth. --- .../xephi/authme/cache/auth/PlayerAuth.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java index 5b1273259..01622c177 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -497,4 +497,97 @@ public class PlayerAuth { this.y = Double.parseDouble(args[10]); this.z = Double.parseDouble(args[11]); } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private String name; + private String realName; + private String hash; + private String salt; + private String ip; + private String world; + private double x; + private double y; + private double z; + private long lastLogin; + private int groupId; + private String email; + + public PlayerAuth build() { + return new PlayerAuth( + name, + hash, + salt, + groupId, + ip, + lastLogin, + x, y, z, world, + email, + realName + ); + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder realName(String realName) { + this.realName = realName; + return this; + } + + public Builder hash(String hash) { + this.hash = hash; + return this; + } + + public Builder salt(String salt) { + this.salt = salt; + return this; + } + + public Builder ip(String ip) { + this.ip = ip; + return this; + } + + public Builder locWorld(String world) { + this.world = world; + return this; + } + + public Builder locX(double x) { + this.x = x; + return this; + } + + public Builder locY(double y) { + this.y = y; + return this; + } + + public Builder locZ(double z) { + this.z = z; + return this; + } + + public Builder lastLogin(long lastLogin) { + this.lastLogin = lastLogin; + return this; + } + + public Builder groupId(int groupId) { + this.groupId = groupId; + return this; + } + + public Builder email(String email) { + this.email = email; + return this; + } + } } From 92f57090bee728849d40874559057ce600b2a717 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Tue, 1 Dec 2015 16:07:58 +0700 Subject: [PATCH 2/3] Set default value for the Builder --- .../xephi/authme/cache/auth/PlayerAuth.java | 93 +++++++++---------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java index 01622c177..618c50189 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -23,9 +23,8 @@ public class PlayerAuth { /** * */ - public PlayerAuth(String serialized) - { - this.unserialize(serialized); + public PlayerAuth(String serialized) { + this.deserialize(serialized); } /** @@ -455,47 +454,45 @@ public class PlayerAuth { } /** - * Method to serialize playerauth + * Method to serialize PlayerAuth * * @return String */ - public String serialize() - { - StringBuilder str = new StringBuilder(); - str.append(this.nickname).append(';'); - str.append(this.realName).append(';'); - str.append(this.ip).append(';'); - str.append(this.email).append(';'); - str.append(this.hash).append(';'); - str.append(this.salt).append(';'); - str.append(this.groupId).append(';'); - str.append(this.lastLogin).append(';'); - str.append(this.world).append(';'); - str.append(this.x).append(';'); - str.append(this.y).append(';'); - str.append(this.z); - return str.toString(); + public String serialize() { + StringBuilder str = new StringBuilder(); + char d = ';'; + str.append(this.nickname).append(d); + str.append(this.realName).append(d); + str.append(this.ip).append(d); + str.append(this.email).append(d); + str.append(this.hash).append(d); + str.append(this.salt).append(d); + str.append(this.groupId).append(d); + str.append(this.lastLogin).append(d); + str.append(this.world).append(d); + str.append(this.x).append(d); + str.append(this.y).append(d); + str.append(this.z); + return str.toString(); } /** - * Method to unserialize playerauth - * + * Method to deserialize PlayerAuth */ - public void unserialize(String str) - { - String[] args = str.split(";"); - this.nickname = args[0]; - this.realName = args[1]; - this.ip = args[2]; - this.email = args[3]; - this.hash = args[4]; - this.salt = args[5]; - this.groupId = Integer.parseInt(args[6]); - this.lastLogin = Long.parseLong(args[7]); - this.world = args[8]; - this.x = Double.parseDouble(args[9]); - this.y = Double.parseDouble(args[10]); - this.z = Double.parseDouble(args[11]); + public void deserialize(String str) { + String[] args = str.split(";"); + this.nickname = args[0]; + this.realName = args[1]; + this.ip = args[2]; + this.email = args[3]; + this.hash = args[4]; + this.salt = args[5]; + this.groupId = Integer.parseInt(args[6]); + this.lastLogin = Long.parseLong(args[7]); + this.world = args[8]; + this.x = Double.parseDouble(args[9]); + this.y = Double.parseDouble(args[10]); + this.z = Double.parseDouble(args[11]); } public static Builder builder() { @@ -504,17 +501,17 @@ public class PlayerAuth { public static final class Builder { private String name; - private String realName; - private String hash; - private String salt; - private String ip; - private String world; - private double x; - private double y; - private double z; - private long lastLogin; - private int groupId; - private String email; + private String realName = "Player"; + private String hash = ""; + private String salt = ""; + private String ip = "127.0.0.1"; + private String world = "world"; + private double x = 0.0f; + private double y = 0.0f; + private double z = 0.0f; + private long lastLogin = System.currentTimeMillis(); + private int groupId = -1; + private String email = "your@email.com"; public PlayerAuth build() { return new PlayerAuth( From e02af46d65506e4506bd2bd1643cf629592d2930 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Wed, 2 Dec 2015 04:10:56 +0700 Subject: [PATCH 3/3] Lowercase the name input. --- src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java index 618c50189..5339ac3a3 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -528,7 +528,7 @@ public class PlayerAuth { } public Builder name(String name) { - this.name = name; + this.name = name.toLowerCase(); return this; }