Vault Data

This commit is contained in:
Rsl1122 2017-11-26 17:19:47 +02:00
parent 97bdfe1ec8
commit 87377b2586
8 changed files with 156 additions and 251 deletions

View File

@ -18,6 +18,7 @@ import main.java.com.djrapitops.plan.utilities.comparators.TPSComparator;
import main.java.com.djrapitops.plan.utilities.html.tables.PlayersTableCreator;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -44,6 +45,8 @@ public class ServerProfile {
private long allTimePeak;
private int allTimePeakPlayers;
// Calculated once
private Map<UUID, PlayerProfile> playerMap;
public ServerProfile(UUID serverUUID) {
this.serverUUID = serverUUID;
@ -374,4 +377,12 @@ public class ServerProfile {
return count / tpsData.size();
}
public PlayerProfile getPlayer(UUID uuid) {
if (playerMap == null) {
playerMap = players.stream().collect(Collectors.toMap(PlayerProfile::getUuid, Function.identity()));
}
return playerMap.get(uuid);
}
}

View File

@ -1,62 +0,0 @@
package com.djrapitops.pluginbridge.plan.vault;
import com.djrapitops.pluginbridge.plan.FakeOfflinePlayer;
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;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.OfflinePlayer;
import java.io.Serializable;
import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
* PluginData class for Vault-plugin.
* <p>
* Registered to the plugin by VaultHook
* <p>
* Gives Total Balance Double as value.
*
* @author Rsl1122
* @see VaultHook
* @since 3.1.0
*/
public class EconomyBalance extends PluginData {
private final Economy econ;
/**
* Class Constructor, sets the parameters of the PluginData object.
*
* @param econ Economy given by Vault.
*/
public EconomyBalance(Economy econ) {
super("Vault", "balance", AnalysisType.DOUBLE_TOTAL, AnalysisType.DOUBLE_AVG);
this.econ = econ;
super.setAnalysisOnly(false);
super.setIcon("money");
super.setPrefix("Balance: ");
super.setSuffix(" " + FormatUtils.removeNumbers(econ.format(0)));
}
@Override
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
OfflinePlayer p = new FakeOfflinePlayer(uuid, getNameOf(uuid));
if (this.econ.hasAccount(p)) {
return parseContainer(modifierPrefix, Double.toString(this.econ.getBalance(p)));
}
return parseContainer(modifierPrefix, "0");
}
@Override
public Serializable getValue(UUID uuid) {
OfflinePlayer p = getOfflinePlayer(uuid);
if (this.econ.hasAccount(p)) {
return this.econ.getBalance(p);
}
return -1;
}
}

View File

@ -1,60 +0,0 @@
/*
* 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 com.djrapitops.pluginbridge.plan.vault;
import com.djrapitops.pluginbridge.plan.FakeOfflinePlayer;
import main.java.com.djrapitops.plan.Plan;
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;
import main.java.com.djrapitops.plan.utilities.html.Html;
import net.milkbowl.vault.economy.Economy;
import java.io.Serializable;
import java.util.UUID;
/**
* PluginData class for Vault-plugin.
*
* @author Rsl1122
* @since 3.5.0
*/
public class EconomyBalanceTable extends PluginData {
private final Economy econ;
public EconomyBalanceTable(Economy econ) {
super("Vault", "eco_balance_table", AnalysisType.HTML);
this.econ = econ;
String user = Html.FONT_AWESOME_ICON.parse("user") + " Player";
String balance = Html.FONT_AWESOME_ICON.parse("money") + " Balance";
super.setPrefix(Html.TABLE_START_2.parse(user, balance));
super.setSuffix(Html.TABLE_END.parse());
}
@Override
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
String tableLines = getTableLines();
return parseContainer("", tableLines);
}
@Override
public Serializable getValue(UUID uuid) {
return -1;
}
private String getTableLines() {
StringBuilder html = new StringBuilder();
getUUIDsBeingAnalyzed().forEach(uuid -> {
String name = getNameOf(uuid);
String link = Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(name), name);
String bal = FormatUtils.cutDecimals(econ.getBalance(new FakeOfflinePlayer(uuid, name)));
html.append(Html.TABLELINE_2.parse(link, bal));
});
return html.toString();
}
}

View File

@ -1,47 +0,0 @@
/*
* 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 com.djrapitops.pluginbridge.plan.vault;
import java.io.Serializable;
import java.util.UUID;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import net.milkbowl.vault.permission.Permission;
import org.apache.commons.lang3.StringUtils;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
/**
* PluginData class for Vault-plugin.
*
* @author Rsl1122
* @since 3.5.0
*/
public class PermGroup extends PluginData {
private final Permission permSys;
public PermGroup(Permission permSystem) {
super("Vault", "permission_group");
permSys = permSystem;
super.setIcon("balance-scale");
super.setPrefix("Permission Group: ");
}
@Override
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
OfflinePlayer p = getOfflinePlayer(uuid);
if (!p.hasPlayedBefore()) {
return parseContainer("", "Hasn't played.");
}
String group = permSys.getPrimaryGroup(null, p);
return parseContainer(modifierPrefix, StringUtils.capitalize(group));
}
@Override
public Serializable getValue(UUID uuid) {
return -1;
}
}

View File

@ -1,78 +0,0 @@
/*
* 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 com.djrapitops.pluginbridge.plan.vault;
import com.djrapitops.plugin.utilities.Format;
import com.djrapitops.plugin.utilities.Verify;
import com.djrapitops.pluginbridge.plan.FakeOfflinePlayer;
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.html.Html;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.OfflinePlayer;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* PluginData class for Vault-plugin.
*
* @author Rsl1122
* @since 3.5.0
*/
public class PermGroupTable extends PluginData {
private final Permission permSys;
PermGroupTable(Permission permSystem) {
super("Vault", "permission_group_table", AnalysisType.HTML);
permSys = permSystem;
String group = Html.FONT_AWESOME_ICON.parse("balance-scale") + " Perm. Group";
String members = Html.FONT_AWESOME_ICON.parse("users") + " Members";
super.setPrefix(Html.TABLE_START_2.parse(group, members));
super.setSuffix(Html.TABLE_END.parse());
}
@Override
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
String tableLines = getTableLines();
return parseContainer("", tableLines);
}
@Override
public Serializable getValue(UUID uuid) {
return -1;
}
private String getTableLines() {
Map<String, Integer> groups = new HashMap<>();
List<FakeOfflinePlayer> userData = getUUIDsBeingAnalyzed().stream()
.map(uuid -> new FakeOfflinePlayer(uuid, getNameOf(uuid))).collect(Collectors.toList());
for (OfflinePlayer p : userData) {
String group = permSys.getPrimaryGroup(null, p);
if (Verify.isEmpty(group)) {
continue;
}
if (!groups.containsKey(group)) {
groups.put(group, 0);
}
groups.put(group, groups.get(group) + 1);
}
StringBuilder html = new StringBuilder();
for (Map.Entry<String, Integer> entry : groups.entrySet()) {
String group = entry.getKey();
Integer members = entry.getValue();
String groupName = Format.create(group).capitalize().toString();
html.append(Html.TABLELINE_2.parse(groupName, members));
}
return html.toString();
}
}

View File

@ -0,0 +1,73 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.pluginbridge.plan.vault;
import com.djrapitops.plugin.utilities.Verify;
import com.djrapitops.pluginbridge.plan.FakeOfflinePlayer;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.PlayerProfile;
import main.java.com.djrapitops.plan.data.ServerProfile;
import main.java.com.djrapitops.plan.data.additional.AnalysisContainer;
import main.java.com.djrapitops.plan.data.additional.ContainerSize;
import main.java.com.djrapitops.plan.data.additional.InspectContainer;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.utilities.FormatUtils;
import main.java.com.djrapitops.plan.utilities.analysis.Analysis;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.OfflinePlayer;
import java.util.*;
import java.util.stream.Collectors;
/**
* PluginData for Vault Economy.
*
* @author Rsl1122
*/
public class VaultEcoData extends PluginData {
private final Economy econ;
public VaultEcoData(Economy econ) {
super(ContainerSize.THIRD, "Economy (" + econ.getName() + ")");
super.setIconColor("green");
super.setPluginIcon("money");
this.econ = econ;
}
@Override
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) throws Exception {
String name = Plan.getInstance().getDataCache().getName(uuid);
if (name == null) {
return inspectContainer;
}
OfflinePlayer p = new FakeOfflinePlayer(uuid, name);
inspectContainer.addValue(getWithIcon("Balance", "money", "green"), econ.format(econ.getBalance(p)));
return inspectContainer;
}
@Override
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) throws Exception {
ServerProfile serverProfile = Analysis.getServerProfile();
List<PlayerProfile> profiles = collection.stream()
.map(serverProfile::getPlayer)
.filter(Verify::notNull)
.collect(Collectors.toList());
Map<UUID, String> balances = new HashMap<>();
double totalBalance = 0.0;
for (PlayerProfile profile : profiles) {
double bal = econ.getBalance(profile);
totalBalance += bal;
balances.put(profile.getUuid(), econ.format(bal));
}
analysisContainer.addValue(getWithIcon("Server Balance", "money", "green"), FormatUtils.cutDecimals(totalBalance));
analysisContainer.addPlayerTableValues(getWithIcon("Balance", "money"), balances);
return analysisContainer;
}
}

View File

@ -36,15 +36,13 @@ public class VaultHook extends Hook {
try {
Permission permSys = getServer().getServicesManager().getRegistration(Permission.class).getProvider();
addPluginDataSource(new PermGroup(permSys));
addPluginDataSource(new PermGroupTable(permSys));
addPluginDataSource(new VaultPermData(permSys));
} catch (NoSuchFieldError | NoSuchMethodError | Exception e) {
}
try {
Economy econ = getServer().getServicesManager().getRegistration(Economy.class).getProvider();
addPluginDataSource(new EconomyBalance(econ));
addPluginDataSource(new EconomyBalanceTable(econ));
addPluginDataSource(new VaultEcoData(econ));
} catch (NoSuchFieldError | NoSuchMethodError | Exception e) {
}
}

View File

@ -0,0 +1,70 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.pluginbridge.plan.vault;
import com.djrapitops.plugin.utilities.Verify;
import com.djrapitops.pluginbridge.plan.FakeOfflinePlayer;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.PlayerProfile;
import main.java.com.djrapitops.plan.data.ServerProfile;
import main.java.com.djrapitops.plan.data.additional.AnalysisContainer;
import main.java.com.djrapitops.plan.data.additional.ContainerSize;
import main.java.com.djrapitops.plan.data.additional.InspectContainer;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.utilities.analysis.Analysis;
import net.milkbowl.vault.permission.Permission;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.OfflinePlayer;
import java.util.*;
import java.util.stream.Collectors;
/**
* PluginData for Vault Economy.
*
* @author Rsl1122
*/
public class VaultPermData extends PluginData {
private final Permission permSys;
public VaultPermData(Permission permSys) {
super(ContainerSize.THIRD, "Permissions (" + permSys.getName() + ")");
super.setIconColor("cyan");
super.setPluginIcon("asl-interpreting");
this.permSys = permSys;
}
@Override
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) throws Exception {
String name = Plan.getInstance().getDataCache().getName(uuid);
if (name == null) {
return inspectContainer;
}
OfflinePlayer p = new FakeOfflinePlayer(uuid, name);
inspectContainer.addValue(getWithIcon("Permission Group", "bookmark-o", "cyan"), permSys.getPrimaryGroup(null, p));
return inspectContainer;
}
@Override
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) throws Exception {
ServerProfile serverProfile = Analysis.getServerProfile();
List<PlayerProfile> profiles = collection.stream()
.map(serverProfile::getPlayer)
.filter(Verify::notNull)
.collect(Collectors.toList());
Map<UUID, String> groups = new HashMap<>();
for (PlayerProfile profile : profiles) {
String group = StringUtils.capitalize(permSys.getPrimaryGroup(null, profile));
groups.put(profile.getUuid(), group);
}
analysisContainer.addPlayerTableValues(getWithIcon("Balance", "money"), groups);
return analysisContainer;
}
}