mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-07 11:20:11 +01:00
Bridge: Removed AAC & ViaVersion
This commit is contained in:
parent
91bbb00968
commit
8575061e25
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>PlanPluginBridge</artifactId>
|
||||
<version>4.8.8-R0.2</version>
|
||||
<version>4.9.0-R0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.groupId}:${project.artifactId}</name>
|
||||
@ -61,10 +61,6 @@
|
||||
<id>jitpack.io (GriefPrevention)</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>viaversion-repo</id>
|
||||
<url>https://repo.viaversion.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
@ -127,12 +123,6 @@
|
||||
<version>2.10.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency> <!-- Maven Central -->
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
@ -141,13 +131,6 @@
|
||||
</dependency>
|
||||
|
||||
<!-- Plugins requiring local install -->
|
||||
|
||||
<dependency>
|
||||
<groupId>me.konsolas</groupId>
|
||||
<artifactId>AAC</artifactId>
|
||||
<version>4.0.0-b1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.massivecraft</groupId>
|
||||
<artifactId>factions</artifactId>
|
||||
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
import com.djrapitops.plan.data.element.AnalysisContainer;
|
||||
import com.djrapitops.plan.data.element.InspectContainer;
|
||||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.data.plugin.ContainerSize;
|
||||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.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;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
import com.djrapitops.plugin.utilities.Format;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* PluginData for AAC plugin.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
class AdvancedAntiCheatData extends PluginData {
|
||||
|
||||
private final Database database;
|
||||
private final 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.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
||||
List<HackObject> hackObjects = database.query(HackerTable.getHackObjects(uuid));
|
||||
|
||||
inspectContainer.addValue(
|
||||
getWithIcon("Times Kicked for Possible Hacking", Icon.called("exclamation-triangle").of(Color.RED)),
|
||||
hackObjects.size()
|
||||
);
|
||||
|
||||
TableContainer hackTable = new TableContainer(
|
||||
getWithIcon("Kicked", Icon.called("calendar").of(Family.REGULAR)),
|
||||
getWithIcon("Hack", Icon.called("exclamation-triangle")),
|
||||
getWithIcon("Violation Level", Icon.called("gavel"))
|
||||
);
|
||||
hackTable.setColor("red");
|
||||
|
||||
for (HackObject hackObject : hackObjects) {
|
||||
String date = timestampFormatter.apply(hackObject.getDate());
|
||||
String hack = new Format(hackObject.getHackType()).capitalize().toString();
|
||||
hackTable.addRow(date, hack, hackObject.getViolationLevel());
|
||||
}
|
||||
inspectContainer.addTable("hackTable", hackTable);
|
||||
|
||||
return inspectContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) {
|
||||
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()));
|
||||
|
||||
analysisContainer.addPlayerTableValues(getWithIcon("Kicked for Hacking", Icon.called("exclamation-triangle")), violations);
|
||||
|
||||
return analysisContainer;
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
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.utilities.formatting.Formatters;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Hook for AAC plugin.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class AdvancedAntiCheatHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DBSystem dbSystem;
|
||||
private final Formatters formatters;
|
||||
|
||||
@Inject
|
||||
public AdvancedAntiCheatHook(
|
||||
Plan plugin,
|
||||
DBSystem dbSystem,
|
||||
Formatters formatters
|
||||
) {
|
||||
super("me.konsolas.aac.AAC");
|
||||
this.plugin = plugin;
|
||||
this.dbSystem = dbSystem;
|
||||
this.formatters = formatters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hook(HookHandler hookHandler) throws NoClassDefFoundError {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
Database database = dbSystem.getDatabase();
|
||||
database.executeTransaction(new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(HackerTable.createTableSQL(database.getType()));
|
||||
}
|
||||
});
|
||||
database.executeTransaction(new HackerTableMissingDateColumnPatch());
|
||||
|
||||
plugin.registerListener(new PlayerHackKickListener(database));
|
||||
hookHandler.addPluginDataSource(new AdvancedAntiCheatData(database, formatters.yearLong()));
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Data object for AAC data.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class HackObject {
|
||||
|
||||
private final UUID uuid;
|
||||
private final long date;
|
||||
private final String hackType;
|
||||
private final int violationLevel;
|
||||
|
||||
public HackObject(UUID uuid, long date, String hackType, int violationLevel) {
|
||||
this.uuid = uuid;
|
||||
this.date = date;
|
||||
this.hackType = hackType;
|
||||
this.violationLevel = violationLevel;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public long getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public String getHackType() {
|
||||
return hackType;
|
||||
}
|
||||
|
||||
public int getViolationLevel() {
|
||||
return violationLevel;
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
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;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Table information about 'plan_aac_hack_table'.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class HackerTable {
|
||||
|
||||
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";
|
||||
|
||||
private HackerTable() {
|
||||
/* Static information class */
|
||||
}
|
||||
|
||||
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_DATE, Sql.LONG).notNull()
|
||||
.column(COL_HACK_TYPE, Sql.varchar(100)).notNull()
|
||||
.column(COL_VIOLATION_LEVEL, Sql.INT).notNull()
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Query<List<HackObject>> getHackObjects(UUID uuid) {
|
||||
String sql = "SELECT * FROM " + TABLE_NAME + " WHERE " + COL_UUID + "=?";
|
||||
|
||||
return new QueryStatement<List<HackObject>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, uuid.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HackObject> processResults(ResultSet set) throws SQLException {
|
||||
List<HackObject> hackObjects = new ArrayList<>();
|
||||
while (set.next()) {
|
||||
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 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(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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
import com.djrapitops.plan.db.patches.Patch;
|
||||
|
||||
/**
|
||||
* Patch to fix a bug
|
||||
* https://github.com/plan-player-analytics/Plan/issues/1027
|
||||
* introduced in commit 530c4a2
|
||||
* https://github.com/plan-player-analytics/Plan/commit/530c4a2ea6fd56fd9a7aa3382f7571f31971dc1a#commitcomment-33415938
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class HackerTableMissingDateColumnPatch extends Patch {
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return hasColumn(HackerTable.TABLE_NAME, HackerTable.COL_DATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
addColumn(HackerTable.TABLE_NAME, HackerTable.COL_DATE + " bigint NOT NULL DEFAULT 0");
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.aac;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import me.konsolas.aac.api.AACAPIProvider;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.api.PlayerViolationCommandEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Class responsible for listening kick events made by AAC.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlayerHackKickListener implements Listener {
|
||||
|
||||
private final Database database;
|
||||
|
||||
PlayerHackKickListener(Database database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onKick(PlayerViolationCommandEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
HackType hackType = event.getHackType();
|
||||
String hackTypeName = hackType.getName();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
int violations = new AACAPIProvider().getAPI().getViolationLevel(player, hackType);
|
||||
|
||||
HackObject hackObject = new HackObject(uuid, time, hackTypeName, violations);
|
||||
|
||||
database.executeTransaction(new StoreHackViolationKickTransaction(hackObject));
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.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());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
package com.djrapitops.pluginbridge.plan.protocolsupport;
|
||||
|
||||
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;
|
||||
|
@ -25,7 +25,6 @@ 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.ProtocolTable;
|
||||
import protocolsupport.api.ProtocolVersion;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -22,7 +22,6 @@ import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
import com.djrapitops.pluginbridge.plan.viaversion.ProtocolTable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -14,7 +14,7 @@
|
||||
* 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;
|
||||
package com.djrapitops.pluginbridge.plan.protocolsupport;
|
||||
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
import com.djrapitops.plan.db.access.Query;
|
@ -14,7 +14,7 @@
|
||||
* 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;
|
||||
package com.djrapitops.pluginbridge.plan.protocolsupport;
|
||||
|
||||
import com.djrapitops.plan.db.access.ExecStatement;
|
||||
import com.djrapitops.plan.db.access.Executable;
|
||||
@ -25,7 +25,7 @@ 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.*;
|
||||
import static com.djrapitops.pluginbridge.plan.protocolsupport.ProtocolTable.*;
|
||||
|
||||
/**
|
||||
* Transaction to store used version protocol.
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Class responsible for listening join events for Version protocol.
|
||||
*
|
||||
* @author Rsl1122
|
||||
|
||||
*/
|
||||
public class BukkitPlayerVersionListener implements Listener {
|
||||
|
||||
private final ViaAPI viaAPI;
|
||||
|
||||
private final Database database;
|
||||
|
||||
BukkitPlayerVersionListener(
|
||||
ViaAPI viaAPI,
|
||||
Database database
|
||||
) {
|
||||
this.viaAPI = viaAPI;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
int playerVersion = viaAPI.getPlayerVersion(uuid);
|
||||
database.executeTransaction(new StoreUsedProtocolTransaction(uuid, playerVersion));
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
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;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Class responsible for listening join events for Version protocol.
|
||||
*
|
||||
* @author Rsl1122
|
||||
|
||||
*/
|
||||
public class BungeePlayerVersionListener implements Listener {
|
||||
|
||||
private final ViaAPI viaAPI;
|
||||
|
||||
private final Database database;
|
||||
|
||||
BungeePlayerVersionListener(
|
||||
ViaAPI viaAPI,
|
||||
Database database
|
||||
) {
|
||||
this.viaAPI = viaAPI;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PostLoginEvent event) {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
int playerVersion = viaAPI.getPlayerVersion(uuid);
|
||||
database.executeTransaction(new StoreUsedProtocolTransaction(uuid, playerVersion));
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
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.pluginbridge.plan.Hook;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* A Class responsible for hooking to ViaVersion and registering data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class ViaVersionBukkitHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DBSystem dbSystem;
|
||||
|
||||
@Inject
|
||||
public ViaVersionBukkitHook(
|
||||
Plan plugin,
|
||||
DBSystem dbSystem
|
||||
) {
|
||||
super("us.myles.ViaVersion.ViaVersionPlugin");
|
||||
this.plugin = plugin;
|
||||
this.dbSystem = dbSystem;
|
||||
}
|
||||
|
||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
ViaAPI api = Via.getAPI();
|
||||
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));
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.PlanBungee;
|
||||
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.pluginbridge.plan.Hook;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* A Class responsible for hooking to ViaVersion and registering data sources.
|
||||
*
|
||||
* @author Rsl1122
|
||||
|
||||
*/
|
||||
@Singleton
|
||||
public class ViaVersionBungeeHook extends Hook {
|
||||
|
||||
private final PlanBungee plugin;
|
||||
private final DBSystem dbSystem;
|
||||
|
||||
@Inject
|
||||
public ViaVersionBungeeHook(
|
||||
PlanBungee plugin,
|
||||
DBSystem dbSystem
|
||||
) {
|
||||
super("us.myles.ViaVersion.BungeePlugin");
|
||||
this.plugin = plugin;
|
||||
this.dbSystem = dbSystem;
|
||||
}
|
||||
|
||||
public void hook(HookHandler handler) throws NoClassDefFoundError {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
ViaAPI api = Via.getAPI();
|
||||
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));
|
||||
}
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.pluginbridge.plan.viaversion;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.element.AnalysisContainer;
|
||||
import com.djrapitops.plan.data.element.InspectContainer;
|
||||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.data.plugin.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 us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* PluginData for ViaVersion plugin.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
class ViaVersionData extends PluginData {
|
||||
|
||||
private final Database database;
|
||||
|
||||
ViaVersionData(Database database) {
|
||||
super(ContainerSize.THIRD, "ViaVersion");
|
||||
setPluginIcon(Icon.called("gamepad").of(Color.LIGHT_GREEN).build());
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
|
||||
try {
|
||||
int version = database.query(ProtocolTable.getProtocolVersion(uuid));
|
||||
|
||||
inspectContainer.addValue(getWithIcon("Last Join Version", Icon.called("signal").of(Color.LIGHT_GREEN)),
|
||||
getProtocolVersionString(version));
|
||||
} catch (DBOpException ex) {
|
||||
inspectContainer.addValue("Error", ex.toString());
|
||||
}
|
||||
|
||||
return inspectContainer;
|
||||
}
|
||||
|
||||
private String getProtocolVersionString(int version) {
|
||||
return version != -1 ? ProtocolVersion.getProtocol(version).getName() : "Not Yet Known";
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) {
|
||||
Map<UUID, Integer> versions;
|
||||
|
||||
try {
|
||||
versions = database.query(ProtocolTable.getProtocolVersions());
|
||||
} catch (DBOpException ex) {
|
||||
analysisContainer.addValue("Error", ex.toString());
|
||||
return analysisContainer;
|
||||
}
|
||||
|
||||
Map<UUID, String> userVersions = versions.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> getProtocolVersionString(entry.getValue())));
|
||||
|
||||
analysisContainer.addPlayerTableValues(getWithIcon("Last Version", Icon.called("signal")), userVersions);
|
||||
|
||||
String versionS = getWithIcon("Version", Icon.called("signal"));
|
||||
String membersS = getWithIcon("Users", Icon.called("users"));
|
||||
TableContainer versionTable = new TableContainer(versionS, membersS);
|
||||
versionTable.setColor("light-green");
|
||||
Map<String, Integer> usersPerVersion = getUsersPerVersion(userVersions);
|
||||
for (Map.Entry<String, Integer> entry : usersPerVersion.entrySet()) {
|
||||
versionTable.addRow(entry.getKey(), entry.getValue());
|
||||
}
|
||||
analysisContainer.addTable("versionTable", versionTable);
|
||||
|
||||
return analysisContainer;
|
||||
}
|
||||
|
||||
private Map<String, Integer> getUsersPerVersion(Map<UUID, String> userVersions) {
|
||||
Map<String, Integer> usersPerVersion = new HashMap<>();
|
||||
|
||||
for (String version : userVersions.values()) {
|
||||
if (!usersPerVersion.containsKey(version)) {
|
||||
usersPerVersion.put(version, 0);
|
||||
}
|
||||
usersPerVersion.replace(version, usersPerVersion.get(version) + 1);
|
||||
}
|
||||
return usersPerVersion;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user