Changed permissions for PlanLite plan. > planlite. Begun working on PlanLite features

Analysis and html creation untested for new planlite when planlite is
enabled.
This commit is contained in:
Rsl1122 2017-01-15 14:17:42 +02:00
parent 3ab14a6dd5
commit 2538e32e6d
28 changed files with 486 additions and 343 deletions

View File

@ -3,7 +3,6 @@ package com.djrapitops.planlite;
import com.djrapitops.planlite.command.CommandType;
import com.djrapitops.planlite.command.SubCommand;
import com.djrapitops.planlite.command.commands.AnalyzeCommand;
import com.djrapitops.planlite.command.commands.DebugCommand;
import com.djrapitops.planlite.command.commands.HelpCommand;
import com.djrapitops.planlite.command.commands.InfoCommand;
import com.djrapitops.planlite.command.commands.InspectCommand;
@ -33,7 +32,6 @@ public class PlanCommand implements CommandExecutor {
commands.add(new SearchCommand(plugin));
commands.add(new InfoCommand(plugin));
commands.add(new ReloadCommand(plugin));
commands.add(new DebugCommand(plugin));
}
public List<SubCommand> getCommands() {

View File

@ -32,6 +32,7 @@ public class PlanLite extends JavaPlugin {
private final Map<String, Hook> hooks;
private API api;
private final Map<String, Hook> extraHooks;
private PlanCommand planCommand;
public PlanLite() {
this.hooks = new HashMap<>();
@ -78,8 +79,9 @@ public class PlanLite extends JavaPlugin {
if (!hookFail.isEmpty()) {
Bukkit.getServer().getConsoleSender().sendMessage("[PlanLite] " + failedMsg);
}
planCommand = new PlanCommand(this);
getCommand("plan").setExecutor(new PlanCommand(this));
getCommand("planlite").setExecutor(planCommand);
log("Player Analytics Enabled.");
}
@ -170,4 +172,8 @@ public class PlanLite extends JavaPlugin {
logToFile("Failed to hook " + name + "\n" + e);
}
}
public PlanCommand getPlanCommand() {
return planCommand;
}
}

View File

@ -1,6 +1,5 @@
package com.djrapitops.planlite.command;
//import com.djrapitops.plan.Phrase;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@ -24,7 +24,7 @@ public class AnalyzeCommand extends SubCommand {
private Date refreshDate;
public AnalyzeCommand(PlanLite plugin) {
super("analyze", "plan.analyze", "Analyze data of all players /plan analyze [-refresh]", CommandType.CONSOLE);
super("analyze", "planlite.analyze", "Analyze data of all players /plan analyze [-refresh]", CommandType.CONSOLE);
this.plugin = plugin;
}
@ -34,7 +34,7 @@ public class AnalyzeCommand extends SubCommand {
ChatColor textColor = ChatColor.GRAY;
for (String arg : args) {
if (arg.toLowerCase().equals("-refresh")) {
if (sender.hasPermission("plan.analyze.refresh") || !(sender instanceof Player)) {
if (sender.hasPermission("planlite.analyze.refresh") || !(sender instanceof Player)) {
refreshAnalysisData(sender);
}
}

View File

@ -1,37 +0,0 @@
package com.djrapitops.planlite.command.commands;
import com.djrapitops.planlite.PlanLite;
import com.djrapitops.planlite.command.CommandType;
import com.djrapitops.planlite.command.SubCommand;
import com.djrapitops.planlite.command.utils.DataUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class DebugCommand extends SubCommand {
private PlanLite plugin;
public DebugCommand(PlanLite plugin) {
super("debug", "plan.debug", "Test plugin for possible errors (debug feature)", CommandType.PLAYER);
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (!plugin.getConfig().getBoolean("debug")) {
sender.sendMessage(ChatColor.RED+"[PlanLite] Debug disabled in config");
return true;
}
String[] commands = {"plan", "plan info", "plan reload", "plan inspect",
"plan inspect "+sender.getName()+"-a", "plan inspect reinogiern",
"plan analyze", "plan search", "plan search "+sender.getName()+" -p"};
for (String command : commands) {
Bukkit.dispatchCommand(sender, command);
}
sender.sendMessage(ChatColor.GREEN+"[PlanLite] Debug successful, possible errors written in file.");
return true;
}
}

View File

@ -1,6 +1,5 @@
package com.djrapitops.planlite.command.commands;
//import com.djrapitops.plan.Phrase;
import com.djrapitops.planlite.PlanLite;
import com.djrapitops.planlite.PlanCommand;
import com.djrapitops.planlite.command.CommandType;
@ -16,7 +15,7 @@ public class HelpCommand extends SubCommand {
private final PlanCommand command;
public HelpCommand(PlanLite plugin, PlanCommand command) {
super("help,?", "plan.?", "Show command list.", CommandType.CONSOLE);
super("help,?", "planlite.?", "Show command list.", CommandType.CONSOLE);
this.plugin = plugin;
this.command = command;
@ -29,7 +28,7 @@ public class HelpCommand extends SubCommand {
ChatColor textColor = ChatColor.GRAY;
sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Player Analytics" + textColor + "] --");
sender.sendMessage(textColor + "-- [" + operatorColor + "Plan Lite - Player Analytics Lite" + textColor + "] --");
for (SubCommand command : this.command.getCommands()) {
if (command.getName().equalsIgnoreCase(getName())) {
@ -44,7 +43,7 @@ public class HelpCommand extends SubCommand {
continue;
}
sender.sendMessage(operatorColor + "/plan " + command.getFirstName() + textColor + " - " + command.getUsage());
sender.sendMessage(operatorColor + "/planlite " + command.getFirstName() + textColor + " - " + command.getUsage());
}
return true;

View File

@ -13,7 +13,7 @@ public class InfoCommand extends SubCommand {
private PlanLite plugin;
public InfoCommand(PlanLite plugin) {
super("info", "plan.info", "View version and enabled hooks", CommandType.CONSOLE);
super("info", "planlite.info", "View version and enabled hooks", CommandType.CONSOLE);
this.plugin = plugin;
}

View File

@ -21,7 +21,7 @@ public class InspectCommand extends SubCommand {
private PlanLite plugin;
public InspectCommand(PlanLite plugin) {
super("inspect", "plan.inspect", "Inspect data /plan <player> [-a, -r].", CommandType.CONSOLE_WITH_ARGUMENTS);
super("inspect", "planlite.inspect", "Inspect data /plan <player> [-a, -r].", CommandType.CONSOLE_WITH_ARGUMENTS);
this.plugin = plugin;
}

View File

@ -15,7 +15,7 @@ public class ReloadCommand extends SubCommand {
private PlanLite plugin;
public ReloadCommand(PlanLite plugin) {
super("reload", "plan.reload", "Reload plugin config & Hooks", CommandType.CONSOLE);
super("reload", "planlite.reload", "Reload plugin config & Hooks", CommandType.CONSOLE);
this.plugin = plugin;
}

View File

@ -25,7 +25,7 @@ public class SearchCommand extends SubCommand {
private final PlanLite plugin;
public SearchCommand(PlanLite plugin) {
super("search", "plan.search", "Inspect specific data /plan <search terms> [-p]", CommandType.CONSOLE_WITH_ARGUMENTS);
super("search", "planlite.search", "Inspect specific data /plan <search terms> [-p]", CommandType.CONSOLE_WITH_ARGUMENTS);
this.plugin = plugin;
}

View File

@ -8,7 +8,6 @@ import com.djrapitops.planlite.api.DataType;
import io.minimum.minecraft.superbvote.SuperbVote;
import java.util.HashMap;
import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;

View File

@ -16,8 +16,6 @@ import com.palmergames.bukkit.util.BukkitTools;
import java.util.HashMap;
import java.util.List;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import static com.palmergames.bukkit.towny.TownyFormatter.getFormattedResidents;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import static com.palmergames.bukkit.towny.TownyFormatter.getFormattedResidents;
import static org.bukkit.Bukkit.getOfflinePlayer;

View File

@ -9,7 +9,6 @@ import java.util.HashMap;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import net.milkbowl.vault.economy.Economy;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getServer;
import static org.bukkit.Bukkit.getOfflinePlayer;

View File

@ -75,7 +75,7 @@ public class DataUtils {
plugin.logToFile("INSPECT-GETNAME\nNo username given, returned empty username.\n" + args[0]);
} else if (sender.hasPermission("plan.inspect.other") || !(sender instanceof Player)) {
} else if (sender.hasPermission("planlite.inspect.other") || !(sender instanceof Player)) {
playerName = args[0];
}
} else {

View File

@ -34,50 +34,50 @@ softdepend:
- PlayerLogger
permissions:
plan.?:
planlite.?:
description: Help command
default: true
plan.inspect:
planlite.inspect:
description: Allows you to check your player data.
default: true
plan.inspect.other:
planlite.inspect.other:
description: Allows you to check other players' player data.
default: true
plan.analyze:
planlite.analyze:
description: Allows you to check analysed data about all players.
default: true
plan.analyze.refresh:
planlite.analyze.refresh:
description: Allows you to refresh the analyse result with -r argument
default: op
plan.reload:
planlite.reload:
description: Allows to reload plugin config
default: true
plan.search:
planlite.search:
description: Allows search
default: true
plan.info:
planlite.info:
description: Allows to view info
default: true
plan.debug:
planlite.debug:
description: Allows debug command
default: op
plan.basic:
planlite.basic:
children:
plan.?: true
plan.inspect: true
plan.info: true
plan.search: true
plan.advanced:
planlite.?: true
planlite.inspect: true
planlite.info: true
planlite.search: true
planlite.advanced:
childer:
plan.basic: true
plan.analyze: true
plan.staff:
planlite.basic: true
planlite.analyze: true
planlite.staff:
children:
plan.debug: true
plan.advanced: true
plan.inspect.other: true
plan.analyze.refresh: true
plan.reload: true
plan.*:
planlite.debug: true
planlite.advanced: true
planlite.inspect.other: true
planlite.analyze.refresh: true
planlite.reload: true
planlite.*:
children:
plan.staff: true
planlite.staff: true

View File

@ -108,19 +108,12 @@ public class Plan extends JavaPlugin {
public void hookPlanLite() {
try {
if (getConfig().getBoolean("Settings.PlanLite.Enabled")) {
planLiteHook = new PlanLiteHook(this);
}
} catch (NoClassDefFoundError | Exception e) {
}
}
@Deprecated
public List<String> hookInit() {
return new ArrayList<>();
}
@Override
public void onDisable() {
uiServer.stop();
@ -169,14 +162,6 @@ public class Plan extends JavaPlugin {
return api;
}
public void addExtraHook(String name, Hook hook) {
if (planLiteHook != null) {
planLiteHook.addExtraHook(name, hook);
} else {
logError(Phrase.ERROR_PLANLITE.toString());
}
}
private void registerListeners() {
getServer().getPluginManager().registerEvents(new PlanChatListener(this), this);
getServer().getPluginManager().registerEvents(new PlanPlayerListener(this), this);

View File

@ -3,8 +3,9 @@ package com.djrapitops.plan;
import com.djrapitops.planlite.PlanLite;
import com.djrapitops.planlite.api.API;
import com.djrapitops.planlite.api.DataPoint;
import com.djrapitops.planlite.api.Hook;
import java.util.HashMap;
import java.util.Set;
import org.bukkit.Bukkit;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
/**
@ -17,105 +18,47 @@ public class PlanLiteHook {
private Plan plugin;
private API planLiteApi;
private boolean enabled;
/**
* Class Constructor.
*
* Attempts to hook to PlanLite, if not present logs error.
* Attempts to hook to PlanLite, if not present sets enabled to false
*
* @param plugin
*/
public PlanLiteHook(Plan plugin) {
this.plugin = plugin;
if (plugin.getConfig().getBoolean("Settings.PlanLite.Enabled")) {
if (Bukkit.getPluginManager().isPluginEnabled("PlanLite")) {
try {
this.planLite = getPlugin(PlanLite.class);
if (planLite == null) {
throw new Exception(Phrase.ERROR_PLANLITE.toString());
}
enabled = true;
planLiteApi = planLite.getAPI();
return;
} catch (Exception e) {
}
}
}
enabled = false;
}
void addExtraHook(String name, Hook hook) {
try {
if (planLite == null) {
throw new Exception(Phrase.ERROR_PLANLITE.toString());
}
planLite.addExtraHook(name, hook);
plugin.log(Phrase.PLANLITE_REG_HOOK.toString() + name);
} catch (Exception | NoClassDefFoundError e) {
plugin.logError("Failed to hook " + name + "\n " + e);
}
public Set<String> getEnabledHooksNames() {
return planLite.getHooks().keySet();
}
@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);
public boolean isEnabled() {
return enabled;
}
}

View File

@ -2,11 +2,8 @@ package com.djrapitops.plan.api;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLiteHook;
import com.djrapitops.planlite.api.DataPoint;
import com.djrapitops.planlite.api.Hook;
import com.djrapitops.plan.utilities.FormatUtils;
import java.util.Date;
import java.util.HashMap;
/**
*
@ -68,150 +65,4 @@ public class API {
public static String formatTimeStamp(String timeInMs) {
return FormatUtils.formatTimeStamp(timeInMs);
}
/**
* @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);
}
}

View File

@ -1,5 +1,7 @@
package com.djrapitops.plan.data;
import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData;
/**
*
* @author Rsl1122
@ -32,10 +34,30 @@ public class AnalysisData {
private long totalLoginTimes;
private int ops;
private boolean planLiteEnabled;
private PlanLiteAnalyzedData planLiteData;
public AnalysisData() {
}
// Getters and setters v---------------------------------v
public boolean isPlanLiteEnabled() {
return planLiteEnabled;
}
public void setPlanLiteEnabled(boolean planLiteEnabled) {
this.planLiteEnabled = planLiteEnabled;
}
public PlanLiteAnalyzedData getPlanLiteData() {
return planLiteData;
}
public void setPlanLiteData(PlanLiteAnalyzedData planLiteData) {
this.planLiteData = planLiteData;
}
public String getPlayersChartImgHtmlMonth() {
return playersChartImgHtmlMonth;
}

View File

@ -0,0 +1,54 @@
package main.java.com.djrapitops.plan.data;
import java.util.HashMap;
/**
*
* @author Rsl1122
*/
public class PlanLiteAnalyzedData {
private HashMap<String, Integer> townMap;
private HashMap<String, Integer> factionMap;
private int totalVotes;
private int totalMoney;
public PlanLiteAnalyzedData() {
}
public HashMap<String, Integer> getTownMap() {
return townMap;
}
public void setTownMap(HashMap<String, Integer> townMap) {
this.townMap = townMap;
}
public HashMap<String, Integer> getFactionMap() {
return factionMap;
}
public void setFactionMap(HashMap<String, Integer> factionMap) {
this.factionMap = factionMap;
}
public int getTotalVotes() {
return totalVotes;
}
public void setTotalVotes(int totalVotes) {
this.totalVotes = totalVotes;
}
public int getTotalMoney() {
return totalMoney;
}
public void setTotalMoney(int totalMoney) {
this.totalMoney = totalMoney;
}
}

View File

@ -0,0 +1,137 @@
package main.java.com.djrapitops.plan.data;
/**
*
* @author Rsl1122
*/
public class PlanLitePlayerData {
private boolean towny;
private boolean factions;
private boolean superbVote;
private boolean vault;
private String town;
private String friends;
private String plotPerms;
private String plotOptions;
private String faction;
private int votes;
private double money;
public PlanLitePlayerData() {
}
public void setTowny(boolean towny) {
this.towny = towny;
}
public void setFactions(boolean factions) {
this.factions = factions;
}
public void setSuperbVote(boolean superbVote) {
this.superbVote = superbVote;
}
public void setVault(boolean vault) {
this.vault = vault;
}
public void setTown(String town) {
this.town = town;
}
public void setFriends(String friends) {
this.friends = friends;
}
public void setPlotPerms(String plotPerms) {
this.plotPerms = plotPerms;
}
public void setPlotOptions(String plotOptions) {
this.plotOptions = plotOptions;
}
public void setFaction(String faction) {
this.faction = faction;
}
public void setVotes(int votes) {
this.votes = votes;
}
public void setMoney(double money) {
this.money = money;
}
public boolean hasTowny() {
return towny;
}
public boolean hasFactions() {
return factions;
}
public boolean hasSuperbVote() {
return superbVote;
}
public boolean hasVault() {
return vault;
}
public String getTown() {
if (towny) {
return town;
}
return "";
}
public String getFriends() {
if (towny) {
return friends;
}
return "";
}
public String getPlotPerms() {
if (towny) {
return plotPerms;
}
return "";
}
public String getPlotOptions() {
if (towny) {
return plotOptions;
}
return "";
}
public String getFaction() {
if (factions) {
return faction;
}
return "";
}
public int getVotes() {
if (superbVote) {
return votes;
}
return -1;
}
public double getMoney() {
if (vault) {
return money;
}
return -1;
}
}

View File

@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import main.java.com.djrapitops.plan.data.PlanLitePlayerData;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -36,6 +37,9 @@ public class UserData {
private boolean isBanned;
private DemographicsData demData;
private boolean planLiteFound;
private PlanLitePlayerData planLiteData;
private String name;
public UserData(Player player, DemographicsData demData, Database db) {
@ -144,6 +148,23 @@ public class UserData {
}
// Getters -------------------------------------------------------------
public boolean isPlanLiteFound() {
return planLiteFound;
}
public void setPlanLiteFound(boolean planLiteFound) {
this.planLiteFound = planLiteFound;
}
public PlanLitePlayerData getPlanLiteData() {
return planLiteData;
}
public void setPlanLiteData(PlanLitePlayerData planLiteData) {
this.planLiteData = planLiteData;
}
public UUID getUuid() {
return uuid;
}

View File

@ -100,7 +100,11 @@ public class DataCacheHandler {
public UserData getCurrentData(UUID uuid, boolean cache) {
if (cache) {
if (dataCache.get(uuid) == null) {
dataCache.put(uuid, db.getUserData(uuid));
UserData uData = db.getUserData(uuid);
if (uData.getPlanLiteData() == null) {
getPlanLiteHandler().handleEvents(uData.getName(), uData);
}
dataCache.put(uuid, uData);
plugin.log("Added " + uuid.toString() + " to Cache.");
}
return dataCache.get(uuid);
@ -108,7 +112,11 @@ public class DataCacheHandler {
if (dataCache.get(uuid) != null) {
return dataCache.get(uuid);
}
return db.getUserData(uuid);
UserData uData = db.getUserData(uuid);
if (uData.getPlanLiteData() == null) {
getPlanLiteHandler().handleEvents(uData.getName(), uData);
}
return uData;
}
}
@ -185,6 +193,12 @@ public class DataCacheHandler {
});
}
/**
* Saves a single player's data to the cache from the handler if the player
* is online.
*
* @param uuid UUID of the Player to save
*/
public void saveHandlerDataToCache(UUID uuid) {
Player p = getPlayer(uuid);
if (p != null) {
@ -294,6 +308,13 @@ public class DataCacheHandler {
return gamemodeTimesHandler;
}
/**
* @return Current instance of PlanLiteHandler
*/
public PlanLiteHandler getPlanLiteHandler() {
return planLiteHandler;
}
/**
* Returns the same value as Plan#getDB().
*
@ -341,6 +362,11 @@ public class DataCacheHandler {
}
}
/**
* Used by Analysis for Player activity graphs.
*
* @return Maximum number of players defined in server.properties.
*/
public int getMaxPlayers() {
return maxPlayers;
}

View File

@ -2,14 +2,81 @@ package com.djrapitops.plan.data.handlers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLiteHook;
import com.djrapitops.plan.data.UserData;
import com.djrapitops.plan.data.cache.DataCacheHandler;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.planlite.api.DataPoint;
import java.util.HashMap;
import java.util.Set;
import main.java.com.djrapitops.plan.data.PlanLitePlayerData;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
public class PlanLiteHandler {
private Plan plugin;
private PlanLiteHook hook;
private DataCacheHandler handler;
private boolean enabled;
public PlanLiteHandler(Plan plugin) {
this.plugin = plugin;
hook = plugin.getPlanLiteHook();
PlanLiteHook planLiteHook = plugin.getPlanLiteHook();
enabled = planLiteHook.isEnabled();
if (enabled) {
hook = planLiteHook;
}
}
public void handleLogin(PlayerJoinEvent event, UserData data) {
if (!enabled) {
data.setPlanLiteFound(false);
return;
}
Player p = event.getPlayer();
String playerName = p.getName();
handleEvents(playerName, data);
}
public void handleEvents(String playerName, UserData data) {
if (!enabled) {
return;
}
Set<String> enabledHooks = hook.getEnabledHooksNames();
HashMap<String, DataPoint> liteData = hook.getAllData(playerName, true);
PlanLitePlayerData plData = new PlanLitePlayerData();
plData.setTowny(enabledHooks.contains("Towny"));
plData.setFactions(enabledHooks.contains("Factions"));
plData.setSuperbVote(enabledHooks.contains("SuperbVote"));
plData.setVault(enabledHooks.contains("Vault"));
if (plData.hasTowny()) {
DataPoint town = liteData.get("TOW-TOWN");
plData.setTown((town != null) ? town.data() : "Not in a town");
plData.setFriends(liteData.get("TOW-FRIENDS").data());
plData.setPlotPerms(liteData.get("TOW-PLOT PERMS").data());
plData.setPlotOptions(liteData.get("TOW-PLOT OPTIONS").data());
}
if (plData.hasFactions()) {
DataPoint faction = liteData.get("FAC-FACTION");
plData.setFaction((faction != null) ? faction.data() : "Not in a faction");
}
if (plData.hasSuperbVote()) {
try {
plData.setVotes(Integer.parseInt(liteData.get("SVO-VOTES").data()));
} catch (Exception e) {
plData.setVotes(0);
}
}
if (plData.hasVault()) {
try {
plData.setMoney(Double.parseDouble(FormatUtils.removeLetters(liteData.get("ECO-BALANCE").data())));
} catch (Exception e) {
plData.setMoney(0);
}
}
data.setPlanLiteFound(true);
data.setPlanLiteData(plData);
}
}

View File

@ -12,7 +12,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import org.bukkit.scheduler.BukkitRunnable;
/**
@ -29,6 +28,7 @@ public class PlanPlayerListener implements Listener {
private final LocationHandler locationH;
private final DemographicsHandler demographicH;
private final RuleBreakingHandler rulebreakH;
private final PlanLiteHandler planLiteH;
private final ServerDataHandler serverHandler;
/**
@ -48,6 +48,7 @@ public class PlanPlayerListener implements Listener {
demographicH = handler.getDemographicsHandler();
locationH = handler.getLocationHandler();
rulebreakH = handler.getRuleBreakingHandler();
planLiteH = handler.getPlanLiteHandler();
serverHandler = handler.getServerDataHandler();
}
@ -73,6 +74,7 @@ public class PlanPlayerListener implements Listener {
basicInfoH.handleLogin(event, data);
gmTimesH.handleLogin(event, data);
demographicH.handleLogin(event, data);
planLiteH.handleLogin(event, data);
(new BukkitRunnable() {
@Override
public void run() {

View File

@ -11,7 +11,8 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData;
import main.java.com.djrapitops.plan.data.PlanLitePlayerData;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import org.bukkit.scheduler.BukkitRunnable;
@ -96,7 +97,30 @@ public class Analysis {
int ops = 0;
List<Integer> ages = new ArrayList<>();
boolean planLiteEnabled = plugin.getPlanLiteHook().isEnabled();
PlanLiteAnalyzedData plData = new PlanLiteAnalyzedData();
HashMap<String, Integer> townMap = new HashMap<>();
HashMap<String, Integer> factionMap = new HashMap<>();
int totalVotes = 0;
int totalMoney = 0;
for (UserData uData : rawData) {
if (planLiteEnabled) {
PlanLitePlayerData litePlayerData = uData.getPlanLiteData();
String town = litePlayerData.getTown();
if (!townMap.containsKey(town)) {
townMap.put(town, 0);
}
townMap.replace(town, townMap.get(town) + 1);
String faction = litePlayerData.getFaction();
if (!factionMap.containsKey(faction)) {
factionMap.put(faction, 0);
}
factionMap.replace(faction, factionMap.get(faction) + 1);
totalVotes += litePlayerData.getVotes();
totalMoney += litePlayerData.getMoney();
}
HashMap<GameMode, Long> gmTimes = uData.getGmTimes();
gmZero += gmTimes.get(GameMode.SURVIVAL);
gmOne += gmTimes.get(GameMode.CREATIVE);
@ -119,7 +143,20 @@ public class Analysis {
} else {
inactive++;
}
}
if (planLiteEnabled) {
plData.setFactionMap(factionMap);
plData.setTownMap(townMap);
plData.setTotalVotes(totalVotes);
plData.setTotalMoney(totalMoney);
data.setPlanLiteEnabled(true);
data.setPlanLiteData(plData);
} else {
data.setPlanLiteEnabled(false);
}
data.setTotalLoginTimes(totalLoginTimes);
String activityPieChartHtml = AnalysisUtils.createActivityPieChart(totalBanned, active, inactive);

View File

@ -9,6 +9,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData;
import main.java.com.djrapitops.plan.ui.graphs.ActivityPieChartCreator;
import main.java.com.djrapitops.plan.ui.graphs.PlayerActivityGraphCreator;
import main.java.com.djrapitops.plan.utilities.comparators.MapComparator;
@ -93,6 +94,12 @@ public class AnalysisUtils {
replaceMap.put("%ops%", "" + data.getOps());
replaceMap.put("%refresh%", FormatUtils.formatTimeAmountSinceString("" + data.getRefreshDate(), new Date()));
replaceMap.put("%totallogins%", "" + data.getTotalLoginTimes());
if (data.isPlanLiteEnabled()) {
replaceMap.put("%planlite%", getPlanLiteAnalysisHtml(data.getPlanLiteData()));
} else {
replaceMap.put("%planlite%", "");
}
return replaceMap;
}
@ -134,4 +141,45 @@ public class AnalysisUtils {
html += "</table>";
return html;
}
private static String getPlanLiteAnalysisHtml(PlanLiteAnalyzedData planLiteData) {
List<String[]> sortedTowns = MapComparator.sortByValue(planLiteData.getTownMap());
Collections.reverse(sortedTowns);
List<String[]> sortedFactions = MapComparator.sortByValue(planLiteData.getFactionMap());
Collections.reverse(sortedFactions);
String html = "<tr>"
+ "<td style=\"margin-left: 3px; margin-right: auto; "
+ "border-style: groove; border-width: 3px; border-radius: 12px; padding: 2px 4px 2px 3px; "
+ "box-shadow: 5px 5px 4px 0px #888888;\">";
html += "<table style=\"border-collapse: collapse;table-layout: fixed; border-style: solid; border-width: 1px; width: 100%;\">";
int i = 1;
for (String[] values : sortedTowns) {
if (i >= 20) {
break;
}
html += "<tr style=\"text-align: center;border-style: solid; border-width: 1px;height: 28px;\"><td><b>" + values[1] + "</b></td>\r\n<td>" + values[0] + "</td></tr>";
i++;
}
html += "</table><table style=\"border-collapse: collapse;table-layout: fixed; border-style: solid; border-width: 1px; width: 100%;\">";
int j = 1;
for (String[] values : sortedFactions) {
if (j >= 20) {
break;
}
html += "<tr style=\"text-align: center;border-style: solid; border-width: 1px;height: 28px;\"><td><b>" + values[1] + "</b></td>\r\n<td>" + values[0] + "</td></tr>";
j++;
}
html += "</table></tr>" + "<tr>"
+ " <td style=\"margin-left: 3px; margin-right: auto; "
+ " border-style: groove; border-width: 3px; border-radius: 12px; padding: 2px 4px 2px 3px;"
+ " box-shadow: 5px 5px 4px 0px #888888;\">"
+ "<h4>Information</h4>"
+ "<p>Total Money on the server: " + planLiteData.getTotalMoney() + "<br/>Players have voted the server "
+ planLiteData.getTotalVotes() + " times.</p>"
+ "</td>";
html += "</tr>";
return html;
}
}

View File

@ -47,18 +47,7 @@
%top50commands%
</td>
</tr>
<tr>
<td style="margin-left: 3px; margin-right: auto;
border-style: groove; border-width: 3px; border-radius: 12px; padding: 2px 4px 2px 3px;
box-shadow: 5px 5px 4px 0px #888888;text-align: center;">
<p>Empty wrapper</p>
</td>
<td style="margin-left: 3px; margin-right: auto;
border-style: groove; border-width: 3px; border-radius: 12px; padding: 2px 4px 2px 3px;
box-shadow: 5px 5px 4px 0px #888888;text-align: center;">
<p>Empty wrapper</p>
</td>
</tr>
%planlite%
</table>
</div>
</body>