Search in sources :

Example 1 with MotdTask

use of com.alessiodp.parties.tasks.MotdTask in project Parties by AlessioDP.

the class JoinLeaveListener method onPlayerJoin.

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onPlayerJoin(PlayerJoinEvent event) {
    // Make it async
    plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
        Player player = event.getPlayer();
        PartyPlayerEntity pp = plugin.getPlayerManager().loadPlayer(player.getUniqueId());
        // None database: stop deleting player/party
        if (plugin.getDatabaseManager().getDatabaseType().isNone() && plugin.getPlayerManager().getListPartyPlayersToDelete().contains(player.getUniqueId()))
            plugin.getPlayerManager().getListPartyPlayersToDelete().remove(player.getUniqueId());
        // Spy listener
        if (pp.isSpy())
            plugin.getSpyManager().addSpy(pp.getPlayerUUID());
        // Party checking
        if (!pp.getPartyName().isEmpty() || ConfigParties.FIXED_DEFAULT_ENABLE) {
            PartyEntity party = plugin.getPartyManager().loadParty(pp.getPartyName());
            if (party != null) {
                // Party found
                party.getOnlinePlayers().add(player);
                if (plugin.getPartyManager().getListPartiesToDelete().containsKey(party.getName().toLowerCase())) {
                    Bukkit.getScheduler().cancelTask(plugin.getPartyManager().getListPartiesToDelete().get(party.getName().toLowerCase()));
                    plugin.getPartyManager().getListPartiesToDelete().remove(party.getName().toLowerCase());
                    LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_DELETE_STOP.replace("{party}", party.getName()), true);
                }
                if (!party.getMotd().isEmpty())
                    new MotdTask(plugin, player, pp.getCreateID()).runTaskLater(plugin, ConfigParties.MOTD_DELAY);
                LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PLAYER_JOIN.replace("{player}", player.getName()).replace("{party}", party.getName()), true);
            } else {
                // Party not found - checking for default one
                if (ConfigParties.FIXED_DEFAULT_ENABLE) {
                    party = plugin.getPartyManager().loadParty(ConfigParties.FIXED_DEFAULT_PARTY);
                    if (party != null) {
                        party.getMembers().add(pp.getPlayerUUID());
                        party.getOnlinePlayers().add(player);
                        pp.setPartyName(party.getName());
                        pp.setRank(ConfigParties.RANK_SET_DEFAULT);
                        party.updateParty();
                        pp.updatePlayer();
                        if (!party.getMotd().isEmpty())
                            new MotdTask(plugin, player, pp.getCreateID()).runTaskLater(plugin, ConfigParties.MOTD_DELAY);
                        pp.sendMessage(Messages.OTHER_FIXED_DEFAULTJOIN, party);
                        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_PLAYER_JOIN_DEFAULTJOIN.replace("{player}", player.getName()).replace("{party}", party.getName()), true);
                    } else {
                        LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_PLAYER_JOIN_DEFAULTFAIL.replace("{party}", ConfigParties.FIXED_DEFAULT_PARTY), true, ConsoleColor.RED);
                    }
                }
            }
            if (ConfigMain.PARTIES_JLMESSAGES && party != null) {
                party.sendBroadcast(pp, Messages.OTHER_JOINLEAVE_SERVERJOIN);
            }
        }
        if (ConfigMain.PARTIES_UPDATES_WARN && player.hasPermission(PartiesPermission.ADMIN_UPDATES.toString())) {
            if (!ADPUpdater.getFoundVersion().isEmpty()) {
                pp.sendMessage(Messages.PARTIES_UPDATEAVAILABLE.replace("%version%", ADPUpdater.getFoundVersion()).replace("%thisversion%", plugin.getDescription().getVersion()));
            }
        }
    });
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) MotdTask(com.alessiodp.parties.tasks.MotdTask) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)1 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)1 MotdTask (com.alessiodp.parties.tasks.MotdTask)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1