From 06bd3518f6b0204524e6ef5dab2abd11d9f1de4c Mon Sep 17 00:00:00 2001 From: Fuzzlemann Date: Sun, 23 Jul 2017 17:18:08 +0200 Subject: [PATCH] Simplifies if statements with && or || Removes one not existing argument in a JavaDoc Removes some unnecessary variable assignments Remove the check if an error happened while hashing the password in RegisterCommand.playerRegister because it's not possible that the hash is null Fixes that the command use table isn't limited -> now again limited (Bug caused by my conversion to foreach) More performance by using .computeIfPresent at GeolocationPart.addGeoloc(String) --- .../plan/command/commands/InfoCommand.java | 4 +-- .../command/commands/RegisterCommand.java | 9 ++----- .../commands/webuser/WebLevelCommand.java | 4 +-- .../com/djrapitops/plan/data/KillData.java | 5 +--- .../java/com/djrapitops/plan/data/TPS.java | 5 +--- .../com/djrapitops/plan/data/UserData.java | 26 ++++++------------- .../plan/data/additional/PluginData.java | 11 +++----- .../plan/data/analysis/GeolocationPart.java | 5 +--- .../plan/data/cache/DataCacheHandler.java | 22 ++++++++-------- .../plan/database/databases/SQLDB.java | 21 ++++++++------- .../html/tables/CommandUseTableCreator.java | 8 +++--- .../plan/utilities/PassEncryptUtil.java | 14 +++++----- 12 files changed, 55 insertions(+), 79 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java index f55a14564..f98bc7701 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java @@ -33,14 +33,14 @@ public class InfoCommand extends SubCommand { @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { ChatColor tColor = Phrase.COLOR_SEC.color(); - String[] messages = { + String[] msgs = { Phrase.CMD_INFO_HEADER + "", Phrase.CMD_INFO_VERSION.parse(plugin.getDescription().getVersion()), Phrase.CMD_BALL.toString() + tColor + " " + Version.checkVersion(plugin), Phrase.CMD_MANAGE_STATUS_ACTIVE_DB.parse(plugin.getDB().getConfigName()), Phrase.CMD_FOOTER + "" }; - sender.sendMessage(messages); + sender.sendMessage(msgs); return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java index 235c39af0..1d007417f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java @@ -43,7 +43,7 @@ public class RegisterCommand extends SubCommand { String permLvlErrorMsg = ChatColor.RED + "Incorrect perm level, not a number: "; try { if (CommandUtils.isPlayer(sender)) { - Log.info(sender.getName()+" issued WebUser register command."); + Log.info(sender.getName() + " issued WebUser register command."); playerRegister(args, sender); } else { consoleRegister(args, sender, notEnoughArgsMsg); @@ -74,11 +74,6 @@ public class RegisterCommand extends SubCommand { if (registerSenderAsUser) { String user = sender.getName(); String pass = PassEncryptUtil.createHash(args[0]); - - if (!Check.isTrue(pass != null, ChatColor.RED + "Password hash error.", sender)) { - return; - } - int permLvl = getPermissionLevel(sender); registerUser(new WebUser(user, pass, permLvl), sender); } else if (sender.hasPermission(Permissions.MANAGE_WEB.getPermission())) { @@ -119,7 +114,7 @@ public class RegisterCommand extends SubCommand { } securityTable.addNewUser(webUser); sender.sendMessage(successMsg); - Log.info("Registered new user: "+userName+" Perm level: "+webUser.getPermLevel()); + Log.info("Registered new user: " + userName + " Perm level: " + webUser.getPermLevel()); } catch (Exception e) { Log.toLog(this.getClass().getName(), e); } finally { diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java index bb68c8657..810070e63 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java @@ -28,7 +28,7 @@ public class WebLevelCommand extends SubCommand { ColorScheme cs = plugin.getColorScheme(); String sCol = cs.getSecondaryColor(); String cmdBall = Phrase.CMD_BALL.parse(); - String[] msgs = new String[]{ + String[] messages = new String[]{ Phrase.CMD_FOOTER.parse(), cmdBall + sCol + "0: Access all pages", cmdBall + sCol + "1: Access '/players' and all inspect pages", @@ -36,7 +36,7 @@ public class WebLevelCommand extends SubCommand { cmdBall + sCol + "3+: No permissions", Phrase.CMD_FOOTER.parse() }; - sender.sendMessage(msgs); + sender.sendMessage(messages); return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/KillData.java b/Plan/src/main/java/com/djrapitops/plan/data/KillData.java index e11248c57..b5ece8001 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/KillData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/KillData.java @@ -84,10 +84,7 @@ public class KillData { return false; } final KillData other = (KillData) obj; - if (this.date != other.date) { - return false; - } - return Objects.equals(this.weapon, other.weapon) && Objects.equals(this.victim, other.victim); + return this.date == other.date && Objects.equals(this.weapon, other.weapon) && Objects.equals(this.victim, other.victim); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/data/TPS.java b/Plan/src/main/java/com/djrapitops/plan/data/TPS.java index cc0013b8c..56a91425b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/TPS.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/TPS.java @@ -78,10 +78,7 @@ public class TPS { return false; } final TPS other = (TPS) obj; - if (this.date != other.date) { - return false; - } - return Double.doubleToLongBits(this.tps) == Double.doubleToLongBits(other.tps) && this.players == other.players; + return this.date == other.date && Double.doubleToLongBits(this.tps) == Double.doubleToLongBits(other.tps) && this.players == other.players; } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/data/UserData.java b/Plan/src/main/java/com/djrapitops/plan/data/UserData.java index df4e3ec7a..4219a4f9c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/UserData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/UserData.java @@ -3,19 +3,12 @@ package main.java.com.djrapitops.plan.data; import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.player.IOfflinePlayer; import com.djrapitops.plugin.utilities.player.IPlayer; -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; import main.java.com.djrapitops.plan.Log; +import java.net.InetAddress; +import java.util.*; +import java.util.stream.Collectors; + /** * This class is used for storing information about a player during runtime. * @@ -800,13 +793,10 @@ public class UserData { if (!Objects.equals(this.nicknames, other.nicknames)) { return false; } - if (!Objects.equals(this.lastGamemode, other.lastGamemode)) { - return false; - } - if (!Objects.equals(this.gmTimes, other.gmTimes)) { - return false; - } - return Objects.equals(this.playerKills, other.playerKills) && Objects.equals(this.sessions, other.sessions); + return Objects.equals(this.lastGamemode, other.lastGamemode) + && Objects.equals(this.gmTimes, other.gmTimes) + && Objects.equals(this.playerKills, other.playerKills) + && Objects.equals(this.sessions, other.sessions); } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginData.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginData.java index bf0596bab..eb8497190 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginData.java @@ -294,13 +294,10 @@ public abstract class PluginData { return false; } final PluginData other = (PluginData) obj; - if (this.analysisOnly != other.analysisOnly) { - return false; - } - if (!Objects.equals(this.placeholder, other.placeholder)) { - return false; - } - return Objects.equals(this.sourcePlugin, other.sourcePlugin) && Objects.equals(this.analysisTypes, other.analysisTypes); + return this.analysisOnly == other.analysisOnly + && Objects.equals(this.placeholder, other.placeholder) + && Objects.equals(this.sourcePlugin, other.sourcePlugin) + && Objects.equals(this.analysisTypes, other.analysisTypes); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/GeolocationPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/GeolocationPart.java index 9e7d29f87..957bdf047 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/GeolocationPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/GeolocationPart.java @@ -73,10 +73,7 @@ public class GeolocationPart extends RawData { } public void addGeoloc(String country) { - if (geolocations.get(country) == null) { - return; - } - geolocations.replace(country, geolocations.get(country) + 1); + geolocations.computeIfPresent(country, (computedCountry, amount) -> amount + 1); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java index aada560d0..953e4d944 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java @@ -1,20 +1,17 @@ package main.java.com.djrapitops.plan.data.cache; import com.djrapitops.plugin.task.AbsRunnable; -import com.djrapitops.plugin.task.ITask; import com.djrapitops.plugin.utilities.player.IPlayer; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Phrase; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Settings; -import main.java.com.djrapitops.plan.data.*; -import main.java.com.djrapitops.plan.data.cache.queue.*; +import main.java.com.djrapitops.plan.data.TPS; +import main.java.com.djrapitops.plan.data.UserData; +import main.java.com.djrapitops.plan.data.cache.queue.DataCacheClearQueue; +import main.java.com.djrapitops.plan.data.cache.queue.DataCacheGetQueue; +import main.java.com.djrapitops.plan.data.cache.queue.DataCacheProcessQueue; +import main.java.com.djrapitops.plan.data.cache.queue.DataCacheSaveQueue; import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo; import main.java.com.djrapitops.plan.data.handling.info.LogoutInfo; import main.java.com.djrapitops.plan.data.handling.info.ReloadInfo; @@ -25,6 +22,9 @@ import main.java.com.djrapitops.plan.utilities.NewPlayerCreator; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; import main.java.com.djrapitops.plan.utilities.comparators.HandlingInfoTimeComparator; +import java.sql.SQLException; +import java.util.*; + /** * This Class contains the Cache. * @@ -131,7 +131,7 @@ public class DataCacheHandler extends SessionCache { clearAfterXsaves = configValue; } DataCacheHandler handler = this; - ITask asyncPeriodicCacheSaveTask = plugin.getRunnableFactory().createNew(new AbsRunnable("PeriodicCacheSaveTask") { + plugin.getRunnableFactory().createNew(new AbsRunnable("PeriodicCacheSaveTask") { private int timesSaved = 0; @Override @@ -492,7 +492,7 @@ public class DataCacheHandler extends SessionCache { * Calls all the methods that are ran when PlayerJoinEvent is fired */ public void handleReload() { - ITask asyncReloadCacheUpdateTask = plugin.getRunnableFactory().createNew(new AbsRunnable("ReloadCacheUpdateTask") { + plugin.getRunnableFactory().createNew(new AbsRunnable("ReloadCacheUpdateTask") { @Override public void run() { final List onlinePlayers = plugin.fetch().getOnlinePlayers(); diff --git a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java index d4bf26881..4b4ae1eb7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java @@ -1,20 +1,23 @@ package main.java.com.djrapitops.plan.database.databases; import com.djrapitops.plugin.task.AbsRunnable; +import main.java.com.djrapitops.plan.Log; +import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.data.KillData; +import main.java.com.djrapitops.plan.data.SessionData; +import main.java.com.djrapitops.plan.data.UserData; +import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor; +import main.java.com.djrapitops.plan.database.Database; +import main.java.com.djrapitops.plan.database.tables.*; +import main.java.com.djrapitops.plan.utilities.Benchmark; +import main.java.com.djrapitops.plan.utilities.FormatUtils; + import java.net.InetAddress; import java.sql.Connection; import java.sql.SQLException; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; -import main.java.com.djrapitops.plan.Log; -import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.data.*; -import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor; -import main.java.com.djrapitops.plan.database.Database; -import main.java.com.djrapitops.plan.database.tables.*; -import main.java.com.djrapitops.plan.utilities.Benchmark; -import main.java.com.djrapitops.plan.utilities.FormatUtils; /** * @@ -52,8 +55,6 @@ public abstract class SQLDB extends Database { } /** - * - * @param plugin * @throws IllegalArgumentException * @throws IllegalStateException */ diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/CommandUseTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/CommandUseTableCreator.java index 6661c87f9..e1c6dce43 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/CommandUseTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/CommandUseTableCreator.java @@ -1,13 +1,14 @@ package main.java.com.djrapitops.plan.ui.html.tables; -import java.util.Collections; -import java.util.List; -import java.util.Map; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.ui.html.Html; import main.java.com.djrapitops.plan.utilities.Benchmark; import main.java.com.djrapitops.plan.utilities.comparators.MapComparator; +import java.util.Collections; +import java.util.List; +import java.util.Map; + /** * * @author Rsl1122 @@ -38,6 +39,7 @@ public class CommandUseTableCreator { Log.toLog("SortableCommandUseTableCreator", e); Log.toLog("Cause: " + values[0] + " " + values[1], Log.getErrorsFilename()); } + i++; } } Benchmark.stop("Create commanduse table"); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java b/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java index 7140d4782..97917ff82 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java @@ -1,11 +1,11 @@ package main.java.com.djrapitops.plan.utilities; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.spec.InvalidKeySpecException; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.xml.bind.DatatypeConverter; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.InvalidKeySpecException; /** * Password Encryption utility. @@ -98,7 +98,7 @@ public class PassEncryptUtil { ); } - int iterations = 0; + int iterations; try { iterations = Integer.parseInt(params[ITERATION_INDEX]); } catch (NumberFormatException ex) { @@ -113,7 +113,7 @@ public class PassEncryptUtil { ); } - byte[] salt = null; + byte[] salt; try { salt = fromBase64(params[SALT_INDEX]); } catch (IllegalArgumentException ex) { @@ -122,7 +122,7 @@ public class PassEncryptUtil { ); } - byte[] hash = null; + byte[] hash; try { hash = fromBase64(params[PBKDF2_INDEX]); } catch (IllegalArgumentException ex) { @@ -131,7 +131,7 @@ public class PassEncryptUtil { ); } - int storedHashSize = 0; + int storedHashSize; try { storedHashSize = Integer.parseInt(params[HASH_SIZE_INDEX]); } catch (NumberFormatException ex) {