use of com.alessiodp.parties.common.players.objects.RequestCooldown in project Parties by AlessioDP.
the class CooldownManager method insertRequestCooldown.
public void insertRequestCooldown(HashMap<UUID, List<RequestCooldown>> map, UUID player, UUID target, int seconds, String debugMessage) {
if (seconds > 0) {
List<RequestCooldown> list = map.get(player);
if (list == null)
list = new ArrayList<>();
RequestCooldown ic = new RequestCooldown(plugin, player, target, seconds);
list.add(ic);
map.put(player, list);
plugin.getScheduler().scheduleAsyncLater(() -> {
List<RequestCooldown> newList = map.get(player);
if (newList != null) {
newList.remove(ic);
if (newList.isEmpty()) {
map.remove(player);
} else {
map.put(player, newList);
}
}
plugin.getLoggerManager().logDebug(String.format(debugMessage, player.toString()), true);
}, seconds, TimeUnit.SECONDS);
}
}
use of com.alessiodp.parties.common.players.objects.RequestCooldown in project Parties by AlessioDP.
the class CooldownManager method insertRequestCooldown.
protected void insertRequestCooldown(HashMap<UUID, List<RequestCooldown>> map, UUID subject, UUID target, int seconds, MultiAction multiAction) {
if (seconds > 0) {
List<RequestCooldown> list = map.get(subject);
if (list == null)
list = new ArrayList<>();
RequestCooldown ic = new RequestCooldown(plugin, subject, target, seconds);
list.add(ic);
map.put(subject, list);
plugin.getScheduler().scheduleAsyncLater(() -> {
List<RequestCooldown> newList = map.get(subject);
if (newList != null) {
newList.remove(ic);
if (newList.isEmpty()) {
map.remove(subject);
} else {
map.put(subject, newList);
}
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_TASK_ACTION_EXPIRED, multiAction.name(), subject.toString()), true);
}, seconds, TimeUnit.SECONDS);
}
}
use of com.alessiodp.parties.common.players.objects.RequestCooldown in project Parties by AlessioDP.
the class CommandInvite 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
User invitedPlayer = plugin.getPlayerByName(commandData.getArgs()[1]);
if (invitedPlayer == null) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYEROFFLINE);
return;
}
PartyPlayerImpl invitedPartyPlayer = getPlugin().getPlayerManager().getPlayer(invitedPlayer.getUUID());
if (invitedPartyPlayer.isVanished()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYEROFFLINE);
return;
}
if (invitedPartyPlayer.getPlayerUUID().equals(sender.getUUID())) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_INVITE_YOURSELF);
return;
}
if (invitedPartyPlayer.isInParty()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYERINPARTY, invitedPartyPlayer);
return;
}
if (ConfigParties.GENERAL_INVITE_PREVENTINVITEPERM && // Check if the user is inside the network (skip if Redis)
invitedPlayer.isInsideNetwork() && !invitedPlayer.hasPermission(PartiesPermission.USER_ACCEPT)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYERNOPERM, invitedPartyPlayer);
return;
}
// Check for party, create one if option enabled
if (party == null) {
if (ConfigParties.GENERAL_INVITE_AUTO_CREATE_PARTY_UPON_INVITE && ConfigParties.GENERAL_NAME_DYNAMIC_ENABLE) {
String partyName = CommandCreate.generateDynamicName(getPlugin(), partyPlayer);
party = CommandCreate.createParty((PartiesPlugin) plugin, this, sender, partyPlayer, partyName, false);
if (party == null || party.isFixed()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_FAILED, invitedPartyPlayer);
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
}
if (invitedPartyPlayer.getIgnoredParties().contains(party.getId())) {
// Invited player ignoring the party, fake sent
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_SENT, invitedPartyPlayer);
return;
}
if (invitedPartyPlayer.isMuted() && ConfigMain.ADDITIONAL_MUTE_ENABLE && ConfigMain.ADDITIONAL_MUTE_BLOCK_INVITE) {
// Invited player has disabled notifications, fake sent
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_SENT, invitedPartyPlayer);
return;
}
boolean isRevoke = false;
final PartyImpl finalParty = party;
Optional<PartyInvite> revokeInvite = invitedPartyPlayer.getPendingInvites().stream().filter(pv -> pv.getParty().getId().equals(finalParty.getId())).findAny();
if (revokeInvite.isPresent()) {
isRevoke = true;
if (!ConfigParties.GENERAL_INVITE_REVOKE) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_ALREADYINVITED, invitedPartyPlayer);
return;
}
}
boolean mustStartCooldown = false;
if (!isRevoke && ConfigParties.GENERAL_INVITE_COOLDOWN_ENABLE && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_INVITE_BYPASS)) {
// Check invited player cooldown
RequestCooldown inviteAfterLeaveCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.INVITE_AFTER_LEAVE, invitedPlayer.getUUID(), party.getId());
if (inviteAfterLeaveCooldown != null) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_COOLDOWN_ON_LEAVE.replace("%seconds%", String.valueOf(inviteAfterLeaveCooldown.getWaitTime())));
return;
}
// Check invite cooldown
mustStartCooldown = true;
RequestCooldown inviteCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), invitedPlayer.getUUID());
if (inviteCooldown != null) {
sendMessage(sender, partyPlayer, (inviteCooldown.isGlobal() ? Messages.MAINCMD_INVITE_COOLDOWN_GLOBAL : Messages.MAINCMD_INVITE_COOLDOWN_INDIVIDUAL).replace("%seconds%", String.valueOf(inviteCooldown.getCooldown() - inviteCooldown.getDiffTime())));
return;
}
}
// Command starts
if (isRevoke) {
// Revoke invite
revokeInvite.get().revoke();
} else {
// Send invite
party.invitePlayer(invitedPartyPlayer, partyPlayer);
if (mustStartCooldown) {
getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), null, ConfigParties.GENERAL_INVITE_COOLDOWN_GLOBAL);
getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), invitedPartyPlayer.getPlayerUUID(), ConfigParties.GENERAL_INVITE_COOLDOWN_INDIVIDUAL);
}
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_INVITE, partyPlayer.getName(), invitedPartyPlayer.getName(), party.getName() != null ? party.getName() : party.getId(), isRevoke), true);
}
use of com.alessiodp.parties.common.players.objects.RequestCooldown in project Parties by AlessioDP.
the class CommandAsk method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String partyName = commandData.getArgs()[1];
PartyImpl party = getPlugin().getPartyManager().getParty(partyName);
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", partyName));
return;
}
if (party.isFull()) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYFULL);
return;
}
boolean mustStartCooldown = false;
if (ConfigParties.ADDITIONAL_ASK_COOLDOWN_ENABLE && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_ASK_BYPASS)) {
// Check invite cooldown
mustStartCooldown = true;
RequestCooldown askCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.ASK, partyPlayer.getPlayerUUID(), party.getId());
if (askCooldown != null) {
sendMessage(sender, partyPlayer, (askCooldown.isGlobal() ? Messages.ADDCMD_ASK_COOLDOWN_GLOBAL : Messages.ADDCMD_ASK_COOLDOWN_INDIVIDUAL).replace("%seconds%", String.valueOf(askCooldown.getWaitTime())));
}
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.ASK, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
// Command starts
partyPlayer.askToJoin(party);
if (mustStartCooldown) {
getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.ASK, partyPlayer.getPlayerUUID(), null, ConfigParties.ADDITIONAL_ASK_COOLDOWN_GLOBAL);
getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.ASK, partyPlayer.getPlayerUUID(), party.getId(), ConfigParties.ADDITIONAL_ASK_COOLDOWN_INDIVIDUAL);
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_ASK, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
Aggregations