Search in sources :

Example 1 with FinishedLoadingPlayerEvent

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);
}
Also used : LPlayer(biz.princeps.landlord.persistent.LPlayer) FinishedLoadingPlayerEvent(biz.princeps.landlord.api.events.FinishedLoadingPlayerEvent) LPlayer(biz.princeps.landlord.persistent.LPlayer) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) FinishedLoadingPlayerEvent(biz.princeps.landlord.api.events.FinishedLoadingPlayerEvent) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) Event(org.bukkit.event.Event) List(java.util.List) EventHandler(org.bukkit.event.EventHandler)

Aggregations

FinishedLoadingPlayerEvent (biz.princeps.landlord.api.events.FinishedLoadingPlayerEvent)1 LPlayer (biz.princeps.landlord.persistent.LPlayer)1 List (java.util.List)1 Player (org.bukkit.entity.Player)1 Event (org.bukkit.event.Event)1 EventHandler (org.bukkit.event.EventHandler)1 PlayerJoinEvent (org.bukkit.event.player.PlayerJoinEvent)1 PlayerQuitEvent (org.bukkit.event.player.PlayerQuitEvent)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1