use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandOpen method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
PartyImpl party;
// Command handling
if (commandData.getArgs().length == 1 && sender.isPlayer()) {
party = getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer);
} else if (commandData.getArgs().length == 2 && commandData.havePermission(PartiesPermission.ADMIN_OPEN_OTHERS)) {
party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
return;
}
if (party == null) {
if (commandData.getArgs().length > 1)
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
else
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
if (party.isOpen()) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_ALREADY_OPEN);
return;
}
boolean mustStartCooldown = false;
if (ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_COOLDOWN_OPEN > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_OPEN_BYPASS)) {
mustStartCooldown = true;
long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.OPEN, sender.getUUID(), ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_COOLDOWN_OPEN);
if (remainingCooldown > 0) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
return;
}
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.OPEN, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
if (mustStartCooldown)
getPlugin().getCooldownManager().startAction(CooldownManager.Action.OPEN, sender.getUUID(), ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_COOLDOWN_OPEN);
// Command starts
party.setOpen(true);
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_OPENED);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_OPENCLOSE, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", true), true);
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandProtection method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
PartyImpl party = ((PartiesCommandData) commandData).getParty();
// Command handling
Boolean protection = plugin.getCommandManager().getCommandUtils().handleOnOffCommand(partyPlayer.isChatParty(), commandData.getArgs());
if (protection == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return;
}
if (protection && getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.PROTECTION, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
// Command starts
party.setProtection(protection);
sendMessage(sender, partyPlayer, protection ? Messages.ADDCMD_PROTECTION_ON : Messages.ADDCMD_PROTECTION_OFF);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_PROTECTION, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", protection), true);
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandRank method preRequisites.
@Override
public boolean preRequisites(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = null;
if (sender.isPlayer()) {
partyPlayer = getPlugin().getPlayerManager().getPlayer(sender.getUUID());
// Checks for command prerequisites
if (!sender.hasPermission(permission)) {
sendNoPermissionMessage(partyPlayer, permission);
return false;
}
if (!sender.hasPermission(PartiesPermission.ADMIN_RANK_OTHERS)) {
if (!partyPlayer.isInParty()) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
// Not using handlePreRequesitesFull for this
if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.ADMIN_RANK))
return false;
}
((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
commandData.addPermission(PartiesPermission.ADMIN_RANK_OTHERS);
}
if (commandData.getArgs().length < 3 || commandData.getArgs().length > 4) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return false;
}
return true;
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData 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.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandRename method onCommand.
@Override
public void onCommand(CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
PartyImpl party = null;
String partyName;
if (commandData.getArgs().length == 2) {
// 2 arguments - own party
if (partyPlayer.isInParty())
party = getPlugin().getPartyManager().getParty(partyPlayer.getPartyId());
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.ADMIN_RENAME))
return;
partyName = commandData.getArgs()[1];
} else {
// 3 arguments - another party
if (!sender.isPlayer() || commandData.havePermission(PartiesPermission.ADMIN_RENAME_OTHERS)) {
party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
}
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
return;
}
partyName = commandData.getArgs()[2];
}
if (partyName.length() > ConfigParties.GENERAL_NAME_MAXLENGTH) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_NAMETOOLONG);
return;
}
if (partyName.length() < ConfigParties.GENERAL_NAME_MINLENGTH) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_NAMETOOSHORT);
return;
}
if (!CensorUtils.checkAllowedCharacters(ConfigParties.GENERAL_NAME_ALLOWEDCHARS, partyName, PartiesConstants.DEBUG_CMD_CREATE_REGEXERROR_ALLOWEDCHARS)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_INVALIDNAME);
return;
}
if (CensorUtils.checkCensor(ConfigParties.GENERAL_NAME_CENSORREGEX, partyName, PartiesConstants.DEBUG_CMD_CREATE_REGEXERROR_CENSORED)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_CENSORED);
return;
}
if (getPlugin().getPartyManager().existsParty(partyName)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_NAMEEXISTS.replace("%party%", partyName));
return;
}
boolean mustStartCooldown = false;
if (ConfigParties.GENERAL_NAME_RENAME_COOLDOWN > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_RENAME_BYPASS)) {
mustStartCooldown = true;
long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.RENAME, party.getId(), ConfigParties.GENERAL_NAME_RENAME_COOLDOWN);
if (remainingCooldown > 0) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RENAME_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
return;
}
}
if (partyPlayer != null && getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.RENAME, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
if (mustStartCooldown) {
getPlugin().getCooldownManager().startAction(CooldownManager.Action.RENAME, party.getId(), ConfigParties.GENERAL_NAME_RENAME_COOLDOWN);
}
// Command starts
String oldPartyName = party.getName();
// Calling API event
IPartyPreRenameEvent partiesPreRenameEvent = getPlugin().getEventManager().preparePartyPreRenameEvent(party, party.getName(), partyName, partyPlayer, commandData.getArgs().length > 2);
getPlugin().getEventManager().callEvent(partiesPreRenameEvent);
partyName = partiesPreRenameEvent.getNewPartyName();
if (!partiesPreRenameEvent.isCancelled()) {
party.rename(partyName, partyPlayer, commandData.getArgs().length > 2);
sendMessage(sender, partyPlayer, Messages.MAINCMD_RENAME_RENAMED.replace("%old%", CommonUtils.getOr(oldPartyName, "null")), party);
party.broadcastMessage(Messages.MAINCMD_RENAME_BROADCAST.replace("%old%", CommonUtils.getOr(oldPartyName, "null")), partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_RENAME, sender.getName(), oldPartyName, party.getName()), true);
} else {
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_RENAMEEVENT_DENY, party.getName(), oldPartyName, sender.getUUID().toString()), true);
}
}
Aggregations