Search in sources :

Example 61 with PartyPlayerEntity

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

the class PlayerManager method getPlayer.

public PartyPlayerEntity getPlayer(UUID uuid) {
    PartyPlayerEntity ret = null;
    if (getListPartyPlayers().containsKey(uuid)) {
        ret = getListPartyPlayers().get(uuid);
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PLAYER_GET_LIST.replace("{player}", ret.getName()).replace("{party}", ret.getPartyName()), true);
    } else {
        if (ret == null) {
            PartyPlayer pp = plugin.getDatabaseManager().getPlayer(uuid).join();
            if (pp != null) {
                ret = new PartyPlayerEntity(pp, plugin);
                // Compare name
                Player pl = ret.getPlayer();
                if (pl != null) {
                    ret.compareName(pl.getName());
                }
                LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PLAYER_GET_DATABASE.replace("{player}", ret.getName()).replace("{party}", ret.getPartyName()), true);
            }
        }
        if (ret == null)
            ret = new PartyPlayerEntity(uuid, plugin);
    }
    return ret;
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer)

Example 62 with PartyPlayerEntity

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

the class CommandInfo 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.INFO.toString())) {
        pp.sendNoPermission(PartiesPermission.INFO);
        return false;
    }
    if (commandData.getArgs().length == 1 && pp.getPartyName().isEmpty()) {
        pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
        return false;
    }
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    commandData.addPermission(PartiesPermission.INFO_OTHERS);
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity)

Example 63 with PartyPlayerEntity

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

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

the class CommandJoin 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.JOIN.toString())) {
        pp.sendNoPermission(PartiesPermission.JOIN);
        return false;
    }
    if (!pp.getPartyName().isEmpty()) {
        pp.sendMessage(Messages.ADDCMD_JOIN_ALREADYINPARTY);
        return false;
    }
    if (commandData.getArgs().length < 2 || commandData.getArgs().length > 3) {
        pp.sendMessage(Messages.ADDCMD_JOIN_WRONGCMD);
        return false;
    }
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    commandData.addPermission(PartiesPermission.JOIN_BYPASS);
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity)

Example 65 with PartyPlayerEntity

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

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