use of com.alessiodp.parties.common.PartiesPlugin 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.PartiesPlugin in project Parties by AlessioDP.
the class BungeePartiesCommandManager method registerCommands.
@Override
public void registerCommands() {
mainCommands = new ArrayList<>();
mainCommands.add(new BungeeCommandParty((PartiesPlugin) plugin));
mainCommands.add(new BungeeCommandP((PartiesPlugin) plugin));
}
use of com.alessiodp.parties.common.PartiesPlugin in project Parties by AlessioDP.
the class BukkitPartiesBungeecordListener method handleUnloadParty.
public void handleUnloadParty(PartiesPacket packet) {
PartyImpl party = ((PartiesPlugin) plugin).getPartyManager().getCacheParties().get(packet.getParty());
if (party != null) {
((PartiesPlugin) plugin).getPartyManager().unloadParty(party);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_UNLOAD_PARTY, packet.getParty().toString()), true);
}
}
use of com.alessiodp.parties.common.PartiesPlugin in project Parties by AlessioDP.
the class PartiesRedisBungeeListener method handlePostPartyAddMember.
public void handlePostPartyAddMember(UUID partyId, UUID playerId, JoinCause cause, UUID inviterId) {
// Remove party invite, if in this server, before party reload
PartyImpl party = ((PartiesPlugin) plugin).getPartyManager().getCacheParties().get(partyId);
if (party != null) {
party.getInviteRequests().stream().filter(partyInvite -> partyInvite.getInvitedPlayer().getPlayerUUID().equals(playerId)).findAny().ifPresent(partyInvite -> partyInvite.timeout(false));
}
commonListener.handlePostPartyAddMember(partyId, playerId, cause, inviterId);
}
use of com.alessiodp.parties.common.PartiesPlugin in project Parties by AlessioDP.
the class BukkitCommandHome method teleportPlayer.
@Override
protected void teleportPlayer(User player, PartyPlayerImpl partyPlayer, PartyHomeImpl home) {
Location loc = new Location(Bukkit.getWorld(home.getWorld()), home.getX(), home.getY(), home.getZ(), home.getYaw(), home.getPitch());
BukkitUser bukkitUser = (BukkitUser) plugin.getPlayer(partyPlayer.getPlayerUUID());
if (bukkitUser != null)
teleportToPartyHome((PartiesPlugin) plugin, partyPlayer, bukkitUser, home, loc);
}
Aggregations