Search in sources :

Example 6 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity 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)

Example 7 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.

the class PartyPlayerEntity method sendMessage.

public void sendMessage(String message, PartyPlayerEntity victim) {
    if (message == null || message.isEmpty())
        return;
    PartyEntity party = plugin.getPartyManager().getParty(getPartyName());
    String formattedMessage = PartiesUtils.convertAllPlaceholders(message, party, victim);
    send(formattedMessage);
}
Also used : PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 8 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.

the class CommandInfo method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    String partyName;
    if (commandData.getArgs().length > 1) {
        if (!commandData.havePermission(PartiesPermission.INFO_OTHERS)) {
            pp.sendNoPermission(PartiesPermission.INFO_OTHERS);
            return;
        }
        partyName = commandData.getArgs()[1];
    } else if (!pp.getPartyName().isEmpty()) {
        partyName = pp.getPartyName();
    } else {
        pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
        return;
    }
    PartyEntity party = plugin.getPartyManager().getParty(partyName);
    if (party == null) {
        pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", partyName));
        return;
    }
    /*
		 * Command starts
		 */
    StringBuilder sb = new StringBuilder();
    for (String str : Messages.MAINCMD_INFO_CONTENT) sb.append(str + "\n");
    String text = sb.toString();
    Matcher mat = Pattern.compile("%list_(.*?)%").matcher(text);
    while (mat.find()) {
        Rank rr = plugin.getRankManager().searchRankByHardName(mat.group().substring(6, mat.group().length() - 1));
        if (rr != null) {
            StringBuilder list = new StringBuilder();
            int counter = 0;
            for (UUID playerUUID : party.getMembers()) {
                PartyPlayer pl = plugin.getPlayerManager().getPlayer(playerUUID);
                // Check rank level
                if (pl.getRank() == rr.getLevel()) {
                    if (list.length() > 0) {
                        list.append(Messages.MAINCMD_INFO_LIST_SEPARATOR);
                    }
                    OfflinePlayer op = Bukkit.getOfflinePlayer(pl.getPlayerUUID());
                    if (op != null)
                        list.append((op.isOnline() && !PartiesUtils.isVanished((Player) op) ? Messages.MAINCMD_INFO_LIST_ONLINEPREFIX : Messages.MAINCMD_INFO_LIST_OFFLINEPREFIX) + pl.getName());
                    else
                        list.append(Messages.MAINCMD_INFO_LIST_UNKNOWN);
                    counter++;
                }
            }
            text = text.replace(mat.group(), list.toString().isEmpty() ? Messages.MAINCMD_INFO_LIST_EMPTY : list.toString());
            text = text.replace("%number_" + mat.group().substring(6, mat.group().length() - 1) + "%", Integer.toString(counter));
        }
    }
    int numOnlinePlayers = party.getNumberOnlinePlayers();
    sb = new StringBuilder();
    if (text.contains("%online%")) {
        if (numOnlinePlayers == 0)
            sb.append(Messages.MAINCMD_INFO_LIST_EMPTY);
        else {
            for (Player pl : party.getOnlinePlayers()) {
                if (sb.length() > 0) {
                    sb.append(Messages.MAINCMD_INFO_LIST_SEPARATOR);
                }
                if (!PartiesUtils.isVanished(pl))
                    sb.append(Messages.MAINCMD_INFO_LIST_ONLINEPREFIX + pl.getName());
            }
        }
        text = text.replace("%online%", sb.toString());
    }
    text = PartiesUtils.convertPartyPlaceholders(text, party, Messages.MAINCMD_INFO_LIST_EMPTY);
    pp.sendMessage(text);
    LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_INFO.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) Matcher(java.util.regex.Matcher) OfflinePlayer(org.bukkit.OfflinePlayer) Rank(com.alessiodp.partiesapi.interfaces.Rank) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) UUID(java.util.UUID)

Example 9 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.

the class CommandInvite method preRequisites.

@Override
public boolean preRequisites(CommandData commandData) {
    Player player = (Player) commandData.getSender();
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
    /*
		 * Checks for command prerequisites
		 */
    if (!player.hasPermission(PartiesPermission.INVITE.toString())) {
        pp.sendNoPermission(PartiesPermission.INVITE);
        return false;
    }
    PartyEntity party = pp.getPartyName().isEmpty() ? null : plugin.getPartyManager().getParty(pp.getPartyName());
    if (party == null) {
        pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
        return false;
    }
    if (!PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_INVITE))
        return false;
    if (commandData.getArgs().length != 2) {
        pp.sendMessage(Messages.MAINCMD_INVITE_WRONGCMD);
        return false;
    }
    if ((ConfigParties.GENERAL_MEMBERSLIMIT != -1) && (party.getMembers().size() >= ConfigParties.GENERAL_MEMBERSLIMIT)) {
        pp.sendMessage(Messages.PARTIES_COMMON_PARTYFULL);
        return false;
    }
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    commandData.setParty(party);
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 10 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.

the class CommandLeave method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command starts
		 */
    // Calling API event
    PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(pp, party, false, null);
    Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
    if (!partiesLeaveEvent.isCancelled()) {
        if (party.getLeader().equals(pp.getPlayerUUID())) {
            // Is leader
            // Calling Pre API event
            PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.LEAVE, null, pp);
            Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
            if (!partiesPreDeleteEvent.isCancelled()) {
                // Disbanding party
                pp.sendMessage(Messages.MAINCMD_LEAVE_LEFT, party);
                party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_DISBANDED);
                party.removeParty();
                party.callChange();
                // Calling Post API event
                PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.LEAVE, null, pp);
                Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
                LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_LEAVE_DISBAND.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
            } else
                LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
        } else {
            party.getMembers().remove(pp.getPlayerUUID());
            party.getOnlinePlayers().remove(commandData.getPlayer());
            pp.cleanupPlayer(true);
            pp.sendMessage(Messages.MAINCMD_LEAVE_LEFT, party);
            party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_BROADCAST);
            party.updateParty();
            party.callChange();
            LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_LEAVE.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
        }
    } else
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
}
Also used : PartiesPartyPostDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesPartyPreDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) PartiesPlayerLeaveEvent(com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)67 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)56 Player (org.bukkit.entity.Player)31 EventHandler (org.bukkit.event.EventHandler)11 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)6 Status (com.alessiodp.partiesapi.enums.Status)5 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)5 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)5 UUID (java.util.UUID)5 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)3 Party (com.alessiodp.partiesapi.objects.Party)3 ArrayList (java.util.ArrayList)3 PartiesPlaceholder (com.alessiodp.parties.addons.internal.PartiesPlaceholder)2 ChatTask (com.alessiodp.parties.tasks.ChatTask)2 PartiesChatEvent (com.alessiodp.partiesapi.events.PartiesChatEvent)2 PartiesFriendlyFireBlockedEvent (com.alessiodp.partiesapi.events.PartiesFriendlyFireBlockedEvent)2 Rank (com.alessiodp.partiesapi.interfaces.Rank)2 Matcher (java.util.regex.Matcher)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 Result (com.alessiodp.parties.addons.external.GriefPreventionHandler.Result)1