mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-31 07:50:09 +01:00
Ban and Operator status Transactions:
- Removed SaveOperations - Removed BanAndOpProcessor, PlayerProcessors - Removed UserInfoTable#updateOpStatus, UserInfoTable#updateBanStatus
This commit is contained in:
parent
57695d6e43
commit
0c893ea59c
@ -92,10 +92,11 @@ public class PlayerOnlineListener implements Listener {
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
try {
|
||||
PlayerLoginEvent.Result result = event.getResult();
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
boolean op = event.getPlayer().isOp();
|
||||
UUID playerUUID = event.getPlayer().getUniqueId();
|
||||
boolean operator = event.getPlayer().isOp();
|
||||
boolean banned = result == PlayerLoginEvent.Result.KICK_BANNED;
|
||||
processing.submit(processors.player().banAndOpProcessor(uuid, () -> banned, op));
|
||||
dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, () -> banned));
|
||||
dbSystem.getDatabase().executeTransaction(new OperatorStatusTransaction(playerUUID, operator));
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
@ -194,7 +195,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
|
||||
nicknameCache.removeDisplayName(playerUUID);
|
||||
|
||||
processing.submit(processors.player().banAndOpProcessor(playerUUID, player::isBanned, player.isOp()));
|
||||
dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, player::isBanned));
|
||||
|
||||
sessionCache.endSession(playerUUID, time)
|
||||
.ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));
|
||||
|
@ -21,7 +21,6 @@ import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||
import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
|
||||
|
||||
/**
|
||||
* Interface for interacting with a Plan SQL database.
|
||||
@ -57,9 +56,6 @@ public interface Database {
|
||||
@Deprecated
|
||||
FetchOperations fetch();
|
||||
|
||||
@Deprecated
|
||||
SaveOperations save();
|
||||
|
||||
/**
|
||||
* Used to get the {@code DBType} of the Database
|
||||
*
|
||||
|
@ -31,9 +31,7 @@ import com.djrapitops.plan.db.sql.tables.TPSTable;
|
||||
import com.djrapitops.plan.db.sql.tables.UserInfoTable;
|
||||
import com.djrapitops.plan.db.tasks.PatchTask;
|
||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||
import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
|
||||
import com.djrapitops.plan.system.database.databases.sql.operation.SQLFetchOps;
|
||||
import com.djrapitops.plan.system.database.databases.sql.operation.SQLSaveOps;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.PluginSettings;
|
||||
@ -77,7 +75,6 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
private final TPSTable tpsTable;
|
||||
|
||||
private final SQLFetchOps fetchOps;
|
||||
private final SQLSaveOps saveOps;
|
||||
|
||||
private PluginTask dbCleanTask;
|
||||
|
||||
@ -104,7 +101,6 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
userInfoTable = new UserInfoTable(this);
|
||||
|
||||
fetchOps = new SQLFetchOps(this);
|
||||
saveOps = new SQLSaveOps(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -340,12 +336,6 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
return fetchOps;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public SaveOperations save() {
|
||||
return saveOps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.plan.db.access.transactions.events;
|
||||
|
||||
import com.djrapitops.plan.db.access.ExecStatement;
|
||||
import com.djrapitops.plan.db.access.Executable;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.db.sql.parsing.Update;
|
||||
import com.djrapitops.plan.db.sql.tables.UserInfoTable;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
/**
|
||||
* Transaction to update a player's ban status.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BanStatusTransaction extends Transaction {
|
||||
|
||||
private UUID playerUUID;
|
||||
private BooleanSupplier banStatus;
|
||||
|
||||
public BanStatusTransaction(UUID playerUUID, BooleanSupplier banStatus) {
|
||||
this.playerUUID = playerUUID;
|
||||
this.banStatus = banStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(updateBanStatus());
|
||||
}
|
||||
|
||||
private Executable updateBanStatus() {
|
||||
String sql = Update.values(UserInfoTable.TABLE_NAME, UserInfoTable.BANNED)
|
||||
.where(UserInfoTable.USER_UUID + "=?")
|
||||
.toString();
|
||||
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setBoolean(1, banStatus.getAsBoolean());
|
||||
statement.setString(2, playerUUID.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.plan.db.access.transactions.events;
|
||||
|
||||
import com.djrapitops.plan.db.access.ExecStatement;
|
||||
import com.djrapitops.plan.db.access.Executable;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.db.sql.parsing.Update;
|
||||
import com.djrapitops.plan.db.sql.tables.UserInfoTable;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transaction to update a player's operator status.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OperatorStatusTransaction extends Transaction {
|
||||
|
||||
private UUID playerUUID;
|
||||
private boolean operatorStatus;
|
||||
|
||||
public OperatorStatusTransaction(UUID playerUUID, boolean operatorStatus) {
|
||||
this.playerUUID = playerUUID;
|
||||
this.operatorStatus = operatorStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(updateOperatorStatus());
|
||||
}
|
||||
|
||||
private Executable updateOperatorStatus() {
|
||||
String sql = Update.values(UserInfoTable.TABLE_NAME, UserInfoTable.OP)
|
||||
.where(UserInfoTable.USER_UUID + "=?")
|
||||
.toString();
|
||||
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setBoolean(1, operatorStatus);
|
||||
statement.setString(2, playerUUID.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -18,16 +18,10 @@ package com.djrapitops.plan.db.sql.tables;
|
||||
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.access.ExecStatement;
|
||||
import com.djrapitops.plan.db.patches.UserInfoOptimizationPatch;
|
||||
import com.djrapitops.plan.db.patches.Version10Patch;
|
||||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
import com.djrapitops.plan.db.sql.parsing.Update;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Table that is in charge of storing server specific player data.
|
||||
@ -73,32 +67,4 @@ public class UserInfoTable extends Table {
|
||||
.column(BANNED, Sql.BOOL).notNull().defaultValue(false)
|
||||
.toString();
|
||||
}
|
||||
|
||||
public void updateOpStatus(UUID uuid, boolean op) {
|
||||
String sql = Update.values(TABLE_NAME, OP)
|
||||
.where(USER_UUID + "=?")
|
||||
.toString();
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setBoolean(1, op);
|
||||
statement.setString(2, uuid.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateBanStatus(UUID uuid, boolean banned) {
|
||||
String sql = Update.values(TABLE_NAME, BANNED)
|
||||
.where(USER_UUID + "=?")
|
||||
.toString();
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setBoolean(1, banned);
|
||||
statement.setString(2, uuid.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +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.plan.system.database.databases.operation;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Operation methods for saving data.
|
||||
* <p>
|
||||
* Note: Method names subject to change
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public interface SaveOperations {
|
||||
|
||||
// Bulk save
|
||||
|
||||
// Single data point
|
||||
|
||||
@Deprecated
|
||||
void banStatus(UUID uuid, boolean banned);
|
||||
|
||||
@Deprecated
|
||||
void opStatus(UUID uuid, boolean op);
|
||||
|
||||
}
|
@ -1,45 +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.plan.system.database.databases.sql.operation;
|
||||
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* SaveOperations implementation for SQL databases.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SQLSaveOps extends SQLOps implements SaveOperations {
|
||||
|
||||
public SQLSaveOps(SQLDB db) {
|
||||
super(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void banStatus(UUID uuid, boolean banned) {
|
||||
userInfoTable.updateBanStatus(uuid, banned);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void opStatus(UUID uuid, boolean op) {
|
||||
userInfoTable.updateOpStatus(uuid, op);
|
||||
}
|
||||
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
package com.djrapitops.plan.system.processing.processors;
|
||||
|
||||
import com.djrapitops.plan.system.processing.processors.info.InfoProcessors;
|
||||
import com.djrapitops.plan.system.processing.processors.player.PlayerProcessors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -30,22 +29,15 @@ import javax.inject.Singleton;
|
||||
@Singleton
|
||||
public class Processors {
|
||||
|
||||
private final PlayerProcessors playerProcessors;
|
||||
private final InfoProcessors infoProcessors;
|
||||
|
||||
@Inject
|
||||
public Processors(
|
||||
PlayerProcessors playerProcessors,
|
||||
InfoProcessors infoProcessors
|
||||
) {
|
||||
this.playerProcessors = playerProcessors;
|
||||
this.infoProcessors = infoProcessors;
|
||||
}
|
||||
|
||||
public PlayerProcessors player() {
|
||||
return playerProcessors;
|
||||
}
|
||||
|
||||
public InfoProcessors info() {
|
||||
return infoProcessors;
|
||||
}
|
||||
|
@ -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.plan.system.processing.processors.player;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
/**
|
||||
* Updates ban and OP status of the player to the database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BanAndOpProcessor implements Runnable {
|
||||
|
||||
private final UUID uuid;
|
||||
private final BooleanSupplier banned;
|
||||
private final boolean op;
|
||||
|
||||
private final Database database;
|
||||
|
||||
BanAndOpProcessor(
|
||||
UUID uuid, BooleanSupplier banned, boolean op,
|
||||
Database database
|
||||
) {
|
||||
this.uuid = uuid;
|
||||
this.banned = banned;
|
||||
this.op = op;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SaveOperations save = database.save();
|
||||
save.banStatus(uuid, banned.getAsBoolean());
|
||||
save.opStatus(uuid, op);
|
||||
}
|
||||
}
|
@ -1,47 +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.plan.system.processing.processors.player;
|
||||
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
/**
|
||||
* Factory for creating Runnables related to Player data to run with {@link com.djrapitops.plan.system.processing.Processing}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class PlayerProcessors {
|
||||
|
||||
private final Lazy<DBSystem> dbSystem;
|
||||
|
||||
@Inject
|
||||
public PlayerProcessors(
|
||||
Lazy<DBSystem> dbSystem
|
||||
) {
|
||||
this.dbSystem = dbSystem;
|
||||
}
|
||||
|
||||
public BanAndOpProcessor banAndOpProcessor(UUID uuid, BooleanSupplier banned, boolean op) {
|
||||
return new BanAndOpProcessor(uuid, banned, op, dbSystem.get().getDatabase());
|
||||
}
|
||||
}
|
@ -417,7 +417,7 @@ public abstract class CommonDBTest {
|
||||
public void userInfoTableUpdatesBanStatus() {
|
||||
saveUserOne();
|
||||
|
||||
db.getUserInfoTable().updateBanStatus(playerUUID, true);
|
||||
db.executeTransaction(new BanStatusTransaction(playerUUID, () -> true));
|
||||
|
||||
List<UserInfo> userInfo = db.query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID, 1000L, false, true));
|
||||
@ -429,7 +429,7 @@ public abstract class CommonDBTest {
|
||||
public void userInfoTableUpdatesOperatorStatus() {
|
||||
saveUserOne();
|
||||
|
||||
db.getUserInfoTable().updateOpStatus(playerUUID, true);
|
||||
db.executeTransaction(new OperatorStatusTransaction(playerUUID, true));
|
||||
|
||||
List<UserInfo> userInfo = db.query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID, 1000L, true, false));
|
||||
|
@ -105,7 +105,7 @@ public class SpongePlayerListener {
|
||||
GameProfile profile = event.getProfile();
|
||||
UUID playerUUID = profile.getUniqueId();
|
||||
boolean banned = isBanned(profile);
|
||||
processing.submit(processors.player().banAndOpProcessor(playerUUID, () -> banned, false));
|
||||
dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, () -> banned));
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
@ -199,7 +199,7 @@ public class SpongePlayerListener {
|
||||
nicknameCache.removeDisplayName(playerUUID);
|
||||
|
||||
boolean banned = isBanned(player.getProfile());
|
||||
processing.submit(processors.player().banAndOpProcessor(playerUUID, () -> banned, false));
|
||||
dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, () -> banned));
|
||||
|
||||
sessionCache.endSession(playerUUID, time)
|
||||
.ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));
|
||||
|
Loading…
Reference in New Issue
Block a user