use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class VelocityCommandHome method teleportToPartyHome.
public static void teleportToPartyHome(PartiesPlugin plugin, User player, PartyPlayerImpl partyPlayer, PartyHomeImpl home) {
PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
if (home.getServer() != null && !home.getServer().isEmpty()) {
boolean serverChange = false;
RegisteredServer server = ((ADPVelocityBootstrap) plugin.getBootstrap()).getServer().getServer(home.getServer()).orElse(null);
IPlayerPreHomeEvent partiesPreHomeEvent = plugin.getEventManager().preparePlayerPreHomeEvent(partyPlayer, party, home);
plugin.getEventManager().callEvent(partiesPreHomeEvent);
if (!partiesPreHomeEvent.isCancelled()) {
if (VelocityConfigParties.ADDITIONAL_HOME_CROSS_SERVER && !((VelocityUser) player).getServerName().equalsIgnoreCase(home.getServer())) {
if (server == null) {
plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_CMD_HOME_NO_SERVER, home));
return;
}
((VelocityUser) player).connectTo(server);
serverChange = true;
}
String message = plugin.getMessageUtils().convertPlaceholders(Messages.ADDCMD_HOME_TELEPORTED, partyPlayer, party);
if (serverChange) {
plugin.getScheduler().scheduleAsyncLater(() -> ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message), VelocityConfigParties.ADDITIONAL_HOME_CROSS_SERVER_DELAY, TimeUnit.MILLISECONDS);
} else {
((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message);
}
IPlayerPostHomeEvent partiesPostHomeEvent = plugin.getEventManager().preparePlayerPostHomeEvent(partyPlayer, party, home);
plugin.getEventManager().callEvent(partiesPostHomeEvent);
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_HOMEEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
} else {
plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_HOME_NO_SERVER, party.getId()));
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class VelocityCommandTeleport method teleportSinglePlayer.
public static void teleportSinglePlayer(PartiesPlugin plugin, PartyPlayerImpl player, PartyPlayerImpl targetPlayer, RegisteredServer server) {
Player velocityPlayer = ((VelocityPartiesBootstrap) plugin.getBootstrap()).getServer().getPlayer(player.getPlayerUUID()).orElse(null);
if (velocityPlayer != null) {
PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
IPlayerPreTeleportEvent partiesPreTeleportEvent = plugin.getEventManager().preparePlayerPreTeleportEvent(player, party, server);
plugin.getEventManager().callEvent(partiesPreTeleportEvent);
if (!partiesPreTeleportEvent.isCancelled()) {
velocityPlayer.getCurrentServer().ifPresent(serverConnection1 -> {
boolean serverChange = false;
if (!serverConnection1.getServer().equals(server)) {
serverChange = true;
velocityPlayer.createConnectionRequest(server);
}
User velocityUser = plugin.getPlayer(player.getPlayerUUID());
if (velocityUser != null) {
if (serverChange) {
plugin.getScheduler().scheduleAsyncLater(() -> ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(velocityUser, targetPlayer), VelocityConfigParties.ADDITIONAL_TELEPORT_EXACT_LOCATION_DELAY, TimeUnit.MILLISECONDS);
} else {
((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(velocityUser, targetPlayer);
}
player.sendMessage(Messages.ADDCMD_TELEPORT_PLAYER_TELEPORTED, targetPlayer);
IPlayerPostTeleportEvent partiesPostTeleportEvent = plugin.getEventManager().preparePlayerPostTeleportEvent(player, party, server);
plugin.getEventManager().callEvent(partiesPostTeleportEvent);
}
});
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_TELEPORTEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class MotdTask method run.
@Override
public void run() {
PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(playerUUID);
User sender = plugin.getPlayer(playerUUID);
if (sender != null && ConfigParties.ADDITIONAL_MOTD_ENABLE && createID.equals(partyPlayer.getCreateID())) {
PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
if (party != null && party.getMotd() != null && !party.getMotd().isEmpty()) {
// Formatting motd
String motd = party.getMotd();
motd = motd.replace(ConfigParties.ADDITIONAL_MOTD_NEWLINECODE, "\n");
for (String line : Messages.ADDCMD_MOTD_CONTENT) {
// Used to bypass tags from convertAllPlaceholders
line = line.replace("%motd%", "%temporary_motd%");
line = plugin.getMessageUtils().convertPlaceholders(line, partyPlayer, party);
line = Color.translateAlternateColorCodes(line);
line = line.replace("%temporary_motd%", motd);
partyPlayer.sendMessage(line);
}
}
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl 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.parties.objects.PartyImpl 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);
}
Aggregations