Search in sources :

Example 1 with PartiesDatabaseManager

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

the class BukkitCommandDebug method commandStart.

@Override
protected void commandStart(CommandType commandType, User sender, PartyPlayerImpl partyPlayer, PartyImpl targetParty, PartyPlayerImpl targetPlayer) {
    if (commandType == CommandType.BUNGEECORD) {
        UUID temporaryUuid = UUID.randomUUID();
        TemporaryPartyPlayer temporaryPlayer = new TemporaryPartyPlayer((PartiesPlugin) plugin, temporaryUuid);
        UUID receiver = null;
        boolean replyToPlayer = false;
        if (plugin.getOnlinePlayers().size() < 1) {
            sendMessage(sender, partyPlayer, BukkitMessages.ADDCMD_DEBUG_BUNGEECORD_SERVER_PLAYERS);
            return;
        }
        if (partyPlayer != null) {
            receiver = partyPlayer.getPlayerUUID();
            replyToPlayer = true;
        } else {
            User anyUser = plugin.getOnlinePlayers().stream().findAny().orElse(null);
            if (anyUser != null) {
                receiver = anyUser.getUUID();
            }
        }
        final UUID finalReceiver = receiver;
        final boolean finalReplyToPlayer = replyToPlayer;
        ((PartiesDatabaseManager) plugin.getDatabaseManager()).updatePlayer(temporaryPlayer).thenRun(() -> {
            ((BukkitPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendDebugBungeeCord(temporaryUuid, finalReceiver, finalReplyToPlayer);
            sendMessage(sender, partyPlayer, BukkitMessages.ADDCMD_DEBUG_BUNGEECORD_SENT);
            plugin.getScheduler().scheduleAsyncLater(() -> {
                // Set it not persistent so it can be removed from db
                temporaryPlayer.setPersistent(false);
                ((PartiesDatabaseManager) plugin.getDatabaseManager()).updatePlayer(temporaryPlayer);
            }, 10, TimeUnit.SECONDS);
        });
    } else {
        super.commandStart(commandType, sender, partyPlayer, targetParty, targetPlayer);
    }
}
Also used : PartiesDatabaseManager(com.alessiodp.parties.common.storage.PartiesDatabaseManager) User(com.alessiodp.core.common.user.User) BukkitPartiesMessageDispatcher(com.alessiodp.parties.bukkit.messaging.BukkitPartiesMessageDispatcher) UUID(java.util.UUID)

Aggregations

User (com.alessiodp.core.common.user.User)1 BukkitPartiesMessageDispatcher (com.alessiodp.parties.bukkit.messaging.BukkitPartiesMessageDispatcher)1 PartiesDatabaseManager (com.alessiodp.parties.common.storage.PartiesDatabaseManager)1 UUID (java.util.UUID)1