Refactor PlayerLoginProcessEvent

This is technically a breaking change, but I'm fairly sure I'm the only person using this event. It's quite obscure ;p
This commit is contained in:
Luck 2019-01-02 13:54:55 +00:00
parent a0d04790a5
commit 6fc2321fad
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
7 changed files with 49 additions and 23 deletions

View File

@ -23,29 +23,36 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event.user;
package me.lucko.luckperms.api.event.player;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.api.event.Param;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.UUID;
/**
* Called when LuckPerms has finished processing a certain Player's connection.
* Called when LuckPerms has finished processing a Player's initial connection.
*
* <p>This event will always execute during the platforms async login/auth event.
* All handlers will be called instantly.</p>
* <p>This event will always execute during the platforms async connection
* event. The LuckPerms platform listener processing the connection will block
* while this event is posted.</p>
*
* <p>This, among other things, allows you to wait until permission data is loaded
* for a User during the BungeeCord 'LoginEvent', as event priorities are ignored
* by the current implementation.</p>
* <p>This, among other things, allows you to wait until permission data is
* loaded for a User during the BungeeCord 'LoginEvent', as event priorities are
* ignored by the current implementation.</p>
*
* @since 3.4
* <p>The implementation will make an attempt to ensure this event is called
* for all connections, even if the operation to load User data was not
* successful. Note that LuckPerms will usually cancel the platform connection
* event if data could not be loaded.</p>
*
* @since 4.4
*/
public interface UserLoginProcessEvent extends LuckPermsEvent {
public interface PlayerLoginProcessEvent extends LuckPermsEvent {
/**
* Gets the UUID of the connection which was processed
@ -61,11 +68,23 @@ public interface UserLoginProcessEvent extends LuckPermsEvent {
*/
@NonNull @Param(1) String getUsername();
/**
* Gets if the login was processed successfully.
*
* @return true if the login was successful
*/
default boolean wasSuccessful() {
return getUser() != null;
}
/**
* Gets the resultant User instance which was loaded.
*
* <p>Returns {@code null} if the login was not processed
* {@link #wasSuccessful() successfully.}</p>
*
* @return the user instance
*/
@NonNull @Param(2) User getUser();
@Nullable @Param(2) User getUser();
}

View File

@ -86,8 +86,8 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
- setting up cached data. */
try {
User user = loadUser(e.getUniqueId(), e.getName());
this.plugin.getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
recordConnection(e.getUniqueId());
this.plugin.getEventFactory().handlePlayerLoginProcess(e.getUniqueId(), e.getName(), user);
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUniqueId() + " - " + e.getName());
ex.printStackTrace();
@ -95,6 +95,7 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
// deny the connection
this.deniedAsyncLogin.add(e.getUniqueId());
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager()));
this.plugin.getEventFactory().handlePlayerLoginProcess(e.getUniqueId(), e.getName(), null);
}
}

View File

@ -82,8 +82,8 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
- setting up cached data. */
try {
User user = loadUser(c.getUniqueId(), c.getName());
this.plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
recordConnection(c.getUniqueId());
this.plugin.getEventFactory().handlePlayerLoginProcess(c.getUniqueId(), c.getName(), user);
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + c.getUniqueId() + " - " + c.getName());
ex.printStackTrace();
@ -94,6 +94,7 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager())));
e.setCancelled(true);
}
this.plugin.getEventFactory().handlePlayerLoginProcess(c.getUniqueId(), c.getName(), null);
}
// finally, complete our intent to modify state, so the proxy can continue handling the connection.

View File

@ -52,6 +52,7 @@ import me.lucko.luckperms.api.event.node.NodeAddEvent;
import me.lucko.luckperms.api.event.node.NodeClearEvent;
import me.lucko.luckperms.api.event.node.NodeRemoveEvent;
import me.lucko.luckperms.api.event.player.PlayerDataSaveEvent;
import me.lucko.luckperms.api.event.player.PlayerLoginProcessEvent;
import me.lucko.luckperms.api.event.source.Source;
import me.lucko.luckperms.api.event.sync.ConfigReloadEvent;
import me.lucko.luckperms.api.event.sync.PostSyncEvent;
@ -68,7 +69,6 @@ import me.lucko.luckperms.api.event.user.UserCacheLoadEvent;
import me.lucko.luckperms.api.event.user.UserDataRecalculateEvent;
import me.lucko.luckperms.api.event.user.UserFirstLoginEvent;
import me.lucko.luckperms.api.event.user.UserLoadEvent;
import me.lucko.luckperms.api.event.user.UserLoginProcessEvent;
import me.lucko.luckperms.api.event.user.track.UserDemoteEvent;
import me.lucko.luckperms.api.event.user.track.UserPromoteEvent;
import me.lucko.luckperms.common.api.implementation.ApiPermissionHolder;
@ -121,7 +121,7 @@ public final class EventFactory {
return;
}
T event = supplier.get();
this.eventBus.post(event);
post(event);
});
}
@ -280,6 +280,14 @@ public final class EventFactory {
post(UserFirstLoginEvent.class, () -> generate(UserFirstLoginEvent.class, uuid, username));
}
public void handlePlayerLoginProcess(UUID uuid, String username, User user) {
if (!shouldPost(PlayerLoginProcessEvent.class)) {
return;
}
post(generate(PlayerLoginProcessEvent.class, uuid, username, new ApiUser(user)));
}
public void handlePlayerDataSave(UUID uuid, String username, PlayerSaveResult result) {
post(PlayerDataSaveEvent.class, () -> generate(PlayerDataSaveEvent.class, uuid, username, result));
}
@ -288,10 +296,6 @@ public final class EventFactory {
post(UserLoadEvent.class, () -> generate(UserLoadEvent.class, new ApiUser(user)));
}
public void handleUserLoginProcess(UUID uuid, String username, User user) {
post(UserLoginProcessEvent.class, () -> generate(UserLoginProcessEvent.class, uuid, username, new ApiUser(user)));
}
public void handleUserDemote(User user, Track track, String from, String to, @Nullable Sender source) {
post(UserDemoteEvent.class, () -> {
Source s = source == null ? UnknownSource.INSTANCE : new EntitySourceImpl(new SenderEntity(source));

View File

@ -77,8 +77,8 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme
- setting up cached data. */
try {
User user = loadUser(e.getUuid(), e.getName());
this.plugin.getEventFactory().handleUserLoginProcess(e.getUuid(), e.getName(), user);
recordConnection(e.getUuid());
this.plugin.getEventFactory().handlePlayerLoginProcess(e.getUuid(), e.getName(), user);
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUuid() + " - " + e.getName());
ex.printStackTrace();
@ -86,6 +86,7 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme
// deny the connection
this.deniedAsyncLogin.add(e.getUuid());
e.disAllow(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager()));
this.plugin.getEventFactory().handlePlayerLoginProcess(e.getUuid(), e.getName(), null);
}
}

View File

@ -79,8 +79,8 @@ public class SpongeConnectionListener extends AbstractConnectionListener {
- setting up cached data. */
try {
User user = loadUser(profile.getUniqueId(), username);
this.plugin.getEventFactory().handleUserLoginProcess(profile.getUniqueId(), username, user);
recordConnection(profile.getUniqueId());
this.plugin.getEventFactory().handlePlayerLoginProcess(profile.getUniqueId(), username, user);
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName());
ex.printStackTrace();
@ -91,6 +91,7 @@ public class SpongeConnectionListener extends AbstractConnectionListener {
e.setMessageCancelled(false);
//noinspection deprecation
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager())));
this.plugin.getEventFactory().handlePlayerLoginProcess(profile.getUniqueId(), username, null);
}
}

View File

@ -86,11 +86,9 @@ public class VelocityConnectionListener extends AbstractConnectionListener {
- setting up cached data. */
try {
User user = loadUser(p.getUniqueId(), p.getUsername());
this.plugin.getEventFactory().handleUserLoginProcess(p.getUniqueId(), p.getUsername(), user);
recordConnection(p.getUniqueId());
// set permission provider
e.setProvider(new PlayerPermissionProvider(p, user, this.plugin.getContextManager().getCacheFor(p)));
this.plugin.getEventFactory().handlePlayerLoginProcess(p.getUniqueId(), p.getUsername(), user);
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + p.getUniqueId() + " - " + p.getUsername());
ex.printStackTrace();
@ -100,6 +98,7 @@ public class VelocityConnectionListener extends AbstractConnectionListener {
// cancel the login attempt
this.deniedLogin.add(p.getUniqueId());
}
this.plugin.getEventFactory().handlePlayerLoginProcess(p.getUniqueId(), p.getUsername(), null);
}
}