mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-02 05:21:36 +01:00
More Bugfixes, API calls fixed, Deprecated API that moves to PlanLite
Fixed bugs: - Logintimes now 1 instead of 2 after first login. - Location ID now primary key - Database now saves UserID correctly, might have been old database file causing the error. - Confirmed that database doesn't save multiples of entries - API now handling deprecated methods through PlanLiteHook - Optimized GamemodeTimesHandler code Other: - GameModeTimes Table is optimizable: Can save all entries on one line instead of 4. - OP and Banned are not checked yet. Known bugs: - LastPlayed is handling weird (0 on logout) -> PlayTime is getting assigned wrong value -> GamemodeTimes are getting assigned wrong value - Locations not saved when player moves
This commit is contained in:
parent
7758c5c581
commit
0885ea4db1
@ -67,8 +67,7 @@ public class Plan extends JavaPlugin {
|
||||
saveConfig();
|
||||
|
||||
initDatabase();
|
||||
|
||||
this.api = new API(this);
|
||||
|
||||
hookPlanLite();
|
||||
this.handler = new DataHandler(this);
|
||||
registerListeners();
|
||||
@ -76,7 +75,10 @@ public class Plan extends JavaPlugin {
|
||||
log(MiscUtils.checkVersion());
|
||||
|
||||
getCommand("plan").setExecutor(new PlanCommand(this));
|
||||
|
||||
this.api = new API(this);
|
||||
handler.handleReload();
|
||||
|
||||
log("Player Analytics Enabled.");
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,16 @@
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.api.API;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.Hook;
|
||||
import java.util.HashMap;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
public class PlanLiteHook {
|
||||
|
||||
private PlanLite planLite;
|
||||
private Plan plugin;
|
||||
private API planLiteApi;
|
||||
|
||||
public PlanLiteHook(Plan plugin) {
|
||||
try {
|
||||
@ -14,6 +18,7 @@ public class PlanLiteHook {
|
||||
if (planLite == null) {
|
||||
throw new Exception(Phrase.ERROR_PLANLITE.toString());
|
||||
}
|
||||
planLiteApi = planLite.getAPI();
|
||||
} catch (Exception e) {
|
||||
plugin.logError(e.toString());
|
||||
}
|
||||
@ -30,4 +35,74 @@ public class PlanLiteHook {
|
||||
plugin.logError("Failed to hook " + name + "\n " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getDebug() {
|
||||
return planLiteApi.getDebug();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleEssentials() {
|
||||
return planLiteApi.getVisibleEssentials();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleOnTime() {
|
||||
return planLiteApi.getVisibleOnTime();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleFactions() {
|
||||
return planLiteApi.getVisibleFactions();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleSuperbVote() {
|
||||
return planLiteApi.getVisibleSuperbVote();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleTowny() {
|
||||
return planLiteApi.getVisibleTowny();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleVault() {
|
||||
return planLiteApi.getVisibleVault();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleAdvancedAchievements() {
|
||||
return planLiteApi.getVisibleAdvancedAchievements();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisiblePlaceholderAPI() {
|
||||
return planLiteApi.getVisiblePlaceholderAPI();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, DataPoint> getData(String playerName, boolean dataPoint) {
|
||||
return planLiteApi.getData(playerName, dataPoint);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, String> getData(String playerName) {
|
||||
return planLiteApi.getData(playerName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, DataPoint> getAllData(String playerName, boolean dataPoint) {
|
||||
return planLiteApi.getAllData(playerName, dataPoint);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, String> getAllData(String playerName) {
|
||||
return planLiteApi.getAllData(playerName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, DataPoint> transformOldDataFormat(HashMap<String, String> oldData) {
|
||||
return planLiteApi.transformOldDataFormat(oldData);
|
||||
}
|
||||
}
|
||||
|
@ -1,112 +1,114 @@
|
||||
package com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanLiteHook;
|
||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class API {
|
||||
|
||||
private Plan plugin;
|
||||
private PlanLiteHook hook;
|
||||
|
||||
public API(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
hook = plugin.getPlanLiteHook();
|
||||
}
|
||||
|
||||
public boolean getDebug() {
|
||||
return plugin.getConfig().getBoolean("debug");
|
||||
}
|
||||
|
||||
public boolean getVisibleEssentials() {
|
||||
return plugin.getConfig().getBoolean("visible.essentials");
|
||||
}
|
||||
|
||||
public boolean getVisibleOnTime() {
|
||||
return plugin.getConfig().getBoolean("visible.ontime");
|
||||
}
|
||||
|
||||
public boolean getVisibleFactions() {
|
||||
return plugin.getConfig().getBoolean("visible.factions");
|
||||
}
|
||||
|
||||
public boolean getVisibleSuperbVote() {
|
||||
return plugin.getConfig().getBoolean("visible.superbvote");
|
||||
}
|
||||
|
||||
public boolean getVisibleTowny() {
|
||||
return plugin.getConfig().getBoolean("visible.towny");
|
||||
}
|
||||
|
||||
public boolean getVisibleVault() {
|
||||
return plugin.getConfig().getBoolean("visible.vault");
|
||||
}
|
||||
|
||||
public boolean getVisibleAdvancedAchievements() {
|
||||
return plugin.getConfig().getBoolean("visible.advancedachievements");
|
||||
}
|
||||
|
||||
public boolean getVisiblePlaceholderAPI() {
|
||||
return plugin.getConfig().getBoolean("visible.placeholderapi");
|
||||
}
|
||||
|
||||
public HashMap<String, DataPoint> getData(String playerName, boolean dataPoint) {
|
||||
return DataFormatUtils.removeExtraDataPoints(DataUtils.getData(false, playerName));
|
||||
}
|
||||
|
||||
// Please move to DataPoint system as soon as possible
|
||||
@Deprecated
|
||||
public HashMap<String, String> getData(String playerName) {
|
||||
HashMap<String, String> data = new HashMap<>();
|
||||
HashMap<String, DataPoint> dataWPoints = getData(playerName, true);
|
||||
dataWPoints.keySet().parallelStream().forEach((key) -> {
|
||||
data.put(key, dataWPoints.get(key).data());
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
public HashMap<String, DataPoint> getAllData(String playerName, boolean dataPoint) {
|
||||
return DataFormatUtils.removeExtraDataPoints(DataUtils.getData(true, playerName));
|
||||
}
|
||||
|
||||
// Please move to DataPoint system as soon as possible
|
||||
@Deprecated
|
||||
public HashMap<String, String> getAllData(String playerName) {
|
||||
HashMap<String, String> data = new HashMap<>();
|
||||
HashMap<String, DataPoint> dataWPoints = getAllData(playerName, true);
|
||||
dataWPoints.keySet().parallelStream().forEach((key) -> {
|
||||
data.put(key, dataWPoints.get(key).data());
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
public HashMap<String, DataPoint> transformOldDataFormat(HashMap<String, String> oldData) {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
for (String key : oldData.keySet()) {
|
||||
data.put(key, new DataPoint(oldData.get(key), DataType.OTHER));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// use (new Date) on after parameter for time since moment to now
|
||||
public static String formatTimeSinceDate(Date before, Date after) {
|
||||
return DataFormatUtils.formatTimeAmountSinceDate(before, after);
|
||||
}
|
||||
|
||||
// use (new Date) on after parameter for time since moment to now
|
||||
|
||||
public static String formatTimeSinceString(String before, Date after) {
|
||||
return DataFormatUtils.formatTimeAmountSinceString(before, after);
|
||||
}
|
||||
|
||||
|
||||
public static String formatTimeAmount(String timeInMs) {
|
||||
return DataFormatUtils.formatTimeAmount(timeInMs);
|
||||
}
|
||||
|
||||
|
||||
public static String formatTimeStamp(String timeInMs) {
|
||||
return DataFormatUtils.formatTimeStamp(timeInMs);
|
||||
}
|
||||
|
||||
public void addExtraHook(String name, Hook hook) {
|
||||
|
||||
/*
|
||||
Deprecated this part of the API, move to PlanLite API to register hooks
|
||||
If PlanLite is installed PlanLiteAPI methods will be attempted
|
||||
If PlanLite is not installed -> NullPointerException will be thrown.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getDebug() throws NullPointerException {
|
||||
return hook.getDebug();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleEssentials() throws NullPointerException {
|
||||
return hook.getVisibleEssentials();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleOnTime() throws NullPointerException {
|
||||
return hook.getVisibleOnTime();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleFactions() throws NullPointerException {
|
||||
return hook.getVisibleFactions();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleSuperbVote() throws NullPointerException {
|
||||
return hook.getVisibleSuperbVote();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleTowny() throws NullPointerException {
|
||||
return hook.getVisibleTowny();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleVault() throws NullPointerException {
|
||||
return hook.getVisibleVault();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisibleAdvancedAchievements() throws NullPointerException {
|
||||
return hook.getVisibleAdvancedAchievements();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getVisiblePlaceholderAPI() throws NullPointerException {
|
||||
return hook.getVisiblePlaceholderAPI();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, DataPoint> getData(String playerName, boolean dataPoint) throws NullPointerException {
|
||||
return hook.getData(playerName, dataPoint);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, String> getData(String playerName) throws NullPointerException {
|
||||
return hook.getData(playerName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, DataPoint> getAllData(String playerName, boolean dataPoint) throws NullPointerException {
|
||||
return hook.getAllData(playerName, dataPoint);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, String> getAllData(String playerName) throws NullPointerException {
|
||||
return hook.getAllData(playerName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, DataPoint> transformOldDataFormat(HashMap<String, String> oldData) throws NullPointerException {
|
||||
return hook.transformOldDataFormat(oldData);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addExtraHook(String name, Hook hook) throws NullPointerException {
|
||||
plugin.addExtraHook(name, hook);
|
||||
}
|
||||
}
|
||||
|
@ -71,12 +71,15 @@ public class InspectCommand extends SubCommand {
|
||||
msgs.add("Ips " + data.getIps().toString());
|
||||
msgs.add("Last gamemode " + data.getLastGamemode());
|
||||
msgs.add("Last gm swap time " + data.getLastGmSwapTime());
|
||||
msgs.add("Last Played" + data.getLastPlayed());
|
||||
msgs.add("Last Played " + data.getLastPlayed());
|
||||
msgs.add("Location " + data.getLocation().getBlockX());
|
||||
msgs.add("Nicknames " + data.getNicknames().toString());
|
||||
msgs.add("Registered " + data.getRegistered());
|
||||
msgs.add("TimesKicked " + data.getTimesKicked());
|
||||
msgs.add("Uuid " + data.getUuid());
|
||||
msgs.add("PlayTime " + data.getPlayTime());
|
||||
msgs.add("Banned "+ data.isBanned());
|
||||
msgs.add("Opped" + data.isOp());
|
||||
msgs.add(operatorColor + "SERVER");
|
||||
ServerData sdata = plugin.getHandler().getServerData();
|
||||
msgs.add("Commands " + sdata.getCommandUsage().keySet().toString());
|
||||
|
@ -156,7 +156,7 @@ public abstract class SQLDB extends Database {
|
||||
set.close();
|
||||
|
||||
query("CREATE TABLE IF NOT EXISTS " + userName + " ("
|
||||
+ userColumnID + " int PRIMARY KEY, "
|
||||
+ userColumnID + " integer PRIMARY KEY, "
|
||||
+ userColumnUUID + " varchar(36) NOT NULL, "
|
||||
+ userColumnDemAge + " int NOT NULL, "
|
||||
+ userColumnDemGender + " varchar(8) NOT NULL, "
|
||||
@ -169,7 +169,7 @@ public abstract class SQLDB extends Database {
|
||||
);
|
||||
|
||||
query("CREATE TABLE IF NOT EXISTS " + locationName + " ("
|
||||
+ locationColumnID + " int NOT NULL, "
|
||||
+ locationColumnID + " integer PRIMARY KEY, "
|
||||
+ locationColumnUserID + " int NOT NULL, "
|
||||
+ locationColumnCoordinatesX + " int NOT NULL, "
|
||||
+ locationColumnCoordinatesZ + " int NOT NULL, "
|
||||
@ -317,7 +317,6 @@ public abstract class SQLDB extends Database {
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
|
||||
|
||||
while (set.next()) {
|
||||
data.getDemData().setAge(set.getInt(userColumnDemAge));
|
||||
data.getDemData().setGender(Gender.parse(set.getString(userColumnDemGender)));
|
||||
@ -329,7 +328,7 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
set.close();
|
||||
statement.close();
|
||||
String userId = ""+getUserId(uuid.toString());
|
||||
String userId = "" + getUserId(uuid.toString());
|
||||
|
||||
statement = connection.prepareStatement("SELECT * FROM " + locationName + " WHERE UPPER(" + locationColumnUserID + ") LIKE UPPER(?)");
|
||||
statement.setString(1, userId);
|
||||
@ -524,31 +523,31 @@ public abstract class SQLDB extends Database {
|
||||
try {
|
||||
int update = 0;
|
||||
if (userId != -1) {
|
||||
String sql = "UPDATE " + userName + " SET "
|
||||
+ userColumnDemAge + "=?, "
|
||||
+ userColumnDemGender + "=?, "
|
||||
+ userColumnDemGeoLocation + "=?, "
|
||||
+ userColumnLastGM + "=?, "
|
||||
+ userColumnLastGMSwapTime + "=?, "
|
||||
+ userColumnPlayTime + "=?, "
|
||||
+ userColumnLoginTimes + "=? "
|
||||
+ "WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)";
|
||||
String sql = "UPDATE " + userName + " SET "
|
||||
+ userColumnDemAge + "=?, "
|
||||
+ userColumnDemGender + "=?, "
|
||||
+ userColumnDemGeoLocation + "=?, "
|
||||
+ userColumnLastGM + "=?, "
|
||||
+ userColumnLastGMSwapTime + "=?, "
|
||||
+ userColumnPlayTime + "=?, "
|
||||
+ userColumnLoginTimes + "=? "
|
||||
+ "WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)";
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(sql);
|
||||
statement.setInt(1, data.getDemData().getAge());
|
||||
statement.setString(2, data.getDemData().getGender().toString().toLowerCase());
|
||||
statement.setString(3, data.getDemData().getGeoLocation());
|
||||
GameMode gm = data.getLastGamemode();
|
||||
if (gm != null) {
|
||||
statement.setString(4, data.getLastGamemode().name());
|
||||
} else {
|
||||
statement.setString(4, GameMode.SURVIVAL.name());
|
||||
}
|
||||
statement.setLong(5, data.getLastGmSwapTime());
|
||||
statement.setLong(6, data.getPlayTime());
|
||||
statement.setInt(7, data.getLoginTimes());
|
||||
statement.setString(8, uuid.toString());
|
||||
update = statement.executeUpdate();
|
||||
PreparedStatement statement = connection.prepareStatement(sql);
|
||||
statement.setInt(1, data.getDemData().getAge());
|
||||
statement.setString(2, data.getDemData().getGender().toString().toLowerCase());
|
||||
statement.setString(3, data.getDemData().getGeoLocation());
|
||||
GameMode gm = data.getLastGamemode();
|
||||
if (gm != null) {
|
||||
statement.setString(4, data.getLastGamemode().name());
|
||||
} else {
|
||||
statement.setString(4, GameMode.SURVIVAL.name());
|
||||
}
|
||||
statement.setLong(5, data.getLastGmSwapTime());
|
||||
statement.setLong(6, data.getPlayTime());
|
||||
statement.setInt(7, data.getLoginTimes());
|
||||
statement.setString(8, uuid.toString());
|
||||
update = statement.executeUpdate();
|
||||
}
|
||||
if (update == 0) {
|
||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO " + userName + " ("
|
||||
@ -606,18 +605,16 @@ public abstract class SQLDB extends Database {
|
||||
for (int i = 0; i < locations.size(); i++) {
|
||||
Location location = locations.get(i);
|
||||
statement = connection.prepareStatement("INSERT INTO " + locationName + " ("
|
||||
+ locationColumnID + ", "
|
||||
+ locationColumnUserID + ", "
|
||||
+ locationColumnCoordinatesX + ", "
|
||||
+ locationColumnCoordinatesZ + ", "
|
||||
+ locationColumnWorld
|
||||
+ ") VALUES (?, ?, ?, ?, ?)");
|
||||
+ ") VALUES (?, ?, ?, ?)");
|
||||
|
||||
statement.setInt(1, i);
|
||||
statement.setInt(2, userId);
|
||||
statement.setInt(3, location.getBlockX());
|
||||
statement.setInt(4, location.getBlockZ());
|
||||
statement.setString(5, location.getWorld().getName());
|
||||
statement.setInt(1, userId);
|
||||
statement.setInt(2, location.getBlockX());
|
||||
statement.setInt(3, location.getBlockZ());
|
||||
statement.setString(4, location.getWorld().getName());
|
||||
|
||||
statement.execute();
|
||||
statement.close();
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class GamemodeTimesHandler {
|
||||
|
||||
@ -50,15 +51,11 @@ public class GamemodeTimesHandler {
|
||||
}
|
||||
|
||||
void handleReload(Player p, UserData data) {
|
||||
HashMap<GameMode, Long> times = data.getGmTimes();
|
||||
handler.getActivityHandler().saveToCache(p, data);
|
||||
saveToCache(p, data);
|
||||
}
|
||||
|
||||
long lastSwap = data.getLastGmSwapTime();
|
||||
long playTime = data.getPlayTime();
|
||||
GameMode currentGM = p.getGameMode();
|
||||
data.setGMTime(currentGM, times.get(currentGM) + (playTime - lastSwap));
|
||||
|
||||
data.setLastGmSwapTime(playTime);
|
||||
public void handleLogOut(PlayerQuitEvent event, UserData data) {
|
||||
saveToCache(event.getPlayer(), data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class NewPlayerCreator {
|
||||
long zero = Long.parseLong("0");
|
||||
data.setPlayTime(zero);
|
||||
data.setTimesKicked(0);
|
||||
data.setLoginTimes(1);
|
||||
data.setLoginTimes(0);
|
||||
data.setLastGmSwapTime(zero);
|
||||
db.saveUserData(p.getUniqueId(), data);
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ public class PlanPlayerListener implements Listener {
|
||||
UserData data = handler.getCurrentData(uuid);
|
||||
activityH.handleLogOut(event, data);
|
||||
locationH.handleLogOut(event, data);
|
||||
gmTimesH.handleLogOut(event, data);
|
||||
serverHandler.handleLogout();
|
||||
handler.saveCachedData(uuid);
|
||||
handler.clearFromCache(uuid);
|
||||
|
Loading…
Reference in New Issue
Block a user