Search in sources :

Example 71 with PartyPlayerEntity

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

the class CommandMotd method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command handling
		 */
    boolean isRemove = false;
    String motd = "";
    if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_SUB_REMOVE)) {
        // Remove command
        isRemove = true;
    } else {
        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(ConfigParties.MOTD_ALLOWEDCHARS).matcher(sb.toString()).matches() || (sb.toString().length() > ConfigParties.MOTD_MAXLENGTH) || (sb.toString().length() < ConfigParties.MOTD_MINLENGTH)) {
            pp.sendMessage(Messages.ADDCMD_MOTD_INVALID);
            return;
        }
        if (PartiesUtils.checkCensor(sb.toString())) {
            pp.sendMessage(Messages.ADDCMD_MOTD_CENSORED);
            return;
        }
        if (VaultHandler.payCommand(VaultHandler.VaultCommand.MOTD, pp, commandData.getCommandLabel(), commandData.getArgs()))
            return;
        motd = sb.toString();
    }
    /*
		 * Command starts
		 */
    party.setMotd(motd);
    party.updateParty();
    if (isRemove) {
        pp.sendMessage(Messages.ADDCMD_MOTD_REMOVED);
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_MOTD.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
    } else {
        pp.sendMessage(Messages.ADDCMD_MOTD_CHANGED);
        party.sendBroadcast(pp, Messages.ADDCMD_MOTD_BROADCAST);
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_MOTD_REM.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 72 with PartyPlayerEntity

use of com.alessiodp.parties.players.objects.PartyPlayerEntity 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 73 with PartyPlayerEntity

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

the class CommandParty method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command starts
		 */
    List<String> list = new ArrayList<String>();
    LinkedHashMap<String, String> commands = pp.getAllowedCommands();
    for (Entry<String, String> entry : commands.entrySet()) {
        list.add(entry.getValue());
    }
    // Split commands per page
    int page = 1;
    int maxpages;
    if (list.size() == 0)
        maxpages = 1;
    else if ((list.size() % ConfigMain.COMMANDS_HELP_PERPAGE) == 0)
        maxpages = list.size() / ConfigMain.COMMANDS_HELP_PERPAGE;
    else
        maxpages = (list.size() / ConfigMain.COMMANDS_HELP_PERPAGE) + 1;
    // Start priting
    int commandNumber = 0;
    String message = Messages.HELP_HEADER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages)) + "\n";
    for (String string : list) {
        int currentChoosenPage = (page - 1) * ConfigMain.COMMANDS_HELP_PERPAGE;
        if (commandNumber >= currentChoosenPage && commandNumber < currentChoosenPage + ConfigMain.COMMANDS_HELP_PERPAGE) {
            message += string + "\n";
        }
        commandNumber++;
    }
    message += Messages.HELP_FOOTER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages));
    pp.sendMessage(message);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) ArrayList(java.util.ArrayList)

Example 74 with PartyPlayerEntity

use of com.alessiodp.parties.players.objects.PartyPlayerEntity 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 75 with PartyPlayerEntity

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

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