Search in sources :

Example 61 with PartyImpl

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

the class PartiesSQLDispatcher method getListParties.

@Override
public LinkedHashSet<PartyImpl> getListParties(PartiesDatabaseManager.ListOrder order, int limit, int offset) {
    LinkedHashSet<PartyImpl> ret;
    List<String> blacklist = ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES;
    if (order == PartiesDatabaseManager.ListOrder.NAME)
        ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByName(blacklist, limit, offset));
    else if (order == PartiesDatabaseManager.ListOrder.MEMBERS)
        ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByMembers(blacklist, limit, offset));
    else if (order == PartiesDatabaseManager.ListOrder.KILLS)
        ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByKills(blacklist, limit, offset));
    else if (order == PartiesDatabaseManager.ListOrder.EXPERIENCE)
        ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByExperience(blacklist, limit, offset));
    else
        throw new IllegalStateException("Cannot get the list of parties with the order " + order.name());
    // Load members
    for (PartyImpl party : ret) {
        party.setAccessible(true);
        party.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(party.getId().toString())));
        party.setAccessible(false);
    }
    return ret;
}
Also used : PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) HashMap(java.util.HashMap) MySQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MySQLConnectionFactory) H2PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.H2PlayersDao) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) TreeSet(java.util.TreeSet) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) StorageType(com.alessiodp.core.common.storage.StorageType) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) Handle(org.jdbi.v3.core.Handle) SQLDispatcher(com.alessiodp.core.common.storage.dispatchers.SQLDispatcher) PartiesDatabaseManager(com.alessiodp.parties.common.storage.PartiesDatabaseManager) LinkedList(java.util.LinkedList) ADPPlugin(com.alessiodp.core.common.ADPPlugin) LinkedHashSet(java.util.LinkedHashSet) H2PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao) PostgreSQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.PostgreSQLConnectionFactory) PostgreSQLPlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao) SQLitePlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao) H2ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.H2ConnectionFactory) Set(java.util.Set) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) UUID(java.util.UUID) ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) List(java.util.List) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) MariaDBConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MariaDBConnectionFactory) IPartiesDatabase(com.alessiodp.parties.common.storage.interfaces.IPartiesDatabase) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao) SQLiteConnectionFactory(com.alessiodp.core.common.storage.sql.connection.SQLiteConnectionFactory) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 62 with PartyImpl

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

the class CommandSetHome 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
    String selectedHome;
    boolean isRemove = commandData.getArgs().length > 1 && commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE);
    if (ConfigParties.ADDITIONAL_HOME_MAX_HOMES > 1) {
        if (commandData.getArgs().length == 1) {
            // Home not selected
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
            return;
        } else if (commandData.getArgs().length == 2) {
            if (isRemove) {
                // Home not selected
                sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
                return;
            } else {
                selectedHome = commandData.getArgs()[1];
            }
        } else if (commandData.getArgs().length == 3 && isRemove) {
            selectedHome = commandData.getArgs()[2];
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
            return;
        }
    } else {
        if (commandData.getArgs().length == 1 || (commandData.getArgs().length == 2 && isRemove)) {
            selectedHome = "default";
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
            return;
        }
    }
    if (!isRemove && party.getHomes().size() >= ConfigParties.ADDITIONAL_HOME_MAX_HOMES) {
        final String finalSelectedHome = selectedHome;
        if (finalSelectedHome == null || party.getHomes().stream().noneMatch((h) -> finalSelectedHome.equalsIgnoreCase(h.getName()))) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_MAXHOMES);
            return;
        }
    }
    if (!isRemove) {
        boolean mustStartCooldown = false;
        if (ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_SETHOME_BYPASS)) {
            mustStartCooldown = true;
            long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.SETHOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME);
            if (remainingCooldown > 0) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
                return;
            }
        }
        if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.SETHOME, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
            return;
        if (mustStartCooldown) {
            getPlugin().getCooldownManager().startAction(CooldownManager.Action.SETHOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME);
        }
    }
    // Command starts
    if (isRemove) {
        boolean removed;
        if (selectedHome == null || ConfigParties.ADDITIONAL_HOME_MAX_HOMES <= 1) {
            party.getHomes().clear();
            removed = true;
        } else {
            final String finalSelectedHome = selectedHome;
            removed = party.getHomes().removeIf(h -> h.getName() != null && h.getName().equalsIgnoreCase(finalSelectedHome));
        }
        if (removed) {
            party.updateParty();
            sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_REMOVED);
        } else {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_REMOVED_NONE);
        }
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SETHOME_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(selectedHome, "default")), true);
    } else {
        getLocationAndSave(partyPlayer, party, selectedHome);
        sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_CHANGED);
        party.broadcastMessage(Messages.ADDCMD_SETHOME_BROADCAST, partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SETHOME, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(selectedHome, "default")), true);
    }
}
Also used : CommonUtils(com.alessiodp.core.common.utils.CommonUtils) CooldownManager(com.alessiodp.parties.common.parties.CooldownManager) PartiesPermission(com.alessiodp.parties.common.utils.PartiesPermission) CommandData(com.alessiodp.core.common.commands.utils.CommandData) Messages(com.alessiodp.parties.common.configuration.data.Messages) EconomyManager(com.alessiodp.parties.common.utils.EconomyManager) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) ArrayList(java.util.ArrayList) CommonCommands(com.alessiodp.parties.common.commands.list.CommonCommands) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) 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) User(com.alessiodp.core.common.user.User) NotNull(org.jetbrains.annotations.NotNull) RankPermission(com.alessiodp.parties.common.utils.RankPermission) ADPPlugin(com.alessiodp.core.common.ADPPlugin) 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) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 63 with PartyImpl

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

the class CommandTag method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party;
    // Command handling
    String tag = null;
    if (commandData.getArgs().length == 3 && commandData.havePermission(PartiesPermission.ADMIN_TAG_OTHERS)) {
        party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
        if (party != null) {
            if (!commandData.getArgs()[2].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
                tag = commandData.getArgs()[2];
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
            return;
        }
    } else if (commandData.getArgs().length == 2) {
        party = getPlugin().getPartyManager().getParty(partyPlayer.getPartyId());
        if (party == null) {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
            return;
        }
        if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.EDIT_TAG)) {
            return;
        }
        if (!commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
            tag = commandData.getArgs()[1];
        }
    } else {
        sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
        return;
    }
    if (tag != null) {
        if (!CensorUtils.checkAllowedCharacters(ConfigParties.ADDITIONAL_TAG_ALLOWEDCHARS, tag, PartiesConstants.DEBUG_CMD_TAG_REGEXERROR_AC) || (tag.length() > ConfigParties.ADDITIONAL_TAG_MAXLENGTH) || (tag.length() < ConfigParties.ADDITIONAL_TAG_MINLENGTH)) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_INVALID);
            return;
        }
        if (CensorUtils.checkCensor(ConfigParties.ADDITIONAL_TAG_CENSORREGEX, tag, PartiesConstants.DEBUG_CMD_TAG_REGEXERROR_CEN)) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_CENSORED);
            return;
        }
    }
    if (tag != null && ConfigParties.ADDITIONAL_TAG_MUST_BE_UNIQUE && getPlugin().getPartyManager().existsTag(tag)) {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_ALREADY_USED.replace("%tag%", tag));
        return;
    }
    if (!commandData.havePermission(PartiesPermission.ADMIN_TAG_OTHERS) && getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.TAG, partyPlayer, commandData.getCommandLabel(), commandData.getArgs())) {
        return;
    }
    // Command starts
    party.setTag(tag);
    if (tag == null) {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_REMOVED);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_TAG_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_CHANGED);
        party.broadcastMessage(Messages.ADDCMD_TAG_BROADCAST, partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_TAG, 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) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 64 with PartyImpl

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

the class CommandTeleport 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
    boolean mustStartCooldown = false;
    if (ConfigParties.ADDITIONAL_TELEPORT_COOLDOWN > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_TELEPORT_BYPASS)) {
        mustStartCooldown = true;
        long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.TELEPORT, partyPlayer.getPlayerUUID(), ConfigParties.ADDITIONAL_TELEPORT_COOLDOWN);
        if (remainingCooldown > 0) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_TELEPORT_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
            return;
        }
    }
    if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.TELEPORT, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    if (mustStartCooldown) {
        getPlugin().getCooldownManager().startAction(CooldownManager.Action.TELEPORT, partyPlayer.getPlayerUUID(), ConfigParties.GENERAL_NAME_RENAME_COOLDOWN);
    }
    // Command starts
    int delay = ConfigParties.ADDITIONAL_TELEPORT_DELAY;
    String teleportDelayPermission = sender.getDynamicPermission(PartiesPermission.USER_TELEPORT + ".");
    if (teleportDelayPermission != null) {
        try {
            delay = Integer.parseInt(teleportDelayPermission);
        } catch (Exception ignored) {
        }
    }
    performTeleport(party, partyPlayer, delay);
    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_TELEPORT, 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) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 65 with PartyImpl

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

the class PartiesSubCommand method handlePreRequisitesFullWithParty.

protected boolean handlePreRequisitesFullWithParty(CommandData commandData, Boolean inParty, int argMin, int argMax, RankPermission requiredRank) {
    boolean ret = handlePreRequisitesFull(commandData, inParty, argMin, argMax);
    if (ret && commandData.getSender().isPlayer()) {
        PartyImpl party = getPlugin().getPartyManager().getPartyOfPlayer(((PartiesCommandData) commandData).getPartyPlayer());
        if (party == null) {
            sendMessage(commandData.getSender(), ((PartiesCommandData) commandData).getPartyPlayer(), Messages.PARTIES_COMMON_NOTINPARTY);
            return false;
        }
        if (requiredRank != null && !getPlugin().getRankManager().checkPlayerRankAlerter(((PartiesCommandData) commandData).getPartyPlayer(), requiredRank))
            return false;
        ((PartiesCommandData) commandData).setParty(party);
    }
    return ret;
}
Also used : 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