mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-02 21:41:28 +01:00
Fixed pluginbridge
- AAC SQL stuff - ViaVersion & ProtocolSupport SQL stuff - Litebans SQL stuff - PlaceholderAPIHook (unfinished) SQL stuff - Towny & Vault DataCache stuff - Removed since javadoc tags - Bridge Version bump to 4.7.0
This commit is contained in:
parent
acae1c4b3d
commit
530c4a2ea6
@ -12,7 +12,7 @@ allprojects {
|
||||
wrapper.gradleVersion = "5.0"
|
||||
|
||||
group "com.djrapitops"
|
||||
version "4.6.2-SNAPSHOT"
|
||||
version "4.7.0-SNAPSHOT"
|
||||
|
||||
test {
|
||||
// useJUnitPlatform()
|
||||
|
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>PlanPluginBridge</artifactId>
|
||||
<version>4.6.2</version>
|
||||
<version>4.7.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.groupId}:${project.artifactId}</name>
|
||||
@ -58,8 +58,8 @@
|
||||
<url>https://repo.spongepowered.org/maven</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
<id>vault-repo</id> <!-- Essentials build repository since Vault repo goes down often. -->
|
||||
<url>https://ci.ender.zone/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io (GriefPrevention)</id>
|
||||
@ -95,7 +95,7 @@
|
||||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>Plan-plugin</artifactId>
|
||||
<version>4.6.1-SNAPSHOT</version>
|
||||
<version>4.7.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -23,7 +23,7 @@ import com.djrapitops.plugin.api.Check;
|
||||
* Abstract class for easy hooking of plugins.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 2.6.0
|
||||
|
||||
*/
|
||||
public abstract class Hook {
|
||||
|
||||
|
@ -21,6 +21,7 @@ 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.db.Database;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
||||
import com.djrapitops.plan.utilities.html.icon.Family;
|
||||
@ -40,19 +41,19 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
class AdvancedAntiCheatData extends PluginData {
|
||||
|
||||
private final HackerTable table;
|
||||
private final Database database;
|
||||
private final Formatter<Long> timestampFormatter;
|
||||
|
||||
AdvancedAntiCheatData(HackerTable table, Formatter<Long> timestampFormatter) {
|
||||
AdvancedAntiCheatData(Database database, Formatter<Long> timestampFormatter) {
|
||||
super(ContainerSize.THIRD, "AdvancedAntiCheat");
|
||||
this.timestampFormatter = timestampFormatter;
|
||||
super.setPluginIcon(Icon.called("heart").of(Color.RED).build());
|
||||
this.table = table;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
||||
List<HackObject> hackObjects = table.getHackObjects(uuid);
|
||||
List<HackObject> hackObjects = database.query(HackerTable.getHackObjects(uuid));
|
||||
|
||||
inspectContainer.addValue(
|
||||
getWithIcon("Times Kicked for Possible Hacking", Icon.called("exclamation-triangle").of(Color.RED)),
|
||||
@ -78,7 +79,7 @@ class AdvancedAntiCheatData extends PluginData {
|
||||
|
||||
@Override
|
||||
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) {
|
||||
Map<UUID, List<HackObject>> hackObjects = table.getHackObjects();
|
||||
Map<UUID, List<HackObject>> hackObjects = database.query(HackerTable.getHackObjects());
|
||||
|
||||
Map<UUID, Integer> violations = hackObjects.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().size()));
|
||||
|
@ -17,12 +17,10 @@
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
|
||||
@ -38,20 +36,17 @@ import javax.inject.Singleton;
|
||||
public class AdvancedAntiCheatHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final Formatters formatters;
|
||||
|
||||
@Inject
|
||||
public AdvancedAntiCheatHook(
|
||||
Plan plugin,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
Formatters formatters
|
||||
) {
|
||||
super("me.konsolas.aac.AAC");
|
||||
this.plugin = plugin;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
this.formatters = formatters;
|
||||
}
|
||||
@ -62,14 +57,15 @@ public class AdvancedAntiCheatHook extends Hook {
|
||||
return;
|
||||
}
|
||||
|
||||
HackerTable hackerTable = new HackerTable((SQLDB) dbSystem.getDatabase());
|
||||
try {
|
||||
hackerTable.createTable();
|
||||
} catch (DBInitException e) {
|
||||
throw new DBOpException("Failed to create AAC database table", e);
|
||||
}
|
||||
Database database = dbSystem.getDatabase();
|
||||
database.executeTransaction(new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(HackerTable.createTableSQL(database.getType()));
|
||||
}
|
||||
});
|
||||
|
||||
plugin.registerListener(new PlayerHackKickListener(hackerTable, processing));
|
||||
hookHandler.addPluginDataSource(new AdvancedAntiCheatData(hackerTable, formatters.yearLong()));
|
||||
plugin.registerListener(new PlayerHackKickListener(database));
|
||||
hookHandler.addPluginDataSource(new AdvancedAntiCheatData(database, formatters.yearLong()));
|
||||
}
|
||||
}
|
@ -16,13 +16,13 @@
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.Table;
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Select;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -30,41 +30,36 @@ import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class responsible for AAC kick information in Plan database.
|
||||
* Table information about 'plan_aac_hack_table'.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class HackerTable extends Table {
|
||||
public class HackerTable {
|
||||
|
||||
private final String columnUUID;
|
||||
private final String columnDate;
|
||||
private final String columnHackType;
|
||||
private final String columnViolations;
|
||||
public static final String TABLE_NAME = "plan_aac_hack_table";
|
||||
public static final String COL_ID = "id";
|
||||
public static final String COL_UUID = "uuid";
|
||||
public static final String COL_DATE = "date";
|
||||
public static final String COL_HACK_TYPE = "hack_type";
|
||||
public static final String COL_VIOLATION_LEVEL = "violation_level";
|
||||
|
||||
public HackerTable(SQLDB db) {
|
||||
super("plan_aac_hack_table", db);
|
||||
columnUUID = "uuid";
|
||||
columnDate = "date";
|
||||
columnHackType = "hack_type";
|
||||
columnViolations = "violation_level";
|
||||
private HackerTable() {
|
||||
/* Static information class */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTable() throws DBInitException {
|
||||
createTable("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
+ columnUUID + " varchar(36) NOT NULL, "
|
||||
+ columnDate + " bigint NOT NULL, "
|
||||
+ columnHackType + " varchar(100) NOT NULL, "
|
||||
+ columnViolations + " integer NOT NULL"
|
||||
+ ")"
|
||||
);
|
||||
public static String createTableSQL(DBType dbType) {
|
||||
return CreateTableParser.create(TABLE_NAME, dbType)
|
||||
.column(COL_ID, Sql.INT).primaryKey()
|
||||
.column(COL_UUID, Sql.varchar(36)).notNull()
|
||||
.column(COL_HACK_TYPE, Sql.varchar(100)).notNull()
|
||||
.column(COL_VIOLATION_LEVEL, Sql.INT).notNull()
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<HackObject> getHackObjects(UUID uuid) {
|
||||
String sql = "SELECT * FROM " + tableName + " WHERE " + columnUUID + "=?";
|
||||
public static Query<List<HackObject>> getHackObjects(UUID uuid) {
|
||||
String sql = "SELECT * FROM " + TABLE_NAME + " WHERE " + COL_UUID + "=?";
|
||||
|
||||
return query(new QueryStatement<List<HackObject>>(sql) {
|
||||
return new QueryStatement<List<HackObject>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, uuid.toString());
|
||||
@ -74,52 +69,33 @@ public class HackerTable extends Table {
|
||||
public List<HackObject> processResults(ResultSet set) throws SQLException {
|
||||
List<HackObject> hackObjects = new ArrayList<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(columnUUID));
|
||||
long date = set.getLong(columnDate);
|
||||
String hackType = set.getString(columnHackType);
|
||||
int violationLevel = set.getInt(columnViolations);
|
||||
UUID uuid = UUID.fromString(set.getString(COL_UUID));
|
||||
long date = set.getLong(COL_DATE);
|
||||
String hackType = set.getString(COL_HACK_TYPE);
|
||||
int violationLevel = set.getInt(COL_VIOLATION_LEVEL);
|
||||
hackObjects.add(new HackObject(uuid, date, hackType, violationLevel));
|
||||
}
|
||||
return hackObjects;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public Map<UUID, List<HackObject>> getHackObjects() {
|
||||
return query(new QueryAllStatement<Map<UUID, List<HackObject>>>(Select.all(tableName).toString(), 5000) {
|
||||
public static Query<Map<UUID, List<HackObject>>> getHackObjects() {
|
||||
return new QueryAllStatement<Map<UUID, List<HackObject>>>(Select.all(TABLE_NAME).toString(), 5000) {
|
||||
@Override
|
||||
public Map<UUID, List<HackObject>> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<HackObject>> hackObjects = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(columnUUID));
|
||||
long date = set.getLong(columnDate);
|
||||
String hackType = set.getString(columnHackType);
|
||||
int violationLevel = set.getInt(columnViolations);
|
||||
UUID uuid = UUID.fromString(set.getString(COL_UUID));
|
||||
long date = set.getLong(COL_DATE);
|
||||
String hackType = set.getString(COL_HACK_TYPE);
|
||||
int violationLevel = set.getInt(COL_VIOLATION_LEVEL);
|
||||
List<HackObject> list = hackObjects.getOrDefault(uuid, new ArrayList<>());
|
||||
list.add(new HackObject(uuid, date, hackType, violationLevel));
|
||||
hackObjects.put(uuid, list);
|
||||
}
|
||||
return hackObjects;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void insertHackRow(HackObject hackObject) {
|
||||
String sql = "INSERT INTO " + tableName + " ("
|
||||
+ columnUUID + ", "
|
||||
+ columnDate + ", "
|
||||
+ columnHackType + ", "
|
||||
+ columnViolations
|
||||
+ ") VALUES (?, ?, ?, ?)";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, hackObject.getUuid().toString());
|
||||
statement.setLong(2, hackObject.getDate());
|
||||
statement.setString(3, hackObject.getHackType());
|
||||
statement.setInt(4, hackObject.getViolationLevel());
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import me.konsolas.aac.api.AACAPIProvider;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.api.PlayerViolationCommandEvent;
|
||||
@ -31,16 +31,13 @@ import java.util.UUID;
|
||||
* Class responsible for listening kick events made by AAC.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public class PlayerHackKickListener implements Listener {
|
||||
|
||||
private final HackerTable hackerTable;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
|
||||
PlayerHackKickListener(HackerTable hackerTable, Processing processing) {
|
||||
this.hackerTable = hackerTable;
|
||||
this.processing = processing;
|
||||
PlayerHackKickListener(Database database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@ -58,6 +55,6 @@ public class PlayerHackKickListener implements Listener {
|
||||
|
||||
HackObject hackObject = new HackObject(uuid, time, hackTypeName, violations);
|
||||
|
||||
processing.submitNonCritical(() -> hackerTable.insertHackRow(hackObject));
|
||||
database.executeTransaction(new StoreHackViolationKickTransaction(hackObject));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
import com.djrapitops.plan.db.access.ExecStatement;
|
||||
import com.djrapitops.plan.db.access.Executable;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static com.djrapitops.pluginbridge.plan.aac.HackerTable.*;
|
||||
|
||||
/**
|
||||
* Transaction to store kick information when AAC kicks a player for hacking.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StoreHackViolationKickTransaction extends Transaction {
|
||||
|
||||
private final HackObject info;
|
||||
|
||||
public StoreHackViolationKickTransaction(HackObject info) {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(storeViolationKick());
|
||||
}
|
||||
|
||||
private Executable storeViolationKick() {
|
||||
String sql = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ COL_UUID + ", "
|
||||
+ COL_DATE + ", "
|
||||
+ COL_HACK_TYPE + ", "
|
||||
+ COL_VIOLATION_LEVEL
|
||||
+ ") VALUES (?, ?, ?, ?)";
|
||||
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, info.getUuid().toString());
|
||||
statement.setLong(2, info.getDate());
|
||||
statement.setString(3, info.getHackType());
|
||||
statement.setInt(4, info.getViolationLevel());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ import java.util.Optional;
|
||||
* data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.1.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class AdvancedAchievementsHook extends Hook {
|
||||
|
@ -29,7 +29,7 @@ import javax.inject.Singleton;
|
||||
* A Class responsible for hooking to ASkyBlock and registering data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class ASkyBlockHook extends Hook {
|
||||
|
@ -29,7 +29,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
* A Class responsible for hooking to Essentials.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.1.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class EssentialsHook extends Hook {
|
||||
|
@ -28,7 +28,7 @@ import java.util.Comparator;
|
||||
* Note: this comparator imposes orderings that are inconsistent with equals.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.1.0
|
||||
|
||||
* @see FactionsHook
|
||||
*/
|
||||
public class FactionComparator implements Comparator<Faction> {
|
||||
|
@ -28,7 +28,7 @@ import javax.inject.Singleton;
|
||||
* A Class responsible for hooking to Factions and registering 4 data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.1.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class FactionsHook extends Hook {
|
||||
|
@ -32,7 +32,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
* sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class GriefPreventionHook extends Hook {
|
||||
|
@ -31,7 +31,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
* sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class GriefPreventionPlusHook extends Hook {
|
||||
|
@ -28,7 +28,7 @@ import javax.inject.Singleton;
|
||||
* A Class responsible for hooking to Jobs and registering data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.2.1
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class JobsHook extends Hook {
|
||||
|
@ -30,7 +30,7 @@ import javax.inject.Singleton;
|
||||
* sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class LiteBansBukkitHook extends Hook {
|
||||
|
@ -30,7 +30,7 @@ import javax.inject.Singleton;
|
||||
* sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class LiteBansBungeeHook extends Hook {
|
||||
|
@ -17,9 +17,8 @@
|
||||
package com.djrapitops.pluginbridge.plan.litebans;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.Table;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import litebans.api.Database;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -33,9 +32,8 @@ import java.util.UUID;
|
||||
* Class responsible for making queries to LiteBans database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class LiteBansDatabaseQueries extends Table {
|
||||
public class LiteBansDatabaseQueries {
|
||||
private final Database database;
|
||||
|
||||
private final String banTable;
|
||||
@ -46,7 +44,6 @@ public class LiteBansDatabaseQueries extends Table {
|
||||
private final String selectSQL;
|
||||
|
||||
public LiteBansDatabaseQueries() {
|
||||
super("litebans", null);
|
||||
database = Database.get();
|
||||
banTable = "{bans}";
|
||||
mutesTable = "{mutes}";
|
||||
@ -55,7 +52,6 @@ public class LiteBansDatabaseQueries extends Table {
|
||||
selectSQL = "SELECT uuid, reason, banned_by_name, until, active, time FROM ";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T query(QueryStatement<T> statement) {
|
||||
try (PreparedStatement preparedStatement = database.prepareStatement(statement.getSql())) {
|
||||
return statement.executeQuery(preparedStatement);
|
||||
@ -145,9 +141,4 @@ public class LiteBansDatabaseQueries extends Table {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTable() {
|
||||
throw new IllegalStateException("Not Supposed to be called.");
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import javax.inject.Singleton;
|
||||
* A Class responsible for hooking to MCMMO and registering data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.2.1
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class McmmoHook extends Hook {
|
||||
|
@ -71,7 +71,7 @@ public class PlaceholderAPIHook extends Hook {
|
||||
if (enabled) {
|
||||
PlaceholderAPI.unregisterPlaceholderHook("plan");
|
||||
PlaceholderAPI.registerPlaceholderHook("plan",
|
||||
new PlanPlaceholders(plugin, config, dbSystem, serverInfo, webServer, formatters, errorHandler)
|
||||
new PlanPlaceholders(plugin, config, serverInfo, webServer, formatters, errorHandler)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,16 @@
|
||||
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.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.containers.ServerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.*;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
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;
|
||||
@ -37,6 +41,7 @@ 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;
|
||||
|
||||
@ -50,7 +55,6 @@ public class PlanPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
private final PlanPlugin plugin;
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final WebServer webServer;
|
||||
private final Formatters formatters;
|
||||
@ -59,7 +63,6 @@ public class PlanPlaceholders extends PlaceholderExpansion {
|
||||
public PlanPlaceholders(
|
||||
PlanPlugin plugin,
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
WebServer webServer,
|
||||
Formatters formatters,
|
||||
@ -67,7 +70,6 @@ public class PlanPlaceholders extends PlaceholderExpansion {
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.webServer = webServer;
|
||||
this.formatters = formatters;
|
||||
@ -125,7 +127,7 @@ public class PlanPlaceholders extends PlaceholderExpansion {
|
||||
}
|
||||
|
||||
private Serializable getServerValue(String identifier) {
|
||||
ServerContainer serverContainer = dbSystem.getDatabase().fetch().getServerContainer(serverInfo.getServerUUID());
|
||||
ServerContainer serverContainer = PlanAPI.getInstance().fetchServerContainer(serverInfo.getServerUUID());
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long dayAgo = now - TimeUnit.DAYS.toMillis(1L);
|
||||
@ -133,7 +135,7 @@ public class PlanPlaceholders extends PlaceholderExpansion {
|
||||
long monthAgo = now - TimeAmount.MONTH.toMillis(1L);
|
||||
|
||||
try {
|
||||
PlayersMutator playersMutator = PlayersMutator.forContainer(serverContainer);
|
||||
PlayersMutator playersMutator = new PlayersMutator(serverContainer.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>()));
|
||||
switch (identifier.toLowerCase()) {
|
||||
case "players_total":
|
||||
return playersMutator.count();
|
||||
@ -162,9 +164,9 @@ public class PlanPlaceholders extends PlaceholderExpansion {
|
||||
case "deaths_total":
|
||||
return new SessionsMutator(playersMutator.getSessions()).toDeathCount();
|
||||
case "tps_day":
|
||||
return TPSMutator.forContainer(serverContainer).filterDataBetween(dayAgo, now).averageTPS();
|
||||
return new TPSMutator(serverContainer.getValue(ServerKeys.TPS).orElse(new ArrayList<>())).filterDataBetween(dayAgo, now).averageTPS();
|
||||
case "tps_drops_week":
|
||||
return TPSMutator.forContainer(serverContainer).filterDataBetween(weekAgo, now)
|
||||
return new TPSMutator(serverContainer.getValue(ServerKeys.TPS).orElse(new ArrayList<>())).filterDataBetween(weekAgo, now)
|
||||
.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED));
|
||||
default:
|
||||
break;
|
||||
@ -177,7 +179,7 @@ public class PlanPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
private Serializable getPlayerValue(Player player, String identifier) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
PlayerContainer playerContainer = dbSystem.getDatabase().fetch().getPlayerContainer(uuid);
|
||||
PlayerContainer playerContainer = PlanAPI.getInstance().fetchPlayerContainer(uuid);
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long dayAgo = now - TimeUnit.DAYS.toMillis(1L);
|
||||
@ -185,7 +187,7 @@ public class PlanPlaceholders extends PlaceholderExpansion {
|
||||
long monthAgo = now - TimeAmount.MONTH.toMillis(1L);
|
||||
|
||||
try {
|
||||
SessionsMutator sessionsMutator = SessionsMutator.forContainer(playerContainer);
|
||||
SessionsMutator sessionsMutator = new SessionsMutator(playerContainer.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>()));
|
||||
switch (identifier.toLowerCase()) {
|
||||
case "playtime":
|
||||
return formatters.timeAmount().apply(sessionsMutator.toPlaytime());
|
||||
@ -196,14 +198,14 @@ public class PlanPlaceholders extends PlaceholderExpansion {
|
||||
case "playtime_month":
|
||||
return formatters.timeAmount().apply(sessionsMutator.filterSessionsBetween(monthAgo, now).toPlaytime());
|
||||
case "geolocation":
|
||||
return GeoInfoMutator.forContainer(playerContainer).mostRecent().map(GeoInfo::getGeolocation).orElse("Unknown");
|
||||
return new GeoInfoMutator(playerContainer.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>())).mostRecent().map(GeoInfo::getGeolocation).orElse("Unknown");
|
||||
case "activity_index":
|
||||
ActivityIndex activityIndex = playerContainer.getActivityIndex(
|
||||
double activityIndex = playerContainer.getActivityIndex(
|
||||
now,
|
||||
config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD),
|
||||
config.get(TimeSettings.ACTIVE_LOGIN_THRESHOLD)
|
||||
);
|
||||
return activityIndex.getValue() + " (" + activityIndex.getGroup() + ")";
|
||||
return activityIndex;
|
||||
case "registered":
|
||||
return formatters.yearLong().apply(playerContainer.getValue(PlayerKeys.REGISTERED).orElse(0L));
|
||||
case "last_seen":
|
||||
|
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.protocolsupport;
|
||||
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.pluginbridge.plan.viaversion.ProtocolTable;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.pluginbridge.plan.viaversion.StoreUsedProtocolTransaction;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -26,29 +26,19 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import protocolsupport.api.ProtocolSupportAPI;
|
||||
import protocolsupport.api.ProtocolVersion;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Class responsible for listening join events for Version protocol.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 4.1.0
|
||||
*/
|
||||
@Singleton
|
||||
public class PlayerVersionListener implements Listener {
|
||||
|
||||
private final Processing processing;
|
||||
private final ProtocolTable protocolTable;
|
||||
private final Database database;
|
||||
|
||||
@Inject
|
||||
public PlayerVersionListener(
|
||||
Processing processing,
|
||||
ProtocolTable protocolTable
|
||||
) {
|
||||
this.processing = processing;
|
||||
this.protocolTable = protocolTable;
|
||||
public PlayerVersionListener(Database database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@ -57,6 +47,6 @@ public class PlayerVersionListener implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
ProtocolVersion protocolVersion = ProtocolSupportAPI.getProtocolVersion(player);
|
||||
int playerVersion = protocolVersion.getId();
|
||||
processing.submitNonCritical(() -> protocolTable.saveProtocolVersion(uuid, playerVersion));
|
||||
database.executeTransaction(new StoreUsedProtocolTransaction(uuid, playerVersion));
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ 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.db.Database;
|
||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
import com.djrapitops.pluginbridge.plan.viaversion.Protocol;
|
||||
@ -40,18 +41,18 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
class ProtocolSupportData extends PluginData {
|
||||
|
||||
private final ProtocolTable table;
|
||||
private final Database database;
|
||||
|
||||
ProtocolSupportData(ProtocolTable table) {
|
||||
ProtocolSupportData(Database database) {
|
||||
super(ContainerSize.THIRD, "ProtocolSupport");
|
||||
setPluginIcon(Icon.called("gamepad").of(Color.CYAN).build());
|
||||
this.table = table;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
||||
try {
|
||||
int protocolVersion = table.getProtocolVersion(uuid);
|
||||
int protocolVersion = database.query(ProtocolTable.getProtocolVersion(uuid));
|
||||
|
||||
inspectContainer.addValue(getWithIcon("Last Join Version", Icon.called("signal").of(Color.CYAN)),
|
||||
protocolVersion != -1 ? Protocol.getMCVersion(protocolVersion) : "Not Yet Known");
|
||||
@ -67,7 +68,7 @@ class ProtocolSupportData extends PluginData {
|
||||
Map<UUID, Integer> versions;
|
||||
|
||||
try {
|
||||
versions = table.getProtocolVersions();
|
||||
versions = database.query(ProtocolTable.getProtocolVersions());
|
||||
} catch (DBOpException ex) {
|
||||
analysisContainer.addValue("Error", ex.toString());
|
||||
return analysisContainer;
|
||||
|
@ -17,12 +17,10 @@
|
||||
package com.djrapitops.pluginbridge.plan.protocolsupport;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
import com.djrapitops.pluginbridge.plan.viaversion.ProtocolTable;
|
||||
|
||||
@ -38,18 +36,15 @@ import javax.inject.Singleton;
|
||||
public class ProtocolSupportHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
|
||||
@Inject
|
||||
public ProtocolSupportHook(
|
||||
Plan plugin,
|
||||
Processing processing,
|
||||
DBSystem dbSystem
|
||||
) {
|
||||
super("protocolsupport.ProtocolSupport");
|
||||
this.plugin = plugin;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
}
|
||||
|
||||
@ -58,13 +53,15 @@ public class ProtocolSupportHook extends Hook {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
ProtocolTable protocolTable = new ProtocolTable((SQLDB) dbSystem.getDatabase());
|
||||
try {
|
||||
protocolTable.createTable();
|
||||
} catch (DBException e) {
|
||||
throw new DBOpException("Failed to create Protocol table", e);
|
||||
}
|
||||
plugin.registerListener(new PlayerVersionListener(processing, protocolTable));
|
||||
handler.addPluginDataSource(new ProtocolSupportData(protocolTable));
|
||||
Database database = dbSystem.getDatabase();
|
||||
database.executeTransaction(new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(ProtocolTable.createTableSQL(database.getType()));
|
||||
}
|
||||
});
|
||||
|
||||
plugin.registerListener(new PlayerVersionListener(database));
|
||||
handler.addPluginDataSource(new ProtocolSupportData(database));
|
||||
}
|
||||
}
|
@ -17,14 +17,11 @@
|
||||
package com.djrapitops.pluginbridge.plan.react;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.Table;
|
||||
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;
|
||||
|
||||
@ -41,57 +38,52 @@ import java.util.Map;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ReactDataTable extends Table {
|
||||
public class ReactDataTable {
|
||||
|
||||
private static final String TABLE_NAME = "plan_react_data";
|
||||
|
||||
public ReactDataTable(SQLDB db) {
|
||||
super(TABLE_NAME, db);
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
// 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 void clean() {
|
||||
String sql = "DELETE FROM " + tableName + " WHERE " + Col.DATE + "<?";
|
||||
public Executable clean() {
|
||||
String sql = "DELETE FROM " + TABLE_NAME + " WHERE " + Col.DATE + "<?";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, System.currentTimeMillis() - TimeAmount.MONTH.toMillis(1L));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public void addData(ReactValue value) {
|
||||
String sql = "INSERT INTO " + tableName + " (" +
|
||||
public Executable addData(ReactValue value) {
|
||||
String sql = "INSERT INTO " + TABLE_NAME + " (" +
|
||||
Col.SAMPLED_TYPE + ", " +
|
||||
Col.DATE + ", " +
|
||||
Col.MINUTE_AVERAGE +
|
||||
") VALUES (?, ?, ?)";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, value.getType().name());
|
||||
statement.setLong(2, value.getDate());
|
||||
statement.setDouble(3, value.getDataValue());
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public Map<SampledType, List<ReactValue>> getAllData() {
|
||||
String sql = Select.all(tableName).toString();
|
||||
public Query<Map<SampledType, List<ReactValue>>> getAllData() {
|
||||
String sql = Select.all(TABLE_NAME).toString();
|
||||
|
||||
return query(new QueryAllStatement<Map<SampledType, List<ReactValue>>>(sql, 50000) {
|
||||
return new QueryAllStatement<Map<SampledType, List<ReactValue>>>(sql, 50000) {
|
||||
@Override
|
||||
public Map<SampledType, List<ReactValue>> processResults(ResultSet set) throws SQLException {
|
||||
Map<SampledType, List<ReactValue>> results = new EnumMap<>(SampledType.class);
|
||||
@ -112,10 +104,10 @@ public class ReactDataTable extends Table {
|
||||
}
|
||||
return results;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public enum Col implements Column {
|
||||
public enum Col {
|
||||
ID("id"),
|
||||
SAMPLED_TYPE("sampled_type"),
|
||||
DATE("date"),
|
||||
|
@ -16,20 +16,15 @@
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.react;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
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;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Hook in charge for hooking into React.
|
||||
@ -71,17 +66,17 @@ public class ReactHook extends Hook {
|
||||
@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();
|
||||
// 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);
|
||||
// PluginTask task = runnableFactory.create("React Data Task", new ReactDataTask(table, processing))
|
||||
// .runTaskTimerAsynchronously(TimeAmount.toTicks(10L, TimeUnit.SECONDS), TimeAmount.toTicks(10L, TimeUnit.SECONDS));
|
||||
// setTask(task);
|
||||
}
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ import java.util.Optional;
|
||||
* A Class responsible for hooking to Sponge and registering 1 data sources
|
||||
*
|
||||
* @author BrainStone
|
||||
* @since 4.4.6
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class SpongeEconomyHook extends Hook {
|
||||
|
@ -31,7 +31,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
* sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class SuperbVoteHook extends Hook {
|
||||
|
@ -28,7 +28,7 @@ import java.util.Comparator;
|
||||
* Note: this comparator imposes orderings that are inconsistent with equals.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.1.0
|
||||
|
||||
* @see TownyHook
|
||||
*/
|
||||
public class TownComparator implements Comparator<Town> {
|
||||
|
@ -23,7 +23,6 @@ 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.cache.DataCache;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.PluginDataSettings;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
@ -48,18 +47,16 @@ import java.util.stream.Collectors;
|
||||
class TownyData extends PluginData {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final DataCache dataCache;
|
||||
|
||||
TownyData(PlanConfig config, DataCache dataCache) {
|
||||
TownyData(PlanConfig config) {
|
||||
super(ContainerSize.TAB, "Towny");
|
||||
this.config = config;
|
||||
this.dataCache = dataCache;
|
||||
setPluginIcon(Icon.called("university").of(Color.BROWN).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
||||
String playerName = dataCache.getName(uuid);
|
||||
String playerName = PlanAPI.getInstance().getPlayerName(uuid);
|
||||
|
||||
try {
|
||||
Resident resident = TownyUniverse.getDataSource().getResident(playerName);
|
||||
@ -104,10 +101,11 @@ class TownyData extends PluginData {
|
||||
for (Town town : towns) {
|
||||
String townName = town.getName();
|
||||
String mayor = town.getMayor().getName();
|
||||
UUID mayorUUID = dataCache.getUUIDof(mayor);
|
||||
PlanAPI planAPI = PlanAPI.getInstance();
|
||||
UUID mayorUUID = planAPI.playerNameToUUID(mayor);
|
||||
town.getResidents().stream()
|
||||
.map(Resident::getName)
|
||||
.map(dataCache::getUUIDof)
|
||||
.map(planAPI::playerNameToUUID)
|
||||
.filter(Verify::notNull)
|
||||
.forEach(uuid -> userTowns.put(uuid, uuid.equals(mayorUUID) ? "<b>" + townName + "</b>" : townName));
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
package com.djrapitops.pluginbridge.plan.towny;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
|
||||
@ -28,27 +27,24 @@ import javax.inject.Singleton;
|
||||
* A Class responsible for hooking to Towny and registering 2 data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.1.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class TownyHook extends Hook {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final DataCache dataCache;
|
||||
|
||||
@Inject
|
||||
public TownyHook(
|
||||
PlanConfig config,
|
||||
DataCache dataCache
|
||||
PlanConfig config
|
||||
) {
|
||||
super("com.palmergames.bukkit.towny.Towny");
|
||||
this.config = config;
|
||||
this.dataCache = dataCache;
|
||||
}
|
||||
|
||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
||||
if (enabled) {
|
||||
handler.addPluginDataSource(new TownyData(config, dataCache));
|
||||
handler.addPluginDataSource(new TownyData(config));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ 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.system.cache.DataCache;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
@ -41,16 +40,13 @@ class VaultEcoData extends PluginData {
|
||||
|
||||
private final Economy econ;
|
||||
|
||||
private final DataCache dataCache;
|
||||
private final Formatter<Double> decimalFormatter;
|
||||
|
||||
VaultEcoData(
|
||||
Economy econ,
|
||||
DataCache dataCache,
|
||||
Formatter<Double> decimalFormatter
|
||||
) {
|
||||
super(ContainerSize.THIRD, "Economy (" + econ.getName() + ")");
|
||||
this.dataCache = dataCache;
|
||||
this.decimalFormatter = decimalFormatter;
|
||||
setPluginIcon(Icon.called("money-bill-wave").of(Color.GREEN).build());
|
||||
this.econ = econ;
|
||||
@ -58,10 +54,7 @@ class VaultEcoData extends PluginData {
|
||||
|
||||
@Override
|
||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
||||
String name = dataCache.getName(uuid);
|
||||
if (name == null) {
|
||||
return inspectContainer;
|
||||
}
|
||||
String name = uuid.toString();
|
||||
OfflinePlayer p = new FakeOfflinePlayer(uuid, name);
|
||||
inspectContainer.addValue(getWithIcon("Balance", Icon.called("money-bill-wave").of(Color.GREEN)), econ.format(econ.getBalance(p)));
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
package com.djrapitops.pluginbridge.plan.vault;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
@ -32,22 +31,19 @@ import static org.bukkit.Bukkit.getServer;
|
||||
* A Class responsible for hooking to Vault and registering data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.1.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class VaultHook extends Hook {
|
||||
|
||||
private final DataCache dataCache;
|
||||
private final Formatter<Double> decimalFormatter;
|
||||
|
||||
@Inject
|
||||
public VaultHook(
|
||||
DataCache dataCache,
|
||||
Formatters formatters
|
||||
) throws NoClassDefFoundError {
|
||||
super("net.milkbowl.vault.Vault");
|
||||
|
||||
this.dataCache = dataCache;
|
||||
decimalFormatter = formatters.decimals();
|
||||
}
|
||||
|
||||
@ -58,7 +54,7 @@ public class VaultHook extends Hook {
|
||||
|
||||
try {
|
||||
Economy econ = getServer().getServicesManager().getRegistration(Economy.class).getProvider();
|
||||
handler.addPluginDataSource(new VaultEcoData(econ, dataCache, decimalFormatter));
|
||||
handler.addPluginDataSource(new VaultEcoData(econ, decimalFormatter));
|
||||
} catch (NoSuchFieldError | NoSuchMethodError | Exception ignore) {
|
||||
/* Economy service not present */
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -29,29 +29,26 @@ import java.util.UUID;
|
||||
* Class responsible for listening join events for Version protocol.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
|
||||
*/
|
||||
public class BukkitPlayerVersionListener implements Listener {
|
||||
|
||||
private final ViaAPI viaAPI;
|
||||
|
||||
private final ProtocolTable protocolTable;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
|
||||
BukkitPlayerVersionListener(
|
||||
ViaAPI viaAPI,
|
||||
ProtocolTable protocolTable,
|
||||
Processing processing
|
||||
Database database
|
||||
) {
|
||||
this.viaAPI = viaAPI;
|
||||
this.protocolTable = protocolTable;
|
||||
this.processing = processing;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
int playerVersion = viaAPI.getPlayerVersion(uuid);
|
||||
processing.submitNonCritical(() -> protocolTable.saveProtocolVersion(uuid, playerVersion));
|
||||
database.executeTransaction(new StoreUsedProtocolTransaction(uuid, playerVersion));
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
@ -28,29 +28,26 @@ 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 final ViaAPI viaAPI;
|
||||
|
||||
private final ProtocolTable protocolTable;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
|
||||
BungeePlayerVersionListener(
|
||||
ViaAPI viaAPI,
|
||||
ProtocolTable protocolTable,
|
||||
Processing processing
|
||||
Database database
|
||||
) {
|
||||
this.viaAPI = viaAPI;
|
||||
this.protocolTable = protocolTable;
|
||||
this.processing = processing;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PostLoginEvent event) {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
int playerVersion = viaAPI.getPlayerVersion(uuid);
|
||||
processing.submitNonCritical(() -> protocolTable.saveProtocolVersion(uuid, playerVersion));
|
||||
database.executeTransaction(new StoreUsedProtocolTransaction(uuid, playerVersion));
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,13 @@
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.Table;
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Select;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -35,32 +35,31 @@ import java.util.UUID;
|
||||
* Class responsible for version protocol information in Plan database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
|
||||
*/
|
||||
public class ProtocolTable extends Table {
|
||||
public class ProtocolTable {
|
||||
|
||||
private final String columnUUID;
|
||||
private final String columnProtocolVersion;
|
||||
public static final String TABLE_NAME = "plan_version_protocol";
|
||||
public static final String COL_ID = "id";
|
||||
public static final String COL_UUID = "uuid";
|
||||
public static final String COL_PROTOCOL_VERSION = "protocol_version";
|
||||
|
||||
public ProtocolTable(SQLDB db) {
|
||||
super("plan_version_protocol", db);
|
||||
columnUUID = "uuid";
|
||||
columnProtocolVersion = "protocol_version";
|
||||
private ProtocolTable() {
|
||||
/* Static information class */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTable() throws DBInitException {
|
||||
createTable("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
+ columnUUID + " varchar(36) NOT NULL UNIQUE, "
|
||||
+ columnProtocolVersion + " integer NOT NULL"
|
||||
+ ")"
|
||||
);
|
||||
public static String createTableSQL(DBType dbType) {
|
||||
return CreateTableParser.create(TABLE_NAME, dbType)
|
||||
.column(COL_ID, Sql.INT).primaryKey()
|
||||
.column(COL_UUID, Sql.varchar(36)).notNull().unique()
|
||||
.column(COL_PROTOCOL_VERSION, Sql.INT).notNull()
|
||||
.build();
|
||||
}
|
||||
|
||||
public int getProtocolVersion(UUID uuid) {
|
||||
String sql = "SELECT " + columnProtocolVersion + " FROM " + tableName + " WHERE " + columnUUID + "=?";
|
||||
public static Query<Integer> getProtocolVersion(UUID uuid) {
|
||||
String sql = "SELECT " + COL_PROTOCOL_VERSION + " FROM " + TABLE_NAME + " WHERE " + COL_UUID + "=?";
|
||||
|
||||
return query(new QueryStatement<Integer>(sql) {
|
||||
return new QueryStatement<Integer>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, uuid.toString());
|
||||
@ -69,41 +68,26 @@ public class ProtocolTable extends Table {
|
||||
@Override
|
||||
public Integer processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
return set.getInt(columnProtocolVersion);
|
||||
return set.getInt(COL_PROTOCOL_VERSION);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public Map<UUID, Integer> getProtocolVersions() {
|
||||
return query(new QueryAllStatement<Map<UUID, Integer>>(Select.all(tableName).toString(), 5000) {
|
||||
public static Query<Map<UUID, Integer>> getProtocolVersions() {
|
||||
return new QueryAllStatement<Map<UUID, Integer>>(Select.all(TABLE_NAME).toString(), 5000) {
|
||||
@Override
|
||||
public Map<UUID, Integer> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, Integer> versions = new HashMap<>();
|
||||
while (set.next()) {
|
||||
String uuidS = set.getString(columnUUID);
|
||||
String uuidS = set.getString(COL_UUID);
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
versions.put(uuid, set.getInt(columnProtocolVersion));
|
||||
versions.put(uuid, set.getInt(COL_PROTOCOL_VERSION));
|
||||
}
|
||||
return versions;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void saveProtocolVersion(UUID uuid, int version) {
|
||||
String sql = "REPLACE INTO " + tableName + " ("
|
||||
+ columnUUID + ", "
|
||||
+ columnProtocolVersion
|
||||
+ ") VALUES (?, ?)";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setInt(2, version);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.db.access.ExecStatement;
|
||||
import com.djrapitops.plan.db.access.Executable;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||
import static com.djrapitops.pluginbridge.plan.viaversion.ProtocolTable.*;
|
||||
|
||||
/**
|
||||
* Transaction to store used version protocol.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StoreUsedProtocolTransaction extends Transaction {
|
||||
|
||||
private final UUID playerUUID;
|
||||
private final int protocolVersion;
|
||||
|
||||
public StoreUsedProtocolTransaction(UUID playerUUID, int protocolVersion) {
|
||||
this.playerUUID = playerUUID;
|
||||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(storeProtocol());
|
||||
}
|
||||
|
||||
private Executable storeProtocol() {
|
||||
return connection -> {
|
||||
if (!updateProtocol().execute(connection)) {
|
||||
return insertProtocol().execute(connection);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
private Executable updateProtocol() {
|
||||
String sql = "UPDATE " + TABLE_NAME + " SET "
|
||||
+ COL_PROTOCOL_VERSION + "=?"
|
||||
+ WHERE + COL_UUID + "=?";
|
||||
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setInt(1, protocolVersion);
|
||||
statement.setString(2, playerUUID.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Executable insertProtocol() {
|
||||
String sql = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ COL_UUID + ", "
|
||||
+ COL_PROTOCOL_VERSION
|
||||
+ ") VALUES (?, ?)";
|
||||
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
statement.setInt(2, protocolVersion);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -17,12 +17,10 @@
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
@ -34,25 +32,22 @@ import javax.inject.Singleton;
|
||||
* A Class responsible for hooking to ViaVersion and registering data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.1.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class ViaVersionBukkitHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DBSystem dbSystem;
|
||||
private final Processing processing;
|
||||
|
||||
@Inject
|
||||
public ViaVersionBukkitHook(
|
||||
Plan plugin,
|
||||
DBSystem dbSystem,
|
||||
Processing processing
|
||||
DBSystem dbSystem
|
||||
) {
|
||||
super("us.myles.ViaVersion.ViaVersionPlugin");
|
||||
this.plugin = plugin;
|
||||
this.dbSystem = dbSystem;
|
||||
this.processing = processing;
|
||||
}
|
||||
|
||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
||||
@ -60,13 +55,15 @@ public class ViaVersionBukkitHook extends Hook {
|
||||
return;
|
||||
}
|
||||
ViaAPI api = Via.getAPI();
|
||||
ProtocolTable protocolTable = new ProtocolTable((SQLDB) dbSystem.getDatabase());
|
||||
try {
|
||||
protocolTable.createTable();
|
||||
} catch (DBException e) {
|
||||
throw new DBOpException("Failed to create protocol table", e);
|
||||
}
|
||||
plugin.registerListener(new BukkitPlayerVersionListener(api, protocolTable, processing));
|
||||
handler.addPluginDataSource(new ViaVersionData(protocolTable));
|
||||
Database database = dbSystem.getDatabase();
|
||||
database.executeTransaction(new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(ProtocolTable.createTableSQL(database.getType()));
|
||||
}
|
||||
});
|
||||
|
||||
plugin.registerListener(new BukkitPlayerVersionListener(api, database));
|
||||
handler.addPluginDataSource(new ViaVersionData(database));
|
||||
}
|
||||
}
|
@ -17,12 +17,10 @@
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.PlanBungee;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
@ -34,25 +32,22 @@ import javax.inject.Singleton;
|
||||
* A Class responsible for hooking to ViaVersion and registering data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.1.0
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class ViaVersionBungeeHook extends Hook {
|
||||
|
||||
private final PlanBungee plugin;
|
||||
private final DBSystem dbSystem;
|
||||
private final Processing processing;
|
||||
|
||||
@Inject
|
||||
public ViaVersionBungeeHook(
|
||||
PlanBungee plugin,
|
||||
DBSystem dbSystem,
|
||||
Processing processing
|
||||
DBSystem dbSystem
|
||||
) {
|
||||
super("us.myles.ViaVersion.BungeePlugin");
|
||||
this.plugin = plugin;
|
||||
this.dbSystem = dbSystem;
|
||||
this.processing = processing;
|
||||
}
|
||||
|
||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
||||
@ -60,13 +55,15 @@ public class ViaVersionBungeeHook extends Hook {
|
||||
return;
|
||||
}
|
||||
ViaAPI api = Via.getAPI();
|
||||
ProtocolTable protocolTable = new ProtocolTable((SQLDB) dbSystem.getDatabase());
|
||||
try {
|
||||
protocolTable.createTable();
|
||||
} catch (DBException e) {
|
||||
throw new DBOpException("Failed to create protocol table", e);
|
||||
}
|
||||
plugin.registerListener(new BungeePlayerVersionListener(api, protocolTable, processing));
|
||||
handler.addPluginDataSource(new ViaVersionData(protocolTable));
|
||||
Database database = dbSystem.getDatabase();
|
||||
database.executeTransaction(new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(ProtocolTable.createTableSQL(database.getType()));
|
||||
}
|
||||
});
|
||||
|
||||
plugin.registerListener(new BungeePlayerVersionListener(api, database));
|
||||
handler.addPluginDataSource(new ViaVersionData(database));
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ 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.db.Database;
|
||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
|
||||
@ -38,18 +39,18 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
class ViaVersionData extends PluginData {
|
||||
|
||||
private final ProtocolTable table;
|
||||
private final Database database;
|
||||
|
||||
ViaVersionData(ProtocolTable table) {
|
||||
ViaVersionData(Database database) {
|
||||
super(ContainerSize.THIRD, "ViaVersion");
|
||||
setPluginIcon(Icon.called("gamepad").of(Color.LIGHT_GREEN).build());
|
||||
this.table = table;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
||||
try {
|
||||
int protocolVersion = table.getProtocolVersion(uuid);
|
||||
int protocolVersion = database.query(ProtocolTable.getProtocolVersion(uuid));
|
||||
|
||||
inspectContainer.addValue(getWithIcon("Last Join Version", Icon.called("signal").of(Color.LIGHT_GREEN)),
|
||||
protocolVersion != -1 ? Protocol.getMCVersion(protocolVersion) : "Not Yet Known");
|
||||
@ -65,7 +66,7 @@ class ViaVersionData extends PluginData {
|
||||
Map<UUID, Integer> versions;
|
||||
|
||||
try {
|
||||
versions = table.getProtocolVersions();
|
||||
versions = database.query(ProtocolTable.getProtocolVersions());
|
||||
} catch (DBOpException ex) {
|
||||
analysisContainer.addValue("Error", ex.toString());
|
||||
return analysisContainer;
|
||||
|
Loading…
Reference in New Issue
Block a user