Search in sources :

Example 51 with PartyEntity

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

the class CommandP method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command handling
		 */
    if (ConfigParties.GENERAL_CHAT_CHATCD > 0 && !PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_BYPASSCOOLDOWN)) {
        Long unixTimestamp = plugin.getPlayerManager().getChatCooldown().get(pp.getPlayerUUID());
        long unixNow = System.currentTimeMillis() / 1000L;
        if (unixTimestamp != null) {
            pp.sendMessage(Messages.MAINCMD_P_COOLDOWN.replace("%seconds%", String.valueOf(ConfigParties.GENERAL_CHAT_CHATCD - (unixNow - unixTimestamp))));
            return;
        }
        plugin.getPlayerManager().getChatCooldown().put(pp.getPlayerUUID(), unixNow);
        new ChatTask(pp.getPlayerUUID(), plugin.getPlayerManager()).runTaskLater(plugin, ConfigParties.GENERAL_CHAT_CHATCD * 20);
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_CMD_P_TASK.replace("{value}", Integer.toString(ConfigParties.GENERAL_CHAT_CHATCD * 20)).replace("{player}", pp.getName()), true);
    }
    /*
		 * Command starts
		 */
    StringBuilder sb = new StringBuilder();
    for (String word : commandData.getArgs()) {
        if (sb.length() > 0) {
            sb.append(" ");
        }
        sb.append(word);
    }
    // Calling API event
    PartiesChatEvent partiesChatEvent = new PartiesChatEvent(pp, party, sb.toString());
    Bukkit.getServer().getPluginManager().callEvent(partiesChatEvent);
    String newMessage = partiesChatEvent.getMessage();
    if (!partiesChatEvent.isCancelled()) {
        party.sendPlayerMessage(pp, newMessage);
        if (ConfigMain.STORAGE_LOG_CHAT)
            LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_P.replace("{party}", party.getName()).replace("{player}", pp.getName()).replace("{message}", newMessage), true);
    } else
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_CHATEVENT_DENY.replace("{player}", pp.getName()).replace("{message}", sb.toString()), true);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) ChatTask(com.alessiodp.parties.tasks.ChatTask) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) PartiesChatEvent(com.alessiodp.partiesapi.events.PartiesChatEvent)

Example 52 with PartyEntity

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

the class CommandPassword 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.PASSWORD.toString())) {
        pp.sendNoPermission(PartiesPermission.PASSWORD);
        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_PASSWORD))
        return false;
    if (commandData.getArgs().length != 2) {
        pp.sendMessage(Messages.ADDCMD_PASSWORD_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 53 with PartyEntity

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

the class CommandPassword method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command handling
		 */
    boolean isRemove = false;
    String password = "";
    if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_SUB_REMOVE)) {
        // Remove command
        isRemove = true;
    } else {
        // Normal command
        if (!Pattern.compile(ConfigParties.PASSWORD_ALLOWECHARS).matcher(commandData.getArgs()[1]).matches() || (commandData.getArgs()[1].length() > ConfigParties.PASSWORD_MAXLENGTH) || (commandData.getArgs()[1].length() < ConfigParties.PASSWORD_MINLENGTH)) {
            pp.sendMessage(Messages.ADDCMD_PASSWORD_INVALID);
            return;
        }
        password = hash(commandData.getArgs()[1]);
    }
    /*
		 * Command starts
		 */
    party.setPassword(password);
    party.updateParty();
    if (isRemove) {
        pp.sendMessage(Messages.ADDCMD_PASSWORD_REMOVED);
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_PASSWORD_REM.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
    } else {
        pp.sendMessage(Messages.ADDCMD_PASSWORD_CHANGED);
        party.sendBroadcast(pp, Messages.ADDCMD_PASSWORD_BROADCAST);
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_PASSWORD.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 54 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity 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 55 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity 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)

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