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)
This commit is contained in:
Fuzzlemann 2017-07-23 17:18:08 +02:00
parent 9719d3097f
commit 06bd3518f6
12 changed files with 55 additions and 79 deletions

View File

@ -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;
}

View File

@ -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 {

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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);
}
/**

View File

@ -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

View File

@ -73,10 +73,7 @@ public class GeolocationPart extends RawData<GeolocationPart> {
}
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);
}
}

View File

@ -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<IPlayer> onlinePlayers = plugin.fetch().getOnlinePlayers();

View File

@ -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
*/

View File

@ -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");

View File

@ -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) {