use of com.alessiodp.partiesapi.objects.PartyPlayer in project Parties by AlessioDP.
the class FileDispatcher 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);
}
use of com.alessiodp.partiesapi.objects.PartyPlayer in project Parties by AlessioDP.
the class CommandInfo method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command handling
*/
String partyName;
if (commandData.getArgs().length > 1) {
if (!commandData.havePermission(PartiesPermission.INFO_OTHERS)) {
pp.sendNoPermission(PartiesPermission.INFO_OTHERS);
return;
}
partyName = commandData.getArgs()[1];
} else if (!pp.getPartyName().isEmpty()) {
partyName = pp.getPartyName();
} else {
pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
PartyEntity party = plugin.getPartyManager().getParty(partyName);
if (party == null) {
pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", partyName));
return;
}
/*
* Command starts
*/
StringBuilder sb = new StringBuilder();
for (String str : Messages.MAINCMD_INFO_CONTENT) sb.append(str + "\n");
String text = sb.toString();
Matcher mat = Pattern.compile("%list_(.*?)%").matcher(text);
while (mat.find()) {
Rank rr = plugin.getRankManager().searchRankByHardName(mat.group().substring(6, mat.group().length() - 1));
if (rr != null) {
StringBuilder list = new StringBuilder();
int counter = 0;
for (UUID playerUUID : party.getMembers()) {
PartyPlayer pl = plugin.getPlayerManager().getPlayer(playerUUID);
// Check rank level
if (pl.getRank() == rr.getLevel()) {
if (list.length() > 0) {
list.append(Messages.MAINCMD_INFO_LIST_SEPARATOR);
}
OfflinePlayer op = Bukkit.getOfflinePlayer(pl.getPlayerUUID());
if (op != null)
list.append((op.isOnline() && !PartiesUtils.isVanished((Player) op) ? Messages.MAINCMD_INFO_LIST_ONLINEPREFIX : Messages.MAINCMD_INFO_LIST_OFFLINEPREFIX) + pl.getName());
else
list.append(Messages.MAINCMD_INFO_LIST_UNKNOWN);
counter++;
}
}
text = text.replace(mat.group(), list.toString().isEmpty() ? Messages.MAINCMD_INFO_LIST_EMPTY : list.toString());
text = text.replace("%number_" + mat.group().substring(6, mat.group().length() - 1) + "%", Integer.toString(counter));
}
}
int numOnlinePlayers = party.getNumberOnlinePlayers();
sb = new StringBuilder();
if (text.contains("%online%")) {
if (numOnlinePlayers == 0)
sb.append(Messages.MAINCMD_INFO_LIST_EMPTY);
else {
for (Player pl : party.getOnlinePlayers()) {
if (sb.length() > 0) {
sb.append(Messages.MAINCMD_INFO_LIST_SEPARATOR);
}
if (!PartiesUtils.isVanished(pl))
sb.append(Messages.MAINCMD_INFO_LIST_ONLINEPREFIX + pl.getName());
}
}
text = text.replace("%online%", sb.toString());
}
text = PartiesUtils.convertPartyPlaceholders(text, party, Messages.MAINCMD_INFO_LIST_EMPTY);
pp.sendMessage(text);
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_INFO.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
use of com.alessiodp.partiesapi.objects.PartyPlayer in project Parties by AlessioDP.
the class SQLDispatcher method getPlayerFromResultSet.
/*
* Private MySQL queries
*/
private PartyPlayer getPlayerFromResultSet(Connection connection, ResultSet rs) {
PartyPlayer ret = null;
try {
ret = new PartyPlayer(UUID.fromString(rs.getString("uuid")), ConfigParties.RANK_SET_DEFAULT);
ret.setName(rs.getString("name"));
ret.setNameTimestamp(rs.getInt("timestamp"));
ret.setPartyName(rs.getString("party"));
ret.setRank(rs.getInt("rank"));
ret.setSpy(rs.getBoolean("spy"));
ret.setPreventNotify(rs.getBoolean("notify"));
} catch (Exception ex) {
LoggerManager.printError(LoggerManager.formatErrorCallTrace(Constants.DEBUG_SQL_ERROR, ex));
}
return ret;
}
use of com.alessiodp.partiesapi.objects.PartyPlayer in project Parties by AlessioDP.
the class CommandRank method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command handling
*/
String playerName = commandData.getArgs()[1];
PartyPlayerEntity promoted;
// Conflict checker
List<PartyPlayer> listPlayers = plugin.getDatabaseManager().getPartyPlayersByName(playerName).join();
if (!listPlayers.isEmpty()) {
promoted = plugin.getPlayerManager().getPlayer(listPlayers.get(0).getPlayerUUID());
} else {
pp.sendMessage(Messages.MAINCMD_RANK_PLAYERNOTINPARTY_OTHER.replace("%player%", playerName));
return;
}
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
if (commandData.havePermission(PartiesPermission.RANK_OTHERS)) {
party = plugin.getPartyManager().getParty(promoted.getPartyName());
if (party == null) {
pp.sendMessage(Messages.MAINCMD_RANK_PLAYERNOTINPARTY_OTHER, promoted);
return;
}
} else {
if (party == null || !party.getMembers().contains(promoted.getPlayerUUID())) {
pp.sendMessage(Messages.MAINCMD_RANK_PLAYERNOTINPARTY, promoted);
return;
}
}
if (!party.getMembers().contains(promoted.getPlayerUUID())) {
if (!commandData.havePermission(PartiesPermission.RANK_OTHERS) || promoted.getPartyName().isEmpty()) {
pp.sendMessage(Messages.MAINCMD_RANK_PLAYERNOTINPARTY, promoted);
return;
}
party = plugin.getPartyManager().getParty(promoted.getPartyName());
}
Rank rank = plugin.getRankManager().searchRankByName(commandData.getArgs()[2]);
if (rank == null) {
pp.sendMessage(Messages.MAINCMD_RANK_WRONGRANK.replace("%rank_typed%", // TODO: Bypass, remove in future updates
commandData.getArgs()[2]).replace("%rank_name%", commandData.getArgs()[2]).replace("%rank_chat%", commandData.getArgs()[2]));
return;
}
if (rank.getLevel() == promoted.getRank()) {
pp.sendMessage(Messages.MAINCMD_RANK_SAMERANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promoted.getName()));
return;
}
if (!commandData.havePermission(PartiesPermission.RANK_OTHERS)) {
if (pp.getRank() <= promoted.getRank()) {
pp.sendMessage(Messages.MAINCMD_RANK_LOWRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promoted.getName()));
return;
}
if (promoted.getPlayerUUID().equals(pp.getPlayerUUID())) {
pp.sendMessage(Messages.MAINCMD_RANK_CHANGINGYOURSELF);
return;
}
if ((rank.getLevel() != ConfigParties.RANK_SET_HIGHER) && (rank.getLevel() >= pp.getRank())) {
pp.sendMessage(Messages.MAINCMD_RANK_TOHIGHERRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()));
return;
}
}
/*
* Command starts
*/
int oldRank = promoted.getRank();
if (rank.getLevel() == ConfigParties.RANK_SET_HIGHER) {
PartyPlayerEntity oldLeader = plugin.getPlayerManager().getPlayer(party.getLeader());
oldLeader.setRank(promoted.getRank());
oldLeader.updatePlayer();
party.setLeader(promoted.getPlayerUUID());
party.updateParty();
}
promoted.setRank(rank.getLevel());
promoted.updatePlayer();
party.callChange();
pp.sendMessage(Messages.MAINCMD_RANK_CHANGED, promoted);
party.sendBroadcast(promoted, Messages.MAINCMD_RANK_BROADCAST);
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_RANK.replace("{player}", promoted.getName()).replace("{value1}", Integer.toString(oldRank)).replace("{value2}", Integer.toString(rank.getLevel())).replace("{sender}", pp.getName()), true);
}
use of com.alessiodp.partiesapi.objects.PartyPlayer in project Parties by AlessioDP.
the class ApiHandler method broadcastPartyMessage.
@Deprecated
@Override
public Status broadcastPartyMessage(String paramParty, UUID paramUUID, String paramMessage) {
Party party = plugin.getPartyManager().getParty(paramParty);
PartyPlayer player = plugin.getPlayerManager().getPlayer(paramUUID);
return broadcastPartyMessage(party, player, paramMessage);
}
Aggregations