Search in sources :

Example 21 with PartyEntity

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

the class MotdTask method run.

@Override
public void run() {
    if (pl != null && pl.isOnline()) {
        PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(pl.getUniqueId());
        if (createID.equals(pp.getCreateID()) && !pp.getPartyName().isEmpty()) {
            PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
            if (party != null && !party.getMotd().isEmpty()) {
                StringBuilder sb = new StringBuilder();
                for (String str : Messages.ADDCMD_MOTD_CONTENT) {
                    sb.append(str.replace(Constants.PLACEHOLDER_PARTY_MOTD, "%temporary_motd%") + "\n");
                }
                String message = PartiesUtils.convertAllPlaceholders(sb.toString(), party, pp);
                sb = new StringBuilder();
                for (String str : party.getMotd().split(ConfigParties.MOTD_NEWLINECODE)) {
                    sb.append(str + "\n");
                }
                message = message.replace("%temporary_motd%", sb.toString());
                pp.sendMessage(message);
            }
        }
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 22 with PartyEntity

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

the class PartiesUtils method handleExperienceDistribution.

/*
	 * Experience
	 */
public static boolean handleExperienceDistribution(Player killer, Entity killedMob, String killedMobName, double vanillaExp, double skillApiExp) {
    boolean ret = false;
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(killer.getUniqueId());
    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
    if (party != null) {
        // Start to handle the event
        // Get nearest players
        List<Player> playersList = new ArrayList<Player>();
        playersList.add(killer);
        for (Player partyPlayer : party.getOnlinePlayers()) {
            if (!partyPlayer.getUniqueId().equals(killer.getUniqueId()) && partyPlayer.getLocation().getWorld() == killer.getWorld() && killer.getLocation().distance(partyPlayer.getLocation()) < ConfigMain.ADDITIONAL_EXP_RANGE) {
                playersList.add(partyPlayer);
            }
        }
        if (playersList.size() > 1) {
            // Remove skillapi exp handler
            if (skillApiExp > 0) {
                SkillAPIHandler.blockEvent(killedMob);
            }
            // Merge experience
            switch(ConfigMain.ADDITIONAL_EXP_GIVEAS_VANILLA) {
                case VANILLA:
                    // Same exp
                    break;
                case SKILLAPI:
                    skillApiExp += vanillaExp;
                    vanillaExp = 0;
                    break;
            }
            switch(ConfigMain.ADDITIONAL_EXP_GIVEAS_SKILLAPI) {
                case VANILLA:
                    vanillaExp += skillApiExp;
                    skillApiExp = 0;
                    break;
                case SKILLAPI:
                    // Same exp
                    break;
            }
            // Give experience
            if (vanillaExp > 0) {
                PartiesUtils.distributeExperience(pp, playersList, killedMobName, vanillaExp, ExpType.VANILLA);
            }
            if (skillApiExp > 0) {
                PartiesUtils.distributeExperience(pp, playersList, killedMobName, skillApiExp, ExpType.SKILLAPI);
            }
            ret = true;
        }
    }
    return ret;
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 23 with PartyEntity

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

the class CommandP method preRequisites.

@Override
public boolean preRequisites(CommandData commandData) {
    Player player = (Player) commandData.getSender();
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
    /*
		 * Checks for command prerequisites
		 */
    if (!player.hasPermission(PartiesPermission.SENDMESSAGE.toString())) {
        pp.sendNoPermission(PartiesPermission.SENDMESSAGE);
        return false;
    }
    PartyEntity party = pp.getPartyName().isEmpty() ? null : plugin.getPartyManager().getParty(pp.getPartyName());
    if (party == null) {
        pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
        return false;
    }
    if (!PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_SENDMESSAGE))
        return false;
    if (commandData.getArgs().length == 0) {
        pp.sendMessage(Messages.MAINCMD_P_WRONGCMD);
        return false;
    }
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    commandData.setParty(party);
    commandData.addPermission(PartiesPermission.KICK_OTHERS);
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 24 with PartyEntity

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

the class CommandPrefix method preRequisites.

@Override
public boolean preRequisites(CommandData commandData) {
    Player player = (Player) commandData.getSender();
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
    /*
		 * Checks for command prerequisites
		 */
    if (!player.hasPermission(PartiesPermission.PREFIX.toString())) {
        pp.sendNoPermission(PartiesPermission.PREFIX);
        return false;
    }
    PartyEntity party = pp.getPartyName().isEmpty() ? null : plugin.getPartyManager().getParty(pp.getPartyName());
    if (party == null) {
        pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
        return false;
    }
    if (!PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_EDIT_PREFIX))
        return false;
    if (commandData.getArgs().length < 2) {
        pp.sendMessage(Messages.ADDCMD_PREFIX_WRONGCMD);
        return false;
    }
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    commandData.setParty(party);
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 25 with PartyEntity

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

the class CommandRank method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    String playerName = commandData.getArgs()[1];
    PartyPlayerEntity promoted;
    // Conflict checker
    List<PartyPlayer> listPlayers = plugin.getDatabaseManager().getPartyPlayersByName(playerName).join();
    if (!listPlayers.isEmpty()) {
        promoted = plugin.getPlayerManager().getPlayer(listPlayers.get(0).getPlayerUUID());
    } else {
        pp.sendMessage(Messages.MAINCMD_RANK_PLAYERNOTINPARTY_OTHER.replace("%player%", playerName));
        return;
    }
    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
    if (commandData.havePermission(PartiesPermission.RANK_OTHERS)) {
        party = plugin.getPartyManager().getParty(promoted.getPartyName());
        if (party == null) {
            pp.sendMessage(Messages.MAINCMD_RANK_PLAYERNOTINPARTY_OTHER, promoted);
            return;
        }
    } else {
        if (party == null || !party.getMembers().contains(promoted.getPlayerUUID())) {
            pp.sendMessage(Messages.MAINCMD_RANK_PLAYERNOTINPARTY, promoted);
            return;
        }
    }
    if (!party.getMembers().contains(promoted.getPlayerUUID())) {
        if (!commandData.havePermission(PartiesPermission.RANK_OTHERS) || promoted.getPartyName().isEmpty()) {
            pp.sendMessage(Messages.MAINCMD_RANK_PLAYERNOTINPARTY, promoted);
            return;
        }
        party = plugin.getPartyManager().getParty(promoted.getPartyName());
    }
    Rank rank = plugin.getRankManager().searchRankByName(commandData.getArgs()[2]);
    if (rank == null) {
        pp.sendMessage(Messages.MAINCMD_RANK_WRONGRANK.replace("%rank_typed%", // TODO: Bypass, remove in future updates
        commandData.getArgs()[2]).replace("%rank_name%", commandData.getArgs()[2]).replace("%rank_chat%", commandData.getArgs()[2]));
        return;
    }
    if (rank.getLevel() == promoted.getRank()) {
        pp.sendMessage(Messages.MAINCMD_RANK_SAMERANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promoted.getName()));
        return;
    }
    if (!commandData.havePermission(PartiesPermission.RANK_OTHERS)) {
        if (pp.getRank() <= promoted.getRank()) {
            pp.sendMessage(Messages.MAINCMD_RANK_LOWRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promoted.getName()));
            return;
        }
        if (promoted.getPlayerUUID().equals(pp.getPlayerUUID())) {
            pp.sendMessage(Messages.MAINCMD_RANK_CHANGINGYOURSELF);
            return;
        }
        if ((rank.getLevel() != ConfigParties.RANK_SET_HIGHER) && (rank.getLevel() >= pp.getRank())) {
            pp.sendMessage(Messages.MAINCMD_RANK_TOHIGHERRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()));
            return;
        }
    }
    /*
		 * Command starts
		 */
    int oldRank = promoted.getRank();
    if (rank.getLevel() == ConfigParties.RANK_SET_HIGHER) {
        PartyPlayerEntity oldLeader = plugin.getPlayerManager().getPlayer(party.getLeader());
        oldLeader.setRank(promoted.getRank());
        oldLeader.updatePlayer();
        party.setLeader(promoted.getPlayerUUID());
        party.updateParty();
    }
    promoted.setRank(rank.getLevel());
    promoted.updatePlayer();
    party.callChange();
    pp.sendMessage(Messages.MAINCMD_RANK_CHANGED, promoted);
    party.sendBroadcast(promoted, Messages.MAINCMD_RANK_BROADCAST);
    LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_RANK.replace("{player}", promoted.getName()).replace("{value1}", Integer.toString(oldRank)).replace("{value2}", Integer.toString(rank.getLevel())).replace("{sender}", pp.getName()), true);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) Rank(com.alessiodp.partiesapi.interfaces.Rank) 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