[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) { public String parse(String... p) {
String returnValue = this.toString(); String returnValue = this.toString();
for (int i = 0; i < p.length; i++) { for (int i = 0; i < p.length; i++) {
returnValue = returnValue.replaceAll("REPLACE" + i, p[i]); returnValue = returnValue.replace("REPLACE" + i, p[i]);
} }
return returnValue; return returnValue;
} }

View File

@ -130,6 +130,7 @@ public class UserData {
/** /**
* Creates a new UserData object with copied values. * Creates a new UserData object with copied values.
*
* @param data UserData to copy into the new object. * @param data UserData to copy into the new object.
*/ */
public UserData(UserData data) { public UserData(UserData data) {
@ -210,11 +211,13 @@ public class UserData {
*/ */
public boolean addNickname(String nick) { public boolean addNickname(String nick) {
if (!nicknames.contains(nick)) { if (!nicknames.contains(nick)) {
if (nick != null) {
if (!nick.isEmpty()) { if (!nick.isEmpty()) {
nicknames.add(nick); nicknames.add(nick);
return true; return true;
} }
} }
}
return false; return false;
} }
@ -313,12 +316,10 @@ public class UserData {
} }
// Getters ------------------------------------------------------------- // Getters -------------------------------------------------------------
/** /**
* *
* @return * @return
*/ */
public UUID getUuid() { public UUID getUuid() {
return uuid; return uuid;
} }
@ -452,7 +453,6 @@ public class UserData {
} }
// Setters ------------------------------------------------------------- // Setters -------------------------------------------------------------
/** /**
* *
* @param uuid * @param uuid
@ -735,5 +735,4 @@ public class UserData {
return true; return true;
} }
} }

View File

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

View File

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

View File

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

View File

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