Search in sources :

Example 1 with BukkitPartyPlayerImpl

use of com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl in project Parties by AlessioDP.

the class BukkitPartiesMessageListener method handleFromSub.

public void handleFromSub(byte[] bytes, String channel) {
    PartiesPacket packet = PartiesPacket.read(plugin, bytes);
    if (packet != null) {
        PartyImpl party;
        PartyPlayerImpl partyPlayer;
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_RECEIVED, packet.getType().name(), channel), true);
        switch(packet.getType()) {
            case UPDATE_PARTY:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC && ((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getPartyId())) {
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_UPDATE_PARTY, packet.getPartyId().toString()), true);
                }
                break;
            case UPDATE_PLAYER:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PLAYER_SYNC && ((PartiesPlugin) plugin).getPlayerManager().reloadPlayer(packet.getPlayerUuid())) {
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_UPDATE_PLAYER, packet.getPlayerUuid().toString()), true);
                }
                break;
            case LOAD_PARTY:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_LOAD_PARTIES) {
                    ((PartiesPlugin) plugin).getPartyManager().loadParty(packet.getPartyId());
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_LOAD_PARTY, packet.getPartyId().toString()), true);
                }
                break;
            case LOAD_PLAYER:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_LOAD_PLAYERS) {
                    partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().loadPlayer(packet.getPlayerUuid());
                    if (partyPlayer != null) {
                        if (partyPlayer.isInParty()) {
                            // Load party
                            ((PartiesPlugin) plugin).getPartyManager().loadParty(partyPlayer.getPartyId());
                        }
                        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_LOAD_PLAYER, packet.getPlayerUuid().toString()), true);
                    }
                }
                break;
            case UNLOAD_PARTY:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_LOAD_PARTIES) {
                    party = ((PartiesPlugin) plugin).getPartyManager().getCacheParties().get(packet.getPartyId());
                    if (party != null) {
                        ((PartiesPlugin) plugin).getPartyManager().unloadParty(party);
                        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_UNLOAD_PARTY, packet.getPartyId().toString()), true);
                    }
                }
                break;
            case UNLOAD_PLAYER:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_LOAD_PLAYERS) {
                    ((PartiesPlugin) plugin).getPlayerManager().unloadPlayer(packet.getPlayerUuid());
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_UNLOAD_PLAYER, packet.getPlayerUuid().toString()), true);
                }
                break;
            case PLAY_SOUND:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_SOUNDS) {
                    partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayerUuid());
                    if (partyPlayer != null) {
                        ((BukkitPartyPlayerImpl) partyPlayer).playPacketSound(packet.getPayloadRaw());
                    }
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_PLAY_SOUND, packet.getPlayerUuid().toString()), true);
                }
                break;
            case CREATE_PARTY:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC) {
                    PartyImpl finalParty = ((PartiesPlugin) plugin).getPartyManager().loadParty(packet.getPartyId());
                    if (finalParty != null) {
                        ((PartiesPlugin) plugin).getPlayerManager().reloadPlayer(packet.getPlayerUuid());
                        PartyPlayerImpl leader = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayerUuid());
                        // Calling API Event
                        IPartyPostCreateEvent partiesPostCreateEvent = ((PartiesPlugin) plugin).getEventManager().preparePartyPostCreateEvent(leader, finalParty);
                        ((PartiesPlugin) plugin).getEventManager().callEvent(partiesPostCreateEvent);
                        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_CREATE_PARTY, packet.getPartyId().toString(), leader != null ? leader.getPlayerUUID().toString() : "none"), true);
                    }
                }
                break;
            case DELETE_PARTY:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC) {
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    if (party != null) {
                        try {
                            ByteArrayDataInput input = ByteStreams.newDataInput(packet.getPayloadRaw());
                            DeleteCause cause = DeleteCause.valueOf(input.readUTF());
                            String uuidKicked = input.readUTF();
                            PartyPlayerImpl kicked = uuidKicked.isEmpty() ? null : ((PartiesPlugin) plugin).getPlayerManager().getPlayer(UUID.fromString(uuidKicked));
                            String uuidCommandSender = input.readUTF();
                            PartyPlayerImpl commandSender = uuidCommandSender.isEmpty() ? null : ((PartiesPlugin) plugin).getPlayerManager().getPlayer(UUID.fromString(uuidCommandSender));
                            // Reload players
                            party.getMembers().forEach(u -> {
                                ((PartiesPlugin) plugin).getPlayerManager().reloadPlayer(u);
                            });
                            // Unload party
                            ((PartiesPlugin) plugin).getPartyManager().removePartyFromCache(party);
                            // Calling API Event
                            IPartyPostDeleteEvent partiesPostDeleteEvent = ((PartiesPlugin) plugin).getEventManager().preparePartyPostDeleteEvent(party, cause, kicked, commandSender);
                            ((PartiesPlugin) plugin).getEventManager().callEvent(partiesPostDeleteEvent);
                            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_DELETE_PARTY, party.getId().toString(), cause.name(), kicked != null ? kicked.getPlayerUUID().toString() : "none", commandSender != null ? commandSender.getPlayerUUID().toString() : "none"), true);
                        } catch (Exception ex) {
                            plugin.getLoggerManager().printError(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_DELETE_PARTY_ERROR, ex.getMessage() != null ? ex.getMessage() : ex.toString()));
                        }
                    }
                }
                break;
            case RENAME_PARTY:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC) {
                    ((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getPartyId());
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    if (party != null) {
                        try {
                            ByteArrayDataInput input = ByteStreams.newDataInput(packet.getPayloadRaw());
                            String oldName = input.readUTF();
                            String newName = input.readUTF();
                            String uuidPlayer = input.readUTF();
                            PartyPlayerImpl player = uuidPlayer.isEmpty() ? null : ((PartiesPlugin) plugin).getPlayerManager().getPlayer(UUID.fromString(uuidPlayer));
                            boolean isAdmin = input.readBoolean();
                            // Calling API Event
                            IPartyPostRenameEvent partiesPostRenameEvent = ((PartiesPlugin) plugin).getEventManager().preparePartyPostRenameEvent(party, oldName, newName, player, isAdmin);
                            ((PartiesPlugin) plugin).getEventManager().callEvent(partiesPostRenameEvent);
                            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_RENAME_PARTY, party.getId().toString(), oldName, newName, player != null ? player.getPlayerUUID().toString() : "none"), true);
                        } catch (Exception ex) {
                            plugin.getLoggerManager().printError(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_RENAME_PARTY_ERROR, ex.getMessage() != null ? ex.getMessage() : ex.toString()));
                        }
                    }
                }
                break;
            case ADD_MEMBER_PARTY:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC) {
                    ((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getPartyId());
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    if (party != null) {
                        try {
                            ByteArrayDataInput input = ByteStreams.newDataInput(packet.getPayloadRaw());
                            UUID playerUuid = UUID.fromString(input.readUTF());
                            ((PartiesPlugin) plugin).getPlayerManager().reloadPlayer(playerUuid);
                            PartyPlayerImpl player = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(playerUuid);
                            JoinCause cause = JoinCause.valueOf(input.readUTF());
                            String uuidInviter = input.readUTF();
                            PartyPlayerImpl inviter = uuidInviter.isEmpty() ? null : ((PartiesPlugin) plugin).getPlayerManager().getPlayer(UUID.fromString(uuidInviter));
                            // Calling API Event
                            IPlayerPostJoinEvent partiesPostJoinEvent = ((PartiesPlugin) plugin).getEventManager().preparePlayerPostJoinEvent(player, party, cause, inviter);
                            ((PartiesPlugin) plugin).getEventManager().callEvent(partiesPostJoinEvent);
                            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_MEMBER_PARTY, player.getPlayerUUID().toString(), party.getId().toString(), cause.name(), inviter != null ? inviter.getPlayerUUID().toString() : "none"), true);
                        } catch (Exception ex) {
                            plugin.getLoggerManager().printError(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_MEMBER_PARTY_ERROR, ex.getMessage() != null ? ex.getMessage() : ex.toString()));
                        }
                    }
                }
                break;
            case REMOVE_MEMBER_PARTY:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC) {
                    ((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getPartyId());
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    if (party != null) {
                        try {
                            ByteArrayDataInput input = ByteStreams.newDataInput(packet.getPayloadRaw());
                            UUID playerUuid = UUID.fromString(input.readUTF());
                            ((PartiesPlugin) plugin).getPlayerManager().reloadPlayer(playerUuid);
                            PartyPlayerImpl player = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(playerUuid);
                            LeaveCause cause = LeaveCause.valueOf(input.readUTF());
                            String uuidInviter = input.readUTF();
                            PartyPlayerImpl inviter = uuidInviter.isEmpty() ? null : ((PartiesPlugin) plugin).getPlayerManager().getPlayer(UUID.fromString(uuidInviter));
                            // Calling API Event
                            IPlayerPostLeaveEvent partiesPostLeaveEvent = ((PartiesPlugin) plugin).getEventManager().preparePlayerPostLeaveEvent(player, party, cause, inviter);
                            ((PartiesPlugin) plugin).getEventManager().callEvent(partiesPostLeaveEvent);
                            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_REMOVE_MEMBER_PARTY, player.getPlayerUUID().toString(), party.getId().toString(), cause.name(), inviter != null ? inviter.getPlayerUUID().toString() : "none"), true);
                        } catch (Exception ex) {
                            plugin.getLoggerManager().printError(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_REMOVE_MEMBER_PARTY_ERROR, ex.getMessage() != null ? ex.getMessage() : ex.toString()));
                        }
                    }
                }
                break;
            case CHAT_MESSAGE:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_CHAT) {
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayerUuid());
                    if (party != null && partyPlayer != null) {
                        // Calling API event
                        IPlayerPostChatEvent partiesPostChatEvent = ((PartiesPlugin) plugin).getEventManager().preparePlayerPostChatEvent(partyPlayer, party, packet.getPayload());
                        ((PartiesPlugin) plugin).getEventManager().callEvent(partiesPostChatEvent);
                        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_CHAT_MESSAGE, partyPlayer.getPlayerUUID().toString(), packet.getPartyId().toString(), packet.getPayload()), true);
                    }
                }
                break;
            case INVITE_PLAYER:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC) {
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    if (party != null) {
                        try {
                            ByteArrayDataInput input = ByteStreams.newDataInput(packet.getPayloadRaw());
                            PartyPlayerImpl invitedPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(UUID.fromString(input.readUTF()));
                            String uuidInviter = input.readUTF();
                            PartyPlayerImpl inviter = uuidInviter.isEmpty() ? null : ((PartiesPlugin) plugin).getPlayerManager().getPlayer(UUID.fromString(uuidInviter));
                            // Calling API Event
                            IPlayerPostInviteEvent partiesPostInviteEvent = ((PartiesPlugin) plugin).getEventManager().preparePlayerPostInviteEvent(invitedPlayer, inviter, party);
                            ((PartiesPlugin) plugin).getEventManager().callEvent(partiesPostInviteEvent);
                            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_INVITE_PARTY, invitedPlayer.getPlayerUUID().toString(), party.getId().toString(), inviter != null ? inviter.getPlayerUUID().toString() : "none"), true);
                        } catch (Exception ex) {
                            plugin.getLoggerManager().printError(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_INVITE_PARTY_ERROR, ex.getMessage() != null ? ex.getMessage() : ex.toString()));
                        }
                    }
                }
                break;
            case ADD_HOME:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC) {
                    ((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getPartyId());
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayerUuid());
                    if (party != null && partyPlayer != null) {
                        try {
                            ByteArrayDataInput input = ByteStreams.newDataInput(packet.getPayloadRaw());
                            String name = input.readUTF();
                            String server = input.readUTF();
                            PartyHomeImpl home = BukkitCommandSetHome.getHomeLocationOfPlayer(partyPlayer, name, server);
                            if (home != null) {
                                if (((PartiesPlugin) plugin).isBungeeCordEnabled())
                                    ((BukkitPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendAddHome(party, home.toString());
                                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_HOME, home, party.getId().toString(), partyPlayer.getPlayerUUID().toString(), server), true);
                            }
                        } catch (Exception ex) {
                            plugin.getLoggerManager().printError(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_HOME_ERROR, ex.getMessage() != null ? ex.getMessage() : ex.toString()));
                        }
                    }
                }
                break;
            case HOME_TELEPORT:
                partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayerUuid());
                if (partyPlayer != null) {
                    User user = plugin.getPlayer(packet.getPlayerUuid());
                    if (user != null) {
                        try {
                            ByteArrayDataInput input = ByteStreams.newDataInput(packet.getPayloadRaw());
                            String homeSerialized = input.readUTF();
                            String message = input.readUTF();
                            PartyHomeImpl home = PartyHomeImpl.deserialize(homeSerialized);
                            if (home != null) {
                                Location location = new Location(Bukkit.getWorld(home.getWorld()), home.getX(), home.getY(), home.getZ(), home.getYaw(), home.getPitch());
                                BukkitCommandHome.teleportToPartyHome((PartiesPlugin) plugin, partyPlayer, (BukkitUser) user, home, location, message);
                                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_HOME_TELEPORT, packet.getPlayerUuid().toString(), homeSerialized), true);
                            }
                        } catch (Exception ex) {
                            plugin.getLoggerManager().printError(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_HOME_TELEPORT_ERROR, ex.getMessage() != null ? ex.getMessage() : ex.toString()));
                        }
                    }
                }
                break;
            case TELEPORT:
                partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayerUuid());
                if (partyPlayer != null) {
                    User user = plugin.getPlayer(packet.getPlayerUuid());
                    if (user != null) {
                        try {
                            UUID targetUuid = UUID.fromString(packet.getPayload());
                            Player bukkitTargetPlayer = Bukkit.getPlayer(targetUuid);
                            if (bukkitTargetPlayer != null) {
                                plugin.getScheduler().getSyncExecutor().execute(() -> ((BukkitUser) user).teleportAsync(bukkitTargetPlayer.getLocation()));
                            }
                            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_TELEPORT, packet.getPlayerUuid().toString(), packet.getPayload()), true);
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                }
                break;
            case EXPERIENCE:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC && ConfigMain.ADDITIONAL_EXP_ENABLE) {
                    ((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getPartyId());
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayerUuid());
                    if (party != null) {
                        IPartyGetExperienceEvent partiesGetExperienceEvent = ((PartiesPlugin) plugin).getEventManager().preparePartyGetExperienceEvent(party, packet.getPayloadNumber(), partyPlayer);
                        ((PartiesPlugin) plugin).getEventManager().callEvent(partiesGetExperienceEvent);
                    }
                }
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_EXPERIENCE, CommonUtils.formatDouble(packet.getPayloadNumber()), packet.getPartyId().toString(), packet.getPlayerUuid() != null ? packet.getPlayerUuid().toString() : "none"), true);
                break;
            case LEVEL_UP:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_PARTY_SYNC && ConfigMain.ADDITIONAL_EXP_ENABLE && ConfigMain.ADDITIONAL_EXP_LEVELS_ENABLE) {
                    ((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getPartyId());
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    if (party != null) {
                        IPartyLevelUpEvent partiesLevelUpEvent = ((PartiesPlugin) plugin).getEventManager().prepareLevelUpEvent(party, (int) packet.getPayloadNumber());
                        ((PartiesPlugin) plugin).getEventManager().callEvent(partiesLevelUpEvent);
                    }
                }
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_LEVEL_UP, packet.getPartyId().toString(), (int) packet.getPayloadNumber()), true);
                break;
            case CONFIGS:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_CONFIG_SYNC) {
                    ((PartiesConfigurationManager) plugin.getConfigurationManager()).parseConfigsPacket(packet.getPayloadRaw());
                    plugin.getLoggerManager().logDebug(PartiesConstants.DEBUG_MESSAGING_LISTEN_CONFIGS, true);
                }
                break;
            default:
        }
    } else {
        plugin.getLoggerManager().printError(String.format(PartiesConstants.DEBUG_MESSAGING_RECEIVED_WRONG, channel));
    }
}
Also used : IPlayerPostLeaveEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostLeaveEvent) IPlayerPostInviteEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostInviteEvent) User(com.alessiodp.core.common.user.User) BukkitUser(com.alessiodp.core.bukkit.user.BukkitUser) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) IPartyPostDeleteEvent(com.alessiodp.parties.api.events.common.party.IPartyPostDeleteEvent) PartiesConfigurationManager(com.alessiodp.parties.common.configuration.PartiesConfigurationManager) IPlayerPostJoinEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostJoinEvent) IPartyPostRenameEvent(com.alessiodp.parties.api.events.common.party.IPartyPostRenameEvent) JoinCause(com.alessiodp.parties.api.enums.JoinCause) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) IPartyGetExperienceEvent(com.alessiodp.parties.api.events.common.party.IPartyGetExperienceEvent) UUID(java.util.UUID) IPlayerPostChatEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostChatEvent) Player(org.bukkit.entity.Player) IPartyLevelUpEvent(com.alessiodp.parties.api.events.common.party.IPartyLevelUpEvent) LeaveCause(com.alessiodp.parties.api.enums.LeaveCause) DeleteCause(com.alessiodp.parties.api.enums.DeleteCause) IPartyPostCreateEvent(com.alessiodp.parties.api.events.common.party.IPartyPostCreateEvent) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) PartiesPacket(com.alessiodp.parties.common.messaging.PartiesPacket) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) Location(org.bukkit.Location)

Example 2 with BukkitPartyPlayerImpl

use of com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl in project Parties by AlessioDP.

the class BukkitFollowListener method sendMembers.

private void sendMembers(PartyImpl party, PartyPlayerImpl player, Player bukkitPlayer, World oldWorld) {
    for (PartyPlayer member : party.getOnlineMembers(true)) {
        BukkitUser memberUser = (BukkitUser) plugin.getPlayer(member.getPlayerUUID());
        Player bukkitMember = Bukkit.getPlayer(member.getPlayerUUID());
        if (bukkitMember != null && !bukkitMember.getUniqueId().equals(bukkitPlayer.getUniqueId()) && bukkitMember.getWorld().equals(oldWorld)) {
            plugin.getScheduler().getSyncExecutor().execute(() -> {
                ((BukkitPartyPlayerImpl) member).setPortalPause(true);
                plugin.getScheduler().scheduleAsyncLater(() -> {
                    ((BukkitPartyPlayerImpl) member).setPortalPause(false);
                }, BukkitConfigMain.ADDITIONAL_FOLLOW_TIMEOUT * 50L, TimeUnit.MILLISECONDS);
                ((BukkitPartyPlayerImpl) member).sendMessage(plugin.getMessageUtils().convertPlaceholders(BukkitMessages.OTHER_FOLLOW_WORLD.replace("%world%", bukkitPlayer.getWorld().getName()), player, party));
                Location destination = BukkitConfigMain.ADDITIONAL_FOLLOW_TELEPORT_TO_SAME_LOCATION ? bukkitPlayer.getLocation() : bukkitPlayer.getWorld().getSpawnLocation();
                memberUser.teleportAsync(destination).thenRun(() -> {
                    if (BukkitConfigMain.ADDITIONAL_FOLLOW_PERFORMCMD_ENABLE) {
                        // Schedule it later
                        plugin.getScheduler().scheduleAsyncLater(() -> {
                            for (String command : BukkitConfigMain.ADDITIONAL_FOLLOW_PERFORMCMD_COMMANDS) {
                                plugin.getScheduler().getSyncExecutor().execute(() -> bukkitMember.performCommand(plugin.getMessageUtils().convertPlaceholders(command, (PartyPlayerImpl) member, party)));
                            }
                        }, BukkitConfigMain.ADDITIONAL_FOLLOW_PERFORMCMD_DELAY, TimeUnit.MILLISECONDS);
                    }
                });
            });
        }
    }
}
Also used : PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) Player(org.bukkit.entity.Player) PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) BukkitUser(com.alessiodp.core.bukkit.user.BukkitUser) Location(org.bukkit.Location)

Example 3 with BukkitPartyPlayerImpl

use of com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl in project Parties by AlessioDP.

the class BukkitCommandConfirm method onCommand.

@Override
public void onCommand(CommandData commandData) {
    User sender = commandData.getSender();
    BukkitPartyPlayerImpl partyPlayer = (BukkitPartyPlayerImpl) ((PartiesCommandData) commandData).getPartyPlayer();
    // Command handling
    LastConfirmedCommand packet = partyPlayer.getLastConfirmedCommand();
    if (packet == null || ((System.currentTimeMillis() - packet.getTimestamp()) > BukkitConfigMain.ADDONS_VAULT_CONFIRM_TIMEOUT)) {
        sendMessage(sender, partyPlayer, BukkitMessages.ADDCMD_VAULT_CONFIRM_NOCMD);
        return;
    }
    // Command starts
    packet.setConfirmed(true);
    partyPlayer.setLastConfirmedCommand(packet);
    sendMessage(sender, partyPlayer, BukkitMessages.ADDCMD_VAULT_CONFIRM_CONFIRMED);
    // Make it sync
    plugin.getScheduler().getSyncExecutor().execute(() -> {
        Player player = Bukkit.getPlayer(sender.getUUID());
        if (player != null)
            Bukkit.getServer().dispatchCommand(player, packet.getCommand());
    });
}
Also used : Player(org.bukkit.entity.Player) User(com.alessiodp.core.common.user.User) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) LastConfirmedCommand(com.alessiodp.parties.bukkit.utils.LastConfirmedCommand)

Example 4 with BukkitPartyPlayerImpl

use of com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl in project Parties by AlessioDP.

the class BukkitFightListener method onPlayerGotHit.

@EventHandler(ignoreCancelled = true)
public void onPlayerGotHit(EntityDamageByEntityEvent event) {
    if (event.getEntity() instanceof Player && (BukkitConfigParties.ADDITIONAL_HOME_CANCEL_HIT || BukkitConfigParties.ADDITIONAL_TELEPORT_CANCEL_HIT)) {
        // Make it async
        plugin.getScheduler().runAsync(() -> {
            BukkitPartyPlayerImpl partyPlayer = (BukkitPartyPlayerImpl) plugin.getPlayerManager().getPlayer(event.getEntity().getUniqueId());
            User user = plugin.getPlayer(partyPlayer.getPlayerUUID());
            // Check if the player is on home cooldown
            if (partyPlayer.getPendingHomeDelay() != null) {
                // Cancelling home task
                partyPlayer.getPendingHomeDelay().cancel();
                user.sendMessage(plugin.getMessageUtils().convertPlaceholders(BukkitMessages.ADDCMD_HOME_TELEPORTDENIED, partyPlayer, null), true);
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_TASK_HOME_DENIED_FIGHT, partyPlayer.getPlayerUUID().toString()), true);
            }
            // Check if the player is on teleport cooldown
            if (partyPlayer.getPendingTeleportDelay() != null) {
                // Cancelling home task
                partyPlayer.getPendingTeleportDelay().cancel();
                user.sendMessage(plugin.getMessageUtils().convertPlaceholders(BukkitMessages.ADDCMD_TELEPORT_PLAYER_TELEPORTDENIED, partyPlayer, null), true);
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_TASK_TELEPORT_DENIED_FIGHT, partyPlayer.getPlayerUUID().toString()), true);
            }
        });
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.alessiodp.core.common.user.User) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BukkitPartyPlayerImpl (com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl)4 Player (org.bukkit.entity.Player)4 User (com.alessiodp.core.common.user.User)3 BukkitUser (com.alessiodp.core.bukkit.user.BukkitUser)2 Location (org.bukkit.Location)2 DeleteCause (com.alessiodp.parties.api.enums.DeleteCause)1 JoinCause (com.alessiodp.parties.api.enums.JoinCause)1 LeaveCause (com.alessiodp.parties.api.enums.LeaveCause)1 IPartyGetExperienceEvent (com.alessiodp.parties.api.events.common.party.IPartyGetExperienceEvent)1 IPartyLevelUpEvent (com.alessiodp.parties.api.events.common.party.IPartyLevelUpEvent)1 IPartyPostCreateEvent (com.alessiodp.parties.api.events.common.party.IPartyPostCreateEvent)1 IPartyPostDeleteEvent (com.alessiodp.parties.api.events.common.party.IPartyPostDeleteEvent)1 IPartyPostRenameEvent (com.alessiodp.parties.api.events.common.party.IPartyPostRenameEvent)1 IPlayerPostChatEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostChatEvent)1 IPlayerPostInviteEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostInviteEvent)1 IPlayerPostJoinEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostJoinEvent)1 IPlayerPostLeaveEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostLeaveEvent)1 PartyPlayer (com.alessiodp.parties.api.interfaces.PartyPlayer)1 LastConfirmedCommand (com.alessiodp.parties.bukkit.utils.LastConfirmedCommand)1 PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)1