Search in sources :

Example 46 with PartyEntity

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

the class CommandJoin method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    String partyName = commandData.getArgs()[1];
    PartyEntity party = plugin.getPartyManager().getParty(partyName);
    if (party == null) {
        pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", partyName));
        return;
    }
    if (commandData.getArgs().length == 2) {
        if (!commandData.havePermission(PartiesPermission.JOIN_BYPASS)) {
            if (party.getPassword() != null && !party.getPassword().isEmpty()) {
                pp.sendMessage(Messages.ADDCMD_JOIN_WRONGPASSWORD);
                return;
            }
        }
    } else {
        if (!hash(commandData.getArgs()[2]).equals(party.getPassword())) {
            pp.sendMessage(Messages.ADDCMD_JOIN_WRONGPASSWORD);
            return;
        }
    }
    if ((ConfigParties.GENERAL_MEMBERSLIMIT != -1) && (party.getMembers().size() >= ConfigParties.GENERAL_MEMBERSLIMIT)) {
        pp.sendMessage(Messages.PARTIES_COMMON_PARTYFULL);
        return;
    }
    if (VaultHandler.payCommand(VaultHandler.VaultCommand.JOIN, pp, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    /*
		 * Command starts
		 */
    // Calling API Event
    PartiesPlayerJoinEvent partiesJoinEvent = new PartiesPlayerJoinEvent(pp, party, false, null);
    Bukkit.getServer().getPluginManager().callEvent(partiesJoinEvent);
    if (!partiesJoinEvent.isCancelled()) {
        pp.sendMessage(Messages.ADDCMD_JOIN_JOINED);
        party.sendBroadcast(pp, Messages.ADDCMD_JOIN_PLAYERJOINED);
        party.getMembers().add(pp.getPlayerUUID());
        party.getOnlinePlayers().add(pp.getPlayer());
        pp.setPartyName(party.getName());
        pp.setRank(ConfigParties.RANK_SET_DEFAULT);
        party.updateParty();
        pp.updatePlayer();
        party.callChange();
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_JOIN.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
    } else
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_JOINEVENT_DENY.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) PartiesPlayerJoinEvent(com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent)

Example 47 with PartyEntity

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

the class CommandInvite method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command handling
		 */
    Player invitedPlayer = plugin.getServer().getPlayer(commandData.getArgs()[1]);
    if ((invitedPlayer == null) || (!invitedPlayer.isOnline())) {
        pp.sendMessage(Messages.MAINCMD_INVITE_PLAYEROFFLINE);
        return;
    }
    PartyPlayerEntity invitedPp = plugin.getPlayerManager().getPlayer(invitedPlayer.getUniqueId());
    if (!invitedPp.getPartyName().isEmpty()) {
        pp.sendMessage(Messages.MAINCMD_INVITE_PLAYERINPARTY, invitedPp);
        return;
    }
    if (ConfigParties.GENERAL_INVITE_PREVENTINVITEPERM && !invitedPlayer.hasPermission(PartiesPermission.ACCEPT.toString())) {
        pp.sendMessage(Messages.MAINCMD_INVITE_PLAYERNOPERM, invitedPp);
        return;
    }
    if (invitedPp.getIgnoredParties().contains(party.getName())) {
        // Invited player ignoring the party, fake sent
        pp.sendMessage(Messages.MAINCMD_INVITE_SENT, invitedPp);
        return;
    }
    if (invitedPp.isPreventNotify() && ConfigMain.ADDITIONAL_NOTIFY_ENABLE && ConfigMain.ADDITIONAL_NOTIFY_BLOCK_INVITE) {
        // Invited player has disabled notifications, fake sent
        pp.sendMessage(Messages.MAINCMD_INVITE_SENT, invitedPp);
        return;
    }
    boolean isRevoke = false;
    if (invitedPp.getLastInvite().contains(party.getName())) {
        isRevoke = true;
        if (!ConfigParties.GENERAL_INVITE_REVOKE) {
            pp.sendMessage(Messages.MAINCMD_INVITE_ALREADYINVITED, invitedPp);
            return;
        }
    }
    if (!isRevoke && ConfigParties.GENERAL_INVITE_COOLDOWN_ENABLE) {
        // Check invite cooldown
        ArrayList<InviteCooldown> list = plugin.getPlayerManager().getInviteCooldown().get(pp.getPlayerUUID());
        if (list != null) {
            for (InviteCooldown ic : list) {
                long diff = ic.getDiffTime();
                if (ic.getType() == InviteCooldown.CooldownType.GLOBAL || ic.getInvited().equals(invitedPp.getPlayerUUID())) {
                    if (diff < ic.getType().getTick()) {
                        String msg = "";
                        switch(ic.getType()) {
                            case GLOBAL:
                                msg = Messages.MAINCMD_INVITE_COOLDOWN_GLOBAL;
                                break;
                            case INDIVIDUAL:
                                msg = Messages.MAINCMD_INVITE_COOLDOWN_INDIVIDUAL;
                        }
                        pp.sendMessage(msg.replace("%seconds%", String.valueOf(ic.getType().getTick() - diff)));
                        return;
                    }
                }
            }
        }
    }
    /*
		 * Command starts
		 */
    if (isRevoke) {
        // Revoke
        plugin.getServer().getScheduler().cancelTask(party.getInvited().get(invitedPp.getPlayerUUID()));
        party.getInvited().remove(invitedPp.getPlayerUUID());
        party.getWhoInvite().remove(invitedPp.getPlayerUUID());
        invitedPp.setLastInvite("");
        pp.sendMessage(Messages.MAINCMD_INVITE_REVOKE_SENT, invitedPp);
        invitedPp.sendMessage(Messages.MAINCMD_INVITE_REVOKE_REVOKED, party);
    } else {
        // Invite
        invitedPp.setLastInvite(party.getName());
        pp.sendMessage(Messages.MAINCMD_INVITE_SENT, invitedPp);
        invitedPp.sendMessage(Messages.MAINCMD_INVITE_PLAYERINVITED.replace("%player%", pp.getName()), party);
        party.invitePlayer(pp.getPlayerUUID(), invitedPlayer.getUniqueId());
        if (ConfigParties.GENERAL_INVITE_COOLDOWN_ENABLE) {
            if (ConfigParties.GENERAL_INVITE_COOLDOWN_GLOBAL > 0) {
                new InviteCooldown(plugin, pp.getPlayerUUID()).createTask(ConfigParties.GENERAL_INVITE_COOLDOWN_GLOBAL);
            }
            if (ConfigParties.GENERAL_INVITE_COOLDOWN_INDIVIDUAL > 0) {
                new InviteCooldown(plugin, pp.getPlayerUUID(), invitedPp.getPlayerUUID()).createTask(ConfigParties.GENERAL_INVITE_COOLDOWN_INDIVIDUAL);
            }
        }
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_INVITE.replace("{player}", pp.getName()).replace("{victim}", invitedPlayer.getName()).replace("{party}", party.getName()), true);
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) InviteCooldown(com.alessiodp.parties.players.objects.InviteCooldown)

Example 48 with PartyEntity

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

the class CommandKick method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    String playerName = commandData.getArgs()[1];
    UUID playerUUID = null;
    // Players conflict handler
    List<PartyPlayer> listPlayers = plugin.getDatabaseManager().getPartyPlayersByName(playerName).join();
    UUID[] playerSelection = new UUID[listPlayers.size()];
    if (listPlayers.size() < 1) {
        // Other player not in party
        pp.sendMessage(Messages.MAINCMD_KICK_PLAYERNOTINPARTY_OTHER.replace("%player%", playerName));
        return;
    } else if (listPlayers.size() == 1) {
        // Get the player
        playerUUID = listPlayers.get(0).getPlayerUUID();
    } else {
        // Found multiple players name
        StringBuilder sb = new StringBuilder();
        for (String str : Messages.MAINCMD_KICK_CONFLICT_CONTENT) {
            if (str.contains("%list_players%")) {
                int i = 1;
                for (PartyPlayer pl : listPlayers) {
                    String mojangName = getNameFromMojangAPI(playerName, pl.getPlayerUUID());
                    if (mojangName == null)
                        mojangName = pl.getName();
                    Date date = new Date(pl.getNameTimestamp() * 1000);
                    Time time = new Time(date.getTime());
                    sb.append(Messages.MAINCMD_KICK_CONFLICT_PLAYER.replace("%number%", Integer.toString(i)).replace("%username%", mojangName).replace("%party%", pl.getPartyName()).replace("%date%", date.toString()).replace("%time%", time.toString()) + "\n");
                    playerSelection[i - 1] = pl.getPlayerUUID();
                    i++;
                }
            } else
                sb.append(str + "\n");
        }
        // Selection handling
        if (commandData.getArgs().length == 2) {
            // Print content
            pp.sendMessage(sb.toString());
            return;
        }
        int sel = -1;
        try {
            sel = Integer.parseInt(commandData.getArgs()[2]);
            playerUUID = playerSelection[sel - 1];
        } catch (Exception ex) {
            // Problem with selection, print content
            pp.sendMessage(sb.toString());
            return;
        }
    }
    OfflinePlayer kickedPlayer = Bukkit.getOfflinePlayer(playerUUID);
    PartyPlayerEntity kickedPp = plugin.getPlayerManager().getPlayer(playerUUID);
    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
    boolean otherParty = false;
    if (party == null || !party.getMembers().contains(kickedPlayer.getUniqueId()) && commandData.havePermission(PartiesPermission.KICK_OTHERS)) {
        // Other party
        otherParty = true;
        party = plugin.getPartyManager().getParty(kickedPp.getPartyName());
        if (party == null) {
            pp.sendMessage(Messages.MAINCMD_KICK_PLAYERNOTINPARTY_OTHER, kickedPp);
            return;
        }
    } else {
        // Same party
        if (party == null || !party.getMembers().contains(playerUUID)) {
            pp.sendMessage(Messages.MAINCMD_KICK_PLAYERNOTINPARTY, kickedPp);
            return;
        }
        if (pp.getRank() < kickedPp.getRank() && !commandData.havePermission(PartiesPermission.KICK_OTHERS)) {
            pp.sendMessage(Messages.MAINCMD_KICK_PLAYERHIGHERRANK, kickedPp);
            return;
        }
    }
    /*
		 * Command starts
		 */
    // Calling API event
    PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(kickedPp, party, otherParty, pp);
    Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
    if (!partiesLeaveEvent.isCancelled()) {
        if (party.getLeader().equals(kickedPlayer.getUniqueId())) {
            // Leader
            // Calling Pre API event
            PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.LEAVE, kickedPp, pp);
            Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
            if (!partiesPreDeleteEvent.isCancelled()) {
                // Disbanding party
                pp.sendMessage(Messages.MAINCMD_KICK_SENT, kickedPp);
                party.sendBroadcast(pp, Messages.MAINCMD_KICK_BROADCAST_DISBAND);
                party.removeParty();
                party.callChange();
                // Calling Post API event
                PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.LEAVE, kickedPp, pp);
                Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
                LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_KICK_DISBAND.replace("{player}", kickedPp.getName()).replace("{party}", party.getName()).replace("{sender}", pp.getName()).replace("{other}", Boolean.toString(otherParty)), true);
            } else
                LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
        } else {
            // Normal
            party.getMembers().remove(kickedPlayer.getUniqueId());
            Player kickedPl = kickedPp.getPlayer();
            if (kickedPl != null) {
                // Online
                party.getOnlinePlayers().remove(kickedPl);
                pp.sendMessage(Messages.MAINCMD_KICK_SENT, kickedPp);
                kickedPp.sendMessage(Messages.MAINCMD_KICK_PLAYERKICKED, pp);
                party.sendBroadcast(kickedPp, Messages.MAINCMD_KICK_BROADCAST);
                kickedPp.cleanupPlayer(true);
                party.callChange();
            } else {
                pp.sendMessage(Messages.MAINCMD_KICK_SENT, kickedPp);
                party.sendBroadcast(kickedPp, Messages.MAINCMD_KICK_BROADCAST);
                kickedPp.cleanupPlayer(true);
            }
            party.updateParty();
            LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_KICK.replace("{player}", kickedPp.getName()).replace("{party}", party.getName()).replace("{sender}", pp.getName()).replace("{other}", Boolean.toString(otherParty)), true);
        }
    } else
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
}
Also used : PartiesPartyPostDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) Time(java.sql.Time) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) PartiesPlayerLeaveEvent(com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent) Date(java.sql.Date) PartiesPartyPreDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent) OfflinePlayer(org.bukkit.OfflinePlayer) UUID(java.util.UUID)

Example 49 with PartyEntity

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

the class CommandLeave 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.LEAVE.toString())) {
        pp.sendNoPermission(PartiesPermission.LEAVE);
        return false;
    }
    PartyEntity party = pp.getPartyName().isEmpty() ? null : plugin.getPartyManager().getParty(pp.getPartyName());
    if (party == null) {
        pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
        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 50 with PartyEntity

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

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