Added Bungee PluginData rendering support #571

Added Bungee Plugin Support: AdvancedBan, BuyCraft, LiteBans, ViaVersion
Added Sponge Plugin support: BuyCraft
This commit is contained in:
Rsl1122 2018-08-27 10:33:21 +03:00
parent 5295d56f3c
commit af2eed4d88
17 changed files with 269 additions and 43 deletions

View File

@ -87,10 +87,10 @@
<exclude>org.slf4j.Logger</exclude> <exclude>org.slf4j.Logger</exclude>
</excludes> </excludes>
</relocation> </relocation>
<relocation> <relocation>
<pattern>org.bstats</pattern> <pattern>org.bstats</pattern>
<shadedPattern>com.djrapitops.plan.utilities.metrics</shadedPattern> <shadedPattern>com.djrapitops.plan.utilities.metrics</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
</configuration> </configuration>
</plugin> </plugin>
@ -149,14 +149,14 @@
<id>sponge-repo</id> <id>sponge-repo</id>
<url>https://repo.spongepowered.org/maven</url> <url>https://repo.spongepowered.org/maven</url>
</repository> </repository>
<repository> <repository>
<id>md_5-snapshots</id> <id>md_5-snapshots</id>
<url>http://repo.md-5.net/content/repositories/snapshots/</url> <url>http://repo.md-5.net/content/repositories/snapshots/</url>
</repository> </repository>
<repository> <repository>
<id>bstats-repo</id> <id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url> <url>http://repo.bstats.org/content/repositories/releases/</url>
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
@ -359,12 +359,12 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.imaginarycode.minecraft</groupId> <groupId>com.imaginarycode.minecraft</groupId>
<artifactId>RedisBungee</artifactId> <artifactId>RedisBungee</artifactId>
<version>0.3.8-SNAPSHOT</version> <version>0.3.8-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
@ -388,7 +388,7 @@
<dependency> <dependency>
<groupId>org.xerial</groupId> <groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId> <artifactId>sqlite-jdbc</artifactId>
<version>3.23.1</version> <version>3.23.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -173,4 +173,7 @@ public class NetworkContainer extends DataContainer {
putSupplier(NetworkKeys.PLAYERS_MONTH, () -> getUnsafe(uniqueMonth).count()); putSupplier(NetworkKeys.PLAYERS_MONTH, () -> getUnsafe(uniqueMonth).count());
} }
public ServerContainer getBungeeContainer() {
return bungeeContainer;
}
} }

View File

@ -10,6 +10,7 @@ import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.connection.BungeeConnectionSystem; import com.djrapitops.plan.system.info.connection.BungeeConnectionSystem;
import com.djrapitops.plan.system.info.request.CacheRequest; import com.djrapitops.plan.system.info.request.CacheRequest;
import com.djrapitops.plan.system.info.request.GenerateInspectPageRequest; import com.djrapitops.plan.system.info.request.GenerateInspectPageRequest;
import com.djrapitops.plan.system.info.request.GenerateInspectPluginsTabRequest;
import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.cache.PageId; import com.djrapitops.plan.system.webserver.cache.PageId;
@ -30,8 +31,10 @@ public class BungeeInfoSystem extends InfoSystem {
@Override @Override
public void runLocally(InfoRequest infoRequest) throws WebException { public void runLocally(InfoRequest infoRequest) throws WebException {
if (infoRequest instanceof CacheRequest || if (infoRequest instanceof CacheRequest
infoRequest instanceof GenerateInspectPageRequest) { || infoRequest instanceof GenerateInspectPageRequest
|| infoRequest instanceof GenerateInspectPluginsTabRequest
) {
infoRequest.runLocally(); infoRequest.runLocally();
} else { } else {
// runLocally is called when ConnectionSystem has no servers. // runLocally is called when ConnectionSystem has no servers.

View File

@ -7,6 +7,7 @@ package com.djrapitops.plan.system.info.connection;
import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.connection.NoServersException;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.request.*; import com.djrapitops.plan.system.info.request.*;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
@ -44,7 +45,9 @@ public class BungeeConnectionSystem extends ConnectionSystem {
protected Server selectServerForRequest(InfoRequest infoRequest) throws NoServersException { protected Server selectServerForRequest(InfoRequest infoRequest) throws NoServersException {
refreshServerMap(); refreshServerMap();
Server server = null; Server server = null;
if (infoRequest instanceof CacheRequest || infoRequest instanceof GenerateInspectPageRequest) { if (infoRequest instanceof CacheRequest
|| infoRequest instanceof GenerateInspectPageRequest
|| infoRequest instanceof GenerateInspectPluginsTabRequest) {
// Run locally // Run locally
return ServerInfo.getServer(); return ServerInfo.getServer();
} else if (infoRequest instanceof GenerateAnalysisPageRequest) { } else if (infoRequest instanceof GenerateAnalysisPageRequest) {
@ -66,6 +69,10 @@ public class BungeeConnectionSystem extends ConnectionSystem {
for (Server server : bukkitServers.values()) { for (Server server : bukkitServers.values()) {
WebExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server)); WebExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server));
} }
// Quick hack
if (infoRequest instanceof GenerateInspectPluginsTabRequest) {
WebExceptionLogger.logIfOccurs(this.getClass(), () -> InfoSystem.getInstance().sendRequest(infoRequest));
}
} }
@Override @Override

View File

@ -13,6 +13,7 @@ import com.djrapitops.plan.system.webserver.cache.PageId;
import com.djrapitops.plan.system.webserver.cache.ResponseCache; import com.djrapitops.plan.system.webserver.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.pages.parts.NetworkPageContent; import com.djrapitops.plan.system.webserver.response.pages.parts.NetworkPageContent;
import com.djrapitops.plan.utilities.file.FileUtil; import com.djrapitops.plan.utilities.file.FileUtil;
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
import static com.djrapitops.plan.data.store.keys.NetworkKeys.*; import static com.djrapitops.plan.data.store.keys.NetworkKeys.*;
@ -51,6 +52,13 @@ public class NetworkPage implements Page {
ResponseCache.loadResponse(PageId.NETWORK_CONTENT.id(), NetworkPageContent::new); ResponseCache.loadResponse(PageId.NETWORK_CONTENT.id(), NetworkPageContent::new);
placeholderReplacer.put("tabContentServers", networkPageContent.getContents()); placeholderReplacer.put("tabContentServers", networkPageContent.getContents());
String[] content = AnalysisPluginsTabContentCreator.createContent(networkContainer.getUnsafe(NetworkKeys.PLAYERS_MUTATOR), null);
String nav = content[0];
String tabs = content[1];
placeholderReplacer.put("navPluginsTabs", nav);
placeholderReplacer.put("tabsPlugins", tabs);
return placeholderReplacer.apply(FileUtil.getStringFromResource("web/network.html")); return placeholderReplacer.apply(FileUtil.getStringFromResource("web/network.html"));
} catch (Exception e) { } catch (Exception e) {
throw new ParseException(e); throw new ParseException(e);

View File

@ -148,4 +148,9 @@ Servers:
Example: Example:
WebServerPort: 8034 WebServerPort: 8034
ServerName: Example ServerName: Example
ThemeBase: Default ThemeBase: Default
# -----------------------------------------------------
Plugins:
BuyCraft:
# http://help.buycraft.net/article/36-where-to-find-the-secret-key
Secret: "-"

View File

@ -130,6 +130,15 @@
<span>Network Players</span> <span>Network Players</span>
</a> </a>
</li> </li>
<li>
<a href="javascript:void(0);" class="menu-toggle">
<i class="material-icons">extension</i>
<span>Plugins</span>
</a>
<ul class="ml-menu">
${navPluginsTabs}
</ul>
</li>
</ul> </ul>
</div> </div>
<!-- #Menu --> <!-- #Menu -->
@ -487,6 +496,7 @@
<!-- #END# Geolocations --> <!-- #END# Geolocations -->
</div> </div>
<!-- #END# Tab Geolocations --> <!-- #END# Tab Geolocations -->
${tabsPlugins}
</div> </div>
</div> </div>
</section> </section>

View File

@ -41,6 +41,10 @@
</properties> </properties>
<repositories> <repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
@ -97,7 +101,13 @@
<type>jar</type> <type>jar</type>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.12-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- Plugins from repositories --> <!-- Plugins from repositories -->
<dependency> <dependency>

View File

@ -16,14 +16,16 @@ import com.djrapitops.pluginbridge.plan.griefprevention.GriefPreventionHook;
import com.djrapitops.pluginbridge.plan.griefprevention.plus.GriefPreventionPlusHook; import com.djrapitops.pluginbridge.plan.griefprevention.plus.GriefPreventionPlusHook;
import com.djrapitops.pluginbridge.plan.jobs.JobsHook; import com.djrapitops.pluginbridge.plan.jobs.JobsHook;
import com.djrapitops.pluginbridge.plan.kingdoms.KingdomsHook; import com.djrapitops.pluginbridge.plan.kingdoms.KingdomsHook;
import com.djrapitops.pluginbridge.plan.litebans.LiteBansHook; import com.djrapitops.pluginbridge.plan.litebans.LiteBansBukkitHook;
import com.djrapitops.pluginbridge.plan.litebans.LiteBansBungeeHook;
import com.djrapitops.pluginbridge.plan.mcmmo.McmmoHook; import com.djrapitops.pluginbridge.plan.mcmmo.McmmoHook;
import com.djrapitops.pluginbridge.plan.protocolsupport.ProtocolSupportHook; import com.djrapitops.pluginbridge.plan.protocolsupport.ProtocolSupportHook;
import com.djrapitops.pluginbridge.plan.redprotect.RedProtectHook; import com.djrapitops.pluginbridge.plan.redprotect.RedProtectHook;
import com.djrapitops.pluginbridge.plan.superbvote.SuperbVoteHook; import com.djrapitops.pluginbridge.plan.superbvote.SuperbVoteHook;
import com.djrapitops.pluginbridge.plan.towny.TownyHook; import com.djrapitops.pluginbridge.plan.towny.TownyHook;
import com.djrapitops.pluginbridge.plan.vault.VaultHook; import com.djrapitops.pluginbridge.plan.vault.VaultHook;
import com.djrapitops.pluginbridge.plan.viaversion.ViaVersionHook; import com.djrapitops.pluginbridge.plan.viaversion.ViaVersionBukkitHook;
import com.djrapitops.pluginbridge.plan.viaversion.ViaVersionBungeeHook;
/** /**
* Manages connection to other plugins. * Manages connection to other plugins.
@ -56,17 +58,30 @@ public class Bridge {
private static Hook[] getHooks(HookHandler h) { private static Hook[] getHooks(HookHandler h) {
Hook[] hooks; Hook[] hooks;
if (Check.isBukkitAvailable()) { if (Check.isBungeeAvailable()) {
hooks = getBukkitHooks(h);
} else {
hooks = getBungeeHooks(h); hooks = getBungeeHooks(h);
} else if (Check.isBukkitAvailable()) {
hooks = getBukkitHooks(h);
} else if (Check.isSpongeAvailable()) {
hooks = getSpongeHooks(h);
} else {
return new Hook[0];
} }
return hooks; return hooks;
} }
private static Hook[] getSpongeHooks(HookHandler h) {
return new Hook[]{
new BuyCraftHook(h)
};
}
private static Hook[] getBungeeHooks(HookHandler h) { private static Hook[] getBungeeHooks(HookHandler h) {
return new Hook[]{ return new Hook[]{
new AdvancedBanHook(h) new AdvancedBanHook(h),
new BuyCraftHook(h),
new LiteBansBungeeHook(h),
new ViaVersionBungeeHook(h)
}; };
} }
@ -84,7 +99,7 @@ public class Bridge {
new GriefPreventionPlusHook(h), new GriefPreventionPlusHook(h),
new JobsHook(h), new JobsHook(h),
new KingdomsHook(h), new KingdomsHook(h),
new LiteBansHook(h), new LiteBansBukkitHook(h),
new McmmoHook(h), new McmmoHook(h),
new SuperbVoteHook(h), new SuperbVoteHook(h),
new ProtocolSupportHook(h), new ProtocolSupportHook(h),
@ -92,7 +107,7 @@ public class Bridge {
new RedProtectHook(h), new RedProtectHook(h),
new TownyHook(h), new TownyHook(h),
new VaultHook(h), new VaultHook(h),
new ViaVersionHook(h)//, new ViaVersionBukkitHook(h)//,
// new PlaceholderAPIHook(h) // new PlaceholderAPIHook(h)
}; };
} }

View File

@ -5,6 +5,7 @@ import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.pluginbridge.plan.Hook; import com.djrapitops.pluginbridge.plan.Hook;
import litebans.api.Database; import litebans.api.Database;
import org.bukkit.Bukkit;
/** /**
* A Class responsible for hooking to LiteBans and registering data * A Class responsible for hooking to LiteBans and registering data
@ -13,7 +14,7 @@ import litebans.api.Database;
* @author Rsl1122 * @author Rsl1122
* @since 3.5.0 * @since 3.5.0
*/ */
public class LiteBansHook extends Hook { public class LiteBansBukkitHook extends Hook {
/** /**
* Hooks the plugin and registers it's PluginData objects. * Hooks the plugin and registers it's PluginData objects.
@ -24,7 +25,7 @@ public class LiteBansHook extends Hook {
* @throws NoClassDefFoundError when the plugin class can not be found. * @throws NoClassDefFoundError when the plugin class can not be found.
*/ */
@SuppressWarnings("ResultOfMethodCallIgnored") @SuppressWarnings("ResultOfMethodCallIgnored")
public LiteBansHook(HookHandler hookH) { public LiteBansBukkitHook(HookHandler hookH) {
super(hookH); super(hookH);
try { try {
Database.get(); Database.get();
@ -39,7 +40,8 @@ public class LiteBansHook extends Hook {
public void hook() throws NoClassDefFoundError { public void hook() throws NoClassDefFoundError {
if (enabled) { if (enabled) {
LiteBansDatabaseQueries db = new LiteBansDatabaseQueries(); String tablePrefix = Bukkit.getPluginManager().getPlugin("LiteBans").getConfig().getString("sql.table_prefix");
LiteBansDatabaseQueries db = new LiteBansDatabaseQueries(tablePrefix);
addPluginDataSource(new LiteBansData(db)); addPluginDataSource(new LiteBansData(db));
} }
} }

View File

@ -0,0 +1,69 @@
package com.djrapitops.pluginbridge.plan.litebans;
import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.pluginbridge.plan.Hook;
import litebans.api.Database;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A Class responsible for hooking to LiteBans and registering data
* sources.
*
* @author Rsl1122
* @since 3.5.0
*/
public class LiteBansBungeeHook extends Hook {
/**
* Hooks the plugin and registers it's PluginData objects.
* <p>
* API#addPluginDataSource uses the same method from HookHandler.
*
* @param hookH HookHandler instance for registering the data sources.
* @throws NoClassDefFoundError when the plugin class can not be found.
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
public LiteBansBungeeHook(HookHandler hookH) {
super(hookH);
try {
Database.get();
enabled = true;
} catch (NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError | Exception e) {
if (Settings.DEV_MODE.isTrue()) {
Log.toLog(this.getClass(), e);
}
enabled = false;
}
}
public void hook() throws NoClassDefFoundError {
if (enabled) {
LiteBansDatabaseQueries db = new LiteBansDatabaseQueries(getTablePrefix());
addPluginDataSource(new LiteBansData(db));
}
}
private String getTablePrefix() {
String tablePrefix = "libeans_";
try {
File litebansDataFolder = ProxyServer.getInstance().getPluginManager().getPlugin("LiteBans").getDataFolder();
File configFile = new File(litebansDataFolder, "config.yml");
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
tablePrefix = configuration.getString("sql.table_prefix");
} catch (NullPointerException | IOException e) {
Logger.getLogger("Plan").log(Level.WARNING, "Could not get Litebans table prefix, using default (litebans_). " + e.toString());
}
return tablePrefix;
}
}

View File

@ -5,7 +5,6 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStat
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement; import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
import com.djrapitops.plan.system.database.databases.sql.tables.Table; import com.djrapitops.plan.system.database.databases.sql.tables.Table;
import litebans.api.Database; import litebans.api.Database;
import org.bukkit.Bukkit;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -30,10 +29,9 @@ public class LiteBansDatabaseQueries extends Table {
private final String selectSQL; private final String selectSQL;
public LiteBansDatabaseQueries() { public LiteBansDatabaseQueries(String tablePrefix) {
super("litebans", null); super("litebans", null);
database = Database.get(); database = Database.get();
String tablePrefix = Bukkit.getPluginManager().getPlugin("LiteBans").getConfig().getString("sql.table_prefix");
banTable = tablePrefix + "bans"; banTable = tablePrefix + "bans";
mutesTable = tablePrefix + "mutes"; mutesTable = tablePrefix + "mutes";
warningsTable = tablePrefix + "warnings"; warningsTable = tablePrefix + "warnings";

View File

@ -24,11 +24,11 @@ import java.util.UUID;
* @author Rsl1122 * @author Rsl1122
* @since 3.5.0 * @since 3.5.0
*/ */
public class PlayerVersionListener implements Listener { public class BukkitPlayerVersionListener implements Listener {
private ViaAPI viaAPI; private ViaAPI viaAPI;
public PlayerVersionListener(ViaAPI viaAPI) { public BukkitPlayerVersionListener(ViaAPI viaAPI) {
this.viaAPI = viaAPI; this.viaAPI = viaAPI;
} }

View File

@ -0,0 +1,46 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.djrapitops.pluginbridge.plan.viaversion;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plugin.api.utility.log.Log;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import us.myles.ViaVersion.api.ViaAPI;
import java.util.UUID;
/**
* Class responsible for listening join events for Version protocol.
*
* @author Rsl1122
* @since 3.5.0
*/
public class BungeePlayerVersionListener implements Listener {
private ViaAPI viaAPI;
public BungeePlayerVersionListener(ViaAPI viaAPI) {
this.viaAPI = viaAPI;
}
@EventHandler
public void onJoin(PostLoginEvent event) {
UUID uuid = event.getPlayer().getUniqueId();
int playerVersion = viaAPI.getPlayerVersion(uuid);
Processing.submitNonCritical(() -> {
try {
new ProtocolTable((SQLDB) Database.getActive()).saveProtocolVersion(uuid, playerVersion);
} catch (DBOpException e) {
Log.toLog(this.getClass(), e);
}
});
}
}

View File

@ -25,6 +25,8 @@ public class Protocol {
*/ */
public static String getMCVersion(int protocolVersion) { public static String getMCVersion(int protocolVersion) {
switch (protocolVersion) { switch (protocolVersion) {
case 401:
return "1.13.1";
case 390: case 390:
case 391: case 391:
case 392: case 392:

View File

@ -16,7 +16,7 @@ import us.myles.ViaVersion.api.ViaAPI;
* @author Rsl1122 * @author Rsl1122
* @since 3.1.0 * @since 3.1.0
*/ */
public class ViaVersionHook extends Hook { public class ViaVersionBukkitHook extends Hook {
/** /**
* Hooks the plugin and registers it's PluginData objects. * Hooks the plugin and registers it's PluginData objects.
@ -25,7 +25,7 @@ public class ViaVersionHook extends Hook {
* *
* @param hookH HookHandler instance for registering the data sources. * @param hookH HookHandler instance for registering the data sources.
*/ */
public ViaVersionHook(HookHandler hookH) { public ViaVersionBukkitHook(HookHandler hookH) {
super("us.myles.ViaVersion.ViaVersionPlugin", hookH); super("us.myles.ViaVersion.ViaVersionPlugin", hookH);
} }
@ -42,7 +42,7 @@ public class ViaVersionHook extends Hook {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
return; return;
} }
plan.registerListener(new PlayerVersionListener(api)); plan.registerListener(new BukkitPlayerVersionListener(api));
addPluginDataSource(new ViaVersionData(table)); addPluginDataSource(new ViaVersionData(table));
} }
} }

View File

@ -0,0 +1,48 @@
package com.djrapitops.pluginbridge.plan.viaversion;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.pluginbridge.plan.Hook;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI;
/**
* A Class responsible for hooking to ViaVersion and registering data sources.
*
* @author Rsl1122
* @since 3.1.0
*/
public class ViaVersionBungeeHook extends Hook {
/**
* Hooks the plugin and registers it's PluginData objects.
* <p>
* API#addPluginDataSource uses the same method from HookHandler.
*
* @param hookH HookHandler instance for registering the data sources.
*/
public ViaVersionBungeeHook(HookHandler hookH) {
super("us.myles.ViaVersion.BungeePlugin", hookH);
}
public void hook() throws NoClassDefFoundError {
if (!enabled) {
return;
}
PlanBungee plan = PlanBungee.getInstance();
ViaAPI api = Via.getAPI();
ProtocolTable table = new ProtocolTable((SQLDB) Database.getActive());
try {
table.createTable();
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
return;
}
plan.registerListener(new BungeePlayerVersionListener(api));
addPluginDataSource(new ViaVersionData(table));
}
}