mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-24 16:14:26 +08:00
Version 1.6.1
- Removed getData for plugins that did not offer OfflinePlayer support. - PlaceholderAPI is no longer returns data. - placeholders.yml is no longer read or created. - Unsupported Advanced Achievements versions no longer return data. Bugfixes: - Fixed Essentials Online Since, now shows proper value. (Was using afk check method instead of LastLogin.) - Essentials Offline Since now shows correct value even after reloads (Same cause as above) - Fixed Analysis failing because Time Average could not be converted to long from double. (Caused by DataType.TIME values) Other: - Hooks no longer return data if player has not played on the server. - Replaced some null checks with Optional.of().isPresent()
This commit is contained in:
parent
bbc6b7f05a
commit
b0e0697df6
@ -1,6 +1,7 @@
|
||||
compile.on.save=true
|
||||
do.depend=false
|
||||
do.jar=true
|
||||
file.reference.AdvancedAchievements-4.0.2.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\AdvancedAchievements.jar
|
||||
file.reference.craftbukkit-1.10.2.jar=D:\\Minecraft Servers\\Buildtools\\craftbukkit-1.10.2.jar
|
||||
file.reference.EssentialsX-2.0.1.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\EssentialsX-2.0.1.jar
|
||||
file.reference.OnTime.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\OnTime.jar
|
||||
|
@ -2,21 +2,6 @@
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/utils/MiscUtils.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/utils/Analysis.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/api/DataType.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/utils/DataFormatUtils.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/PlanCommand.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/commands/InfoCommand.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/api/API.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/utils/AnalysisUtils.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/EssentialsHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/AdvancedAchievementsHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/Plan.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/utils/DataUtils.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/plugin.yml</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/OnTimeHook.java</file>
|
||||
</group>
|
||||
<group/>
|
||||
</open-files>
|
||||
</project-private>
|
||||
|
@ -32,7 +32,6 @@ import org.bukkit.ChatColor;
|
||||
public class Plan extends JavaPlugin {
|
||||
|
||||
private final Map<String, Hook> hooks;
|
||||
private Hook placeholderAPIHook;
|
||||
private API api;
|
||||
private final Map<String, Hook> extraHooks;
|
||||
|
||||
@ -60,14 +59,8 @@ public class Plan extends JavaPlugin {
|
||||
|
||||
try {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
String[] placeholders = DataUtils.getPlaceholdersFileData();
|
||||
if (placeholders != null) {
|
||||
this.placeholderAPIHook = new PlaceholderAPIHook(this, placeholders);
|
||||
PlaceholderAPIHook phAHook = (PlaceholderAPIHook) placeholderAPIHook;
|
||||
phAHook.hook();
|
||||
} else {
|
||||
logToFile("Failed to read placeholders.yml\n");
|
||||
}
|
||||
PlaceholderAPIHook phAHook = new PlaceholderAPIHook(this);
|
||||
phAHook.hook();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logError("Failed to create placeholders.yml");
|
||||
@ -85,7 +78,7 @@ public class Plan extends JavaPlugin {
|
||||
this.api = new API(this);
|
||||
|
||||
log(MiscUtils.checkVersion());
|
||||
|
||||
|
||||
String loadedMsg = "Hooked into: ";
|
||||
for (String key : this.hooks.keySet()) {
|
||||
loadedMsg += ChatColor.GREEN + key + " ";
|
||||
@ -111,6 +104,8 @@ public class Plan extends JavaPlugin {
|
||||
"AdvancedAchievements", "BukkitData", "PlayerLogger"};
|
||||
List<String> plugins = new ArrayList<>();
|
||||
plugins.addAll(Arrays.asList(pluginsArray));
|
||||
StringBuilder errors = new StringBuilder();
|
||||
errors.append("MAIN-HOOKINIT\n");
|
||||
plugins.parallelStream().forEach((pluginName) -> {
|
||||
if (getConfig().getBoolean("visible." + pluginName.toLowerCase())) {
|
||||
try {
|
||||
@ -119,27 +114,17 @@ public class Plan extends JavaPlugin {
|
||||
this.hooks.put(pluginName, clazz.getConstructor(Plan.class).newInstance(this));
|
||||
} catch (Exception | NoClassDefFoundError e) {
|
||||
hookFail.add(pluginName);
|
||||
String toLog = "MAIN-HOOKINIT\nFailed to hook " + pluginName + "\n" + e;
|
||||
toLog += "\n" + e.getCause();
|
||||
logToFile(toLog);
|
||||
|
||||
errors.append("Failed to hook ").append(pluginName).append("\n").append(e);
|
||||
errors.append("\n").append(e.getCause());
|
||||
}
|
||||
} else {
|
||||
hookFail.add(ChatColor.YELLOW + pluginName);
|
||||
}
|
||||
});
|
||||
logToFile(errors.toString());
|
||||
for (String extraHook : this.extraHooks.keySet()) {
|
||||
this.hooks.put(extraHook, this.extraHooks.get(extraHook));
|
||||
}
|
||||
if (getConfig().getBoolean("visible.placeholderapi")) {
|
||||
if (this.placeholderAPIHook != null) {
|
||||
this.hooks.put("PlaceholderAPI", this.placeholderAPIHook);
|
||||
} else {
|
||||
hookFail.add("PlaceholderAPI");
|
||||
}
|
||||
} else {
|
||||
hookFail.add(ChatColor.YELLOW + "PlaceholderAPI");
|
||||
}
|
||||
return hookFail;
|
||||
}
|
||||
|
||||
@ -178,10 +163,6 @@ public class Plan extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public Hook getPlaceholderAPIHook() {
|
||||
return this.placeholderAPIHook;
|
||||
}
|
||||
|
||||
public API getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
@ -27,14 +27,6 @@ public class ReloadCommand extends SubCommand {
|
||||
List<String> hookFail = plugin.hookInit();
|
||||
ChatColor operatorColor = ChatColor.DARK_GREEN;
|
||||
ChatColor textColor = ChatColor.GRAY;
|
||||
try {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
PlaceholderAPIHook papih = (PlaceholderAPIHook) plugin.getPlaceholderAPIHook();
|
||||
papih.setPlaceholders(DataUtils.getPlaceholdersFileData());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.logToFile("RELOAD-PlaceholderAPI reload failed\n" + e);
|
||||
}
|
||||
sender.sendMessage(textColor + "[" + operatorColor + "PLAN" + textColor + "] Config & Hooks reloaded.");
|
||||
String loadedMsg = " Hooked into: ";
|
||||
for (String key : plugin.getHooks().keySet()) {
|
||||
|
@ -10,9 +10,10 @@ import com.hm.achievement.category.MultipleAchievements;
|
||||
import com.hm.achievement.category.NormalAchievements;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import static org.bukkit.Bukkit.getPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
public class AdvancedAchievementsHook implements Hook {
|
||||
@ -46,8 +47,8 @@ public class AdvancedAchievementsHook implements Hook {
|
||||
plugin.logError("Advanced Achievements 4.0.3 or above required for Offline players");
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
plugin.logToFile("AAHOOK\nError getting version number.\n" + e2+"\n"+e+"\n"
|
||||
+aAPlugin.getDescription().getVersion()+"\n"+Arrays.toString(aAVersion));
|
||||
plugin.logToFile("AAHOOK\nError getting version number.\n" + e2 + "\n" + e + "\n"
|
||||
+ aAPlugin.getDescription().getVersion() + "\n" + Arrays.toString(aAVersion));
|
||||
}
|
||||
}
|
||||
// Get total number of Achievements
|
||||
@ -72,34 +73,20 @@ public class AdvancedAchievementsHook implements Hook {
|
||||
if (!aAPlugin.getDisabledCategorySet().contains("Commands")) {
|
||||
totalAchievements += aAPlugin.getPluginConfig().getConfigurationSection("Commands").getKeys(false).size();
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getData(String player) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
// Check if achievements exist
|
||||
if (totalAchievements > 0) {
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
||||
try {
|
||||
// Check if correct method is present
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
||||
OfflinePlayer p = getOfflinePlayer(uuid);
|
||||
if (p.hasPlayedBefore()) {
|
||||
if (totalAchievements > 0) {
|
||||
if (this.usingUUID) {
|
||||
data.put("AAC-ACHIEVEMENTS", new DataPoint(aAPlugin.getDb().getPlayerAchievementsAmount(uuid.toString()) + " / " + totalAchievements, DataType.AMOUNT_WITH_MAX));
|
||||
} else {
|
||||
// Fallback method for older versions, only returns Online player data
|
||||
Player p;
|
||||
if (uuid != null) {
|
||||
p = getPlayer(uuid);
|
||||
} else {
|
||||
p = getPlayer(player);
|
||||
}
|
||||
|
||||
if (p != null) {
|
||||
data.put("AAC-ACHIEVEMENTS", new DataPoint(aAPlugin.getDb().getPlayerAchievementsAmount(p) + " / " + totalAchievements, DataType.AMOUNT_WITH_MAX));
|
||||
}
|
||||
plugin.log("You're using outdated version of AdvancedAchievements!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.logToFile("AAHOOK-GetData\nFailed to get data\n" + e + "\nfor: " + player);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
|
@ -5,6 +5,7 @@ import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.UUIDFetcher;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.DataType;
|
||||
import com.google.common.base.Optional;
|
||||
import java.util.HashMap;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.Location;
|
||||
@ -40,7 +41,7 @@ public class BukkitDataHook implements Hook {
|
||||
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
|
||||
if (p.hasPlayedBefore()) {
|
||||
Location loc = p.getBedSpawnLocation();
|
||||
if (loc != null) {
|
||||
if (Optional.of(loc).isPresent()) {
|
||||
data.put("BUK-BED LOCATION WORLD", new DataPoint(loc.getWorld().getName(), DataType.STRING));
|
||||
data.put("BUK-BED LOCATION", new DataPoint(" X:" + loc.getBlockX() + " Y:" + loc.getBlockY() + " Z:" + loc.getBlockZ(), DataType.LOCATION));
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.djrapitops.plan.command.hooks;
|
||||
|
||||
import com.djrapitops.plan.api.Hook;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.UUIDFetcher;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.DataType;
|
||||
import java.util.HashMap;
|
||||
@ -10,9 +11,12 @@ import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import com.earth2me.essentials.craftbukkit.BanLookup;
|
||||
import java.util.Optional;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
import org.bukkit.BanList;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class EssentialsHook implements Hook {
|
||||
|
||||
@ -29,39 +33,42 @@ public class EssentialsHook implements Hook {
|
||||
public HashMap<String, DataPoint> getData(String player) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
User user = this.ess.getOfflineUser(player);
|
||||
if (user != null) {
|
||||
if (this.ess.getServer().getBanList(BanList.Type.IP).isBanned(player)
|
||||
|| BanLookup.isBanned(this.ess, player)) {
|
||||
data.put("ESS-BANNED", new DataPoint("" + true, DataType.BOOLEAN));
|
||||
data.put("ESS-BAN REASON", new DataPoint("" + BanLookup.getBanEntry(this.ess, player).getReason(), DataType.STRING));
|
||||
}
|
||||
if (user.isJailed()) {
|
||||
data.put("ESS-JAILED", new DataPoint("" + true, DataType.BOOLEAN));
|
||||
data.put("ESS-JAIL TIME", new DataPoint("" + user.getJailTimeout(), DataType.TIME));
|
||||
}
|
||||
if (user.isMuted()) {
|
||||
data.put("ESS-MUTED", new DataPoint("" + true, DataType.BOOLEAN));
|
||||
data.put("ESS-MUTE TIME", new DataPoint("" + user.getMuteTimeout(), DataType.TIME));
|
||||
}
|
||||
try {
|
||||
if (user.isReachable()) {
|
||||
Location loc = user.getLocation();
|
||||
data.put("ESS-LOCATION WORLD", new DataPoint(loc.getWorld().getName(), DataType.STRING));
|
||||
data.put("ESS-LOCATION", new DataPoint(" X:" + loc.getBlockX() + " Y:" + loc.getBlockY() + " Z:" + loc.getBlockZ(), DataType.LOCATION));
|
||||
} else {
|
||||
Location loc = user.getLogoutLocation();
|
||||
data.put("ESS-LOCATION WORLD", new DataPoint(loc.getWorld().getName(), DataType.STRING));
|
||||
data.put("ESS-LOCATION", new DataPoint("X:" + loc.getBlockX() + " Y:" + loc.getBlockY() + " Z:" + loc.getBlockZ(), DataType.LOCATION));
|
||||
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
|
||||
if (p.hasPlayedBefore()) {
|
||||
if (Optional.of(user).isPresent()) {
|
||||
if (this.ess.getServer().getBanList(BanList.Type.IP).isBanned(player)
|
||||
|| BanLookup.isBanned(this.ess, player)) {
|
||||
data.put("ESS-BANNED", new DataPoint("" + true, DataType.BOOLEAN));
|
||||
data.put("ESS-BAN REASON", new DataPoint("" + BanLookup.getBanEntry(this.ess, player).getReason(), DataType.STRING));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.plugin.logToFile("ESSENTIALSHOOK\n" + e + "\n" + e.getMessage());
|
||||
if (user.isJailed()) {
|
||||
data.put("ESS-JAILED", new DataPoint("" + true, DataType.BOOLEAN));
|
||||
data.put("ESS-JAIL TIME", new DataPoint("" + user.getJailTimeout(), DataType.TIME));
|
||||
}
|
||||
if (user.isMuted()) {
|
||||
data.put("ESS-MUTED", new DataPoint("" + true, DataType.BOOLEAN));
|
||||
data.put("ESS-MUTE TIME", new DataPoint("" + user.getMuteTimeout(), DataType.TIME));
|
||||
}
|
||||
try {
|
||||
if (user.isReachable()) {
|
||||
Location loc = user.getLocation();
|
||||
data.put("ESS-LOCATION WORLD", new DataPoint(loc.getWorld().getName(), DataType.STRING));
|
||||
data.put("ESS-LOCATION", new DataPoint(" X:" + loc.getBlockX() + " Y:" + loc.getBlockY() + " Z:" + loc.getBlockZ(), DataType.LOCATION));
|
||||
} else {
|
||||
Location loc = user.getLogoutLocation();
|
||||
data.put("ESS-LOCATION WORLD", new DataPoint(loc.getWorld().getName(), DataType.STRING));
|
||||
data.put("ESS-LOCATION", new DataPoint("X:" + loc.getBlockX() + " Y:" + loc.getBlockY() + " Z:" + loc.getBlockZ(), DataType.LOCATION));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.plugin.logToFile("ESSENTIALSHOOK\n" + e + "\n" + e.getMessage());
|
||||
|
||||
}
|
||||
data.put("ESS-NICKNAME", new DataPoint("" + user.getDisplayName(), DataType.STRING));
|
||||
if (user.isReachable()) {
|
||||
data.put("ESS-ONLINE SINCE", new DataPoint("" + user.getLastOnlineActivity(), DataType.TIME));
|
||||
} else {
|
||||
data.put("ESS-OFFLINE SINCE", new DataPoint("" + user.getLastOnlineActivity(), DataType.TIME));
|
||||
}
|
||||
data.put("ESS-NICKNAME", new DataPoint("" + user.getDisplayName(), DataType.STRING));
|
||||
if (user.isReachable()) {
|
||||
data.put("ESS-ONLINE SINCE", new DataPoint("" + user.getLastLogin(), DataType.TIME));
|
||||
} else {
|
||||
data.put("ESS-OFFLINE SINCE", new DataPoint("" + user.getLastLogout(), DataType.TIME));
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
@ -71,15 +78,18 @@ public class EssentialsHook implements Hook {
|
||||
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
data.putAll(getData(player));
|
||||
User user = this.ess.getOfflineUser(player);
|
||||
if (user != null) {
|
||||
data.put("ESS-UUID", new DataPoint("" + user.getBase().getUniqueId().toString(), DataType.OTHER));
|
||||
data.put("ESS-HEALTH", new DataPoint("" + user.getBase().getHealth(), DataType.AMOUNT));
|
||||
data.put("ESS-HUNGER", new DataPoint("" + user.getBase().getFoodLevel(), DataType.AMOUNT));
|
||||
data.put("ESS-XP LEVEL", new DataPoint("" + user.getBase().getLevel(), DataType.AMOUNT));
|
||||
data.put("ESS-OPPED", new DataPoint("" + user.getBase().isOp(), DataType.BOOLEAN));
|
||||
// data.put("ESS-GOD MODE", "" + user.isGodModeEnabled());
|
||||
data.put("ESS-FLYING", new DataPoint("" + user.getBase().isFlying(), DataType.BOOLEAN));
|
||||
|
||||
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
|
||||
if (p.hasPlayedBefore()) {
|
||||
User user = this.ess.getOfflineUser(player);
|
||||
if (Optional.of(user).isPresent()) {
|
||||
data.put("ESS-UUID", new DataPoint("" + user.getBase().getUniqueId().toString(), DataType.OTHER));
|
||||
data.put("ESS-HEALTH", new DataPoint("" + user.getBase().getHealth(), DataType.AMOUNT));
|
||||
data.put("ESS-HUNGER", new DataPoint("" + user.getBase().getFoodLevel(), DataType.AMOUNT));
|
||||
data.put("ESS-XP LEVEL", new DataPoint("" + user.getBase().getLevel(), DataType.AMOUNT));
|
||||
data.put("ESS-OPPED", new DataPoint("" + user.getBase().isOp(), DataType.BOOLEAN));
|
||||
data.put("ESS-FLYING", new DataPoint("" + user.getBase().isFlying(), DataType.BOOLEAN));
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -29,17 +29,9 @@ public class FactionsHook implements Hook {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
MPlayer mplayer;
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
||||
OfflinePlayer p;
|
||||
if (uuid != null) {
|
||||
p = getOfflinePlayer(uuid);
|
||||
mplayer = MPlayer.get(uuid);
|
||||
} else {
|
||||
// Fallback method if UUID is not found
|
||||
p = getOfflinePlayer(player);
|
||||
mplayer = MPlayer.get(p.getUniqueId());
|
||||
}
|
||||
// Check if player has played on server
|
||||
OfflinePlayer p = getOfflinePlayer(uuid);
|
||||
if (p.hasPlayedBefore()) {
|
||||
mplayer = MPlayer.get(uuid);
|
||||
if (mplayer.hasFaction()) {
|
||||
data.put("FAC-FACTION", new DataPoint(mplayer.getFactionName(), DataType.STRING));
|
||||
if (mplayer.hasTitle()) {
|
||||
|
@ -2,10 +2,13 @@ package com.djrapitops.plan.command.hooks;
|
||||
|
||||
import com.djrapitops.plan.api.Hook;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.UUIDFetcher;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.DataType;
|
||||
import java.util.HashMap;
|
||||
import me.edge209.OnTime.OnTimeAPI;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class OnTimeHook implements Hook {
|
||||
|
||||
@ -21,17 +24,20 @@ public class OnTimeHook implements Hook {
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getData(String player) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
try {
|
||||
data.put("ONT-LAST LOGIN", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.LASTLOGIN), DataType.DEPRECATED));
|
||||
data.put("ONT-TOTAL PLAY", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.TOTALPLAY), DataType.TIME));
|
||||
data.put("ONT-TOTAL VOTES", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.TOTALVOTE), DataType.AMOUNT));
|
||||
data.put("ONT-TOTAL REFERRED", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.TOTALREFER), DataType.AMOUNT));
|
||||
} catch (NoClassDefFoundError e) {
|
||||
plugin.logToFile("ONTIME HOOK ERROR"
|
||||
+ "\nOntimeHook enabled but failing, could not get data."
|
||||
+ "\n" + e
|
||||
+ "\n" + e.getMessage());
|
||||
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
|
||||
if (p.hasPlayedBefore()) {
|
||||
try {
|
||||
data.put("ONT-LAST LOGIN", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.LASTLOGIN), DataType.DEPRECATED));
|
||||
data.put("ONT-TOTAL PLAY", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.TOTALPLAY), DataType.TIME));
|
||||
data.put("ONT-TOTAL VOTES", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.TOTALVOTE), DataType.AMOUNT));
|
||||
data.put("ONT-TOTAL REFERRED", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.TOTALREFER), DataType.AMOUNT));
|
||||
} catch (NoClassDefFoundError e) {
|
||||
plugin.logToFile("ONTIME HOOK ERROR"
|
||||
+ "\nOntimeHook enabled but failing, could not get data."
|
||||
+ "\n" + e
|
||||
+ "\n" + e.getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -1,38 +1,28 @@
|
||||
package com.djrapitops.plan.command.hooks;
|
||||
|
||||
import com.djrapitops.plan.api.Hook;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.UUIDFetcher;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.DataType;
|
||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import com.google.common.base.Optional;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.external.EZPlaceholderHook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlaceholderAPIHook extends EZPlaceholderHook implements Hook {
|
||||
public class PlaceholderAPIHook extends EZPlaceholderHook {
|
||||
|
||||
private final List<String> placeholders;
|
||||
private final Plan plan;
|
||||
|
||||
public PlaceholderAPIHook(Plan plan, String[] placeholders) {
|
||||
public PlaceholderAPIHook(Plan plan) {
|
||||
super(plan, "plan");
|
||||
this.plan = plan;
|
||||
this.placeholders = new ArrayList<>();
|
||||
this.placeholders.addAll(Arrays.asList(placeholders));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player player, String identifier) {
|
||||
HashMap<String, DataPoint> data = DataFormatUtils.removeExtraDataPoints(DataUtils.getData(true, player.getDisplayName()));
|
||||
String key = identifier.toUpperCase();
|
||||
if (data.get(key) != null) {
|
||||
if (Optional.of(data.get(key)).isPresent()) {
|
||||
return data.get(key).data();
|
||||
} else {
|
||||
plan.logToFile("PlaceholderAPIHOOK\nFailed to get data\n" + player.getDisplayName() + "\n" + key);
|
||||
@ -40,29 +30,6 @@ public class PlaceholderAPIHook extends EZPlaceholderHook implements Hook {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getData(String playerName) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
Player player = Bukkit.getPlayer(UUIDFetcher.getUUIDOf(playerName));
|
||||
for (String placeholder : placeholders) {
|
||||
if (placeholder.length() > 0 && placeholder.contains("%") || placeholder.contains("{")) {
|
||||
String key = ("" + placeholder.subSequence(1, placeholder.length() - 1)).toUpperCase();
|
||||
data.put("PHA-" + key.toUpperCase(), new DataPoint(PlaceholderAPI.setPlaceholders(player, placeholder), DataType.OTHER));
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
|
||||
return getData(player);
|
||||
}
|
||||
|
||||
public void setPlaceholders(String[] placeholders) {
|
||||
this.placeholders.clear();
|
||||
this.placeholders.addAll(Arrays.asList(placeholders));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hook() {
|
||||
return super.hook();
|
||||
|
@ -7,6 +7,9 @@ import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.DataType;
|
||||
import io.minimum.minecraft.superbvote.SuperbVote;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class SuperbVoteHook implements Hook {
|
||||
|
||||
@ -21,7 +24,11 @@ public class SuperbVoteHook implements Hook {
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getData(String player) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
data.put("SVO-VOTES", new DataPoint("" + hookP.getVoteStorage().getVotes(UUIDFetcher.getUUIDOf(player)), DataType.AMOUNT));
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
||||
OfflinePlayer p = getOfflinePlayer(uuid);
|
||||
if (p.hasPlayedBefore()) {
|
||||
data.put("SVO-VOTES", new DataPoint("" + hookP.getVoteStorage().getVotes(uuid), DataType.AMOUNT));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.djrapitops.plan.command.hooks;
|
||||
|
||||
import com.djrapitops.plan.api.Hook;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.UUIDFetcher;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.DataType;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
@ -16,10 +17,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
import static com.palmergames.bukkit.towny.TownyFormatter.getFormattedResidents;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class TownyHook implements Hook {
|
||||
|
||||
private Towny towny;
|
||||
private final Towny towny;
|
||||
private final Plan plugin;
|
||||
|
||||
public TownyHook(Plan p) throws Exception {
|
||||
@ -30,31 +33,33 @@ public class TownyHook implements Hook {
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getData(String player) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
try {
|
||||
Resident resident = TownyUniverse.getDataSource().getResident(player);
|
||||
if (resident != null) {
|
||||
data.put("TOW-ONLINE", new DataPoint("" + BukkitTools.isOnline(player), DataType.BOOLEAN));
|
||||
data.put("TOW-REGISTERED", new DataPoint(registeredFormat.format(resident.getRegistered()), DataType.DEPRECATED));
|
||||
data.put("TOW-LAST LOGIN", new DataPoint(lastOnlineFormat.format(resident.getLastOnline()), DataType.DEPRECATED));
|
||||
data.put("TOW-OWNER OF", new DataPoint(resident.getTownBlocks().size() + " plots", DataType.STRING));
|
||||
try {
|
||||
if (resident.hasTown()) {
|
||||
data.put("TOW-TOWN", new DataPoint(getFormattedName(resident.getTown()), DataType.STRING));
|
||||
}
|
||||
if (resident.hasNation()) {
|
||||
if (!resident.getNationRanks().isEmpty()) {
|
||||
data.put("TOW-NATION", new DataPoint(resident.getTown().getNation().getName(), DataType.STRING));
|
||||
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
|
||||
if (p.hasPlayedBefore()) {
|
||||
try {
|
||||
Resident resident = TownyUniverse.getDataSource().getResident(player);
|
||||
if (resident != null) {
|
||||
data.put("TOW-ONLINE", new DataPoint("" + BukkitTools.isOnline(player), DataType.BOOLEAN));
|
||||
data.put("TOW-REGISTERED", new DataPoint(registeredFormat.format(resident.getRegistered()), DataType.DEPRECATED));
|
||||
data.put("TOW-LAST LOGIN", new DataPoint(lastOnlineFormat.format(resident.getLastOnline()), DataType.DEPRECATED));
|
||||
data.put("TOW-OWNER OF", new DataPoint(resident.getTownBlocks().size() + " plots", DataType.STRING));
|
||||
try {
|
||||
if (resident.hasTown()) {
|
||||
data.put("TOW-TOWN", new DataPoint(getFormattedName(resident.getTown()), DataType.STRING));
|
||||
}
|
||||
if (resident.hasNation()) {
|
||||
if (!resident.getNationRanks().isEmpty()) {
|
||||
data.put("TOW-NATION", new DataPoint(resident.getTown().getNation().getName(), DataType.STRING));
|
||||
}
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
plugin.logToFile("TOWNYHOOK\n" + e + "\n" + e.getMessage());
|
||||
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
plugin.logToFile("TOWNYHOOK\n" + e + "\n" + e.getMessage());
|
||||
|
||||
}
|
||||
|
||||
} catch (TownyException e) {
|
||||
plugin.logToFile("TOWNYHOOK\n" + e + "\nError resident: " + player);
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
plugin.logToFile("TOWNYHOOK\n" + e + "\nError resident: " + player);
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@ -63,16 +68,19 @@ public class TownyHook implements Hook {
|
||||
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
data.putAll(getData(player));
|
||||
try {
|
||||
Resident resident = TownyUniverse.getDataSource().getResident(player);
|
||||
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
|
||||
if (p.hasPlayedBefore()) {
|
||||
try {
|
||||
Resident resident = TownyUniverse.getDataSource().getResident(player);
|
||||
|
||||
data.put("TOW-PLOT PERMS", new DataPoint(resident.getPermissions().getColourString(), DataType.STRING));
|
||||
data.put("TOW-PLOT OPTIONS", new DataPoint("PVP: " + ((resident.getPermissions().pvp) ? "ON" : "OFF") + " Explosions: " + ((resident.getPermissions().explosion) ? "ON" : "OFF") + " Firespread: " + ((resident.getPermissions().fire) ? "ON" : "OFF") + " Mob Spawns: " + ((resident.getPermissions().mobs) ? "ON" : "OFF"), DataType.STRING));
|
||||
List<Resident> friends = resident.getFriends();
|
||||
data.put("TOW-FRIENDS", new DataPoint(getFormattedResidents("Friends", friends).toString(), DataType.STRING));
|
||||
} catch (TownyException e) {
|
||||
plugin.logToFile("TOWNYHOOK-All\n" + e + "\nError resident: " + player);
|
||||
data.put("TOW-PLOT PERMS", new DataPoint(resident.getPermissions().getColourString(), DataType.STRING));
|
||||
data.put("TOW-PLOT OPTIONS", new DataPoint("PVP: " + ((resident.getPermissions().pvp) ? "ON" : "OFF") + " Explosions: " + ((resident.getPermissions().explosion) ? "ON" : "OFF") + " Firespread: " + ((resident.getPermissions().fire) ? "ON" : "OFF") + " Mob Spawns: " + ((resident.getPermissions().mobs) ? "ON" : "OFF"), DataType.STRING));
|
||||
List<Resident> friends = resident.getFriends();
|
||||
data.put("TOW-FRIENDS", new DataPoint(getFormattedResidents("Friends", friends).toString(), DataType.STRING));
|
||||
} catch (TownyException e) {
|
||||
plugin.logToFile("TOWNYHOOK-All\n" + e + "\nError resident: " + player);
|
||||
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -25,20 +25,10 @@ public class VaultHook implements Hook {
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getData(String player) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
try {
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
||||
OfflinePlayer p;
|
||||
if (uuid != null) {
|
||||
p = getOfflinePlayer(uuid);
|
||||
} else {
|
||||
p = getOfflinePlayer(player);
|
||||
}
|
||||
if (p.hasPlayedBefore()) {
|
||||
data.put("ECO-BALANCE", new DataPoint(this.econ.format(this.econ.getBalance(p)), DataType.AMOUNT_WITH_LETTERS));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.logToFile("VAULTHOOK\n" + e + "\nError player: " + player);
|
||||
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
||||
OfflinePlayer p = getOfflinePlayer(uuid);
|
||||
if (p.hasPlayedBefore()) {
|
||||
data.put("ECO-BALANCE", new DataPoint(this.econ.format(this.econ.getBalance(p)), DataType.AMOUNT_WITH_LETTERS));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class AnalysisUtils {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return "" + (time * 1.0 / dataPoints.size());
|
||||
return "" + (time / dataPoints.size());
|
||||
}
|
||||
|
||||
static String BooleanPercent(List<String> dataPoints) {
|
||||
|
@ -14,6 +14,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
public class DataFormatUtils {
|
||||
|
||||
public static HashMap<String, DataPoint> removeExtraDataPoints(HashMap<String, DataPoint> data) throws NumberFormatException {
|
||||
Date now = new Date();
|
||||
List<String> remove = new ArrayList<>();
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
data.keySet().parallelStream().forEach((key) -> {
|
||||
@ -39,7 +40,7 @@ public class DataFormatUtils {
|
||||
data.remove(removedKey);
|
||||
});
|
||||
remove.clear();
|
||||
// Process Towny data (Empty returns Java Epoch date 1970 for REGISTERED)
|
||||
// Process Towny data (Empty returns date with 1970 for REGISTERED)
|
||||
if (data.get("TOW-REGISTERED") != null) {
|
||||
if (data.get("TOW-REGISTERED").data().contains("1970")) {
|
||||
remove.add("TOW-REGISTERED");
|
||||
@ -101,8 +102,8 @@ public class DataFormatUtils {
|
||||
data.get(key).setData(formatted);
|
||||
} else if (data.get(key).type() == DataType.TIME) {
|
||||
String formatted;
|
||||
if (key.equals("ESS-ONLINE SINCE") || key.equals("ESS_OFFLINE SINCE")) {
|
||||
formatted = formatTimeAmountSinceString(data.get(key).data(), new Date());
|
||||
if (key.equals("ESS-ONLINE SINCE") || key.equals("ESS-OFFLINE SINCE")) {
|
||||
formatted = formatTimeAmountSinceString(data.get(key).data(), now);
|
||||
} else {
|
||||
formatted = formatTimeAmount(data.get(key).data());
|
||||
}
|
||||
@ -222,14 +223,14 @@ public class DataFormatUtils {
|
||||
}
|
||||
|
||||
// Formats Time Difference String before -> Date now
|
||||
public static String formatTimeAmountSinceString(String string, Date date) throws NumberFormatException {
|
||||
long ms = (date.toInstant().getEpochSecond() * 1000) - Long.parseLong(string);
|
||||
public static String formatTimeAmountSinceString(String string, Date now) throws NumberFormatException {
|
||||
long ms = Math.abs((now.toInstant().getEpochSecond() * 1000) - Long.parseLong(string));
|
||||
return turnMsLongToString(ms);
|
||||
}
|
||||
|
||||
// Formats Time Difference Date before -> Date now
|
||||
public static String formatTimeAmountSinceDate(Date before, Date now) throws NumberFormatException {
|
||||
long ms = (now.toInstant().getEpochSecond() * 1000) - (before.toInstant().getEpochSecond() * 1000);
|
||||
long ms = Math.abs((now.toInstant().getEpochSecond() * 1000) - (before.toInstant().getEpochSecond() * 1000));
|
||||
return turnMsLongToString(ms);
|
||||
}
|
||||
|
||||
@ -282,7 +283,7 @@ public class DataFormatUtils {
|
||||
// Sorts HashMap into Sorted List of Arrays
|
||||
public static List<String[]> turnDataHashMapToSortedListOfArrays(HashMap<String, DataPoint> data) {
|
||||
List<String[]> dataList = new ArrayList<>();
|
||||
data.keySet().parallelStream().forEach((key) -> {
|
||||
data.keySet().stream().forEach((key) -> {
|
||||
dataList.add(new String[]{key, data.get(key).data()});
|
||||
});
|
||||
Collections.sort(dataList, (String[] strings, String[] otherStrings) -> strings[0].compareTo(otherStrings[0]));
|
||||
|
@ -60,26 +60,6 @@ public class DataUtils {
|
||||
return playerData;
|
||||
}
|
||||
|
||||
public static String[] getPlaceholdersFileData() {
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
File placeholdersFile = new File(plugin.getDataFolder(), "placeholders.yml");
|
||||
try {
|
||||
if (!placeholdersFile.exists()) {
|
||||
placeholdersFile.createNewFile();
|
||||
}
|
||||
Scanner filescanner = new Scanner(placeholdersFile);
|
||||
String placeholdersString = "";
|
||||
if (filescanner.hasNextLine()) {
|
||||
placeholdersString = filescanner.nextLine();
|
||||
}
|
||||
String[] returnArray = placeholdersString.split(" ");
|
||||
return returnArray;
|
||||
} catch (Exception e) {
|
||||
plugin.logToFile("Failed to create placeholders.yml\n" + e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static HashMap<String, DataPoint> analyze(HashMap<UUID, HashMap<String, DataPoint>> playerData) {
|
||||
return Analysis.analyze(playerData);
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: Plan
|
||||
main: com.djrapitops.plan.Plan
|
||||
version: 1.6.0
|
||||
version: 1.6.1
|
||||
|
||||
commands:
|
||||
plan:
|
||||
@ -17,6 +17,7 @@ commands:
|
||||
description: reload plugin config
|
||||
search:
|
||||
usage: /plan <search terms> -p add -p to make not search playername
|
||||
description: search data of multiple players with search terms
|
||||
|
||||
softdepend:
|
||||
- OnTime
|
||||
|
Loading…
Reference in New Issue
Block a user