Search in sources :

Example 1 with PartiesPlayerJoinEvent

use of com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent in project Parties by AlessioDP.

the class PartyEntity method acceptInvite.

public void acceptInvite(UUID to) {
    plugin.getServer().getScheduler().cancelTask(invited.get(to));
    UUID from = whoInvite.get(to);
    PartyPlayerEntity fromPp = plugin.getPlayerManager().getPlayer(from);
    PartyPlayerEntity toPp = plugin.getPlayerManager().getPlayer(to);
    // Calling API Event
    PartiesPlayerJoinEvent partiesJoinEvent = new PartiesPlayerJoinEvent(toPp, this, true, from);
    Bukkit.getServer().getPluginManager().callEvent(partiesJoinEvent);
    if (!partiesJoinEvent.isCancelled()) {
        // Send accepted
        fromPp.sendMessage(Messages.MAINCMD_ACCEPT_ACCEPTRECEIPT, toPp);
        // Send you accepted
        toPp.sendMessage(Messages.MAINCMD_ACCEPT_ACCEPTED, fromPp);
        whoInvite.remove(to);
        invited.remove(to);
        toPp.setLastInvite("");
        sendBroadcast(toPp, Messages.MAINCMD_ACCEPT_BROADCAST);
        getMembers().add(to);
        onlinePlayers.add(toPp.getPlayer());
        toPp.setPartyName(getName());
        toPp.setRank(ConfigParties.RANK_SET_DEFAULT);
        updateParty();
        toPp.updatePlayer();
        callChange();
    } else
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_JOINEVENT_DENY.replace("{player}", toPp.getName()).replace("{party}", getName()), true);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) UUID(java.util.UUID) PartiesPlayerJoinEvent(com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent)

Example 2 with PartiesPlayerJoinEvent

use of com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent 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)

Aggregations

PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)2 PartiesPlayerJoinEvent (com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent)2 PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)1 UUID (java.util.UUID)1