Delay GeoIP join task to ensure display name is set (#3968)

Delays the GeoIP join messages by 2 ticks to ensure the user's display name has been set by Essentials' `DelayedJoin` task.

Fixes #2388.
This commit is contained in:
Josh Roy 2021-03-06 14:22:00 -05:00 committed by GitHub
parent 00b71cafc9
commit c41bb0ec42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import com.earth2me.essentials.utils.VersionUtil;
import io.papermc.lib.PaperLib;
import net.ess3.api.IEssentials;
import net.ess3.api.events.AfkStatusChangeEvent;
import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent;
import org.bukkit.BanEntry;
import org.bukkit.BanList;
import org.bukkit.GameMode;
@ -306,6 +307,8 @@ public class EssentialsPlayerListener implements Listener {
user.setDisplayNick();
updateCompass(user);
ess.runTaskAsynchronously(() -> ess.getServer().getPluginManager().callEvent(new AsyncUserDataLoadEvent(user)));
if (!ess.getVanishedPlayersNew().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
for (final String p : ess.getVanishedPlayersNew()) {
final Player toVanish = ess.getServer().getPlayerExact(p);

View File

@ -0,0 +1,33 @@
package net.essentialsx.api.v2.events;
import net.ess3.api.IUser;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Called during player login after the user's data has been loaded.
* This is useful for printing login messages once EssentialsX has updated a player's display name.
*/
public class AsyncUserDataLoadEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final IUser user;
public AsyncUserDataLoadEvent(IUser user) {
super(true);
this.user = user;
}
public IUser getUser() {
return user;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -11,11 +11,11 @@ import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CityResponse;
import com.maxmind.geoip2.model.CountryResponse;
import net.ess3.api.IEssentials;
import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent;
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 java.io.File;
import java.io.FileOutputStream;
@ -53,8 +53,9 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf {
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(final PlayerJoinEvent event) {
ess.runTaskAsynchronously(() -> delayedJoin(event.getPlayer()));
public void onDataLoad(final AsyncUserDataLoadEvent event) {
// Already async so just jump right into it.
delayedJoin(event.getUser().getBase());
}
private void delayedJoin(final Player player) {