[2.8.4-DEV] Bugfixes

Fixed #52
Fixed 10 issues found by PlanDebugger #47
This commit is contained in:
Rsl1122 2017-03-12 14:18:07 +02:00
parent 39bb967e08
commit ce6b961e99
7 changed files with 47 additions and 31 deletions

View File

@ -179,7 +179,7 @@ public enum Phrase {
public String parse(String... p) {
String returnValue = this.toString();
for (int i = 0; i < p.length; i++) {
returnValue = returnValue.replaceAll("REPLACE" + i, p[i]);
returnValue = returnValue.replace("REPLACE" + i, p[i]);
}
return returnValue;
}

View File

@ -81,7 +81,7 @@ public class UserData {
isBanned = player.isBanned();
} catch (Exception e) {
Plan plugin = getPlugin(Plan.class);
plugin.logError("Error getting ban date from Bukkit files. "+uuid.toString());
plugin.logError("Error getting ban date from Bukkit files. " + uuid.toString());
plugin.toLog(this.getClass().getName(), e);
}
name = player.getName();
@ -118,7 +118,7 @@ public class UserData {
isBanned = player.isBanned();
} catch (Exception e) {
Plan plugin = getPlugin(Plan.class);
plugin.logError("Error getting ban date from Bukkit files. "+uuid.toString());
plugin.logError("Error getting ban date from Bukkit files. " + uuid.toString());
plugin.toLog(this.getClass().getName(), e);
}
name = player.getName();
@ -130,6 +130,7 @@ public class UserData {
/**
* Creates a new UserData object with copied values.
*
* @param data UserData to copy into the new object.
*/
public UserData(UserData data) {
@ -210,9 +211,11 @@ public class UserData {
*/
public boolean addNickname(String nick) {
if (!nicknames.contains(nick)) {
if (!nick.isEmpty()) {
nicknames.add(nick);
return true;
if (nick != null) {
if (!nick.isEmpty()) {
nicknames.add(nick);
return true;
}
}
}
return false;
@ -313,12 +316,10 @@ public class UserData {
}
// Getters -------------------------------------------------------------
/**
*
* @return
*/
public UUID getUuid() {
return uuid;
}
@ -452,7 +453,6 @@ public class UserData {
}
// Setters -------------------------------------------------------------
/**
*
* @param uuid
@ -735,5 +735,4 @@ public class UserData {
return true;
}
}

View File

@ -5,6 +5,8 @@ import java.util.*;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
/**
@ -164,4 +166,5 @@ public abstract class Database {
* @throws SQLException
*/
public abstract int getUserId(String uuid) throws SQLException;
public abstract List<Location> getLocations(String userId, HashMap<String, World> worlds) throws SQLException;
}

View File

@ -714,7 +714,8 @@ public abstract class SQLDB extends Database {
return nicknames;
}
private List<Location> getLocations(String userId, HashMap<String, World> worlds) throws SQLException {
@Override
public List<Location> getLocations(String userId, HashMap<String, World> worlds) throws SQLException {
PreparedStatement statement;
ResultSet set;
statement = connection.prepareStatement("SELECT * FROM " + locationName + " WHERE UPPER(" + locationColumnUserID + ") LIKE UPPER(?)");
@ -965,11 +966,11 @@ public abstract class SQLDB extends Database {
* @throws SQLException
*/
public void saveAdditionalLocationsList(int userId, List<Location> locations) throws SQLException {
List<Location> newLocations = new ArrayList<>();
newLocations.addAll(locations);
if (newLocations.isEmpty()) {
if (locations == null || locations.isEmpty()) {
return;
}
List<Location> newLocations = new ArrayList<>();
newLocations.addAll(locations);
PreparedStatement saveStatement = connection.prepareStatement("INSERT INTO " + locationName + " ("
+ locationColumnUserID + ", "
+ locationColumnCoordinatesX + ", "
@ -979,6 +980,9 @@ public abstract class SQLDB extends Database {
boolean commitRequired = false;
if (!newLocations.isEmpty()) {
for (Location location : newLocations) {
if (location == null) {
continue;
}
saveStatement.setInt(1, userId);
saveStatement.setInt(2, (int) location.getBlockX());
saveStatement.setInt(3, (int) location.getBlockZ());
@ -1006,7 +1010,7 @@ public abstract class SQLDB extends Database {
* @throws SQLException
*/
public void saveNickList(int userId, HashSet<String> names, String lastNick) throws SQLException {
if (names.isEmpty()) {
if (names == null || names.isEmpty()) {
return;
}
PreparedStatement statement = connection.prepareStatement(
@ -1056,9 +1060,14 @@ public abstract class SQLDB extends Database {
+ ") VALUES (?, ?, ?)");
boolean commitRequired = false;
for (SessionData session : sessions) {
long end = session.getSessionEnd();
long start = session.getSessionStart();
if (end < start) {
continue;
}
statement.setInt(1, userId);
statement.setLong(2, session.getSessionStart());
statement.setLong(3, session.getSessionEnd());
statement.setLong(2, start);
statement.setLong(3, end);
statement.addBatch();
commitRequired = true;
}
@ -1076,7 +1085,7 @@ public abstract class SQLDB extends Database {
* @throws SQLException
*/
public void savePlayerKills(int userId, List<KillData> kills) throws SQLException {
if (kills.isEmpty()) {
if (kills == null || kills.isEmpty()) {
return;
}
PreparedStatement statement = connection.prepareStatement(
@ -1092,6 +1101,9 @@ public abstract class SQLDB extends Database {
+ ") VALUES (?, ?, ?, ?)");
boolean commitRequired = false;
for (KillData kill : kills) {
if (kill == null) {
continue;
}
statement.setInt(1, userId);
statement.setInt(2, kill.getVictimUserID());
statement.setString(3, kill.getWeapon());
@ -1101,7 +1113,6 @@ public abstract class SQLDB extends Database {
}
if (commitRequired) {
statement.executeBatch();
}
statement.close();
}
@ -1113,7 +1124,7 @@ public abstract class SQLDB extends Database {
* @throws SQLException
*/
public void saveIPList(int userId, HashSet<InetAddress> ips) throws SQLException {
if (ips.isEmpty()) {
if (ips == null || ips.isEmpty()) {
return;
}
PreparedStatement statement = connection.prepareStatement(
@ -1128,6 +1139,9 @@ public abstract class SQLDB extends Database {
+ ") VALUES (?, ?)");
boolean commitRequired = false;
for (InetAddress ip : ips) {
if (ip == null) {
continue;
}
statement.setInt(1, userId);
statement.setString(2, ip.getHostAddress());
statement.addBatch();
@ -1147,7 +1161,7 @@ public abstract class SQLDB extends Database {
* @throws SQLException
*/
public void saveGMTimes(int userId, HashMap<GameMode, Long> gamemodeTimes) throws SQLException {
if (gamemodeTimes.isEmpty()) {
if (gamemodeTimes == null || gamemodeTimes.isEmpty()) {
return;
}
PreparedStatement statement = connection.prepareStatement(

View File

@ -103,7 +103,7 @@ public enum Html {
public String parse(String... p) {
String returnValue = this.html;
for (int i = 0; i < p.length; i++) {
returnValue = returnValue.replaceAll("REPLACE" + i, p[i]);
returnValue = returnValue.replace("REPLACE" + i, p[i]);
}
return returnValue;
}

View File

@ -33,7 +33,7 @@ public class SortableCommandUseTableCreator {
} catch (IllegalArgumentException e) {
Plan plugin = getPlugin(Plan.class);
plugin.toLog("SortableCommandUseTableCreator", e);
plugin.toLog("Cause: "+values[1]+" "+values[2]);
plugin.toLog("Cause: "+values[0]+" "+values[1]);
}
}
return html;

View File

@ -82,9 +82,9 @@ public class HtmlUtils {
}
public static String removeXSS(String string) {
return string.replaceAll("<!--", "")
.replaceAll("-->", "")
.replaceAll("<script>", "")
.replaceAll("</script>", "");
return string.replace("<!--", "")
.replace("-->", "")
.replace("<script>", "")
.replace("</script>", "");
}
}