mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-04-18 18:30:31 +08:00
Changed the 3rd party plugin structure
- Untested - New Tab required - HtmlUtils replace utility required for new plugin data.
This commit is contained in:
parent
2c45aa60fc
commit
7892d695f9
@ -15,7 +15,7 @@
|
||||
<dependency>
|
||||
<groupId>com.hm</groupId>
|
||||
<artifactId>advanced.achievements</artifactId>
|
||||
<version>4.1.5</version>
|
||||
<version>5.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -26,7 +26,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -160,15 +159,6 @@ public class Plan extends JavaPlugin {
|
||||
Log.info(Phrase.DISABLED + "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to access the API.
|
||||
*
|
||||
* @return Plan API
|
||||
*/
|
||||
public API getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
final PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new PlanChatListener(this), this);
|
||||
@ -312,6 +302,10 @@ public class Plan extends JavaPlugin {
|
||||
return bootAnalysisTaskID;
|
||||
}
|
||||
|
||||
public API getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
||||
private void initLocale() {
|
||||
String locale = Settings.LOCALE.toString().toUpperCase();
|
||||
/*// Used to write a new Locale file
|
||||
@ -367,7 +361,7 @@ public class Plan extends JavaPlugin {
|
||||
}
|
||||
Log.info("Using locale: " + usingLocale);
|
||||
}
|
||||
|
||||
|
||||
public static Plan getInstance() {
|
||||
Plan INSTANCE = PlanHolder.INSTANCE;
|
||||
if (INSTANCE == null) {
|
||||
@ -380,6 +374,14 @@ public class Plan extends JavaPlugin {
|
||||
PlanHolder.INSTANCE = plan;
|
||||
}
|
||||
|
||||
public static API getPlanAPI() throws IllegalStateException {
|
||||
Plan INSTANCE = PlanHolder.INSTANCE;
|
||||
if (INSTANCE == null) {
|
||||
throw new IllegalStateException("Plugin not enabled properly, Singleton instance is null.");
|
||||
}
|
||||
return INSTANCE.api;
|
||||
}
|
||||
|
||||
private static class PlanHolder {
|
||||
|
||||
private static Plan INSTANCE = null;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This enum contains all of the config settings used by the plugin for easier
|
||||
* access.
|
||||
@ -55,7 +57,10 @@ public enum Settings {
|
||||
HCOLOR_GMP_3("Customization.Colors.HTML.GamemodePie.Spectator"),
|
||||
HCOLOR_GENP_M("Customization.Colors.HTML.GenderPie.Male"),
|
||||
HCOLOR_GENP_F("Customization.Colors.HTML.GenderPie.Female"),
|
||||
HCOLOR_GENP_U("Customization.Colors.HTML.GenderPie.Unknown");
|
||||
HCOLOR_GENP_U("Customization.Colors.HTML.GenderPie.Unknown"),
|
||||
// StringList
|
||||
HIDE_FACTIONS("Customization.Plugins.Factions.HideFactions"),
|
||||
HIDE_TOWNS("Customization.Plugins.Towny.HideTowns");
|
||||
|
||||
private final String configPath;
|
||||
|
||||
@ -90,6 +95,10 @@ public enum Settings {
|
||||
public int getNumber() {
|
||||
return Plan.getInstance().getConfig().getInt(configPath);
|
||||
}
|
||||
|
||||
public List<String> getStringList() {
|
||||
return Plan.getInstance().getConfig().getStringList(configPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the String path of a the config setting eg.
|
||||
|
@ -5,10 +5,14 @@ import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.AnalysisData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.ui.DataRequestHandler;
|
||||
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
* This class contains the API methods.
|
||||
@ -31,52 +35,18 @@ public class API {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Deprecated
|
||||
public static String formatTimeSinceDate(Date before, Date after) {
|
||||
return FormatUtils.formatTimeAmountSinceDate(before, after);
|
||||
public void addPluginDataSource(PluginData dataSource) {
|
||||
plugin.getHookHandler().addPluginDataSource(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Deprecated
|
||||
public static String formatTimeSinceString(String before, Date after) {
|
||||
return FormatUtils.formatTimeAmountSinceString(before, after);
|
||||
|
||||
public String getPlayerInspectPageLinkHtml(UUID uuid) throws IllegalStateException {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (offlinePlayer.hasPlayedBefore()) {
|
||||
return HtmlUtils.getInspectUrl(offlinePlayer.getName());
|
||||
}
|
||||
throw new IllegalStateException("Player has not played on this server before.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Deprecated
|
||||
public static String formatTimeAmount(String timeInMs) {
|
||||
return FormatUtils.formatTimeAmount(timeInMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns user readable format of a Date.
|
||||
*
|
||||
* @param timeInMs String of long since Epoch 1970
|
||||
* @return String that is easily readable date.
|
||||
*/
|
||||
@Deprecated
|
||||
public static String formatTimeStamp(String timeInMs) {
|
||||
return FormatUtils.formatTimeStamp(timeInMs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uses UUIDFetcher to turn PlayerName to UUID
|
||||
*
|
||||
@ -87,34 +57,34 @@ public class API {
|
||||
public UUID playerNameToUUID(String playerName) throws Exception {
|
||||
return UUIDFetcher.getUUIDOf(playerName);
|
||||
}
|
||||
|
||||
|
||||
// DEPRECATED METHODS WILL BE REMOVED IN 3.2.0
|
||||
@Deprecated
|
||||
public static String formatTimeSinceDate(Date before, Date after) {
|
||||
return FormatUtils.formatTimeAmountSinceDate(before, after);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatTimeSinceString(String before, Date after) {
|
||||
return FormatUtils.formatTimeAmountSinceString(before, after);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatTimeAmount(String timeInMs) {
|
||||
return FormatUtils.formatTimeAmount(timeInMs);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatTimeStamp(String timeInMs) {
|
||||
return FormatUtils.formatTimeStamp(timeInMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches the UserData to the InspectCache for time specified in the Plan
|
||||
* config, so it can be called by webserver.
|
||||
*
|
||||
* Does not cache anything if the player has not joined the server or has no
|
||||
* data in the database.
|
||||
*
|
||||
* @param uuid UUID of the Player
|
||||
*/
|
||||
@Deprecated
|
||||
public void cacheUserDataToInspectCache(UUID uuid) {
|
||||
plugin.getInspectCache().cache(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ip:port/player/playername html as a string so it can be
|
||||
* integrated into other webserver plugins.
|
||||
*
|
||||
* Should use cacheUserDataToInspectCache(UUID uuid) before using this
|
||||
* method.
|
||||
*
|
||||
* If UserData of the specified player is not in the Cache returns <h1>404
|
||||
* Data was not found in cache</h1>
|
||||
*
|
||||
* @param uuid UUID of the Player
|
||||
* @return html as a string or a single error line html.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getPlayerHtmlAsString(UUID uuid) {
|
||||
WebSocketServer server = plugin.getUiServer();
|
||||
@ -125,26 +95,11 @@ public class API {
|
||||
return reqH.getInspectHtml(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the AnalysisCache so the cached data can be called by the
|
||||
* webserver.
|
||||
*/
|
||||
@Deprecated
|
||||
public void updateAnalysisCache() {
|
||||
plugin.getAnalysisCache().updateCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ip:port/server html as a string so it can be integrated into
|
||||
* other webserver plugins.
|
||||
*
|
||||
* Should use updateAnalysisCache() before using this method.
|
||||
*
|
||||
* If AnalysisData is not in the AnalysisCache: returns <h1>404 Data was not
|
||||
* found in cache</h1>
|
||||
*
|
||||
* @return html as a string or a single error line html.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getAnalysisHtmlAsString() {
|
||||
WebSocketServer server = plugin.getUiServer();
|
||||
@ -155,22 +110,11 @@ public class API {
|
||||
return reqH.getAnalysisHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns UserData from the InspectCache
|
||||
*
|
||||
* @param uuid UUID of the Player
|
||||
* @return UserData of the Player in the InspectCache or null if not found
|
||||
*/
|
||||
@Deprecated
|
||||
public UserData getUserDataFromInspectCache(UUID uuid) {
|
||||
return plugin.getInspectCache().getFromCache(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns AnalysisData from the AnalysisCache
|
||||
*
|
||||
* @return AnalysisData in the AnalysisCache or null if not found
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public AnalysisData getAnalysisDataFromCache() {
|
||||
return plugin.getAnalysisCache().getData();
|
||||
|
@ -11,11 +11,11 @@ import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to remove a single player's data from the
|
||||
|
@ -1,6 +1,8 @@
|
||||
package main.java.com.djrapitops.plan.data;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.ui.RecentPlayersButtonsCreator;
|
||||
@ -24,6 +26,7 @@ import main.java.com.djrapitops.plan.utilities.PlaceholderUtils;
|
||||
public class AnalysisData {
|
||||
|
||||
private long refreshDate;
|
||||
private Map<String, String> additionalDataReplaceMap;
|
||||
|
||||
private long averagePlayTime;
|
||||
private long totalPlayTime;
|
||||
@ -79,6 +82,7 @@ public class AnalysisData {
|
||||
geomapCodes = Html.ERROR_NOT_SET + "";
|
||||
playersDataArray = new String[]{"[0]", "[\"No data\"]", "[0]", "[\"No data\"]", "[0]", "[\"No data\"]"};
|
||||
genderData = new int[]{0, 0, 0};
|
||||
additionalDataReplaceMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -189,6 +193,25 @@ public class AnalysisData {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the additional data replaceMap used with Analysis replacerules.
|
||||
*
|
||||
* @param additionalDataReplaceMap Map with placeholder keys %key%, value
|
||||
* @see PlaceholderUtils
|
||||
*/
|
||||
public void setAdditionalDataReplaceMap(Map<String, String> additionalDataReplaceMap) {
|
||||
this.additionalDataReplaceMap = additionalDataReplaceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the additional data replaceMap used with Analysis replacerules.
|
||||
*
|
||||
* @return a Map with placeholder keys %key%, value
|
||||
*/
|
||||
public Map<String, String> getAdditionalDataReplaceMap() {
|
||||
return additionalDataReplaceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the toString representation of a String[] containing all
|
||||
* countries on the Plotly.js Chloropleth map.
|
||||
@ -846,9 +869,9 @@ public class AnalysisData {
|
||||
/**
|
||||
*
|
||||
* Set the integer array containing 3 numbers.
|
||||
*
|
||||
*
|
||||
* 0 Male, 1 Female, 2 Unknown.
|
||||
*
|
||||
*
|
||||
* @param genderData for example [0, 4, 5]
|
||||
*/
|
||||
public void setGenderData(int[] genderData) {
|
||||
|
@ -1,91 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import com.hm.achievement.AdvancedAchievements;
|
||||
import com.hm.achievement.category.MultipleAchievements;
|
||||
import com.hm.achievement.category.NormalAchievements;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AdvancedAchievementsHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private AdvancedAchievements adAc;
|
||||
private int totalAchievements;
|
||||
|
||||
/**
|
||||
* Hooks the plugin and calculates Total Achievements.
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public AdvancedAchievementsHook(Plan plugin) throws NoClassDefFoundError {
|
||||
super("com.hm.achievement.AdvancedAchievements");
|
||||
this.plugin = plugin;
|
||||
if (super.isEnabled()) {
|
||||
try {
|
||||
totalAchievements = calcTotalAchievements();
|
||||
} catch (Exception | NoClassDefFoundError e) {
|
||||
super.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AdvancedAchievementsHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
private int calcTotalAchievements() throws Exception, NoClassDefFoundError {
|
||||
int total = 0;
|
||||
for (NormalAchievements category : NormalAchievements.values()) {
|
||||
String categoryName = category.toString();
|
||||
if (adAc.getDisabledCategorySet().contains(categoryName)) {
|
||||
// Ignore this type.
|
||||
continue;
|
||||
}
|
||||
total += adAc.getPluginConfig().getConfigurationSection(categoryName).getKeys(false).size();
|
||||
}
|
||||
for (MultipleAchievements category : MultipleAchievements.values()) {
|
||||
String categoryName = category.toString();
|
||||
if (adAc.getDisabledCategorySet().contains(categoryName)) {
|
||||
// Ignore this type.
|
||||
continue;
|
||||
}
|
||||
for (String item : adAc.getPluginConfig().getConfigurationSection(categoryName).getKeys(false)) {
|
||||
total += adAc.getPluginConfig().getConfigurationSection(categoryName + '.' + item)
|
||||
.getKeys(false).size();
|
||||
}
|
||||
}
|
||||
if (!adAc.getDisabledCategorySet().contains("Commands")) {
|
||||
total += adAc.getPluginConfig().getConfigurationSection("Commands").getKeys(false).size();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns total number of achievements. isEnabled() should be called before
|
||||
* calling this method
|
||||
*
|
||||
* @return Total Achievements calculated during Initialization
|
||||
*/
|
||||
public int getTotalAchievements() {
|
||||
return totalAchievements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns achievement number of a player. isEnabled() should be called
|
||||
* before calling this method
|
||||
*
|
||||
* @param uuid UUID of player
|
||||
* @return Achievement amount of the Player
|
||||
*/
|
||||
public int getPlayerAchievements(UUID uuid) {
|
||||
return adAc.getDb().getPlayerAchievementsAmount(uuid.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public enum AnalysisType {
|
||||
INT_AVG("Average "), LONG_AVG("Average "), DOUBLE_AVG("Average "),
|
||||
INT_TOTAL, LONG_TOTAL, DOUBLE_TOTAL,
|
||||
LONG_TIME_MS_AVG, LONG_TIME_MS_TOTAL, LONG_EPOCH_MS_MINUS_NOW_TOTAL,
|
||||
BOOLEAN_PERCENTAGE, BOOLEAN_TOTAL,
|
||||
HTML, TOTAL_VALUE;
|
||||
|
||||
private final String modifier;
|
||||
|
||||
private AnalysisType(String modifier) {
|
||||
this.modifier = modifier;
|
||||
}
|
||||
|
||||
private AnalysisType() {
|
||||
this.modifier = "";
|
||||
}
|
||||
|
||||
public String getModifier() {
|
||||
return modifier;
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class EssentialsHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private Essentials ess;
|
||||
private List<String> warps;
|
||||
|
||||
/**
|
||||
* Hooks to Essentials plugin
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public EssentialsHook(Plan plugin) throws NoClassDefFoundError{
|
||||
super("com.earth2me.essentials.Essentials");
|
||||
this.plugin = plugin;
|
||||
if (super.isEnabled()) {
|
||||
ess = getPlugin(Essentials.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public EssentialsHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs information not provided by Player class or Plan from Essentials.
|
||||
* isEnabled() should be called before this method.
|
||||
*
|
||||
* @param uuid UUID of player
|
||||
* @return HashMap with boolean, int and string values: JAILED boolean,
|
||||
* MUTED boolean
|
||||
*/
|
||||
public HashMap<String, Serializable> getEssentialsData(UUID uuid) {
|
||||
HashMap<String, Serializable> essData = new HashMap<>();
|
||||
User user = ess.getUser(uuid);
|
||||
if (user != null) {
|
||||
essData.put("JAILED", user.isJailed());
|
||||
essData.put("MUTED", user.isMuted());
|
||||
} else {
|
||||
essData.put("JAILED", false);
|
||||
essData.put("MUTED", false);
|
||||
}
|
||||
return essData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Warp list
|
||||
*/
|
||||
public List<String> getWarps() {
|
||||
return (ArrayList<String>) ess.getWarps().getList();
|
||||
}
|
||||
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.FactionComparator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class FactionsHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Hooks to Factions plugin
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public FactionsHook(Plan plugin) {
|
||||
super("com.massivecraft.factions.Factions");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public FactionsHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of Faction names sorted by power
|
||||
*/
|
||||
public List<String> getTopFactions() {
|
||||
List<Faction> topFactions = new ArrayList<>();
|
||||
topFactions.addAll(FactionColl.get().getAll());
|
||||
topFactions.remove(FactionColl.get().getWarzone());
|
||||
topFactions.remove(FactionColl.get().getSafezone());
|
||||
topFactions.remove(FactionColl.get().getNone());
|
||||
Collections.sort(topFactions, new FactionComparator());
|
||||
List<String> factionNames = topFactions.stream()
|
||||
.map(faction -> faction.getName())
|
||||
.collect(Collectors.toList());
|
||||
return factionNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab basic info about Faction. isEnabled() should be called before this
|
||||
* method.
|
||||
*
|
||||
* @param factionName Name of the faction.
|
||||
* @return HashMap containing boolean, number & string: LEADER String, POWER
|
||||
* String, LAND int
|
||||
*/
|
||||
public HashMap<String, Serializable> getFactionInfo(String factionName) {
|
||||
HashMap<String, Serializable> info = new HashMap<>();
|
||||
Faction faction = FactionColl.get().getByName(factionName);
|
||||
if (faction != null) {
|
||||
MPlayer leader = faction.getLeader();
|
||||
if (leader != null) {
|
||||
info.put("LEADER", leader.getNameAndSomething("", ""));
|
||||
} else {
|
||||
info.put("LEADER", Html.FACTION_NO_LEADER.parse());
|
||||
}
|
||||
|
||||
info.put("POWER", FormatUtils.cutDecimals(faction.getPower()));
|
||||
info.put("LAND", faction.getLandCount());
|
||||
} else {
|
||||
info.put("LEADER", Html.FACTION_NOT_FOUND.parse());
|
||||
info.put("POWER", Html.FACTION_NOT_FOUND.parse());
|
||||
info.put("LAND", Html.FACTION_NOT_FOUND.parse());
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab info about a Player. isEnabled() should be called before this
|
||||
* method.
|
||||
*
|
||||
* @param uuid UUID of the player
|
||||
* @return HashMap containing boolean, number & string: POWER int, MAXPOWER
|
||||
* int, FACTION String
|
||||
*/
|
||||
public HashMap<String, Serializable> getPlayerInfo(UUID uuid) {
|
||||
HashMap<String, Serializable> info = new HashMap<>();
|
||||
MPlayer mPlayer = MPlayer.get(uuid);
|
||||
if (mPlayer != null) {
|
||||
info.put("POWER", FormatUtils.cutDecimals(mPlayer.getPower()));
|
||||
info.put("MAXPOWER", mPlayer.getPowerMax());
|
||||
if (mPlayer.hasFaction()) {
|
||||
info.put("FACTION", mPlayer.getFactionName());
|
||||
} else {
|
||||
info.put("FACTION", Phrase.NOT_IN_FAC + "");
|
||||
}
|
||||
} else {
|
||||
info.put("POWER", 0);
|
||||
info.put("MAXPOWER", 0);
|
||||
info.put("FACTION", Phrase.NOT_IN_FAC + "");
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
*/
|
||||
public abstract class Hook {
|
||||
|
||||
private boolean enabled;
|
||||
protected boolean enabled;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1,13 +1,16 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import java.io.Serializable;
|
||||
import main.java.com.djrapitops.plan.data.additional.essentials.EssentialsHook;
|
||||
import main.java.com.djrapitops.plan.data.additional.advancedachievements.AdvancedAchievementsHook;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortableFactionsTableCreator;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortableTownTableCreator;
|
||||
import main.java.com.djrapitops.plan.data.additional.factions.FactionsHook;
|
||||
import main.java.com.djrapitops.plan.data.additional.ontime.OnTimeHook;
|
||||
import main.java.com.djrapitops.plan.data.additional.towny.TownyHook;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -16,9 +19,9 @@ import main.java.com.djrapitops.plan.ui.tables.SortableTownTableCreator;
|
||||
public class HookHandler {
|
||||
|
||||
private Plan plan;
|
||||
private List<PluginData> additionalDataSources;
|
||||
private AdvancedAchievementsHook advancedAchievementsHook;
|
||||
private EssentialsHook essentialsHook;
|
||||
private SuperbVoteHook superbVoteHook;
|
||||
private FactionsHook factionsHook;
|
||||
private OnTimeHook onTimeHook;
|
||||
private TownyHook townyHook;
|
||||
@ -29,112 +32,47 @@ public class HookHandler {
|
||||
*/
|
||||
public HookHandler(Plan plan) {
|
||||
this.plan = plan;
|
||||
additionalDataSources = new ArrayList<>();
|
||||
hook();
|
||||
}
|
||||
|
||||
public void addPluginDataSource(PluginData dataSource) {
|
||||
additionalDataSources.add(dataSource);
|
||||
}
|
||||
|
||||
public List<PluginData> getAdditionalDataSources() {
|
||||
return additionalDataSources;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void reloadHooks() {
|
||||
additionalDataSources.clear();
|
||||
hook();
|
||||
}
|
||||
|
||||
private void hook() {
|
||||
try {
|
||||
advancedAchievementsHook = new AdvancedAchievementsHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
advancedAchievementsHook = new AdvancedAchievementsHook();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
}
|
||||
try {
|
||||
essentialsHook = new EssentialsHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
essentialsHook = new EssentialsHook();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
}
|
||||
try {
|
||||
superbVoteHook = new SuperbVoteHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
superbVoteHook = new SuperbVoteHook();
|
||||
}
|
||||
try {
|
||||
factionsHook = new FactionsHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
factionsHook = new FactionsHook();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
}
|
||||
try {
|
||||
townyHook = new TownyHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
townyHook = new TownyHook();
|
||||
}
|
||||
try {
|
||||
onTimeHook = new OnTimeHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
onTimeHook = new OnTimeHook();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
}
|
||||
try {
|
||||
townyHook = new TownyHook();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public AdvancedAchievementsHook getAdvancedAchievementsHook() {
|
||||
return advancedAchievementsHook;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public EssentialsHook getEssentialsHook() {
|
||||
return essentialsHook;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SuperbVoteHook getSuperbVoteHook() {
|
||||
return superbVoteHook;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public FactionsHook getFactionsHook() {
|
||||
return factionsHook;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TownyHook getTownyHook() {
|
||||
return townyHook;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public OnTimeHook getOnTimeHook() {
|
||||
return onTimeHook;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> getAdditionalAnalysisReplaceRules() {
|
||||
Map<String, String> addReplace = new HashMap<>();
|
||||
AdvancedAchievementsHook aH = advancedAchievementsHook;
|
||||
EssentialsHook eH = essentialsHook;
|
||||
SuperbVoteHook sH = superbVoteHook;
|
||||
FactionsHook fH = factionsHook;
|
||||
TownyHook tH = townyHook;
|
||||
addReplace.put("%towntable%", tH.isEnabled() ? SortableTownTableCreator.createSortableTownsTable(tH.getTopTowns(), tH) : "");
|
||||
addReplace.put("%factionstable%", fH.isEnabled() ? SortableFactionsTableCreator.createSortableFactionsTable(fH.getTopFactions(), fH) : "");
|
||||
addReplace.put("%essentialswarps%", eH.isEnabled() ? Html.WARPS.parse(eH.getWarps().toString()) : "");
|
||||
return addReplace;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,32 +82,11 @@ public class HookHandler {
|
||||
*/
|
||||
public Map<String, String> getAdditionalInspectReplaceRules(UUID uuid) {
|
||||
Map<String, String> addReplace = new HashMap<>();
|
||||
AdvancedAchievementsHook aH = advancedAchievementsHook;
|
||||
EssentialsHook eH = essentialsHook;
|
||||
SuperbVoteHook sH = superbVoteHook;
|
||||
FactionsHook fH = factionsHook;
|
||||
TownyHook tH = townyHook;
|
||||
addReplace.put("%achievements%", (aH.isEnabled() ? Html.ACHIEVEMENTS.parse(aH.getPlayerAchievements(uuid) + "", aH.getTotalAchievements() + "") : ""));
|
||||
if (eH.isEnabled()) {
|
||||
HashMap<String, Serializable> essData = eH.getEssentialsData(uuid);
|
||||
addReplace.put("%essentials%", ((boolean) essData.get("JAILED") ? Html.JAILED.parse() : "")
|
||||
+ " " + ((boolean) essData.get("MUTED") ? Html.MUTED.parse() : ""));
|
||||
} else {
|
||||
addReplace.put("%essentials%", "");
|
||||
}
|
||||
|
||||
addReplace.put("%votes%", sH.isEnabled() ? Html.VOTES.parse(sH.getVotes(uuid) + "") : "");
|
||||
if (fH.isEnabled()) {
|
||||
HashMap<String, Serializable> facInfo = fH.getPlayerInfo(uuid);
|
||||
addReplace.put("%faction%", Html.FACTION.parse(facInfo.get("FACTION") + "", facInfo.get("POWER") + "", facInfo.get("MAXPOWER") + ""));
|
||||
} else {
|
||||
addReplace.put("%faction%", "");
|
||||
}
|
||||
if (tH.isEnabled()) {
|
||||
HashMap<String, Serializable> townInfo = tH.getPlayerInfo(uuid);
|
||||
addReplace.put("%town%", Html.TOWN.parse(townInfo.get("TOWN") + ""));
|
||||
} else {
|
||||
addReplace.put("%town%", "");
|
||||
for (PluginData source : additionalDataSources) {
|
||||
if (source.analysisOnly()) {
|
||||
continue;
|
||||
}
|
||||
addReplace.put(source.getPlaceholder(""), source.getHtmlReplaceValue("", uuid));
|
||||
}
|
||||
return addReplace;
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import me.edge209.OnTime.OnTimeAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OnTimeHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private OnTimeAPI ontimeAPI;
|
||||
|
||||
/**
|
||||
* Hooks to OnTime plugin
|
||||
* @param plugin
|
||||
*/
|
||||
public OnTimeHook(Plan plugin) throws NoClassDefFoundError{
|
||||
super("me.edge209.OnTime.OnTime");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public OnTimeHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs information not provided by Player class or Plan from OnTime.
|
||||
* isEnabled() should be called before this method.
|
||||
*
|
||||
* @param uuid UUID of player
|
||||
* @return HashMap with boolean, int and string values: VOTES int, REFERRALS int
|
||||
*/
|
||||
public HashMap<String, Serializable> getOnTimeData(UUID uuid) {
|
||||
HashMap<String, Serializable> ontimeData = new HashMap<>();
|
||||
String name = Bukkit.getOfflinePlayer(uuid).getName();
|
||||
ontimeData.put("VOTES", OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.TOTALVOTE));
|
||||
ontimeData.put("REFERRALS", OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.TOTALREFER));
|
||||
return ontimeData;
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public abstract class PluginData {
|
||||
|
||||
protected String placeholder;
|
||||
protected String sourcePlugin;
|
||||
protected boolean analysisOnly;
|
||||
protected String icon;
|
||||
protected String prefix;
|
||||
protected String suffix;
|
||||
protected List<AnalysisType> analysisTypes;
|
||||
|
||||
public PluginData(String sourcePlugin, String placeholder, List<AnalysisType> analysisTypes) {
|
||||
this.placeholder = placeholder;
|
||||
this.sourcePlugin = sourcePlugin;
|
||||
analysisOnly = true;
|
||||
this.analysisTypes = analysisTypes;
|
||||
this.icon = "";
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
}
|
||||
|
||||
public PluginData(String sourcePlugin, String placeholder, AnalysisType... analysisTypes) {
|
||||
this(sourcePlugin, placeholder, Arrays.asList(analysisTypes));
|
||||
}
|
||||
|
||||
public PluginData(String sourcePlugin, String placeholder) {
|
||||
this(sourcePlugin, placeholder, new ArrayList<>());
|
||||
}
|
||||
|
||||
public List<AnalysisType> getAnalysisTypes() {
|
||||
return analysisTypes;
|
||||
}
|
||||
|
||||
public String parseContainer(String modifier, String contents) {
|
||||
return "<div class=\"plugin-data\">" + icon + modifier + prefix + contents + suffix + "</div>";
|
||||
}
|
||||
|
||||
public String getPlaceholder(String modifier) {
|
||||
return "%" + placeholder + modifier + "%";
|
||||
}
|
||||
|
||||
public String getSourcePlugin() {
|
||||
return sourcePlugin;
|
||||
}
|
||||
|
||||
public abstract String getHtmlReplaceValue(String modifierPrefix, UUID uuid);
|
||||
|
||||
public abstract Serializable getValue(UUID uuid);
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public void setSuffix(String suffix) {
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
public void setIcon(String iconName) {
|
||||
this.icon = Html.FONT_AWESOME_ICON.parse(iconName)+" ";
|
||||
}
|
||||
|
||||
public void setAnalysisOnly(boolean analysisOnly) {
|
||||
this.analysisOnly = analysisOnly;
|
||||
}
|
||||
|
||||
public boolean analysisOnly() {
|
||||
return analysisOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a PluginData object has same placeholder, sourcePlugin &
|
||||
* analysisTypes, it is considired equal.
|
||||
*
|
||||
* @param obj Another Object.
|
||||
* @return Is current object equal to given object.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final PluginData other = (PluginData) obj;
|
||||
if (this.analysisOnly != other.analysisOnly) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.placeholder, other.placeholder)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.sourcePlugin, other.sourcePlugin)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.analysisTypes, other.analysisTypes)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 47 * hash + Objects.hashCode(this.placeholder);
|
||||
hash = 47 * hash + Objects.hashCode(this.sourcePlugin);
|
||||
hash = 47 * hash + (this.analysisOnly ? 1 : 0);
|
||||
hash = 47 * hash + Objects.hashCode(this.prefix);
|
||||
hash = 47 * hash + Objects.hashCode(this.suffix);
|
||||
hash = 47 * hash + Objects.hashCode(this.analysisTypes);
|
||||
return hash;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import io.minimum.minecraft.superbvote.storage.VoteStorage;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SuperbVoteHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private VoteStorage votes;
|
||||
|
||||
/**
|
||||
* Hooks to SuperbVote plugin
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public SuperbVoteHook(Plan plugin) throws NoClassDefFoundError {
|
||||
super("io.minimum.minecraft.superbvote.SuperbVote");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SuperbVoteHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs votes from SuperbVote.
|
||||
* isEnabled() should be called before this
|
||||
* method.
|
||||
*
|
||||
* @param uuid UUID of player
|
||||
* @return Amount of votes
|
||||
*/
|
||||
public int getVotes(UUID uuid) {
|
||||
return votes.getVotes(uuid);
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.TownComparator;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TownyHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private Towny towny;
|
||||
|
||||
/**
|
||||
* Hooks to Factions plugin
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public TownyHook(Plan plugin) throws NoClassDefFoundError {
|
||||
super("com.palmergames.bukkit.towny.Towny");
|
||||
this.plugin = plugin;
|
||||
this.towny = getPlugin(Towny.class);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public TownyHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of Faction names sorted by power
|
||||
*/
|
||||
public List<String> getTopTowns() {
|
||||
List<Town> topTowns = TownyUniverse.getDataSource().getTowns();
|
||||
Collections.sort(topTowns, new TownComparator());
|
||||
List<String> townNames = topTowns.stream()
|
||||
.map(town -> town.getName())
|
||||
.collect(Collectors.toList());
|
||||
return townNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab basic info about Town. isEnabled() should be called before this
|
||||
* method.
|
||||
*
|
||||
* @param townName Name of the town.
|
||||
* @return HashMap containing boolean, number & string: RESIDENTS int, MAYOR string, LAND int
|
||||
*/
|
||||
public HashMap<String, Serializable> getTownInfo(String townName) {
|
||||
HashMap<String, Serializable> info = new HashMap<>();
|
||||
try {
|
||||
Town town = TownyUniverse.getDataSource().getTown(townName);
|
||||
info.put("RESIDENTS", town.getNumResidents());
|
||||
info.put("MAYOR", town.getMayor().getName());
|
||||
info.put("LAND", town.getPurchasedBlocks());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab basic info about Player. isEnabled() should be called before this
|
||||
* method.
|
||||
*
|
||||
* @param uuid UUID of player
|
||||
* @return HashMap containing boolean, number & string: TOWN string, Friends string
|
||||
*/
|
||||
public HashMap<String, Serializable> getPlayerInfo(UUID uuid) {
|
||||
HashMap<String, Serializable> info = new HashMap<>();
|
||||
String name = getOfflinePlayer(uuid).getName();
|
||||
try {
|
||||
Resident res = TownyUniverse.getDataSource().getResident(name);
|
||||
if (res.hasTown()) {
|
||||
info.put("TOWN", res.getTown().getName());
|
||||
} else {
|
||||
info.put("TOWN", Phrase.NOT_IN_TOWN+"");
|
||||
}
|
||||
info.put("FRIENDS", res.getFriends().toString());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.advancedachievements;
|
||||
|
||||
import com.hm.achievement.api.AdvancedAchievementsAPI;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AdvancedAchievementsAchievements extends PluginData {
|
||||
|
||||
private AdvancedAchievementsAPI aaAPI;
|
||||
|
||||
public AdvancedAchievementsAchievements(AdvancedAchievementsAPI aaAPI) {
|
||||
super("AdvancedAchievements", "achievements", new AnalysisType[]{AnalysisType.INT_TOTAL, AnalysisType.INT_AVG});
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Achivements: ");
|
||||
super.setSuffix(" / %totalachievements%");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
return parseContainer(modifierPrefix, aaAPI.getPlayerTotalAchievements(uuid) + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
return aaAPI.getPlayerTotalAchievements(uuid);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.advancedachievements;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.additional.Hook;
|
||||
import com.hm.achievement.AdvancedAchievements;
|
||||
import com.hm.achievement.api.AdvancedAchievementsAPI;
|
||||
import com.hm.achievement.api.AdvancedAchievementsBukkitAPI;
|
||||
import com.hm.achievement.category.MultipleAchievements;
|
||||
import com.hm.achievement.category.NormalAchievements;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.API;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AdvancedAchievementsHook extends Hook {
|
||||
|
||||
private AdvancedAchievements hookedPlugin;
|
||||
private AdvancedAchievementsAPI aaAPI;
|
||||
|
||||
/**
|
||||
* Hooks the plugin and calculates Total Achievements.
|
||||
*/
|
||||
public AdvancedAchievementsHook() throws NoClassDefFoundError {
|
||||
super("com.hm.achievement.AdvancedAchievements");
|
||||
if (enabled) {
|
||||
if (Integer.parseInt(Character.toString(hookedPlugin.getDescription().getVersion().charAt(0))) >= 5) {
|
||||
aaAPI = AdvancedAchievementsBukkitAPI.linkAdvancedAchievements();
|
||||
API planAPI = Plan.getPlanAPI();
|
||||
planAPI.addPluginDataSource(new AdvancedAchievementsTable(aaAPI));
|
||||
planAPI.addPluginDataSource(new AdvancedAchievementsTotalAchievements(calcTotalAchievements()));
|
||||
planAPI.addPluginDataSource(new AdvancedAchievementsAchievements(aaAPI));
|
||||
} else {
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int calcTotalAchievements() {
|
||||
int total = 0;
|
||||
for (NormalAchievements category : NormalAchievements.values()) {
|
||||
String categoryName = category.toString();
|
||||
if (hookedPlugin.getDisabledCategorySet().contains(categoryName)) {
|
||||
// Ignore this type.
|
||||
continue;
|
||||
}
|
||||
total += hookedPlugin.getPluginConfig().getConfigurationSection(categoryName).getKeys(false).size();
|
||||
}
|
||||
for (MultipleAchievements category : MultipleAchievements.values()) {
|
||||
String categoryName = category.toString();
|
||||
if (hookedPlugin.getDisabledCategorySet().contains(categoryName)) {
|
||||
// Ignore this type.
|
||||
continue;
|
||||
}
|
||||
for (String item : hookedPlugin.getPluginConfig().getConfigurationSection(categoryName).getKeys(false)) {
|
||||
total += hookedPlugin.getPluginConfig().getConfigurationSection(categoryName + '.' + item)
|
||||
.getKeys(false).size();
|
||||
}
|
||||
}
|
||||
if (!hookedPlugin.getDisabledCategorySet().contains("Commands")) {
|
||||
total += hookedPlugin.getPluginConfig().getConfigurationSection("Commands").getKeys(false).size();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.advancedachievements;
|
||||
|
||||
import com.hm.achievement.api.AdvancedAchievementsAPI;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayers;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AdvancedAchievementsTable extends PluginData {
|
||||
|
||||
private AdvancedAchievementsAPI aaAPI;
|
||||
|
||||
public AdvancedAchievementsTable(AdvancedAchievementsAPI aaAPI) {
|
||||
super("AdvancedAchievements", "achievementstable", AnalysisType.HTML);
|
||||
String player = Html.FONT_AWESOME_ICON.parse("user") + "Player";
|
||||
String achievements = Html.FONT_AWESOME_ICON.parse("check-circle-o") + "Achievements";
|
||||
// analysisOnly true by default.
|
||||
super.setPrefix(Html.TABLE_START_2.parse(player, achievements));
|
||||
super.setSuffix(Html.TABLE_END.parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
List<OfflinePlayer> offlinePlayers = Arrays.stream(getOfflinePlayers()).filter(p -> p.hasPlayedBefore()).collect(Collectors.toList());
|
||||
if (offlinePlayers.isEmpty()) {
|
||||
html.append(Html.TABLELINE_2.parse("No Players.",""));
|
||||
} else {
|
||||
for (OfflinePlayer p : offlinePlayers) {
|
||||
String inspectUrl = HtmlUtils.getInspectUrl(p.getName());
|
||||
String achievements = aaAPI.getPlayerTotalAchievements(p.getUniqueId()) + "";
|
||||
html.append(Html.TABLELINE_2.parse(inspectUrl, achievements));
|
||||
}
|
||||
}
|
||||
return parseContainer(modifierPrefix, html.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
return "";
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.advancedachievements;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AdvancedAchievementsTotalAchievements extends PluginData {
|
||||
|
||||
private int totalAchievements;
|
||||
|
||||
public AdvancedAchievementsTotalAchievements(int totalAchievements) {
|
||||
super("AdvancedAchievements", "totalachievements", AnalysisType.TOTAL_VALUE);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Total Achivements: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
return totalAchievements + "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
return totalAchievements;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.essentials;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.additional.Hook;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.API;
|
||||
import main.java.com.djrapitops.plan.data.additional.essentials.EssentialsJailed;
|
||||
import main.java.com.djrapitops.plan.data.additional.essentials.EssentialsMuted;
|
||||
import main.java.com.djrapitops.plan.data.additional.essentials.EssentialsWarps;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class EssentialsHook extends Hook {
|
||||
|
||||
private Essentials ess;
|
||||
private List<String> warps;
|
||||
|
||||
/**
|
||||
* Hooks to Essentials plugin
|
||||
*
|
||||
*/
|
||||
public EssentialsHook() throws NoClassDefFoundError{
|
||||
super("com.earth2me.essentials.Essentials");
|
||||
if (super.isEnabled()) {
|
||||
ess = getPlugin(Essentials.class);
|
||||
API planAPI = Plan.getPlanAPI();
|
||||
planAPI.addPluginDataSource(new EssentialsJailed(ess));
|
||||
planAPI.addPluginDataSource(new EssentialsMuted(ess));
|
||||
planAPI.addPluginDataSource(new EssentialsWarps(ess));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.essentials;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class EssentialsJailed extends PluginData {
|
||||
|
||||
private Essentials essentials;
|
||||
|
||||
public EssentialsJailed(Essentials essentials) {
|
||||
super("Essentials", "jailed", AnalysisType.BOOLEAN_PERCENTAGE, AnalysisType.BOOLEAN_TOTAL);
|
||||
this.essentials = essentials;
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Jailed: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifier, UUID uuid) {
|
||||
User user = essentials.getUser(uuid);
|
||||
if (user != null) {
|
||||
return parseContainer(modifier, user.isJailed() ? "Yes" : "No");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
User user = essentials.getUser(uuid);
|
||||
return user != null && user.isJailed();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.essentials;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class EssentialsMuted extends PluginData {
|
||||
|
||||
private Essentials essentials;
|
||||
|
||||
public EssentialsMuted(Essentials essentials) {
|
||||
super("Essentials", "muted", AnalysisType.BOOLEAN_PERCENTAGE, AnalysisType.BOOLEAN_TOTAL);
|
||||
this.essentials = essentials;
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Muted: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifier, UUID uuid) {
|
||||
User user = essentials.getUser(uuid);
|
||||
if (user != null) {
|
||||
return parseContainer("", user.isMuted()? "Yes" : "No");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
User user = essentials.getUser(uuid);
|
||||
return user != null && user.isMuted();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.essentials;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.Warps;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class EssentialsWarps extends PluginData {
|
||||
|
||||
private Essentials essentials;
|
||||
|
||||
public EssentialsWarps(Essentials essentials) {
|
||||
super("Essentials", "warps");
|
||||
this.essentials = essentials;
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Warps: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifier, UUID uuid) {
|
||||
Warps warps = essentials.getWarps();
|
||||
if (!warps.isEmpty()) {
|
||||
return parseContainer("", warps.getList().toString());
|
||||
}
|
||||
return parseContainer("", "No Warps.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
Warps warps = essentials.getWarps();
|
||||
if (!warps.isEmpty()) {
|
||||
return warps.getList().toString();
|
||||
}
|
||||
return "No Warps.";
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package main.java.com.djrapitops.plan.utilities.comparators;
|
||||
package main.java.com.djrapitops.plan.data.additional.factions;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import java.util.Comparator;
|
@ -0,0 +1,32 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.factions;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class FactionsFaction extends PluginData {
|
||||
|
||||
public FactionsFaction() {
|
||||
super("Factions", "faction");
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Faction: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
MPlayer mPlayer = MPlayer.get(uuid);
|
||||
return parseContainer("", mPlayer.getFactionName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
MPlayer mPlayer = MPlayer.get(uuid);
|
||||
return mPlayer.getFactionName();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.factions;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.additional.Hook;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.api.API;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class FactionsHook extends Hook {
|
||||
|
||||
/**
|
||||
* Hooks to Factions plugin
|
||||
*
|
||||
*/
|
||||
public FactionsHook() {
|
||||
super("com.massivecraft.factions.Factions");
|
||||
if (enabled) {
|
||||
API planAPI = Plan.getPlanAPI();
|
||||
planAPI.addPluginDataSource(new FactionsTable(this.getTopFactions()));
|
||||
planAPI.addPluginDataSource(new FactionsFaction());
|
||||
planAPI.addPluginDataSource(new FactionsPower());
|
||||
planAPI.addPluginDataSource(new FactionsMaxPower());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of Faction names sorted by power
|
||||
*/
|
||||
public List<Faction> getTopFactions() {
|
||||
List<Faction> topFactions = new ArrayList<>();
|
||||
topFactions.addAll(FactionColl.get().getAll());
|
||||
topFactions.remove(FactionColl.get().getWarzone());
|
||||
topFactions.remove(FactionColl.get().getSafezone());
|
||||
topFactions.remove(FactionColl.get().getNone());
|
||||
List<String> hide = Settings.HIDE_FACTIONS.getStringList();
|
||||
Collections.sort(topFactions, new FactionComparator());
|
||||
List<Faction> factionNames = topFactions.stream()
|
||||
.filter(faction -> !hide.contains(faction.getName()))
|
||||
.collect(Collectors.toList());
|
||||
return factionNames;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.factions;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class FactionsMaxPower extends PluginData {
|
||||
|
||||
public FactionsMaxPower() {
|
||||
super("Factions", "maxpower", AnalysisType.TOTAL_VALUE);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Max Power: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
MPlayer mPlayer = MPlayer.get(uuid);
|
||||
return parseContainer(modifierPrefix, FormatUtils.cutDecimals(mPlayer.getPowerMax()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
MPlayer mPlayer = MPlayer.get(uuid);
|
||||
return mPlayer.getPowerMax();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.factions;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class FactionsPower extends PluginData {
|
||||
|
||||
public FactionsPower() {
|
||||
super("Factions", "power", AnalysisType.DOUBLE_AVG);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Power: ");
|
||||
super.setSuffix(" / %maxpower%");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
MPlayer mPlayer = MPlayer.get(uuid);
|
||||
return parseContainer(modifierPrefix, FormatUtils.cutDecimals(mPlayer.getPower()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
MPlayer mPlayer = MPlayer.get(uuid);
|
||||
return mPlayer.getPower();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.factions;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class FactionsTable extends PluginData {
|
||||
|
||||
private List<Faction> factions;
|
||||
|
||||
public FactionsTable(List<Faction> factions) {
|
||||
super("Factions", "factionstable", AnalysisType.HTML);
|
||||
this.factions = factions;
|
||||
super.setPrefix(Html.TABLE_FACTIONS_START.parse());
|
||||
super.setSuffix(Html.TABLE_END.parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
if (factions.isEmpty()) {
|
||||
html.append(Html.TABLELINE_4.parse(Html.FACTION_NO_FACTIONS.parse(), "", "", ""));
|
||||
} else {
|
||||
for (Faction f : factions) {
|
||||
String name;
|
||||
String leader;
|
||||
String power;
|
||||
String land;
|
||||
if (f != null) {
|
||||
name = f.getName();
|
||||
MPlayer fLeader = f.getLeader();
|
||||
leader = fLeader != null ? fLeader.getNameAndSomething("", "") : Html.FACTION_NO_LEADER.parse();
|
||||
power = FormatUtils.cutDecimals(f.getPower());
|
||||
land = f.getLandCount() + "";
|
||||
} else {
|
||||
name = Html.FACTION_NOT_FOUND.parse();
|
||||
leader = Html.FACTION_NOT_FOUND.parse();
|
||||
power = Html.FACTION_NOT_FOUND.parse();
|
||||
land = Html.FACTION_NOT_FOUND.parse();
|
||||
}
|
||||
String leaderPage = Html.LINK.parse(HtmlUtils.getInspectUrl(leader), leader);
|
||||
html.append(Html.TABLELINE_4.parse(name, power, land, leaderPage));
|
||||
}
|
||||
}
|
||||
return parseContainer(modifierPrefix, html.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
MPlayer mPlayer = MPlayer.get(uuid);
|
||||
return mPlayer.getPower();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.ontime;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.additional.Hook;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.API;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OnTimeHook extends Hook {
|
||||
|
||||
|
||||
/**
|
||||
* Hooks to OnTime plugin
|
||||
*/
|
||||
public OnTimeHook() throws NoClassDefFoundError {
|
||||
super("me.edge209.OnTime.OnTime");
|
||||
if (enabled) {
|
||||
API planAPI = Plan.getPlanAPI();
|
||||
planAPI.addPluginDataSource(new OntimeVotes());
|
||||
planAPI.addPluginDataSource(new OntimeVotesWeek());
|
||||
planAPI.addPluginDataSource(new OntimeVotesMonth());
|
||||
planAPI.addPluginDataSource(new OntimeRefer());
|
||||
planAPI.addPluginDataSource(new OntimeReferWeek());
|
||||
planAPI.addPluginDataSource(new OntimeReferMonth());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.ontime;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import me.edge209.OnTime.OnTimeAPI;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OntimeRefer extends PluginData {
|
||||
|
||||
public OntimeRefer() {
|
||||
super("OnTime", "refer", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Referrals All Time: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return "";
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long referTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.TOTALREFER);
|
||||
if (referTotal == -1) {
|
||||
return parseContainer(modifierPrefix, "No Referrals.");
|
||||
}
|
||||
return parseContainer(modifierPrefix, referTotal + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long referTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.TOTALREFER);
|
||||
if (referTotal == -1) {
|
||||
return 0;
|
||||
}
|
||||
return referTotal;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.ontime;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import me.edge209.OnTime.OnTimeAPI;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OntimeReferMonth extends PluginData {
|
||||
|
||||
public OntimeReferMonth() {
|
||||
super("OnTime", "refer_30d", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Referrals Last 30d: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return "";
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long referTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.MONTHREFER);
|
||||
if (referTotal == -1) {
|
||||
return parseContainer(modifierPrefix, "No Referrals.");
|
||||
}
|
||||
return parseContainer(modifierPrefix, referTotal + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long referTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.MONTHREFER);
|
||||
if (referTotal == -1) {
|
||||
return 0;
|
||||
}
|
||||
return referTotal;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.ontime;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import me.edge209.OnTime.OnTimeAPI;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OntimeReferWeek extends PluginData {
|
||||
|
||||
public OntimeReferWeek() {
|
||||
super("OnTime", "refer_7d", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Referrals Last 7d: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return "";
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long referTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.WEEKREFER);
|
||||
if (referTotal == -1) {
|
||||
return parseContainer(modifierPrefix, "No Referrals.");
|
||||
}
|
||||
return parseContainer(modifierPrefix, referTotal + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long referTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.WEEKREFER);
|
||||
if (referTotal == -1) {
|
||||
return 0;
|
||||
}
|
||||
return referTotal;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.ontime;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import me.edge209.OnTime.OnTimeAPI;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OntimeVotes extends PluginData {
|
||||
|
||||
public OntimeVotes() {
|
||||
super("OnTime", "votes", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Votes All Time: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return "";
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long votesTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.TOTALVOTE);
|
||||
if (votesTotal == -1) {
|
||||
return parseContainer(modifierPrefix, "No votes.");
|
||||
}
|
||||
return parseContainer(modifierPrefix, votesTotal + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long votesTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.TOTALVOTE);
|
||||
if (votesTotal == -1) {
|
||||
return 0;
|
||||
}
|
||||
return votesTotal;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.ontime;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import me.edge209.OnTime.OnTimeAPI;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OntimeVotesMonth extends PluginData {
|
||||
|
||||
public OntimeVotesMonth() {
|
||||
super("OnTime", "votes_30d", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Votes Last 30d: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return "";
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long votesTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.MONTHVOTE);
|
||||
if (votesTotal == -1) {
|
||||
return parseContainer(modifierPrefix, "No votes.");
|
||||
}
|
||||
return parseContainer(modifierPrefix, votesTotal + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long votesTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.MONTHVOTE);
|
||||
if (votesTotal == -1) {
|
||||
return 0;
|
||||
}
|
||||
return votesTotal;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.ontime;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import me.edge209.OnTime.OnTimeAPI;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OntimeVotesWeek extends PluginData {
|
||||
|
||||
public OntimeVotesWeek() {
|
||||
super("OnTime", "votes_7d", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Votes Last 7d: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return "";
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long votesTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.WEEKVOTE);
|
||||
if (votesTotal == -1) {
|
||||
return parseContainer(modifierPrefix, "No votes.");
|
||||
}
|
||||
return parseContainer(modifierPrefix, votesTotal + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long votesTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.WEEKVOTE);
|
||||
if (votesTotal == -1) {
|
||||
return 0;
|
||||
}
|
||||
return votesTotal;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package main.java.com.djrapitops.plan.utilities.comparators;
|
||||
package main.java.com.djrapitops.plan.data.additional.towny;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import java.util.Comparator;
|
@ -0,0 +1,44 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.towny;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.additional.Hook;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.api.API;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TownyHook extends Hook {
|
||||
|
||||
/**
|
||||
* Hooks to Factions plugin
|
||||
*
|
||||
*/
|
||||
public TownyHook() throws NoClassDefFoundError {
|
||||
super("com.palmergames.bukkit.towny.Towny");
|
||||
if (enabled) {
|
||||
API planAPI = Plan.getPlanAPI();
|
||||
planAPI.addPluginDataSource(new TownyTable(getTopTowns()));
|
||||
planAPI.addPluginDataSource(new TownyTown());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of Faction names sorted by power
|
||||
*/
|
||||
public List<Town> getTopTowns() {
|
||||
List<Town> topTowns = TownyUniverse.getDataSource().getTowns();
|
||||
Collections.sort(topTowns, new TownComparator());
|
||||
List<String> hide = Settings.HIDE_TOWNS.getStringList();
|
||||
List<Town> townNames = topTowns.stream()
|
||||
.filter(town -> !hide.contains(town.getName()))
|
||||
.collect(Collectors.toList());
|
||||
return townNames;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.towny;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TownyTable extends PluginData {
|
||||
|
||||
private List<Town> towns;
|
||||
|
||||
public TownyTable(List<Town> towns) {
|
||||
super("Towny", "townstable", AnalysisType.HTML);
|
||||
this.towns = towns;
|
||||
super.setPrefix(Html.TABLE_TOWNS_START.parse());
|
||||
super.setSuffix(Html.TABLE_END.parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
if (towns.isEmpty()) {
|
||||
html.append(Html.TABLELINE_4.parse(Html.TOWN_NO_TOWNS.parse(), "", "", ""));
|
||||
} else {
|
||||
for (Town t : towns) {
|
||||
String name = t.getName();
|
||||
String mayor = t.getMayor().getName();
|
||||
String residents = t.getNumResidents() + "";
|
||||
String land = t.getPurchasedBlocks() + "";
|
||||
String leaderPage = Html.LINK.parse(HtmlUtils.getInspectUrl(mayor), mayor);
|
||||
html.append(Html.TABLELINE_4.parse(name, residents, land, leaderPage));
|
||||
}
|
||||
}
|
||||
return parseContainer(modifierPrefix, html.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
MPlayer mPlayer = MPlayer.get(uuid);
|
||||
return mPlayer.getPower();
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package main.java.com.djrapitops.plan.data.additional.towny;
|
||||
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TownyTown extends PluginData {
|
||||
|
||||
public TownyTown() {
|
||||
super("Towny", "town");
|
||||
super.setAnalysisOnly(false);
|
||||
super.setPrefix("Town: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return "";
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
try {
|
||||
Resident res = TownyUniverse.getDataSource().getResident(name);
|
||||
String town;
|
||||
if (res.hasTown()) {
|
||||
town = res.getTown().getName();
|
||||
} else {
|
||||
town = Phrase.NOT_IN_TOWN + "";
|
||||
}
|
||||
return parseContainer("", town);
|
||||
} catch (NotRegisteredException ex) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return "";
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
try {
|
||||
Resident res = TownyUniverse.getDataSource().getResident(name);
|
||||
String town;
|
||||
if (res.hasTown()) {
|
||||
town = res.getTown().getName();
|
||||
} else {
|
||||
town = Phrase.NOT_IN_TOWN + "";
|
||||
}
|
||||
return town;
|
||||
} catch (NotRegisteredException ex) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,9 +12,9 @@ import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
*/
|
||||
public abstract class Table {
|
||||
|
||||
String tableName;
|
||||
SQLDB db;
|
||||
boolean usingMySQL;
|
||||
protected String tableName;
|
||||
protected SQLDB db;
|
||||
protected boolean usingMySQL;
|
||||
|
||||
public Table(String name, SQLDB db, boolean usingMySQL) {
|
||||
this.tableName = name;
|
||||
@ -24,7 +24,7 @@ public abstract class Table {
|
||||
|
||||
public abstract boolean createTable();
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
protected Connection getConnection() throws SQLException {
|
||||
Connection connection = db.getConnection();
|
||||
if (connection == null || connection.isClosed()) {
|
||||
connection = db.getNewConnection();
|
||||
@ -36,17 +36,17 @@ public abstract class Table {
|
||||
return db.getVersion();
|
||||
}
|
||||
|
||||
public boolean execute(String sql) throws SQLException {
|
||||
protected boolean execute(String sql) throws SQLException {
|
||||
Connection connection = getConnection();
|
||||
boolean success = connection.createStatement().execute(sql);
|
||||
return success;
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
protected PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
return getConnection().prepareStatement(sql);
|
||||
}
|
||||
|
||||
public void close(AutoCloseable toClose) {
|
||||
protected void close(AutoCloseable toClose) {
|
||||
if (toClose != null) {
|
||||
try {
|
||||
toClose.close();
|
||||
|
@ -32,28 +32,22 @@ public enum Html {
|
||||
COLOR_d("<span class=\"pink\">"),
|
||||
COLOR_e("<span class=\"yellow\">"),
|
||||
COLOR_f("<span class=\"white\">"),
|
||||
//
|
||||
FONT_AWESOME_ICON("<i class=\"fa fa-REPLACE0\" aria-hidden=\"true\"></i>"),
|
||||
SPAN("" + REPLACE0 + "</span>"),
|
||||
BUTTON("<a class=\"button\" href=\"" + REPLACE0 + "\">" + REPLACE1 + "</a>"),
|
||||
BUTTON_CLASS("class=\"button\""),
|
||||
LINK("<a class=\"link\" href=\"" + REPLACE0 + "\">" + REPLACE1 + "</a>"),
|
||||
LINK_CLASS("class=\"link\""),
|
||||
IMG("<img src=\"" + REPLACE0 + "\">"),
|
||||
//
|
||||
TOP_TOWNS("<p><b>Top 20 Towns</b></p>"),
|
||||
TOP_FACTIONS("<p><b>Top 20 Factions</b></p>"),
|
||||
TOTAL_BALANCE("<p>Server Total Balance: " + REPLACE0 + "</p>"),
|
||||
TOTAL_VOTES("<p>Players have voted total of " + REPLACE0 + " times.</p>"),
|
||||
PLOT_OPTIONS("<p>Plot options: " + REPLACE0 + "</p>"),
|
||||
FRIENDS("<p>Friends with " + REPLACE0 + "</p>"),
|
||||
BALANCE("<p>Balance: " + REPLACE0 + "</p>"),
|
||||
BANNED("| " + SPAN.parse(COLOR_4.parse() + "Banned")),
|
||||
OPERATOR(", Operator (Op)"),
|
||||
ONLINE("| " + SPAN.parse(COLOR_2.parse() + "Online")),
|
||||
OFFLINE("| " + SPAN.parse(COLOR_4.parse() + "Offline")),
|
||||
ACTIVE("Player is Active"),
|
||||
INACTIVE("Player is inactive"),
|
||||
ERROR_LIST("Error Creating List</p>"),
|
||||
HIDDEN("Hidden (config)"),
|
||||
ERROR_NOT_SET("Error: Replace rule was not set"),
|
||||
BALANCE("<p>Balance: " + REPLACE0 + "</p>"),
|
||||
FACTION_NOT_FOUND("Faction not found"),
|
||||
FACTION_NO_LEADER("No leader"),
|
||||
FACTION_NO_FACTIONS("No Factions"),
|
||||
@ -65,6 +59,17 @@ public enum Html {
|
||||
FACTION("<br/>Faction: " + REPLACE0 + " | Power: " + REPLACE1 + "/REPLACE2"),
|
||||
TOWN("<br/>Town: " + REPLACE0),
|
||||
TOWN_NO_TOWNS("No Towns"),
|
||||
//
|
||||
BANNED("| " + SPAN.parse(COLOR_4.parse() + "Banned")),
|
||||
OPERATOR(", Operator (Op)"),
|
||||
ONLINE("| " + SPAN.parse(COLOR_2.parse() + "Online")),
|
||||
OFFLINE("| " + SPAN.parse(COLOR_4.parse() + "Offline")),
|
||||
ACTIVE("Player is Active"),
|
||||
INACTIVE("Player is inactive"),
|
||||
ERROR_LIST("Error Creating List</p>"),
|
||||
HIDDEN("Hidden (config)"),
|
||||
ERROR_NOT_SET("Error: Replace rule was not set"),
|
||||
//
|
||||
GRAPH_BANNED("Banned"),
|
||||
GRAPH_UNKNOWN("Unknown"),
|
||||
GRAPH_INACTIVE("Inactive"),
|
||||
@ -72,6 +77,8 @@ public enum Html {
|
||||
GRAPH_ONLINE("Players Online"),
|
||||
GRAPH_PLAYERS("Players"),
|
||||
GRAPH_DATE("Date"),
|
||||
//
|
||||
TABLE_START_2("<table class=\"sortable table\"><thead><tr><th>REPLACE0</th><th>REPLACE1</th></tr></thead><tbody>"),
|
||||
TABLE_START_3("<table class=\"sortable table\"><thead><tr><th>REPLACE0</th><th>REPLACE1</th><th>REPLACE2</th></tr></thead><tbody>"),
|
||||
TABLE_START_4("<table class=\"sortable table\"><thead><tr><th>REPLACE0</th><th>REPLACE1</th><th>REPLACE2</th><th>REPLACE3</th></tr></thead><tbody>"),
|
||||
TABLE_SESSIONS_START(TABLE_START_3.parse("Session Started", "Session Ended", "Session Length")),
|
||||
|
@ -23,7 +23,7 @@ public class PlayerActivityGraphCreator {
|
||||
public static String[] generateDataArray(List<SessionData> sessionData, long scale, int maxPlayers) {
|
||||
long now = new Date().toInstant().getEpochSecond() * (long) 1000;
|
||||
long nowMinusScale = now - scale;
|
||||
List<List<Long>> s = filterSessions(sessionData, nowMinusScale);
|
||||
List<List<Long>> s = filterAndTransformSessions(sessionData, nowMinusScale);
|
||||
List<Long> sessionStarts = s.get(0);
|
||||
List<Long> sessionEnds = s.get(1);
|
||||
List<Long> playersOnline = new ArrayList<>();
|
||||
@ -63,9 +63,10 @@ public class PlayerActivityGraphCreator {
|
||||
.count();
|
||||
}
|
||||
|
||||
public static List<List<Long>> filterSessions(List<SessionData> sessionData, long nowMinusScale) {
|
||||
public static List<List<Long>> filterAndTransformSessions(List<SessionData> sessionData, long nowMinusScale) {
|
||||
List<Long[]> values = sessionData.parallelStream()
|
||||
.filter(session -> (session != null))
|
||||
.filter(session -> session.isValid())
|
||||
.filter((session) -> (session.getSessionStart() >= nowMinusScale || session.getSessionEnd() >= nowMinusScale))
|
||||
.map(session -> new Long[]{session.getSessionStart(), session.getSessionEnd()})
|
||||
.collect(Collectors.toList());
|
||||
|
@ -1,41 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.ui.tables;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import main.java.com.djrapitops.plan.data.additional.FactionsHook;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SortableFactionsTableCreator {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param factionList
|
||||
* @param fHook
|
||||
* @return
|
||||
*/
|
||||
public static String createSortableFactionsTable(Collection<String> factionList, FactionsHook fHook) {
|
||||
String html = Html.TABLE_FACTIONS_START.parse();
|
||||
if (factionList.isEmpty()) {
|
||||
html += Html.TABLELINE_4.parse(Html.FACTION_NO_FACTIONS.parse(), "", "", "");
|
||||
} else {
|
||||
for (String factionName : factionList) {
|
||||
HashMap<String, Serializable> info = fHook.getFactionInfo(factionName);
|
||||
String leader = (String) info.get("LEADER");
|
||||
html += Html.TABLELINE_4.parse(
|
||||
factionName,
|
||||
info.get("POWER") + "",
|
||||
info.get("LAND") + "",
|
||||
Html.LINK.parse(HtmlUtils.getInspectUrl(leader), leader)
|
||||
);
|
||||
}
|
||||
}
|
||||
html += Html.TABLE_END.parse();
|
||||
return html;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.ui.tables;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import main.java.com.djrapitops.plan.data.additional.TownyHook;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SortableTownTableCreator {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param townNames
|
||||
* @param tHook
|
||||
* @return
|
||||
*/
|
||||
public static String createSortableTownsTable(Collection<String> townNames, TownyHook tHook) {
|
||||
String html = Html.TABLE_TOWNS_START.parse();
|
||||
if (townNames.isEmpty()) {
|
||||
html += Html.TABLELINE_4.parse(Html.TOWN_NO_TOWNS.parse(), "", "", "");
|
||||
} else {
|
||||
for (String town : townNames) {
|
||||
HashMap<String, Serializable> info = tHook.getTownInfo(town);
|
||||
html += Html.TABLELINE_4.parse(
|
||||
town,
|
||||
info.get("RESIDENTS") + "",
|
||||
info.get("LAND") + "",
|
||||
Html.LINK.parse(HtmlUtils.getInspectUrl((String) info.get("MAYOR")), (String) info.get("MAYOR"))
|
||||
);
|
||||
}
|
||||
}
|
||||
html += Html.TABLE_END.parse();
|
||||
return html;
|
||||
}
|
||||
}
|
@ -16,9 +16,9 @@ import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -105,7 +105,7 @@ public class PlaceholderUtils {
|
||||
+ "\",\"#" + Settings.HCOLOR_GENP_U + "\"");
|
||||
replaceMap.put("%genderfcolor%", "#" + Settings.HCOLOR_GENP_F);
|
||||
replaceMap.put("%gendermcolor%", "#" + Settings.HCOLOR_GENP_M);
|
||||
replaceMap.putAll(plugin.getHookHandler().getAdditionalAnalysisReplaceRules());
|
||||
replaceMap.putAll(data.getAdditionalDataReplaceMap());
|
||||
replaceMap.put("%sessionaverage%", FormatUtils.formatTimeAmount(data.getSessionAverage() + ""));
|
||||
replaceMap.put("%geomapcountries%", data.getGeomapCountries());
|
||||
replaceMap.put("%geomapz%", data.getGeomapZ());
|
||||
|
@ -61,6 +61,13 @@ Customization:
|
||||
Female: 'female, girl, gurl, woman, gal, mrs, she, miss, feminin, weiblich, mädchen, frau'
|
||||
Male: 'male, boy, man, boe, sir, mr, guy, he, männlich, maskulin, junge, mann'
|
||||
IgnoreWhen: 'sure, think, with, are, you, din'
|
||||
Plugins:
|
||||
Factions:
|
||||
HideFactions:
|
||||
- ExampleFaction
|
||||
Towny:
|
||||
HideTowns:
|
||||
- ExampleTown
|
||||
|
||||
database:
|
||||
type: sqlite
|
||||
|
@ -21,17 +21,17 @@ import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -19,10 +19,10 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -18,17 +18,17 @@ import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -21,11 +21,11 @@ import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1,8 +1,3 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.ui.graphs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -19,7 +14,7 @@ import org.junit.Test;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlayerActivityGraphCreatorTest {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -36,7 +31,7 @@ public class PlayerActivityGraphCreatorTest {
|
||||
String result = PlayerActivityGraphCreator.generateDataArray(sessionData, scale, 20)[1];
|
||||
assertTrue("0", 0 < result.length());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
@ -47,10 +42,78 @@ public class PlayerActivityGraphCreatorTest {
|
||||
long now = new Date().toInstant().getEpochSecond();
|
||||
while (list.size() < 500) {
|
||||
int randomStart = r.nextInt(2592000);
|
||||
long start = now - (long) (randomStart+10);
|
||||
long start = now - (long) (randomStart + 10);
|
||||
long end = start + (long) r.nextInt(randomStart);
|
||||
list.add(new SessionData((start * (long) 1000), (end * (long) 1000)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCount() {
|
||||
List<Long> test = new ArrayList<>();
|
||||
long exp = 5;
|
||||
test.add(5000L);
|
||||
test.add(5000L);
|
||||
test.add(5000L);
|
||||
test.add(5000L);
|
||||
test.add(5000L);
|
||||
test.add(0L);
|
||||
test.add(3450L);
|
||||
test.add(37560L);
|
||||
long result = PlayerActivityGraphCreator.getCount(test, 5000L);
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterSessions() {
|
||||
List<SessionData> test = new ArrayList<>();
|
||||
SessionData invalid = new SessionData(0);
|
||||
test.add(invalid);
|
||||
long now = 10000L;
|
||||
long nowMinusScale = now - 3000L;
|
||||
SessionData valid1 = new SessionData(9000L, 11000L);
|
||||
test.add(valid1);
|
||||
SessionData valid2 = new SessionData(8000L, 10000L);
|
||||
test.add(valid2);
|
||||
SessionData valid3 = new SessionData(7000L, 9000L);
|
||||
test.add(valid3);
|
||||
SessionData invalid2 = new SessionData(5000L, 5500L);
|
||||
test.add(invalid2);
|
||||
List<List<Long>> result = PlayerActivityGraphCreator.filterAndTransformSessions(test, nowMinusScale);
|
||||
List<Long> starts = result.get(0);
|
||||
List<Long> ends = result.get(1);
|
||||
assertTrue("Contained invalid session" + starts, !starts.contains(invalid.getSessionStart()));
|
||||
assertTrue("Contained invalid session" + starts, !starts.contains(invalid2.getSessionStart()));
|
||||
assertTrue("Contained invalid session" + ends, !ends.contains(invalid2.getSessionEnd()));
|
||||
assertTrue("Contained invalid session" + ends, !ends.contains(invalid2.getSessionEnd()));
|
||||
assertTrue("Did not contain valid session" + starts, starts.contains(valid1.getSessionStart()));
|
||||
assertTrue("Did not contain valid session" + ends, ends.contains(valid1.getSessionEnd()));
|
||||
assertTrue("Did not contain valid session" + starts, starts.contains(valid2.getSessionStart()));
|
||||
assertTrue("Did not contain valid session" + ends, ends.contains(valid2.getSessionEnd()));
|
||||
assertTrue("Did not contain valid session" + starts, starts.contains(valid3.getSessionStart()));
|
||||
assertTrue("Did not contain valid session" + ends, ends.contains(valid3.getSessionEnd()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSecond() {
|
||||
Date test = new Date();
|
||||
long exp = test.toInstant().getEpochSecond() * 1000L;
|
||||
long result = PlayerActivityGraphCreator.getSecond(test.getTime());
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSecond2() {
|
||||
long exp = 2000L;
|
||||
long result = PlayerActivityGraphCreator.getSecond(2456L);
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSecond3() {
|
||||
long exp = 2000L;
|
||||
long result = PlayerActivityGraphCreator.getSecond(2956L);
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ package test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import static org.junit.Assert.*;
|
||||
|
Loading…
x
Reference in New Issue
Block a user