DiscordSRV plugin data by Vankka (#743)

This commit is contained in:
Vankka 2018-10-05 22:30:57 +03:00 committed by Rsl1122
parent a33ca5b004
commit 27c2492599
5 changed files with 164 additions and 1 deletions

View File

@ -21,6 +21,7 @@ softdepend:
- RedProtect - RedProtect
- AdvancedBan - AdvancedBan
- LuckPerms - LuckPerms
- DiscordSRV
commands: commands:
plan: plan:
@ -89,7 +90,7 @@ permissions:
default: op default: op
plan.webmanage: plan.webmanage:
description: Manage the webusers, delete, list, check description: Manage the webusers, delete, list, check
default: op; default: op
plan.basic: plan.basic:
children: children:

View File

@ -85,6 +85,10 @@
<id>nucleus-repo</id> <id>nucleus-repo</id>
<url>http://repo.drnaylor.co.uk/artifactory/list/minecraft</url> <url>http://repo.drnaylor.co.uk/artifactory/list/minecraft</url>
</repository> </repository>
<repository>
<id>discordsrv-repo</id>
<url>https://ci.scarsz.me/plugin/repository/everything/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -179,6 +183,12 @@
<version>4.3</version> <version>4.3</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>github.scarsz.discordsrv</groupId>
<artifactId>DiscordSRV</artifactId>
<version>1.16.4</version>
<scope>provided</scope>
</dependency>
<!-- Plugins requiring local install --> <!-- Plugins requiring local install -->

View File

@ -10,6 +10,7 @@ import com.djrapitops.pluginbridge.plan.advancedban.AdvancedBanHook;
import com.djrapitops.pluginbridge.plan.askyblock.ASkyBlockHook; import com.djrapitops.pluginbridge.plan.askyblock.ASkyBlockHook;
import com.djrapitops.pluginbridge.plan.banmanager.BanManagerHook; import com.djrapitops.pluginbridge.plan.banmanager.BanManagerHook;
import com.djrapitops.pluginbridge.plan.buycraft.BuyCraftHook; import com.djrapitops.pluginbridge.plan.buycraft.BuyCraftHook;
import com.djrapitops.pluginbridge.plan.discordsrv.DiscordSRVHook;
import com.djrapitops.pluginbridge.plan.essentials.EssentialsHook; import com.djrapitops.pluginbridge.plan.essentials.EssentialsHook;
import com.djrapitops.pluginbridge.plan.factions.FactionsHook; import com.djrapitops.pluginbridge.plan.factions.FactionsHook;
import com.djrapitops.pluginbridge.plan.griefprevention.GriefPreventionHook; import com.djrapitops.pluginbridge.plan.griefprevention.GriefPreventionHook;
@ -100,6 +101,7 @@ public class Bridge {
new ASkyBlockHook(h), new ASkyBlockHook(h),
new BanManagerHook(h), new BanManagerHook(h),
new BuyCraftHook(h), new BuyCraftHook(h),
new DiscordSRVHook(h),
new EssentialsHook(h), new EssentialsHook(h),
new FactionsHook(h), new FactionsHook(h),
new GriefPreventionHook(h), new GriefPreventionHook(h),

View File

@ -0,0 +1,124 @@
/*
* 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.discordsrv;
import com.djrapitops.plan.data.element.AnalysisContainer;
import com.djrapitops.plan.data.element.InspectContainer;
import com.djrapitops.plan.data.plugin.ContainerSize;
import com.djrapitops.plan.data.plugin.PluginData;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.html.icon.Color;
import com.djrapitops.plan.utilities.html.icon.Family;
import com.djrapitops.plan.utilities.html.icon.Icon;
import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.dependencies.jda.core.entities.Member;
import github.scarsz.discordsrv.dependencies.jda.core.entities.Role;
import github.scarsz.discordsrv.dependencies.jda.core.entities.User;
import github.scarsz.discordsrv.util.DiscordUtil;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.text.TextStringBuilder;
/**
* PluginData for DiscordSRV plugin.
*
* @author Vankka
*/
public class DiscordSRVData extends PluginData {
public DiscordSRVData() {
super(ContainerSize.THIRD, "DiscordSRV");
setPluginIcon(Icon.called("discord").of(Family.BRAND).build());
}
@Override
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
if (!DiscordSRV.isReady) {
return inspectContainer;
}
String userId = DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(uuid);
User user = userId != null ? DiscordUtil.getUserById(userId) : null;
if (user == null) {
return inspectContainer;
}
inspectContainer.addValue(
getWithIcon("Username", Icon.called("user").of(Family.SOLID).of(Color.CYAN)),
"@" + user.getName() + "#" + user.getDiscriminator()
);
inspectContainer.addValue(
getWithIcon("Account creation date", Icon.called("plus").of(Family.SOLID).of(Color.BLUE)),
FormatUtils.formatTimeStampYear(user.getCreationTime().toEpochSecond() * 1000L)
);
Member member = DiscordSRV.getPlugin().getMainGuild().getMember(user);
if (member != null) {
addMemberData(member, inspectContainer);
}
return inspectContainer;
}
private void addMemberData(Member member, InspectContainer inspectContainer) {
String nickname = member.getNickname();
inspectContainer.addValue(
getWithIcon("Nickname", Icon.called("user-ninja").of(Family.SOLID).of(Color.ORANGE)),
nickname != null ? nickname : "None"
);
inspectContainer.addValue(
getWithIcon("Join Date", Icon.called("plus").of(Family.SOLID).of(Color.GREEN)),
FormatUtils.formatTimeStampYear(member.getJoinDate().toEpochSecond() * 1000L)
);
List<String> roles = member.getRoles().stream().map(Role::getName).collect(Collectors.toList()); // Ordered list of role names
if (!roles.isEmpty()) {
inspectContainer.addValue(
getWithIcon("Roles", Icon.called("user-circle").of(Family.SOLID).of(Color.RED)),
new TextStringBuilder().appendWithSeparators(roles, ", ").build()
);
}
}
@Override
public AnalysisContainer getServerData(Collection<UUID> uuids, AnalysisContainer analysisContainer) {
if (!DiscordSRV.isReady) {
return analysisContainer;
}
int accountsLinked = DiscordSRV.getPlugin().getAccountLinkManager().getLinkedAccounts().size();
int guildUsers = DiscordSRV.getPlugin().getMainGuild().getMembers().size();
analysisContainer.addValue(
getWithIcon("Accounts linked", Icon.called("link").of(Family.SOLID).of(Color.CYAN)),
accountsLinked
);
analysisContainer.addValue(
getWithIcon("Users in main guild", Icon.called("users").of(Family.SOLID).of(Color.GREEN)),
guildUsers
);
analysisContainer.addValue(
getWithIcon("Accounts linked / Total players", Icon.called("percentage").of(Family.SOLID).of(Color.TEAL)),
calculatePercentage(accountsLinked, uuids.size()) + "%"
);
analysisContainer.addValue(
getWithIcon("Accounts linked / Users in main guild", Icon.called("percentage").of(Family.SOLID).of(Color.LIGHT_GREEN)),
calculatePercentage(accountsLinked, guildUsers) + "%"
);
return analysisContainer;
}
private double calculatePercentage(int input1, int input2) {
if (input1 == 0 || input2 == 0)
return 0D;
return Math.round((double) input1 / input2 * 10000D) / 100D; // 2 decimals
}
}

View File

@ -0,0 +1,26 @@
/*
* 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.discordsrv;
import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.pluginbridge.plan.Hook;
/**
* Hook for DiscordSRV plugin.
*
* @author Vankka
*/
public class DiscordSRVHook extends Hook {
public DiscordSRVHook(HookHandler hookHandler) {
super("github.scarsz.discordsrv.DiscordSRV", hookHandler);
}
@Override
public void hook() throws NoClassDefFoundError {
if (enabled) {
addPluginDataSource(new DiscordSRVData());
}
}
}