Search in sources :

Example 6 with PartyPlayerEntity

use of com.alessiodp.parties.players.objects.PartyPlayerEntity 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 PartyPlayerEntity

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

the class PartyEntity method acceptInvite.

public void acceptInvite(UUID to) {
    plugin.getServer().getScheduler().cancelTask(invited.get(to));
    UUID from = whoInvite.get(to);
    PartyPlayerEntity fromPp = plugin.getPlayerManager().getPlayer(from);
    PartyPlayerEntity toPp = plugin.getPlayerManager().getPlayer(to);
    // Calling API Event
    PartiesPlayerJoinEvent partiesJoinEvent = new PartiesPlayerJoinEvent(toPp, this, true, from);
    Bukkit.getServer().getPluginManager().callEvent(partiesJoinEvent);
    if (!partiesJoinEvent.isCancelled()) {
        // Send accepted
        fromPp.sendMessage(Messages.MAINCMD_ACCEPT_ACCEPTRECEIPT, toPp);
        // Send you accepted
        toPp.sendMessage(Messages.MAINCMD_ACCEPT_ACCEPTED, fromPp);
        whoInvite.remove(to);
        invited.remove(to);
        toPp.setLastInvite("");
        sendBroadcast(toPp, Messages.MAINCMD_ACCEPT_BROADCAST);
        getMembers().add(to);
        onlinePlayers.add(toPp.getPlayer());
        toPp.setPartyName(getName());
        toPp.setRank(ConfigParties.RANK_SET_DEFAULT);
        updateParty();
        toPp.updatePlayer();
        callChange();
    } else
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_JOINEVENT_DENY.replace("{player}", toPp.getName()).replace("{party}", getName()), true);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) UUID(java.util.UUID) PartiesPlayerJoinEvent(com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent)

Example 8 with PartyPlayerEntity

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

the class PartyEntity method removeParty.

public void removeParty() {
    plugin.getPartyManager().getListParties().remove(getName().toLowerCase());
    DynmapHandler.removeMarker(getName());
    plugin.getDatabaseManager().removeParty(this);
    plugin.getTagManager().deleteTag(this);
    LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PARTY_REMOVED.replace("{party}", getName()), true);
    for (UUID uuid : getMembers()) {
        PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(uuid);
        pp.cleanupPlayer(true);
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) UUID(java.util.UUID)

Example 9 with PartyPlayerEntity

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

the class CommandIgnore method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    boolean isPrompt = false;
    String ignoredParty = "";
    if (commandData.getArgs().length == 1) {
        // Shows ignore list
        isPrompt = true;
    } else {
        // Edit party ignore
        if (commandData.getArgs().length > 2) {
            pp.sendMessage(Messages.MAINCMD_IGNORE_WRONGCMD);
            return;
        }
        ignoredParty = commandData.getArgs()[1];
        if (!plugin.getPartyManager().existParty(ignoredParty)) {
            pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", ignoredParty));
            return;
        }
    }
    /*
		 * Command starts
		 */
    if (isPrompt) {
        StringBuilder builder = new StringBuilder();
        for (String name : pp.getIgnoredParties()) {
            if (builder.length() > 0) {
                builder.append(Messages.MAINCMD_IGNORE_LIST_SEPARATOR);
            }
            builder.append(Messages.MAINCMD_IGNORE_LIST_PARTYPREFIX + name);
        }
        String ignores = builder.toString();
        if (pp.getIgnoredParties().size() == 0 || ignores == null)
            ignores = Messages.MAINCMD_IGNORE_LIST_EMPTY;
        pp.sendMessage(Messages.MAINCMD_IGNORE_LIST_HEADER.replace("%number%", Integer.toString(pp.getIgnoredParties().size())));
        pp.sendMessage(ignores);
    } else {
        if (pp.getIgnoredParties().contains(ignoredParty)) {
            // Remove
            pp.getIgnoredParties().remove(ignoredParty);
            pp.sendMessage(Messages.MAINCMD_IGNORE_STOP.replace("%party%", ignoredParty));
            LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_IGNORE_START.replace("{player}", pp.getName()).replace("{party}", ignoredParty), true);
        } else {
            // Add
            pp.getIgnoredParties().add(ignoredParty);
            pp.sendMessage(Messages.MAINCMD_IGNORE_START.replace("%party%", ignoredParty));
            LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_IGNORE_STOP.replace("{player}", pp.getName()).replace("{party}", ignoredParty), true);
        }
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity)

Example 10 with PartyPlayerEntity

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

the class CommandIgnore 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.IGNORE.toString())) {
        pp.sendNoPermission(PartiesPermission.IGNORE);
        return false;
    }
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity)

Aggregations

PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)92 PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)56 Player (org.bukkit.entity.Player)53 EventHandler (org.bukkit.event.EventHandler)13 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)9 UUID (java.util.UUID)8 ArrayList (java.util.ArrayList)6 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)4 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)4 OfflinePlayer (org.bukkit.OfflinePlayer)4 Status (com.alessiodp.partiesapi.enums.Status)3 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)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 PartiesPlayerJoinEvent (com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent)2 Rank (com.alessiodp.partiesapi.interfaces.Rank)2 Matcher (java.util.regex.Matcher)2 Result (com.alessiodp.parties.addons.external.GriefPreventionHandler.Result)1