Code clean up

This commit is contained in:
games647 2021-06-19 17:53:13 +02:00
parent b1a9abc019
commit e437321f8f
No known key found for this signature in database
GPG Key ID: BFC68C8708713A88
3 changed files with 19 additions and 14 deletions

View File

@ -1,20 +1,21 @@
package fr.xephi.authme.listener.protocollib;
import ch.jalu.injector.annotations.NoFieldScan;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.listener.ListenerService;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import org.bukkit.entity.Player;
@NoFieldScan
public class ProtocolLibService implements SettingsDependent {

View File

@ -117,18 +117,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
}
final boolean isAuthAvailable = database.isAuthAvailable(name);
RegistrationStatus status = RegistrationStatus.UNREGISTERED;
playerCache.addRegistrationStatus(name, isAuthAvailable ? RegistrationStatus.REGISTERED : status);
playerCache.addRegistrationStatus(name, isAuthAvailable ? RegistrationStatus.REGISTERED : RegistrationStatus.UNREGISTERED);
if (isAuthAvailable) {
// Protect inventory
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
ProtectInventoryEvent ev = bukkitService.createAndCallEvent(
isAsync -> new ProtectInventoryEvent(player, isAsync));
if (ev.isCancelled()) {
player.updateInventory();
logger.fine("ProtectInventoryEvent has been cancelled for " + player.getName() + "...");
}
}
protectInventory(player);
// Session logic
if (sessionService.canResumeSession(player)) {
@ -160,6 +151,18 @@ public class AsynchronousJoin implements AsynchronousProcess {
processJoinSync(player, isAuthAvailable);
}
private void protectInventory(Player player) {
// Protect inventory
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
ProtectInventoryEvent ev = bukkitService.createAndCallEvent(
isAsync -> new ProtectInventoryEvent(player, isAsync));
if (ev.isCancelled()) {
player.updateInventory();
logger.fine("ProtectInventoryEvent has been cancelled for " + player.getName() + "...");
}
}
}
private void handlePlayerWithUnmetNameRestriction(Player player, String ip) {
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
player.kickPlayer(service.retrieveSingleMessage(player, MessageKey.NOT_OWNER_ERROR));

View File

@ -113,7 +113,8 @@ public class TeleportationService implements Reloadable {
return;
}
if (!player.hasPlayedBefore() || playerCache.getRegistrationStatus(player.getName()) == RegistrationStatus.UNREGISTERED) {
RegistrationStatus registrationStatus = playerCache.getRegistrationStatus(player.getName());
if (!player.hasPlayedBefore() || registrationStatus == RegistrationStatus.UNREGISTERED) {
logger.debug("Attempting to teleport player `{0}` to first spawn", player.getName());
performTeleportation(player, new FirstSpawnTeleportEvent(player, firstSpawn));
}