Rsl1122 2017-01-28 15:01:06 +02:00
parent 96240195ef
commit c71e014096
8 changed files with 61 additions and 36 deletions

View File

@ -20,7 +20,7 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitRunnable;
/* TODO 2.1.0
/* TODO 2.2.0
Placeholder API
Immutable InspectCache ?
Recent players 25%
@ -69,6 +69,7 @@ public class Plan extends JavaPlugin {
saveConfig();
log(MiscUtils.checkVersion());
log("Database init..");
if (initDatabase()) {
log("Database initiated.");
@ -84,8 +85,6 @@ public class Plan extends JavaPlugin {
this.analysisCache = new AnalysisCacheHandler(this);
registerListeners();
log(MiscUtils.checkVersion());
getCommand("plan").setExecutor(new PlanCommand(this));
this.api = new API(this);
@ -177,7 +176,9 @@ public class Plan extends JavaPlugin {
pluginManager.registerEvents(new PlanPlayerListener(this), this);
pluginManager.registerEvents(new PlanGamemodeChangeListener(this), this);
pluginManager.registerEvents(new PlanCommandPreprocessListener(this), this);
pluginManager.registerEvents(new PlanPlayerMoveListener(this), this);
if (getConfig().getBoolean("Settings.Data.GatherLocations")) {
pluginManager.registerEvents(new PlanPlayerMoveListener(this), this);
}
}
private boolean initDatabase() {

View File

@ -115,11 +115,13 @@ public class DataCacheHandler {
if (cache) {
if (dataCache.get(uuid) == null) {
UserData uData = db.getUserData(uuid);
if (uData.getPlanLiteData() == null) {
getPlanLiteHandler().handleEvents(uData.getName(), uData);
if (uData != null) {
if (uData.getPlanLiteData() == null) {
getPlanLiteHandler().handleEvents(uData.getName(), uData);
}
dataCache.put(uuid, uData);
plugin.log("Added " + uuid.toString() + " to Cache.");
}
dataCache.put(uuid, uData);
plugin.log("Added " + uuid.toString() + " to Cache.");
}
return dataCache.get(uuid);
} else {
@ -127,8 +129,10 @@ public class DataCacheHandler {
return dataCache.get(uuid);
}
UserData uData = db.getUserData(uuid);
if (uData.getPlanLiteData() == null) {
getPlanLiteHandler().handleEvents(uData.getName(), uData);
if (uData != null) {
if (uData.getPlanLiteData() == null) {
getPlanLiteHandler().handleEvents(uData.getName(), uData);
}
}
return uData;
}

View File

@ -154,14 +154,13 @@ public abstract class SQLDB extends Database {
if (connection == null || connection.isClosed()) {
return false;
}
// ResultSet set = connection.prepareStatement(supportsModification ? ("SHOW TABLES LIKE '" + userName + "'") : "SELECT name FROM sqlite_master WHERE type='table' AND name='" + userName + "'").executeQuery();
// boolean newDatabase = set.next();
// set.close();
boolean usingMySQL = getConfigName().toLowerCase().equals("mysql");
System.out.println(usingMySQL ? "Using MySQL":"Not using MySQL"+getConfigName());
// ResultSet set = connection.prepareStatement(supportsModification ? ("SHOW TABLES LIKE '" + userName + "'") : "SELECT name FROM sqlite_master WHERE type='table' AND name='" + userName + "'").executeQuery();
// boolean newDatabase = set.next();
// set.close();
query("CREATE TABLE IF NOT EXISTS " + userName + " ("
+ userColumnID + " integer PRIMARY KEY, "
+ userColumnID + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", "
+ userColumnUUID + " varchar(36) NOT NULL, "
+ userColumnDemAge + " integer NOT NULL, "
+ userColumnDemGender + " varchar(8) NOT NULL, "
@ -171,15 +170,17 @@ public abstract class SQLDB extends Database {
+ userColumnPlayTime + " bigint NOT NULL, "
+ userColumnLoginTimes + " integer NOT NULL, "
+ userColumnLastPlayed + " bigint NOT NULL"
+ (usingMySQL ? ", PRIMARY KEY (" + userColumnID + ")" : "")
+ ")"
);
query("CREATE TABLE IF NOT EXISTS " + locationName + " ("
+ locationColumnID + " integer PRIMARY KEY, "
+ locationColumnID + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", "
+ locationColumnUserID + " integer NOT NULL, "
+ locationColumnCoordinatesX + " integer NOT NULL, "
+ locationColumnCoordinatesZ + " integer NOT NULL, "
+ locationColumnWorld + " varchar(64) NOT NULL, "
+ (usingMySQL ? "PRIMARY KEY (" + userColumnID + "), " : "")
+ "FOREIGN KEY(" + locationColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
+ ")"
);
@ -390,13 +391,17 @@ public abstract class SQLDB extends Database {
+ commanduseColumnCommand + ", "
+ commanduseColumnTimesUsed
+ ") VALUES (?, ?)");
boolean commitRequired = false;
for (String key : data.keySet()) {
statement.setString(1, key);
statement.setInt(2, data.get(key));
statement.addBatch();
commitRequired = true;
}
statement.executeBatch();
connection.commit();
if (commitRequired) {
connection.commit();
}
statement.close();
connection.setAutoCommit(true);
@ -582,13 +587,14 @@ public abstract class SQLDB extends Database {
try {
connection.setAutoCommit(false);
PreparedStatement uStatement = connection.prepareStatement(uSQL);
boolean commitRequired = false;
for (UserData uData : data) {
int userId = getUserId(uData.getUuid().toString());
if (userId == -1) {
saveLast.add(uData);
continue;
}
uStatement.setInt(1, uData.getDemData().getAge());
uStatement.setString(2, uData.getDemData().getGender().toString().toLowerCase());
uStatement.setString(3, uData.getDemData().getGeoLocation());
@ -603,10 +609,13 @@ public abstract class SQLDB extends Database {
uStatement.setInt(7, uData.getLoginTimes());
uStatement.setLong(8, uData.getLastPlayed());
uStatement.setString(9, uData.getUuid().toString());
uStatement.addBatch();
uStatement.addBatch();
commitRequired = true;
}
uStatement.executeBatch();
connection.commit();
if (commitRequired) {
connection.commit();
}
uStatement.close();
connection.setAutoCommit(true);
data.removeAll(saveLast);
@ -619,7 +628,7 @@ public abstract class SQLDB extends Database {
}
for (UserData userData : saveLast) {
saveUserData(userData.getUuid(), userData);
}
}
} catch (SQLException | NullPointerException e) {
e.printStackTrace();
}
@ -718,15 +727,19 @@ public abstract class SQLDB extends Database {
+ locationColumnCoordinatesZ + ", "
+ locationColumnWorld
+ ") VALUES (?, ?, ?, ?)");
boolean commitRequired = false;
for (Location location : locations) {
saveStatement.setInt(1, userId);
saveStatement.setInt(2, (int) location.getBlockX());
saveStatement.setInt(3, (int) location.getBlockZ());
saveStatement.setString(4, location.getWorld().getName());
saveStatement.addBatch();
commitRequired = true;
}
saveStatement.executeBatch();
connection.commit();
if (commitRequired) {
connection.commit();
}
saveStatement.close();
connection.setAutoCommit(true);
} catch (SQLException e) {
@ -746,13 +759,17 @@ public abstract class SQLDB extends Database {
+ nicknamesColumnUserID + ", "
+ nicknamesColumnNick
+ ") VALUES (?, ?)");
boolean commitRequired = false;
for (String name : names) {
statement.setInt(1, userId);
statement.setString(2, name);
statement.addBatch();
commitRequired = true;
}
statement.executeBatch();
connection.commit();
if (commitRequired) {
connection.commit();
}
statement.close();
connection.setAutoCommit(true);
@ -774,13 +791,17 @@ public abstract class SQLDB extends Database {
+ ipsColumnUserID + ", "
+ ipsColumnIP
+ ") VALUES (?, ?)");
boolean commitRequired = false;
for (InetAddress ip : ips) {
statement.setInt(1, userId);
statement.setString(2, ip.getHostAddress());
statement.addBatch();
commitRequired = true;
}
statement.executeBatch();
connection.commit();
if (commitRequired) {
connection.commit();
}
statement.close();
connection.setAutoCommit(true);
@ -830,7 +851,7 @@ public abstract class SQLDB extends Database {
@Override
public void clean() {
checkConnection();
plugin.log("DATABASE-SQLDB\nCleaning DB not implemented");
plugin.log("Database Cleaning has not yet been implemented.");
}
public void removeAllData() {

View File

@ -101,7 +101,7 @@ public class FormatUtils {
}
/**
* Turns the version string into a double
* Turns the version string into a integer
*
* @param versionString String - number format 1.1.1
* @return parsed double - for example 1,11

View File

@ -28,9 +28,9 @@
%playerchartweek%
<h4>Player Activity - Last 30 days</h4>
%playerchartmonth%
<p>Recent logins: %recentlogins%</p>
<!-- <p>Recent logins: %recentlogins%</p>
<br/><h4>Top 20 Most Active</h4>
%top20mostactive%
%top20mostactive%-->
</td>
<td style="margin-left: 3px; margin-right: auto;
border-style: groove; border-width: 3px; border-radius: 12px; padding: 2px 4px 2px 3px;

View File

@ -1,4 +1,6 @@
Settings:
Data:
GatherLocations: true
Analysis:
MinutesPlayedUntilConsidiredActive: 10
Cache:

View File

@ -4,10 +4,10 @@
<h4>Information from PlanLite</h4>
%totalmoneyline%
%totalvotesline%
<br/><h4>Richest Players</h4>
<!-- <br/><h4>Richest Players</h4>
%top10richest%
<br/><h4>Top Voters</h4>
%top10votes%
%top10votes%-->
</td>
<td style="margin-left: 3px; margin-right: auto;border-style: groove; border-width: 3px;
border-radius: 12px; padding: 2px 4px 2px 3px; box-shadow: 5px 5px 4px 0px #888888;">

View File

@ -1,7 +1,7 @@
name: Plan
author: Rsl1122
main: com.djrapitops.plan.Plan
version: 2.1.3
version: 2.2.0
commands:
plan:
@ -19,9 +19,6 @@ commands:
search:
usage: /plan <search terms> -p add -p to make not search playername
description: search data of multiple players with search terms
debug:
usage: /plan debug
description: run commands to debug the plugin.
softdepend:
- PlanLite