diff --git a/PlanPluginBridge/install_dependencies.bat b/PlanPluginBridge/install_dependencies.bat deleted file mode 100644 index 4558c418a..000000000 --- a/PlanPluginBridge/install_dependencies.bat +++ /dev/null @@ -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 \ No newline at end of file diff --git a/PlanPluginBridge/pom.xml b/PlanPluginBridge/pom.xml deleted file mode 100644 index 12c1bc7c4..000000000 --- a/PlanPluginBridge/pom.xml +++ /dev/null @@ -1,210 +0,0 @@ - - - 4.0.0 - com.djrapitops - PlanPluginBridge - 4.9.0-R0.3 - jar - - ${project.groupId}:${project.artifactId} - Artifact for reducing requirements for manually installing artifacts for another project, Plan - - https://github.com/Rsl1122/Plan-PlayerAnalytics/tree/master/PlanPluginBridge - - - - GNU Lesser General Public License v3 (LGPLv3) - https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/LICENSE - - - - - - Risto Lahtela (Rsl1122) - djrapitops@hotmail.com - None - https://github.com/Rsl1122 - - - - - scm:git:git://github.com/Rsl1122/Plan-PlayerAnalytics.git - scm:git:ssh://github.com:Rsl1122/Plan-PlayerAnalytics.git - https://github.com/Rsl1122/Plan-PlayerAnalytics - - - - UTF-8 - 1.8 - 1.8 - - - - - bungeecord-repo - https://oss.sonatype.org/content/repositories/snapshots - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - paper-repo - https://repo.destroystokyo.com/repository/maven-public/ - - - sponge-repo - https://repo.spongepowered.org/maven - - - jitpack.io (GriefPrevention) - https://jitpack.io - - - placeholderapi - http://repo.extendedclip.com/content/repositories/placeholderapi/ - - - - - - com.djrapitops - Plan-plugin - 4.8.7 - provided - - - org.apache.commons - commons-text - 1.8 - - - - - com.destroystokyo.paper - paper-api - 1.12.2-R0.1-SNAPSHOT - provided - - - org.spigotmc - spigot-api - 1.12-R0.1-SNAPSHOT - jar - provided - - - net.md-5 - bungeecord-api - 1.12-SNAPSHOT - jar - provided - - - org.spongepowered - spongeapi - 7.1.0 - jar - provided - - - - com.google.dagger - dagger - 2.24 - - - - - - me.clip - placeholderapi - 2.10.3 - provided - - - me.lucko.luckperms - luckperms-api - 4.4 - provided - - - - - com.massivecraft - factions - 2.14.0 - provided - - - com.massivecraft - mcore - 2.14.0 - provided - - - com.gamingmesh - jobs - 4.13.0 - provided - - - litebans - api - 0.3.1 - provided - - - com.volmit - react - 6.612 - provided - - - com.palmergames - towny - 0.92.0.0 - provided - - - - - ${project.artifactId} - - - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - com.google.dagger - dagger-compiler - 2.16 - - - - - - org.apache.maven.plugins - maven-install-plugin - 2.5.2 - - - org.jacoco - jacoco-maven-plugin - 0.8.4 - - - - - - - bintray-rsl1122-Plan-repository - rsl1122-Plan-repository - https://api.bintray.com/maven/rsl1122/Plan-repository/PlanPluginBridge/;publish=1 - - - \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/AbstractBridge.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/AbstractBridge.java deleted file mode 100644 index 68c06ba63..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/AbstractBridge.java +++ /dev/null @@ -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 . - */ -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(); - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java deleted file mode 100644 index 4b8c84824..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java +++ /dev/null @@ -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); -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/BukkitBridge.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/BukkitBridge.java deleted file mode 100644 index 808e47820..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/BukkitBridge.java +++ /dev/null @@ -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 . - */ -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, - }; - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/BungeeBridge.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/BungeeBridge.java deleted file mode 100644 index 717ed99b0..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/BungeeBridge.java +++ /dev/null @@ -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 . - */ -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, - }; - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/FakeOfflinePlayer.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/FakeOfflinePlayer.java deleted file mode 100644 index 1c02648b2..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/FakeOfflinePlayer.java +++ /dev/null @@ -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 . - */ -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 serialize() { - return new HashMap<>(); - } - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Hook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Hook.java deleted file mode 100644 index 182b2aac5..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Hook.java +++ /dev/null @@ -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 . - */ -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. - *

- * 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; - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/PluginBridgeModule.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/PluginBridgeModule.java deleted file mode 100644 index 51b388bb8..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/PluginBridgeModule.java +++ /dev/null @@ -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 . - */ -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; - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/SpongeBridge.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/SpongeBridge.java deleted file mode 100644 index 3571bdb84..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/SpongeBridge.java +++ /dev/null @@ -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 . - */ -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 - }; - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/VelocityBridge.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/VelocityBridge.java deleted file mode 100644 index 6572d25fb..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/VelocityBridge.java +++ /dev/null @@ -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 . - */ -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 - }; - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/BuyCraftData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/BuyCraftData.java deleted file mode 100644 index 8a4cf8ad3..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/BuyCraftData.java +++ /dev/null @@ -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 . - */ -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 timestampFormatter; - private final Formatter decimalFormatter; - - BuyCraftData( - String secret, - PlanConfig config, Formatter timestampFormatter, - Formatter 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 collection, AnalysisContainer analysisContainer) throws Exception { - try { - - List 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 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("

") + - ""; - - analysisContainer.addHtml("moneygraph", graphHtml); - } - - private void addPaymentTotals(AnalysisContainer analysisContainer, List payments) { - Map 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 entry : paymentTotals.entrySet()) { - analysisContainer.addValue( - getWithIcon("Total " + entry.getKey(), Icon.called("money-bill-wave").of(Color.BLUE)), - decimalFormatter.apply(entry.getValue()) - ); - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/BuyCraftHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/BuyCraftHook.java deleted file mode 100644 index 42ea87272..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/BuyCraftHook.java +++ /dev/null @@ -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 . - */ -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())); - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/ListPaymentRequest.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/ListPaymentRequest.java deleted file mode 100644 index 226d14f61..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/ListPaymentRequest.java +++ /dev/null @@ -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 . - */ -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 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 payments = new ArrayList<>(); - if (json.isJsonObject()) { - return readError(json); - } else if (json.isJsonArray()) { - readAndAddPayments(json, payments); - } - return payments; - } - - private void readAndAddPayments(JsonElement json, List 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("
"); - } - - payments.add(new Payment(amount, currency, null, playerName, date, packages.toString())); - } - } - - private List 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); - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/MoneyStackGraph.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/MoneyStackGraph.java deleted file mode 100644 index 1bd5e3a6a..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/MoneyStackGraph.java +++ /dev/null @@ -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 . - */ -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 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> stacks = getStacks(payments); - - StackDataSet[] dataSets = getDataSets(labels, stacks); - - this.stackGraph = new StackGraph(labels, dataSets); - } - - private StackDataSet[] getDataSets(String[] labels, Map> stacks) { - String[] colors = ThemeVal.GRAPH_GM_PIE.getDefaultValue().split(", "); - int maxCol = colors.length; - - List stackDataSets = new ArrayList<>(); - - int i = 0; - for (Map.Entry> entry : stacks.entrySet()) { - String currency = entry.getKey(); - List payments = entry.getValue(); - - List 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 sortValuesByLabels(String[] labels, Map valueMap) { - List values = new ArrayList<>(); - for (String label : labels) { - values.add(valueMap.getOrDefault(label, 0.0)); - } - return values; - } - - private Map getValueMap(List payments) { - Map 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> getStacks(List payments) { - Map> stacks = new HashMap<>(); - for (Payment payment : payments) { - String currency = payment.getCurrency(); - - List 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 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(); - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/Payment.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/Payment.java deleted file mode 100644 index d045cda75..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/buycraft/Payment.java +++ /dev/null @@ -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 . - */ -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 { - - 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); - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionComparator.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionComparator.java deleted file mode 100644 index 47291c8f3..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionComparator.java +++ /dev/null @@ -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 . - */ -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 { - - @Override - public int compare(Faction fac1, Faction fac2) { - return -Double.compare(fac1.getPower(), fac2.getPower()); - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionsAccordion.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionsAccordion.java deleted file mode 100644 index 0b85701a3..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionsAccordion.java +++ /dev/null @@ -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 . - */ -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 factions; - private final PlayersMutator playersMutator; - - private final Formatter timestampFormatter; - private final Formatter decimalFormatter; - - FactionsAccordion( - List factions, - PlayersMutator playersMutator, - Formatter timestampFormatter, - Formatter 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 members = new HashSet<>(); - List 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 + "" + separated + "") - .setColor("deep-purple") - .setLeftSide(leftSide) - .setRightSide(rightSide) - ); - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionsData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionsData.java deleted file mode 100644 index 3c9f67e67..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionsData.java +++ /dev/null @@ -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 . - */ -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 timestampFormatter; - private final Formatter decimalFormatter; - - FactionsData( - PlanConfig config, - Formatter timestampFormatter, - Formatter 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 uuids, AnalysisContainer analysisContainer) { - List 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 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) ? "" + factionName + "" : factionName); - } - } - - analysisContainer.addPlayerTableValues(getWithIcon("Faction", Icon.called("flag")), userFactions); - } - - return analysisContainer; - } - - private List getTopFactions() { - List topFactions = new ArrayList<>(FactionColl.get().getAll()); - topFactions.remove(FactionColl.get().getWarzone()); - topFactions.remove(FactionColl.get().getSafezone()); - topFactions.remove(FactionColl.get().getNone()); - List hide = config.get(PluginDataSettings.HIDE_FACTIONS); - return topFactions.stream() - .filter(faction -> !hide.contains(faction.getName())) - .sorted(new FactionComparator()) - .collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionsHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionsHook.java deleted file mode 100644 index 9d46588fd..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/factions/FactionsHook.java +++ /dev/null @@ -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 . - */ -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())); - } - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/jobs/JobsData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/jobs/JobsData.java deleted file mode 100644 index 584ba2c34..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/jobs/JobsData.java +++ /dev/null @@ -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 . - */ -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 decimalFormatter; - - JobsData(Formatter 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 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 collection, AnalysisContainer analysisContainer) { - List 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 workers = new HashMap<>(); - Map 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 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; - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/jobs/JobsHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/jobs/JobsHook.java deleted file mode 100644 index 5337c87ee..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/jobs/JobsHook.java +++ /dev/null @@ -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 . - */ -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 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)); - } - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBukkitHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBukkitHook.java deleted file mode 100644 index effb56429..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBukkitHook.java +++ /dev/null @@ -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 . - */ -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 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)); - } - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBungeeHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBungeeHook.java deleted file mode 100644 index c66325825..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBungeeHook.java +++ /dev/null @@ -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 . - */ -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 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)); - } - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDBObj.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDBObj.java deleted file mode 100644 index f48d29f25..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDBObj.java +++ /dev/null @@ -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 . - */ -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; - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java deleted file mode 100644 index 427d2899e..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java +++ /dev/null @@ -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 . - */ -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 timestampFormatter; - - LiteBansData( - LiteBansDatabaseQueries db, - Formatter 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 bans = db.getBans(uuid); - List mutes = db.getMutes(uuid); - List warns = db.getWarnings(uuid); - List 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( - "Ban", - 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( - "Mute", - 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( - "Warning", - 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( - "Kick", - 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 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 objects) { - if (objects.isEmpty()) { - table.addRow("No Data"); - } else { - Map 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 filterBanned(Collection collection) { - try { - Set 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<>(); - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDatabaseQueries.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDatabaseQueries.java deleted file mode 100644 index 51fc09b90..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDatabaseQueries.java +++ /dev/null @@ -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 . - */ -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 query(QueryStatement statement) { - try (PreparedStatement preparedStatement = database.prepareStatement(statement.getSql())) { - return statement.executeQuery(preparedStatement); - } catch (SQLException e) { - throw DBOpException.forCause(statement.getSql(), e); - } - } - - private List getObjs(String table) { - String sql = selectSQL + table + " LIMIT 5000"; - - return query(new QueryAllStatement>(sql, 2000) { - @Override - public List processResults(ResultSet resultSet) throws SQLException { - return processIntoObjects(resultSet); - } - }); - } - - public List getBans() { - return getObjs(banTable); - } - - public List getMutes() { - return getObjs(mutesTable); - } - - public List getWarnings() { - return getObjs(warningsTable); - } - - public List getKicks() { - return getObjs(kicksTable); - } - - private List processIntoObjects(ResultSet set) throws SQLException { - List 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 getBans(UUID playerUUID) { - return getObjs(playerUUID, banTable); - } - - public List getMutes(UUID playerUUID) { - return getObjs(playerUUID, mutesTable); - } - - public List getWarnings(UUID playerUUID) { - return getObjs(playerUUID, warningsTable); - } - - public List getKicks(UUID playerUUID) { - return getObjs(playerUUID, kicksTable); - } - - private List getObjs(UUID playerUUID, String table) { - String sql = selectSQL + table + " WHERE uuid=?"; - - return query(new QueryStatement>(sql, 2000) { - @Override - public void prepare(PreparedStatement statement) throws SQLException { - statement.setString(1, playerUUID.toString()); - } - - @Override - public List processResults(ResultSet resultSet) throws SQLException { - return processIntoObjects(resultSet); - } - }); - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/luckperms/LuckPermsData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/luckperms/LuckPermsData.java deleted file mode 100644 index 646f8e7c9..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/luckperms/LuckPermsData.java +++ /dev/null @@ -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 . - */ -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 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 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 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 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(); - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/luckperms/LuckPermsHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/luckperms/LuckPermsHook.java deleted file mode 100644 index 6637a1d68..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/luckperms/LuckPermsHook.java +++ /dev/null @@ -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 . - */ -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())); - } - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/placeholderapi/PlaceholderAPIHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/placeholderapi/PlaceholderAPIHook.java deleted file mode 100644 index 54e6a449c..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/placeholderapi/PlaceholderAPIHook.java +++ /dev/null @@ -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 . - */ -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) - ); - } - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/placeholderapi/PlanPlaceholders.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/placeholderapi/PlanPlaceholders.java deleted file mode 100644 index add6328b7..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/placeholderapi/PlanPlaceholders.java +++ /dev/null @@ -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 . - */ -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; - } - -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactDataTable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactDataTable.java deleted file mode 100644 index 939c136f7..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactDataTable.java +++ /dev/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 . - */ -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 + ">> getAllData() { - String sql = Select.all(TABLE_NAME).toString(); - - return new QueryAllStatement>>(sql, 50000) { - @Override - public Map> processResults(ResultSet set) throws SQLException { - Map> 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 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; - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactDataTask.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactDataTask.java deleted file mode 100644 index 7879640f3..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactDataTask.java +++ /dev/null @@ -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 . - */ -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> history; - - public ReactDataTask(ReactDataTable table, Processing processing) { - this.table = table; - this.processing = processing; - history = new EnumMap<>(SampledType.class); - } - - @Override - public void run() { - try { - GMap samplers = React.instance.graphController.getG(); - - for (SampledType type : STORED_TYPES) { - processType(samplers, type); - } - } catch (Exception e) { - cancel(); - } - } - - private void processType(GMap samplers, SampledType type) { - GMap values = samplers.get(type).getPlotBoard().getBetween(M.ms() - 10000, M.ms()); - if (values.isEmpty()) { - return; - } - List 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); - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactHook.java deleted file mode 100644 index 139a16548..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactHook.java +++ /dev/null @@ -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 . - */ -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); - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactValue.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactValue.java deleted file mode 100644 index 34c021ca4..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactValue.java +++ /dev/null @@ -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 . - */ -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 { - - 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); - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ValueStoringProcessor.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ValueStoringProcessor.java deleted file mode 100644 index b5f122bf6..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ValueStoringProcessor.java +++ /dev/null @@ -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 . - */ -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 values; - - ValueStoringProcessor(ReactDataTable table, SampledType type, List 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 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); - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownComparator.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownComparator.java deleted file mode 100644 index b0429fb9c..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownComparator.java +++ /dev/null @@ -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 . - */ -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 { - - /** - * 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; - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownsAccordion.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownsAccordion.java deleted file mode 100644 index 3a41e34ae..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownsAccordion.java +++ /dev/null @@ -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 . - */ -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 towns; - private final PlayersMutator playersMutator; - - TownsAccordion(List 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 residents = town.getResidents(); - int residentCount = residents.size(); - long claimedBlocks = town.getTownBlocks().stream().filter(TownBlock::hasTown).count(); - String landCount = claimedBlocks + " / " + town.getTotalBlocks(); - - Set 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 + "" + separated + "") - .setColor("brown") - .setLeftSide(leftSide) - .setRightSide(rightSide)); - } - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownyData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownyData.java deleted file mode 100644 index 73c59541e..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownyData.java +++ /dev/null @@ -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 . - */ -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 collection, AnalysisContainer analysisContainer) { - List towns = getTopTowns(); - - analysisContainer.addValue(getWithIcon("Number of Towns", Icon.called("university").of(Color.BROWN)), towns.size()); - - if (!towns.isEmpty()) { - - Map 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) ? "" + townName + "" : 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 getTopTowns() { - List topTowns = TownyUniverse.getDataSource().getTowns(); - topTowns.sort(new TownComparator()); - List hide = config.get(PluginDataSettings.HIDE_TOWNS); - return topTowns.stream() - .filter(town -> !hide.contains(town.getName())) - .collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownyHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownyHook.java deleted file mode 100644 index d9894c0fa..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/towny/TownyHook.java +++ /dev/null @@ -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 . - */ -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)); - } - } -} diff --git a/PlanPluginBridge/src/test/java/com/djrapitops/pluginbridge/plan/buycraft/ListPaymentRequestTest.java b/PlanPluginBridge/src/test/java/com/djrapitops/pluginbridge/plan/buycraft/ListPaymentRequestTest.java deleted file mode 100644 index e53e8079a..000000000 --- a/PlanPluginBridge/src/test/java/com/djrapitops/pluginbridge/plan/buycraft/ListPaymentRequestTest.java +++ /dev/null @@ -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(); - } -} \ No newline at end of file