Search in sources :

Example 1 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl 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 PartyImpl

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

the class BungeePartiesMessageListener method handleChannelMain.

protected void handleChannelMain(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 (((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getPartyId())) {
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_UPDATE_PARTY, packet.getPartyId().toString()), true);
                }
                break;
            case INVITE_PLAYER:
                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));
                        party.invitePlayer(invitedPlayer, inviter);
                        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:
                party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                if (party != null) {
                    String serializedHome = packet.getPayload();
                    CommandSetHome.savePartyHome(party, PartyHomeImpl.deserialize(serializedHome));
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_HOME_BUNGEE, party.getId().toString()), true);
                }
                break;
            case EXPERIENCE:
                if (ConfigMain.ADDITIONAL_EXP_ENABLE) {
                    party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getPartyId());
                    partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayerUuid());
                    if (party != null) {
                        party.giveExperience(packet.getPayloadNumber(), partyPlayer);
                    }
                    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 REQUEST_CONFIGS:
                if (ConfigMain.PARTIES_BUNGEECORD_PACKETS_CONFIG_SYNC) {
                    ((BungeePartiesConfigurationManager) plugin.getConfigurationManager()).makeConfigsSync();
                    plugin.getLoggerManager().logDebug(PartiesConstants.DEBUG_MESSAGING_LISTEN_REQUEST_CONFIGS, true);
                }
                break;
            default:
                // Nothing to do
                break;
        }
    } else {
        plugin.getLoggerManager().printError(String.format(PartiesConstants.DEBUG_MESSAGING_RECEIVED_WRONG, channel));
    }
}
Also used : PartiesPacket(com.alessiodp.parties.common.messaging.PartiesPacket) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) BungeePartiesConfigurationManager(com.alessiodp.parties.bungeecord.configuration.BungeePartiesConfigurationManager) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 3 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, PartiesPermission requiredRank) {
    boolean ret = handlePreRequisitesFull(commandData, inParty, argMin, argMax);
    if (ret && commandData.getSender().isPlayer()) {
        PartyImpl party = ((PartiesPlugin) plugin).getPartyManager().getPartyOfPlayer(((PartiesCommandData) commandData).getPartyPlayer());
        if (party == null) {
            sendMessage(commandData.getSender(), ((PartiesCommandData) commandData).getPartyPlayer(), Messages.PARTIES_COMMON_NOTINPARTY);
            return false;
        }
        if (requiredRank != null && !((PartiesPlugin) plugin).getRankManager().checkPlayerRankAlerter(((PartiesCommandData) commandData).getPartyPlayer(), requiredRank))
            return false;
        ((PartiesCommandData) commandData).setParty(party);
    }
    return ret;
}
Also used : PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 4 with PartyImpl

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

the class FileDispatcherTest method party.

private void party(PartiesYAMLDispatcher dispatcher, boolean remove) {
    PartyImpl party = initializeParty(UUID.randomUUID());
    PartyPlayerImpl player = initializePlayer(UUID.randomUUID());
    PartyImpl mockParty = mock(party.getClass());
    doReturn(CompletableFuture.completedFuture(null)).when(mockParty).updateParty();
    PartyPlayerImpl mockPlayer = mock(player.getClass());
    doReturn(CompletableFuture.completedFuture(null)).when(mockPlayer).updatePlayer();
    PartyManager mockPartyManager = mock(PartyManager.class);
    when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
    when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> initializeParty(mock.getArgument(0)));
    PlayerManager mockPlayerManager = mock(PlayerManager.class);
    when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
    when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mock.getArgument(0)));
    party.setAccessible(true);
    party.setup("test", player.getPlayerUUID().toString());
    party.setDescription("description");
    party.setKills(10);
    party.setMembers(Collections.singleton(player.getPlayerUUID()));
    party.setAccessible(false);
    player.setAccessible(true);
    player.setPartyId(party.getId());
    player.setAccessible(false);
    dispatcher.updatePlayer(player);
    assertNull(dispatcher.getDatabase().getYaml().getConfigurationSection("parties"));
    assertNull(dispatcher.getDatabase().getYaml().getConfigurationSection("map-parties-by-name"));
    dispatcher.updateParty(party);
    assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("parties").getKeys(false).size(), 1);
    assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("map-parties-by-name").getKeys(false).size(), 1);
    PartyImpl newParty = dispatcher.getParty(party.getId());
    assertEquals(party, newParty);
    // Party remove
    if (remove) {
        dispatcher.removeParty(party);
        assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("parties").getKeys(false).size(), 0);
        assertEquals(dispatcher.getDatabase().getYaml().getConfigurationSection("map-parties-by-name").getKeys(false).size(), 0);
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PlayerManager(com.alessiodp.parties.common.players.PlayerManager) PartyManager(com.alessiodp.parties.common.parties.PartyManager) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 5 with PartyImpl

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

the class FileDispatcherTest method countParties.

private void countParties(PartiesYAMLDispatcher dispatcher) {
    ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES = Collections.emptyList();
    PartyImpl party = initializeParty(UUID.randomUUID());
    party.setAccessible(true);
    party.setup("test3", null);
    party.setDescription("description");
    party.setAccessible(false);
    assertEquals(dispatcher.getListPartiesNumber(), 0);
    dispatcher.updateParty(party);
    assertEquals(dispatcher.getListPartiesNumber(), 1);
}
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