Merge pull request #243 from Fuzzlemann/master

PR for 3.6.3 (Fuzzlemann) (2)
This commit is contained in:
Rsl1122 2017-08-12 16:08:57 +03:00 committed by GitHub
commit d4cd53cd07
23 changed files with 172 additions and 180 deletions

View File

@ -32,14 +32,17 @@ public class WebLevelCommand extends SubCommand {
ColorScheme cs = plugin.getColorScheme(); ColorScheme cs = plugin.getColorScheme();
String sCol = cs.getSecondaryColor(); String sCol = cs.getSecondaryColor();
String cmdBall = Locale.get(Msg.CMD_CONSTANT_LIST_BALL).parse(); String cmdBall = Locale.get(Msg.CMD_CONSTANT_LIST_BALL).parse();
String cmdFooter = Locale.get(Msg.CMD_CONSTANT_FOOTER).parse();
String[] messages = new String[]{ String[] messages = new String[]{
Locale.get(Msg.CMD_CONSTANT_FOOTER).parse(), cmdFooter,
cmdBall + sCol + "0: Access all pages", cmdBall + sCol + "0: Access all pages",
cmdBall + sCol + "1: Access '/players' and all inspect pages", cmdBall + sCol + "1: Access '/players' and all inspect pages",
cmdBall + sCol + "2: Access inspect page with the same username as the webuser", cmdBall + sCol + "2: Access inspect page with the same username as the webuser",
cmdBall + sCol + "3+: No permissions", cmdBall + sCol + "3+: No permissions",
Locale.get(Msg.CMD_CONSTANT_FOOTER).parse() cmdFooter
}; };
sender.sendMessage(messages); sender.sendMessage(messages);
return true; return true;
} }

View File

@ -484,14 +484,6 @@ public class UserData {
return gmTimes; return gmTimes;
} }
public void setGmTimes(Map<String, Long> times) {
if (Verify.notNull(times)) {
for (Map.Entry<String, Long> entry : times.entrySet()) {
gmTimes.setTime(entry.getKey(), entry.getValue());
}
}
}
/** /**
* Set the GM Times object containing playtime in each gamemode. * Set the GM Times object containing playtime in each gamemode.
* *
@ -503,6 +495,14 @@ public class UserData {
} }
} }
public void setGmTimes(Map<String, Long> times) {
if (Verify.notNull(times)) {
for (Map.Entry<String, Long> entry : times.entrySet()) {
gmTimes.setTime(entry.getKey(), entry.getValue());
}
}
}
/** /**
* Is the user Operator? * Is the user Operator?
* *

View File

@ -64,7 +64,7 @@ public class AnalysisCacheHandler {
} }
/** /**
* @return * @return if currently an analysis is being run
*/ */
public boolean isAnalysisBeingRun() { public boolean isAnalysisBeingRun() {
return analysis.isAnalysisBeingRun(); return analysis.isAnalysisBeingRun();

View File

@ -516,28 +516,28 @@ public class DataCacheHandler extends SessionCache {
} }
/** /**
* @return * @return The SaveTask
*/ */
public DataCacheSaveQueue getSaveTask() { public DataCacheSaveQueue getSaveTask() {
return saveTask; return saveTask;
} }
/** /**
* @return * @return The ClearTask
*/ */
public DataCacheClearQueue getClearTask() { public DataCacheClearQueue getClearTask() {
return clearTask; return clearTask;
} }
/** /**
* @return * @return The ProcessTask
*/ */
public DataCacheProcessQueue getProcessTask() { public DataCacheProcessQueue getProcessTask() {
return processTask; return processTask;
} }
/** /**
* @return * @return The GetTask
*/ */
public DataCacheGetQueue getGetTask() { public DataCacheGetQueue getGetTask() {
return getTask; return getTask;

View File

@ -33,9 +33,8 @@ public class DBUtils {
* BATCH_SIZE. * BATCH_SIZE.
* *
* @param <T> Object type * @param <T> Object type
* @param objects Collection of the objects. // * @return Lists with max * @param objects Collection of the objects
* size of BATCH_SIZE. * @return Lists with max size of BATCH_SIZE
* @return
*/ */
public static <T> List<List<T>> splitIntoBatches(Collection<T> objects) { public static <T> List<List<T>> splitIntoBatches(Collection<T> objects) {
List<List<T>> batches = new ArrayList<>(); List<List<T>> batches = new ArrayList<>();
@ -57,9 +56,9 @@ public class DBUtils {
} }
/** /**
* @param <T> * @param <T> Object type
* @param objects * @param objects Collection of the objects
* @return * @return Lists with max size of BATCH_SIZE
*/ */
public static <T> List<List<Container<T>>> splitIntoBatchesId(Map<Integer, List<T>> objects) { public static <T> List<List<Container<T>>> splitIntoBatchesId(Map<Integer, List<T>> objects) {
List<List<Container<T>>> wrappedBatches = new ArrayList<>(); List<List<Container<T>>> wrappedBatches = new ArrayList<>();
@ -83,6 +82,11 @@ public class DBUtils {
return wrappedBatches; return wrappedBatches;
} }
/**
* @param <T> Object type
* @param objects Collection of the objects
* @return Lists with max size of BATCH_SIZE
*/
public static <T> List<List<Container<T>>> splitIntoBatchesWithID(Map<Integer, T> objects) { public static <T> List<List<Container<T>>> splitIntoBatchesWithID(Map<Integer, T> objects) {
List<List<Container<T>>> wrappedBatches = new ArrayList<>(); List<List<Container<T>>> wrappedBatches = new ArrayList<>();

View File

@ -306,7 +306,7 @@ public abstract class SQLDB extends Database {
int userId = usersTable.getUserId(uuid); int userId = usersTable.getUserId(uuid);
boolean success = userId != -1 boolean success = userId != -1
&& locationsTable.removeUserLocations(userId) && locationsTable.removeUserLocations(userId)
&& ipsTable.removeUserIps(userId) && ipsTable.removeUserIPs(userId)
&& nicknamesTable.removeUserNicknames(userId) && nicknamesTable.removeUserNicknames(userId)
&& gmTimesTable.removeUserGMTimes(userId) && gmTimesTable.removeUserGMTimes(userId)
&& sessionsTable.removeUserSessions(userId) && sessionsTable.removeUserSessions(userId)

View File

@ -1,5 +1,6 @@
package main.java.com.djrapitops.plan.database.tables; package main.java.com.djrapitops.plan.database.tables;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.database.databases.SQLDB; import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.utilities.Benchmark; import main.java.com.djrapitops.plan.utilities.Benchmark;
@ -20,8 +21,8 @@ public class IPsTable extends Table {
private final String columnIP; private final String columnIP;
/** /**
* @param db * @param db The database
* @param usingMySQL * @param usingMySQL if the server is using MySQL
*/ */
public IPsTable(SQLDB db, boolean usingMySQL) { public IPsTable(SQLDB db, boolean usingMySQL) {
super("plan_ips", db, usingMySQL); super("plan_ips", db, usingMySQL);
@ -30,7 +31,7 @@ public class IPsTable extends Table {
} }
/** /**
* @return * @return if the table was created successfully
*/ */
@Override @Override
public boolean createTable() { public boolean createTable() {
@ -50,10 +51,10 @@ public class IPsTable extends Table {
} }
/** /**
* @param userId * @param userId The User ID from which the IPs should be removed from
* @return * @return if the IPs were removed successfully
*/ */
public boolean removeUserIps(int userId) { public boolean removeUserIPs(int userId) {
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUserID + "=?)"); statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUserID + "=?)");
@ -69,18 +70,19 @@ public class IPsTable extends Table {
} }
/** /**
* @param userId * @param userId The User ID from which the IPs should be retrieved from
* @return * @return The retrieved IPs
* @throws SQLException * @throws SQLException when an error at retrieval happens
*/ */
public List<InetAddress> getIPAddresses(int userId) throws SQLException { public List<InetAddress> getIPAddresses(int userId) throws SQLException {
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet set = null; ResultSet set = null;
try { try {
List<InetAddress> ips = new ArrayList<>();
statement = prepareStatement("SELECT * FROM " + tableName + " WHERE UPPER(" + columnUserID + ") LIKE UPPER(?)"); statement = prepareStatement("SELECT * FROM " + tableName + " WHERE UPPER(" + columnUserID + ") LIKE UPPER(?)");
statement.setInt(1, userId); statement.setInt(1, userId);
set = statement.executeQuery(); set = statement.executeQuery();
List<InetAddress> ips = new ArrayList<>();
while (set.next()) { while (set.next()) {
String ipAddressName = set.getString(columnIP); String ipAddressName = set.getString(columnIP);
try { try {
@ -92,15 +94,14 @@ public class IPsTable extends Table {
return ips; return ips;
} finally { } finally {
close(set); close(set, statement);
close(statement);
} }
} }
/** /**
* @param userId * @param userId The User ID for which the IPs should be saved for
* @param ips * @param ips The IPs
* @throws SQLException * @throws SQLException when an error at saving happens
*/ */
public void saveIPList(int userId, Set<InetAddress> ips) throws SQLException { public void saveIPList(int userId, Set<InetAddress> ips) throws SQLException {
if (ips == null) { if (ips == null) {
@ -120,8 +121,8 @@ public class IPsTable extends Table {
+ columnIP + columnIP
+ ") VALUES (?, ?)"); + ") VALUES (?, ?)");
boolean commitRequired = false; boolean commitRequired = false;
for (InetAddress ip : ips) {
for (InetAddress ip : ips) {
if (ip == null) { if (ip == null) {
continue; continue;
} }
@ -142,12 +143,12 @@ public class IPsTable extends Table {
} }
/** /**
* @param ids * @param ids The User IDs for which the IPs should be retrieved for
* @return * @return The User IDs corresponding with their used IPs
* @throws SQLException * @throws SQLException when an error at retrieval happens
*/ */
public Map<Integer, Set<InetAddress>> getIPList(Collection<Integer> ids) throws SQLException { public Map<Integer, Set<InetAddress>> getIPList(Collection<Integer> ids) throws SQLException {
if (ids == null || ids.isEmpty()) { if (Verify.isEmpty(ids)) {
return new HashMap<>(); return new HashMap<>();
} }
@ -182,22 +183,23 @@ public class IPsTable extends Table {
return ips; return ips;
} finally { } finally {
close(set); close(set, statement);
close(statement);
Benchmark.stop("Database", "Get Ips Multiple"); Benchmark.stop("Database", "Get Ips Multiple");
} }
} }
/** /**
* @param ips * @param ips The User IDs corresponding to their IPs used
* @throws SQLException * @throws SQLException when an error at saving happens
*/ */
public void saveIPList(Map<Integer, Set<InetAddress>> ips) throws SQLException { public void saveIPList(Map<Integer, Set<InetAddress>> ips) throws SQLException {
if (ips == null || ips.isEmpty()) { if (Verify.isEmpty(ips)) {
return; return;
} }
Benchmark.start("Save Ips Multiple"); Benchmark.start("Save Ips Multiple");
Map<Integer, Set<InetAddress>> saved = getIPList(ips.keySet()); Map<Integer, Set<InetAddress>> saved = getIPList(ips.keySet());
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = prepareStatement("INSERT INTO " + tableName + " (" statement = prepareStatement("INSERT INTO " + tableName + " ("
@ -205,7 +207,7 @@ public class IPsTable extends Table {
+ columnIP + columnIP
+ ") VALUES (?, ?)"); + ") VALUES (?, ?)");
boolean commitRequired = false; boolean commitRequired = false;
int batchSize = 0;
for (Map.Entry<Integer, Set<InetAddress>> entrySet : ips.entrySet()) { for (Map.Entry<Integer, Set<InetAddress>> entrySet : ips.entrySet()) {
Integer id = entrySet.getKey(); Integer id = entrySet.getKey();
Set<InetAddress> ipAddresses = entrySet.getValue(); Set<InetAddress> ipAddresses = entrySet.getValue();
@ -229,7 +231,6 @@ public class IPsTable extends Table {
statement.setString(2, ip.getHostAddress()); statement.setString(2, ip.getHostAddress());
statement.addBatch(); statement.addBatch();
commitRequired = true; commitRequired = true;
batchSize++;
} }
} }

View File

@ -1,5 +1,6 @@
package main.java.com.djrapitops.plan.database.tables; package main.java.com.djrapitops.plan.database.tables;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.database.databases.SQLDB; import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.utilities.Benchmark; import main.java.com.djrapitops.plan.utilities.Benchmark;
@ -19,8 +20,8 @@ public class NicknamesTable extends Table {
private final String columnCurrent; private final String columnCurrent;
/** /**
* @param db * @param db The database
* @param usingMySQL * @param usingMySQL if the server is using MySQL
*/ */
public NicknamesTable(SQLDB db, boolean usingMySQL) { public NicknamesTable(SQLDB db, boolean usingMySQL) {
super("plan_nicknames", db, usingMySQL); super("plan_nicknames", db, usingMySQL);
@ -30,7 +31,7 @@ public class NicknamesTable extends Table {
} }
/** /**
* @return * @return if the table was created successfully
*/ */
@Override @Override
public boolean createTable() { public boolean createTable() {
@ -43,6 +44,7 @@ public class NicknamesTable extends Table {
+ "FOREIGN KEY(" + columnUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + ")" + "FOREIGN KEY(" + columnUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + ")"
+ ")" + ")"
); );
if (getVersion() < 3) { if (getVersion() < 3) {
alterTablesV3(); alterTablesV3();
} }
@ -58,8 +60,8 @@ public class NicknamesTable extends Table {
} }
/** /**
* @param userId * @param userId The User ID from which the nicknames should be removed from
* @return * @return if the removal was successful
*/ */
public boolean removeUserNicknames(int userId) { public boolean removeUserNicknames(int userId) {
PreparedStatement statement = null; PreparedStatement statement = null;
@ -77,9 +79,9 @@ public class NicknamesTable extends Table {
} }
/** /**
* @param userId * @param userId The User ID from which the nicknames should be retrieved from
* @return * @return The nicknames of the User
* @throws SQLException * @throws SQLException when an error at retrieval happens
*/ */
public List<String> getNicknames(int userId) throws SQLException { public List<String> getNicknames(int userId) throws SQLException {
PreparedStatement statement = null; PreparedStatement statement = null;
@ -88,6 +90,7 @@ public class NicknamesTable extends Table {
statement = prepareStatement("SELECT * FROM " + tableName + " WHERE (" + columnUserID + "=?)"); statement = prepareStatement("SELECT * FROM " + tableName + " WHERE (" + columnUserID + "=?)");
statement.setInt(1, userId); statement.setInt(1, userId);
set = statement.executeQuery(); set = statement.executeQuery();
List<String> nicknames = new ArrayList<>(); List<String> nicknames = new ArrayList<>();
String lastNick = ""; String lastNick = "";
while (set.next()) { while (set.next()) {
@ -95,36 +98,39 @@ public class NicknamesTable extends Table {
if (nickname.isEmpty()) { if (nickname.isEmpty()) {
continue; continue;
} }
nicknames.add(nickname); nicknames.add(nickname);
if (set.getBoolean(columnCurrent)) { if (set.getBoolean(columnCurrent)) {
lastNick = nickname; lastNick = nickname;
} }
} }
if (!lastNick.isEmpty()) { if (!lastNick.isEmpty()) {
nicknames.remove(lastNick); nicknames.set(nicknames.size() - 1, lastNick);
nicknames.add(lastNick);
} }
return nicknames; return nicknames;
} finally { } finally {
close(set); close(set, statement);
close(statement);
} }
} }
/** /**
* @param userId * @param userId The User ID for which the nicknames should be saved for
* @param names * @param names The nicknames
* @param lastNick * @param lastNick The latest nickname
* @throws SQLException * @throws SQLException when an error at saving happens
*/ */
public void saveNickList(int userId, Set<String> names, String lastNick) throws SQLException { public void saveNickList(int userId, Set<String> names, String lastNick) throws SQLException {
if (names == null || names.isEmpty()) { if (Verify.isEmpty(names)) {
return; return;
} }
names.removeAll(getNicknames(userId)); names.removeAll(getNicknames(userId));
if (names.isEmpty()) { if (names.isEmpty()) {
return; return;
} }
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = prepareStatement("INSERT INTO " + tableName + " (" statement = prepareStatement("INSERT INTO " + tableName + " ("
@ -132,53 +138,55 @@ public class NicknamesTable extends Table {
+ columnCurrent + ", " + columnCurrent + ", "
+ columnNick + columnNick
+ ") VALUES (?, ?, ?)"); + ") VALUES (?, ?, ?)");
boolean commitRequired = false;
for (String name : names) { for (String name : names) {
statement.setInt(1, userId); statement.setInt(1, userId);
statement.setInt(2, (name.equals(lastNick)) ? 1 : 0); statement.setInt(2, name.equals(lastNick) ? 1 : 0);
statement.setString(3, name); statement.setString(3, name);
statement.addBatch(); statement.addBatch();
commitRequired = true;
} }
if (commitRequired) {
statement.executeBatch();
} statement.executeBatch();
} finally { } finally {
close(statement); close(statement);
} }
} }
/** /**
* @param ids * @param ids The User IDs for which the nicknames should be retrieved for
* @return * @return The User ID corresponding with the nicknames
* @throws SQLException * @throws SQLException when an error at retrieval happens
*/ */
public Map<Integer, List<String>> getNicknames(Collection<Integer> ids) throws SQLException { public Map<Integer, List<String>> getNicknames(Collection<Integer> ids) throws SQLException {
if (ids == null || ids.isEmpty()) { if (Verify.isEmpty(ids)) {
return new HashMap<>(); return new HashMap<>();
} }
Benchmark.start("Get Nicknames Multiple"); Benchmark.start("Get Nicknames Multiple");
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet set = null; ResultSet set = null;
try { try {
Map<Integer, List<String>> nicks = new HashMap<>(); Map<Integer, List<String>> nicks = new HashMap<>();
Map<Integer, String> lastNicks = new HashMap<>(); Map<Integer, String> lastNicks = new HashMap<>();
for (Integer id : ids) { for (Integer id : ids) {
nicks.put(id, new ArrayList<>()); nicks.put(id, new ArrayList<>());
} }
statement = prepareStatement("SELECT * FROM " + tableName); statement = prepareStatement("SELECT * FROM " + tableName);
set = statement.executeQuery(); set = statement.executeQuery();
while (set.next()) { while (set.next()) {
Integer id = set.getInt(columnUserID); Integer id = set.getInt(columnUserID);
if (!ids.contains(id)) { if (!ids.contains(id)) {
continue; continue;
} }
String nickname = set.getString(columnNick); String nickname = set.getString(columnNick);
if (nickname.isEmpty()) { if (nickname.isEmpty()) {
continue; continue;
} }
nicks.get(id).add(nickname); nicks.get(id).add(nickname);
if (set.getBoolean(columnCurrent)) { if (set.getBoolean(columnCurrent)) {
lastNicks.put(id, nickname); lastNicks.put(id, nickname);
@ -199,19 +207,18 @@ public class NicknamesTable extends Table {
return nicks; return nicks;
} finally { } finally {
close(set); close(set, statement);
close(statement);
Benchmark.stop("Database", "Get Nicknames Multiple"); Benchmark.stop("Database", "Get Nicknames Multiple");
} }
} }
/** /**
* @param nicknames * @param nicknames The User ID corresponding to the nicknames
* @param lastNicks * @param lastNicks The User ID corresponding with the last nick they inherited
* @throws SQLException * @throws SQLException when an error at saving happens
*/ */
public void saveNickLists(Map<Integer, Set<String>> nicknames, Map<Integer, String> lastNicks) throws SQLException { public void saveNickLists(Map<Integer, Set<String>> nicknames, Map<Integer, String> lastNicks) throws SQLException {
if (nicknames == null || nicknames.isEmpty()) { if (Verify.isEmpty(nicknames)) {
return; return;
} }

View File

@ -44,6 +44,21 @@ public class Locale implements Closeable {
messages = new HashMap<>(); messages = new HashMap<>();
} }
public static void unload() {
Locale locale = LocaleHolder.getLocale();
if (locale != null) {
locale.close();
}
}
public static Message get(Msg msg) {
Locale locale = LocaleHolder.getLocale();
if (locale == null) {
throw new IllegalStateException("Locale has not been initialized.");
}
return locale.getMessage(msg);
}
public void loadLocale() { public void loadLocale() {
String locale = Settings.LOCALE.toString().toUpperCase(); String locale = Settings.LOCALE.toString().toUpperCase();
Benchmark.start("Initializing locale"); Benchmark.start("Initializing locale");
@ -325,31 +340,16 @@ public class Locale implements Closeable {
LocaleHolder.locale = null; LocaleHolder.locale = null;
} }
public static void unload() {
Locale locale = LocaleHolder.getLocale();
if (locale != null) {
locale.close();
}
}
public static Message get(Msg msg) {
Locale locale = LocaleHolder.getLocale();
if (locale == null) {
throw new IllegalStateException("Locale has not been initialized.");
}
return locale.getMessage(msg);
}
private static class LocaleHolder { private static class LocaleHolder {
private static Locale locale; private static Locale locale;
public static void setLocale(Locale locale) {
LocaleHolder.locale = locale;
}
public static Locale getLocale() { public static Locale getLocale() {
return locale; return locale;
} }
public static void setLocale(Locale locale) {
LocaleHolder.locale = locale;
}
} }
} }

View File

@ -147,11 +147,11 @@ public enum Msg {
this.identifier = identifier; this.identifier = identifier;
} }
public String getIdentifier() {
return identifier;
}
public static Map<String, Msg> getIdentifiers() { public static Map<String, Msg> getIdentifiers() {
return Arrays.stream(values()).collect(Collectors.toMap(Msg::getIdentifier, Function.identity())); return Arrays.stream(values()).collect(Collectors.toMap(Msg::getIdentifier, Function.identity()));
} }
public String getIdentifier() {
return identifier;
}
} }

View File

@ -1,13 +1,6 @@
package main.java.com.djrapitops.plan.ui.html; package main.java.com.djrapitops.plan.ui.html;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/** /**
* @author Rsl1122 * @author Rsl1122
@ -60,8 +53,7 @@ public enum Html {
TABLELINE_3_CUSTOMKEY("<tr><td sorttable_customkey=\"REPLACE0\">REPLACE1</td><td sorttable_customkey=\"REPLACE2\">REPLACE3</td><td sorttable_customkey=\"REPLACE4\">REPLACE5</td></tr>"), TABLELINE_3_CUSTOMKEY("<tr><td sorttable_customkey=\"REPLACE0\">REPLACE1</td><td sorttable_customkey=\"REPLACE2\">REPLACE3</td><td sorttable_customkey=\"REPLACE4\">REPLACE5</td></tr>"),
TABLELINE_3_CUSTOMKEY_1("<tr><td sorttable_customkey=\"REPLACE0\">REPLACE1</td><td>REPLACE2</td><td>REPLACE3</td></tr>"), TABLELINE_3_CUSTOMKEY_1("<tr><td sorttable_customkey=\"REPLACE0\">REPLACE1</td><td>REPLACE2</td><td>REPLACE3</td></tr>"),
ERROR_TABLE_2(TABLELINE_2.parse("No data", "No data")), ERROR_TABLE_2(TABLELINE_2.parse("No data", "No data")),
TABLE_END("</tbody></table>"), // KILLDATA_NONE("No Kills"), TABLE_END("</tbody></table>"); // KILLDATA_NONE("No Kills"),
;
private String html; private String html;
@ -70,50 +62,15 @@ public enum Html {
} }
/** /**
* @param localeFile * @return The HTML String
*/
public static void loadLocale(File localeFile) {
try (Scanner localeScanner = new Scanner(localeFile, "UTF-8")) {
List<String> localeRows = new ArrayList<>();
boolean html = false;
while (localeScanner.hasNextLine()) {
String line = localeScanner.nextLine();
if (line.equals("<<<<<<HTML>>>>>>")) {
html = true;
continue;
}
if (!html) {
continue;
}
localeRows.add(line);
}
for (String localeRow : localeRows) {
try {
String[] split = localeRow.split(" <> ");
Html.valueOf(split[0]).setHtml(split[1]);
} catch (IllegalArgumentException e) {
Log.error("There is a miswritten lines in locale on lines " + localeRows.indexOf(localeRow));
}
}
} catch (IOException e) {
Log.error("Something went wrong at loading locale " + localeFile.getAbsoluteFile() + ": " + e.getCause());
}
}
/**
* @return
*/ */
public String parse() { public String parse() {
return html; return html;
} }
/** /**
* @param p * @param p The replacement Strings
* @return * @return The parsed HTML String
*/ */
public String parse(String... p) { public String parse(String... p) {
Verify.nullCheck(p); Verify.nullCheck(p);
@ -125,7 +82,7 @@ public enum Html {
} }
/** /**
* @param html * @param html Sets the HTML String
*/ */
public void setHtml(String html) { public void setHtml(String html) {
this.html = html; this.html = html;

View File

@ -14,8 +14,8 @@ public class WorldMapCreator {
/** /**
* Creates a data series with iso-a3 specification of Country codes. * Creates a data series with iso-a3 specification of Country codes.
* *
* @param geoCodeCounts * @param geoCodeCounts The country codes and the amount of players located in the country
* @return * @return The created data series
*/ */
public static String createDataSeries(Map<String, Integer> geoCodeCounts) { public static String createDataSeries(Map<String, Integer> geoCodeCounts) {
StringBuilder arrayBuilder = new StringBuilder("["); StringBuilder arrayBuilder = new StringBuilder("[");
@ -25,16 +25,17 @@ public class WorldMapCreator {
for (Map.Entry<String, Integer> entry : geoCodeCounts.entrySet()) { for (Map.Entry<String, Integer> entry : geoCodeCounts.entrySet()) {
String geoCode = entry.getKey(); String geoCode = entry.getKey();
Integer players = entry.getValue(); Integer players = entry.getValue();
if (players != 0) { if (players != 0) {
arrayBuilder.append("{'code':'").append(geoCode).append("','value':").append(players).append("}"); arrayBuilder.append("{'code':'").append(geoCode).append("','value':").append(players).append("}");
if (i < size - 1) { if (i < size - 1) {
arrayBuilder.append(","); arrayBuilder.append(",");
} }
} }
i++; i++;
} }
arrayBuilder.append("]"); arrayBuilder.append("]");
return arrayBuilder.toString(); return arrayBuilder.toString();
} }

View File

@ -21,11 +21,12 @@ public class CommandUseTableCreator {
} }
/** /**
* @param commandUse * @param commandUse The commands and the amount of times casted
* @return * @return The created command use table
*/ */
public static String createSortedCommandUseTable(Map<String, Integer> commandUse) { public static String createSortedCommandUseTable(Map<String, Integer> commandUse) {
List<String[]> sorted = MapComparator.sortByValue(commandUse); List<String[]> sorted = MapComparator.sortByValue(commandUse);
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder();
if (sorted.isEmpty()) { if (sorted.isEmpty()) {
html.append(Html.ERROR_TABLE_2.parse()); html.append(Html.ERROR_TABLE_2.parse());
@ -47,6 +48,7 @@ public class CommandUseTableCreator {
i++; i++;
} }
} }
return html.toString(); return html.toString();
} }
} }

View File

@ -26,8 +26,8 @@ public class KillsTableCreator {
} }
/** /**
* @param killData * @param killData The list of the {@link KillData} Objects from which the kill table should be created
* @return * @return The created kills table
*/ */
public static String createKillsTable(List<KillData> killData) { public static String createKillsTable(List<KillData> killData) {
StringBuilder html = new StringBuilder(Html.TABLE_KILLS_START.parse()); StringBuilder html = new StringBuilder(Html.TABLE_KILLS_START.parse());
@ -35,16 +35,17 @@ public class KillsTableCreator {
if (killData.isEmpty()) { if (killData.isEmpty()) {
html.append(Html.TABLELINE_3.parse(Locale.get(Msg.HTML_TABLE_NO_KILLS).parse(), "", "")); html.append(Html.TABLELINE_3.parse(Locale.get(Msg.HTML_TABLE_NO_KILLS).parse(), "", ""));
} else { } else {
int i = 0;
killData.sort(new KillDataComparator()); killData.sort(new KillDataComparator());
Collections.reverse(killData); Collections.reverse(killData);
int i = 0;
for (KillData kill : killData) { for (KillData kill : killData) {
if (i >= 20) { if (i >= 20) {
break; break;
} }
long date = kill.getDate(); long date = kill.getDate();
IOfflinePlayer victim = Fetch.getIOfflinePlayer(kill.getVictim()); IOfflinePlayer victim = Fetch.getIOfflinePlayer(kill.getVictim());
String name = victim.getName(); String name = victim.getName();
html.append(Html.TABLELINE_3_CUSTOMKEY_1.parse( html.append(Html.TABLELINE_3_CUSTOMKEY_1.parse(
@ -52,9 +53,11 @@ public class KillsTableCreator {
Html.LINK.parse(HtmlUtils.getInspectUrl(name), name), Html.LINK.parse(HtmlUtils.getInspectUrl(name), name),
kill.getWeapon() kill.getWeapon()
)); ));
i++; i++;
} }
} }
html.append(Html.TABLE_END.parse()); html.append(Html.TABLE_END.parse());
return html.toString(); return html.toString();

View File

@ -23,8 +23,8 @@ public class PlayersTableCreator {
} }
/** /**
* @param data * @param data The list of the {@link UserData} Objects from which the players table should be created
* @return * @return The created players table
*/ */
public static String createSortablePlayersTable(List<UserData> data) { public static String createSortablePlayersTable(List<UserData> data) {
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder();
@ -37,6 +37,7 @@ public class PlayersTableCreator {
if (i >= 750) { if (i >= 750) {
break; break;
} }
try { try {
boolean isBanned = uData.isBanned(); boolean isBanned = uData.isBanned();
boolean isUnknown = uData.getLoginTimes() == 1; boolean isUnknown = uData.getLoginTimes() == 1;
@ -59,7 +60,9 @@ public class PlayersTableCreator {
String.valueOf(uData.getGeolocation()) String.valueOf(uData.getGeolocation())
)); ));
} catch (NullPointerException ignored) { } catch (NullPointerException ignored) {
/* ignored */
} }
i++; i++;
} }

View File

@ -29,15 +29,17 @@ public class TextUI {
} }
/** /**
* @param uuid * @param uuid The UUID for which the inspect messages should be get for
* @return * @return The inspect messages
*/ */
public static String[] getInspectMessages(UUID uuid) { public static String[] getInspectMessages(UUID uuid) {
InspectCacheHandler inspectCache = Plan.getInstance().getInspectCache(); InspectCacheHandler inspectCache = Plan.getInstance().getInspectCache();
long now = MiscUtils.getTime(); long now = MiscUtils.getTime();
if (!inspectCache.isCached(uuid)) { if (!inspectCache.isCached(uuid)) {
return new String[]{"Error has occurred, please retry."}; return new String[]{"Error has occurred, please retry."};
} }
UserData d = inspectCache.getFromCache(uuid); UserData d = inspectCache.getFromCache(uuid);
ColorScheme cs = Plan.getInstance().getColorScheme(); ColorScheme cs = Plan.getInstance().getColorScheme();
@ -49,6 +51,7 @@ public class TextUI {
boolean banned = d.isBanned(); boolean banned = d.isBanned();
boolean online = d.isOnline(); boolean online = d.isOnline();
String ball = sec + " " + DefaultMessages.BALL + main; String ball = sec + " " + DefaultMessages.BALL + main;
return new String[]{ return new String[]{
sec + " " + DefaultMessages.BALL + (banned ? ChatColor.DARK_RED + " Banned" : ter + (active ? " Active" : " Inactive")) + (online ? ChatColor.GREEN + " Online" : ChatColor.RED + " Offline"), sec + " " + DefaultMessages.BALL + (banned ? ChatColor.DARK_RED + " Banned" : ter + (active ? " Active" : " Inactive")) + (online ? ChatColor.GREEN + " Online" : ChatColor.RED + " Offline"),
ball + " Registered: " + sec + FormatUtils.formatTimeStampYear(d.getRegistered()), ball + " Registered: " + sec + FormatUtils.formatTimeStampYear(d.getRegistered()),
@ -62,26 +65,31 @@ public class TextUI {
} }
/** /**
* @return * Gets the analysis messages
*
* @return The analysis messages
*/ */
public static String[] getAnalysisMessages() { public static String[] getAnalysisMessages() {
AnalysisCacheHandler analysisCache = Plan.getInstance().getAnalysisCache(); AnalysisCacheHandler analysisCache = Plan.getInstance().getAnalysisCache();
if (!analysisCache.isCached()) { if (!analysisCache.isCached()) {
return new String[]{"Error has occurred, please retry."}; return new String[]{"Error has occurred, please retry."};
} }
AnalysisData d = analysisCache.getData(); AnalysisData d = analysisCache.getData();
ColorScheme cs = Plan.getInstance().getColorScheme(); ColorScheme cs = Plan.getInstance().getColorScheme();
String main = cs.getMainColor(); String main = cs.getMainColor();
String sec = cs.getSecondaryColor(); String sec = cs.getSecondaryColor();
String ball = sec + " " + DefaultMessages.BALL + main; String ball = sec + " " + DefaultMessages.BALL + main;
final ActivityPart activity = d.getActivityPart(); final ActivityPart activity = d.getActivityPart();
final JoinInfoPart join = d.getJoinInfoPart(); final JoinInfoPart join = d.getJoinInfoPart();
final KillPart kills = d.getKillPart(); final KillPart kills = d.getKillPart();
final PlaytimePart playtime = d.getPlaytimePart(); final PlaytimePart playtime = d.getPlaytimePart();
final PlayerCountPart count = d.getPlayerCountPart(); final PlayerCountPart count = d.getPlayerCountPart();
final TPSPart tps = d.getTpsPart(); final TPSPart tps = d.getTpsPart();
return new String[]{ return new String[]{
ball + " Total Players: " + sec + count.getPlayerCount(), ball + " Total Players: " + sec + count.getPlayerCount(),

View File

@ -103,7 +103,8 @@ public class Request implements Closeable {
if (reqLine.length >= 2) { if (reqLine.length >= 2) {
request = reqLine[0]; request = reqLine[0];
target = reqLine[1].replace("%20", " ") target = reqLine[1].replace("%20", " ")
.replace("%2E", ".");; .replace("%2E", ".");
;
} else { } else {
request = "GET"; request = "GET";
target = "/"; target = "/";

View File

@ -350,7 +350,7 @@ public class WebServer {
} }
/** /**
* @return * @return if the WebServer is enabled
*/ */
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;

View File

@ -29,6 +29,7 @@ public class PassEncryptUtil {
public static final int HASH_SIZE_INDEX = 2; public static final int HASH_SIZE_INDEX = 2;
public static final int SALT_INDEX = 3; public static final int SALT_INDEX = 3;
public static final int PBKDF2_INDEX = 4; public static final int PBKDF2_INDEX = 4;
/** /**
* Constructor used to hide the public constructor * Constructor used to hide the public constructor
*/ */

View File

@ -45,7 +45,7 @@ public class PlaceholderUtils {
replaceMap.put("%plugins%", data.replacePluginsTabLayout()); replaceMap.put("%plugins%", data.replacePluginsTabLayout());
replaceMap.put("%refresh%", FormatUtils.formatTimeAmountDifference(data.getRefreshDate(), MiscUtils.getTime())); replaceMap.put("%refresh%", FormatUtils.formatTimeAmountDifference(data.getRefreshDate(), MiscUtils.getTime()));
replaceMap.put("%refreshlong%", data.getRefreshDate() + ""); replaceMap.put("%refreshlong%", String.valueOf(data.getRefreshDate()));
replaceMap.put("%servername%", Settings.SERVER_NAME.toString()); replaceMap.put("%servername%", Settings.SERVER_NAME.toString());
@ -94,7 +94,7 @@ public class PlaceholderUtils {
gmPart.analyse(); gmPart.analyse();
replaceMap.putAll(gmPart.getReplaceMap()); replaceMap.putAll(gmPart.getReplaceMap());
replaceMap.put("%ips%", (showIPandUUID ? data.getIps().toString() : "Hidden (Config)")); replaceMap.put("%ips%", showIPandUUID ? data.getIps().toString() : "Hidden (Config)");
replaceMap.put("%nicknames%", HtmlUtils.removeXSS(HtmlUtils.swapColorsToSpan(data.getNicknames().toString()))); replaceMap.put("%nicknames%", HtmlUtils.removeXSS(HtmlUtils.swapColorsToSpan(data.getNicknames().toString())));
replaceMap.put("%name%", data.getName()); replaceMap.put("%name%", data.getName());
replaceMap.put("%registered%", FormatUtils.formatTimeStampYear(data.getRegistered())); replaceMap.put("%registered%", FormatUtils.formatTimeStampYear(data.getRegistered()));
@ -102,7 +102,7 @@ public class PlaceholderUtils {
replaceMap.put("%playtime%", FormatUtils.formatTimeAmount(data.getPlayTime())); replaceMap.put("%playtime%", FormatUtils.formatTimeAmount(data.getPlayTime()));
replaceMap.put("%banned%", data.isBanned() ? Locale.get(Msg.HTML_BANNED).parse() : ""); replaceMap.put("%banned%", data.isBanned() ? Locale.get(Msg.HTML_BANNED).parse() : "");
replaceMap.put("%op%", data.isOp() ? Locale.get(Msg.HTML_OP).parse() : ""); replaceMap.put("%op%", data.isOp() ? Locale.get(Msg.HTML_OP).parse() : "");
replaceMap.put("%isonline%", (data.isOnline()) ? Locale.get(Msg.HTML_ONLINE).parse() : Locale.get(Msg.HTML_OFFLINE).parse()); replaceMap.put("%isonline%", data.isOnline() ? Locale.get(Msg.HTML_ONLINE).parse() : Locale.get(Msg.HTML_OFFLINE).parse());
replaceMap.put("%deaths%", data.getDeaths()); replaceMap.put("%deaths%", data.getDeaths());
replaceMap.put("%playerkills%", data.getPlayerKills().size()); replaceMap.put("%playerkills%", data.getPlayerKills().size());
replaceMap.put("%mobkills%", data.getMobKills()); replaceMap.put("%mobkills%", data.getMobKills());

View File

@ -267,7 +267,7 @@ public class Analysis {
long now = MiscUtils.getTime(); long now = MiscUtils.getTime();
Benchmark.start("Fill Dataset"); Benchmark.start("Fill Dataset");
List<PluginData> banSources = plugin.getHookHandler().getAdditionalDataSources() List<PluginData> banSources = plugin.getHookHandler().getAdditionalDataSources()
.stream().filter(PluginData::isBanData).collect(Collectors.toList()); .stream().filter(PluginData::isBanData).collect(Collectors.toList());
rawData.forEach(uData -> { rawData.forEach(uData -> {
uData.access(); uData.access();

View File

@ -13,6 +13,7 @@ public class MathUtils {
private static final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH); private static final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
private static final DecimalFormat decimalFormat = new DecimalFormat("#.##", decimalFormatSymbols); private static final DecimalFormat decimalFormat = new DecimalFormat("#.##", decimalFormatSymbols);
/** /**
* Constructor used to hide the public constructor * Constructor used to hide the public constructor
*/ */

View File

@ -10,8 +10,8 @@ import java.util.Map;
/** /**
* Compares Locale Map Entries and sorts them alphabetically according to the Enum Names. * Compares Locale Map Entries and sorts them alphabetically according to the Enum Names.
* *
* @since 3.6.2
* @author Rsl1122 * @author Rsl1122
* @since 3.6.2
*/ */
public class LocaleEntryComparator implements Comparator<Map.Entry<Msg, Message>> { public class LocaleEntryComparator implements Comparator<Map.Entry<Msg, Message>> {