Search in sources :

Example 11 with PartyPlayer

use of com.alessiodp.partiesapi.objects.PartyPlayer in project Parties by AlessioDP.

the class YAMLDao method loadPartyPlayerData.

@Override
public PartyPlayer loadPartyPlayerData(UUID uuid) {
    PartyPlayer ret = new PartyPlayer(uuid, ConfigParties.RANK_SET_DEFAULT);
    String node = "players." + uuid.toString();
    ret.setName(data.getString(node + ".name.name", ""));
    ret.setNameTimestamp(data.getLong(node + ".name.timestamp"));
    ret.setRank(data.getInt(node + ".rank"));
    ret.setPartyName(data.getString(node + ".party", ""));
    ret.setSpy(data.getBoolean(node + ".options.spy", false));
    ret.setPreventNotify(data.getBoolean(node + ".options.notify", false));
    return ret;
}
Also used : PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer)

Example 12 with PartyPlayer

use of com.alessiodp.partiesapi.objects.PartyPlayer 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 13 with PartyPlayer

use of com.alessiodp.partiesapi.objects.PartyPlayer 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 14 with PartyPlayer

use of com.alessiodp.partiesapi.objects.PartyPlayer in project Parties by AlessioDP.

the class SQLDispatcher method saveEntireData.

@Override
public boolean saveEntireData(DatabaseData data) {
    boolean ret = false;
    try (Connection connection = getConnection()) {
        connection.setAutoCommit(false);
        // Players
        for (Entry<UUID, PartyPlayer> entry : data.getPlayers().entrySet()) updatePlayer(entry.getValue(), connection);
        // Parties
        for (Entry<String, Party> entry : data.getParties().entrySet()) {
            updateParty(entry.getValue(), connection);
        }
        connection.commit();
        ret = true;
    } catch (Exception ex) {
        LoggerManager.printError(LoggerManager.formatErrorCallTrace(Constants.DEBUG_SQL_ERROR, ex));
    }
    return ret;
}
Also used : Party(com.alessiodp.partiesapi.objects.Party) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) Connection(java.sql.Connection) UUID(java.util.UUID) SQLException(java.sql.SQLException)

Example 15 with PartyPlayer

use of com.alessiodp.partiesapi.objects.PartyPlayer in project Parties by AlessioDP.

the class SQLDispatcher method loadEntireData.

@Override
public DatabaseData loadEntireData() {
    // Players
    Map<UUID, PartyPlayer> players = new HashMap<UUID, PartyPlayer>();
    for (PartyPlayer pp : getAllPlayers()) players.put(pp.getPlayerUUID(), pp);
    // Parties
    Map<String, Party> parties = new HashMap<String, Party>();
    for (Party p : getAllParties()) parties.put(p.getName(), p);
    return new DatabaseData(players, parties);
}
Also used : Party(com.alessiodp.partiesapi.objects.Party) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) HashMap(java.util.HashMap) UUID(java.util.UUID) DatabaseData(com.alessiodp.parties.storage.DatabaseData)

Aggregations

PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)16 UUID (java.util.UUID)6 PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)5 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)5 Party (com.alessiodp.partiesapi.objects.Party)5 Player (org.bukkit.entity.Player)4 DatabaseData (com.alessiodp.parties.storage.DatabaseData)2 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)2 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)2 Rank (com.alessiodp.partiesapi.interfaces.Rank)2 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 Status (com.alessiodp.partiesapi.enums.Status)1 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)1 Connection (java.sql.Connection)1 Date (java.sql.Date)1 Time (java.sql.Time)1 Matcher (java.util.regex.Matcher)1