use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class PartiesSQLDispatcher method getListParties.
@Override
public LinkedHashSet<PartyImpl> getListParties(PartiesDatabaseManager.ListOrder order, int limit, int offset) {
LinkedHashSet<PartyImpl> ret;
List<String> blacklist = ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES;
if (order == PartiesDatabaseManager.ListOrder.NAME)
ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByName(blacklist, limit, offset));
else if (order == PartiesDatabaseManager.ListOrder.MEMBERS)
ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByMembers(blacklist, limit, offset));
else if (order == PartiesDatabaseManager.ListOrder.KILLS)
ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByKills(blacklist, limit, offset));
else if (order == PartiesDatabaseManager.ListOrder.EXPERIENCE)
ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByExperience(blacklist, limit, offset));
else
throw new IllegalStateException("Cannot get the list of parties with the order " + order.name());
// Load members
for (PartyImpl party : ret) {
party.setAccessible(true);
party.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(party.getId().toString())));
party.setAccessible(false);
}
return ret;
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl 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.parties.objects.PartyImpl 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);
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandTeleport 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 mustStartCooldown = false;
if (ConfigParties.ADDITIONAL_TELEPORT_COOLDOWN > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_TELEPORT_BYPASS)) {
mustStartCooldown = true;
long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.TELEPORT, partyPlayer.getPlayerUUID(), ConfigParties.ADDITIONAL_TELEPORT_COOLDOWN);
if (remainingCooldown > 0) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_TELEPORT_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
return;
}
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.TELEPORT, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
if (mustStartCooldown) {
getPlugin().getCooldownManager().startAction(CooldownManager.Action.TELEPORT, partyPlayer.getPlayerUUID(), ConfigParties.GENERAL_NAME_RENAME_COOLDOWN);
}
// Command starts
int delay = ConfigParties.ADDITIONAL_TELEPORT_DELAY;
String teleportDelayPermission = sender.getDynamicPermission(PartiesPermission.USER_TELEPORT + ".");
if (teleportDelayPermission != null) {
try {
delay = Integer.parseInt(teleportDelayPermission);
} catch (Exception ignored) {
}
}
performTeleport(party, partyPlayer, delay);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_TELEPORT, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class PartiesSubCommand method handlePreRequisitesFullWithParty.
protected boolean handlePreRequisitesFullWithParty(CommandData commandData, Boolean inParty, int argMin, int argMax, RankPermission requiredRank) {
boolean ret = handlePreRequisitesFull(commandData, inParty, argMin, argMax);
if (ret && commandData.getSender().isPlayer()) {
PartyImpl party = getPlugin().getPartyManager().getPartyOfPlayer(((PartiesCommandData) commandData).getPartyPlayer());
if (party == null) {
sendMessage(commandData.getSender(), ((PartiesCommandData) commandData).getPartyPlayer(), Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
if (requiredRank != null && !getPlugin().getRankManager().checkPlayerRankAlerter(((PartiesCommandData) commandData).getPartyPlayer(), requiredRank))
return false;
((PartiesCommandData) commandData).setParty(party);
}
return ret;
}
Aggregations