Search in sources :

Example 41 with PartyImpl

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

the class BukkitFollowListener method onChangeWorld.

@EventHandler(ignoreCancelled = true)
public void onChangeWorld(PlayerChangedWorldEvent event) {
    if (BukkitConfigMain.ADDITIONAL_FOLLOW_ENABLE) {
        // Make it async
        Player bukkitPlayer = event.getPlayer();
        plugin.getScheduler().scheduleAsyncLater(() -> {
            if (allowedWorld(event.getPlayer().getWorld().getName())) {
                PartyPlayerImpl player = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
                PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
                if (party != null && party.isFollowEnabled() && (party.getLeader() != null && party.getLeader().equals(player.getPlayerUUID()))) {
                    // Let other players follow him
                    sendMembers(party, player, bukkitPlayer, event.getFrom());
                }
            }
        }, ConfigMain.ADDITIONAL_FOLLOW_DELAY, TimeUnit.MILLISECONDS);
    }
}
Also used : PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) Player(org.bukkit.entity.Player) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) EventHandler(org.bukkit.event.EventHandler)

Example 42 with PartyImpl

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

the class BungeeFollowListener method onConnected.

@EventHandler
public void onConnected(ServerSwitchEvent event) {
    if (!BungeeConfigMain.ADDITIONAL_FOLLOW_ENABLE)
        return;
    // Not connected to the network yet
    if (event.getPlayer().getServer() == null)
        return;
    plugin.getScheduler().scheduleAsyncLater(() -> {
        if (allowedServer(event.getPlayer().getServer().getInfo().getName())) {
            PartyPlayerImpl player = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
            PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
            if (party != null && party.isFollowEnabled() && (party.getLeader() != null && party.getLeader().equals(player.getPlayerUUID()))) {
                String playerServer = event.getPlayer().getServer().getInfo().getName();
                ServerInfo serverInfo = ((BungeePartiesBootstrap) plugin.getBootstrap()).getProxy().getServerInfo(playerServer);
                // Calling API event
                BungeePartiesPartyFollowEvent partyFollowEvent = ((BungeeEventManager) plugin.getEventManager()).preparePartyFollowEvent(party, playerServer);
                plugin.getEventManager().callEvent(partyFollowEvent);
                if (!partyFollowEvent.isCancelled()) {
                    // Let other players follow him
                    sendMembers(party, player, serverInfo);
                }
            }
        }
    }, ConfigMain.ADDITIONAL_FOLLOW_DELAY, TimeUnit.MILLISECONDS);
}
Also used : BungeeEventManager(com.alessiodp.parties.bungeecord.events.BungeeEventManager) BungeePartiesPartyFollowEvent(com.alessiodp.parties.api.events.bungee.unique.BungeePartiesPartyFollowEvent) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) ServerInfo(net.md_5.bungee.api.config.ServerInfo) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) EventHandler(net.md_5.bungee.event.EventHandler)

Example 43 with PartyImpl

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

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

the class BungeeCommandHome method teleportToPartyHome.

public static void teleportToPartyHome(PartiesPlugin plugin, User player, PartyPlayerImpl partyPlayer, PartyHomeImpl home) {
    PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
    if (home.getServer() != null && !home.getServer().isEmpty()) {
        boolean serverChange = false;
        ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(home.getServer());
        IPlayerPreHomeEvent partiesPreHomeEvent = plugin.getEventManager().preparePlayerPreHomeEvent(partyPlayer, party, home);
        plugin.getEventManager().callEvent(partiesPreHomeEvent);
        if (!partiesPreHomeEvent.isCancelled()) {
            if (((BungeeUser) player).getServer() == null)
                // Cannot get player server
                return;
            if (BungeeConfigParties.ADDITIONAL_HOME_CROSS_SERVER && !((BungeeUser) player).getServer().getName().equalsIgnoreCase(home.getServer())) {
                if (serverInfo == null) {
                    plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_CMD_HOME_NO_SERVER, home));
                    return;
                }
                ((BungeeUser) player).connectTo(serverInfo);
                serverChange = true;
            }
            String message = plugin.getMessageUtils().convertPlaceholders(Messages.ADDCMD_HOME_TELEPORTED, partyPlayer, party);
            if (serverChange) {
                plugin.getScheduler().scheduleAsyncLater(() -> ((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message, serverInfo), BungeeConfigParties.ADDITIONAL_HOME_CROSS_SERVER_DELAY, TimeUnit.MILLISECONDS);
            } else {
                ((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message, serverInfo);
            }
            IPlayerPostHomeEvent partiesPostHomeEvent = plugin.getEventManager().preparePlayerPostHomeEvent(partyPlayer, party, home);
            plugin.getEventManager().callEvent(partiesPostHomeEvent);
        } else
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_HOMEEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else {
        plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_HOME_NO_SERVER, party.getId()));
    }
}
Also used : BungeePartiesMessageDispatcher(com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher) IPlayerPostHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent) ServerInfo(net.md_5.bungee.api.config.ServerInfo) IPlayerPreHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent) BungeeUser(com.alessiodp.core.bungeecord.user.BungeeUser) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 45 with PartyImpl

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

the class CommandColor method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party = ((PartiesCommandData) commandData).getParty();
    // Command handling
    Set<PartyColorImpl> availableColors = getPlugin().getColorManager().getAvailableColors(sender);
    if (commandData.getArgs().length == 1) {
        if (party.getColor() != null)
            sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_INFO, availableColors));
        else
            sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_EMPTY, availableColors));
        return;
    }
    boolean isRemove = false;
    PartyColor color = null;
    if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
        // Remove command
        isRemove = true;
    } else {
        // Normal command
        for (PartyColorImpl pc : availableColors) {
            if (pc.getCommand().equalsIgnoreCase(commandData.getArgs()[1])) {
                color = pc;
                break;
            }
        }
        if (color == null) {
            // Color doesn't exist
            sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_WRONGCOLOR, availableColors));
            return;
        }
        if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.COLOR, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
            return;
    }
    // Command starts
    party.setColor(color);
    if (isRemove) {
        sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_REMOVED, availableColors));
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_COLOR_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else {
        sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_CHANGED, availableColors), party);
        party.broadcastMessage(parseWithAvailableColors(Messages.ADDCMD_COLOR_BROADCAST, availableColors), partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_COLOR, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", color.getName()), true);
    }
}
Also used : User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) PartyColor(com.alessiodp.parties.api.interfaces.PartyColor) PartyColorImpl(com.alessiodp.parties.common.parties.objects.PartyColorImpl) 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