Search in sources :

Example 31 with PartyImpl

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

the class PartiesSQLDispatcher method getParty.

@Override
public PartyImpl getParty(UUID id) {
    PartyImpl ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).get(id.toString())).orElse(null);
    if (ret != null) {
        ret.setAccessible(true);
        ret.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(id.toString())));
        ret.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 32 with PartyImpl

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

the class BukkitCommandClaim method onCommand.

@Override
public void onCommand(CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party = ((PartiesCommandData) commandData).getParty();
    // Command handling
    Selection selection = Selection.FAILED_GENERAL;
    if (commandData.getArgs()[1].equalsIgnoreCase(BukkitConfigMain.ADDONS_CLAIM_CMD_TRUST))
        selection = Selection.TRUST;
    else if (commandData.getArgs()[1].equalsIgnoreCase(BukkitConfigMain.ADDONS_CLAIM_CMD_CONTAINER))
        selection = Selection.CONTAINER;
    else if (commandData.getArgs()[1].equalsIgnoreCase(BukkitConfigMain.ADDONS_CLAIM_CMD_ACCESS))
        selection = Selection.ACCESS;
    else if (commandData.getArgs()[1].equalsIgnoreCase(BukkitConfigMain.ADDONS_CLAIM_CMD_MANAGER) && ClaimHandler.canChangeManager())
        selection = Selection.MANAGER;
    else if (commandData.getArgs()[1].equalsIgnoreCase(BukkitConfigMain.ADDONS_CLAIM_CMD_REMOVE))
        selection = Selection.REMOVE;
    if (!selection.equals(Selection.FAILED_GENERAL)) {
        Player bukkitSender = Bukkit.getPlayer(sender.getUUID());
        if (bukkitSender == null)
            return;
        ClaimHandler.Result res = ClaimHandler.isManager(bukkitSender);
        switch(res) {
            case NOEXIST:
                selection = Selection.FAILED_NOEXIST;
                break;
            case NOMANAGER:
                selection = Selection.FAILED_NOMANAGER;
                break;
            default:
                // Success, selection it's okay
                break;
        }
    }
    if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.CLAIM, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    // Command starts
    switch(selection) {
        case FAILED_NOEXIST:
            // Return: No exist claim
            sendMessage(sender, partyPlayer, BukkitMessages.ADDCMD_CLAIM_CLAIMNOEXISTS);
            break;
        case FAILED_NOMANAGER:
            // Return: No manager
            sendMessage(sender, partyPlayer, BukkitMessages.ADDCMD_CLAIM_NOMANAGER);
            break;
        case FAILED_GENERAL:
            // Return: Wrong command
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
            sendMessage(sender, partyPlayer, BukkitMessages.ADDCMD_CLAIM_ALLOWED_PERMISSIONS);
            break;
        default:
            ClaimHandler.addPartyPermission(Bukkit.getPlayer(commandData.getSender().getUUID()), party, selection.getPermission());
            sendMessage(sender, partyPlayer, selection.getPermission().isRemove() ? BukkitMessages.ADDCMD_CLAIM_REMOVED : BukkitMessages.ADDCMD_CLAIM_CLAIMED);
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_CLAIM, partyPlayer.getName(), selection.name()), true);
            break;
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) ClaimHandler(com.alessiodp.parties.bukkit.addons.external.ClaimHandler) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 33 with PartyImpl

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

the class BukkitCommandHome method teleportToPartyHome.

public static void teleportToPartyHome(PartiesPlugin plugin, PartyPlayerImpl player, BukkitUser bukkitUser, PartyHome home, Location location, String message) {
    PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
    IPlayerPreHomeEvent partiesPreHomeEvent = plugin.getEventManager().preparePlayerPreHomeEvent(player, party, home);
    plugin.getEventManager().callEvent(partiesPreHomeEvent);
    if (!partiesPreHomeEvent.isCancelled()) {
        plugin.getScheduler().getSyncExecutor().execute(() -> {
            EssentialsHandler.updateLastTeleportLocation(player.getPlayerUUID());
            bukkitUser.teleportAsync(location).thenAccept(result -> {
                if (result) {
                    player.sendMessage(message);
                    IPlayerPostHomeEvent partiesPostHomeEvent = plugin.getEventManager().preparePlayerPostHomeEvent(player, party, home);
                    plugin.getEventManager().callEvent(partiesPostHomeEvent);
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_TASK_TELEPORT_DONE, player.getPlayerUUID()), true);
                } else {
                    plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_TELEPORT_ASYNC, player.getPlayerUUID()));
                }
            });
        });
    } else
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_HOMEEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
}
Also used : IPlayerPostHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent) IPlayerPreHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 34 with PartyImpl

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

the class EssentialsChatHandler method onChatPlayer.

@EventHandler
public void onChatPlayer(AsyncPlayerChatEvent event) {
    String old = event.getFormat();
    if (CommonUtils.toLowerCase(old).contains("{parties_")) {
        // Bypass useless checks if this isn't an Parties placeholder
        boolean somethingChanged = false;
        PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
        PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
        Matcher mat = PATTERN.matcher(old);
        while (mat.find()) {
            String base = mat.group(0);
            String identifier = mat.group(1);
            if (identifier != null) {
                identifier = CommonUtils.toLowerCase(identifier);
                PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder(identifier);
                if (placeholder != null) {
                    String parsed = placeholder.formatPlaceholder(partyPlayer, party, identifier);
                    if (parsed != null) {
                        old = old.replace(base, Color.translateAlternateColorCodes(parsed));
                        somethingChanged = true;
                    }
                }
            }
        }
        if (somethingChanged)
            event.setFormat(old);
    }
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) Matcher(java.util.regex.Matcher) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) EventHandler(org.bukkit.event.EventHandler)

Example 35 with PartyImpl

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

the class PAPIHook method onRequest.

@Override
public String onRequest(OfflinePlayer offlinePlayer, @NotNull String identifier) {
    if (offlinePlayer != null) {
        PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(offlinePlayer.getUniqueId());
        PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
        PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder(identifier);
        return placeholder != null ? placeholder.formatPlaceholder(partyPlayer, party, identifier) : null;
    }
    return null;
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) 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