Search in sources :

Example 66 with PartyPlayerEntity

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

the class CommandKick 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.KICK.toString())) {
        pp.sendNoPermission(PartiesPermission.KICK);
        return false;
    }
    if (!player.hasPermission(PartiesPermission.KICK_OTHERS.toString())) {
        if (pp.getPartyName().isEmpty()) {
            pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
            return false;
        }
        if (!PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_KICK))
            return false;
    }
    if (commandData.getArgs().length < 2) {
        pp.sendMessage(Messages.MAINCMD_KICK_WRONGCMD);
        return false;
    }
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    commandData.addPermission(PartiesPermission.KICK_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 67 with PartyPlayerEntity

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

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

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

the class CommandMigrate method preRequisites.

@Override
public boolean preRequisites(CommandData commandData) {
    if (commandData.getSender() instanceof Player) {
        Player player = (Player) commandData.getSender();
        PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
        commandData.setPlayer((Player) commandData.getSender());
        commandData.setPartyPlayer(pp);
        commandData.addPermission(PartiesPermission.ADMIN_MIGRATE);
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity)

Example 70 with PartyPlayerEntity

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

the class CommandMigrate method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    if (pp == null || !ConfigMain.STORAGE_MIGRATE_ONLYCONSOLE) {
        // If party is null == is a console (PASS), or if it's a player => is onlyconsole false? (PASS)
        if (pp == null || commandData.havePermission(PartiesPermission.ADMIN_MIGRATE)) {
            StorageType databaseNow = plugin.getDatabaseManager().getDatabaseType();
            if (commandData.getArgs().length == 3) {
                // Migrate command
                StorageType databaseFrom = StorageType.getExactEnum(commandData.getArgs()[1]);
                StorageType databaseTo = StorageType.getExactEnum(commandData.getArgs()[2]);
                if (databaseFrom != null && databaseTo != null && !databaseFrom.isNone() && !databaseTo.isNone()) {
                    // Exist these databases?
                    if (!databaseFrom.equals(databaseTo)) {
                        // Are different these databases?
                        if (!plugin.getDatabaseManager().isStorageOnline(databaseFrom)) {
                            // Database from is offline
                            String msg = Messages.MAINCMD_MIGRATE_FAILED_DBOFFLINE.replace("%database%", databaseFrom.getFormattedName());
                            sendMessage(msg, pp, commandData.getSender());
                        } else if (!plugin.getDatabaseManager().isStorageOnline(databaseTo)) {
                            // Database to is offline
                            String msg = Messages.MAINCMD_MIGRATE_FAILED_DBOFFLINE.replace("%database%", databaseTo.getFormattedName());
                            sendMessage(msg, pp, commandData.getSender());
                        } else {
                            // Databases online, start migration
                            if (plugin.getDatabaseManager().migrate(databaseFrom, databaseTo)) {
                                // Migration done
                                String msg = Messages.MAINCMD_MIGRATE_COMPLETED.replace("%database_to%", databaseTo.getFormattedName()).replace("%database_from%", databaseFrom.getFormattedName());
                                sendMessage(msg, pp, commandData.getSender());
                                LoggerManager.log(LogLevel.BASIC, msg, commandData.getPlayer() != null ? true : false);
                            } else {
                                // Migration failed
                                String msg = Messages.MAINCMD_MIGRATE_FAILED_FAILED.replace("%database_to%", databaseTo.getFormattedName()).replace("%database_from%", databaseFrom.getFormattedName());
                                sendMessage(msg, pp, commandData.getSender());
                                LoggerManager.log(LogLevel.BASIC, msg, commandData.getPlayer() != null ? true : false);
                            }
                        }
                    } else {
                        // Same databases
                        sendMessage(Messages.MAINCMD_MIGRATE_FAILED_SAMEDB, pp, commandData.getSender());
                    }
                } else {
                    // Wrong database (or None)
                    sendMessage(Messages.MAINCMD_MIGRATE_WRONGDB, pp, commandData.getSender());
                }
            } else {
                // Shows info
                String msg = Messages.MAINCMD_MIGRATE_INFO.replace("%database%", databaseNow.getFormattedName());
                sendMessage(msg, pp, commandData.getSender());
            }
        } else {
            // No permission
            pp.sendNoPermission(PartiesPermission.ADMIN_MIGRATE);
        }
    } else {
        // Players can't use migrate command
        pp.sendMessage(Messages.PARTIES_COMMON_INVALIDCMD);
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) StorageType(com.alessiodp.parties.storage.StorageType)

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