use of com.alessiodp.parties.common.commands.utils.PartiesCommandData 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.commands.utils.PartiesCommandData 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.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandJoin 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 (commandData.getArgs().length == 2) {
if (!commandData.havePermission(PartiesPermission.ADMIN_JOIN_BYPASS)) {
if (ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_ENABLE && !party.isOpen()) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_CANNOT_JOIN);
return;
}
if (ConfigParties.ADDITIONAL_JOIN_PASSWORD_ENABLE && party.getPassword() != null) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_PASSWORD_WRONGPASSWORD);
return;
}
}
} else if (commandData.getArgs().length == 3 && ConfigParties.ADDITIONAL_JOIN_PASSWORD_ENABLE) {
if (!PasswordUtils.hashText(commandData.getArgs()[2]).equals(party.getPassword())) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_PASSWORD_WRONGPASSWORD);
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
return;
}
if (party.isFull()) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYFULL);
return;
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.JOIN, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
// Command starts
// Calling API Event
IPlayerPreJoinEvent partiesPreJoinEvent = getPlugin().getEventManager().preparePlayerPreJoinEvent(partyPlayer, party, JoinCause.JOIN, partyPlayer);
getPlugin().getEventManager().callEvent(partiesPreJoinEvent);
if (!partiesPreJoinEvent.isCancelled()) {
party.addMember(partyPlayer, JoinCause.JOIN, partyPlayer);
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_JOINED);
party.broadcastMessage(Messages.ADDCMD_JOIN_PLAYERJOINED, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_JOIN, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_JOINEVENT_DENY, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandKick method preRequisites.
@Override
public boolean preRequisites(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = null;
if (sender.isPlayer()) {
partyPlayer = getPlugin().getPlayerManager().getPlayer(sender.getUUID());
// Checks for command prerequisites
if (!sender.hasPermission(permission)) {
sendNoPermissionMessage(partyPlayer, permission);
return false;
}
if (!sender.hasPermission(PartiesPermission.ADMIN_KICK_OTHERS)) {
if (!partyPlayer.isInParty()) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
// Not using handlePreRequesitesFull for this
if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.KICK))
return false;
}
((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
}
if (commandData.getArgs().length < 2 || commandData.getArgs().length > 3) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return false;
}
commandData.addPermission(PartiesPermission.ADMIN_KICK_OTHERS);
return true;
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandKick method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String playerName = commandData.getArgs()[1];
UUID playerUUID = null;
Set<UUID> matchingPlayers = LLAPIHandler.getPlayerByName(playerName);
List<UUID> listPlayers = new LinkedList<>(matchingPlayers);
listPlayers.removeIf((uuid) -> !getPlugin().getPlayerManager().getPlayer(uuid).isInParty());
Collections.sort(listPlayers);
if (listPlayers.size() > 1) {
// Check if the player have selected someone
if (commandData.getArgs().length > 2) {
try {
int sel = Integer.parseInt(commandData.getArgs()[2]);
playerUUID = listPlayers.get(sel - 1);
} catch (Exception ignored) {
}
}
// The player didn't select a player
if (playerUUID == null) {
for (String str : Messages.MAINCMD_KICK_CONFLICT_CONTENT) {
if (str.contains("%list_players%")) {
int i = 1;
for (UUID uuid : listPlayers) {
PartyPlayerImpl pp = getPlugin().getPlayerManager().getPlayer(uuid);
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_CONFLICT_PLAYER.replace("%number%", Integer.toString(i)).replace("%username%", playerName), pp, getPlugin().getPartyManager().getPartyOfPlayer(pp));
i++;
}
} else {
sendMessage(sender, partyPlayer, str);
}
}
return;
}
} else if (listPlayers.size() == 1) {
// Player found
playerUUID = listPlayers.get(0);
} else {
// Not found
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_FOUND.replace("%player%", playerName));
return;
}
OfflineUser kickedPlayer = plugin.getOfflinePlayer(playerUUID);
Objects.requireNonNull(kickedPlayer);
PartyPlayerImpl kickedPp = getPlugin().getPlayerManager().getPlayer(playerUUID);
PartyImpl party = partyPlayer != null ? getPlugin().getPartyManager().getParty(partyPlayer.getPartyId()) : null;
boolean otherParty = false;
if (party == null || !party.getMembers().contains(kickedPlayer.getUUID())) {
// Other party
otherParty = true;
if (commandData.havePermission(PartiesPermission.ADMIN_KICK_OTHERS)) {
party = getPlugin().getPartyManager().getParty(kickedPp.getPartyId());
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_IN_PARTY, kickedPp);
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_PLAYERNOTINPARTY, kickedPp);
return;
}
} else {
// Same party
if (partyPlayer.getRank() < kickedPp.getRank() && !commandData.havePermission(PartiesPermission.ADMIN_KICK_OTHERS)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_PLAYERHIGHERRANK, kickedPp);
return;
}
}
// Command starts
// Calling API event
IPlayerPreLeaveEvent partiesPreLeaveEvent = getPlugin().getEventManager().preparePlayerPreLeaveEvent(kickedPp, party, LeaveCause.KICK, partyPlayer);
getPlugin().getEventManager().callEvent(partiesPreLeaveEvent);
if (!partiesPreLeaveEvent.isCancelled()) {
if (party.getLeader() != null && party.getLeader().equals(kickedPlayer.getUUID())) {
// Leader
boolean mustDelete = true;
// Check if leader can be changed
if (ConfigParties.GENERAL_MEMBERS_ON_PARTY_LEAVE_CHANGE_LEADER && party.getMembers().size() > 1) {
PartyPlayerImpl newLeader = party.findNewLeader();
if (newLeader != null) {
// Found a new leader
mustDelete = false;
party.changeLeader(newLeader);
party.removeMember(kickedPp, LeaveCause.KICK, partyPlayer);
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_SENT, kickedPp);
party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST_LEADER_CHANGED, newLeader);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_KICK_LEADER_CHANGE, sender.getName(), kickedPp.getName(), party.getName() != null ? party.getName() : "_", newLeader.getName()), true);
}
}
if (mustDelete) {
// Calling Pre API event
IPartyPreDeleteEvent partiesPreDeleteEvent = getPlugin().getEventManager().preparePartyPreDeleteEvent(party, DeleteCause.KICK, kickedPp, partyPlayer);
getPlugin().getEventManager().callEvent(partiesPreDeleteEvent);
if (!partiesPreDeleteEvent.isCancelled()) {
// Disbanding party
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_SENT, kickedPp);
party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST_DISBAND, kickedPp);
party.delete(DeleteCause.KICK, kickedPp, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_KICK, sender.getName(), kickedPp.getName(), party.getName() != null ? party.getName() : "_", otherParty, true), true);
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_DELETEEVENT_DENY, party.getId(), sender.getName(), sender.getUUID().toString()), true);
}
} else {
// Normal
if (kickedPlayer.isOnline()) {
// Online
kickedPp.sendMessage(Messages.MAINCMD_KICK_PLAYERKICKED, partyPlayer);
}
party.removeMember(kickedPp, LeaveCause.KICK, partyPlayer);
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_SENT, kickedPp);
party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST, kickedPp);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_KICK, sender.getName(), kickedPp.getName(), party.getName() != null ? party.getName() : "_", otherParty, false), true);
}
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_LEAVEEVENT_DENY, sender.getUUID().toString(), party.getId()), true);
}
Aggregations