Search in sources :

Example 81 with PartyImpl

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

the class VelocityCommandHome method teleportToPartyHome.

public static void teleportToPartyHome(PartiesPlugin plugin, User player, PartyPlayerImpl partyPlayer, PartyHomeImpl home) {
    PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
    if (home.getServer() != null && !home.getServer().isEmpty()) {
        boolean serverChange = false;
        RegisteredServer server = ((ADPVelocityBootstrap) plugin.getBootstrap()).getServer().getServer(home.getServer()).orElse(null);
        IPlayerPreHomeEvent partiesPreHomeEvent = plugin.getEventManager().preparePlayerPreHomeEvent(partyPlayer, party, home);
        plugin.getEventManager().callEvent(partiesPreHomeEvent);
        if (!partiesPreHomeEvent.isCancelled()) {
            if (VelocityConfigParties.ADDITIONAL_HOME_CROSS_SERVER && !((VelocityUser) player).getServerName().equalsIgnoreCase(home.getServer())) {
                if (server == null) {
                    plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_CMD_HOME_NO_SERVER, home));
                    return;
                }
                ((VelocityUser) player).connectTo(server);
                serverChange = true;
            }
            String message = plugin.getMessageUtils().convertPlaceholders(Messages.ADDCMD_HOME_TELEPORTED, partyPlayer, party);
            if (serverChange) {
                plugin.getScheduler().scheduleAsyncLater(() -> ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message), VelocityConfigParties.ADDITIONAL_HOME_CROSS_SERVER_DELAY, TimeUnit.MILLISECONDS);
            } else {
                ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message);
            }
            IPlayerPostHomeEvent partiesPostHomeEvent = plugin.getEventManager().preparePlayerPostHomeEvent(partyPlayer, party, home);
            plugin.getEventManager().callEvent(partiesPostHomeEvent);
        } else
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_HOMEEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else {
        plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_HOME_NO_SERVER, party.getId()));
    }
}
Also used : ADPVelocityBootstrap(com.alessiodp.core.velocity.bootstrap.ADPVelocityBootstrap) IPlayerPostHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent) IPlayerPreHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) VelocityPartiesMessageDispatcher(com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher) VelocityUser(com.alessiodp.core.velocity.user.VelocityUser) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 82 with PartyImpl

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

the class VelocityCommandTeleport method teleportSinglePlayer.

public static void teleportSinglePlayer(PartiesPlugin plugin, PartyPlayerImpl player, PartyPlayerImpl targetPlayer, RegisteredServer server) {
    Player velocityPlayer = ((VelocityPartiesBootstrap) plugin.getBootstrap()).getServer().getPlayer(player.getPlayerUUID()).orElse(null);
    if (velocityPlayer != null) {
        PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
        IPlayerPreTeleportEvent partiesPreTeleportEvent = plugin.getEventManager().preparePlayerPreTeleportEvent(player, party, server);
        plugin.getEventManager().callEvent(partiesPreTeleportEvent);
        if (!partiesPreTeleportEvent.isCancelled()) {
            velocityPlayer.getCurrentServer().ifPresent(serverConnection1 -> {
                boolean serverChange = false;
                if (!serverConnection1.getServer().equals(server)) {
                    serverChange = true;
                    velocityPlayer.createConnectionRequest(server);
                }
                User velocityUser = plugin.getPlayer(player.getPlayerUUID());
                if (velocityUser != null) {
                    if (serverChange) {
                        plugin.getScheduler().scheduleAsyncLater(() -> ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(velocityUser, targetPlayer), VelocityConfigParties.ADDITIONAL_TELEPORT_EXACT_LOCATION_DELAY, TimeUnit.MILLISECONDS);
                    } else {
                        ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(velocityUser, targetPlayer);
                    }
                    player.sendMessage(Messages.ADDCMD_TELEPORT_PLAYER_TELEPORTED, targetPlayer);
                    IPlayerPostTeleportEvent partiesPostTeleportEvent = plugin.getEventManager().preparePlayerPostTeleportEvent(player, party, server);
                    plugin.getEventManager().callEvent(partiesPostTeleportEvent);
                }
            });
        } else
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_TELEPORTEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
    }
}
Also used : IPlayerPreTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent) PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) Player(com.velocitypowered.api.proxy.Player) User(com.alessiodp.core.common.user.User) VelocityPartiesMessageDispatcher(com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher) IPlayerPostTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostTeleportEvent) VelocityPartiesBootstrap(com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 83 with PartyImpl

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

the class MotdTask method run.

@Override
public void run() {
    PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(playerUUID);
    User sender = plugin.getPlayer(playerUUID);
    if (sender != null && ConfigParties.ADDITIONAL_MOTD_ENABLE && createID.equals(partyPlayer.getCreateID())) {
        PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
        if (party != null && party.getMotd() != null && !party.getMotd().isEmpty()) {
            // Formatting motd
            String motd = party.getMotd();
            motd = motd.replace(ConfigParties.ADDITIONAL_MOTD_NEWLINECODE, "\n");
            for (String line : Messages.ADDCMD_MOTD_CONTENT) {
                // Used to bypass tags from convertAllPlaceholders
                line = line.replace("%motd%", "%temporary_motd%");
                line = plugin.getMessageUtils().convertPlaceholders(line, partyPlayer, party);
                line = Color.translateAlternateColorCodes(line);
                line = line.replace("%temporary_motd%", motd);
                partyPlayer.sendMessage(line);
            }
        }
    }
}
Also used : User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 84 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl 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 85 with PartyImpl

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

the class CommandJoin method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    // Command handling
    String partyName = commandData.getArgs()[1];
    PartyImpl party = getPlugin().getPartyManager().getParty(partyName);
    if (party == null) {
        sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", partyName));
        return;
    }
    if (commandData.getArgs().length == 2) {
        if (!commandData.havePermission(PartiesPermission.ADMIN_JOIN_BYPASS)) {
            if (ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_ENABLE && !party.isOpen()) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_CANNOT_JOIN);
                return;
            }
            if (ConfigParties.ADDITIONAL_JOIN_PASSWORD_ENABLE && party.getPassword() != null) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_PASSWORD_WRONGPASSWORD);
                return;
            }
        }
    } else if (commandData.getArgs().length == 3 && ConfigParties.ADDITIONAL_JOIN_PASSWORD_ENABLE) {
        if (!PasswordUtils.hashText(commandData.getArgs()[2]).equals(party.getPassword())) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_PASSWORD_WRONGPASSWORD);
            return;
        }
    } else {
        sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
        return;
    }
    if (party.isFull()) {
        sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYFULL);
        return;
    }
    if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.JOIN, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    // Command starts
    // Calling API Event
    IPlayerPreJoinEvent partiesPreJoinEvent = getPlugin().getEventManager().preparePlayerPreJoinEvent(partyPlayer, party, JoinCause.JOIN, partyPlayer);
    getPlugin().getEventManager().callEvent(partiesPreJoinEvent);
    if (!partiesPreJoinEvent.isCancelled()) {
        party.addMember(partyPlayer, JoinCause.JOIN, partyPlayer);
        sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_JOINED);
        party.broadcastMessage(Messages.ADDCMD_JOIN_PLAYERJOINED, partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_JOIN, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_JOINEVENT_DENY, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
Also used : User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) IPlayerPreJoinEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreJoinEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)106 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)75 User (com.alessiodp.core.common.user.User)39 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)31 ADPPlugin (com.alessiodp.core.common.ADPPlugin)11 UUID (java.util.UUID)11 ConfigMain (com.alessiodp.parties.common.configuration.data.ConfigMain)10 ConfigParties (com.alessiodp.parties.common.configuration.data.ConfigParties)10 PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)9 PartiesConstants (com.alessiodp.parties.common.configuration.PartiesConstants)9 PartyHomeImpl (com.alessiodp.parties.common.parties.objects.PartyHomeImpl)8 LinkedList (java.util.LinkedList)8 LinkedHashSet (java.util.LinkedHashSet)7 List (java.util.List)7 HashMap (java.util.HashMap)6 ADPMainCommand (com.alessiodp.core.common.commands.utils.ADPMainCommand)5 CommandData (com.alessiodp.core.common.commands.utils.CommandData)5 OfflineUser (com.alessiodp.core.common.user.OfflineUser)5 CommonCommands (com.alessiodp.parties.common.commands.list.CommonCommands)5 PartiesSubCommand (com.alessiodp.parties.common.commands.utils.PartiesSubCommand)5