mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-08 17:37:34 +01:00
Removed PlanPluginBridge
This commit is contained in:
parent
45a115495f
commit
a544b75838
@ -1 +0,0 @@
|
|||||||
mvn install:install-file -Dfile="AAC-3.5.0-b1.jar" -DgroupId=me.konsolas -DartifactId=AAC -Dversion=3.5.0 -Dpackaging=jar & mvn install:install-file -Dfile="AdvancedBan-2.1.5.jar" -DgroupId=me.leoko -DartifactId=advancedban -Dversion=2.1.5 -Dpackaging=jar & mvn install:install-file -Dfile="ASkyBlock-3.0.9.4.jar" -DgroupId=com.wasteofplastic.askyblock -DartifactId=ASkyBlock -Dversion=3.0.9.4 -Dpackaging=jar & mvn install:install-file -Dfile="BanManager-5.15.0.jar" -DgroupId=me.confuser -DartifactId=banmanager -Dversion=5.15.0 -Dpackaging=jar & mvn install:install-file -Dfile="EssentialsX-2.15.0.1.jar" -DgroupId=net.ess3 -DartifactId=EssentialsX -Dversion=2.15.0.1 -Dpackaging=jar & mvn install:install-file -Dfile="Factions-2.14.0.jar" -DgroupId=com.massivecraft -DartifactId=factions -Dversion=2.14.0 -Dpackaging=jar & mvn install:install-file -Dfile="MassiveCore-2.14.0.jar" -DgroupId=com.massivecraft -DartifactId=mcore -Dversion=2.14.0 -Dpackaging=jar & mvn install:install-file -Dfile="GriefPreventionPlus-13.3.jar" -DgroupId=net.kaikk.mc -DartifactId=GriefPreventionPlus -Dversion=13.3 -Dpackaging=jar & mvn install:install-file -Dfile="Jobs4.7.4.jar" -DgroupId=com.gamingmesh -DartifactId=jobs -Dversion=4.7.4 -Dpackaging=jar & mvn install:install-file -Dfile="Kingdoms-13.3.40.jar" -DgroupId=org.kingdoms -DartifactId=kingdoms_demo -Dversion=13.3.40 -Dpackaging=jar & mvn install:install-file -Dfile="LiteBansAPI-0.3.jar" -DgroupId=litebans -DartifactId=api -Dversion=0.3 -Dpackaging=jar & mvn install:install-file -Dfile="mcMMO-1.6.0-SNAPSHOT.jar" -DgroupId=com.gmail.nossr50 -DartifactId=mcMMO -Dversion=1.6.0 -Dpackaging=jar & mvn install:install-file -Dfile="ProtocolSupport-4.28.jar" -DgroupId=com.github.ProtocolSupport -DartifactId=ProtocolSupport -Dversion=4.28 -Dpackaging=jar & mvn install:install-file -Dfile="React-6.573.jar" -DgroupId=com.volmit -DartifactId=react -Dversion=6.573 -Dpackaging=jar & mvn install:install-file -Dfile="SuperbVote-0.5.3.jar" -DgroupId=io.minimum -DartifactId=minecraft.superbvote -Dversion=0.5.3 -Dpackaging=jar & mvn install:install-file -Dfile="Towny-0.92.0.0.jar" -DgroupId=com.palmergames -DartifactId=towny -Dversion=0.92.0.0 -Dpackaging=jar & mvn install:install-file -Dfile="Vault-1.6.7.jar" -DgroupId=net.milkbowl.vault -DartifactId=VaultAPI -Dversion=1.6 -Dpackaging=jar
|
|
@ -1,210 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>com.djrapitops</groupId>
|
|
||||||
<artifactId>PlanPluginBridge</artifactId>
|
|
||||||
<version>4.9.0-R0.3</version>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<name>${project.groupId}:${project.artifactId}</name>
|
|
||||||
<description>Artifact for reducing requirements for manually installing artifacts for another project, Plan
|
|
||||||
</description>
|
|
||||||
<url>https://github.com/Rsl1122/Plan-PlayerAnalytics/tree/master/PlanPluginBridge</url>
|
|
||||||
|
|
||||||
<licenses>
|
|
||||||
<license>
|
|
||||||
<name>GNU Lesser General Public License v3 (LGPLv3)</name>
|
|
||||||
<url>https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/LICENSE</url>
|
|
||||||
</license>
|
|
||||||
</licenses>
|
|
||||||
|
|
||||||
<developers>
|
|
||||||
<developer>
|
|
||||||
<name>Risto Lahtela (Rsl1122)</name>
|
|
||||||
<email>djrapitops@hotmail.com</email>
|
|
||||||
<organization>None</organization>
|
|
||||||
<organizationUrl>https://github.com/Rsl1122</organizationUrl>
|
|
||||||
</developer>
|
|
||||||
</developers>
|
|
||||||
|
|
||||||
<scm>
|
|
||||||
<connection>scm:git:git://github.com/Rsl1122/Plan-PlayerAnalytics.git</connection>
|
|
||||||
<developerConnection>scm:git:ssh://github.com:Rsl1122/Plan-PlayerAnalytics.git</developerConnection>
|
|
||||||
<url>https://github.com/Rsl1122/Plan-PlayerAnalytics</url>
|
|
||||||
</scm>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>bungeecord-repo</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>spigot-repo</id>
|
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>paper-repo</id>
|
|
||||||
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>sponge-repo</id>
|
|
||||||
<url>https://repo.spongepowered.org/maven</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>jitpack.io (GriefPrevention)</id>
|
|
||||||
<url>https://jitpack.io</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>placeholderapi</id>
|
|
||||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.djrapitops</groupId>
|
|
||||||
<artifactId>Plan-plugin</artifactId>
|
|
||||||
<version>4.8.7</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-text</artifactId>
|
|
||||||
<version>1.8</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Server APIs -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.destroystokyo.paper</groupId>
|
|
||||||
<artifactId>paper-api</artifactId>
|
|
||||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot-api</artifactId>
|
|
||||||
<version>1.12-R0.1-SNAPSHOT</version>
|
|
||||||
<type>jar</type>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.md-5</groupId>
|
|
||||||
<artifactId>bungeecord-api</artifactId>
|
|
||||||
<version>1.12-SNAPSHOT</version>
|
|
||||||
<type>jar</type>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spongepowered</groupId>
|
|
||||||
<artifactId>spongeapi</artifactId>
|
|
||||||
<version>7.1.0</version>
|
|
||||||
<type>jar</type>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.dagger</groupId>
|
|
||||||
<artifactId>dagger</artifactId>
|
|
||||||
<version>2.24</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Plugins from repositories -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.clip</groupId>
|
|
||||||
<artifactId>placeholderapi</artifactId>
|
|
||||||
<version>2.10.3</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency> <!-- Maven Central -->
|
|
||||||
<groupId>me.lucko.luckperms</groupId>
|
|
||||||
<artifactId>luckperms-api</artifactId>
|
|
||||||
<version>4.4</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Plugins requiring local install -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.massivecraft</groupId>
|
|
||||||
<artifactId>factions</artifactId>
|
|
||||||
<version>2.14.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.massivecraft</groupId>
|
|
||||||
<artifactId>mcore</artifactId>
|
|
||||||
<version>2.14.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.gamingmesh</groupId>
|
|
||||||
<artifactId>jobs</artifactId>
|
|
||||||
<version>4.13.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>litebans</groupId>
|
|
||||||
<artifactId>api</artifactId>
|
|
||||||
<version>0.3.1</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.volmit</groupId>
|
|
||||||
<artifactId>react</artifactId>
|
|
||||||
<version>6.612</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.palmergames</groupId>
|
|
||||||
<artifactId>towny</artifactId>
|
|
||||||
<version>0.92.0.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<finalName>${project.artifactId}</finalName>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
<annotationProcessorPaths>
|
|
||||||
<path>
|
|
||||||
<groupId>com.google.dagger</groupId>
|
|
||||||
<artifactId>dagger-compiler</artifactId>
|
|
||||||
<version>2.16</version>
|
|
||||||
</path>
|
|
||||||
</annotationProcessorPaths>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
|
||||||
<version>2.5.2</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.jacoco</groupId>
|
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
|
||||||
<version>0.8.4</version>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<distributionManagement>
|
|
||||||
<repository>
|
|
||||||
<id>bintray-rsl1122-Plan-repository</id>
|
|
||||||
<name>rsl1122-Plan-repository</name>
|
|
||||||
<url>https://api.bintray.com/maven/rsl1122/Plan-repository/PlanPluginBridge/;publish=1</url>
|
|
||||||
</repository>
|
|
||||||
</distributionManagement>
|
|
||||||
</project>
|
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plan.system.settings.paths.PluginSettings;
|
|
||||||
import com.djrapitops.plugin.logging.L;
|
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages connection to other plugins.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public abstract class AbstractBridge implements Bridge {
|
|
||||||
|
|
||||||
private final PlanConfig config;
|
|
||||||
private final ErrorHandler errorHandler;
|
|
||||||
|
|
||||||
AbstractBridge(
|
|
||||||
PlanConfig config,
|
|
||||||
ErrorHandler errorHandler
|
|
||||||
) {
|
|
||||||
this.config = config;
|
|
||||||
this.errorHandler = errorHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hook(HookHandler handler) {
|
|
||||||
Hook[] hooks = getHooks();
|
|
||||||
hookInto(handler, hooks);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void hookInto(HookHandler handler, Hook[] hooks) {
|
|
||||||
boolean devMode = config.isTrue(PluginSettings.DEV_MODE);
|
|
||||||
for (Hook hook : hooks) {
|
|
||||||
try {
|
|
||||||
hook.hook(handler);
|
|
||||||
} catch (Exception | NoClassDefFoundError e) {
|
|
||||||
if (devMode) {
|
|
||||||
errorHandler.log(L.WARN, this.getClass(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract Hook[] getHooks();
|
|
||||||
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.djrapitops.pluginbridge.plan;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for Hooking into other plugins.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public interface Bridge {
|
|
||||||
void hook(HookHandler handler);
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
|
||||||
import com.djrapitops.pluginbridge.plan.buycraft.BuyCraftHook;
|
|
||||||
import com.djrapitops.pluginbridge.plan.factions.FactionsHook;
|
|
||||||
import com.djrapitops.pluginbridge.plan.jobs.JobsHook;
|
|
||||||
import com.djrapitops.pluginbridge.plan.litebans.LiteBansBukkitHook;
|
|
||||||
import com.djrapitops.pluginbridge.plan.luckperms.LuckPermsHook;
|
|
||||||
import com.djrapitops.pluginbridge.plan.towny.TownyHook;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plugin bridge for Bukkit plugins.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class BukkitBridge extends AbstractBridge {
|
|
||||||
|
|
||||||
private final BuyCraftHook buyCraftHook;
|
|
||||||
private final FactionsHook factionsHook;
|
|
||||||
private final JobsHook jobsHook;
|
|
||||||
private final LiteBansBukkitHook liteBansHook;
|
|
||||||
private final LuckPermsHook luckPermsHook;
|
|
||||||
private final TownyHook townyHook;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public BukkitBridge(
|
|
||||||
PlanConfig config,
|
|
||||||
ErrorHandler errorHandler,
|
|
||||||
BuyCraftHook buyCraftHook,
|
|
||||||
FactionsHook factionsHook,
|
|
||||||
JobsHook jobsHook,
|
|
||||||
LiteBansBukkitHook liteBansHook,
|
|
||||||
LuckPermsHook luckPermsHook,
|
|
||||||
TownyHook townyHook
|
|
||||||
) {
|
|
||||||
super(config, errorHandler);
|
|
||||||
this.buyCraftHook = buyCraftHook;
|
|
||||||
this.factionsHook = factionsHook;
|
|
||||||
this.jobsHook = jobsHook;
|
|
||||||
this.liteBansHook = liteBansHook;
|
|
||||||
this.luckPermsHook = luckPermsHook;
|
|
||||||
this.townyHook = townyHook;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Hook[] getHooks() {
|
|
||||||
return new Hook[]{
|
|
||||||
buyCraftHook,
|
|
||||||
factionsHook,
|
|
||||||
jobsHook,
|
|
||||||
liteBansHook,
|
|
||||||
luckPermsHook,
|
|
||||||
townyHook,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
|
||||||
import com.djrapitops.pluginbridge.plan.buycraft.BuyCraftHook;
|
|
||||||
import com.djrapitops.pluginbridge.plan.litebans.LiteBansBungeeHook;
|
|
||||||
import com.djrapitops.pluginbridge.plan.luckperms.LuckPermsHook;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plugin bridge for BungeeCord plugins.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class BungeeBridge extends AbstractBridge {
|
|
||||||
|
|
||||||
private final BuyCraftHook buyCraftHook;
|
|
||||||
private final LiteBansBungeeHook liteBansHook;
|
|
||||||
private final LuckPermsHook luckPermsHook;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public BungeeBridge(
|
|
||||||
PlanConfig config,
|
|
||||||
ErrorHandler errorHandler,
|
|
||||||
BuyCraftHook buyCraftHook,
|
|
||||||
LiteBansBungeeHook liteBansHook,
|
|
||||||
LuckPermsHook luckPermsHook
|
|
||||||
) {
|
|
||||||
super(config, errorHandler);
|
|
||||||
this.buyCraftHook = buyCraftHook;
|
|
||||||
this.liteBansHook = liteBansHook;
|
|
||||||
this.luckPermsHook = luckPermsHook;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Hook[] getHooks() {
|
|
||||||
return new Hook[]{
|
|
||||||
buyCraftHook,
|
|
||||||
liteBansHook,
|
|
||||||
luckPermsHook,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
|
||||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class FakeOfflinePlayer implements OfflinePlayer {
|
|
||||||
|
|
||||||
private final UUID uuid;
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
public FakeOfflinePlayer(UUID uuid, String name) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FakeOfflinePlayer(PlayerContainer player) {
|
|
||||||
this(player.getValue(PlayerKeys.UUID).orElse(null), player.getValue(PlayerKeys.NAME).orElse("Notch"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOnline() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getUniqueId() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBanned() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isWhitelisted() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setWhitelisted(boolean bln) {
|
|
||||||
/* Not used */
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Player getPlayer() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getFirstPlayed() {
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLastPlayed() {
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPlayedBefore() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getBedSpawnLocation() {
|
|
||||||
return new Location(null, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOp() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOp(boolean bln) {
|
|
||||||
/* Not used */
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> serialize() {
|
|
||||||
return new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plugin.api.Check;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract class for easy hooking of plugins.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
|
|
||||||
*/
|
|
||||||
public abstract class Hook {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the plugin being hooked properly enabled?
|
|
||||||
*/
|
|
||||||
protected boolean enabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
* <p>
|
|
||||||
* Checks if the given plugin (class path) is enabled.
|
|
||||||
*
|
|
||||||
* @param pluginClass Class path string of the plugin's main JavaPlugin class.
|
|
||||||
*/
|
|
||||||
public Hook(String pluginClass) {
|
|
||||||
enabled = Check.isAvailable(pluginClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void hook(HookHandler handler) throws NoClassDefFoundError;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor to set enabled to false.
|
|
||||||
*/
|
|
||||||
public Hook() {
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan;
|
|
||||||
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.Provides;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dagger modules for different plugin bridges.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class PluginBridgeModule {
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public static class Bukkit {
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
public Bridge provideBridge(BukkitBridge bridge) {
|
|
||||||
return bridge;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public static class Bungee {
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
public Bridge provideBridge(BungeeBridge bridge) {
|
|
||||||
return bridge;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public static class Sponge {
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
public Bridge provideBridge(SpongeBridge bridge) {
|
|
||||||
return bridge;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public static class Velocity {
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
public Bridge provideBridge(VelocityBridge bridge) {
|
|
||||||
return bridge;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
|
||||||
import com.djrapitops.pluginbridge.plan.buycraft.BuyCraftHook;
|
|
||||||
import com.djrapitops.pluginbridge.plan.luckperms.LuckPermsHook;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plugin bridge for Sponge plugins.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class SpongeBridge extends AbstractBridge {
|
|
||||||
|
|
||||||
private final BuyCraftHook buyCraftHook;
|
|
||||||
private final LuckPermsHook luckPermsHook;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public SpongeBridge(
|
|
||||||
PlanConfig config,
|
|
||||||
ErrorHandler errorHandler,
|
|
||||||
|
|
||||||
BuyCraftHook buyCraftHook,
|
|
||||||
LuckPermsHook luckPermsHook
|
|
||||||
) {
|
|
||||||
super(config, errorHandler);
|
|
||||||
this.buyCraftHook = buyCraftHook;
|
|
||||||
this.luckPermsHook = luckPermsHook;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Hook[] getHooks() {
|
|
||||||
return new Hook[]{
|
|
||||||
buyCraftHook,
|
|
||||||
luckPermsHook
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
|
||||||
import com.djrapitops.pluginbridge.plan.buycraft.BuyCraftHook;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plugin bridge for Velocity plugins.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class VelocityBridge extends AbstractBridge {
|
|
||||||
|
|
||||||
private final BuyCraftHook buyCraftHook;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public VelocityBridge(
|
|
||||||
PlanConfig config,
|
|
||||||
ErrorHandler errorHandler,
|
|
||||||
|
|
||||||
BuyCraftHook buyCraftHook
|
|
||||||
) {
|
|
||||||
super(config, errorHandler);
|
|
||||||
this.buyCraftHook = buyCraftHook;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Hook[] getHooks() {
|
|
||||||
return new Hook[]{
|
|
||||||
buyCraftHook
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.buycraft;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.api.PlanAPI;
|
|
||||||
import com.djrapitops.plan.api.exceptions.connection.ForbiddenException;
|
|
||||||
import com.djrapitops.plan.data.element.AnalysisContainer;
|
|
||||||
import com.djrapitops.plan.data.element.InspectContainer;
|
|
||||||
import com.djrapitops.plan.data.element.TableContainer;
|
|
||||||
import com.djrapitops.plan.data.plugin.ContainerSize;
|
|
||||||
import com.djrapitops.plan.data.plugin.PluginData;
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.utilities.html.Html;
|
|
||||||
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 java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PluginData for BuyCraft plugin.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class BuyCraftData extends PluginData {
|
|
||||||
|
|
||||||
private final String secret;
|
|
||||||
|
|
||||||
private final PlanConfig config;
|
|
||||||
private final Formatter<Long> timestampFormatter;
|
|
||||||
private final Formatter<Double> decimalFormatter;
|
|
||||||
|
|
||||||
BuyCraftData(
|
|
||||||
String secret,
|
|
||||||
PlanConfig config, Formatter<Long> timestampFormatter,
|
|
||||||
Formatter<Double> decimalFormatter
|
|
||||||
) {
|
|
||||||
super(ContainerSize.TAB, "BuyCraft");
|
|
||||||
this.config = config;
|
|
||||||
this.timestampFormatter = timestampFormatter;
|
|
||||||
this.decimalFormatter = decimalFormatter;
|
|
||||||
setPluginIcon(Icon.called("shopping-bag").of(Color.BLUE).build());
|
|
||||||
|
|
||||||
this.secret = secret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) throws Exception {
|
|
||||||
try {
|
|
||||||
|
|
||||||
List<Payment> payments = new ListPaymentRequest(secret).makeRequest();
|
|
||||||
Collections.sort(payments);
|
|
||||||
|
|
||||||
addPaymentTotals(analysisContainer, payments);
|
|
||||||
addPlayerTable(analysisContainer, payments);
|
|
||||||
|
|
||||||
} catch (ForbiddenException e) {
|
|
||||||
analysisContainer.addValue("Configuration error", e.getMessage());
|
|
||||||
}
|
|
||||||
return analysisContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addPlayerTable(AnalysisContainer analysisContainer, List<Payment> payments) {
|
|
||||||
TableContainer payTable = new TableContainer(
|
|
||||||
true,
|
|
||||||
getWithIcon("Date", Icon.called("calendar").of(Family.REGULAR)),
|
|
||||||
getWithIcon("Amount", Icon.called("money-bill-wave")),
|
|
||||||
getWithIcon("Packages", Icon.called("cube"))
|
|
||||||
);
|
|
||||||
payTable.setColor("blue");
|
|
||||||
for (Payment payment : payments) {
|
|
||||||
String name = payment.getPlayerName();
|
|
||||||
payTable.addRow(
|
|
||||||
Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(name), name),
|
|
||||||
timestampFormatter.apply(payment.getDate()),
|
|
||||||
decimalFormatter.apply(payment.getAmount()) + " " + payment.getCurrency(),
|
|
||||||
payment.getPackages()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
analysisContainer.addTable("payTable", payTable);
|
|
||||||
|
|
||||||
MoneyStackGraph moneyStackGraph = new MoneyStackGraph(payments, config);
|
|
||||||
String graphHtml = Html.PANEL_BODY.parse("<div id=\"buycraftChart\" class=\"dashboard-flot-chart\"></div>") +
|
|
||||||
"<script>$(function () {setTimeout(function() {" +
|
|
||||||
"stackChart('buycraftChart', "
|
|
||||||
+ moneyStackGraph.toHighChartsLabels() + ", "
|
|
||||||
+ moneyStackGraph.toHighChartsSeries() + ", '');}, 1000)});</script>";
|
|
||||||
|
|
||||||
analysisContainer.addHtml("moneygraph", graphHtml);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addPaymentTotals(AnalysisContainer analysisContainer, List<Payment> payments) {
|
|
||||||
Map<String, Double> paymentTotals = new HashMap<>();
|
|
||||||
for (Payment payment : payments) {
|
|
||||||
String currency = payment.getCurrency();
|
|
||||||
double amount = payment.getAmount();
|
|
||||||
paymentTotals.put(currency, paymentTotals.getOrDefault(currency, 0.0) + amount);
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, Double> entry : paymentTotals.entrySet()) {
|
|
||||||
analysisContainer.addValue(
|
|
||||||
getWithIcon("Total " + entry.getKey(), Icon.called("money-bill-wave").of(Color.BLUE)),
|
|
||||||
decimalFormatter.apply(entry.getValue())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.buycraft;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plan.system.settings.paths.PluginDataSettings;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook for BuyCraft plugin.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class BuyCraftHook extends Hook {
|
|
||||||
|
|
||||||
private final PlanConfig config;
|
|
||||||
private final Formatters formatters;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public BuyCraftHook(
|
|
||||||
PlanConfig config,
|
|
||||||
Formatters formatters
|
|
||||||
) {
|
|
||||||
super();
|
|
||||||
this.config = config;
|
|
||||||
this.formatters = formatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
|
||||||
String secret = config.get(PluginDataSettings.PLUGIN_BUYCRAFT_SECRET);
|
|
||||||
|
|
||||||
enabled = !secret.equals("-") && !secret.isEmpty();
|
|
||||||
if (enabled) {
|
|
||||||
handler.addPluginDataSource(new BuyCraftData(secret, config, formatters.yearLong(), formatters.decimals()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,112 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.buycraft;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.connection.ForbiddenException;
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.text.ParsePosition;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to Buycraft API for payment listings.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ListPaymentRequest {
|
|
||||||
|
|
||||||
private final String secret;
|
|
||||||
|
|
||||||
public ListPaymentRequest(String secret) {
|
|
||||||
this.secret = secret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Payment> makeRequest() throws IOException, ForbiddenException {
|
|
||||||
URL url = new URL("https://plugin.buycraft.net/payments");
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
|
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
connection.setRequestProperty("X-BuyCraft-Secret", secret);
|
|
||||||
|
|
||||||
JsonElement json;
|
|
||||||
try {
|
|
||||||
InputStreamReader reader = new InputStreamReader(connection.getInputStream());
|
|
||||||
json = new JsonParser().parse(reader);
|
|
||||||
} finally {
|
|
||||||
connection.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json == null || json.isJsonNull()) {
|
|
||||||
throw new NullPointerException("JSON should not be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Payment> payments = new ArrayList<>();
|
|
||||||
if (json.isJsonObject()) {
|
|
||||||
return readError(json);
|
|
||||||
} else if (json.isJsonArray()) {
|
|
||||||
readAndAddPayments(json, payments);
|
|
||||||
}
|
|
||||||
return payments;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void readAndAddPayments(JsonElement json, List<Payment> payments) {
|
|
||||||
JsonArray jsonArray = json.getAsJsonArray();
|
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
|
||||||
|
|
||||||
for (JsonElement element : jsonArray) {
|
|
||||||
JsonObject payment = element.getAsJsonObject();
|
|
||||||
double amount = payment.get("amount").getAsDouble();
|
|
||||||
String dateString = payment.get("date").getAsString();
|
|
||||||
Date dateObj = dateFormat.parse(dateString, new ParsePosition(0));
|
|
||||||
long date = dateObj.getTime();
|
|
||||||
String currency = payment.get("currency").getAsJsonObject().get("iso_4217").getAsString();
|
|
||||||
JsonObject player = payment.get("player").getAsJsonObject();
|
|
||||||
String playerName = player.get("name").getAsString();
|
|
||||||
// UUID uuid = UUID.fromString(player.get("uuid").getAsString().replaceFirst(
|
|
||||||
// "(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"
|
|
||||||
// ));
|
|
||||||
StringBuilder packages = new StringBuilder();
|
|
||||||
for (JsonElement pack : payment.get("packages").getAsJsonArray()) {
|
|
||||||
packages.append(pack.getAsJsonObject().get("name")).append("<br>");
|
|
||||||
}
|
|
||||||
|
|
||||||
payments.add(new Payment(amount, currency, null, playerName, date, packages.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Payment> readError(JsonElement json) throws ForbiddenException {
|
|
||||||
JsonObject jsonObject = json.getAsJsonObject();
|
|
||||||
int errorCode = jsonObject.get("error_code").getAsInt();
|
|
||||||
String errorMessage = jsonObject.get("error_message").getAsString();
|
|
||||||
|
|
||||||
if (errorCode == 403) {
|
|
||||||
throw new ForbiddenException("Incorrect Server Secret. Check config.");
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException(errorCode + ": " + errorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.buycraft;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plan.system.settings.paths.PluginSettings;
|
|
||||||
import com.djrapitops.plan.system.settings.paths.TimeSettings;
|
|
||||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
|
||||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackDataSet;
|
|
||||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.time.format.TextStyle;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility for creating Money Stack Graph.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class MoneyStackGraph {
|
|
||||||
|
|
||||||
private final StackGraph stackGraph;
|
|
||||||
private final ZoneId timeZoneID;
|
|
||||||
private String locale;
|
|
||||||
|
|
||||||
MoneyStackGraph(List<Payment> payments, PlanConfig config) {
|
|
||||||
timeZoneID = config.get(TimeSettings.USE_SERVER_TIME) ? ZoneId.systemDefault() : ZoneOffset.UTC;
|
|
||||||
locale = config.get(PluginSettings.LOCALE);
|
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
long oldestDate = payments.isEmpty() ? now : payments.get(payments.size() - 1).getDate();
|
|
||||||
|
|
||||||
String[] labels = getLabels(now, oldestDate);
|
|
||||||
Map<String, List<Payment>> stacks = getStacks(payments);
|
|
||||||
|
|
||||||
StackDataSet[] dataSets = getDataSets(labels, stacks);
|
|
||||||
|
|
||||||
this.stackGraph = new StackGraph(labels, dataSets);
|
|
||||||
}
|
|
||||||
|
|
||||||
private StackDataSet[] getDataSets(String[] labels, Map<String, List<Payment>> stacks) {
|
|
||||||
String[] colors = ThemeVal.GRAPH_GM_PIE.getDefaultValue().split(", ");
|
|
||||||
int maxCol = colors.length;
|
|
||||||
|
|
||||||
List<StackDataSet> stackDataSets = new ArrayList<>();
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (Map.Entry<String, List<Payment>> entry : stacks.entrySet()) {
|
|
||||||
String currency = entry.getKey();
|
|
||||||
List<Payment> payments = entry.getValue();
|
|
||||||
|
|
||||||
List<Double> values = sortValuesByLabels(labels, getValueMap(payments));
|
|
||||||
|
|
||||||
String color = colors[(i) % maxCol];
|
|
||||||
|
|
||||||
stackDataSets.add(new StackDataSet(values, currency, color));
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stackDataSets.toArray(new StackDataSet[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Double> sortValuesByLabels(String[] labels, Map<String, Double> valueMap) {
|
|
||||||
List<Double> values = new ArrayList<>();
|
|
||||||
for (String label : labels) {
|
|
||||||
values.add(valueMap.getOrDefault(label, 0.0));
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, Double> getValueMap(List<Payment> payments) {
|
|
||||||
Map<String, Double> valueMap = new HashMap<>();
|
|
||||||
for (Payment payment : payments) {
|
|
||||||
String label = getLabel(payment.getDate());
|
|
||||||
Double value = valueMap.getOrDefault(label, 0.0);
|
|
||||||
valueMap.put(label, value + payment.getAmount());
|
|
||||||
}
|
|
||||||
return valueMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, List<Payment>> getStacks(List<Payment> payments) {
|
|
||||||
Map<String, List<Payment>> stacks = new HashMap<>();
|
|
||||||
for (Payment payment : payments) {
|
|
||||||
String currency = payment.getCurrency();
|
|
||||||
|
|
||||||
List<Payment> dataSetPayments = stacks.getOrDefault(currency, new ArrayList<>());
|
|
||||||
dataSetPayments.add(payment);
|
|
||||||
stacks.put(currency, dataSetPayments);
|
|
||||||
}
|
|
||||||
return stacks;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] getLabels(long now, long oldestDate) {
|
|
||||||
long oneYearAgo = now - TimeAmount.YEAR.toMillis(1L);
|
|
||||||
|
|
||||||
long leftLimit = Math.max(oldestDate, oneYearAgo);
|
|
||||||
|
|
||||||
List<String> labels = new ArrayList<>();
|
|
||||||
for (long time = leftLimit; time < now; time += TimeAmount.MONTH.toMillis(1L)) {
|
|
||||||
labels.add(getLabel(time));
|
|
||||||
}
|
|
||||||
|
|
||||||
return labels.toArray(new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getLabel(long time) {
|
|
||||||
Locale usedLocale = locale.equalsIgnoreCase("default") ? Locale.ENGLISH : Locale.forLanguageTag(locale);
|
|
||||||
|
|
||||||
LocalDate date = Instant.ofEpochMilli(time).atZone(timeZoneID).toLocalDate();
|
|
||||||
String month = date.getMonth().getDisplayName(TextStyle.FULL, usedLocale);
|
|
||||||
int year = date.getYear();
|
|
||||||
return month + " " + year;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toHighChartsLabels() {
|
|
||||||
return stackGraph.toHighChartsLabels();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toHighChartsSeries() {
|
|
||||||
return stackGraph.toHighChartsSeries();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.buycraft;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a BuyCraft payment.
|
|
||||||
*
|
|
||||||
* Payments are sorted most recent first by natural ordering.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class Payment implements Comparable<Payment> {
|
|
||||||
|
|
||||||
private final double amount;
|
|
||||||
private final String currency;
|
|
||||||
private final UUID uuid;
|
|
||||||
private final String playerName;
|
|
||||||
private final long date;
|
|
||||||
private final String packages;
|
|
||||||
|
|
||||||
Payment(double amount, String currency, UUID uuid, String playerName, long date, String packages) {
|
|
||||||
this.amount = amount;
|
|
||||||
this.currency = currency;
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.playerName = playerName;
|
|
||||||
this.date = date;
|
|
||||||
this.packages = packages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getAmount() {
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCurrency() {
|
|
||||||
return currency;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPlayerName() {
|
|
||||||
return playerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDate() {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPackages() {
|
|
||||||
return packages;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Payment o) {
|
|
||||||
return -Long.compare(this.date, o.date);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.factions;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.entity.Faction;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to compare factions in terms of Power.
|
|
||||||
*
|
|
||||||
* Compare method should only be used if FactionsHook.isEnabled() returns true.
|
|
||||||
*
|
|
||||||
* Note: this comparator imposes orderings that are inconsistent with equals.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
|
|
||||||
* @see FactionsHook
|
|
||||||
*/
|
|
||||||
public class FactionComparator implements Comparator<Faction> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(Faction fac1, Faction fac2) {
|
|
||||||
return -Double.compare(fac1.getPower(), fac2.getPower());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,125 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.factions;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.utilities.html.HtmlStructure;
|
|
||||||
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 com.djrapitops.plan.utilities.html.icon.Icons;
|
|
||||||
import com.djrapitops.plan.utilities.html.structure.Accordion;
|
|
||||||
import com.djrapitops.plan.utilities.html.structure.AccordionElement;
|
|
||||||
import com.djrapitops.plan.utilities.html.structure.AccordionElementContentBuilder;
|
|
||||||
import com.massivecraft.factions.entity.Faction;
|
|
||||||
import com.massivecraft.factions.entity.MPlayer;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility for creating Factions Accordion Html.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class FactionsAccordion extends Accordion {
|
|
||||||
|
|
||||||
private final List<Faction> factions;
|
|
||||||
private final PlayersMutator playersMutator;
|
|
||||||
|
|
||||||
private final Formatter<Long> timestampFormatter;
|
|
||||||
private final Formatter<Double> decimalFormatter;
|
|
||||||
|
|
||||||
FactionsAccordion(
|
|
||||||
List<Faction> factions,
|
|
||||||
PlayersMutator playersMutator,
|
|
||||||
Formatter<Long> timestampFormatter,
|
|
||||||
Formatter<Double> decimalFormatter
|
|
||||||
) {
|
|
||||||
super("faction_accordion");
|
|
||||||
this.factions = factions;
|
|
||||||
this.playersMutator = playersMutator;
|
|
||||||
this.timestampFormatter = timestampFormatter;
|
|
||||||
this.decimalFormatter = decimalFormatter;
|
|
||||||
|
|
||||||
addElements();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addElements() {
|
|
||||||
for (Faction faction : factions) {
|
|
||||||
String factionName = faction.getName();
|
|
||||||
long createdAtMillis = faction.getCreatedAtMillis();
|
|
||||||
String created = timestampFormatter.apply(createdAtMillis);
|
|
||||||
double power = faction.getPower();
|
|
||||||
double maxPower = faction.getPowerMax();
|
|
||||||
String powerString = decimalFormatter.apply(power) + " / " + decimalFormatter.apply(maxPower);
|
|
||||||
MPlayer leader = faction.getLeader();
|
|
||||||
String leaderName = leader != null ? leader.getName() : "No Leader";
|
|
||||||
|
|
||||||
int landCount = faction.getLandCount();
|
|
||||||
|
|
||||||
Set<UUID> members = new HashSet<>();
|
|
||||||
List<MPlayer> mPlayers = faction.getMPlayers();
|
|
||||||
int memberCount = mPlayers.size();
|
|
||||||
for (MPlayer mPlayer : mPlayers) {
|
|
||||||
if (mPlayer == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
members.add(mPlayer.getUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayersMutator memberMutator = this.playersMutator.filterBy(
|
|
||||||
player -> player.getValue(PlayerKeys.UUID)
|
|
||||||
.map(members::contains).orElse(false)
|
|
||||||
);
|
|
||||||
|
|
||||||
SessionsMutator memberSessionsMutator = new SessionsMutator(memberMutator.getSessions());
|
|
||||||
|
|
||||||
long playerKills = memberSessionsMutator.toPlayerKillCount();
|
|
||||||
long deaths = memberSessionsMutator.toDeathCount();
|
|
||||||
|
|
||||||
String separated = HtmlStructure.separateWithDots(("Power: " + powerString), leaderName);
|
|
||||||
|
|
||||||
String htmlID = "faction_" + factionName + "_" + createdAtMillis;
|
|
||||||
|
|
||||||
String leftSide = new AccordionElementContentBuilder()
|
|
||||||
.addRowBold(Icon.called("calendar").of(Color.DEEP_PURPLE).of(Family.REGULAR), "Created", created)
|
|
||||||
.addRowBold(Icon.called("bolt").of(Color.PURPLE), "Power", powerString)
|
|
||||||
.addRowBold(Icon.called("user").of(Color.PURPLE), "Leader", leaderName)
|
|
||||||
.addRowBold(Icon.called("users").of(Color.PURPLE), "Members", memberCount)
|
|
||||||
.addRowBold(Icon.called("map").of(Color.PURPLE), "Land Count", landCount)
|
|
||||||
.toHtml();
|
|
||||||
|
|
||||||
String rightSide = new AccordionElementContentBuilder()
|
|
||||||
.addRowBold(Icons.PLAYER_KILLS, "Player Kills", playerKills)
|
|
||||||
.addRowBold(Icons.DEATHS, "Deaths", deaths)
|
|
||||||
.toHtml();
|
|
||||||
|
|
||||||
addElement(
|
|
||||||
new AccordionElement(htmlID, factionName + "<span class=\"pull-right\">" + separated + "</span>")
|
|
||||||
.setColor("deep-purple")
|
|
||||||
.setLeftSide(leftSide)
|
|
||||||
.setRightSide(rightSide)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,138 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.factions;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.api.PlanAPI;
|
|
||||||
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.data.store.keys.AnalysisKeys;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plan.system.settings.paths.PluginDataSettings;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.utilities.html.Html;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
|
||||||
import com.massivecraft.factions.entity.Faction;
|
|
||||||
import com.massivecraft.factions.entity.FactionColl;
|
|
||||||
import com.massivecraft.factions.entity.MPlayer;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PluginData for Factions plugin.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class FactionsData extends PluginData {
|
|
||||||
|
|
||||||
private final PlanConfig config;
|
|
||||||
private final Formatter<Long> timestampFormatter;
|
|
||||||
private final Formatter<Double> decimalFormatter;
|
|
||||||
|
|
||||||
FactionsData(
|
|
||||||
PlanConfig config,
|
|
||||||
Formatter<Long> timestampFormatter,
|
|
||||||
Formatter<Double> decimalFormatter
|
|
||||||
) {
|
|
||||||
super(ContainerSize.TAB, "Factions");
|
|
||||||
this.config = config;
|
|
||||||
this.timestampFormatter = timestampFormatter;
|
|
||||||
this.decimalFormatter = decimalFormatter;
|
|
||||||
setPluginIcon(Icon.called("map").of(Color.DEEP_PURPLE).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
|
||||||
MPlayer mPlayer = MPlayer.get(uuid);
|
|
||||||
|
|
||||||
if (mPlayer == null) {
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mPlayer.hasFaction()) {
|
|
||||||
Faction faction = mPlayer.getFaction();
|
|
||||||
if (faction != null) {
|
|
||||||
String factionName = faction.isNone() ? "-" : faction.getName();
|
|
||||||
String factionLeader = faction.getLeader().getName();
|
|
||||||
String factionLeaderLink = Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(factionLeader), factionLeader);
|
|
||||||
|
|
||||||
inspectContainer.addValue(getWithIcon("Faction", Icon.called("flag").of(Color.DEEP_PURPLE)), factionName);
|
|
||||||
inspectContainer.addValue(getWithIcon("Leader", Icon.called("user").of(Color.PURPLE)), factionLeaderLink);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double power = mPlayer.getPower();
|
|
||||||
double maxPower = mPlayer.getPowerMax();
|
|
||||||
String powerString = decimalFormatter.apply(power) + " / " + decimalFormatter.apply(maxPower);
|
|
||||||
inspectContainer.addValue(getWithIcon("Power", Icon.called("bolt").of(Color.PURPLE)), powerString);
|
|
||||||
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnalysisContainer getServerData(Collection<UUID> uuids, AnalysisContainer analysisContainer) {
|
|
||||||
List<Faction> factions = getTopFactions();
|
|
||||||
|
|
||||||
analysisContainer.addValue(getWithIcon("Number of Factions", Icon.called("flag").of(Color.DEEP_PURPLE)), factions.size());
|
|
||||||
|
|
||||||
if (!factions.isEmpty()) {
|
|
||||||
FactionsAccordion factionsAccordion = new FactionsAccordion(
|
|
||||||
factions,
|
|
||||||
Optional.ofNullable(analysisData).flatMap(c -> c.getValue(AnalysisKeys.PLAYERS_MUTATOR))
|
|
||||||
.orElse(new PlayersMutator(new ArrayList<>())),
|
|
||||||
timestampFormatter, decimalFormatter);
|
|
||||||
analysisContainer.addHtml("factionAccordion", factionsAccordion.toHtml());
|
|
||||||
|
|
||||||
Map<UUID, String> userFactions = new HashMap<>();
|
|
||||||
for (UUID uuid : uuids) {
|
|
||||||
MPlayer mPlayer = MPlayer.get(uuid);
|
|
||||||
|
|
||||||
if (mPlayer.hasFaction()) {
|
|
||||||
Faction faction = mPlayer.getFaction();
|
|
||||||
if (faction == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
MPlayer leader = faction.getLeader();
|
|
||||||
String leaderName = leader != null ? leader.getName() : "";
|
|
||||||
String factionName = faction.isNone() ? "-" : faction.getName();
|
|
||||||
|
|
||||||
userFactions.put(uuid, mPlayer.getName().equals(leaderName) ? "<b>" + factionName + "</b>" : factionName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
analysisContainer.addPlayerTableValues(getWithIcon("Faction", Icon.called("flag")), userFactions);
|
|
||||||
}
|
|
||||||
|
|
||||||
return analysisContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Faction> getTopFactions() {
|
|
||||||
List<Faction> topFactions = new ArrayList<>(FactionColl.get().getAll());
|
|
||||||
topFactions.remove(FactionColl.get().getWarzone());
|
|
||||||
topFactions.remove(FactionColl.get().getSafezone());
|
|
||||||
topFactions.remove(FactionColl.get().getNone());
|
|
||||||
List<String> hide = config.get(PluginDataSettings.HIDE_FACTIONS);
|
|
||||||
return topFactions.stream()
|
|
||||||
.filter(faction -> !hide.contains(faction.getName()))
|
|
||||||
.sorted(new FactionComparator())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.factions;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Class responsible for hooking to Factions and registering 4 data sources.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class FactionsHook extends Hook {
|
|
||||||
|
|
||||||
private final PlanConfig config;
|
|
||||||
private final Formatters formatters;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public FactionsHook(
|
|
||||||
PlanConfig config,
|
|
||||||
Formatters formatters
|
|
||||||
) {
|
|
||||||
super("com.massivecraft.factions.entity.MPlayer");
|
|
||||||
this.config = config;
|
|
||||||
this.formatters = formatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
|
||||||
if (enabled) {
|
|
||||||
handler.addPluginDataSource(new FactionsData(config, formatters.yearLong(), formatters.decimals()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,110 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.jobs;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.element.AnalysisContainer;
|
|
||||||
import com.djrapitops.plan.data.element.InspectContainer;
|
|
||||||
import com.djrapitops.plan.data.element.TableContainer;
|
|
||||||
import com.djrapitops.plan.data.plugin.ContainerSize;
|
|
||||||
import com.djrapitops.plan.data.plugin.PluginData;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
|
||||||
import com.gamingmesh.jobs.dao.JobsDAOData;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PluginData for Jobs plugin.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class JobsData extends PluginData {
|
|
||||||
|
|
||||||
private final Formatter<Double> decimalFormatter;
|
|
||||||
|
|
||||||
JobsData(Formatter<Double> decimalFormatter) {
|
|
||||||
super(ContainerSize.THIRD, "Jobs");
|
|
||||||
this.decimalFormatter = decimalFormatter;
|
|
||||||
setPluginIcon(Icon.called("suitcase").of(Color.BROWN).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
|
||||||
List<JobsDAOData> playersJobs = Jobs.getDBManager().getDB().getAllJobs(null, uuid);
|
|
||||||
|
|
||||||
TableContainer jobTable = new TableContainer(
|
|
||||||
getWithIcon("Job", Icon.called("suitcase")),
|
|
||||||
getWithIcon("Level", Icon.called("plus")));
|
|
||||||
for (JobsDAOData job : playersJobs) {
|
|
||||||
jobTable.addRow(job.getJobName(), job.getLevel());
|
|
||||||
}
|
|
||||||
if (playersJobs.isEmpty()) {
|
|
||||||
jobTable.addRow("No Jobs");
|
|
||||||
}
|
|
||||||
inspectContainer.addTable("jobTable", jobTable);
|
|
||||||
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) {
|
|
||||||
List<JobsDAOData> allJobs = Jobs.getDBManager().getDB().getAllJobs()
|
|
||||||
.values().stream()
|
|
||||||
.flatMap(Collection::stream)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
TableContainer jobTable = new TableContainer(
|
|
||||||
getWithIcon("Job", Icon.called("suitcase")),
|
|
||||||
getWithIcon("Workers", Icon.called("users")),
|
|
||||||
getWithIcon("Total Level", Icon.called("plus")),
|
|
||||||
getWithIcon("Average Level", Icon.called("plus"))
|
|
||||||
);
|
|
||||||
|
|
||||||
if (allJobs.isEmpty()) {
|
|
||||||
jobTable.addRow("No Jobs with Workers");
|
|
||||||
} else {
|
|
||||||
Map<String, Integer> workers = new HashMap<>();
|
|
||||||
Map<String, Long> totals = new HashMap<>();
|
|
||||||
for (JobsDAOData data : allJobs) {
|
|
||||||
String job = data.getJobName();
|
|
||||||
int level = data.getLevel();
|
|
||||||
workers.put(job, workers.getOrDefault(job, 0) + 1);
|
|
||||||
totals.put(job, totals.getOrDefault(job, 0L) + level);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> order = new ArrayList<>(workers.keySet());
|
|
||||||
Collections.sort(order);
|
|
||||||
|
|
||||||
for (String job : order) {
|
|
||||||
int amountOfWorkers = workers.getOrDefault(job, 0);
|
|
||||||
long totalLevel = totals.getOrDefault(job, 0L);
|
|
||||||
jobTable.addRow(
|
|
||||||
job,
|
|
||||||
amountOfWorkers,
|
|
||||||
totalLevel,
|
|
||||||
amountOfWorkers != 0 ? decimalFormatter.apply(totalLevel * 1.0 / amountOfWorkers) : "-"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
analysisContainer.addTable("jobTable", jobTable);
|
|
||||||
|
|
||||||
return analysisContainer;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.jobs;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Class responsible for hooking to Jobs and registering data sources.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class JobsHook extends Hook {
|
|
||||||
|
|
||||||
private final Formatter<Double> decimalFormatter;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public JobsHook(Formatters formatters) {
|
|
||||||
super("com.gamingmesh.jobs.Jobs");
|
|
||||||
decimalFormatter = formatters.decimals();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
|
||||||
if (enabled) {
|
|
||||||
handler.addPluginDataSource(new JobsData(decimalFormatter));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.litebans;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
|
||||||
import litebans.api.Database;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Class responsible for hooking to LiteBans and registering data
|
|
||||||
* sources.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class LiteBansBukkitHook extends Hook {
|
|
||||||
|
|
||||||
private Formatter<Long> timestampFormatter;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public LiteBansBukkitHook(
|
|
||||||
Formatters formatters
|
|
||||||
) {
|
|
||||||
super();
|
|
||||||
try {
|
|
||||||
enabled = Database.get() != null;
|
|
||||||
timestampFormatter = formatters.secondLong();
|
|
||||||
} catch (NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError | Exception e) {
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
|
||||||
if (enabled) {
|
|
||||||
LiteBansDatabaseQueries db = new LiteBansDatabaseQueries();
|
|
||||||
handler.addPluginDataSource(new LiteBansData(db, timestampFormatter));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.litebans;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
|
||||||
import litebans.api.Database;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Class responsible for hooking to LiteBans and registering data
|
|
||||||
* sources.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class LiteBansBungeeHook extends Hook {
|
|
||||||
|
|
||||||
private Formatter<Long> timestampFormatter;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public LiteBansBungeeHook(
|
|
||||||
Formatters formatters
|
|
||||||
) {
|
|
||||||
super();
|
|
||||||
try {
|
|
||||||
enabled = Database.get() != null;
|
|
||||||
timestampFormatter = formatters.secondLong();
|
|
||||||
} catch (NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError | Exception e) {
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
|
||||||
if (enabled) {
|
|
||||||
LiteBansDatabaseQueries db = new LiteBansDatabaseQueries();
|
|
||||||
handler.addPluginDataSource(new LiteBansData(db, timestampFormatter));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.litebans;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class representing LiteBans database data about a ban.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class LiteBansDBObj {
|
|
||||||
private final UUID uuid;
|
|
||||||
private final String reason;
|
|
||||||
private final String bannedBy;
|
|
||||||
private final long expiry;
|
|
||||||
private final boolean active;
|
|
||||||
private final long time;
|
|
||||||
|
|
||||||
public LiteBansDBObj(UUID uuid, String reason, String bannedBy, long expiry, boolean active, long time) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.reason = reason;
|
|
||||||
this.bannedBy = bannedBy;
|
|
||||||
this.expiry = expiry;
|
|
||||||
this.active = active;
|
|
||||||
this.time = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReason() {
|
|
||||||
return reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBannedBy() {
|
|
||||||
return bannedBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getExpiry() {
|
|
||||||
return expiry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isActive() {
|
|
||||||
return active;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTime() {
|
|
||||||
return time;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,242 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.litebans;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.api.PlanAPI;
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
|
||||||
import com.djrapitops.plan.data.element.AnalysisContainer;
|
|
||||||
import com.djrapitops.plan.data.element.InspectContainer;
|
|
||||||
import com.djrapitops.plan.data.element.TableContainer;
|
|
||||||
import com.djrapitops.plan.data.plugin.BanData;
|
|
||||||
import com.djrapitops.plan.data.plugin.ContainerSize;
|
|
||||||
import com.djrapitops.plan.data.plugin.PluginData;
|
|
||||||
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.utilities.html.Html;
|
|
||||||
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 com.djrapitops.plan.utilities.html.icon.Icons;
|
|
||||||
import com.djrapitops.plan.utilities.html.structure.TabsElement;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PluginData for LiteBans plugin.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class LiteBansData extends PluginData implements BanData {
|
|
||||||
|
|
||||||
private final LiteBansDatabaseQueries db;
|
|
||||||
|
|
||||||
private final Formatter<Long> timestampFormatter;
|
|
||||||
|
|
||||||
LiteBansData(
|
|
||||||
LiteBansDatabaseQueries db,
|
|
||||||
Formatter<Long> timestampFormatter
|
|
||||||
) {
|
|
||||||
super(ContainerSize.TAB, "LiteBans");
|
|
||||||
this.timestampFormatter = timestampFormatter;
|
|
||||||
setPluginIcon(Icon.called("ban").of(Color.RED).build());
|
|
||||||
this.db = db;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
|
||||||
|
|
||||||
inspectContainer.addValue(Icon.called("balance-scale").of(Color.RED) +
|
|
||||||
" Hover over 'What' column entry for offence reasons", "");
|
|
||||||
|
|
||||||
String what = getWithIcon("Effect", Icon.called("times-circle").of(Family.REGULAR));
|
|
||||||
String by = getWithIcon("By", Icon.called("gavel"));
|
|
||||||
String date = getWithIcon("Expires", Icon.called("calendar-times").of(Family.REGULAR));
|
|
||||||
TableContainer table = new TableContainer(what, by, date);
|
|
||||||
table.setColor("red");
|
|
||||||
|
|
||||||
try {
|
|
||||||
List<LiteBansDBObj> bans = db.getBans(uuid);
|
|
||||||
List<LiteBansDBObj> mutes = db.getMutes(uuid);
|
|
||||||
List<LiteBansDBObj> warns = db.getWarnings(uuid);
|
|
||||||
List<LiteBansDBObj> kicks = db.getKicks(uuid);
|
|
||||||
if (bans.isEmpty() && mutes.isEmpty() && warns.isEmpty() && kicks.isEmpty()) {
|
|
||||||
table.addRow("None");
|
|
||||||
} else {
|
|
||||||
for (LiteBansDBObj ban : bans) {
|
|
||||||
long expiry = ban.getExpiry();
|
|
||||||
String expires = expiry <= 0 ? "Never" : timestampFormatter.apply(expiry);
|
|
||||||
table.addRow(
|
|
||||||
"<span title=\"" + ban.getReason() + "\">Ban</span>",
|
|
||||||
Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(ban.getBannedBy()), ban.getBannedBy()),
|
|
||||||
expires
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for (LiteBansDBObj mute : mutes) {
|
|
||||||
long expiry = mute.getExpiry();
|
|
||||||
String expires = expiry <= 0 ? "Never" : timestampFormatter.apply(expiry);
|
|
||||||
table.addRow(
|
|
||||||
"<span title=\"" + mute.getReason() + "\">Mute</span>",
|
|
||||||
Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(mute.getBannedBy()), mute.getBannedBy()),
|
|
||||||
expires
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for (LiteBansDBObj warn : warns) {
|
|
||||||
long expiry = warn.getExpiry();
|
|
||||||
String expires = expiry <= 0 ? "Never" : timestampFormatter.apply(expiry);
|
|
||||||
table.addRow(
|
|
||||||
"<span title=\"" + warn.getReason() + "\">Warning</span>",
|
|
||||||
Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(warn.getBannedBy()), warn.getBannedBy()),
|
|
||||||
expires
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for (LiteBansDBObj kick : kicks) {
|
|
||||||
long expiry = kick.getExpiry();
|
|
||||||
String expires = expiry <= 0 ? "Never" : timestampFormatter.apply(expiry);
|
|
||||||
table.addRow(
|
|
||||||
"<span title=\"" + kick.getReason() + "\">Kick</span>",
|
|
||||||
Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(kick.getBannedBy()), kick.getBannedBy()),
|
|
||||||
expires
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (DBOpException ex) {
|
|
||||||
table.addRow("Error: " + ex);
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
inspectContainer.addValue(getWithIcon("Error", Icons.RED_WARN), "Database connection is not available");
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
inspectContainer.addTable("table", table);
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) {
|
|
||||||
try {
|
|
||||||
TableContainer banTable = getBanTable();
|
|
||||||
TableContainer muteTable = getMuteTable();
|
|
||||||
TableContainer warningTable = getWarningTable();
|
|
||||||
TableContainer kickTable = getKickTable();
|
|
||||||
|
|
||||||
Html spacing = Html.PANEL_BODY;
|
|
||||||
String[] navAndHtml = new TabsElement(
|
|
||||||
new TabsElement.Tab(getWithIcon("Bans", Icon.called("ban")), spacing.parse(banTable.parseHtml())),
|
|
||||||
new TabsElement.Tab(getWithIcon("Mutes", Icon.called("bell-slash").of(Family.REGULAR)), spacing.parse(muteTable.parseHtml())),
|
|
||||||
new TabsElement.Tab(getWithIcon("Warnings", Icon.called("exclamation-triangle")), spacing.parse(warningTable.parseHtml())),
|
|
||||||
new TabsElement.Tab(getWithIcon("Kicks", Icon.called("user-times")), spacing.parse(kickTable.parseHtml()))
|
|
||||||
).toHtml();
|
|
||||||
analysisContainer.addHtml("Tables", navAndHtml[0] + navAndHtml[1]);
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
analysisContainer.addValue(getWithIcon("Error", Icons.RED_WARN), "Database connection is not available");
|
|
||||||
}
|
|
||||||
return analysisContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableContainer getBanTable() {
|
|
||||||
String banned = getWithIcon("Banned", Icon.called("ban"));
|
|
||||||
String by = getWithIcon("Banned By", Icon.called("gavel"));
|
|
||||||
TableContainer banTable = createTableContainer(banned, by);
|
|
||||||
banTable.useJqueryDataTables();
|
|
||||||
addRows(banTable, db.getBans());
|
|
||||||
return banTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableContainer getMuteTable() {
|
|
||||||
String muted = getWithIcon("Muted", Icon.called("bell-slash").of(Family.REGULAR));
|
|
||||||
String by = getWithIcon("Muted By", Icon.called("gavel"));
|
|
||||||
TableContainer muteTable = createTableContainer(muted, by);
|
|
||||||
muteTable.useJqueryDataTables();
|
|
||||||
addRows(muteTable, db.getMutes());
|
|
||||||
return muteTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableContainer getWarningTable() {
|
|
||||||
String warned = getWithIcon("Warned", Icon.called("exclamation-triangle"));
|
|
||||||
String by = getWithIcon("Warned By", Icon.called("gavel"));
|
|
||||||
TableContainer warnTable = createTableContainer(warned, by);
|
|
||||||
warnTable.useJqueryDataTables();
|
|
||||||
addRows(warnTable, db.getWarnings());
|
|
||||||
return warnTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableContainer getKickTable() {
|
|
||||||
String kicked = getWithIcon("Kicked", Icon.called("user-times"));
|
|
||||||
String by = getWithIcon("Kicked By", Icon.called("gavel"));
|
|
||||||
TableContainer kickTable = createTableContainer(kicked, by);
|
|
||||||
kickTable.useJqueryDataTables();
|
|
||||||
addRows(kickTable, db.getKicks());
|
|
||||||
return kickTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableContainer createTableContainer(String who, String by) {
|
|
||||||
String reason = getWithIcon("Reason", Icon.called("balance-scale"));
|
|
||||||
String given = getWithIcon("Given", Icon.called("clock").of(Family.REGULAR));
|
|
||||||
String expiry = getWithIcon("Expires", Icon.called("calendar-times").of(Family.REGULAR));
|
|
||||||
String active = getWithIcon("Active", Icon.called("hourglass"));
|
|
||||||
|
|
||||||
return new TableContainer(who, by, reason, given, expiry, active);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addRows(TableContainer table, List<LiteBansDBObj> objects) {
|
|
||||||
if (objects.isEmpty()) {
|
|
||||||
table.addRow("No Data");
|
|
||||||
} else {
|
|
||||||
Map<UUID, String> playerNames = Optional.ofNullable(analysisData)
|
|
||||||
.flatMap(c -> c.getValue(AnalysisKeys.PLAYER_NAMES)).orElse(new HashMap<>());
|
|
||||||
for (LiteBansDBObj object : objects) {
|
|
||||||
UUID uuid = object.getUuid();
|
|
||||||
String name = playerNames.getOrDefault(uuid, uuid.toString());
|
|
||||||
long expiry = object.getExpiry();
|
|
||||||
String expires = expiry <= 0 ? "Never" : timestampFormatter.apply(expiry);
|
|
||||||
long time = object.getTime();
|
|
||||||
String given = time <= 0 ? "Unknown" : timestampFormatter.apply(time);
|
|
||||||
|
|
||||||
table.addRow(
|
|
||||||
Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(name), name),
|
|
||||||
Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(object.getBannedBy()), object.getBannedBy()),
|
|
||||||
object.getReason(),
|
|
||||||
given,
|
|
||||||
expires,
|
|
||||||
object.isActive() ? "Yes" : "No"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBanned(UUID uuid) {
|
|
||||||
try {
|
|
||||||
return db.getBans(uuid).stream().anyMatch(LiteBansDBObj::isActive);
|
|
||||||
} catch (DBOpException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<UUID> filterBanned(Collection<UUID> collection) {
|
|
||||||
try {
|
|
||||||
Set<UUID> banned = db.getBans().stream()
|
|
||||||
.filter(LiteBansDBObj::isActive)
|
|
||||||
.map(LiteBansDBObj::getUuid)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
return collection.stream().filter(banned::contains).collect(Collectors.toSet());
|
|
||||||
} catch (DBOpException e) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,144 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.litebans;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
|
||||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
|
||||||
import com.djrapitops.plan.db.access.QueryStatement;
|
|
||||||
import litebans.api.Database;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class responsible for making queries to LiteBans database.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class LiteBansDatabaseQueries {
|
|
||||||
private final Database database;
|
|
||||||
|
|
||||||
private final String banTable;
|
|
||||||
private final String mutesTable;
|
|
||||||
private final String warningsTable;
|
|
||||||
private final String kicksTable;
|
|
||||||
|
|
||||||
private final String selectSQL;
|
|
||||||
|
|
||||||
public LiteBansDatabaseQueries() {
|
|
||||||
database = Database.get();
|
|
||||||
banTable = "{bans}";
|
|
||||||
mutesTable = "{mutes}";
|
|
||||||
warningsTable = "{warnings}";
|
|
||||||
kicksTable = "{kicks}";
|
|
||||||
selectSQL = "SELECT uuid, reason, banned_by_name, until, active, time FROM ";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected <T> T query(QueryStatement<T> statement) {
|
|
||||||
try (PreparedStatement preparedStatement = database.prepareStatement(statement.getSql())) {
|
|
||||||
return statement.executeQuery(preparedStatement);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw DBOpException.forCause(statement.getSql(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<LiteBansDBObj> getObjs(String table) {
|
|
||||||
String sql = selectSQL + table + " LIMIT 5000";
|
|
||||||
|
|
||||||
return query(new QueryAllStatement<List<LiteBansDBObj>>(sql, 2000) {
|
|
||||||
@Override
|
|
||||||
public List<LiteBansDBObj> processResults(ResultSet resultSet) throws SQLException {
|
|
||||||
return processIntoObjects(resultSet);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LiteBansDBObj> getBans() {
|
|
||||||
return getObjs(banTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LiteBansDBObj> getMutes() {
|
|
||||||
return getObjs(mutesTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LiteBansDBObj> getWarnings() {
|
|
||||||
return getObjs(warningsTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LiteBansDBObj> getKicks() {
|
|
||||||
return getObjs(kicksTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<LiteBansDBObj> processIntoObjects(ResultSet set) throws SQLException {
|
|
||||||
List<LiteBansDBObj> objs = new ArrayList<>();
|
|
||||||
while (set.next()) {
|
|
||||||
String uuidS = set.getString("uuid");
|
|
||||||
if (uuidS == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
UUID uuid;
|
|
||||||
try {
|
|
||||||
uuid = UUID.fromString(uuidS);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String reason = set.getString("reason");
|
|
||||||
String bannedBy = set.getString("banned_by_name");
|
|
||||||
long until = set.getLong("until");
|
|
||||||
long time = set.getLong("time");
|
|
||||||
boolean active = set.getBoolean("active");
|
|
||||||
objs.add(new LiteBansDBObj(uuid, reason, bannedBy, until, active, time));
|
|
||||||
}
|
|
||||||
return objs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LiteBansDBObj> getBans(UUID playerUUID) {
|
|
||||||
return getObjs(playerUUID, banTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LiteBansDBObj> getMutes(UUID playerUUID) {
|
|
||||||
return getObjs(playerUUID, mutesTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LiteBansDBObj> getWarnings(UUID playerUUID) {
|
|
||||||
return getObjs(playerUUID, warningsTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LiteBansDBObj> getKicks(UUID playerUUID) {
|
|
||||||
return getObjs(playerUUID, kicksTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<LiteBansDBObj> getObjs(UUID playerUUID, String table) {
|
|
||||||
String sql = selectSQL + table + " WHERE uuid=?";
|
|
||||||
|
|
||||||
return query(new QueryStatement<List<LiteBansDBObj>>(sql, 2000) {
|
|
||||||
@Override
|
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
|
||||||
statement.setString(1, playerUUID.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<LiteBansDBObj> processResults(ResultSet resultSet) throws SQLException {
|
|
||||||
return processIntoObjects(resultSet);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,139 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.luckperms;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.element.AnalysisContainer;
|
|
||||||
import com.djrapitops.plan.data.element.InspectContainer;
|
|
||||||
import com.djrapitops.plan.data.element.TableContainer;
|
|
||||||
import com.djrapitops.plan.data.plugin.ContainerSize;
|
|
||||||
import com.djrapitops.plan.data.plugin.PluginData;
|
|
||||||
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 me.lucko.luckperms.api.*;
|
|
||||||
import me.lucko.luckperms.api.caching.MetaData;
|
|
||||||
import org.apache.commons.text.TextStringBuilder;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PluginData for LuckPerms plugin.
|
|
||||||
*
|
|
||||||
* @author Vankka
|
|
||||||
*/
|
|
||||||
class LuckPermsData extends PluginData {
|
|
||||||
|
|
||||||
private final LuckPermsApi api;
|
|
||||||
|
|
||||||
LuckPermsData(LuckPermsApi api) {
|
|
||||||
super(ContainerSize.THIRD, "LuckPerms");
|
|
||||||
setPluginIcon(Icon.called("exclamation-triangle").of(Color.LIGHT_GREEN).build());
|
|
||||||
|
|
||||||
this.api = api;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
|
||||||
User user = api.getUser(uuid);
|
|
||||||
|
|
||||||
if (user == null) {
|
|
||||||
inspectContainer.addValue("Data unavailable", "Could not get user data");
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
MetaData metaData = user.getCachedData().getMetaData(Contexts.allowAll());
|
|
||||||
String prefix = metaData.getPrefix();
|
|
||||||
String suffix = metaData.getSuffix();
|
|
||||||
|
|
||||||
inspectContainer.addValue(getWithIcon("Primary group", Icon.called("user-friends").of(Family.SOLID)), user.getPrimaryGroup());
|
|
||||||
inspectContainer.addValue(getWithIcon("Prefix", Icon.called("file-signature").of(Family.SOLID).of(Color.GREEN)), prefix != null ? prefix : "None");
|
|
||||||
inspectContainer.addValue(getWithIcon("Suffix", Icon.called("file-signature").of(Family.SOLID).of(Color.BLUE)),suffix != null ? suffix : "None");
|
|
||||||
|
|
||||||
if (!metaData.getMeta().isEmpty()) {
|
|
||||||
TableContainer metaTable = new TableContainer(
|
|
||||||
getWithIcon("Meta", Icon.called("info-circle").of(Family.SOLID)),
|
|
||||||
getWithIcon("Value", Icon.called("file-alt").of(Family.SOLID))
|
|
||||||
);
|
|
||||||
metaData.getMeta().forEach((key, value) -> metaTable.addRow(key, value));
|
|
||||||
inspectContainer.addTable("Meta", metaTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> groups = user.getPermissions().stream()
|
|
||||||
.filter(Node::isGroupNode)
|
|
||||||
.map(Node::getGroupName)
|
|
||||||
.sorted()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
inspectContainer.addValue(
|
|
||||||
getWithIcon("Groups", Icon.called("user-friends").of(Family.SOLID)),
|
|
||||||
new TextStringBuilder().appendWithSeparators(groups, ", ").build()
|
|
||||||
);
|
|
||||||
|
|
||||||
Set<Track> tracks = api.getTracks();
|
|
||||||
if (!tracks.isEmpty()) {
|
|
||||||
TableContainer trackTable = new TableContainer(
|
|
||||||
getWithIcon("Track", Icon.called("ellipsis-h").of(Family.SOLID)),
|
|
||||||
getWithIcon("Group", Icon.called("user-friends").of(Family.SOLID))
|
|
||||||
);
|
|
||||||
for (Track track : tracks) {
|
|
||||||
// reduce is used to get the last element
|
|
||||||
String currentGroup = api.getGroups().stream()
|
|
||||||
.map(this::getGroupDisplayName).filter(groups::contains)
|
|
||||||
.reduce((first, second) -> second).orElse("None");
|
|
||||||
trackTable.addRow(track.getName(), currentGroup);
|
|
||||||
}
|
|
||||||
inspectContainer.addTable("Tracks", trackTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnalysisContainer getServerData(Collection<UUID> uuids, AnalysisContainer analysisContainer) {
|
|
||||||
// There will *always* be atleast 1 group
|
|
||||||
TableContainer groupTable = new TableContainer(
|
|
||||||
getWithIcon("Group", Icon.called("user-friends").of(Family.SOLID)),
|
|
||||||
getWithIcon("Weight", Icon.called("weight-hanging").of(Family.SOLID)),
|
|
||||||
getWithIcon("Permissions", Icon.called("list").of(Family.SOLID))
|
|
||||||
);
|
|
||||||
|
|
||||||
api.getGroups().stream().sorted(Comparator.comparing(Group::getName)).forEach(group -> {
|
|
||||||
OptionalInt weight = group.getWeight();
|
|
||||||
|
|
||||||
groupTable.addRow(getGroupDisplayName(group), weight.isPresent() ? weight.getAsInt() : "None", group.getPermissions().size());
|
|
||||||
});
|
|
||||||
analysisContainer.addTable("Groups", groupTable);
|
|
||||||
|
|
||||||
Set<Track> tracks = api.getTracks();
|
|
||||||
if (!tracks.isEmpty()) {
|
|
||||||
TableContainer trackTable = new TableContainer(
|
|
||||||
getWithIcon("Track", Icon.called("ellipsis-h").of(Family.SOLID)),
|
|
||||||
getWithIcon("Size", Icon.called("list").of(Family.SOLID))
|
|
||||||
);
|
|
||||||
tracks.forEach(track -> trackTable.addRow(track.getName(), track.getSize()));
|
|
||||||
analysisContainer.addTable("Tracks", trackTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return analysisContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getGroupDisplayName(Group group) {
|
|
||||||
String displayName = group.getDisplayName();
|
|
||||||
return displayName != null ? displayName : group.getName();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.luckperms;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
|
||||||
import me.lucko.luckperms.LuckPerms;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook for LuckPerms plugin.
|
|
||||||
*
|
|
||||||
* @author Vankka
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class LuckPermsHook extends Hook {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public LuckPermsHook() {
|
|
||||||
super("me.lucko.luckperms.LuckPerms");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void hook(HookHandler handler) throws IllegalStateException {
|
|
||||||
if (enabled) {
|
|
||||||
handler.addPluginDataSource(new LuckPermsData(LuckPerms.getApi()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.placeholderapi;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
|
||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plan.system.webserver.WebServer;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Class responsible for hooking to PlaceholderAPI.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class PlaceholderAPIHook extends Hook {
|
|
||||||
|
|
||||||
private final PlanPlugin plugin;
|
|
||||||
private final PlanConfig config;
|
|
||||||
private final DBSystem dbSystem;
|
|
||||||
private final ServerInfo serverInfo;
|
|
||||||
private final WebServer webServer;
|
|
||||||
private final Formatters formatters;
|
|
||||||
private final ErrorHandler errorHandler;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public PlaceholderAPIHook(
|
|
||||||
PlanPlugin plugin,
|
|
||||||
PlanConfig config,
|
|
||||||
DBSystem dbSystem,
|
|
||||||
ServerInfo serverInfo,
|
|
||||||
WebServer webServer,
|
|
||||||
Formatters formatters,
|
|
||||||
ErrorHandler errorHandler
|
|
||||||
) {
|
|
||||||
super("me.clip.placeholderapi.PlaceholderAPI");
|
|
||||||
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.config = config;
|
|
||||||
this.dbSystem = dbSystem;
|
|
||||||
this.serverInfo = serverInfo;
|
|
||||||
this.webServer = webServer;
|
|
||||||
this.formatters = formatters;
|
|
||||||
this.errorHandler = errorHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
|
||||||
if (enabled) {
|
|
||||||
PlaceholderAPI.unregisterPlaceholderHook("plan");
|
|
||||||
PlaceholderAPI.registerPlaceholderHook("plan",
|
|
||||||
new PlanPlaceholders(plugin, config, serverInfo, webServer, formatters, errorHandler)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,228 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.placeholderapi;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.api.PlanAPI;
|
|
||||||
import com.djrapitops.plan.api.data.PlayerContainer;
|
|
||||||
import com.djrapitops.plan.api.data.ServerContainer;
|
|
||||||
import com.djrapitops.plan.data.container.GeoInfo;
|
|
||||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
|
||||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.GeoInfoMutator;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
|
||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plan.system.settings.paths.DisplaySettings;
|
|
||||||
import com.djrapitops.plan.system.settings.paths.TimeSettings;
|
|
||||||
import com.djrapitops.plan.system.webserver.WebServer;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
import com.djrapitops.plugin.logging.L;
|
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Placeholders of Plan.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class PlanPlaceholders extends PlaceholderExpansion {
|
|
||||||
|
|
||||||
private final PlanPlugin plugin;
|
|
||||||
private final PlanConfig config;
|
|
||||||
private final ServerInfo serverInfo;
|
|
||||||
private final WebServer webServer;
|
|
||||||
private final Formatters formatters;
|
|
||||||
private final ErrorHandler errorHandler;
|
|
||||||
|
|
||||||
public PlanPlaceholders(
|
|
||||||
PlanPlugin plugin,
|
|
||||||
PlanConfig config,
|
|
||||||
ServerInfo serverInfo,
|
|
||||||
WebServer webServer,
|
|
||||||
Formatters formatters,
|
|
||||||
ErrorHandler errorHandler
|
|
||||||
) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.config = config;
|
|
||||||
this.serverInfo = serverInfo;
|
|
||||||
this.webServer = webServer;
|
|
||||||
this.formatters = formatters;
|
|
||||||
this.errorHandler = errorHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIdentifier() {
|
|
||||||
return "plan";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPlugin() {
|
|
||||||
return "Plan";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAuthor() {
|
|
||||||
return "Rsl1122";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getVersion() {
|
|
||||||
return plugin.getVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String onPlaceholderRequest(Player player, String identifier) {
|
|
||||||
Serializable planValue = getPlanValue(identifier);
|
|
||||||
if (planValue != null) {
|
|
||||||
return planValue.toString();
|
|
||||||
}
|
|
||||||
Serializable serverValue = getServerValue(identifier);
|
|
||||||
if (serverValue != null) {
|
|
||||||
return serverValue.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player != null) {
|
|
||||||
Serializable playerValue = getPlayerValue(player, identifier);
|
|
||||||
if (playerValue != null) {
|
|
||||||
return playerValue.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Serializable getPlanValue(String identifier) {
|
|
||||||
switch (identifier.toLowerCase()) {
|
|
||||||
case "address":
|
|
||||||
return webServer.getAccessAddress();
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Serializable getServerValue(String identifier) {
|
|
||||||
ServerContainer serverContainer = PlanAPI.getInstance().fetchServerContainer(serverInfo.getServerUUID());
|
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
long dayAgo = now - TimeUnit.DAYS.toMillis(1L);
|
|
||||||
long weekAgo = now - TimeAmount.WEEK.toMillis(1L);
|
|
||||||
long monthAgo = now - TimeAmount.MONTH.toMillis(1L);
|
|
||||||
|
|
||||||
try {
|
|
||||||
PlayersMutator playersMutator = new PlayersMutator(serverContainer.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>()));
|
|
||||||
switch (identifier.toLowerCase()) {
|
|
||||||
case "players_total":
|
|
||||||
return playersMutator.count();
|
|
||||||
case "players_new_day":
|
|
||||||
return playersMutator.filterRegisteredBetween(dayAgo, now).count();
|
|
||||||
case "players_new_week":
|
|
||||||
return playersMutator.filterRegisteredBetween(weekAgo, now).count();
|
|
||||||
case "players_new_month":
|
|
||||||
return playersMutator.filterRegisteredBetween(monthAgo, now).count();
|
|
||||||
case "players_unique_day":
|
|
||||||
return playersMutator.filterPlayedBetween(dayAgo, now).count();
|
|
||||||
case "players_unique_week":
|
|
||||||
return playersMutator.filterPlayedBetween(weekAgo, now).count();
|
|
||||||
case "players_unique_month":
|
|
||||||
return playersMutator.filterPlayedBetween(monthAgo, now).count();
|
|
||||||
case "playtime_total":
|
|
||||||
return formatters.timeAmount().apply(new SessionsMutator(playersMutator.getSessions()).toPlaytime());
|
|
||||||
case "session_avg":
|
|
||||||
return formatters.timeAmount().apply(new SessionsMutator(playersMutator.getSessions()).toAverageSessionLength());
|
|
||||||
case "session_count":
|
|
||||||
return playersMutator.getSessions().size();
|
|
||||||
case "kills_players":
|
|
||||||
return new SessionsMutator(playersMutator.getSessions()).toPlayerKillCount();
|
|
||||||
case "kills_mobs":
|
|
||||||
return new SessionsMutator(playersMutator.getSessions()).toMobKillCount();
|
|
||||||
case "deaths_total":
|
|
||||||
return new SessionsMutator(playersMutator.getSessions()).toDeathCount();
|
|
||||||
case "tps_day":
|
|
||||||
return new TPSMutator(serverContainer.getValue(ServerKeys.TPS).orElse(new ArrayList<>())).filterDataBetween(dayAgo, now).averageTPS();
|
|
||||||
case "tps_drops_week":
|
|
||||||
return new TPSMutator(serverContainer.getValue(ServerKeys.TPS).orElse(new ArrayList<>())).filterDataBetween(weekAgo, now)
|
|
||||||
.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED));
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
errorHandler.log(L.WARN, this.getClass(), e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Serializable getPlayerValue(Player player, String identifier) {
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
PlayerContainer playerContainer = PlanAPI.getInstance().fetchPlayerContainer(uuid);
|
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
long dayAgo = now - TimeUnit.DAYS.toMillis(1L);
|
|
||||||
long weekAgo = now - TimeAmount.WEEK.toMillis(1L);
|
|
||||||
long monthAgo = now - TimeAmount.MONTH.toMillis(1L);
|
|
||||||
|
|
||||||
try {
|
|
||||||
SessionsMutator sessionsMutator = new SessionsMutator(playerContainer.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>()));
|
|
||||||
switch (identifier.toLowerCase()) {
|
|
||||||
case "playtime":
|
|
||||||
return formatters.timeAmount().apply(sessionsMutator.toPlaytime());
|
|
||||||
case "playtime_day":
|
|
||||||
return formatters.timeAmount().apply(sessionsMutator.filterSessionsBetween(dayAgo, now).toPlaytime());
|
|
||||||
case "playtime_week":
|
|
||||||
return formatters.timeAmount().apply(sessionsMutator.filterSessionsBetween(weekAgo, now).toPlaytime());
|
|
||||||
case "playtime_month":
|
|
||||||
return formatters.timeAmount().apply(sessionsMutator.filterSessionsBetween(monthAgo, now).toPlaytime());
|
|
||||||
case "geolocation":
|
|
||||||
return new GeoInfoMutator(playerContainer.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>())).mostRecent().map(GeoInfo::getGeolocation).orElse("Unknown");
|
|
||||||
case "activity_index":
|
|
||||||
double activityIndex = playerContainer.getActivityIndex(
|
|
||||||
now,
|
|
||||||
config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD),
|
|
||||||
config.get(TimeSettings.ACTIVE_LOGIN_THRESHOLD)
|
|
||||||
);
|
|
||||||
return activityIndex;
|
|
||||||
case "registered":
|
|
||||||
return formatters.yearLong().apply(playerContainer.getValue(PlayerKeys.REGISTERED).orElse(0L));
|
|
||||||
case "last_seen":
|
|
||||||
return formatters.yearLong().apply(playerContainer.getValue(PlayerKeys.LAST_SEEN).orElse(0L));
|
|
||||||
case "player_kills":
|
|
||||||
return sessionsMutator.toPlayerKillCount();
|
|
||||||
case "mob_kills":
|
|
||||||
return sessionsMutator.toMobKillCount();
|
|
||||||
case "deaths":
|
|
||||||
return sessionsMutator.toDeathCount();
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
errorHandler.log(L.WARN, this.getClass(), e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,131 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.react;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
|
||||||
import com.djrapitops.plan.db.access.ExecStatement;
|
|
||||||
import com.djrapitops.plan.db.access.Executable;
|
|
||||||
import com.djrapitops.plan.db.access.Query;
|
|
||||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
|
||||||
import com.djrapitops.plan.db.sql.parsing.Select;
|
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
import com.volmit.react.api.SampledType;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Database Table in charge of storing data from React.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ReactDataTable {
|
|
||||||
|
|
||||||
private static final String TABLE_NAME = "plan_react_data";
|
|
||||||
|
|
||||||
public void createTable() throws DBInitException {
|
|
||||||
// createTable(TableSqlParser.createTable(TABLE_NAME)
|
|
||||||
// .primaryKey(supportsMySQLQueries, Col.ID)
|
|
||||||
// .column(Col.DATE, Sql.LONG)
|
|
||||||
// .column(Col.SAMPLED_TYPE, Sql.varchar(30))
|
|
||||||
// .column(Col.MINUTE_AVERAGE, Sql.DOUBLE)
|
|
||||||
// .primaryKeyIDColumn(supportsMySQLQueries, Col.ID)
|
|
||||||
// .toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Executable clean() {
|
|
||||||
String sql = "DELETE FROM " + TABLE_NAME + " WHERE " + Col.DATE + "<?";
|
|
||||||
|
|
||||||
return new ExecStatement(sql) {
|
|
||||||
@Override
|
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
|
||||||
statement.setLong(1, System.currentTimeMillis() - TimeAmount.MONTH.toMillis(1L));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Executable addData(ReactValue value) {
|
|
||||||
String sql = "INSERT INTO " + TABLE_NAME + " (" +
|
|
||||||
Col.SAMPLED_TYPE + ", " +
|
|
||||||
Col.DATE + ", " +
|
|
||||||
Col.MINUTE_AVERAGE +
|
|
||||||
") VALUES (?, ?, ?)";
|
|
||||||
|
|
||||||
return new ExecStatement(sql) {
|
|
||||||
@Override
|
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
|
||||||
statement.setString(1, value.getType().name());
|
|
||||||
statement.setLong(2, value.getDate());
|
|
||||||
statement.setDouble(3, value.getDataValue());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Query<Map<SampledType, List<ReactValue>>> getAllData() {
|
|
||||||
String sql = Select.all(TABLE_NAME).toString();
|
|
||||||
|
|
||||||
return new QueryAllStatement<Map<SampledType, List<ReactValue>>>(sql, 50000) {
|
|
||||||
@Override
|
|
||||||
public Map<SampledType, List<ReactValue>> processResults(ResultSet set) throws SQLException {
|
|
||||||
Map<SampledType, List<ReactValue>> results = new EnumMap<>(SampledType.class);
|
|
||||||
while (set.next()) {
|
|
||||||
try {
|
|
||||||
SampledType type = SampledType.valueOf(set.getString(Col.SAMPLED_TYPE.get()));
|
|
||||||
long date = set.getLong(Col.DATE.get());
|
|
||||||
double average = set.getDouble(Col.MINUTE_AVERAGE.get());
|
|
||||||
|
|
||||||
ReactValue value = new ReactValue(type, date, average);
|
|
||||||
|
|
||||||
List<ReactValue> values = results.getOrDefault(type, new ArrayList<>());
|
|
||||||
values.add(value);
|
|
||||||
results.put(type, values);
|
|
||||||
} catch (NoSuchFieldError ignore) {
|
|
||||||
/* Ignored, field has been removed and is no longer supported */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Col {
|
|
||||||
ID("id"),
|
|
||||||
SAMPLED_TYPE("sampled_type"),
|
|
||||||
DATE("date"),
|
|
||||||
MINUTE_AVERAGE("minute_average");
|
|
||||||
|
|
||||||
private final String columnName;
|
|
||||||
|
|
||||||
Col(String columnName) {
|
|
||||||
this.columnName = columnName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String get() {
|
|
||||||
return columnName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return columnName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.react;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.system.processing.Processing;
|
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
|
||||||
import com.volmit.react.React;
|
|
||||||
import com.volmit.react.api.GraphSampleLine;
|
|
||||||
import com.volmit.react.api.SampledType;
|
|
||||||
import com.volmit.react.util.M;
|
|
||||||
import primal.lang.collection.GMap;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Task in charge of collecting data from React.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class ReactDataTask extends AbsRunnable {
|
|
||||||
|
|
||||||
private static final SampledType[] STORED_TYPES = new SampledType[]{
|
|
||||||
SampledType.ENT,
|
|
||||||
SampledType.ENTLIV,
|
|
||||||
SampledType.ENTDROP,
|
|
||||||
SampledType.ENTTILE,
|
|
||||||
|
|
||||||
SampledType.TIU,
|
|
||||||
SampledType.HOPPER_TICK_USAGE,
|
|
||||||
SampledType.FLUID_TICK_USAGE,
|
|
||||||
SampledType.REDSTONE_TICK_USAGE,
|
|
||||||
|
|
||||||
SampledType.TICK,
|
|
||||||
SampledType.TILE_DROPTICK,
|
|
||||||
SampledType.FLUID_TICK,
|
|
||||||
SampledType.HOPPER_TICK,
|
|
||||||
SampledType.ENTITY_DROPTICK,
|
|
||||||
SampledType.REDSTONE_TICK,
|
|
||||||
|
|
||||||
SampledType.REACT_TASK_TIME
|
|
||||||
};
|
|
||||||
private final ReactDataTable table;
|
|
||||||
private final Processing processing;
|
|
||||||
private final Map<SampledType, List<ReactValue>> history;
|
|
||||||
|
|
||||||
public ReactDataTask(ReactDataTable table, Processing processing) {
|
|
||||||
this.table = table;
|
|
||||||
this.processing = processing;
|
|
||||||
history = new EnumMap<>(SampledType.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
GMap<SampledType, GraphSampleLine> samplers = React.instance.graphController.getG();
|
|
||||||
|
|
||||||
for (SampledType type : STORED_TYPES) {
|
|
||||||
processType(samplers, type);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processType(GMap<SampledType, GraphSampleLine> samplers, SampledType type) {
|
|
||||||
GMap<Long, Double> values = samplers.get(type).getPlotBoard().getBetween(M.ms() - 10000, M.ms());
|
|
||||||
if (values.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<ReactValue> storedValues = history.getOrDefault(type, new ArrayList<>());
|
|
||||||
values.entrySet().stream()
|
|
||||||
.map(entry -> new ReactValue(type, entry.getKey(), entry.getValue()))
|
|
||||||
.sorted()
|
|
||||||
.forEachOrdered(storedValues::add);
|
|
||||||
|
|
||||||
if (storedValues.get(0).getDate() < System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(1L)) {
|
|
||||||
processing.submitNonCritical(new ValueStoringProcessor(table, type, storedValues));
|
|
||||||
history.remove(type);
|
|
||||||
} else {
|
|
||||||
history.put(type, storedValues);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.react;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
|
||||||
import com.djrapitops.plan.system.processing.Processing;
|
|
||||||
import com.djrapitops.plugin.task.PluginTask;
|
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook in charge for hooking into React.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class ReactHook extends Hook {
|
|
||||||
|
|
||||||
private static PluginTask TASK;
|
|
||||||
|
|
||||||
private final Processing processing;
|
|
||||||
private final DBSystem dbSystem;
|
|
||||||
private final RunnableFactory runnableFactory;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public ReactHook(
|
|
||||||
Processing processing,
|
|
||||||
DBSystem dbSystem,
|
|
||||||
RunnableFactory runnableFactory
|
|
||||||
) {
|
|
||||||
super("com.volmit.react.ReactPlugin");
|
|
||||||
this.processing = processing;
|
|
||||||
this.dbSystem = dbSystem;
|
|
||||||
this.runnableFactory = runnableFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setTask(PluginTask task) {
|
|
||||||
if (TASK != null) {
|
|
||||||
try {
|
|
||||||
TASK.cancel();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
/* Possible "Task not registered" exception is ignored. */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ReactHook.TASK = task;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
|
||||||
if (enabled) {
|
|
||||||
// ReactDataTable table = new ReactDataTable((SQLDB) dbSystem.getDatabase());
|
|
||||||
//// try {
|
|
||||||
//// table.createTable();
|
|
||||||
//// } catch (DBInitException e) {
|
|
||||||
//// throw new DBOpException("Failed to create React data table", e);
|
|
||||||
//// }
|
|
||||||
//// table.clean();
|
|
||||||
|
|
||||||
// PluginTask task = runnableFactory.create("React Data Task", new ReactDataTask(table, processing))
|
|
||||||
// .runTaskTimerAsynchronously(TimeAmount.toTicks(10L, TimeUnit.SECONDS), TimeAmount.toTicks(10L, TimeUnit.SECONDS));
|
|
||||||
// setTask(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.react;
|
|
||||||
|
|
||||||
import com.volmit.react.api.SampledType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data container for React data points.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ReactValue implements Comparable<ReactValue> {
|
|
||||||
|
|
||||||
private final SampledType type;
|
|
||||||
private final long date;
|
|
||||||
private final double dataValue;
|
|
||||||
|
|
||||||
public ReactValue(SampledType type, long date, double dataValue) {
|
|
||||||
this.type = type;
|
|
||||||
this.date = date;
|
|
||||||
this.dataValue = dataValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SampledType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDate() {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getDataValue() {
|
|
||||||
return dataValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(ReactValue o) {
|
|
||||||
return Long.compare(this.date, o.date);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.react;
|
|
||||||
|
|
||||||
import com.volmit.react.api.SampledType;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Processor in charge of turning values into single numbers.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class ValueStoringProcessor implements Runnable {
|
|
||||||
|
|
||||||
private final ReactDataTable table;
|
|
||||||
private final SampledType type;
|
|
||||||
private final List<ReactValue> values;
|
|
||||||
|
|
||||||
ValueStoringProcessor(ReactDataTable table, SampledType type, List<ReactValue> values) {
|
|
||||||
this.table = table;
|
|
||||||
this.type = type;
|
|
||||||
this.values = values;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ReactValue average = avgValue(values);
|
|
||||||
|
|
||||||
if (average == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
table.addData(average);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ReactValue avgValue(List<ReactValue> values) {
|
|
||||||
if (values.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
long date = values.get(0).getDate();
|
|
||||||
double average = values.stream().mapToDouble(ReactValue::getDataValue).average().orElse(0.0);
|
|
||||||
|
|
||||||
return new ReactValue(type, date, average);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.towny;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to compare towns in terms of Amount of residents.
|
|
||||||
*
|
|
||||||
* Compare method should only be used if TownyHook.isEnabled() returns true.
|
|
||||||
*
|
|
||||||
* Note: this comparator imposes orderings that are inconsistent with equals.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
|
|
||||||
* @see TownyHook
|
|
||||||
*/
|
|
||||||
public class TownComparator implements Comparator<Town> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to compare two Town objects.
|
|
||||||
*
|
|
||||||
* This method should only be used if TownyHook.isEnabled() returns true.
|
|
||||||
*
|
|
||||||
* Note: this comparator imposes orderings that are inconsistent with
|
|
||||||
* equals.
|
|
||||||
* @param tow1 Town 1
|
|
||||||
* @param tow2 Town 2
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int compare(Town tow1, Town tow2) {
|
|
||||||
if (tow1.equals(tow2)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int tow1res = tow1.getNumResidents();
|
|
||||||
int tow2res = tow2.getNumResidents();
|
|
||||||
if (tow1res == tow2res) {
|
|
||||||
return 0;
|
|
||||||
} else if (tow1res > tow2res) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,115 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.towny;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
|
||||||
import com.djrapitops.plan.utilities.html.HtmlStructure;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
|
||||||
import com.djrapitops.plan.utilities.html.structure.Accordion;
|
|
||||||
import com.djrapitops.plan.utilities.html.structure.AccordionElement;
|
|
||||||
import com.djrapitops.plan.utilities.html.structure.AccordionElementContentBuilder;
|
|
||||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
|
||||||
import com.palmergames.bukkit.towny.object.Coord;
|
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility for creating Towny Accordion Html.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class TownsAccordion extends Accordion {
|
|
||||||
|
|
||||||
private final List<Town> towns;
|
|
||||||
private final PlayersMutator playersMutator;
|
|
||||||
|
|
||||||
TownsAccordion(List<Town> towns, PlayersMutator playersMutator) {
|
|
||||||
super("towny_accordion");
|
|
||||||
this.towns = towns;
|
|
||||||
this.playersMutator = playersMutator;
|
|
||||||
|
|
||||||
addElements();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addElements() {
|
|
||||||
for (Town town : towns) {
|
|
||||||
String townName = town.getName();
|
|
||||||
Resident mayor = town.getMayor();
|
|
||||||
String mayorName = mayor != null ? mayor.getName() : "NPC";
|
|
||||||
|
|
||||||
String coordinates = "";
|
|
||||||
try {
|
|
||||||
Coord homeBlock = town.getHomeBlock().getCoord();
|
|
||||||
coordinates = "x: " + homeBlock.getX() + " z: " + homeBlock.getZ();
|
|
||||||
} catch (TownyException ignore) {
|
|
||||||
/* Town has no home block */
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Resident> residents = town.getResidents();
|
|
||||||
int residentCount = residents.size();
|
|
||||||
long claimedBlocks = town.getTownBlocks().stream().filter(TownBlock::hasTown).count();
|
|
||||||
String landCount = claimedBlocks + " / " + town.getTotalBlocks();
|
|
||||||
|
|
||||||
Set<String> members = new HashSet<>();
|
|
||||||
for (Resident resident : residents) {
|
|
||||||
members.add(resident.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayersMutator memberMutator = this.playersMutator.filterBy(
|
|
||||||
player -> player.getValue(PlayerKeys.NAME)
|
|
||||||
.map(members::contains).orElse(false)
|
|
||||||
);
|
|
||||||
|
|
||||||
SessionsMutator memberSessionsMutator = new SessionsMutator(memberMutator.getSessions());
|
|
||||||
|
|
||||||
long playerKills = memberSessionsMutator.toPlayerKillCount();
|
|
||||||
long mobKills = memberSessionsMutator.toMobKillCount();
|
|
||||||
long deaths = memberSessionsMutator.toDeathCount();
|
|
||||||
|
|
||||||
String separated = HtmlStructure.separateWithDots(("Residents: " + residentCount), mayorName);
|
|
||||||
|
|
||||||
String htmlID = "town_" + townName.replace(" ", "-");
|
|
||||||
|
|
||||||
String leftSide = new AccordionElementContentBuilder()
|
|
||||||
.addRowBold(Icon.called("user").of(Color.BROWN), "Major", mayorName)
|
|
||||||
.addRowBold(Icon.called("users").of(Color.BROWN), "Residents", residentCount)
|
|
||||||
.addRowBold(Icon.called("map").of(Color.BROWN), "Town Blocks", landCount)
|
|
||||||
.addRowBold(Icon.called("map-pin").of(Color.RED), "Location", coordinates)
|
|
||||||
.toHtml();
|
|
||||||
|
|
||||||
String rightSide = new AccordionElementContentBuilder()
|
|
||||||
.addRowBold(Icons.PLAYER_KILLS, "Player Kills", playerKills)
|
|
||||||
.addRowBold(Icons.MOB_KILLS, "Mob Kills", mobKills)
|
|
||||||
.addRowBold(Icons.DEATHS, "Deaths", deaths)
|
|
||||||
.toHtml();
|
|
||||||
|
|
||||||
addElement(new AccordionElement(htmlID, townName + "<span class=\"pull-right\">" + separated + "</span>")
|
|
||||||
.setColor("brown")
|
|
||||||
.setLeftSide(leftSide)
|
|
||||||
.setRightSide(rightSide));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,134 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.towny;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.api.PlanAPI;
|
|
||||||
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.data.store.keys.AnalysisKeys;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.plan.system.settings.paths.PluginDataSettings;
|
|
||||||
import com.djrapitops.plan.utilities.html.Html;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
|
||||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
|
||||||
import com.palmergames.bukkit.towny.object.Coord;
|
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PluginData for Towny plugin.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class TownyData extends PluginData {
|
|
||||||
|
|
||||||
private final PlanConfig config;
|
|
||||||
|
|
||||||
TownyData(PlanConfig config) {
|
|
||||||
super(ContainerSize.TAB, "Towny");
|
|
||||||
this.config = config;
|
|
||||||
setPluginIcon(Icon.called("university").of(Color.BROWN).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
|
||||||
String playerName = PlanAPI.getInstance().getPlayerName(uuid);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Resident resident = TownyUniverse.getDataSource().getResident(playerName);
|
|
||||||
|
|
||||||
if (resident.hasTown()) {
|
|
||||||
Town town = resident.getTown();
|
|
||||||
String townName = town.getName();
|
|
||||||
String mayorName = town.getMayor().getName();
|
|
||||||
String townMayor = Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(mayorName), mayorName);
|
|
||||||
|
|
||||||
inspectContainer.addValue(getWithIcon("Town", Icon.called("university").of(Color.BROWN)), townName);
|
|
||||||
inspectContainer.addValue(getWithIcon("Town Mayor", Icon.called("user").of(Color.BROWN)), townMayor);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Coord homeBlock = town.getHomeBlock().getCoord();
|
|
||||||
String coordinates = "x: " + homeBlock.getX() + " z: " + homeBlock.getZ();
|
|
||||||
inspectContainer.addValue(getWithIcon("Town Coordinates", Icon.called("map-pin").of(Color.RED)), coordinates);
|
|
||||||
} catch (TownyException ignore) {
|
|
||||||
/* Town has no home block */
|
|
||||||
}
|
|
||||||
|
|
||||||
int residents = town.getResidents().size();
|
|
||||||
inspectContainer.addValue(getWithIcon("Town Residents", Icon.called("users").of(Color.BROWN)), residents);
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
} catch (NotRegisteredException ignore) {
|
|
||||||
/* No Towny Resident. */
|
|
||||||
}
|
|
||||||
inspectContainer.addValue(getWithIcon("Town", Icon.called("bank").of(Color.BROWN)), "No Town");
|
|
||||||
return inspectContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) {
|
|
||||||
List<Town> towns = getTopTowns();
|
|
||||||
|
|
||||||
analysisContainer.addValue(getWithIcon("Number of Towns", Icon.called("university").of(Color.BROWN)), towns.size());
|
|
||||||
|
|
||||||
if (!towns.isEmpty()) {
|
|
||||||
|
|
||||||
Map<UUID, String> userTowns = new HashMap<>();
|
|
||||||
for (Town town : towns) {
|
|
||||||
String townName = town.getName();
|
|
||||||
String mayor = town.getMayor().getName();
|
|
||||||
PlanAPI planAPI = PlanAPI.getInstance();
|
|
||||||
UUID mayorUUID = planAPI.playerNameToUUID(mayor);
|
|
||||||
town.getResidents().stream()
|
|
||||||
.map(Resident::getName)
|
|
||||||
.map(planAPI::playerNameToUUID)
|
|
||||||
.filter(Verify::notNull)
|
|
||||||
.forEach(uuid -> userTowns.put(uuid, uuid.equals(mayorUUID) ? "<b>" + townName + "</b>" : townName));
|
|
||||||
}
|
|
||||||
analysisContainer.addPlayerTableValues(getWithIcon("Town", Icon.called("university")), userTowns);
|
|
||||||
|
|
||||||
TownsAccordion townsAccordion = new TownsAccordion(
|
|
||||||
towns,
|
|
||||||
Optional.ofNullable(analysisData).flatMap(c -> c.getValue(AnalysisKeys.PLAYERS_MUTATOR))
|
|
||||||
.orElse(new PlayersMutator(new ArrayList<>()))
|
|
||||||
);
|
|
||||||
|
|
||||||
analysisContainer.addHtml("townAccordion", townsAccordion.toHtml());
|
|
||||||
}
|
|
||||||
|
|
||||||
return analysisContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Town> getTopTowns() {
|
|
||||||
List<Town> topTowns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
topTowns.sort(new TownComparator());
|
|
||||||
List<String> hide = config.get(PluginDataSettings.HIDE_TOWNS);
|
|
||||||
return topTowns.stream()
|
|
||||||
.filter(town -> !hide.contains(town.getName()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.pluginbridge.plan.towny;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Class responsible for hooking to Towny and registering 2 data sources.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class TownyHook extends Hook {
|
|
||||||
|
|
||||||
private final PlanConfig config;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public TownyHook(
|
|
||||||
PlanConfig config
|
|
||||||
) {
|
|
||||||
super("com.palmergames.bukkit.towny.Towny");
|
|
||||||
this.config = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
|
||||||
if (enabled) {
|
|
||||||
handler.addPluginDataSource(new TownyData(config));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package com.djrapitops.pluginbridge.plan.buycraft;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.connection.ForbiddenException;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for ListPaymentRequest.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ListPaymentRequestTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSuccess() throws IOException, ForbiddenException {
|
|
||||||
new ListPaymentRequest("166473e780b59e84d6a19f1975c9282bfcc7a2a7").makeRequest();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user