Bridge: Removed ProtocolSupport

This commit is contained in:
Rsl1122 2019-07-30 11:20:19 +03:00
parent 782f6d5b82
commit 110e47c3ad
7 changed files with 1 additions and 431 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.djrapitops</groupId>
<artifactId>PlanPluginBridge</artifactId>
<version>4.9.0-R0.2</version>
<version>4.9.0-R0.3</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
@ -155,12 +155,6 @@
<version>0.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.ProtocolSupport</groupId>
<artifactId>ProtocolSupport</artifactId>
<version>4.28</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.volmit</groupId>
<artifactId>react</artifactId>

View File

@ -23,7 +23,6 @@ import com.djrapitops.pluginbridge.plan.factions.FactionsHook;
import com.djrapitops.pluginbridge.plan.jobs.JobsHook;
import com.djrapitops.pluginbridge.plan.litebans.LiteBansBukkitHook;
import com.djrapitops.pluginbridge.plan.luckperms.LuckPermsHook;
import com.djrapitops.pluginbridge.plan.protocolsupport.ProtocolSupportHook;
import com.djrapitops.pluginbridge.plan.towny.TownyHook;
import javax.inject.Inject;
@ -42,7 +41,6 @@ public class BukkitBridge extends AbstractBridge {
private final JobsHook jobsHook;
private final LiteBansBukkitHook liteBansHook;
private final LuckPermsHook luckPermsHook;
private final ProtocolSupportHook protocolSupportHook;
private final TownyHook townyHook;
@Inject
@ -54,7 +52,6 @@ public class BukkitBridge extends AbstractBridge {
JobsHook jobsHook,
LiteBansBukkitHook liteBansHook,
LuckPermsHook luckPermsHook,
ProtocolSupportHook protocolSupportHook,
TownyHook townyHook
) {
super(config, errorHandler);
@ -63,7 +60,6 @@ public class BukkitBridge extends AbstractBridge {
this.jobsHook = jobsHook;
this.liteBansHook = liteBansHook;
this.luckPermsHook = luckPermsHook;
this.protocolSupportHook = protocolSupportHook;
this.townyHook = townyHook;
}
@ -75,7 +71,6 @@ public class BukkitBridge extends AbstractBridge {
jobsHook,
liteBansHook,
luckPermsHook,
protocolSupportHook,
townyHook,
};
}

View File

@ -1,51 +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.protocolsupport;
import com.djrapitops.plan.db.Database;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import protocolsupport.api.ProtocolSupportAPI;
import protocolsupport.api.ProtocolVersion;
import java.util.UUID;
/**
* Class responsible for listening join events for Version protocol.
*
* @author Rsl1122
*/
public class PlayerVersionListener implements Listener {
private final Database database;
public PlayerVersionListener(Database database) {
this.database = database;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
ProtocolVersion protocolVersion = ProtocolSupportAPI.getProtocolVersion(player);
int playerVersion = protocolVersion.getId();
database.executeTransaction(new StoreUsedProtocolTransaction(uuid, playerVersion));
}
}

View File

@ -1,122 +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.protocolsupport;
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 protocolsupport.api.ProtocolVersion;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* PluginData for ProtocolSupport plugin.
*
* @author Rsl1122
*/
class ProtocolSupportData extends PluginData {
private final Database database;
ProtocolSupportData(Database database) {
super(ContainerSize.THIRD, "ProtocolSupport");
setPluginIcon(Icon.called("gamepad").of(Color.CYAN).build());
this.database = database;
}
@Override
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
try {
int protocolVersion = database.query(ProtocolTable.getProtocolVersion(uuid));
inspectContainer.addValue(getWithIcon("Last Join Version", Icon.called("signal").of(Color.CYAN)),
getProtocolVersionString(protocolVersion));
} catch (DBOpException ex) {
inspectContainer.addValue("Error", ex.toString());
}
return inspectContainer;
}
private String getProtocolVersionString(int number) {
if (number == -1) {
return "Not Yet Known";
}
ProtocolVersion[] versions = ProtocolVersion.getAllSupported();
for (ProtocolVersion version : versions) {
if (version.getId() == number) {
String name = version.getName();
if (name == null) {
break; // Unknown name for the version
}
return name;
}
}
return "Unknown (" + number + ')';
}
@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("cyan");
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;
}
}

View File

@ -1,66 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.pluginbridge.plan.protocolsupport;
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 javax.inject.Inject;
import javax.inject.Singleton;
/**
* Hook for ProtocolSupport plugin.
*
* @author Rsl1122
*/
@Singleton
public class ProtocolSupportHook extends Hook {
private final Plan plugin;
private final DBSystem dbSystem;
@Inject
public ProtocolSupportHook(
Plan plugin,
DBSystem dbSystem
) {
super("protocolsupport.ProtocolSupport");
this.plugin = plugin;
this.dbSystem = dbSystem;
}
@Override
public void hook(HookHandler handler) throws NoClassDefFoundError {
if (!enabled) {
return;
}
Database database = dbSystem.getDatabase();
database.executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute(ProtocolTable.createTableSQL(database.getType()));
}
});
plugin.registerListener(new PlayerVersionListener(database));
handler.addPluginDataSource(new ProtocolSupportData(database));
}
}

View File

@ -1,93 +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.protocolsupport;
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.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* Class responsible for version protocol information in Plan database.
*
* @author Rsl1122
*/
public class ProtocolTable {
public static final String TABLE_NAME = "plan_version_protocol";
public static final String COL_ID = "id";
public static final String COL_UUID = "uuid";
public static final String COL_PROTOCOL_VERSION = "protocol_version";
private ProtocolTable() {
/* 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().unique()
.column(COL_PROTOCOL_VERSION, Sql.INT).notNull()
.build();
}
public static Query<Integer> getProtocolVersion(UUID uuid) {
String sql = "SELECT " + COL_PROTOCOL_VERSION + " FROM " + TABLE_NAME + " WHERE " + COL_UUID + "=?";
return new QueryStatement<Integer>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString());
}
@Override
public Integer processResults(ResultSet set) throws SQLException {
if (set.next()) {
return set.getInt(COL_PROTOCOL_VERSION);
} else {
return -1;
}
}
};
}
public static Query<Map<UUID, Integer>> getProtocolVersions() {
return new QueryAllStatement<Map<UUID, Integer>>(Select.all(TABLE_NAME).toString(), 5000) {
@Override
public Map<UUID, Integer> processResults(ResultSet set) throws SQLException {
Map<UUID, Integer> versions = new HashMap<>();
while (set.next()) {
String uuidS = set.getString(COL_UUID);
UUID uuid = UUID.fromString(uuidS);
versions.put(uuid, set.getInt(COL_PROTOCOL_VERSION));
}
return versions;
}
};
}
}

View File

@ -1,87 +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.protocolsupport;
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.protocolsupport.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);
}
};
}
}