mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-01 21:11:23 +01:00
Optimization, Some Javadocs, Bugfixes [2.0.0-DEV]
- Optimized GamemodeTimes table. - Added LastPlayed to the users table. Fixed bugs: - Last Played now handling correctly Known bugs: - Locations not saved when player moves - Times don't update on inspect
This commit is contained in:
parent
0885ea4db1
commit
b7b6a0f05a
@ -6,12 +6,12 @@ import com.djrapitops.plan.command.utils.MiscUtils;
|
||||
import com.djrapitops.plan.database.Database;
|
||||
import com.djrapitops.plan.database.databases.MySQLDB;
|
||||
import com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import com.djrapitops.plan.datahandlers.DataHandler;
|
||||
import com.djrapitops.plan.datahandlers.listeners.PlanChatListener;
|
||||
import com.djrapitops.plan.datahandlers.listeners.PlanCommandPreprocessListener;
|
||||
import com.djrapitops.plan.datahandlers.listeners.PlanGamemodeChangeListener;
|
||||
import com.djrapitops.plan.datahandlers.listeners.PlanPlayerListener;
|
||||
import com.djrapitops.plan.datahandlers.listeners.PlanPlayerMoveListener;
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.data.listeners.PlanChatListener;
|
||||
import com.djrapitops.plan.data.listeners.PlanCommandPreprocessListener;
|
||||
import com.djrapitops.plan.data.listeners.PlanGamemodeChangeListener;
|
||||
import com.djrapitops.plan.data.listeners.PlanPlayerListener;
|
||||
import com.djrapitops.plan.data.listeners.PlanPlayerMoveListener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -27,7 +27,7 @@ public class Plan extends JavaPlugin {
|
||||
|
||||
private API api;
|
||||
private PlanLiteHook planLiteHook;
|
||||
private DataHandler handler;
|
||||
private DataCacheHandler handler;
|
||||
private Database db;
|
||||
private HashSet<Database> databases;
|
||||
|
||||
@ -69,7 +69,7 @@ public class Plan extends JavaPlugin {
|
||||
initDatabase();
|
||||
|
||||
hookPlanLite();
|
||||
this.handler = new DataHandler(this);
|
||||
this.handler = new DataCacheHandler(this);
|
||||
registerListeners();
|
||||
|
||||
log(MiscUtils.checkVersion());
|
||||
@ -155,7 +155,7 @@ public class Plan extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(new PlanPlayerMoveListener(this), this);
|
||||
}
|
||||
|
||||
public DataHandler getHandler() {
|
||||
public DataCacheHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
@ -190,7 +190,9 @@ public class Plan extends JavaPlugin {
|
||||
setEnabled(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
db.setVersion(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -6,107 +6,208 @@ import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class API {
|
||||
|
||||
private Plan plugin;
|
||||
private PlanLiteHook hook;
|
||||
|
||||
/**
|
||||
* Class Construcor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public API(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
hook = plugin.getPlanLiteHook();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user readable format of Time difference between two dates
|
||||
*
|
||||
* @param before Date with long value that is lower
|
||||
* @param after Date with long value that is higher
|
||||
* @return String that is easily readable d:h:m:s
|
||||
*/
|
||||
public static String formatTimeSinceDate(Date before, Date after) {
|
||||
return DataFormatUtils.formatTimeAmountSinceDate(before, after);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user readable format of Time difference between two dates
|
||||
*
|
||||
* @param before String of long since Epoch 1970
|
||||
* @param after Date with long value that is higher
|
||||
* @return String that is easily readable d:h:m:s
|
||||
*/
|
||||
public static String formatTimeSinceString(String before, Date after) {
|
||||
return DataFormatUtils.formatTimeAmountSinceString(before, after);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user readable format of Time
|
||||
*
|
||||
* @param timeInMs String of long value in milliseconds
|
||||
* @return String that is easily readable d:h:m:s
|
||||
*/
|
||||
public static String formatTimeAmount(String timeInMs) {
|
||||
return DataFormatUtils.formatTimeAmount(timeInMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns user readable format of a Date.
|
||||
*
|
||||
* @param timeInMs String of long since Epoch 1970
|
||||
* @return String that is easily readable date.
|
||||
*/
|
||||
public static String formatTimeStamp(String timeInMs) {
|
||||
return DataFormatUtils.formatTimeStamp(timeInMs);
|
||||
}
|
||||
|
||||
/*
|
||||
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.
|
||||
/**
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getDebug() throws NullPointerException {
|
||||
return hook.getDebug();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getVisibleEssentials() throws NullPointerException {
|
||||
return hook.getVisibleEssentials();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getVisibleOnTime() throws NullPointerException {
|
||||
return hook.getVisibleOnTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getVisibleFactions() throws NullPointerException {
|
||||
return hook.getVisibleFactions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getVisibleSuperbVote() throws NullPointerException {
|
||||
return hook.getVisibleSuperbVote();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getVisibleTowny() throws NullPointerException {
|
||||
return hook.getVisibleTowny();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getVisibleVault() throws NullPointerException {
|
||||
return hook.getVisibleVault();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getVisibleAdvancedAchievements() throws NullPointerException {
|
||||
return hook.getVisibleAdvancedAchievements();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getVisiblePlaceholderAPI() throws NullPointerException {
|
||||
return hook.getVisiblePlaceholderAPI();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerName
|
||||
* @param dataPoint variable to differentiate between DataPoint and String
|
||||
* return
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public HashMap<String, DataPoint> getData(String playerName, boolean dataPoint) throws NullPointerException {
|
||||
return hook.getData(playerName, dataPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerName
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public HashMap<String, String> getData(String playerName) throws NullPointerException {
|
||||
return hook.getData(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerName
|
||||
* @param dataPoint variable to differentiate between DataPoint and String
|
||||
* return
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public HashMap<String, DataPoint> getAllData(String playerName, boolean dataPoint) throws NullPointerException {
|
||||
return hook.getAllData(playerName, dataPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerName
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public HashMap<String, String> getAllData(String playerName) throws NullPointerException {
|
||||
return hook.getAllData(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param oldData
|
||||
* @return @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public HashMap<String, DataPoint> transformOldDataFormat(HashMap<String, String> oldData) throws NullPointerException {
|
||||
return hook.transformOldDataFormat(oldData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name name of the plugin registering the hook
|
||||
* @param hook Hook that is registered
|
||||
* @throws NullPointerException if PlanLite not installed
|
||||
* @deprecated Moved to PlanLite
|
||||
*/
|
||||
@Deprecated
|
||||
public void addExtraHook(String name, Hook hook) throws NullPointerException {
|
||||
plugin.addExtraHook(name, hook);
|
||||
|
@ -7,10 +7,10 @@ import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import com.djrapitops.plan.database.ServerData;
|
||||
import com.djrapitops.plan.data.ServerData;
|
||||
|
||||
import java.util.Date;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -20,6 +20,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
public class InspectCommand extends SubCommand {
|
||||
|
||||
|
@ -1,22 +1,24 @@
|
||||
package com.djrapitops.plan.command.utils;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import org.bukkit.GameMode;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class MiscUtils {
|
||||
// <h1>Plan - Player Analytics <span class="muted">
|
||||
|
||||
/**
|
||||
* Checks the version and returns response String.
|
||||
*
|
||||
* @return String informing about status of plugins version.
|
||||
*/
|
||||
public static String checkVersion() {
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
String[] nVersion;
|
||||
String[] cVersion;
|
||||
String cVersion;
|
||||
String lineWithVersion;
|
||||
try {
|
||||
URL githubUrl = new URL("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/src/plugin.yml");
|
||||
@ -30,21 +32,42 @@ public class MiscUtils {
|
||||
}
|
||||
}
|
||||
String versionString = lineWithVersion.split(": ")[1];
|
||||
nVersion = versionString.split("\\.");
|
||||
double newestVersionNumber = Double.parseDouble(nVersion[0] + "." + nVersion[1] + nVersion[2]);
|
||||
cVersion = plugin.getDescription().getVersion().split("\\.");
|
||||
double currentVersionNumber = Double.parseDouble(cVersion[0] + "." + cVersion[1] + cVersion[2]);
|
||||
double newestVersionNumber = parseVersionDouble(versionString);
|
||||
cVersion = plugin.getDescription().getVersion();
|
||||
double currentVersionNumber = parseVersionDouble(cVersion);
|
||||
if (newestVersionNumber > currentVersionNumber) {
|
||||
return "New Version (" + versionString + ") is availible at https://www.spigotmc.org/resources/plan-player-analytics.32536/";
|
||||
} else {
|
||||
return "You're running the latest version";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.logToFile("Failed to compare versions.\n"+e);
|
||||
plugin.logToFile("Failed to compare versions.\n" + e);
|
||||
}
|
||||
return "Failed to get newest version number.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the version string into a double
|
||||
*
|
||||
* @param versionString String - number format 1.1.1
|
||||
* @return parsed double - for example 1,11
|
||||
* @throws NumberFormatException When wrong format
|
||||
*/
|
||||
public static double parseVersionDouble(String versionString) throws NumberFormatException {
|
||||
String[] versionArray = versionString.split("\\.");
|
||||
if (versionArray.length != 3) {
|
||||
throw new NumberFormatException("Wrong format used");
|
||||
}
|
||||
double versionDouble = Double.parseDouble(versionArray[0] + "." + versionArray[1] + versionArray[2]);
|
||||
return versionDouble;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges multiple arrays into one.
|
||||
*
|
||||
* @param arrays String arrays that need to be combined
|
||||
* @return One array with contents of the multiple
|
||||
*/
|
||||
public static String[] mergeArrays(String[]... arrays) {
|
||||
int arraySize = 0;
|
||||
for (String[] array : arrays) {
|
||||
@ -59,22 +82,4 @@ public class MiscUtils {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GameMode parseGM(String string) {
|
||||
String survival = GameMode.SURVIVAL.name();
|
||||
String creative = GameMode.CREATIVE.name();
|
||||
String adventure = GameMode.ADVENTURE.name();
|
||||
String spectator = GameMode.SPECTATOR.name();
|
||||
if (string.equalsIgnoreCase(survival)) {
|
||||
return GameMode.SURVIVAL;
|
||||
} else if (string.equalsIgnoreCase(creative)) {
|
||||
return GameMode.CREATIVE;
|
||||
} else if (string.equalsIgnoreCase(adventure)) {
|
||||
return GameMode.ADVENTURE;
|
||||
} else if (string.equalsIgnoreCase(spectator)) {
|
||||
return GameMode.SPECTATOR;
|
||||
} else {
|
||||
return GameMode.SURVIVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
package com.djrapitops.plan.database;
|
||||
package com.djrapitops.plan.data;
|
||||
|
||||
import com.djrapitops.plan.api.Gender;
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
package com.djrapitops.plan.database;
|
||||
package com.djrapitops.plan.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.Bukkit;
|
@ -1,5 +1,6 @@
|
||||
package com.djrapitops.plan.database;
|
||||
package com.djrapitops.plan.data;
|
||||
|
||||
import com.djrapitops.plan.database.Database;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
@ -1,17 +1,19 @@
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
package com.djrapitops.plan.data.cache;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.database.Database;
|
||||
import com.djrapitops.plan.database.DemographicsData;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import com.djrapitops.plan.database.ServerData;
|
||||
import com.djrapitops.plan.data.*;
|
||||
import com.djrapitops.plan.data.handlers.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DataHandler {
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DataCacheHandler {
|
||||
|
||||
private final HashMap<UUID, UserData> dataCache;
|
||||
private final Plan plugin;
|
||||
@ -29,7 +31,15 @@ public class DataHandler {
|
||||
|
||||
private int timesSaved;
|
||||
|
||||
public DataHandler(Plan plugin) {
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* Creates the set of Handlers that will be used to modify UserData gets the
|
||||
* Database from the plugin
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public DataCacheHandler(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
db = plugin.getDB();
|
||||
dataCache = new HashMap<>();
|
||||
@ -59,11 +69,28 @@ public class DataHandler {
|
||||
}, 60 * 20 * minutes, 60 * 20 * minutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells wether or not user has been saved to the database before
|
||||
*
|
||||
* @param uuid Players UUID
|
||||
* @return User's data is not in the database: true
|
||||
* @deprecated Moved to ActivityHandler
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isFirstTimeJoin(UUID uuid) {
|
||||
return activityHandler.isFirstTimeJoin(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses Database to retrieve the UserData of a matching player
|
||||
*
|
||||
* Caches the data to the HashMap if cache: true
|
||||
*
|
||||
* @param uuid Player's UUID
|
||||
* @param cache Wether or not the UserData will be Cached in this instance
|
||||
* of DataCacheHandler
|
||||
* @return UserData matching the Player
|
||||
*/
|
||||
public UserData getCurrentData(UUID uuid, boolean cache) {
|
||||
if (cache) {
|
||||
if (dataCache.get(uuid) == null) {
|
||||
@ -75,10 +102,20 @@ public class DataHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Uses Database to retrieve the UserData of a matching player Caches the
|
||||
* data to the HashMap
|
||||
*
|
||||
* @param uuid Player's UUID
|
||||
* @return UserData matching the Player
|
||||
*/
|
||||
public UserData getCurrentData(UUID uuid) {
|
||||
return getCurrentData(uuid, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all data in the cache to Database with AsyncTasks
|
||||
*/
|
||||
public void saveCachedData() {
|
||||
dataCache.keySet().parallelStream().forEach((uuid) -> {
|
||||
saveCachedData(uuid);
|
||||
@ -87,6 +124,10 @@ public class DataHandler {
|
||||
timesSaved++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all data in the cache to Database without AsyncTask (Disabled
|
||||
* plugins can't register tasks)
|
||||
*/
|
||||
public void saveCacheOnDisable() {
|
||||
dataCache.keySet().stream().forEach((uuid) -> {
|
||||
if (dataCache.get(uuid) != null) {
|
||||
@ -96,6 +137,11 @@ public class DataHandler {
|
||||
db.saveServerData(serverData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the cached data of matching Player if it is in the cache
|
||||
*
|
||||
* @param uuid Player's UUID
|
||||
*/
|
||||
public void saveCachedData(UUID uuid) {
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
@ -107,6 +153,11 @@ public class DataHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the cached ServerData with AsyncTask
|
||||
*
|
||||
* Data is saved on a new line with a long value matching current Date
|
||||
*/
|
||||
public void saveServerData() {
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
@ -124,72 +175,125 @@ public class DataHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all UserData from the HashMap
|
||||
*/
|
||||
public void clearCache() {
|
||||
dataCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the matching UserData from the HashMap
|
||||
*
|
||||
* @param uuid Player's UUID
|
||||
*/
|
||||
public void clearFromCache(UUID uuid) {
|
||||
if (dataCache.get(uuid) != null) {
|
||||
dataCache.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new UserData instance and saves it to the Database
|
||||
*
|
||||
* @param player Player the new UserData is created for
|
||||
*/
|
||||
public void newPlayer(Player player) {
|
||||
newPlayerCreator.createNewPlayer(player);
|
||||
newPlayerCreator.createNewPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The HashMap containing all Cached UserData
|
||||
*/
|
||||
public HashMap<UUID, UserData> getDataCache() {
|
||||
return dataCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current instance of the ActivityHandler
|
||||
*/
|
||||
public ActivityHandler getActivityHandler() {
|
||||
return activityHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current instance of the LocationHandler
|
||||
*/
|
||||
public LocationHandler getLocationHandler() {
|
||||
return locationHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current instance of the DemographicsHandler
|
||||
*/
|
||||
public DemographicsHandler getDemographicsHandler() {
|
||||
return demographicsHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current instance of the BasicInfoHandler
|
||||
*/
|
||||
public BasicInfoHandler getBasicInfoHandler() {
|
||||
return basicInfoHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current instance of the RuleBreakingHandler
|
||||
*/
|
||||
public RuleBreakingHandler getRuleBreakingHandler() {
|
||||
return ruleBreakingHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current instance of the GamemodeTimesHandler
|
||||
*/
|
||||
public GamemodeTimesHandler getGamemodeTimesHandler() {
|
||||
return gamemodeTimesHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the same value as Plan#getDB().
|
||||
*
|
||||
* @return Current instance of the Database,
|
||||
*/
|
||||
public Database getDB() {
|
||||
return db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the player count and returns cached ServerData.
|
||||
*
|
||||
* @return Cached serverData
|
||||
*/
|
||||
public ServerData getServerData() {
|
||||
serverData.updatePlayerCount();
|
||||
return serverData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current instance of ServerDataHandler
|
||||
*/
|
||||
public ServerDataHandler getServerDataHandler() {
|
||||
return serverDataHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* If /reload is run this treats every online player as a new login.
|
||||
*
|
||||
* Calls all the methods that are ran when PlayerJoinEvent is fired
|
||||
*/
|
||||
public void handleReload() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
boolean newPlayer = activityHandler.isFirstTimeJoin(uuid);
|
||||
newPlayer(player);
|
||||
serverDataHandler.handleLogin(newPlayer);
|
||||
boolean isNewPlayer = activityHandler.isFirstTimeJoin(uuid);
|
||||
if (isNewPlayer) {
|
||||
newPlayer(player);
|
||||
}
|
||||
serverDataHandler.handleLogin(isNewPlayer);
|
||||
UserData data = getCurrentData(uuid);
|
||||
activityHandler.handleReload(player, data);
|
||||
basicInfoHandler.handleReload(player, data);
|
||||
gamemodeTimesHandler.handleReload(player, data);
|
||||
demographicsHandler.handleReload(player, data);
|
||||
saveCachedData(uuid);
|
||||
}
|
||||
}
|
62
Plan Advanced/src/com/djrapitops/plan/data/cache/InspectCacheHandler.java
vendored
Normal file
62
Plan Advanced/src/com/djrapitops/plan/data/cache/InspectCacheHandler.java
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
package com.djrapitops.plan.data.cache;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class InspectCacheHandler {
|
||||
|
||||
private DataCacheHandler handler;
|
||||
private Plan plugin;
|
||||
private HashMap<UUID, UserData> cache;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param plugin Current instance of Plan.class
|
||||
*/
|
||||
public InspectCacheHandler(Plan plugin) {
|
||||
this.handler = plugin.getHandler();
|
||||
this.plugin = plugin;
|
||||
this.cache = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches the UserData of user to the HashMap for 5 minutes. Data is removed
|
||||
* from the cache automatically after 5 minutes with a BukkitRunnable
|
||||
*
|
||||
* @param uuid UUID of the player
|
||||
*/
|
||||
public void cache(UUID uuid) {
|
||||
if (!handler.getDB().wasSeenBefore(uuid)) {
|
||||
return;
|
||||
}
|
||||
cache.put(uuid, handler.getCurrentData(uuid, false));
|
||||
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
clearFomCache(uuid);
|
||||
}
|
||||
}, 60 * 20 * 3);
|
||||
}
|
||||
|
||||
private void clearFomCache(UUID uuid) {
|
||||
cache.remove(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the cache for UserData matching UUID
|
||||
*
|
||||
* @param uuid UUID of the Player
|
||||
* @return UserData that matches the player, null if not cached.
|
||||
*/
|
||||
public UserData getFromCache(UUID uuid) {
|
||||
return cache.get(uuid);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ActivityHandler {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataCacheHandler handler;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
* @param h Current instance of DataCacheHandler
|
||||
*/
|
||||
public ActivityHandler(Plan plugin, DataCacheHandler h) {
|
||||
this.plugin = plugin;
|
||||
this.handler = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks from Database if the player's data is present.
|
||||
*
|
||||
* @param uuid Player's UUID
|
||||
* @return true if data is not found.
|
||||
*/
|
||||
public boolean isFirstTimeJoin(UUID uuid) {
|
||||
return !handler.getDB().wasSeenBefore(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves current PlayTime timer and sets lastPlayed.
|
||||
*
|
||||
* lastPlayed is set to long matching current Date.
|
||||
*
|
||||
* @param player Player which data is being saved
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void saveToCache(Player player, UserData data) {
|
||||
long timeNow = new Date().getTime();
|
||||
data.setPlayTime(data.getPlayTime() + (timeNow - data.getLastPlayed()));
|
||||
data.setLastPlayed(timeNow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates UserData about activity related things on Login.
|
||||
*
|
||||
* Updates if player is banned or not, Adds one to login times, Adds current
|
||||
* location to location list.
|
||||
*
|
||||
* @param event JoinEvent from listener
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void handleLogin(PlayerJoinEvent event, UserData data) {
|
||||
data.setLastPlayed(new Date().getTime());
|
||||
Player player = event.getPlayer();
|
||||
data.updateBanned(player);
|
||||
data.setLoginTimes(data.getLoginTimes() + 1);
|
||||
handler.getLocationHandler().addLocation(player.getUniqueId(), player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates UserData about activity related things on Logout.
|
||||
*
|
||||
* Saves PlayTime, Set's LastPlayed
|
||||
* value to long matching current Date
|
||||
*
|
||||
* @param event QuitEvent from Listener
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void handleLogOut(PlayerQuitEvent event, UserData data) {
|
||||
long timeNow = new Date().getTime();
|
||||
data.setPlayTime(data.getPlayTime() + (timeNow - data.getLastPlayed()));
|
||||
data.setLastPlayed(timeNow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates UserData about activity related things on /reload.
|
||||
*
|
||||
* Updates PlayTime, Sets LastPlayed value to long matching current Date
|
||||
*
|
||||
* @param player Player who is online
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void handleReload(Player player, UserData data) {
|
||||
long timeNow = new Date().getTime();
|
||||
data.setPlayTime(data.getPlayTime() + (timeNow - data.getLastPlayed()));
|
||||
data.setLastPlayed(timeNow);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BasicInfoHandler {
|
||||
|
||||
private DataCacheHandler handler;
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
* @param plugin Current instance of Plan
|
||||
* @param h Current instance of DataCacheHandler
|
||||
*/
|
||||
public BasicInfoHandler(Plan plugin, DataCacheHandler h) {
|
||||
this.handler = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new nicknames and IPs to UserData
|
||||
* @param event JoinEvent to get the Player
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void handleLogin(PlayerJoinEvent event, UserData data) {
|
||||
Player player = event.getPlayer();
|
||||
data.addNickname(player.getDisplayName());
|
||||
data.addIpAddress(player.getAddress().getAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new nicknames and IPs to UserData in case of /reload
|
||||
* @param player A player that is online when /reload is run
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void handleReload(Player player, UserData data) {
|
||||
data.addNickname(player.getDisplayName());
|
||||
data.addIpAddress(player.getAddress().getAddress());
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
package com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.Gender;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -15,35 +16,40 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class DemographicsHandler {
|
||||
|
||||
private final DataHandler handler;
|
||||
private final DataCacheHandler handler;
|
||||
|
||||
public DemographicsHandler(Plan plugin, DataHandler h) {
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param plugin Current instance of Plan.class
|
||||
* @param h Current instance of DataCacheHandler h
|
||||
*/
|
||||
public DemographicsHandler(Plan plugin, DataCacheHandler h) {
|
||||
this.handler = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the message for Demographics relevant data
|
||||
*
|
||||
* If message contains triggerwords and words that define data important,
|
||||
* informatino will be saved in the DemographicsData of UserData provided
|
||||
*
|
||||
* @param event The Chat event passed by listener
|
||||
* @param data UserData corresponding to player of this event.
|
||||
*/
|
||||
public void handleChatEvent(AsyncPlayerChatEvent event, UserData data) {
|
||||
Player player = event.getPlayer();
|
||||
// Create lists
|
||||
String[] triggersA = {"i\\'m", "am", "im"};
|
||||
String[] femaleA = {"female", "girl", "gurl", "woman", "gal", "mrs", "she", "miss"};
|
||||
String[] maleA = {"male", "boy", "man", "boe", "sir", "mr", "guy", "he"};
|
||||
String[] ageA = {"years", "year-old", "old"};
|
||||
String[] ignoreA = {"sure", "think", "with", "are"};
|
||||
List<String> triggers = Arrays.asList("i\'m", "am", "im");
|
||||
List<String> female = Arrays.asList("female", "girl", "gurl", "woman", "gal", "mrs", "she", "miss");
|
||||
List<String> male = Arrays.asList("male", "boy", "man", "boe", "sir", "mr", "guy", "he");
|
||||
List<String> ages = Arrays.asList("years", "year-old", "old");
|
||||
List<String> ignore = Arrays.asList("sure", "think", "with", "are");
|
||||
|
||||
Set<String> triggers = new HashSet<>();
|
||||
Set<String> female = new HashSet<>();
|
||||
Set<String> male = new HashSet<>();
|
||||
Set<String> ages = new HashSet<>();
|
||||
Set<String> ignore = new HashSet<>();
|
||||
|
||||
triggers.addAll(Arrays.asList(triggersA));
|
||||
female.addAll(Arrays.asList(femaleA));
|
||||
male.addAll(Arrays.asList(maleA));
|
||||
ages.addAll(Arrays.asList(ageA));
|
||||
ignore.addAll(Arrays.asList(ignoreA));
|
||||
// get message
|
||||
String message = event.getMessage();
|
||||
String[] messageA = message.split("\\s+");
|
||||
|
||||
@ -100,7 +106,16 @@ public class DemographicsHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void handleLogIn(PlayerJoinEvent event, UserData data) {
|
||||
/**
|
||||
* Locates the player upon login
|
||||
*
|
||||
* Uses ip-api.com to locate the IP address If too many calls are made to
|
||||
* the API the IP will be blocked from further calls.
|
||||
*
|
||||
* @param event JoinEvent to get the InetAddress
|
||||
* @param data UserData corresponding the player
|
||||
*/
|
||||
public void handleLogin(PlayerJoinEvent event, UserData data) {
|
||||
InetAddress address = event.getPlayer().getAddress().getAddress();
|
||||
try {
|
||||
Scanner locationScanner = new Scanner("http://ip-api.com/line/" + address.getHostAddress());
|
||||
@ -120,26 +135,4 @@ public class DemographicsHandler {
|
||||
plugin.logToFile(address.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void handleReload(Player player, UserData data) {
|
||||
InetAddress address = player.getAddress().getAddress();
|
||||
try {
|
||||
Scanner locationScanner = new Scanner("http://ip-api.com/line/" + address.getHostAddress());
|
||||
List<String> results = new ArrayList<>();
|
||||
while (locationScanner.hasNextLine()) {
|
||||
results.add(locationScanner.nextLine());
|
||||
}
|
||||
if (results.size() >= 2) {
|
||||
data.getDemData().setGeoLocation(results.get(1));
|
||||
} else {
|
||||
data.getDemData().setGeoLocation("Not Known");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
plugin.logToFile("http://ip-api.com/line/" + address.getHostAddress());
|
||||
plugin.logToFile("" + e);
|
||||
plugin.logToFile(address.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import java.util.HashMap;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class GamemodeTimesHandler {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataCacheHandler handler;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
* @param h Current instance of DataCacheHandler
|
||||
*/
|
||||
public GamemodeTimesHandler(Plan plugin, DataCacheHandler h) {
|
||||
this.plugin = plugin;
|
||||
handler = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates lastGamemode to current gamemode on Login
|
||||
*
|
||||
* @param event JoinEvent from listener
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void handleLogin(PlayerJoinEvent event, UserData data) {
|
||||
data.setLastGamemode(event.getPlayer().getGameMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the GameModeTimes HashMap.
|
||||
*
|
||||
* Updates GMTimes with new values and sets lastSwap and lastGM.
|
||||
*
|
||||
* @param event GMChangeEvent from Listener
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void handleChangeEvent(PlayerGameModeChangeEvent event, UserData data) {
|
||||
HashMap<GameMode, Long> times = data.getGmTimes();
|
||||
handler.getActivityHandler().saveToCache(event.getPlayer(), data);
|
||||
|
||||
long lastSwap = data.getLastGmSwapTime();
|
||||
long playTime = data.getPlayTime();
|
||||
GameMode oldGM = data.getLastGamemode();
|
||||
data.setGMTime(oldGM, times.get(oldGM) + (playTime - lastSwap));
|
||||
|
||||
GameMode newGM = event.getNewGameMode();
|
||||
data.setLastGamemode(newGM);
|
||||
|
||||
data.setLastGmSwapTime(playTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates GMTimes with new values and saves it to cache.
|
||||
*
|
||||
* @param player Player whose data is being saved
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void saveToCache(Player player, UserData data) {
|
||||
HashMap<GameMode, Long> times = data.getGmTimes();
|
||||
handler.getActivityHandler().saveToCache(player, data);
|
||||
|
||||
long lastSwap = data.getLastGmSwapTime();
|
||||
long playtime = data.getPlayTime();
|
||||
GameMode currentGM = player.getGameMode();
|
||||
data.setGMTime(currentGM, times.get(currentGM) + (playtime - lastSwap));
|
||||
|
||||
data.setLastGmSwapTime(playtime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates GMTImes for player who is online when /reload is run.
|
||||
*
|
||||
* @param player Player whose data is updated
|
||||
* @param data UserData matching Player
|
||||
*/
|
||||
public void handleReload(Player player, UserData data) {
|
||||
saveToCache(player, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates GMTimes on Logout.
|
||||
*
|
||||
* @param event QuitEvent from Listener
|
||||
* @param data UserData matching Player
|
||||
*/
|
||||
public void handleLogOut(PlayerQuitEvent event, UserData data) {
|
||||
saveToCache(event.getPlayer(), data);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
package com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Location;
|
||||
@ -10,9 +11,9 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class LocationHandler {
|
||||
|
||||
private final DataHandler handler;
|
||||
private final DataCacheHandler handler;
|
||||
|
||||
public LocationHandler(Plan plugin, DataHandler h) {
|
||||
public LocationHandler(Plan plugin, DataCacheHandler h) {
|
||||
this.handler = h;
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.database.Database;
|
||||
import com.djrapitops.plan.data.DemographicsData;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import java.util.Date;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class NewPlayerCreator {
|
||||
|
||||
private Plan plugin;
|
||||
private Database db;
|
||||
private DataCacheHandler handler;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* Gets the Database from the plugin.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
* @param h Current instance of DataCacheHandler
|
||||
*/
|
||||
public NewPlayerCreator(Plan plugin, DataCacheHandler h) {
|
||||
this.plugin = plugin;
|
||||
db = plugin.getDB();
|
||||
handler = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of UserData with default values and saves it to
|
||||
* DB.
|
||||
*
|
||||
* @param player Player the UserData is created for.
|
||||
*/
|
||||
public void createNewPlayer(Player player) {
|
||||
UserData data = new UserData(player, new DemographicsData(), db);
|
||||
if (player.getGameMode() == null) {
|
||||
GameMode defaultGM = Bukkit.getServer().getDefaultGameMode();
|
||||
if (defaultGM != null) {
|
||||
data.setLastGamemode(defaultGM);
|
||||
} else {
|
||||
data.setLastGamemode(GameMode.SURVIVAL);
|
||||
}
|
||||
} else {
|
||||
data.setLastGamemode(player.getGameMode());
|
||||
}
|
||||
data.setLastPlayed(new Date().getTime());
|
||||
long zero = Long.parseLong("0");
|
||||
data.setPlayTime(zero);
|
||||
data.setTimesKicked(0);
|
||||
data.setLoginTimes(0);
|
||||
data.setLastGmSwapTime(zero);
|
||||
db.saveUserData(player.getUniqueId(), data);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
package com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanLiteHook;
|
@ -0,0 +1,52 @@
|
||||
package com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import java.util.Date;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class RuleBreakingHandler {
|
||||
|
||||
private final DataCacheHandler handler;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
* @param h Current instance of DataCacheHandler
|
||||
*/
|
||||
public RuleBreakingHandler(Plan plugin, DataCacheHandler h) {
|
||||
this.handler = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update if player is banned or not.
|
||||
*
|
||||
* @param event QuitEvent given by Listener
|
||||
* @param data UserData matching Player
|
||||
*/
|
||||
public void handleLogout(PlayerQuitEvent event, UserData data) {
|
||||
Player player = event.getPlayer();
|
||||
data.updateBanned(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update if player is banned or not.
|
||||
*
|
||||
* @param event KickEvent given by Listener
|
||||
* @param data UserData matching Player
|
||||
*/
|
||||
public void handleKick(PlayerKickEvent event, UserData data) {
|
||||
Player player = event.getPlayer();
|
||||
data.setTimesKicked(data.getTimesKicked() + 1);
|
||||
data.setPlayTime(data.getPlayTime() + (new Date().getTime() - data.getLastPlayed()));
|
||||
data.setLastPlayed(new Date().getTime());
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
package com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.database.ServerData;
|
||||
import com.djrapitops.plan.data.ServerData;
|
||||
|
||||
public class ServerDataHandler {
|
||||
private ServerData serverData;
|
@ -1,9 +1,9 @@
|
||||
package com.djrapitops.plan.datahandlers.listeners;
|
||||
package com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.datahandlers.DataHandler;
|
||||
import com.djrapitops.plan.datahandlers.DemographicsHandler;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.data.handlers.DemographicsHandler;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -13,7 +13,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
public class PlanChatListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataHandler handler;
|
||||
private final DataCacheHandler handler;
|
||||
private final DemographicsHandler demographicsHandler;
|
||||
|
||||
public PlanChatListener(Plan plugin) {
|
@ -1,8 +1,8 @@
|
||||
package com.djrapitops.plan.datahandlers.listeners;
|
||||
package com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.datahandlers.DataHandler;
|
||||
import com.djrapitops.plan.datahandlers.ServerDataHandler;
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.data.handlers.ServerDataHandler;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -11,7 +11,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
public class PlanCommandPreprocessListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataHandler handler;
|
||||
private final DataCacheHandler handler;
|
||||
private final ServerDataHandler serverH;
|
||||
|
||||
public PlanCommandPreprocessListener(Plan plugin) {
|
@ -1,9 +1,9 @@
|
||||
package com.djrapitops.plan.datahandlers.listeners;
|
||||
package com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.datahandlers.DataHandler;
|
||||
import com.djrapitops.plan.datahandlers.GamemodeTimesHandler;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.data.handlers.GamemodeTimesHandler;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -13,7 +13,7 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
public class PlanGamemodeChangeListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataHandler handler;
|
||||
private final DataCacheHandler handler;
|
||||
private final GamemodeTimesHandler gmTimesH;
|
||||
|
||||
public PlanGamemodeChangeListener(Plan plugin) {
|
@ -1,15 +1,9 @@
|
||||
package com.djrapitops.plan.datahandlers.listeners;
|
||||
package com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.datahandlers.ActivityHandler;
|
||||
import com.djrapitops.plan.datahandlers.DataHandler;
|
||||
import com.djrapitops.plan.datahandlers.DemographicsHandler;
|
||||
import com.djrapitops.plan.datahandlers.LocationHandler;
|
||||
import com.djrapitops.plan.datahandlers.RuleBreakingHandler;
|
||||
import com.djrapitops.plan.datahandlers.ServerDataHandler;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import com.djrapitops.plan.datahandlers.BasicInfoHandler;
|
||||
import com.djrapitops.plan.datahandlers.GamemodeTimesHandler;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.data.handlers.*;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -17,12 +11,15 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlanPlayerListener implements Listener {
|
||||
|
||||
private final DataHandler handler;
|
||||
private final DataCacheHandler handler;
|
||||
private final ActivityHandler activityH;
|
||||
private final BasicInfoHandler basicInfoH;
|
||||
private final GamemodeTimesHandler gmTimesH;
|
||||
@ -31,6 +28,14 @@ public class PlanPlayerListener implements Listener {
|
||||
private final RuleBreakingHandler rulebreakH;
|
||||
private final ServerDataHandler serverHandler;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* Copies the references to multiple handlers from Current instance of
|
||||
* handler.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public PlanPlayerListener(Plan plugin) {
|
||||
handler = plugin.getHandler();
|
||||
activityH = handler.getActivityHandler();
|
||||
@ -42,6 +47,14 @@ public class PlanPlayerListener implements Listener {
|
||||
serverHandler = handler.getServerDataHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerJoinEvent Listener.
|
||||
*
|
||||
* If player is a new player, creates a new data in the database for the
|
||||
* player. Retrieves the UserData, updates and then saves it to the Cache.
|
||||
*
|
||||
* @param event The Fired event.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerLogin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@ -52,13 +65,21 @@ public class PlanPlayerListener implements Listener {
|
||||
}
|
||||
serverHandler.handleLogin(isNewPlayer);
|
||||
UserData data = handler.getCurrentData(uuid);
|
||||
activityH.handleLogIn(event, data);
|
||||
basicInfoH.handleLogIn(event, data);
|
||||
activityH.handleLogin(event, data);
|
||||
basicInfoH.handleLogin(event, data);
|
||||
gmTimesH.handleLogin(event, data);
|
||||
demographicH.handleLogIn(event, data);
|
||||
demographicH.handleLogin(event, data);
|
||||
handler.saveCachedData(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerQuitEvent Listener.
|
||||
*
|
||||
* Retrieves the current UserData for the Player, updates it, saves the data
|
||||
* to Database and clears it from cache.
|
||||
*
|
||||
* @param event Fired event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
@ -71,6 +92,13 @@ public class PlanPlayerListener implements Listener {
|
||||
handler.clearFromCache(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerKickEvent Listener.
|
||||
*
|
||||
* Updates current playerdata and saves it to the Database.
|
||||
*
|
||||
* @param event Fired event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
if (event.isCancelled()) {
|
@ -1,8 +1,8 @@
|
||||
package com.djrapitops.plan.datahandlers.listeners;
|
||||
package com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.datahandlers.DataHandler;
|
||||
import com.djrapitops.plan.datahandlers.LocationHandler;
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import com.djrapitops.plan.data.handlers.LocationHandler;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -13,7 +13,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
public class PlanPlayerMoveListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataHandler handler;
|
||||
private final DataCacheHandler handler;
|
||||
private final LocationHandler locationH;
|
||||
|
||||
public PlanPlayerMoveListener(Plan plugin) {
|
@ -1,5 +1,7 @@
|
||||
package com.djrapitops.plan.database;
|
||||
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import com.djrapitops.plan.data.ServerData;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
|
@ -2,11 +2,8 @@ package com.djrapitops.plan.database.databases;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.Gender;
|
||||
import com.djrapitops.plan.command.utils.MiscUtils;
|
||||
import com.djrapitops.plan.database.Database;
|
||||
import com.djrapitops.plan.database.DemographicsData;
|
||||
import com.djrapitops.plan.database.ServerData;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import com.djrapitops.plan.data.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.sql.Connection;
|
||||
@ -51,6 +48,7 @@ public abstract class SQLDB extends Database {
|
||||
private String userColumnLastGM;
|
||||
private String userColumnLastGMSwapTime;
|
||||
private String userColumnLoginTimes;
|
||||
private String userColumnLastPlayed;
|
||||
private final String locationColumnUserID;
|
||||
private String locationColumnID;
|
||||
private String locationColumnCoordinatesX;
|
||||
@ -62,8 +60,10 @@ public abstract class SQLDB extends Database {
|
||||
private String commanduseColumnCommand;
|
||||
private String commanduseColumnTimesUsed;
|
||||
private final String gamemodetimesColumnUserID;
|
||||
private String gamemodetimesColumnGamemode;
|
||||
private String gamemodetimesColumnTime;
|
||||
private String gamemodetimesColumnSurvivalTime;
|
||||
private String gamemodetimesColumnCreativeTime;
|
||||
private String gamemodetimesColumnAdventureTime;
|
||||
private String gamemodetimesColumnSpectatorTime;
|
||||
private String nicknamesColumnUserID;
|
||||
private String nicknamesColumnNick;
|
||||
private final String ipsColumnUserID;
|
||||
@ -99,6 +99,7 @@ public abstract class SQLDB extends Database {
|
||||
userColumnLastGMSwapTime = "last_gamemode_swap";
|
||||
userColumnPlayTime = "play_time";
|
||||
userColumnLoginTimes = "login_times";
|
||||
userColumnLastPlayed = "last_played";
|
||||
|
||||
locationColumnCoordinatesX = "x";
|
||||
locationColumnCoordinatesZ = "z";
|
||||
@ -106,8 +107,10 @@ public abstract class SQLDB extends Database {
|
||||
|
||||
nicknamesColumnNick = "nickname";
|
||||
|
||||
gamemodetimesColumnGamemode = "gamemode";
|
||||
gamemodetimesColumnTime = "time";
|
||||
gamemodetimesColumnSurvivalTime = "survival";
|
||||
gamemodetimesColumnCreativeTime = "creative";
|
||||
gamemodetimesColumnAdventureTime = "adventure";
|
||||
gamemodetimesColumnSpectatorTime = "spectator";
|
||||
|
||||
ipsColumnIP = "ip";
|
||||
|
||||
@ -164,7 +167,8 @@ public abstract class SQLDB extends Database {
|
||||
+ userColumnLastGM + " varchar(15) NOT NULL, "
|
||||
+ userColumnLastGMSwapTime + " bigint NOT NULL, "
|
||||
+ userColumnPlayTime + " bigint NOT NULL, "
|
||||
+ userColumnLoginTimes + " int NOT NULL"
|
||||
+ userColumnLoginTimes + " int NOT NULL, "
|
||||
+ userColumnLastPlayed + " bigint NOT NULL"
|
||||
+ ")"
|
||||
);
|
||||
|
||||
@ -180,8 +184,10 @@ public abstract class SQLDB extends Database {
|
||||
|
||||
query("CREATE TABLE IF NOT EXISTS " + gamemodetimesName + " ("
|
||||
+ gamemodetimesColumnUserID + " int NOT NULL, "
|
||||
+ gamemodetimesColumnGamemode + " varchar(15) NOT NULL, "
|
||||
+ gamemodetimesColumnTime + " bigint NOT NULL, "
|
||||
+ gamemodetimesColumnSurvivalTime + " bigint NOT NULL, "
|
||||
+ gamemodetimesColumnCreativeTime + " bigint NOT NULL, "
|
||||
+ gamemodetimesColumnAdventureTime + " bigint NOT NULL, "
|
||||
+ gamemodetimesColumnSpectatorTime + " bigint NOT NULL, "
|
||||
+ "FOREIGN KEY(" + gamemodetimesColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
|
||||
+ ")"
|
||||
);
|
||||
@ -321,10 +327,11 @@ public abstract class SQLDB extends Database {
|
||||
data.getDemData().setAge(set.getInt(userColumnDemAge));
|
||||
data.getDemData().setGender(Gender.parse(set.getString(userColumnDemGender)));
|
||||
data.getDemData().setGeoLocation(set.getString(userColumnDemGeoLocation));
|
||||
data.setLastGamemode(MiscUtils.parseGM(set.getString(userColumnLastGM)));
|
||||
data.setLastGamemode(GameMode.valueOf(set.getString(userColumnLastGM)));
|
||||
data.setLastGmSwapTime(set.getLong(userColumnLastGMSwapTime));
|
||||
data.setPlayTime(set.getLong(userColumnPlayTime));
|
||||
data.setLoginTimes(set.getInt(userColumnLoginTimes));
|
||||
data.setLastPlayed(set.getLong(userColumnLastPlayed));
|
||||
}
|
||||
set.close();
|
||||
statement.close();
|
||||
@ -380,7 +387,10 @@ public abstract class SQLDB extends Database {
|
||||
|
||||
HashMap<GameMode, Long> times = new HashMap<>();
|
||||
while (set.next()) {
|
||||
times.put(GameMode.valueOf(set.getString(gamemodetimesColumnGamemode)), set.getLong(gamemodetimesColumnTime));
|
||||
times.put(GameMode.SURVIVAL, set.getLong(gamemodetimesColumnSurvivalTime));
|
||||
times.put(GameMode.CREATIVE, set.getLong(gamemodetimesColumnCreativeTime));
|
||||
times.put(GameMode.ADVENTURE, set.getLong(gamemodetimesColumnAdventureTime));
|
||||
times.put(GameMode.SPECTATOR, set.getLong(gamemodetimesColumnSpectatorTime));
|
||||
}
|
||||
set.close();
|
||||
statement.close();
|
||||
@ -530,7 +540,8 @@ public abstract class SQLDB extends Database {
|
||||
+ userColumnLastGM + "=?, "
|
||||
+ userColumnLastGMSwapTime + "=?, "
|
||||
+ userColumnPlayTime + "=?, "
|
||||
+ userColumnLoginTimes + "=? "
|
||||
+ userColumnLoginTimes + "=?, "
|
||||
+ userColumnLastPlayed + "=? "
|
||||
+ "WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)";
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(sql);
|
||||
@ -546,7 +557,8 @@ public abstract class SQLDB extends Database {
|
||||
statement.setLong(5, data.getLastGmSwapTime());
|
||||
statement.setLong(6, data.getPlayTime());
|
||||
statement.setInt(7, data.getLoginTimes());
|
||||
statement.setString(8, uuid.toString());
|
||||
statement.setLong(8, data.getLastPlayed());
|
||||
statement.setString(9, uuid.toString());
|
||||
update = statement.executeUpdate();
|
||||
}
|
||||
if (update == 0) {
|
||||
@ -558,8 +570,9 @@ public abstract class SQLDB extends Database {
|
||||
+ userColumnLastGM + ", "
|
||||
+ userColumnLastGMSwapTime + ", "
|
||||
+ userColumnPlayTime + ", "
|
||||
+ userColumnLoginTimes
|
||||
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
+ userColumnLoginTimes +", "
|
||||
+ userColumnLastPlayed
|
||||
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setInt(2, data.getDemData().getAge());
|
||||
@ -574,6 +587,7 @@ public abstract class SQLDB extends Database {
|
||||
statement.setLong(6, data.getLastGmSwapTime());
|
||||
statement.setLong(7, data.getPlayTime());
|
||||
statement.setInt(8, data.getLoginTimes());
|
||||
statement.setLong(9, data.getLastPlayed());
|
||||
|
||||
statement.execute();
|
||||
statement.close();
|
||||
@ -682,19 +696,21 @@ public abstract class SQLDB extends Database {
|
||||
statement.execute();
|
||||
statement.close();
|
||||
|
||||
for (GameMode gm : gamemodeTimes.keySet()) {
|
||||
statement = connection.prepareStatement("INSERT INTO " + gamemodetimesName + " ("
|
||||
+ gamemodetimesColumnUserID + ", "
|
||||
+ gamemodetimesColumnGamemode + ", "
|
||||
+ gamemodetimesColumnTime
|
||||
+ ") VALUES (?, ?, ?)");
|
||||
statement = connection.prepareStatement("INSERT INTO " + gamemodetimesName + " ("
|
||||
+ gamemodetimesColumnUserID + ", "
|
||||
+ gamemodetimesColumnSurvivalTime + ", "
|
||||
+ gamemodetimesColumnCreativeTime + ", "
|
||||
+ gamemodetimesColumnAdventureTime + ", "
|
||||
+ gamemodetimesColumnSpectatorTime
|
||||
+ ") VALUES (?, ?, ?, ?, ?)");
|
||||
|
||||
statement.setInt(1, userId);
|
||||
statement.setString(2, gm.name());
|
||||
statement.setLong(3, gamemodeTimes.get(gm));
|
||||
statement.execute();
|
||||
statement.close();
|
||||
}
|
||||
statement.setInt(1, userId);
|
||||
statement.setLong(2, gamemodeTimes.get(GameMode.SURVIVAL));
|
||||
statement.setLong(3, gamemodeTimes.get(GameMode.CREATIVE));
|
||||
statement.setLong(4, gamemodeTimes.get(GameMode.ADVENTURE));
|
||||
statement.setLong(5, gamemodeTimes.get(GameMode.SPECTATOR));
|
||||
statement.execute();
|
||||
statement.close();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@ -811,12 +827,24 @@ public abstract class SQLDB extends Database {
|
||||
this.commanduseColumnTimesUsed = commanduseColumnTimesUsed;
|
||||
}
|
||||
|
||||
public void setGamemodetimesColumnGamemode(String gamemodetimesColumnGamemode) {
|
||||
this.gamemodetimesColumnGamemode = gamemodetimesColumnGamemode;
|
||||
public void setUserColumnLoginTimes(String userColumnLoginTimes) {
|
||||
this.userColumnLoginTimes = userColumnLoginTimes;
|
||||
}
|
||||
|
||||
public void setGamemodetimesColumnTime(String gamemodetimesColumnTime) {
|
||||
this.gamemodetimesColumnTime = gamemodetimesColumnTime;
|
||||
public void setGamemodetimesColumnSurvivalTime(String gamemodetimesColumnSurvivalTime) {
|
||||
this.gamemodetimesColumnSurvivalTime = gamemodetimesColumnSurvivalTime;
|
||||
}
|
||||
|
||||
public void setGamemodetimesColumnCreativeTime(String gamemodetimesColumnCreativeTime) {
|
||||
this.gamemodetimesColumnCreativeTime = gamemodetimesColumnCreativeTime;
|
||||
}
|
||||
|
||||
public void setGamemodetimesColumnAdventureTime(String gamemodetimesColumnAdventureTime) {
|
||||
this.gamemodetimesColumnAdventureTime = gamemodetimesColumnAdventureTime;
|
||||
}
|
||||
|
||||
public void setGamemodetimesColumnSpectatorTime(String gamemodetimesColumnSpectatorTime) {
|
||||
this.gamemodetimesColumnSpectatorTime = gamemodetimesColumnSpectatorTime;
|
||||
}
|
||||
|
||||
public void setNicknamesColumnUserID(String nicknamesColumnUserID) {
|
||||
|
@ -1,51 +0,0 @@
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class ActivityHandler {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataHandler handler;
|
||||
|
||||
public ActivityHandler(Plan plugin, DataHandler h) {
|
||||
this.plugin = plugin;
|
||||
this.handler = h;
|
||||
}
|
||||
|
||||
public boolean isFirstTimeJoin(UUID uuid) {
|
||||
return !handler.getDB().wasSeenBefore(uuid);
|
||||
}
|
||||
|
||||
public void saveToCache(Player player, UserData data) {
|
||||
long timeNow = new Date().getTime();
|
||||
data.setPlayTime(data.getPlayTime() + (timeNow - data.getLastPlayed()));
|
||||
data.setLastPlayed(timeNow);
|
||||
}
|
||||
|
||||
public void handleLogIn(PlayerJoinEvent event, UserData data) {
|
||||
data.setLastPlayed(new Date().getTime());
|
||||
Player player = event.getPlayer();
|
||||
data.updateBanned(player);
|
||||
data.setLoginTimes(data.getLoginTimes()+1);
|
||||
handler.getLocationHandler().addLocation(player.getUniqueId(), player.getLocation());
|
||||
}
|
||||
|
||||
public void handleLogOut(PlayerQuitEvent event, UserData data) {
|
||||
Player player = event.getPlayer();
|
||||
long now = new Date().getTime();
|
||||
data.setPlayTime(data.getPlayTime() + (now - data.getLastPlayed()));
|
||||
data.setLastPlayed(now);
|
||||
}
|
||||
|
||||
void handleReload(Player player, UserData data) {
|
||||
long now = new Date().getTime();
|
||||
data.setPlayTime(data.getPlayTime() + (now - data.getLastPlayed()));
|
||||
data.setLastPlayed(now);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class BasicInfoHandler {
|
||||
|
||||
private DataHandler handler;
|
||||
|
||||
public BasicInfoHandler(Plan plugin, DataHandler h) {
|
||||
this.handler = h;
|
||||
}
|
||||
|
||||
public void handleLogIn(PlayerJoinEvent event, UserData data) {
|
||||
Player player = event.getPlayer();
|
||||
data.addNickname(player.getDisplayName());
|
||||
data.addIpAddress(player.getAddress().getAddress());
|
||||
}
|
||||
|
||||
void handleReload(Player player, UserData data) {
|
||||
data.addNickname(player.getDisplayName());
|
||||
data.addIpAddress(player.getAddress().getAddress());
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import java.util.HashMap;
|
||||
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 {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataHandler handler;
|
||||
|
||||
public GamemodeTimesHandler(Plan plugin, DataHandler h) {
|
||||
this.plugin = plugin;
|
||||
handler = h;
|
||||
}
|
||||
|
||||
public void handleLogin(PlayerJoinEvent event, UserData data) {
|
||||
data.setLastGamemode(event.getPlayer().getGameMode());
|
||||
}
|
||||
|
||||
public void handleChangeEvent(PlayerGameModeChangeEvent event, UserData data) {
|
||||
HashMap<GameMode, Long> times = data.getGmTimes();
|
||||
handler.getActivityHandler().saveToCache(event.getPlayer(), data);
|
||||
|
||||
long lastSwap = data.getLastGmSwapTime();
|
||||
long playTime = data.getPlayTime();
|
||||
GameMode oldGM = data.getLastGamemode();
|
||||
data.setGMTime(oldGM, times.get(oldGM) + (playTime - lastSwap));
|
||||
|
||||
GameMode newGM = event.getNewGameMode();
|
||||
data.setLastGamemode(newGM);
|
||||
|
||||
data.setLastGmSwapTime(playTime);
|
||||
}
|
||||
|
||||
void saveToCache(Player p, UserData data) {
|
||||
HashMap<GameMode, Long> times = data.getGmTimes();
|
||||
handler.getActivityHandler().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);
|
||||
}
|
||||
|
||||
void handleReload(Player p, UserData data) {
|
||||
saveToCache(p, data);
|
||||
}
|
||||
|
||||
public void handleLogOut(PlayerQuitEvent event, UserData data) {
|
||||
saveToCache(event.getPlayer(), data);
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.database.Database;
|
||||
import com.djrapitops.plan.database.DemographicsData;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class NewPlayerCreator {
|
||||
|
||||
private Plan plugin;
|
||||
private Database db;
|
||||
private DataHandler handler;
|
||||
|
||||
public NewPlayerCreator(Plan plugin, DataHandler h) {
|
||||
this.plugin = plugin;
|
||||
db = plugin.getDB();
|
||||
handler = h;
|
||||
}
|
||||
|
||||
public void createNewPlayer(Player p) {
|
||||
UserData data = new UserData(p, new DemographicsData(), db);
|
||||
if (p.getGameMode() == null) {
|
||||
GameMode defaultGM = Bukkit.getServer().getDefaultGameMode();
|
||||
if (defaultGM != null) {
|
||||
data.setLastGamemode(defaultGM);
|
||||
} else {
|
||||
data.setLastGamemode(GameMode.SURVIVAL);
|
||||
}
|
||||
} else {
|
||||
data.setLastGamemode(p.getGameMode());
|
||||
}
|
||||
long zero = Long.parseLong("0");
|
||||
data.setPlayTime(zero);
|
||||
data.setTimesKicked(0);
|
||||
data.setLoginTimes(0);
|
||||
data.setLastGmSwapTime(zero);
|
||||
db.saveUserData(p.getUniqueId(), data);
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.djrapitops.plan.datahandlers;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.database.UserData;
|
||||
import java.util.Date;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class RuleBreakingHandler {
|
||||
|
||||
private final DataHandler handler;
|
||||
|
||||
public RuleBreakingHandler(Plan plugin, DataHandler h) {
|
||||
this.handler = h;
|
||||
}
|
||||
|
||||
public void handleLogout(PlayerQuitEvent event, UserData data) {
|
||||
Player player = event.getPlayer();
|
||||
data.updateBanned(player);
|
||||
}
|
||||
|
||||
public void handleKick(PlayerKickEvent event, UserData data) {
|
||||
Player player = event.getPlayer();
|
||||
data.setTimesKicked(data.getTimesKicked()+1);
|
||||
data.setPlayTime(data.getPlayTime()+(data.getLastPlayed()-new Date().getTime()));
|
||||
data.setLastPlayed(player.getLastPlayed());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user