Search in sources :

Example 86 with PartyPlayerEntity

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

the class CommandConfirm method onCommand.

@Override
public void onCommand(CommandData commandData) {
    Player player = (Player) commandData.getSender();
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
    /*
		 * Checks for command prerequisites
		 */
    Object[] packet = pp.getLastCommand();
    if (packet == null || ((System.currentTimeMillis() - (long) packet[0]) > ConfigMain.ADDONS_VAULT_CONFIRM_TIMEOUT)) {
        pp.sendMessage(Messages.ADDCMD_VAULT_CONFIRM_NOCMD);
        return;
    }
    /*
		 * Command starts
		 */
    packet[2] = true;
    pp.setLastCommand(packet);
    pp.sendMessage(Messages.ADDCMD_VAULT_CONFIRM_CONFIRMED);
    // Bukkit.isPrimaryThread() to check if is async, false == async
    // Make it sync
    plugin.getPartiesScheduler().runSync(() -> {
        plugin.getServer().dispatchCommand(pp.getPlayer(), (String) packet[1]);
    });
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity)

Example 87 with PartyPlayerEntity

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

the class CommandCreate method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    String partyName = commandData.getArgs()[1];
    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;
    }
    boolean isFixed = false;
    if (ConfigParties.FIXED_ENABLE && commandData.getArgs().length > 2 && commandData.getArgs()[2].equalsIgnoreCase(ConfigMain.COMMANDS_SUB_FIXED)) {
        if (commandData.havePermission(PartiesPermission.ADMIN_CREATE_FIXED))
            isFixed = true;
    }
    if (VaultHandler.payCommand(VaultHandler.VaultCommand.CREATE, pp, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    /*
		 * Command starts
		 */
    PartyEntity party;
    // Calling Pre API event
    PartiesPartyPreCreateEvent partiesPreEvent = new PartiesPartyPreCreateEvent(pp, partyName, isFixed);
    Bukkit.getServer().getPluginManager().callEvent(partiesPreEvent);
    String newPartyName = partiesPreEvent.getPartyName();
    boolean newIsFixed = partiesPreEvent.isFixed();
    if (!partiesPreEvent.isCancelled()) {
        if (newIsFixed) {
            // Fixed creation
            party = new PartyEntity(newPartyName, plugin);
            party.setLeader(UUID.fromString(Constants.FIXED_VALUE_UUID));
            party.setFixed(true);
            plugin.getPartyManager().getListParties().put(party.getName().toLowerCase(), party);
            party.updateParty();
            pp.sendMessage(Messages.MAINCMD_CREATE_CREATEDFIXED, party);
            LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_CREATE_FIXED.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
        } else {
            // Normal creation
            party = new PartyEntity(newPartyName, plugin);
            party.getMembers().add(pp.getPlayerUUID());
            if (pp.getPlayer() != null)
                party.getOnlinePlayers().add(pp.getPlayer());
            party.setLeader(pp.getPlayerUUID());
            plugin.getPartyManager().getListParties().put(party.getName().toLowerCase(), party);
            pp.setRank(ConfigParties.RANK_SET_HIGHER);
            pp.setPartyName(party.getName());
            party.updateParty();
            pp.updatePlayer();
            party.callChange();
            pp.sendMessage(Messages.MAINCMD_CREATE_CREATED, party);
            LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_CREATE.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
        }
        // Calling API event
        PartiesPartyPostCreateEvent partiesPostEvent = new PartiesPartyPostCreateEvent(pp, party);
        Bukkit.getServer().getPluginManager().callEvent(partiesPostEvent);
    } else {
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_CREATEEVENT_DENY.replace("{party}", partyName).replace("{player}", pp.getName()), true);
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesPartyPreCreateEvent(com.alessiodp.partiesapi.events.PartiesPartyPreCreateEvent) PartiesPartyPostCreateEvent(com.alessiodp.partiesapi.events.PartiesPartyPostCreateEvent) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 88 with PartyPlayerEntity

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

the class CommandDelete method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    PartyEntity party = plugin.getPartyManager().getParty(commandData.getArgs()[1]);
    if (party == null) {
        pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
        return;
    }
    boolean isSilent = false;
    if (commandData.getArgs().length == 3) {
        if (commandData.havePermission(PartiesPermission.ADMIN_DELETE_SILENT) && commandData.getArgs()[2].equalsIgnoreCase(ConfigMain.COMMANDS_SUB_SILENT)) {
            isSilent = true;
        } else {
            pp.sendMessage(Messages.MAINCMD_DELETE_WRONGCMD);
            return;
        }
    }
    /*
		 * Command starts
		 */
    // Calling Pre API event
    PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.DELETE, null, pp);
    Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
    if (!partiesPreDeleteEvent.isCancelled()) {
        if (isSilent) {
            pp.sendMessage(Messages.MAINCMD_DELETE_DELETEDSILENTLY, party);
        } else {
            pp.sendMessage(Messages.MAINCMD_DELETE_DELETED, party);
            party.sendBroadcast(pp, Messages.MAINCMD_DELETE_BROADCAST);
        }
        party.removeParty();
        // Calling Post API event
        PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.DELETE, null, pp);
        Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
        LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_DELETE.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
    } else {
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_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) PartiesPartyPreDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 89 with PartyPlayerEntity

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

the class CommandDeny 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.DENY.toString())) {
        pp.sendNoPermission(PartiesPermission.DENY);
        return false;
    }
    if (pp.getLastInvite().isEmpty()) {
        pp.sendMessage(Messages.MAINCMD_DENY_NOINVITE);
        return false;
    }
    PartyEntity party = plugin.getPartyManager().getParty(pp.getLastInvite());
    if (party == null) {
        pp.sendMessage(Messages.MAINCMD_DENY_NOEXISTS);
        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 90 with PartyPlayerEntity

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

the class CommandDesc method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command handling
		 */
    boolean isRemove = false;
    String description = "";
    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(ConfigParties.DESC_ALLOWEDCHARS).matcher(sb.toString()).matches() || (sb.toString().length() > ConfigParties.DESC_MAXLENGTH) || (sb.toString().length() < ConfigParties.DESC_MINLENGTH)) {
            pp.sendMessage(Messages.ADDCMD_DESC_INVALID);
            return;
        }
        if (PartiesUtils.checkCensor(sb.toString())) {
            pp.sendMessage(Messages.ADDCMD_DESC_CENSORED);
            return;
        }
        if (VaultHandler.payCommand(VaultHandler.VaultCommand.DESC, pp, commandData.getCommandLabel(), commandData.getArgs()))
            return;
        description = sb.toString();
    }
    /*
		 * Command starts
		 */
    party.setDescription(description);
    party.updateParty();
    if (isRemove) {
        pp.sendMessage(Messages.ADDCMD_DESC_REMOVED);
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_DESC_REM.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
    } else {
        pp.sendMessage(Messages.ADDCMD_DESC_CHANGED);
        party.sendBroadcast(pp, Messages.ADDCMD_DESC_BROADCAST);
        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_DESC.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