This commit is contained in:
Fuzzlemann 2017-07-27 12:23:27 +02:00
commit 1e1180280b
22 changed files with 1551 additions and 986 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.destroystokyo.paper:paper:1.12-R0.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/destroystokyo/paper/paper/1.12-R0.1-SNAPSHOT/paper-1.12-R0.1-20170725.202533-1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/destroystokyo/paper/paper/1.12-R0.1-SNAPSHOT/paper-1.12-R0.1-20170725.202533-1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/destroystokyo/paper/paper/1.12-R0.1-SNAPSHOT/paper-1.12-R0.1-20170725.202533-1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="Maven: com.destroystokyo.paper:paper-spigot:1.12">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/destroystokyo/paper/paper-spigot/1.12/paper-spigot-1.12.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/destroystokyo/paper/paper-spigot/1.12/paper-spigot-1.12-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/Downloads/PaperSpigot-latest.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/destroystokyo/paper/paper-spigot/1.12/paper-spigot-1.12-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.djrapitops:abstract-plugin-framework:2.0.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/djrapitops/abstract-plugin-framework/2.0.0/abstract-plugin-framework-2.0.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/djrapitops/abstract-plugin-framework/2.0.0/abstract-plugin-framework-2.0.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/djrapitops/abstract-plugin-framework/2.0.0/abstract-plugin-framework-2.0.0-sources.jar!/" />
</SOURCES>
</library>
</component>

124
Plan/.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>com.djrapitops</groupId> <groupId>com.djrapitops</groupId>
<artifactId>abstract-plugin-framework</artifactId> <artifactId>abstract-plugin-framework</artifactId>
<version>2.0.0</version> <version>2.0.1</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- SoftDepended Plugins--> <!-- SoftDepended Plugins-->

View File

@ -125,7 +125,7 @@ public class AnalyzeCommand extends SubCommand {
sender.sendMessage(message + url); sender.sendMessage(message + url);
} else { } else {
sender.sendMessage(message); sender.sendMessage(message);
sendLink(sender, url); sender.sendLink(" ", Phrase.CMD_CLICK_ME.toString(), url);
} }
} }
sender.sendMessage(Phrase.CMD_FOOTER.toString()); sender.sendMessage(Phrase.CMD_FOOTER.toString());

View File

@ -129,7 +129,7 @@ public class InspectCommand extends SubCommand {
sender.sendMessage(message + url); sender.sendMessage(message + url);
} else { } else {
sender.sendMessage(message); sender.sendMessage(message);
sendLink(sender, url); sender.sendLink(" ", Phrase.CMD_CLICK_ME.toString(), url);
} }
} }

View File

@ -56,7 +56,7 @@ public class ListCommand extends SubCommand {
sender.sendMessage(message + url); sender.sendMessage(message + url);
} else { } else {
sender.sendMessage(message); sender.sendMessage(message);
sendLink(sender, url); sender.sendLink(" ", Phrase.CMD_CLICK_ME.toString(), url);
} }
sender.sendMessage(Phrase.CMD_FOOTER + ""); sender.sendMessage(Phrase.CMD_FOOTER + "");
} }

View File

@ -3,6 +3,7 @@ package main.java.com.djrapitops.plan.data.analysis;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.data.KillData; import main.java.com.djrapitops.plan.data.KillData;
import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -16,14 +17,14 @@ import java.util.UUID;
* <p> * <p>
* Placeholder values can be retrieved using the get method. * Placeholder values can be retrieved using the get method.
* <p> * <p>
* Contains following place-holders: deaths, mobkills, playerkilss * Contains following place-holders: deaths, mobkills, playerkills, avgdeaths, avgmobkills, avgplayerkills
* *
* @author Rsl1122 * @author Rsl1122
* @since 3.5.2 * @since 3.5.2
*/ */
public class KillPart extends RawData<KillPart> { public class KillPart extends RawData<KillPart> {
private final PlayerCountPart playerCount; // TODO Averages private final PlayerCountPart playerCount;
private final Map<UUID, List<KillData>> playerKills; private final Map<UUID, List<KillData>> playerKills;
private long mobKills; private long mobKills;
private long deaths; private long deaths;
@ -39,7 +40,12 @@ public class KillPart extends RawData<KillPart> {
public void analyse() { public void analyse() {
addValue("deaths", deaths); addValue("deaths", deaths);
addValue("mobkills", mobKills); addValue("mobkills", mobKills);
addValue("playerkills", getAllPlayerKills().size()); int playerKillAmount = getAllPlayerKills().size();
addValue("playerkills", playerKillAmount);
int playerCount = this.playerCount.getPlayerCount();
addValue("avgdeaths", MathUtils.averageLong(deaths, playerCount));
addValue("avgmobkills", MathUtils.averageLong(mobKills, playerCount));
addValue("avgplayerkills", MathUtils.averageLong(playerKillAmount, playerCount));
} }
public void addKills(UUID uuid, List<KillData> kills) throws IllegalArgumentException { public void addKills(UUID uuid, List<KillData> kills) throws IllegalArgumentException {

View File

@ -220,8 +220,6 @@ public class DataCacheHandler extends SessionCache {
/** /**
* Saves all UserData in the cache to Database. * Saves all UserData in the cache to Database.
* <p> * <p>
* ATTENTION: TODO - Doesn't save the Locations in the locationCache.
* <p>
* Should only be called from Async thread * Should only be called from Async thread
*/ */
public void saveCachedUserData() { public void saveCachedUserData() {

View File

@ -78,8 +78,27 @@ public abstract class Database {
*/ */
protected VersionTable versionTable; protected VersionTable versionTable;
/**
* Table representing plan_security in the database.
*
* @since 3.5.2
*/
protected SecurityTable securityTable; protected SecurityTable securityTable;
/**
* Table representing plan_worlds in the database.
*
* @since 3.6.0
*/
protected WorldTable worldTable;
/**
* Table representing plan_world_times in the database.
*
* @since 3.6.0
*/
protected WorldTimesTable worldTimesTable;
/** /**
* Super constructor. * Super constructor.
* *
@ -343,7 +362,30 @@ public abstract class Database {
return tpsTable; return tpsTable;
} }
/**
* Used to get the security table.
*
* @return Table representing plan_security
*/
public SecurityTable getSecurityTable() { public SecurityTable getSecurityTable() {
return securityTable; return securityTable;
} }
/**
* Used to get the worlds table.
*
* @return Table representing plan_worlds
*/
public WorldTable getWorldTable() {
return worldTable;
}
/**
* Used to get the world times table.
*
* @return Table representing plan_world_times
*/
public WorldTimesTable getWorldTimesTable() {
return worldTimesTable;
}
} }

View File

@ -48,6 +48,8 @@ public abstract class SQLDB extends Database {
versionTable = new VersionTable(this, usingMySQL); versionTable = new VersionTable(this, usingMySQL);
tpsTable = new TPSTable(this, usingMySQL); tpsTable = new TPSTable(this, usingMySQL);
securityTable = new SecurityTable(this, usingMySQL); securityTable = new SecurityTable(this, usingMySQL);
worldTable = new WorldTable(this, usingMySQL);
worldTimesTable = new WorldTimesTable(this, usingMySQL);
startConnectionPingTask(); startConnectionPingTask();
} }
@ -118,7 +120,7 @@ public abstract class SQLDB extends Database {
} }
if (newDatabase) { if (newDatabase) {
Log.info("New Database created."); Log.info("New Database created.");
setVersion(6); setVersion(7);
} }
Benchmark.start("Database: Create tables"); Benchmark.start("Database: Create tables");
for (Table table : getAllTables()) { for (Table table : getAllTables()) {
@ -132,8 +134,8 @@ public abstract class SQLDB extends Database {
return false; return false;
} }
Benchmark.stop("Database: Create tables"); Benchmark.stop("Database: Create tables");
if (!newDatabase && getVersion() < 6) { if (!newDatabase && getVersion() < 7) {
setVersion(6); setVersion(7);
} }
} }
return true; return true;
@ -177,14 +179,22 @@ public abstract class SQLDB extends Database {
* @return * @return
*/ */
public Table[] getAllTables() { public Table[] getAllTables() {
return new Table[]{usersTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, commandUseTable, tpsTable}; return new Table[]{
usersTable, gmTimesTable, ipsTable,
nicknamesTable, sessionsTable, killsTable,
commandUseTable, tpsTable, worldTable,
worldTimesTable};
} }
/** /**
* @return * @return
*/ */
public Table[] getAllTablesInRemoveOrder() { public Table[] getAllTablesInRemoveOrder() {
return new Table[]{locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, usersTable, commandUseTable, tpsTable}; return new Table[]{
locationsTable, gmTimesTable, ipsTable,
nicknamesTable, sessionsTable, killsTable,
worldTimesTable, worldTable, usersTable,
commandUseTable, tpsTable};
} }
/** /**

View File

@ -26,6 +26,9 @@ public class TPSTable extends Table {
private final String columnTPS; private final String columnTPS;
private final String columnPlayers; private final String columnPlayers;
private final String columnCPUUsage; private final String columnCPUUsage;
private final String columnRAMUsage;
private final String columnEntities;
private final String columnChunksLoaded;
/** /**
* @param db * @param db
@ -37,7 +40,9 @@ public class TPSTable extends Table {
columnTPS = "tps"; columnTPS = "tps";
columnPlayers = "players_online"; columnPlayers = "players_online";
columnCPUUsage = "cpu_usage"; columnCPUUsage = "cpu_usage";
//TODO add new columns columnRAMUsage = "ram_usage";
columnEntities = "entities";
columnChunksLoaded = "chunks_loaded";
} }
@Override @Override
@ -47,14 +52,19 @@ public class TPSTable extends Table {
+ columnDate + " bigint NOT NULL, " + columnDate + " bigint NOT NULL, "
+ columnTPS + " double NOT NULL, " + columnTPS + " double NOT NULL, "
+ columnPlayers + " integer NOT NULL, " + columnPlayers + " integer NOT NULL, "
+ columnCPUUsage + " double NOT NULL" + columnCPUUsage + " double NOT NULL, "
+ columnRAMUsage + " bigint NOT NULL, "
+ columnEntities + " integer NOT NULL, "
+ columnChunksLoaded + " integer NOT NULL"
+ ")" + ")"
//TODO add new columns
); );
int version = getVersion(); int version = getVersion();
if (version < 6) { if (version < 6) {
alterTablesV6(); alterTablesV6();
} }
if (version < 7) {
alterTablesV7();
}
return true; return true;
} catch (SQLException ex) { } catch (SQLException ex) {
Log.toLog(this.getClass().getName(), ex); Log.toLog(this.getClass().getName(), ex);
@ -70,11 +80,26 @@ public class TPSTable extends Table {
execute("ALTER TABLE " + tableName + " ADD COLUMN " + columnCPUUsage + " double NOT NULL DEFAULT 0"); execute("ALTER TABLE " + tableName + " ADD COLUMN " + columnCPUUsage + " double NOT NULL DEFAULT 0");
} }
} catch (SQLException e) { } catch (SQLException e) {
} }
} }
//TODO alterTablesV7 private void alterTablesV7() {
String[] sql;
if (usingMySQL) {
sql = new String[]{
"ALTER TABLE " + tableName + " ADD " + columnRAMUsage + " bigint NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD " + columnEntities + " integer NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD " + columnChunksLoaded + " integer NOT NULL DEFAULT 0"
};
} else {
sql = new String[]{
"ALTER TABLE " + tableName + " ADD COLUMN " + columnRAMUsage + " bigint NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD COLUMN " + columnEntities + " integer NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD COLUMN " + columnChunksLoaded + " integer NOT NULL DEFAULT 0"
};
}
executeUnsafe(sql);
}
/** /**
* @return @throws SQLException * @return @throws SQLException
@ -92,8 +117,10 @@ public class TPSTable extends Table {
double tps = set.getDouble(columnTPS); double tps = set.getDouble(columnTPS);
int players = set.getInt(columnPlayers); int players = set.getInt(columnPlayers);
double cpuUsage = set.getDouble(columnCPUUsage); double cpuUsage = set.getDouble(columnCPUUsage);
//TODO add new data long ramUsage = set.getLong(columnRAMUsage);
data.add(new TPS(date, tps, players, cpuUsage, 0, 0, 0)); int entities = set.getInt(columnEntities);
int chunksLoaded = set.getInt(columnChunksLoaded);
data.add(new TPS(date, tps, players, cpuUsage, ramUsage, entities, chunksLoaded));
} }
return data; return data;
} finally { } finally {
@ -121,8 +148,11 @@ public class TPSTable extends Table {
+ columnDate + ", " + columnDate + ", "
+ columnTPS + ", " + columnTPS + ", "
+ columnPlayers + ", " + columnPlayers + ", "
+ columnCPUUsage + columnCPUUsage + ", "
+ ") VALUES (?, ?, ?, ?)"); + columnRAMUsage + ", "
+ columnEntities + ", "
+ columnChunksLoaded
+ ") VALUES (?, ?, ?, ?, ?, ?, ?)");
boolean commitRequired = false; boolean commitRequired = false;
int i = 0; int i = 0;
@ -131,6 +161,9 @@ public class TPSTable extends Table {
statement.setDouble(2, tps.getTps()); statement.setDouble(2, tps.getTps());
statement.setInt(3, tps.getPlayers()); statement.setInt(3, tps.getPlayers());
statement.setDouble(4, tps.getCPUUsage()); statement.setDouble(4, tps.getCPUUsage());
statement.setLong(5, tps.getUsedMemory());
statement.setDouble(6, tps.getEntityCount());
statement.setDouble(7, tps.getChunksLoaded());
statement.addBatch(); statement.addBatch();
commitRequired = true; commitRequired = true;
i++; i++;

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.Container; import main.java.com.djrapitops.plan.database.Container;
import main.java.com.djrapitops.plan.database.DBUtils; import main.java.com.djrapitops.plan.database.DBUtils;
@ -67,13 +68,28 @@ public abstract class Table {
} }
/** /**
* @param sql * @param statement
* @return * @return
* @throws SQLException * @throws SQLException
*/ */
protected boolean execute(String sql) throws SQLException { protected boolean execute(String statement) throws SQLException {
Connection connection = getConnection(); Connection connection = getConnection();
return connection.createStatement().execute(sql); return connection.createStatement().execute(statement);
}
/**
* Used to execute queries while possible SQLExceptions are suppressed.
*
* @param statements SQL statements to execute
*/
protected void executeUnsafe(String... statements) {
Verify.nullCheck(statements);
for (String statement : statements) {
try {
execute(statement);
} catch (SQLException e) {
}
}
} }
/** /**

View File

@ -123,9 +123,9 @@ public class UsersTable extends Table {
} }
private void alterTablesV4() { private void alterTablesV4() {
String[] queries; String[] statements;
if (usingMySQL) { if (usingMySQL) {
queries = new String[]{ statements = new String[]{
"ALTER TABLE " + tableName + " ADD " + columnContainsBukkitData + " boolean NOT NULL DEFAULT 0", "ALTER TABLE " + tableName + " ADD " + columnContainsBukkitData + " boolean NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD " + columnOP + " boolean NOT NULL DEFAULT 0", "ALTER TABLE " + tableName + " ADD " + columnOP + " boolean NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD " + columnBanned + " boolean NOT NULL DEFAULT 0", "ALTER TABLE " + tableName + " ADD " + columnBanned + " boolean NOT NULL DEFAULT 0",
@ -133,7 +133,7 @@ public class UsersTable extends Table {
"ALTER TABLE " + tableName + " ADD " + columnRegistered + " bigint NOT NULL DEFAULT 0" "ALTER TABLE " + tableName + " ADD " + columnRegistered + " bigint NOT NULL DEFAULT 0"
}; };
} else { } else {
queries = new String[]{ statements = new String[]{
"ALTER TABLE " + tableName + " ADD COLUMN " + columnContainsBukkitData + " boolean NOT NULL DEFAULT 0", "ALTER TABLE " + tableName + " ADD COLUMN " + columnContainsBukkitData + " boolean NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD COLUMN " + columnOP + " boolean NOT NULL DEFAULT 0", "ALTER TABLE " + tableName + " ADD COLUMN " + columnOP + " boolean NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD COLUMN " + columnBanned + " boolean NOT NULL DEFAULT 0", "ALTER TABLE " + tableName + " ADD COLUMN " + columnBanned + " boolean NOT NULL DEFAULT 0",
@ -141,34 +141,24 @@ public class UsersTable extends Table {
"ALTER TABLE " + tableName + " ADD COLUMN " + columnRegistered + " bigint NOT NULL DEFAULT 0" "ALTER TABLE " + tableName + " ADD COLUMN " + columnRegistered + " bigint NOT NULL DEFAULT 0"
}; };
} }
for (String query : queries) { executeUnsafe(statements);
try {
execute(query);
} catch (Exception e) {
}
}
} }
private void alterTablesV3() { private void alterTablesV3() {
String[] queries; String[] statements;
if (usingMySQL) { if (usingMySQL) {
queries = new String[]{ statements = new String[]{
"ALTER TABLE " + tableName + " ADD " + columnDeaths + " integer NOT NULL DEFAULT 0", "ALTER TABLE " + tableName + " ADD " + columnDeaths + " integer NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD " + columnMobKills + " integer NOT NULL DEFAULT 0", "ALTER TABLE " + tableName + " ADD " + columnMobKills + " integer NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " DROP INDEX " + columnPlayerKills "ALTER TABLE " + tableName + " DROP INDEX " + columnPlayerKills
}; };
} else { } else {
queries = new String[]{ statements = new String[]{
"ALTER TABLE " + tableName + " ADD COLUMN " + columnDeaths + " integer NOT NULL DEFAULT 0", "ALTER TABLE " + tableName + " ADD COLUMN " + columnDeaths + " integer NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD COLUMN " + columnMobKills + " integer NOT NULL DEFAULT 0" "ALTER TABLE " + tableName + " ADD COLUMN " + columnMobKills + " integer NOT NULL DEFAULT 0"
}; };
} }
for (String query : queries) { executeUnsafe(statements);
try {
execute(query);
} catch (Exception e) {
}
}
} }
/** /**
@ -870,12 +860,4 @@ public class UsersTable extends Table {
close(statement); close(statement);
} }
} }
/**
* @param uuids
* @return
*/
public Map<Integer, Long> getLoginTimes(Collection<UUID> uuids) {
throw new UnsupportedOperationException("Not supported yet."); // TODO
}
} }

View File

@ -0,0 +1,116 @@
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.database.databases.SQLDB;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* Table class representing database table plan_worlds.
* <p>
* Used for storing id references to world names.
*
* @author Rsl1122
* @since 3.6.0 / Database version 7
*/
public class WorldTable extends Table {
private final String columnWorldId;
private final String columnWorldName;
/**
* Constructor.
*
* @param db Database this table is a part of.
* @param usingMySQL Database is a MySQL database.
*/
public WorldTable(SQLDB db, boolean usingMySQL) {
super("plan_worlds", db, usingMySQL);
columnWorldId = "world_id";
columnWorldName = "world_name";
}
@Override
public boolean createTable() {
try {
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ columnWorldId + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", "
+ columnWorldName + " varchar(100) NOT NULL"
+ (usingMySQL ? ", PRIMARY KEY (" + columnWorldId + ")" : "")
+ ")"
);
return true;
} catch (SQLException ex) {
Log.toLog(this.getClass().getName(), ex);
return false;
}
}
/**
* Used to get the available world names.
*
* @return List of all world names in the database.
* @throws SQLException Database error occurs.
*/
public List<String> getWorlds() throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try {
statement = prepareStatement("SELECT * FROM " + tableName);
set = statement.executeQuery();
List<String> worldNames = new ArrayList<>();
while (set.next()) {
String worldName = set.getString(columnWorldName);
worldNames.add(worldName);
}
return worldNames;
} finally {
close(set, statement);
}
}
/**
* Used to save a list of world names.
* <p>
* Already saved names will not be saved.
*
* @param worlds List of world names.
* @throws SQLException Database error occurs.
*/
public void saveWorlds(List<String> worlds) throws SQLException {
Verify.nullCheck(worlds);
List<String> saved = getWorlds();
worlds.removeAll(saved);
if (Verify.isEmpty(worlds)) {
return;
}
PreparedStatement statement = null;
try {
statement = prepareStatement("INSERT INTO " + tableName + " ("
+ columnWorldName
+ ") VALUES (?)");
boolean commitRequired = false;
for (String world : worlds) {
statement.setString(1, world);
statement.addBatch();
commitRequired = true;
}
if (commitRequired) {
statement.executeBatch();
}
} finally {
close(statement);
}
}
public String getColumnID() {
return columnWorldId;
}
}

View File

@ -0,0 +1,54 @@
package main.java.com.djrapitops.plan.database.tables;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.database.databases.SQLDB;
import java.sql.SQLException;
/**
* Table class representing database table plan_world_times.
*
* @author Rsl1122
* @since 3.6.0 / Database version 7
*/
public class WorldTimesTable extends Table {
private final WorldTable worldTable;
private final String columnWorldId;
private final String columnUserId;
private final String columnPlaytime;
/**
* Constructor.
*
* @param db Database this table is a part of.
* @param usingMySQL Database is a MySQL database.
*/
public WorldTimesTable(SQLDB db, boolean usingMySQL) {
super("plan_world_times", db, usingMySQL);
worldTable = db.getWorldTable();
columnWorldId = "world_id";
columnUserId = "user_id";
columnPlaytime = "playtime";
}
@Override
public boolean createTable() {
UsersTable usersTable = db.getUsersTable();
try {
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ columnUserId + " integer NOT NULL, "
+ columnWorldId + " integer NOT NULL, "
+ columnPlaytime + " bigint NOT NULL, "
+ "FOREIGN KEY(" + columnUserId + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + "), "
+ "FOREIGN KEY(" + columnWorldId + ") REFERENCES " + worldTable.getTableName() + "(" + worldTable.getColumnID() + ")"
+ ")"
);
return true;
} catch (SQLException ex) {
Log.toLog(this.getClass().getName(), ex);
return false;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
<changelist name="Fix__198" date="1501136598251" recycled="false">
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Fix__198/shelved.patch" />
<option name="DESCRIPTION" value="Fix #198" />
</changelist>

View File

@ -1,15 +1,15 @@
package com.djrapitops.pluginbridge.plan.griefprevention; package com.djrapitops.pluginbridge.plan.griefprevention;
import java.io.Serializable;
import java.util.UUID;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.data.additional.AnalysisType; import main.java.com.djrapitops.plan.data.additional.AnalysisType;
import main.java.com.djrapitops.plan.data.additional.PluginData; import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore; import me.ryanhamshire.GriefPrevention.DataStore;
import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;
/** /**
* PluginData class for GriefPrevention-plugin. * PluginData class for GriefPrevention-plugin.
* *
@ -37,6 +37,7 @@ public class GriefPreventionClaimArea extends PluginData {
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
Verify.nullCheck(uuid); Verify.nullCheck(uuid);
int area = dataStore.getClaims().stream() int area = dataStore.getClaims().stream()
.filter(Objects::nonNull)
.filter(claim -> uuid.equals(claim.ownerID)) .filter(claim -> uuid.equals(claim.ownerID))
.map(Claim::getArea).mapToInt(i -> i).sum(); .map(Claim::getArea).mapToInt(i -> i).sum();
return parseContainer(modifierPrefix, area + ""); return parseContainer(modifierPrefix, area + "");
@ -46,6 +47,7 @@ public class GriefPreventionClaimArea extends PluginData {
public Serializable getValue(UUID uuid) { public Serializable getValue(UUID uuid) {
Verify.nullCheck(uuid); Verify.nullCheck(uuid);
return dataStore.getClaims().stream() return dataStore.getClaims().stream()
.filter(Objects::nonNull)
.filter(claim -> uuid.equals(claim.ownerID)) .filter(claim -> uuid.equals(claim.ownerID))
.map(Claim::getArea).mapToInt(i -> i).sum(); .map(Claim::getArea).mapToInt(i -> i).sum();
} }

View File

@ -1,13 +1,15 @@
package com.djrapitops.pluginbridge.plan.griefprevention; package com.djrapitops.pluginbridge.plan.griefprevention;
import java.io.Serializable;
import java.util.UUID;
import com.djrapitops.plugin.utilities.FormattingUtils; import com.djrapitops.plugin.utilities.FormattingUtils;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.data.additional.PluginData; import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.ui.html.Html; import main.java.com.djrapitops.plan.ui.html.Html;
import me.ryanhamshire.GriefPrevention.DataStore; import me.ryanhamshire.GriefPrevention.DataStore;
import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;
/** /**
* PluginData class for GriefPrevention-plugin. * PluginData class for GriefPrevention-plugin.
* *
@ -43,9 +45,12 @@ public class GriefPreventionClaimTable extends PluginData {
} }
private String getTableLines(UUID uuid) { private String getTableLines(UUID uuid) {
Verify.nullCheck(uuid);
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder();
dataStore.getClaims().stream() dataStore.getClaims().stream()
.filter(claim -> claim.ownerID.equals(uuid)) .filter(Objects::nonNull)
.filter(claim -> uuid.equals(claim.ownerID))
.forEach(claim -> { .forEach(claim -> {
String location = FormattingUtils.formatLocation(claim.getGreaterBoundaryCorner()); String location = FormattingUtils.formatLocation(claim.getGreaterBoundaryCorner());
String area = claim.getArea() + ""; String area = claim.getArea() + "";

View File

@ -1,16 +1,17 @@
package com.djrapitops.pluginbridge.plan.griefprevention; package com.djrapitops.pluginbridge.plan.griefprevention;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.data.additional.AnalysisType; import main.java.com.djrapitops.plan.data.additional.AnalysisType;
import main.java.com.djrapitops.plan.data.additional.PluginData; import main.java.com.djrapitops.plan.data.additional.PluginData;
import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore; import me.ryanhamshire.GriefPrevention.DataStore;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
/** /**
* PluginData class for GriefPrevention-plugin. * PluginData class for GriefPrevention-plugin.
* *
@ -38,6 +39,7 @@ public class GriefPreventionClaims extends PluginData {
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
Verify.nullCheck(uuid); Verify.nullCheck(uuid);
List<Claim> claims = dataStore.getClaims().stream() List<Claim> claims = dataStore.getClaims().stream()
.filter(Objects::nonNull)
.filter(claim -> uuid.equals(claim.ownerID)) .filter(claim -> uuid.equals(claim.ownerID))
.collect(Collectors.toList()); .collect(Collectors.toList());
return parseContainer(modifierPrefix, claims.size()+""); return parseContainer(modifierPrefix, claims.size()+"");
@ -47,6 +49,7 @@ public class GriefPreventionClaims extends PluginData {
public Serializable getValue(UUID uuid) { public Serializable getValue(UUID uuid) {
Verify.nullCheck(uuid); Verify.nullCheck(uuid);
return dataStore.getClaims().stream() return dataStore.getClaims().stream()
.filter(Objects::nonNull)
.filter(claim -> uuid.equals(claim.ownerID)) .filter(claim -> uuid.equals(claim.ownerID))
.collect(Collectors.toList()).size(); .collect(Collectors.toList()).size();
} }