use of biz.princeps.landlord.api.events.FinishedLoadingPlayerEvent in project LandLord by SpatiumPrinceps.
the class JoinListener method onJoin.
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
new BukkitRunnable() {
@Override
public void run() {
List<Object> lPlayer = plugin.getDatabaseAPI().retrieveObjects(LPlayer.class, new Conditions.Builder().addCondition("uuid", p.getUniqueId().toString()).create());
LPlayer lp;
if (lPlayer.size() > 0)
lp = (LPlayer) lPlayer.get(0);
else
lp = new LPlayer(p.getUniqueId());
if (lp.getName() == null || lp.getName().isEmpty() || !p.getName().equals(lp.getName())) {
lp.setName(p.getName());
}
plugin.getPlayerManager().add(p.getUniqueId(), lp);
// The next to lines are needed to protect claiming of "inactive" lands although the owner is online right now
// might just be a rare never happening edge case, but lets be safe
plugin.getPlayerManager().get(p.getUniqueId()).setLastSeen(LocalDateTime.now());
plugin.getPlayerManager().save(p.getUniqueId());
Event event = new FinishedLoadingPlayerEvent(p, lp);
Bukkit.getPluginManager().callEvent(event);
}
}.runTaskAsynchronously(plugin);
}
Aggregations