use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandInfo method preRequisites.
@Override
public boolean preRequisites(CommandData commandData) {
User sender = commandData.getSender();
if (sender.isPlayer()) {
PartyPlayerImpl partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(sender.getUUID());
// Checks for command prerequisites
if (!sender.hasPermission(permission)) {
sendNoPermissionMessage(partyPlayer, permission);
return false;
}
PartyImpl party = null;
if (commandData.getArgs().length == 1) {
party = ((PartiesPlugin) plugin).getPartyManager().getPartyOfPlayer(partyPlayer);
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
}
((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
((PartiesCommandData) commandData).setParty(party);
} else {
if (commandData.getArgs().length == 1) {
sendMessage(sender, null, Messages.PARTIES_COMMON_PARTYNOTFOUND);
return false;
}
}
commandData.addPermission(PartiesPermission.USER_INFO_OTHERS);
return true;
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandReload method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
plugin.reloadConfiguration();
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_CONFIGRELOAD);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_RELOADED, sender.getName()), true);
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandSetHome 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
String selectedHome;
boolean isRemove = commandData.getArgs().length > 1 && commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE);
if (ConfigParties.ADDITIONAL_HOME_MAX_HOMES > 1) {
if (commandData.getArgs().length == 1) {
// Home not selected
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
return;
} else if (commandData.getArgs().length == 2) {
if (isRemove) {
// Home not selected
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
return;
} else {
selectedHome = commandData.getArgs()[1];
}
} else if (commandData.getArgs().length == 3 && isRemove) {
selectedHome = commandData.getArgs()[2];
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
return;
}
} else {
if (commandData.getArgs().length == 1 || (commandData.getArgs().length == 2 && isRemove)) {
selectedHome = "default";
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
return;
}
}
if (!isRemove && party.getHomes().size() >= ConfigParties.ADDITIONAL_HOME_MAX_HOMES) {
final String finalSelectedHome = selectedHome;
if (finalSelectedHome == null || party.getHomes().stream().noneMatch((h) -> finalSelectedHome.equalsIgnoreCase(h.getName()))) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_MAXHOMES);
return;
}
}
if (!isRemove) {
boolean mustStartCooldown = false;
if (ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_SETHOME_BYPASS)) {
mustStartCooldown = true;
long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.SETHOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME);
if (remainingCooldown > 0) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
return;
}
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.SETHOME, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
if (mustStartCooldown) {
getPlugin().getCooldownManager().startAction(CooldownManager.Action.SETHOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME);
}
}
// Command starts
if (isRemove) {
boolean removed;
if (selectedHome == null || ConfigParties.ADDITIONAL_HOME_MAX_HOMES <= 1) {
party.getHomes().clear();
removed = true;
} else {
final String finalSelectedHome = selectedHome;
removed = party.getHomes().removeIf(h -> h.getName() != null && h.getName().equalsIgnoreCase(finalSelectedHome));
}
if (removed) {
party.updateParty();
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_REMOVED);
} else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_REMOVED_NONE);
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SETHOME_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(selectedHome, "default")), true);
} else {
getLocationAndSave(partyPlayer, party, selectedHome);
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_CHANGED);
party.broadcastMessage(Messages.ADDCMD_SETHOME_BROADCAST, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SETHOME, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(selectedHome, "default")), true);
}
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandSpy method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
Boolean spy = plugin.getCommandManager().getCommandUtils().handleOnOffCommand(partyPlayer.isSpy(), commandData.getArgs());
if (spy == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return;
}
// Command starts
partyPlayer.setSpy(spy);
sendMessage(sender, partyPlayer, spy ? Messages.MAINCMD_SPY_ENABLED : Messages.MAINCMD_SPY_DISABLED);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SPY, partyPlayer.getName(), spy), true);
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandTag method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
PartyImpl party;
// Command handling
String tag = null;
if (commandData.getArgs().length == 3 && commandData.havePermission(PartiesPermission.ADMIN_TAG_OTHERS)) {
party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
if (party != null) {
if (!commandData.getArgs()[2].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
tag = commandData.getArgs()[2];
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
return;
}
} else if (commandData.getArgs().length == 2) {
party = getPlugin().getPartyManager().getParty(partyPlayer.getPartyId());
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.EDIT_TAG)) {
return;
}
if (!commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
tag = commandData.getArgs()[1];
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
return;
}
if (tag != null) {
if (!CensorUtils.checkAllowedCharacters(ConfigParties.ADDITIONAL_TAG_ALLOWEDCHARS, tag, PartiesConstants.DEBUG_CMD_TAG_REGEXERROR_AC) || (tag.length() > ConfigParties.ADDITIONAL_TAG_MAXLENGTH) || (tag.length() < ConfigParties.ADDITIONAL_TAG_MINLENGTH)) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_INVALID);
return;
}
if (CensorUtils.checkCensor(ConfigParties.ADDITIONAL_TAG_CENSORREGEX, tag, PartiesConstants.DEBUG_CMD_TAG_REGEXERROR_CEN)) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_CENSORED);
return;
}
}
if (tag != null && ConfigParties.ADDITIONAL_TAG_MUST_BE_UNIQUE && getPlugin().getPartyManager().existsTag(tag)) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_ALREADY_USED.replace("%tag%", tag));
return;
}
if (!commandData.havePermission(PartiesPermission.ADMIN_TAG_OTHERS) && getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.TAG, partyPlayer, commandData.getCommandLabel(), commandData.getArgs())) {
return;
}
// Command starts
party.setTag(tag);
if (tag == null) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_REMOVED);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_TAG_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
} else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_CHANGED);
party.broadcastMessage(Messages.ADDCMD_TAG_BROADCAST, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_TAG, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
}
Aggregations