Search in sources :

Example 31 with PartyEntity

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

the class BungeeService method onPluginMessageReceived.

public void onPluginMessageReceived(String channel, Player player, byte[] message) {
    if (!channel.equals(partiesChannel)) {
        return;
    }
    ByteArrayInputStream stream = new ByteArrayInputStream(message);
    DataInputStream in = new DataInputStream(stream);
    // Load entities
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
    try {
        // Get packet in input
        Packet packet = new Packet(in);
        if (packet.getVersion().equals(plugin.getDescription().getVersion())) {
            // Does the player have a party
            if (party != null) {
                // Check for rank needed to follow
                if (pp.getRank() < packet.getRankNeeded())
                    return;
                // Preparing a list that contains the name of each player to teleport
                List<String> list = new ArrayList<String>();
                for (Player pl : party.getOnlinePlayers()) {
                    UUID pUuid = pl.getUniqueId();
                    if (!pUuid.equals(player.getUniqueId())) {
                        // Have the player the minimum rank to follow?
                        if (plugin.getPlayerManager().getPlayer(pUuid).getRank() >= packet.getRankMinimum()) {
                            list.add(pUuid.toString());
                        }
                    }
                }
                // Set the info list
                packet.setInfo(list);
                // Set the message for the user
                packet.setMessage(ChatColor.translateAlternateColorCodes('&', Messages.OTHER_FOLLOW_SERVER.replace("%server%", packet.getServer())));
                // Send the output
                ByteArrayOutputStream outstream = new ByteArrayOutputStream();
                DataOutputStream out = new DataOutputStream(outstream);
                packet.write(out);
                try {
                    Player p = Bukkit.getServer().getOnlinePlayers().iterator().next();
                    if (p != null) {
                        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_BUNGEE_REPLY, true);
                        p.sendPluginMessage(plugin, partiesChannel, outstream.toByteArray());
                    }
                } catch (Exception ex) {
                // Server empty
                }
            }
        } else {
            LoggerManager.printError(Constants.DEBUG_BUNGEE_VERSIONMISMATCH.replace("{packet}", packet.getVersion()));
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
Also used : Packet(com.alessiodp.parties.bungeecord.utils.Packet) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) UUID(java.util.UUID)

Example 32 with PartyEntity

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

the class ApiHandler method deleteParty.

@Override
public Status deleteParty(Party paramParty) {
    Status ret = Status.NOEXIST;
    PartyEntity party = new PartyEntity(paramParty, plugin);
    if (party != null) {
        party.removeParty();
        ret = Status.SUCCESS;
    }
    return ret;
}
Also used : Status(com.alessiodp.partiesapi.enums.Status) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 33 with PartyEntity

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

the class ApiHandler method addPlayerIntoParty.

@Override
public Status addPlayerIntoParty(PartyPlayer paramPartyPlayer, Party paramParty) {
    Status ret = Status.ALREADYINPARTY;
    if (!paramPartyPlayer.getPartyName().isEmpty()) {
        if (paramParty != null) {
            if (ConfigParties.GENERAL_MEMBERSLIMIT < 0 || paramParty.getMembers().size() < ConfigParties.GENERAL_MEMBERSLIMIT) {
                PartyEntity party = new PartyEntity(paramParty, plugin);
                party.getMembers().add(paramPartyPlayer.getPlayerUUID());
                paramPartyPlayer.setPartyName(party.getName());
                party.refreshPlayers();
                party.updateParty();
                updatePartyPlayer(paramPartyPlayer);
                party.callChange();
                ret = Status.SUCCESS;
            } else
                ret = Status.PARTYFULL;
        } else
            ret = Status.NOEXIST;
    }
    return ret;
}
Also used : Status(com.alessiodp.partiesapi.enums.Status) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 34 with PartyEntity

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

the class ApiHandler method broadcastPartyMessage.

@Override
public Status broadcastPartyMessage(Party paramParty, PartyPlayer paramPartyPlayer, String paramMessage) {
    Status ret = Status.NOEXIST;
    PartyEntity party = new PartyEntity(paramParty, plugin);
    if (party != null) {
        party.sendBroadcast(new PartyPlayerEntity(paramPartyPlayer, plugin), paramMessage);
        ret = Status.SUCCESS;
    }
    return ret;
}
Also used : Status(com.alessiodp.partiesapi.enums.Status) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 35 with PartyEntity

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

the class ApiHandler method removePlayerFromParty.

@Override
public Status removePlayerFromParty(PartyPlayer paramPartyPlayer) {
    Status ret = Status.NOPARTY;
    if (!paramPartyPlayer.getPartyName().isEmpty()) {
        PartyPlayerEntity player = new PartyPlayerEntity(paramPartyPlayer, plugin);
        PartyEntity party = plugin.getPartyManager().getParty(player.getPartyName());
        if (party != null) {
            if (player.getPlayerUUID().equals(party.getLeader())) {
                party.removeParty();
            } else {
                if (party.getMembers().contains(player.getPlayerUUID())) {
                    party.getMembers().remove(player.getPlayerUUID());
                    party.updateParty();
                    party.callChange();
                }
                player.cleanupPlayer(true);
            }
            ret = Status.SUCCESS;
        }
    }
    return ret;
}
Also used : Status(com.alessiodp.partiesapi.enums.Status) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)67 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)56 Player (org.bukkit.entity.Player)31 EventHandler (org.bukkit.event.EventHandler)11 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)6 Status (com.alessiodp.partiesapi.enums.Status)5 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)5 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)5 UUID (java.util.UUID)5 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)3 Party (com.alessiodp.partiesapi.objects.Party)3 ArrayList (java.util.ArrayList)3 PartiesPlaceholder (com.alessiodp.parties.addons.internal.PartiesPlaceholder)2 ChatTask (com.alessiodp.parties.tasks.ChatTask)2 PartiesChatEvent (com.alessiodp.partiesapi.events.PartiesChatEvent)2 PartiesFriendlyFireBlockedEvent (com.alessiodp.partiesapi.events.PartiesFriendlyFireBlockedEvent)2 Rank (com.alessiodp.partiesapi.interfaces.Rank)2 Matcher (java.util.regex.Matcher)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 Result (com.alessiodp.parties.addons.external.GriefPreventionHandler.Result)1