mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-30 21:17:49 +01:00
Data objects for extension data about a player
These objects make it easier to construct query data from database.
This commit is contained in:
parent
134a7b1e18
commit
fb8d01e5c2
@ -69,7 +69,7 @@ public class DataProviderExtractor {
|
|||||||
return new Icon(pluginInfo.iconFamily(), pluginInfo.iconName(), pluginInfo.color());
|
return new Icon(pluginInfo.iconFamily(), pluginInfo.iconName(), pluginInfo.color());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<PluginTab> getPluginTabs() {
|
public Collection<TabInformation> getPluginTabs() {
|
||||||
Map<String, TabInfo> tabInformation = extensionExtractor.getTabInformation()
|
Map<String, TabInfo> tabInformation = extensionExtractor.getTabInformation()
|
||||||
.stream().collect(Collectors.toMap(TabInfo::tab, Function.identity(), (one, two) -> one));
|
.stream().collect(Collectors.toMap(TabInfo::tab, Function.identity(), (one, two) -> one));
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ public class DataProviderExtractor {
|
|||||||
.distinct()
|
.distinct()
|
||||||
.map(tabName -> {
|
.map(tabName -> {
|
||||||
Optional<TabInfo> tabInfo = Optional.ofNullable(tabInformation.get(tabName));
|
Optional<TabInfo> tabInfo = Optional.ofNullable(tabInformation.get(tabName));
|
||||||
return new PluginTab(
|
return new TabInformation(
|
||||||
tabName,
|
tabName,
|
||||||
tabInfo.map(info -> new Icon(info.iconFamily(), info.iconName(), Color.NONE)).orElse(null),
|
tabInfo.map(info -> new Icon(info.iconFamily(), info.iconName(), Color.NONE)).orElse(null),
|
||||||
tabInfo.map(TabInfo::elementOrder).orElse(null),
|
tabInfo.map(TabInfo::elementOrder).orElse(null),
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.djrapitops.plan.extension.implementation;
|
package com.djrapitops.plan.extension.implementation;
|
||||||
|
|
||||||
import com.djrapitops.plan.extension.icon.Icon;
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
|
import com.djrapitops.plan.extension.implementation.results.player.ExtensionDescriptive;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -26,26 +27,17 @@ import java.util.Optional;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class ProviderInformation {
|
public class ProviderInformation extends ExtensionDescriptive {
|
||||||
|
|
||||||
private final String pluginName;
|
private final String pluginName;
|
||||||
private final String name;
|
|
||||||
private final String text;
|
|
||||||
private final String description; // can be null
|
|
||||||
private final Icon icon;
|
|
||||||
private final int priority;
|
|
||||||
private final String tab; // can be null
|
private final String tab; // can be null
|
||||||
private final String condition; // can be null
|
private final String condition; // can be null
|
||||||
|
|
||||||
public ProviderInformation(
|
public ProviderInformation(
|
||||||
String pluginName, String name, String text, String description, Icon icon, int priority, String tab, String condition
|
String pluginName, String name, String text, String description, Icon icon, int priority, String tab, String condition
|
||||||
) {
|
) {
|
||||||
|
super(name, text, description, icon, priority);
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
this.name = name;
|
|
||||||
this.text = text;
|
|
||||||
this.description = description;
|
|
||||||
this.icon = icon;
|
|
||||||
this.priority = priority;
|
|
||||||
this.tab = tab;
|
this.tab = tab;
|
||||||
this.condition = condition;
|
this.condition = condition;
|
||||||
}
|
}
|
||||||
@ -54,26 +46,6 @@ public class ProviderInformation {
|
|||||||
return StringUtils.truncate(pluginName, 50);
|
return StringUtils.truncate(pluginName, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return StringUtils.truncate(name, 50);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getText() {
|
|
||||||
return StringUtils.truncate(text, 50);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<String> getDescription() {
|
|
||||||
return description == null || description.isEmpty() ? Optional.empty() : Optional.of(StringUtils.truncate(description, 150));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Icon getIcon() {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPriority() {
|
|
||||||
return priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<String> getTab() {
|
public Optional<String> getTab() {
|
||||||
return tab == null || tab.isEmpty() ? Optional.empty() : Optional.of(StringUtils.truncate(tab, 50));
|
return tab == null || tab.isEmpty() ? Optional.empty() : Optional.of(StringUtils.truncate(tab, 50));
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,14 @@ import java.util.Optional;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class PluginTab {
|
public class TabInformation {
|
||||||
|
|
||||||
private final String tabName;
|
private final String tabName;
|
||||||
private final Icon icon; // can be null
|
private final Icon icon; // can be null
|
||||||
private ElementOrder[] elementOrder; // can be null / miss values
|
private ElementOrder[] elementOrder; // can be null / miss values
|
||||||
private int tabPriority;
|
private int tabPriority;
|
||||||
|
|
||||||
public PluginTab(String tabName, Icon icon, ElementOrder[] elementOrder, int tabPriority) {
|
public TabInformation(String tabName, Icon icon, ElementOrder[] elementOrder, int tabPriority) {
|
||||||
this.tabName = tabName;
|
this.tabName = tabName;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.elementOrder = elementOrder;
|
this.elementOrder = elementOrder;
|
@ -20,10 +20,10 @@ import com.djrapitops.plan.db.Database;
|
|||||||
import com.djrapitops.plan.extension.DataExtension;
|
import com.djrapitops.plan.extension.DataExtension;
|
||||||
import com.djrapitops.plan.extension.icon.Icon;
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
import com.djrapitops.plan.extension.implementation.DataProviderExtractor;
|
import com.djrapitops.plan.extension.implementation.DataProviderExtractor;
|
||||||
import com.djrapitops.plan.extension.implementation.PluginTab;
|
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StorePluginTabTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StorePluginTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StorePluginTransaction;
|
||||||
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreTabInformationTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveInvalidResultsTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveInvalidResultsTransaction;
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
import com.djrapitops.plan.system.database.DBSystem;
|
||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
@ -69,9 +69,9 @@ public class ProviderValueGatherer {
|
|||||||
Database database = dbSystem.getDatabase();
|
Database database = dbSystem.getDatabase();
|
||||||
database.executeTransaction(new StoreIconTransaction(pluginIcon));
|
database.executeTransaction(new StoreIconTransaction(pluginIcon));
|
||||||
database.executeTransaction(new StorePluginTransaction(pluginName, time, serverUUID, pluginIcon));
|
database.executeTransaction(new StorePluginTransaction(pluginName, time, serverUUID, pluginIcon));
|
||||||
for (PluginTab tab : extractor.getPluginTabs()) {
|
for (TabInformation tab : extractor.getPluginTabs()) {
|
||||||
database.executeTransaction(new StoreIconTransaction(tab.getTabIcon()));
|
database.executeTransaction(new StoreIconTransaction(tab.getTabIcon()));
|
||||||
database.executeTransaction(new StorePluginTabTransaction(pluginName, serverUUID, tab));
|
database.executeTransaction(new StoreTabInformationTransaction(pluginName, serverUUID, tab));
|
||||||
}
|
}
|
||||||
|
|
||||||
database.executeTransaction(new RemoveInvalidResultsTransaction(pluginName, serverUUID, extractor.getInvalidatedMethods()));
|
database.executeTransaction(new RemoveInvalidResultsTransaction(pluginName, serverUUID, extractor.getInvalidatedMethods()));
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.extension.implementation.results.player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents boolean data returned by a BooleanProvider method.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class ExtensionBooleanData implements ExtensionData {
|
||||||
|
|
||||||
|
private ExtensionDescriptive descriptive;
|
||||||
|
private boolean value;
|
||||||
|
|
||||||
|
public ExtensionBooleanData(ExtensionDescriptive descriptive, boolean value) {
|
||||||
|
this.descriptive = descriptive;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtensionDescriptive getDescriptive() {
|
||||||
|
return descriptive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormattedValue() {
|
||||||
|
return value ? "Yes" : "No";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.djrapitops.plan.extension.implementation.results.player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a data-point given by a Provider method of a DataExtension.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public interface ExtensionData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Descriptive information about the data point.
|
||||||
|
*
|
||||||
|
* @return a {@link ExtensionDescriptive}.
|
||||||
|
*/
|
||||||
|
ExtensionDescriptive getDescriptive();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.extension.implementation.results.player;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes information about an extension value given by a Provider method.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class ExtensionDescriptive implements Comparable<ExtensionDescriptive> {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final String text;
|
||||||
|
private final String description; // can be null
|
||||||
|
private final Icon icon;
|
||||||
|
private final int priority;
|
||||||
|
|
||||||
|
public ExtensionDescriptive(String name, String text, String description, Icon icon, int priority) {
|
||||||
|
this.name = name;
|
||||||
|
this.text = text;
|
||||||
|
this.description = description;
|
||||||
|
this.icon = icon;
|
||||||
|
this.priority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return StringUtils.truncate(name, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return StringUtils.truncate(text, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getDescription() {
|
||||||
|
return description == null || description.isEmpty() ? Optional.empty() : Optional.of(StringUtils.truncate(description, 150));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Icon getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPriority() {
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ExtensionDescriptive other) {
|
||||||
|
Integer.compare(other.priority, this.priority); // Higher is first
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.extension.implementation.results.player;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents double data returned by a DoubleProvider or PercentageProvider method.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class ExtensionDoubleData implements ExtensionData {
|
||||||
|
|
||||||
|
private ExtensionDescriptive descriptive;
|
||||||
|
private double value;
|
||||||
|
|
||||||
|
public ExtensionDoubleData(ExtensionDescriptive descriptive, double value) {
|
||||||
|
this.descriptive = descriptive;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtensionDescriptive getDescriptive() {
|
||||||
|
return descriptive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormattedValue(Formatter<Double> formatter) {
|
||||||
|
return formatter.apply(value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.extension.implementation.results.player;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.FormatType;
|
||||||
|
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents double data returned by a DoubleProvider or PercentageProvider method.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class ExtensionNumberData implements ExtensionData {
|
||||||
|
|
||||||
|
private final ExtensionDescriptive descriptive;
|
||||||
|
private final FormatType formatType;
|
||||||
|
private final long value;
|
||||||
|
|
||||||
|
public ExtensionNumberData(ExtensionDescriptive descriptive, FormatType formatType, long value) {
|
||||||
|
this.descriptive = descriptive;
|
||||||
|
this.formatType = formatType;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtensionDescriptive getDescriptive() {
|
||||||
|
return descriptive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormatType getFormatType() {
|
||||||
|
return formatType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormattedValue(Formatter<Long> formatter) {
|
||||||
|
return formatter.apply(value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.extension.implementation.results.player;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents data of a single extension about a player.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class ExtensionPlayerData {
|
||||||
|
|
||||||
|
private String pluginName;
|
||||||
|
private Icon pluginIcon;
|
||||||
|
|
||||||
|
private List<ExtensionTabData> tabs;
|
||||||
|
|
||||||
|
public ExtensionPlayerData(String pluginName, Icon pluginIcon) {
|
||||||
|
this.pluginName = pluginName;
|
||||||
|
this.pluginIcon = pluginIcon;
|
||||||
|
|
||||||
|
tabs = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ExtensionTabData> getTabs() {
|
||||||
|
return tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Factory {
|
||||||
|
|
||||||
|
private final ExtensionPlayerData data;
|
||||||
|
|
||||||
|
public Factory() {
|
||||||
|
data = new ExtensionPlayerData(pluginName, pluginIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Factory addTab(ExtensionTabData tab) {
|
||||||
|
data.tabs.add(tab);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtensionPlayerData build() {
|
||||||
|
Collections.sort(data.tabs);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.extension.implementation.results.player;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.api.PlanAPI;
|
||||||
|
import com.djrapitops.plan.utilities.html.Html;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents double data returned by a DoubleProvider or PercentageProvider method.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class ExtensionStringData implements ExtensionData {
|
||||||
|
|
||||||
|
private final ExtensionDescriptive descriptive;
|
||||||
|
private final boolean playerName;
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
public ExtensionStringData(ExtensionDescriptive descriptive, boolean playerName, String value) {
|
||||||
|
this.descriptive = descriptive;
|
||||||
|
this.playerName = playerName;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtensionDescriptive getDescriptive() {
|
||||||
|
return descriptive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormattedValue() {
|
||||||
|
return !playerName ? value : Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(value), value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.extension.implementation.results.player;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents data on an extension tab.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class ExtensionTabData implements Comparable<ExtensionTabData> {
|
||||||
|
|
||||||
|
private final TabInformation tabInformation; // Can be null in case where no tab was defined for provider.
|
||||||
|
|
||||||
|
private final Map<String, ExtensionBooleanData> booleanData;
|
||||||
|
private final Map<String, ExtensionDoubleData> doubleData;
|
||||||
|
private final Map<String, ExtensionDoubleData> percentageData;
|
||||||
|
private final Map<String, ExtensionNumberData> numberData;
|
||||||
|
private final Map<String, ExtensionStringData> stringData;
|
||||||
|
|
||||||
|
private List<String> order;
|
||||||
|
|
||||||
|
// Table and Graph data will be added later.
|
||||||
|
|
||||||
|
public ExtensionTabData(TabInformation tabInformation) {
|
||||||
|
this.tabInformation = tabInformation;
|
||||||
|
|
||||||
|
booleanData = new HashMap<>();
|
||||||
|
doubleData = new HashMap<>();
|
||||||
|
percentageData = new HashMap<>();
|
||||||
|
numberData = new HashMap<>();
|
||||||
|
stringData = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getValueOrder() {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ExtensionBooleanData> getBoolean(String providerName) {
|
||||||
|
return Optional.ofNullable(booleanData.get(providerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ExtensionDoubleData> getDouble(String providerName) {
|
||||||
|
return Optional.ofNullable(doubleData.get(providerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ExtensionDoubleData> getPercentage(String providerName) {
|
||||||
|
return Optional.ofNullable(percentageData.get(providerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ExtensionNumberData> getNumber(String providerName) {
|
||||||
|
return Optional.ofNullable(numberData.get(providerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ExtensionStringData> getString(String providerName) {
|
||||||
|
return Optional.ofNullable(stringData.get(providerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createOrderingList() {
|
||||||
|
List<ExtensionDescriptive> descriptives = new ArrayList<>();
|
||||||
|
booleanData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||||
|
doubleData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||||
|
percentageData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||||
|
numberData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||||
|
stringData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||||
|
|
||||||
|
order = descriptives.stream().sorted()
|
||||||
|
.map(ExtensionDescriptive::getName)
|
||||||
|
.distinct()// Method names are usually different, but in case someone had same method name with different parameters.
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ExtensionTabData other) {
|
||||||
|
return Integer.compare(this.tabInformation.getTabPriority(), other.tabInformation.getTabPriority()); // Lower is first
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Factory {
|
||||||
|
|
||||||
|
private final ExtensionTabData data;
|
||||||
|
|
||||||
|
Factory(TabInformation tabInformation) {
|
||||||
|
data = new ExtensionTabData(tabInformation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Factory putBooleanData(ExtensionBooleanData extensionBooleanData) {
|
||||||
|
data.booleanData.put(extensionBooleanData.getDescriptive().getName(), extensionBooleanData);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Factory putDoubleData(ExtensionDoubleData extensionDoubleData) {
|
||||||
|
data.doubleData.put(extensionDoubleData.getDescriptive().getName(), extensionDoubleData);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Factory putPercentageData(ExtensionDoubleData extensionDoubleData) {
|
||||||
|
data.percentageData.put(extensionDoubleData.getDescriptive().getName(), extensionDoubleData);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Factory putNumberData(ExtensionNumberData extensionNumberData) {
|
||||||
|
data.numberData.put(extensionNumberData.getDescriptive().getName(), extensionNumberData);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Factory putStringData(ExtensionStringData extensionStringData) {
|
||||||
|
data.stringData.put(extensionStringData.getDescriptive().getName(), extensionStringData);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtensionTabData build() {
|
||||||
|
data.createOrderingList();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,7 @@ import com.djrapitops.plan.db.sql.tables.ExtensionIconTable;
|
|||||||
import com.djrapitops.plan.db.sql.tables.ExtensionPluginTable;
|
import com.djrapitops.plan.db.sql.tables.ExtensionPluginTable;
|
||||||
import com.djrapitops.plan.db.sql.tables.ExtensionTabTable;
|
import com.djrapitops.plan.db.sql.tables.ExtensionTabTable;
|
||||||
import com.djrapitops.plan.extension.ElementOrder;
|
import com.djrapitops.plan.extension.ElementOrder;
|
||||||
import com.djrapitops.plan.extension.implementation.PluginTab;
|
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -33,20 +33,20 @@ import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
|
|||||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction for storing {@link com.djrapitops.plan.extension.implementation.PluginTab}s.
|
* Transaction for storing {@link TabInformation}s.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class StorePluginTabTransaction extends Transaction {
|
public class StoreTabInformationTransaction extends Transaction {
|
||||||
|
|
||||||
private final String pluginName;
|
private final String pluginName;
|
||||||
private final UUID serverUUID;
|
private final UUID serverUUID;
|
||||||
private final PluginTab pluginTab;
|
private final TabInformation tabInformation;
|
||||||
|
|
||||||
public StorePluginTabTransaction(String pluginName, UUID serverUUID, PluginTab pluginTab) {
|
public StoreTabInformationTransaction(String pluginName, UUID serverUUID, TabInformation tabInformation) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
this.serverUUID = serverUUID;
|
this.serverUUID = serverUUID;
|
||||||
this.pluginTab = pluginTab;
|
this.tabInformation = tabInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,11 +74,11 @@ public class StorePluginTabTransaction extends Transaction {
|
|||||||
return new ExecStatement(sql) {
|
return new ExecStatement(sql) {
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
statement.setInt(1, pluginTab.getTabPriority());
|
statement.setInt(1, tabInformation.getTabPriority());
|
||||||
statement.setString(2, pluginTab.getTabElementOrder().map(ElementOrder::serialize).orElse(null));
|
statement.setString(2, tabInformation.getTabElementOrder().map(ElementOrder::serialize).orElse(null));
|
||||||
ExtensionIconTable.set3IconValuesToStatement(statement, 3, pluginTab.getTabIcon());
|
ExtensionIconTable.set3IconValuesToStatement(statement, 3, tabInformation.getTabIcon());
|
||||||
ExtensionPluginTable.set2PluginValuesToStatement(statement, 6, pluginName, serverUUID);
|
ExtensionPluginTable.set2PluginValuesToStatement(statement, 6, pluginName, serverUUID);
|
||||||
statement.setString(8, pluginTab.getTabName());
|
statement.setString(8, tabInformation.getTabName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -94,10 +94,10 @@ public class StorePluginTabTransaction extends Transaction {
|
|||||||
return new ExecStatement(sql) {
|
return new ExecStatement(sql) {
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
statement.setString(1, pluginTab.getTabName());
|
statement.setString(1, tabInformation.getTabName());
|
||||||
statement.setString(2, pluginTab.getTabElementOrder().map(ElementOrder::serialize).orElse(null));
|
statement.setString(2, tabInformation.getTabElementOrder().map(ElementOrder::serialize).orElse(null));
|
||||||
statement.setInt(3, pluginTab.getTabPriority());
|
statement.setInt(3, tabInformation.getTabPriority());
|
||||||
ExtensionIconTable.set3IconValuesToStatement(statement, 4, pluginTab.getTabIcon());
|
ExtensionIconTable.set3IconValuesToStatement(statement, 4, tabInformation.getTabIcon());
|
||||||
ExtensionPluginTable.set2PluginValuesToStatement(statement, 7, pluginName, serverUUID);
|
ExtensionPluginTable.set2PluginValuesToStatement(statement, 7, pluginName, serverUUID);
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user