Search in sources :

Example 11 with PartiesPlugin

use of com.alessiodp.parties.common.PartiesPlugin in project Parties by AlessioDP.

the class CommandInvite method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party = ((PartiesCommandData) commandData).getParty();
    // Command handling
    User invitedPlayer = plugin.getPlayerByName(commandData.getArgs()[1]);
    if (invitedPlayer == null) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYEROFFLINE);
        return;
    }
    PartyPlayerImpl invitedPartyPlayer = getPlugin().getPlayerManager().getPlayer(invitedPlayer.getUUID());
    if (invitedPartyPlayer.isVanished()) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYEROFFLINE);
        return;
    }
    if (invitedPartyPlayer.getPlayerUUID().equals(sender.getUUID())) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_INVITE_YOURSELF);
        return;
    }
    if (invitedPartyPlayer.isInParty()) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYERINPARTY, invitedPartyPlayer);
        return;
    }
    if (ConfigParties.GENERAL_INVITE_PREVENTINVITEPERM && // Check if the user is inside the network (skip if Redis)
    invitedPlayer.isInsideNetwork() && !invitedPlayer.hasPermission(PartiesPermission.USER_ACCEPT)) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYERNOPERM, invitedPartyPlayer);
        return;
    }
    // Check for party, create one if option enabled
    if (party == null) {
        if (ConfigParties.GENERAL_INVITE_AUTO_CREATE_PARTY_UPON_INVITE && ConfigParties.GENERAL_NAME_DYNAMIC_ENABLE) {
            String partyName = CommandCreate.generateDynamicName(getPlugin(), partyPlayer);
            party = CommandCreate.createParty((PartiesPlugin) plugin, this, sender, partyPlayer, partyName, false);
            if (party == null || party.isFixed()) {
                sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_FAILED, invitedPartyPlayer);
                return;
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
            return;
        }
    }
    if (invitedPartyPlayer.getIgnoredParties().contains(party.getId())) {
        // Invited player ignoring the party, fake sent
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_SENT, invitedPartyPlayer);
        return;
    }
    if (invitedPartyPlayer.isMuted() && ConfigMain.ADDITIONAL_MUTE_ENABLE && ConfigMain.ADDITIONAL_MUTE_BLOCK_INVITE) {
        // Invited player has disabled notifications, fake sent
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_SENT, invitedPartyPlayer);
        return;
    }
    boolean isRevoke = false;
    final PartyImpl finalParty = party;
    Optional<PartyInvite> revokeInvite = invitedPartyPlayer.getPendingInvites().stream().filter(pv -> pv.getParty().getId().equals(finalParty.getId())).findAny();
    if (revokeInvite.isPresent()) {
        isRevoke = true;
        if (!ConfigParties.GENERAL_INVITE_REVOKE) {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_ALREADYINVITED, invitedPartyPlayer);
            return;
        }
    }
    boolean mustStartCooldown = false;
    if (!isRevoke && ConfigParties.GENERAL_INVITE_COOLDOWN_ENABLE && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_INVITE_BYPASS)) {
        // Check invited player cooldown
        RequestCooldown inviteAfterLeaveCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.INVITE_AFTER_LEAVE, invitedPlayer.getUUID(), party.getId());
        if (inviteAfterLeaveCooldown != null) {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_COOLDOWN_ON_LEAVE.replace("%seconds%", String.valueOf(inviteAfterLeaveCooldown.getWaitTime())));
            return;
        }
        // Check invite cooldown
        mustStartCooldown = true;
        RequestCooldown inviteCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), invitedPlayer.getUUID());
        if (inviteCooldown != null) {
            sendMessage(sender, partyPlayer, (inviteCooldown.isGlobal() ? Messages.MAINCMD_INVITE_COOLDOWN_GLOBAL : Messages.MAINCMD_INVITE_COOLDOWN_INDIVIDUAL).replace("%seconds%", String.valueOf(inviteCooldown.getCooldown() - inviteCooldown.getDiffTime())));
            return;
        }
    }
    // Command starts
    if (isRevoke) {
        // Revoke invite
        revokeInvite.get().revoke();
    } else {
        // Send invite
        party.invitePlayer(invitedPartyPlayer, partyPlayer);
        if (mustStartCooldown) {
            getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), null, ConfigParties.GENERAL_INVITE_COOLDOWN_GLOBAL);
            getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), invitedPartyPlayer.getPlayerUUID(), ConfigParties.GENERAL_INVITE_COOLDOWN_INDIVIDUAL);
        }
    }
    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_INVITE, partyPlayer.getName(), invitedPartyPlayer.getName(), party.getName() != null ? party.getName() : party.getId(), isRevoke), true);
}
Also used : CooldownManager(com.alessiodp.parties.common.parties.CooldownManager) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) PartiesPermission(com.alessiodp.parties.common.utils.PartiesPermission) CommandData(com.alessiodp.core.common.commands.utils.CommandData) Messages(com.alessiodp.parties.common.configuration.data.Messages) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) CommonCommands(com.alessiodp.parties.common.commands.list.CommonCommands) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) List(java.util.List) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) ADPMainCommand(com.alessiodp.core.common.commands.utils.ADPMainCommand) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) Optional(java.util.Optional) User(com.alessiodp.core.common.user.User) RequestCooldown(com.alessiodp.parties.common.players.objects.RequestCooldown) NotNull(org.jetbrains.annotations.NotNull) RankPermission(com.alessiodp.parties.common.utils.RankPermission) ADPPlugin(com.alessiodp.core.common.ADPPlugin) PartyInvite(com.alessiodp.parties.api.interfaces.PartyInvite) PartiesSubCommand(com.alessiodp.parties.common.commands.utils.PartiesSubCommand) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) PartyInvite(com.alessiodp.parties.api.interfaces.PartyInvite) RequestCooldown(com.alessiodp.parties.common.players.objects.RequestCooldown) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 12 with PartiesPlugin

use of com.alessiodp.parties.common.PartiesPlugin in project Parties by AlessioDP.

the class BungeePartiesCommandManager method registerCommands.

@Override
public void registerCommands() {
    mainCommands = new ArrayList<>();
    mainCommands.add(new BungeeCommandParty((PartiesPlugin) plugin));
    mainCommands.add(new BungeeCommandP((PartiesPlugin) plugin));
}
Also used : BungeeCommandP(com.alessiodp.parties.bungeecord.commands.main.BungeeCommandP) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) BungeeCommandParty(com.alessiodp.parties.bungeecord.commands.main.BungeeCommandParty)

Example 13 with PartiesPlugin

use of com.alessiodp.parties.common.PartiesPlugin in project Parties by AlessioDP.

the class BukkitPartiesBungeecordListener method handleUnloadParty.

public void handleUnloadParty(PartiesPacket packet) {
    PartyImpl party = ((PartiesPlugin) plugin).getPartyManager().getCacheParties().get(packet.getParty());
    if (party != null) {
        ((PartiesPlugin) plugin).getPartyManager().unloadParty(party);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_UNLOAD_PARTY, packet.getParty().toString()), true);
    }
}
Also used : PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 14 with PartiesPlugin

use of com.alessiodp.parties.common.PartiesPlugin in project Parties by AlessioDP.

the class PartiesRedisBungeeListener method handlePostPartyAddMember.

public void handlePostPartyAddMember(UUID partyId, UUID playerId, JoinCause cause, UUID inviterId) {
    // Remove party invite, if in this server, before party reload
    PartyImpl party = ((PartiesPlugin) plugin).getPartyManager().getCacheParties().get(partyId);
    if (party != null) {
        party.getInviteRequests().stream().filter(partyInvite -> partyInvite.getInvitedPlayer().getPlayerUUID().equals(playerId)).findAny().ifPresent(partyInvite -> partyInvite.timeout(false));
    }
    commonListener.handlePostPartyAddMember(partyId, playerId, cause, inviterId);
}
Also used : PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 15 with PartiesPlugin

use of com.alessiodp.parties.common.PartiesPlugin in project Parties by AlessioDP.

the class BukkitCommandHome method teleportPlayer.

@Override
protected void teleportPlayer(User player, PartyPlayerImpl partyPlayer, PartyHomeImpl home) {
    Location loc = new Location(Bukkit.getWorld(home.getWorld()), home.getX(), home.getY(), home.getZ(), home.getYaw(), home.getPitch());
    BukkitUser bukkitUser = (BukkitUser) plugin.getPlayer(partyPlayer.getPlayerUUID());
    if (bukkitUser != null)
        teleportToPartyHome((PartiesPlugin) plugin, partyPlayer, bukkitUser, home, loc);
}
Also used : PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) Location(org.bukkit.Location) BukkitUser(com.alessiodp.core.bukkit.user.BukkitUser)

Aggregations

PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)16 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)9 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)6 User (com.alessiodp.core.common.user.User)4 BukkitUser (com.alessiodp.core.bukkit.user.BukkitUser)2 ADPPlugin (com.alessiodp.core.common.ADPPlugin)2 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)2 PartiesConfigurationManager (com.alessiodp.parties.common.configuration.PartiesConfigurationManager)2 PartiesPacket (com.alessiodp.parties.common.messaging.PartiesPacket)2 PartyHomeImpl (com.alessiodp.parties.common.parties.objects.PartyHomeImpl)2 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)2 Location (org.bukkit.Location)2 ADPMainCommand (com.alessiodp.core.common.commands.utils.ADPMainCommand)1 CommandData (com.alessiodp.core.common.commands.utils.CommandData)1 LoggerManager (com.alessiodp.core.common.logging.LoggerManager)1 DeleteCause (com.alessiodp.parties.api.enums.DeleteCause)1 JoinCause (com.alessiodp.parties.api.enums.JoinCause)1 LeaveCause (com.alessiodp.parties.api.enums.LeaveCause)1 IPartyGetExperienceEvent (com.alessiodp.parties.api.events.common.party.IPartyGetExperienceEvent)1 IPartyLevelUpEvent (com.alessiodp.parties.api.events.common.party.IPartyLevelUpEvent)1