Moved Player#isBanned call to be executed on an asynchronous thread #616

This commit is contained in:
Rsl1122 2018-07-11 10:08:14 +03:00
parent efa0a2949f
commit b25acb18c4
3 changed files with 9 additions and 7 deletions

View File

@ -41,7 +41,7 @@ public class PlayerOnlineListener implements Listener {
UUID uuid = event.getPlayer().getUniqueId();
boolean op = event.getPlayer().isOp();
boolean banned = result == PlayerLoginEvent.Result.KICK_BANNED;
Processing.submit(new BanAndOpProcessor(uuid, banned, op));
Processing.submit(new BanAndOpProcessor(uuid, () -> banned, op));
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
@ -122,7 +122,7 @@ public class PlayerOnlineListener implements Listener {
AFKListener.AFK_TRACKER.loggedOut(uuid, time);
Processing.submit(new BanAndOpProcessor(uuid, player.isBanned(), player.isOp()));
Processing.submit(new BanAndOpProcessor(uuid, player::isBanned, player.isOp()));
Processing.submit(new EndSessionProcessor(uuid, time));
Processing.submit(new NetworkPageUpdateProcessor());
Processing.submit(new PlayerPageUpdateProcessor(uuid));

View File

@ -44,7 +44,7 @@ public class SpongePlayerListener {
GameProfile profile = event.getProfile();
UUID uuid = profile.getUniqueId();
boolean banned = isBanned(profile);
Processing.submit(new BanAndOpProcessor(uuid, banned, false));
Processing.submit(new BanAndOpProcessor(uuid, () -> banned, false));
}
@Listener(order = Order.POST)
@ -125,7 +125,8 @@ public class SpongePlayerListener {
SpongeAFKListener.AFK_TRACKER.loggedOut(uuid, time);
Processing.submit(new BanAndOpProcessor(uuid, isBanned(player.getProfile()), false));
boolean banned = isBanned(player.getProfile());
Processing.submit(new BanAndOpProcessor(uuid, () -> banned, false));
Processing.submit(new EndSessionProcessor(uuid, time));
Processing.submit(new NetworkPageUpdateProcessor());
Processing.submit(new PlayerPageUpdateProcessor(uuid));

View File

@ -8,6 +8,7 @@ import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
import java.util.UUID;
import java.util.function.Supplier;
/**
* Updates ban and OP status of the player to the database.
@ -17,10 +18,10 @@ import java.util.UUID;
public class BanAndOpProcessor implements Runnable {
private final UUID uuid;
private final boolean banned;
private final Supplier<Boolean> banned;
private final boolean op;
public BanAndOpProcessor(UUID uuid, boolean banned, boolean op) {
public BanAndOpProcessor(UUID uuid, Supplier<Boolean> banned, boolean op) {
this.uuid = uuid;
this.banned = banned;
this.op = op;
@ -29,7 +30,7 @@ public class BanAndOpProcessor implements Runnable {
@Override
public void run() {
SaveOperations save = Database.getActive().save();
save.banStatus(uuid, banned);
save.banStatus(uuid, banned.get());
save.opStatus(uuid, op);
}
}