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