mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-01 21:11:23 +01:00
Added Manage Import command, Command aliases, small phrasing changes [2.3.0-SNAPSHOT]
- Added Manage Import command that can be used to import data to the database from other plugins. Currently supports only ontime. - Added aliases to analyze and manage command - Added OfflinePlayer object support to NewPlayerCreator
This commit is contained in:
parent
7da6a99dd7
commit
369b20aa9b
@ -18,6 +18,12 @@
|
||||
<version>1.6.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.edge209</groupId>
|
||||
<artifactId>ontime</artifactId>
|
||||
<version>4.1.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.charts4j</groupId>
|
||||
<artifactId>charts4j</artifactId>
|
||||
|
@ -34,6 +34,8 @@ public enum Phrase {
|
||||
ERROR_NO_DATA_VIEW(ChatColor.YELLOW + "Webserver disabled but Alternative IP/PlanLite not used, no way to view data!"),
|
||||
ERROR_WEBSERVER_OFF_ANALYSIS(ChatColor.YELLOW + "[Plan] This command can be only used if the webserver is running on this server."),
|
||||
ERROR_WEBSERVER_OFF_INSPECT(ChatColor.YELLOW + "[Plan] This command can be only used if webserver/planlite is enabled on this server."),
|
||||
MANAGE_ERROR_INCORRECT_PLUGIN(ChatColor.RED+"[Plan] Plugin not supported: "),
|
||||
MANAGE_ERROR_PLUGIN_NOT_ENABLED(ChatColor.RED+"[Plan] Plugin is not enabled: "),
|
||||
MANAGE_ERROR_INCORRECT_DB(ChatColor.RED+"[Plan] Incorrect database! (sqlite/mysql accepted): "),
|
||||
MANAGE_ERROR_SAME_DB(ChatColor.RED+"[Plan] Can't move to the same database!"),
|
||||
MANAGE_DATABASE_FAILURE(ChatColor.RED+"[Plan] One of the databases was not initialized properly."),
|
||||
|
@ -24,11 +24,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
Placeholder API
|
||||
Immutable InspectCache ?
|
||||
Recent players 25%
|
||||
Manage command
|
||||
- Import data from sqlite > mysql and other way around
|
||||
- Move data from __
|
||||
- Remove player's data
|
||||
- Import data with PlanLite
|
||||
Database cleaning
|
||||
PlanLite Top 20 richest 25%
|
||||
PlanLite Top 20 most votes 25%
|
||||
|
@ -30,7 +30,7 @@ public class AnalyzeCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public AnalyzeCommand(Plan plugin) {
|
||||
super("analyze", "plan.analyze", "View the Server Analysis", CommandType.CONSOLE, "");
|
||||
super("analyze, analyse, analysis", "plan.analyze", "View the Server Analysis", CommandType.CONSOLE, "");
|
||||
this.plugin = plugin;
|
||||
analysisCache = plugin.getAnalysisCache();
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ManageCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageCommand(Plan plugin) {
|
||||
super("manage", "plan.manage", "Database managment command", CommandType.CONSOLE, "");
|
||||
super("manage, m", "plan.manage", "Database managment command", CommandType.CONSOLE, "");
|
||||
this.plugin = plugin;
|
||||
commands = new ArrayList<>();
|
||||
commands.add(new ManageHelpCommand(plugin, this));
|
||||
@ -37,6 +37,7 @@ public class ManageCommand extends SubCommand {
|
||||
commands.add(new ManageCombineCommand(plugin));
|
||||
commands.add(new ManageHotswapCommand(plugin));
|
||||
commands.add(new ManageStatusCommand(plugin));
|
||||
commands.add(new ManageImportCommand(plugin));
|
||||
commands.add(new ManageRemoveCommand(plugin));
|
||||
commands.add(new ManageClearCommand(plugin));
|
||||
}
|
||||
@ -68,10 +69,7 @@ public class ManageCommand extends SubCommand {
|
||||
}
|
||||
|
||||
private void sendDefaultCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
String command = "inspect";
|
||||
if (args.length < 1) {
|
||||
command = "help";
|
||||
}
|
||||
String command = "help";
|
||||
onCommand(sender, cmd, commandLabel, FormatUtils.mergeArrays(new String[]{command}, args));
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class ManageCombineCommand extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.toString() + " Data in " + args[1] + "-database will be removed!");
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.toString() + " Data in " + args[1] + "-database will be rewritten!");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -140,17 +140,25 @@ public class ManageCombineCommand extends SubCommand {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
uuids.addAll(toUUIDS);
|
||||
uuids.addAll(fromUUIDS);
|
||||
|
||||
List<UserData> combinedUserData = MiscUtils.combineUserDatas(allFromUserData, allToUserData, uuids);
|
||||
|
||||
HashMap<Long, ServerData> fromServerData = moveFromDB.getServerDataHashMap();
|
||||
HashMap<Long, ServerData> toServerData = moveToDB.getServerDataHashMap();
|
||||
HashMap<Long, ServerData> combinedServerData = MiscUtils.combineServerDatas(fromServerData, toServerData);
|
||||
|
||||
HashMap<String, Integer> commandUse = MiscUtils.combineCommandUses(getCommandUse(fromServerData), getCommandUse(toServerData));
|
||||
|
||||
moveToDB.removeAllData();
|
||||
|
||||
moveToDB.saveServerDataHashMap(combinedServerData);
|
||||
moveToDB.saveMultipleUserData(combinedUserData);
|
||||
moveToDB.saveCommandUse(commandUse);
|
||||
sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS+"");
|
||||
sender.sendMessage(Phrase.MANAGE_DB_CONFIG_REMINDER+"");
|
||||
|
||||
sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS + "");
|
||||
if (!toDB.equals(plugin.getDB().getConfigName())) {
|
||||
sender.sendMessage(Phrase.MANAGE_DB_CONFIG_REMINDER + "");
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,128 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.Phrase;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanLiteHook;
|
||||
import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.importing.Importer;
|
||||
import main.java.com.djrapitops.plan.data.importing.OnTimeImporter;
|
||||
import org.bukkit.Bukkit;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ManageImportCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private PlanLiteHook hook;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageImportCommand(Plan plugin) {
|
||||
super("import", "plan.manage", "Import Data from supported plugins to Active Database.", CommandType.CONSOLE, "<plugin> [-a]");
|
||||
this.plugin = plugin;
|
||||
hook = plugin.getPlanLiteHook();
|
||||
}
|
||||
|
||||
/**
|
||||
* Subcommand inspect.
|
||||
*
|
||||
* Adds player's data from DataCache/DB to the InspectCache for amount of
|
||||
* time specified in the config, and clears the data from Cache with a timer
|
||||
* task.
|
||||
*
|
||||
* @param sender
|
||||
* @param cmd
|
||||
* @param commandLabel
|
||||
* @param args Player's name or nothing - if empty sender's name is used.
|
||||
* @return true in all cases.
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
|
||||
if (args.length < 1) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString() + " Use /plan manage import <plugin> [-a]");
|
||||
return true;
|
||||
}
|
||||
|
||||
String importFromPlugin = args[0].toLowerCase();
|
||||
List<String> supportedImports = Arrays.asList(new String[]{"ontime"});
|
||||
if (!supportedImports.contains(importFromPlugin)) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_PLUGIN + importFromPlugin);
|
||||
return true;
|
||||
}
|
||||
HashMap<String, Importer> importPlugins = new HashMap<>();
|
||||
importPlugins.put("ontime", new OnTimeImporter(plugin));
|
||||
|
||||
if (!importPlugins.get(importFromPlugin).isEnabled()) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_PLUGIN_NOT_ENABLED + importFromPlugin);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.toString() + " Some data in " + plugin.getDB().getConfigName() + "-database will be overwritten!");
|
||||
return true;
|
||||
}
|
||||
|
||||
ChatColor oColor = Phrase.COLOR_MAIN.color();
|
||||
ChatColor hColor = Phrase.COLOR_TER.color();
|
||||
|
||||
// Header
|
||||
sender.sendMessage(hColor + Phrase.ARROWS_RIGHT.toString() + oColor + " Importing Data..");
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
for (OfflinePlayer p : Bukkit.getOfflinePlayers()) {
|
||||
uuids.add(p.getUniqueId());
|
||||
}
|
||||
HashMap<UUID, Long> data = importPlugins.get(importFromPlugin).grabNumericData(uuids);
|
||||
DataCacheHandler handler = plugin.getHandler();
|
||||
if (importFromPlugin.equals("ontime")) {
|
||||
importOnTime(data, handler);
|
||||
}
|
||||
handler.saveCachedUserData();
|
||||
|
||||
// Footer
|
||||
sender.sendMessage(hColor
|
||||
+ Phrase.ARROWS_RIGHT.toString() + oColor + " Success!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void importOnTime(HashMap<UUID, Long> data, DataCacheHandler handler) {
|
||||
for (UUID uuid : data.keySet()) {
|
||||
OfflinePlayer player = getOfflinePlayer(uuid);
|
||||
handler.newPlayer(player);
|
||||
if (handler.getActivityHandler().isFirstTimeJoin(uuid)) {
|
||||
handler.newPlayer(player);
|
||||
}
|
||||
UserData uData = handler.getCurrentData(uuid);
|
||||
Long playTime = data.get(uuid);
|
||||
if (playTime > uData.getPlayTime()) {
|
||||
uData.setPlayTime(playTime);
|
||||
uData.setLastGamemode(GameMode.SURVIVAL);
|
||||
uData.setAllGMTimes(playTime, 0, 0, 0);
|
||||
uData.setLastGmSwapTime(playTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -72,7 +72,7 @@ public class ManageMoveCommand extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.toString() + " Data in " + args[1] + "-database will be removed!");
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.toString() + " Data in " + args[1] + "-database will be overwritten!");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -140,7 +140,9 @@ public class ManageMoveCommand extends SubCommand {
|
||||
moveToDB.saveCommandUse(sData.getCommandUsage());
|
||||
}
|
||||
sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS+"");
|
||||
sender.sendMessage(Phrase.MANAGE_DB_CONFIG_REMINDER+"");
|
||||
if (!toDB.equals(plugin.getDB().getConfigName())) {
|
||||
sender.sendMessage(Phrase.MANAGE_DB_CONFIG_REMINDER+"");
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import static org.bukkit.Bukkit.getPlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -307,6 +308,9 @@ public class DataCacheHandler {
|
||||
public void newPlayer(Player player) {
|
||||
newPlayerCreator.createNewPlayer(player);
|
||||
}
|
||||
public void newPlayer(OfflinePlayer player) {
|
||||
newPlayerCreator.createNewPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The HashMap containing all Cached UserData
|
||||
|
@ -100,5 +100,4 @@ public class GamemodeTimesHandler {
|
||||
public void handleLogOut(PlayerQuitEvent event, UserData data) {
|
||||
saveToCache(event.getPlayer(), data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ 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.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
@ -41,17 +41,16 @@ public class NewPlayerCreator {
|
||||
* @param player Player the UserData is created for.
|
||||
*/
|
||||
public void createNewPlayer(Player player) {
|
||||
createNewPlayer((OfflinePlayer) player, player.getGameMode());
|
||||
}
|
||||
|
||||
public void createNewPlayer(OfflinePlayer player) {
|
||||
createNewPlayer(player, GameMode.SURVIVAL);
|
||||
}
|
||||
|
||||
public void createNewPlayer(OfflinePlayer player, GameMode gm) {
|
||||
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.setLastGamemode(gm);
|
||||
data.setLastPlayed(new Date().getTime());
|
||||
long zero = Long.parseLong("0");
|
||||
data.setPlayTime(zero);
|
||||
|
@ -0,0 +1,15 @@
|
||||
|
||||
package main.java.com.djrapitops.plan.data.importing;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public interface Importer {
|
||||
public HashMap<UUID, Long> grabNumericData(Set<UUID> uuids);
|
||||
public boolean isEnabled();
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package main.java.com.djrapitops.plan.data.importing;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.edge209.OnTime.OnTimeAPI;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OnTimeImporter implements Importer {
|
||||
|
||||
private Plan plugin;
|
||||
private boolean enabled;
|
||||
|
||||
public OnTimeImporter(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
this.enabled = Bukkit.getPluginManager().isPluginEnabled("OnTime");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<UUID, Long> grabNumericData(Set<UUID> uuids) {
|
||||
HashMap<UUID, Long> onTimeData = new HashMap<>();
|
||||
for (OfflinePlayer p : Bukkit.getOfflinePlayers()) {
|
||||
Long playTime = OnTimeAPI.getPlayerTimeData(p.getName(), OnTimeAPI.data.TOTALPLAY);
|
||||
if (playTime != -1) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
onTimeData.put(uuid, playTime);
|
||||
}
|
||||
}
|
||||
return onTimeData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user