use of com.alessiodp.parties.common.players.objects.PartyRankImpl in project Parties by AlessioDP.
the class RankManager method checkPlayerRank.
public boolean checkPlayerRank(PartyPlayerImpl pp, PartiesPermission perm) {
boolean ret = true;
PartyRankImpl r = searchRankByLevel(pp.getRank());
if (r != null && !plugin.getPlayer(pp.getPlayerUUID()).hasPermission(PartiesPermission.ADMIN_RANK_BYPASS) && !r.havePermission(perm.toString())) {
ret = false;
}
return ret;
}
use of com.alessiodp.parties.common.players.objects.PartyRankImpl in project Parties by AlessioDP.
the class RankManager method checkPlayerRankAlerter.
public boolean checkPlayerRankAlerter(PartyPlayerImpl partyPlayer, PartiesPermission perm) {
boolean ret = true;
PartyRankImpl r = searchRankByLevel(partyPlayer.getRank());
User user = plugin.getPlayer(partyPlayer.getPlayerUUID());
if (r != null && !user.hasPermission(PartiesPermission.ADMIN_RANK_BYPASS) && !r.havePermission(perm.toString())) {
PartyRankImpl rr = searchUpRank(partyPlayer.getRank(), perm);
if (rr != null) {
partyPlayer.sendMessage(Messages.PARTIES_PERM_NORANK_UPRANK.replace("%rank_name%", rr.getName()).replace("%rank_chat%", rr.getChat()).replace("%rank_level%", Integer.toString(rr.getLevel())));
} else {
partyPlayer.sendMessage(Messages.PARTIES_PERM_NORANK_GENERAL.replace("%permission%", perm.toString()));
}
ret = false;
}
return ret;
}
use of com.alessiodp.parties.common.players.objects.PartyRankImpl in project Parties by AlessioDP.
the class ConfigParties method handleRanks.
private void handleRanks() {
Set<PartyRankImpl> ranks = new HashSet<>();
PartyRankImpl rank;
ConfigurationSection csBlocks = configuration.getConfigurationSection("ranks");
if (csBlocks != null) {
PartyRankImpl def = null;
PartyRankImpl lower = null;
PartyRankImpl higher = null;
for (String key : csBlocks.getKeys(false)) {
rank = new PartyRankImpl(key);
rank.setName(csBlocks.getString(key + ".name", key));
rank.setChat(csBlocks.getString(key + ".chat", rank.getName()));
rank.setLevel(csBlocks.getInt(key + ".level", 1));
if (csBlocks.get(key + ".inheritence") != null) {
Optional<PartyRankImpl> opt = ranks.stream().filter(r -> r.getConfigName().equals(csBlocks.getString(key + ".inheritence"))).findAny();
if (opt.isPresent())
rank.setInheritence(opt.get());
}
rank.getPermissions().addAll(csBlocks.getStringList(key + ".permissions"));
rank.setDefault(csBlocks.getBoolean(key + ".default", false));
if (!rank.isDefault())
rank.setSlot(csBlocks.getInt(key + ".slot", 0));
ranks.add(rank);
if (rank.isDefault())
def = rank;
if (lower == null || rank.getLevel() < lower.getLevel())
lower = rank;
if (higher == null || rank.getLevel() > higher.getLevel())
higher = rank;
}
if (ranks.size() > 1) {
if (def == null) {
// Give error: default rank not found
def = lower;
plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_RANK_NODEFAULT);
}
// Save rank list
ConfigParties.RANK_LIST = ranks;
ConfigParties.RANK_SET_DEFAULT = def.getLevel();
ConfigParties.RANK_SET_HIGHER = higher.getLevel();
} else if (ranks.size() == 1) {
// At least 2 ranks needed
plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_RANK_ONLYONE);
} else {
// Give error: no ranks found
plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_RANK_EMPTY);
}
} else {
// Give error: no ranks node found
plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_RANK_NOTFOUND);
}
}
use of com.alessiodp.parties.common.players.objects.PartyRankImpl in project Parties by AlessioDP.
the class CommandRank method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String playerName = commandData.getArgs()[1];
UUID playerUUID = null;
Set<UUID> matchingPlayers;
if (LLAPIHandler.isEnabled()) {
// Use LastLoginAPI to get a list of players with the same name
matchingPlayers = LLAPIHandler.getPlayerByName(playerName);
} else {
// Get only the online player with the same name
matchingPlayers = new HashSet<>();
User user = plugin.getPlayerByName(playerName);
if (user != null)
matchingPlayers.add(user.getUUID());
}
List<UUID> listPlayers = new LinkedList<>(matchingPlayers);
listPlayers.removeIf((uuid) -> !getPlugin().getPlayerManager().getPlayer(uuid).isInParty());
Collections.sort(listPlayers);
if (listPlayers.size() > 1) {
// Check if the player have selected someone
if (commandData.getArgs().length > 2) {
try {
int sel = Integer.parseInt(commandData.getArgs()[3]);
playerUUID = listPlayers.get(sel - 1);
} catch (Exception ignored) {
}
}
// The player didn't select a player
if (playerUUID == null) {
for (String str : Messages.MAINCMD_RANK_CONFLICT_CONTENT) {
if (str.contains("%list_players%")) {
int i = 1;
for (UUID uuid : listPlayers) {
PartyPlayerImpl pp = getPlugin().getPlayerManager().getPlayer(uuid);
if (pp.isInParty()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_CONFLICT_PLAYER.replace("%number%", Integer.toString(i)).replace("%username%", playerName), pp, getPlugin().getPartyManager().getPartyOfPlayer(pp));
i++;
}
}
} else {
sendMessage(sender, partyPlayer, str);
}
}
return;
}
} else if (listPlayers.size() == 1) {
// Player found
playerUUID = listPlayers.get(0);
} else {
// Not found
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_FOUND.replace("%player%", playerName));
return;
}
OfflineUser promotedPlayer = plugin.getOfflinePlayer(playerUUID);
Objects.requireNonNull(promotedPlayer);
PartyPlayerImpl promotedPp = getPlugin().getPlayerManager().getPlayer(playerUUID);
PartyRankImpl rank = getPlugin().getRankManager().searchRankByName(commandData.getArgs()[2]);
if (rank == null) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_WRONGRANK.replace("%rank_name%", commandData.getArgs()[2]).replace("%rank_chat%", commandData.getArgs()[2]));
return;
}
if (sender.isPlayer() && promotedPlayer.getUUID().equals(sender.getUUID()) && !(promotedPlayer.isOnline() && commandData.havePermission(PartiesPermission.ADMIN_RANK_BYPASS))) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_CHANGINGYOURSELF);
return;
}
PartyImpl party = partyPlayer != null ? getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer) : null;
boolean otherParty = (party == null || !party.getMembers().contains(promotedPlayer.getUUID()));
if (otherParty) {
// Other party
party = getPlugin().getPartyManager().getPartyOfPlayer(promotedPp);
if (sender.isPlayer() && !commandData.havePermission(PartiesPermission.ADMIN_RANK_OTHERS)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_PLAYERNOTINPARTY, promotedPp);
return;
}
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_IN_PARTY, promotedPp);
return;
}
} else if (sender.isPlayer() && !commandData.havePermission(PartiesPermission.ADMIN_RANK_OTHERS)) {
// Do not bypass rank restrictions
if (rank.getLevel() == promotedPp.getRank()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_SAMERANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promotedPlayer.getName()));
return;
}
if (partyPlayer.getRank() <= promotedPp.getRank()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_LOWRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promotedPlayer.getName()));
return;
}
if ((rank.getLevel() != ConfigParties.RANK_SET_HIGHER) && (rank.getLevel() >= partyPlayer.getRank())) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_TOHIGHERRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()));
return;
}
}
if (party.isFixed() && rank.getLevel() == ConfigParties.RANK_SET_HIGHER) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_FIXEDLEADER);
return;
}
if (promotedPp.getRank() == ConfigParties.RANK_SET_HIGHER) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_DEMOTELEADER);
return;
}
if (rank.getSlot() > 0 && countMembersWithRank((PartiesPlugin) plugin, party, rank) >= rank.getSlot()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_FULL.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()));
return;
}
// Command start
int oldRank = promotedPp.getRank();
if (rank.getLevel() == ConfigParties.RANK_SET_HIGHER) {
party.changeLeader(promotedPp);
} else {
promotedPp.setRank(rank.getLevel());
}
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_CHANGED.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()), promotedPp);
party.broadcastMessage(Messages.MAINCMD_RANK_BROADCAST.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()), promotedPp);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_RANK, sender.getName(), promotedPp.getName(), party.getName() != null ? party.getName() : "_", oldRank, rank.getLevel(), otherParty), true);
}
use of com.alessiodp.parties.common.players.objects.PartyRankImpl in project Parties by AlessioDP.
the class PartiesPlaceholderTest method testPlaceholderListRank.
@Test
public void testPlaceholderListRank() {
RankManager mockRankManager = mock(RankManager.class);
when(mockPlugin.getRankManager()).thenReturn(mockRankManager);
when(mockRankManager.searchRankByHardName(any())).thenReturn(new PartyRankImpl("myrank", "myrank", "", 20, 0, null, Collections.emptyList(), true));
when(mockMessageUtils.convertPlaceholders(any(), any(), any())).thenReturn("Dummy");
PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder("list_rank_myrank");
assertEquals(PartiesPlaceholder.LIST_RANK, placeholder);
assertEquals(player1.getName(), placeholder.formatPlaceholder(null, party1, "list_rank_myrank"));
placeholder = PartiesPlaceholder.getPlaceholder("list_rank_myrank_total");
assertEquals(PartiesPlaceholder.LIST_RANK_TOTAL, placeholder);
placeholder = PartiesPlaceholder.getPlaceholder("list_rank_myrank_1");
assertEquals(PartiesPlaceholder.LIST_RANK_NUMBER, placeholder);
placeholder = PartiesPlaceholder.getPlaceholder("list_rank_myrank_1_placeholder");
assertEquals(PartiesPlaceholder.LIST_RANK_NUMBER_PLACEHOLDER, placeholder);
}
Aggregations