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);
}
}
Aggregations