use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandList method preRequisites.
@Override
public boolean preRequisites(CommandData commandData) {
User sender = commandData.getSender();
if (sender.isPlayer()) {
PartyPlayerImpl partyPlayer = getPlugin().getPlayerManager().getPlayer(sender.getUUID());
// Checks for command prerequisites
if (!sender.hasPermission(permission) && !sender.hasPermission(PartiesPermission.USER_LIST_NAME) && !sender.hasPermission(PartiesPermission.USER_LIST_ONLINE_MEMBERS) && !sender.hasPermission(PartiesPermission.USER_LIST_MEMBERS) && !sender.hasPermission(PartiesPermission.USER_LIST_KILLS) && !sender.hasPermission(PartiesPermission.USER_LIST_EXPERIENCE)) {
sendNoPermissionMessage(partyPlayer, permission);
return false;
}
((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
commandData.addPermission(permission);
commandData.addPermission(PartiesPermission.USER_LIST_NAME);
commandData.addPermission(PartiesPermission.USER_LIST_ONLINE_MEMBERS);
commandData.addPermission(PartiesPermission.USER_LIST_MEMBERS);
commandData.addPermission(PartiesPermission.USER_LIST_KILLS);
commandData.addPermission(PartiesPermission.USER_LIST_EXPERIENCE);
}
return true;
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandMotd 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 isRemove = false;
String motd = "";
if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
// Remove command
isRemove = true;
} else {
motd = plugin.getCommandManager().getCommandUtils().handleCommandString(commandData.getArgs(), 1);
if (!CensorUtils.checkAllowedCharacters(ConfigParties.ADDITIONAL_MOTD_ALLOWEDCHARS, motd, PartiesConstants.DEBUG_CMD_MOTD_REGEXERROR_ALLOWEDCHARS) || (motd.length() > ConfigParties.ADDITIONAL_MOTD_MAXLENGTH) || (motd.length() < ConfigParties.ADDITIONAL_MOTD_MINLENGTH)) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MOTD_INVALID);
return;
}
if (CensorUtils.checkCensor(ConfigParties.ADDITIONAL_MOTD_CENSORREGEX, motd, PartiesConstants.DEBUG_CMD_MOTD_REGEXERROR_CENSORED)) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MOTD_CENSORED);
return;
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.MOTD, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
}
// Command starts
party.setMotd(motd);
if (isRemove) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MOTD_REMOVED);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_MOTD, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
} else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MOTD_CHANGED);
party.broadcastMessage(Messages.ADDCMD_MOTD_BROADCAST, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_MOTD_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandNickname method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl senderPp = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String playerName = commandData.getArgs()[1];
UUID playerUUID;
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);
if (listPlayers.size() == 0) {
sendMessage(sender, senderPp, Messages.PARTIES_COMMON_PLAYER_NOT_FOUND.replace("%player%", playerName));
return;
}
listPlayers.removeIf((uuid) -> !getPlugin().getPlayerManager().getPlayer(uuid).isInParty());
playerUUID = listPlayers.stream().findAny().orElse(null);
if (playerUUID == null) {
sendMessage(sender, senderPp, Messages.PARTIES_COMMON_PLAYER_NOT_IN_PARTY.replace("%player%", playerName));
return;
}
OfflineUser targetPlayer = plugin.getOfflinePlayer(playerUUID);
Objects.requireNonNull(targetPlayer);
PartyPlayerImpl targetPp = getPlugin().getPlayerManager().getPlayer(playerUUID);
PartyImpl party = getPlugin().getPartyManager().getParty(targetPp.getPartyId());
boolean isOwn = senderPp != null && senderPp.getPlayerUUID().equals(targetPp.getPlayerUUID());
if (party == null) {
sendMessage(sender, senderPp, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
if (senderPp != null) {
if (isOwn) {
if (!getPlugin().getRankManager().checkPlayerRank(senderPp, RankPermission.EDIT_NICKNAME_OWN)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OWN_NO_PERMISSION);
return;
}
} else {
if (!party.getId().equals(senderPp.getPartyId()) && !commandData.havePermission(PartiesPermission.ADMIN_NICKNAME_OTHERS)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OTHERS_NO_PERMISSION);
return;
}
if (!getPlugin().getRankManager().checkPlayerRank(senderPp, RankPermission.EDIT_NICKNAME_OTHERS)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OTHERS_NO_PERMISSION);
return;
}
}
}
if (commandData.getArgs().length == 2) {
if (targetPp.getNickname() != null) {
sendMessage(sender, senderPp, isOwn ? Messages.ADDCMD_NICKNAME_SHOW_OWN : Messages.ADDCMD_NICKNAME_SHOW_OTHER, targetPp);
} else {
sendMessage(sender, senderPp, isOwn ? Messages.ADDCMD_NICKNAME_SHOW_OWN_NONE : Messages.ADDCMD_NICKNAME_SHOW_OTHER_NONE, targetPp);
}
} else if (commandData.getArgs().length >= 3) {
// Set/remove
boolean isRemove = false;
String nickname = "";
if (commandData.getArgs()[2].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
// Remove command
isRemove = true;
} else {
nickname = plugin.getCommandManager().getCommandUtils().handleCommandString(commandData.getArgs(), 2);
if (!CensorUtils.checkAllowedCharacters(ConfigParties.ADDITIONAL_NICKNAME_ALLOWEDCHARS, nickname, PartiesConstants.DEBUG_CMD_NICKNAME_REGEXERROR_ALLOWEDCHARS) || (nickname.length() > ConfigParties.ADDITIONAL_NICKNAME_MAXLENGTH) || (nickname.length() < ConfigParties.ADDITIONAL_NICKNAME_MINLENGTH)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_INVALID);
return;
}
if (CensorUtils.checkCensor(ConfigParties.ADDITIONAL_NICKNAME_CENSORREGEX, nickname, PartiesConstants.DEBUG_CMD_NICKNAME_REGEXERROR_CENSORED)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_CENSORED);
return;
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.NICKNAME, senderPp, commandData.getCommandLabel(), commandData.getArgs()))
return;
}
// Command starts
if (isRemove) {
targetPp.setNickname(null);
if (isOwn) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OWN_REMOVED, targetPp);
} else {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OTHERS_REMOVED, targetPp);
if (senderPp != null && targetPlayer.isOnline())
targetPp.sendMessage(Messages.ADDCMD_NICKNAME_OTHERS_TARGET_REMOVED, senderPp);
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_NICKNAME, sender.getName(), targetPp.getName()), true);
} else {
targetPp.setNickname(nickname);
if (isOwn) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OWN_CHANGED, targetPp);
} else {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OTHERS_CHANGED, targetPp);
if (senderPp != null && targetPlayer.isOnline())
targetPp.sendMessage(Messages.ADDCMD_NICKNAME_OTHERS_TARGET_CHANGED.replace("%nickname%", nickname), senderPp);
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_NICKNAME_REM, sender.getName(), targetPp.getName()), true);
}
}
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandPassword 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 isRemove = false;
String password;
if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
// Remove command
isRemove = true;
password = null;
} else {
// Normal command
if (!PasswordUtils.isValid(commandData.getArgs()[1])) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_PASSWORD_INVALID);
return;
}
password = PasswordUtils.hashText(commandData.getArgs()[1]);
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.PASSWORD, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
}
// Command starts
party.setPassword(password);
if (isRemove) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_PASSWORD_REMOVED);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_PASSWORD_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
} else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_PASSWORD_CHANGED);
party.broadcastMessage(Messages.ADDCMD_PASSWORD_BROADCAST, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_PASSWORD, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandDebug method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String playerName;
PartyImpl targetParty = null;
PartyPlayerImpl targetPlayer = null;
CommandType commandType = CommandType.parse(commandData.getArgs()[1]);
if (commandType == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return;
}
switch(commandType) {
case CONFIG:
if (commandData.getArgs().length != 2) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxConfig));
return;
}
break;
case EXP:
if (commandData.getArgs().length != 2) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxExp));
return;
}
break;
case PARTY:
if (commandData.getArgs().length == 3) {
targetParty = getPlugin().getPartyManager().getParty(commandData.getArgs()[2]);
if (targetParty == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[2]));
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxParty));
return;
}
break;
case PLAYER:
if (commandData.getArgs().length == 2) {
if (partyPlayer != null)
targetPlayer = partyPlayer;
else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxPlayer));
return;
}
} else if (commandData.getArgs().length == 3) {
playerName = commandData.getArgs()[2];
User targetUser = plugin.getPlayerByName(playerName);
if (targetUser != null) {
targetPlayer = getPlugin().getPlayerManager().getPlayer(targetUser.getUUID());
} else {
Set<UUID> targetPlayersUuid = LLAPIHandler.getPlayerByName(playerName);
if (targetPlayersUuid.size() > 0) {
targetPlayer = getPlugin().getPlayerManager().getPlayer(targetPlayersUuid.iterator().next());
} else {
// Not found
sendMessage(sender, partyPlayer, Messages.ADDCMD_DEBUG_PLAYER_PLAYER_OFFLINE.replace("%player%", playerName));
return;
}
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxPlayer));
return;
}
break;
default:
if (commandHandleExtra(commandType, commandData, sender, partyPlayer)) {
// Command handle extra stopped, return
return;
}
}
// Command starts
commandStart(commandType, sender, partyPlayer, targetParty, targetPlayer);
}
Aggregations