Search in sources :

Example 1 with PartyHomeImpl

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

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

the class PartyHomeTest method testDeserialize.

@Test
public void testDeserialize() {
    PartyHomeImpl expected = new PartyHomeImpl("name", "world", 100, 200, 300, 10, 20);
    assertEquals(expected, PartyHomeImpl.deserialize("name,world,100.0,200.0,300.0,10.0,20.0"));
    assertNotEquals(expected, PartyHomeImpl.deserialize("name,world,0.0,0.0,0.0,10.0,20.0"));
    assertNotEquals(expected, PartyHomeImpl.deserialize("name,world,100.0,200.0,300.0,0.0,0.0"));
    assertNotEquals(expected, PartyHomeImpl.deserialize(",world,100.0,200.0,300.0,10.0,20.0"));
    assertNotEquals(expected, PartyHomeImpl.deserialize("name,,100.0,200.0,300.0,10.0,20.0"));
    expected = new PartyHomeImpl("name", "world", 100, 200, 300, 10, 20, "server");
    assertEquals(expected, PartyHomeImpl.deserialize("name,world,100.0,200.0,300.0,10.0,20.0,server"));
}
Also used : PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) Test(org.junit.jupiter.api.Test)

Example 3 with PartyHomeImpl

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

the class PartyHomeTest method testDeserializeMultiple.

@Test
public void testDeserializeMultiple() {
    HashSet<PartyHomeImpl> expected = new HashSet<>();
    expected.add(new PartyHomeImpl("name", "world", 100, 200, 300, 10, 20));
    expected.add(new PartyHomeImpl("name2", "world", 100, 200, 300, 10, 20, "server"));
    assertEquals(expected, PartyHomeImpl.deserializeMultiple("name,world,100.0,200.0,300.0,10.0,20.0;name2,world,100.0,200.0,300.0,10.0,20.0,server"));
    assertNotEquals(expected, PartyHomeImpl.deserializeMultiple("nameX,world,100.0,200.0,300.0,10.0,20.0;name2,world,100.0,200.0,300.0,10.0,20.0,server"));
}
Also used : PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with PartyHomeImpl

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

the class BukkitPartiesBungeecordListener method handleAddHome.

public void handleAddHome(PartiesPacket packet) {
    ((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getParty());
    PartyImpl party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getParty());
    PartyPlayerImpl partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayer());
    if (party != null && partyPlayer != null) {
        try {
            String name = packet.getText();
            String server = packet.getSecondaryText();
            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(), partyPlayer.getPlayerUUID(), server), true);
            }
        } catch (Exception ex) {
            plugin.getLoggerManager().logError(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_HOME_ERROR, ex);
        }
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 5 with PartyHomeImpl

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

the class CommandHome method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party = getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer);
    // Command handling
    PartyHomeImpl partyHome = null;
    if (commandData.getArgs().length == 1) {
        if (party == null) {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
            return;
        }
        if (party.getHomes().size() == 0) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
            return;
        }
    }
    if (ConfigParties.ADDITIONAL_HOME_MAX_HOMES > 1) {
        // Multiple home
        if (commandData.getArgs().length == 1) {
            if (party.getHomes().size() > 1) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_MUST_SELECT_HOME, party);
                printValidHomes(sender, partyPlayer, party);
                return;
            }
            Optional<PartyHome> opt = party.getHomes().stream().findFirst();
            if (opt.isPresent())
                partyHome = (PartyHomeImpl) opt.get();
            else {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
                printValidHomes(sender, partyPlayer, party);
                return;
            }
        } else if (commandData.getArgs().length == 2) {
            // Not admin - Not in party
            if (!commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS) && party == null) {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
                return;
            }
            // Get the partyHome of the current party
            if (party != null) {
                Optional<PartyHome> opt = party.getHomes().stream().filter((ph) -> ph.getName() != null && ph.getName().equalsIgnoreCase(commandData.getArgs()[1])).findAny();
                if (opt.isPresent())
                    partyHome = (PartyHomeImpl) opt.get();
            }
            // If no home but home.others permission
            if (partyHome == null && commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS)) {
                party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
                if (party != null) {
                    if (party.getHomes().size() > 1) {
                        sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_MUST_SELECT_HOME, party);
                        printValidHomes(sender, partyPlayer, party);
                        return;
                    }
                    Optional<PartyHome> opt = party.getHomes().stream().findFirst();
                    if (opt.isPresent())
                        partyHome = (PartyHomeImpl) opt.get();
                }
            }
            // Not in party
            if (party == null) {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
                return;
            }
            // No party home found
            if (partyHome == null) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_INVALID_HOME, party);
                printValidHomes(sender, partyPlayer, party);
                return;
            }
        } else if (commandData.getArgs().length == 3 && commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS)) {
            party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
            if (party != null) {
                Optional<PartyHome> opt = party.getHomes().stream().filter((ph) -> ph.getName() != null && ph.getName().equalsIgnoreCase(commandData.getArgs()[1])).findAny();
                if (opt.isPresent())
                    partyHome = (PartyHomeImpl) opt.get();
                else {
                    sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
                    printValidHomes(sender, partyPlayer, party);
                    return;
                }
            } else {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
                return;
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
            return;
        }
    } else {
        // Single home
        if (commandData.getArgs().length == 1) {
            Optional<PartyHome> opt = party.getHomes().stream().findFirst();
            if (opt.isPresent())
                partyHome = (PartyHomeImpl) opt.get();
            else {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
                return;
            }
        } else if (commandData.getArgs().length == 2 && commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS)) {
            party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
            if (party != null) {
                Optional<PartyHome> opt = party.getHomes().stream().findFirst();
                if (opt.isPresent())
                    partyHome = (PartyHomeImpl) opt.get();
                else {
                    sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
                    return;
                }
            } else {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
                return;
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
            return;
        }
    }
    if (!commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS) && !getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.HOME))
        return;
    if (partyPlayer.getPendingHomeDelay() != null) {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_TELEPORTWAITING, party);
        return;
    }
    boolean mustStartCooldown = false;
    if (ConfigParties.ADDITIONAL_HOME_COOLDOWN_HOME > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_HOME_BYPASS)) {
        mustStartCooldown = true;
        long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.HOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_HOME);
        if (remainingCooldown > 0) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
            return;
        }
    }
    if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.HOME, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    if (mustStartCooldown)
        getPlugin().getCooldownManager().startAction(CooldownManager.Action.HOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_HOME);
    // Command starts
    int delay = ConfigParties.ADDITIONAL_HOME_DELAY;
    String homeDelayPermission = sender.getDynamicPermission(PartiesPermission.USER_HOME + ".");
    if (homeDelayPermission != null) {
        try {
            delay = Integer.parseInt(homeDelayPermission);
        } catch (Exception ignored) {
        }
    }
    if (delay > 0) {
        HomeDelayTask homeDelayTask = teleportPlayerWithDelay(partyPlayer, partyHome, delay);
        CancellableTask task = plugin.getScheduler().scheduleAsyncRepeating(homeDelayTask, 0, 300, TimeUnit.MILLISECONDS);
        partyPlayer.setPendingHomeDelay(task);
        sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_TELEPORTIN.replace("%seconds%", Integer.toString(delay)));
    } else {
        teleportPlayer(sender, partyPlayer, partyHome);
    }
    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_HOME, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(partyHome.getName(), "default")), true);
}
Also used : PartiesPermission(com.alessiodp.parties.common.utils.PartiesPermission) EconomyManager(com.alessiodp.parties.common.utils.EconomyManager) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) CommonCommands(com.alessiodp.parties.common.commands.list.CommonCommands) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) User(com.alessiodp.core.common.user.User) RankPermission(com.alessiodp.parties.common.utils.RankPermission) ADPPlugin(com.alessiodp.core.common.ADPPlugin) PartiesSubCommand(com.alessiodp.parties.common.commands.utils.PartiesSubCommand) CommonUtils(com.alessiodp.core.common.utils.CommonUtils) CooldownManager(com.alessiodp.parties.common.parties.CooldownManager) CommandData(com.alessiodp.core.common.commands.utils.CommandData) Messages(com.alessiodp.parties.common.configuration.data.Messages) HomeDelayTask(com.alessiodp.parties.common.tasks.HomeDelayTask) TimeUnit(java.util.concurrent.TimeUnit) PartyHome(com.alessiodp.parties.api.interfaces.PartyHome) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) ADPMainCommand(com.alessiodp.core.common.commands.utils.ADPMainCommand) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) CancellableTask(com.alessiodp.core.common.scheduling.CancellableTask) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) Optional(java.util.Optional) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) CancellableTask(com.alessiodp.core.common.scheduling.CancellableTask) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) PartyHome(com.alessiodp.parties.api.interfaces.PartyHome) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) HomeDelayTask(com.alessiodp.parties.common.tasks.HomeDelayTask)

Aggregations

PartyHomeImpl (com.alessiodp.parties.common.parties.objects.PartyHomeImpl)6 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)4 User (com.alessiodp.core.common.user.User)3 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)3 BukkitUser (com.alessiodp.core.bukkit.user.BukkitUser)2 PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)2 Location (org.bukkit.Location)2 Test (org.junit.jupiter.api.Test)2 ADPPlugin (com.alessiodp.core.common.ADPPlugin)1 ADPMainCommand (com.alessiodp.core.common.commands.utils.ADPMainCommand)1 CommandData (com.alessiodp.core.common.commands.utils.CommandData)1 CancellableTask (com.alessiodp.core.common.scheduling.CancellableTask)1 CommonUtils (com.alessiodp.core.common.utils.CommonUtils)1 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