Search in sources :

Example 76 with PartyPlayerEntity

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

the class CommandPrefix method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command handling
		 */
    boolean isRemove = false;
    String prefix = "";
    if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_SUB_REMOVE)) {
        // Remove command
        isRemove = true;
    } else {
        // Normal command
        StringBuilder sb = new StringBuilder();
        for (int word = 1; word < commandData.getArgs().length; word++) {
            if (sb.length() > 0)
                sb.append(" ");
            sb.append(commandData.getArgs()[word]);
        }
        if (!Pattern.compile(ConfigMain.ADDITIONAL_TAG_CUSTOM_ALLOWEDCHARS).matcher(sb.toString()).matches() || (sb.toString().length() > ConfigMain.ADDITIONAL_TAG_CUSTOM_MAXLENGTH) || (sb.toString().length() < ConfigMain.ADDITIONAL_TAG_CUSTOM_MINLENGTH)) {
            pp.sendMessage(Messages.ADDCMD_PREFIX_INVALID);
            return;
        }
        if (PartiesUtils.checkCensor(sb.toString())) {
            pp.sendMessage(Messages.ADDCMD_PREFIX_CENSORED);
            return;
        }
        if (VaultHandler.payCommand(VaultHandler.VaultCommand.PREFIX, pp, commandData.getCommandLabel(), commandData.getArgs()))
            return;
        prefix = sb.toString();
    }
    /*
		 * Command starts
		 */
    party.setPrefix(prefix);
    party.updateParty();
    if (isRemove) {
        pp.sendMessage(Messages.ADDCMD_PREFIX_REMOVED);
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_PREFIX_REM.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
    } else {
        pp.sendMessage(Messages.ADDCMD_PREFIX_CHANGED);
        party.sendBroadcast(pp, Messages.ADDCMD_PREFIX_BROADCAST);
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_PREFIX.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 77 with PartyPlayerEntity

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

the class CommandRank 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.RANK.toString())) {
        pp.sendNoPermission(PartiesPermission.RANK);
        return false;
    }
    if (!player.hasPermission(PartiesPermission.RANK_OTHERS.toString())) {
        if (pp.getPartyName().isEmpty()) {
            pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
            return false;
        }
        if (!PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_ADMIN_RANK))
            return false;
    }
    if (commandData.getArgs().length != 3) {
        pp.sendMessage(Messages.MAINCMD_RANK_WRONGCMD);
        return false;
    }
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    commandData.addPermission(PartiesPermission.RANK_OTHERS);
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity)

Example 78 with PartyPlayerEntity

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

the class CommandReload method preRequisites.

@Override
public boolean preRequisites(CommandData commandData) {
    if (commandData.getSender() instanceof Player) {
        Player player = (Player) commandData.getSender();
        PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
        if (pp != null && !player.hasPermission(PartiesPermission.ADMIN_RELOAD.toString())) {
            pp.sendNoPermission(PartiesPermission.ADMIN_RELOAD);
            return false;
        }
        commandData.setPlayer((Player) commandData.getSender());
        commandData.setPartyPlayer(pp);
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity)

Example 79 with PartyPlayerEntity

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

the class CommandRename method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    PartyEntity party = null;
    Type type = Type.WRONGCMD;
    if (commandData.getArgs().length == 2) {
        // Own party
        if (!pp.getPartyName().isEmpty())
            party = plugin.getPartyManager().getParty(pp.getPartyName());
        type = Type.OWN;
    } else if (commandData.getArgs().length == 3) {
        // Another party
        if (commandData.havePermission(PartiesPermission.RENAME_OTHERS)) {
            party = plugin.getPartyManager().getParty(commandData.getArgs()[1]);
            type = Type.ANOTHER;
        }
    }
    if (party == null) {
        switch(type) {
            case OWN:
                // No party
                pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
                break;
            case ANOTHER:
                // Party doesn't exist
                pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
                break;
            case WRONGCMD:
                // Wrong command
                if (commandData.havePermission(PartiesPermission.RENAME_OTHERS))
                    pp.sendMessage(Messages.MAINCMD_RENAME_WRONGCMD_ADMIN);
                else
                    pp.sendMessage(Messages.MAINCMD_RENAME_WRONGCMD);
        }
        return;
    }
    if (type.equals(Type.OWN) && !PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_ADMIN_RENAME))
        return;
    // type == 1 ? args[1] : args[2]
    String partyName = commandData.getArgs()[(type.equals(Type.OWN) ? 1 : 2)];
    if (partyName.length() > ConfigParties.GENERAL_NAME_MAXLENGTH) {
        pp.sendMessage(Messages.MAINCMD_CREATE_NAMETOOLONG);
        return;
    }
    if (partyName.length() < ConfigParties.GENERAL_NAME_MINLENGTH) {
        pp.sendMessage(Messages.MAINCMD_CREATE_NAMETOOSHORT);
        return;
    }
    if (PartiesUtils.checkCensor(partyName)) {
        pp.sendMessage(Messages.MAINCMD_CREATE_CENSORED);
        return;
    }
    if (!Pattern.compile(ConfigParties.GENERAL_NAME_ALLOWEDCHARS).matcher(partyName).matches()) {
        pp.sendMessage(Messages.MAINCMD_CREATE_INVALIDNAME);
        return;
    }
    if (plugin.getPartyManager().existParty(partyName)) {
        pp.sendMessage(Messages.MAINCMD_CREATE_NAMEEXISTS.replace("%party%", partyName));
        return;
    }
    /*
		 * Command starts
		 */
    String oldPartyName = party.getName();
    // Calling API event
    PartiesPartyRenameEvent partiesRenameEvent = new PartiesPartyRenameEvent(party, partyName, pp, type.equals(Type.ANOTHER) ? true : false);
    Bukkit.getServer().getPluginManager().callEvent(partiesRenameEvent);
    partyName = partiesRenameEvent.getNewPartyName();
    if (!partiesRenameEvent.isCancelled()) {
        party.renamingParty();
        plugin.getDatabaseManager().renameParty(oldPartyName, partyName);
        for (Player player : party.getOnlinePlayers()) {
            plugin.getPlayerManager().getPlayer(player.getUniqueId()).setPartyName(partyName);
        }
        party.setName(partyName);
        plugin.getPartyManager().getListParties().remove(oldPartyName.toLowerCase());
        plugin.getPartyManager().getListParties().put(partyName.toLowerCase(), party);
        party.callChange();
        pp.sendMessage(Messages.MAINCMD_RENAME_RENAMED.replace("%old%", oldPartyName), party);
        party.sendBroadcast(pp, Messages.MAINCMD_RENAME_BROADCAST.replace("%old%", oldPartyName));
        LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_CREATE_FIXED.replace("{player}", pp.getName()).replace("{value}", oldPartyName).replace("{party}", party.getName()), true);
    } else {
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_RENAMEEVENT_DENY.replace("{party}", partyName).replace("{player}", pp.getName()), true);
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesPartyRenameEvent(com.alessiodp.partiesapi.events.PartiesPartyRenameEvent) Player(org.bukkit.entity.Player) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 80 with PartyPlayerEntity

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

the class CommandRename 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.RENAME.toString())) {
        pp.sendNoPermission(PartiesPermission.RENAME);
        return false;
    }
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    commandData.addPermission(PartiesPermission.RENAME_OTHERS);
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity)

Aggregations

PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)92 PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)56 Player (org.bukkit.entity.Player)53 EventHandler (org.bukkit.event.EventHandler)13 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)9 UUID (java.util.UUID)8 ArrayList (java.util.ArrayList)6 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)4 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)4 OfflinePlayer (org.bukkit.OfflinePlayer)4 Status (com.alessiodp.partiesapi.enums.Status)3 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)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 PartiesPlayerJoinEvent (com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent)2 Rank (com.alessiodp.partiesapi.interfaces.Rank)2 Matcher (java.util.regex.Matcher)2 Result (com.alessiodp.parties.addons.external.GriefPreventionHandler.Result)1