Skip to content

Commit

Permalink
Merge branch 'main' into 4-add-mail-functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
zefir-git committed May 19, 2024
2 parents 9dd174a + 39c62d5 commit b1705dd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 34 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,24 @@ jobs:
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'

distribution: 'temurin'

- name: Set release version
run: |
TAG=${{ github.event.release.tag_name }}
echo "VERSION=${TAG#v}" >> $GITHUB_OUTPUT
id: version

- name: Set project version
run: mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false
run: mvn -B versions:set -DnewVersion=${{ steps.version.outputs.VERSION }} -DgenerateBackupPoms=false

- name: Build and package Maven project
run: mvn clean package

- name: Upload to release
uses: JasonEtco/upload-to-release@master
with:
args: target/CloudnodeMSG-${{ github.event.release.tag_name }}.jar application/java-archive
args: target/CloudnodeMSG-${{ steps.version.outputs.VERSION }}.jar application/java-archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -49,7 +55,7 @@ jobs:
with:
token: ${{ secrets.MODRINTH_TOKEN }}
project: 5Ce4fxJB
file: target/CloudnodeMSG-${{ github.event.release.tag_name }}.jar
file: target/CloudnodeMSG-${{ steps.version.outputs.VERSION }}.jar
changelog: ${{ github.event.release.body }}
loaders: paper

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ Enable or disable receiving private messages of another player.
Reload the plugin configuration.

<dl>
<dt>Aliases:</dt> <dd><code>/toggledms</code>, <code>/togglepms</code></dd>
<dt>Permission:</dt> <dd><code>cloudnodemsg.reload</code></dd>
</dl>

Expand Down
57 changes: 43 additions & 14 deletions src/main/java/pro/cloudnode/smp/cloudnodemsg/Message.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pro.cloudnode.smp.cloudnodemsg;

import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
Expand All @@ -12,6 +13,7 @@
import pro.cloudnode.smp.cloudnodemsg.error.InvalidPlayerError;
import pro.cloudnode.smp.cloudnodemsg.error.PlayerHasIncomingDisabledError;
import pro.cloudnode.smp.cloudnodemsg.error.PlayerNotFoundError;
import pro.cloudnode.smp.cloudnodemsg.error.ReplyOfflineError;

import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -35,19 +37,27 @@ public Message(@NotNull OfflinePlayer sender, @NotNull OfflinePlayer recipient,
}

public void send() throws InvalidPlayerError {
send(false);
send(Context.REGULAR);
}

public void send(final boolean channel) throws InvalidPlayerError {
public void send(final @NotNull Context context) throws InvalidPlayerError {
final @NotNull String senderUsername = playerOrServerUsername(this.sender);
final @NotNull String recipientUsername = playerOrServerUsername(this.recipient);

final @NotNull Optional<@NotNull Player> senderPlayer = Optional.ofNullable(this.sender.getPlayer());
final @NotNull Optional<@NotNull Player> recipientPlayer = Optional.ofNullable(this.recipient.getPlayer());

if (senderPlayer.isPresent() && (recipientPlayer.isEmpty() || (CloudnodeMSG.isVanished(recipientPlayer.get()) && !senderPlayer
.get().hasPermission(Permission.SEND_VANISHED)))) {
if (!channel) new PlayerNotFoundError(senderPlayer.get().getName()).send(senderPlayer.get());
if (!recipient.getUniqueId().equals(console.getUniqueId()) && recipientPlayer.isEmpty() || (recipientPlayer.isPresent() && senderPlayer.isPresent() && CloudnodeMSG.isVanished(recipientPlayer.get()) && !senderPlayer.get().hasPermission(Permission.SEND_VANISHED))) {
if (context == Context.CHANNEL) {
final @NotNull Player player = Objects.requireNonNull(sender.getPlayer());
Message.exitChannel(player);
new ChannelOfflineError(player.getName(), Optional.ofNullable(recipient.getName())
.orElse("Unknown Player")).send(player);
}
else {
Message.exitChannel(senderPlayer.get());
new ChannelOfflineError(senderPlayer.get(), recipient).send(senderPlayer.get());
final @NotNull Audience senderAudience = senderPlayer.isPresent() ? senderPlayer.get() : CloudnodeMSG.getInstance().getServer().getConsoleSender();
if (context == Context.REPLY) new ReplyOfflineError(recipientUsername).send(senderAudience);
else new PlayerNotFoundError(recipientUsername).send(senderAudience);
}
return;
}
Expand All @@ -58,17 +68,16 @@ public void send(final boolean channel) throws InvalidPlayerError {
return;
}

sendMessage(sender, CloudnodeMSG.getInstance().config().outgoing(sender, recipient, message));
if (senderPlayer.isPresent() && !Message.hasChannel(senderPlayer.get(), recipient))
setReplyTo(sender, recipient);

sendSpyMessage(sender, recipient, message);

sendMessage(sender, CloudnodeMSG.getInstance().config().outgoing(senderUsername, recipientUsername, message));
if ((recipientPlayer.isPresent() && Message.isIgnored(recipientPlayer.get(), sender)) && (senderPlayer.isPresent() && !senderPlayer
.get().hasPermission(Permission.IGNORE_BYPASS))) return;
sendMessage(recipient, CloudnodeMSG.getInstance().config()
.incoming(sender, recipient, message));
if (recipientPlayer.isPresent() && !Message.hasChannel(recipientPlayer.get(), sender))
.incoming(senderUsername, recipientUsername, message));

if (sender.getUniqueId().equals(console.getUniqueId()) || (senderPlayer.isPresent() && !Message.hasChannel(senderPlayer.get(), recipient)))
setReplyTo(sender, recipient);
if (recipient.getUniqueId().equals(console.getUniqueId()) || (recipientPlayer.isPresent() && !Message.hasChannel(recipientPlayer.get(), sender)))
setReplyTo(recipient, sender);
}

Expand Down Expand Up @@ -289,4 +298,24 @@ public static void exitTeamChannel(final @NotNull Player player) {
public static boolean hasTeamChannel(final @NotNull Player player) {
return player.getPersistentDataContainer().getOrDefault(CHANNEL_TEAM, PersistentDataType.BOOLEAN, false);
}

/**
* The context in which this message is sent
*/
public static enum Context {
/**
* Message sent via command (i.e. no special context)
*/
REGULAR,

/**
* Message sent via messaging channel
*/
CHANNEL,

/**
* Message sent as a reply
*/
REPLY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import pro.cloudnode.smp.cloudnodemsg.CloudnodeMSG;
import pro.cloudnode.smp.cloudnodemsg.Message;
import pro.cloudnode.smp.cloudnodemsg.Permission;
import pro.cloudnode.smp.cloudnodemsg.error.InvalidPlayerError;
import pro.cloudnode.smp.cloudnodemsg.error.NoPermissionError;
import pro.cloudnode.smp.cloudnodemsg.error.NobodyReplyError;
import pro.cloudnode.smp.cloudnodemsg.error.ReplyOfflineError;
import pro.cloudnode.smp.cloudnodemsg.error.PlayerHasIncomingDisabledError;
import pro.cloudnode.smp.cloudnodemsg.Message;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public final class ReplyCommand extends Command {
Expand All @@ -27,17 +24,9 @@ public boolean run(final @NotNull CommandSender sender, final @NotNull String la

final @NotNull Optional<@NotNull OfflinePlayer> recipient = Message.getReplyTo(Message.offlinePlayer(sender));
if (recipient.isEmpty()) return new NobodyReplyError().send(sender);
if (
!recipient.get().getUniqueId().equals(Message.console.getUniqueId())
&& (
!recipient.get().isOnline()
|| (CloudnodeMSG.isVanished(Objects.requireNonNull(recipient.get().getPlayer())) && !sender.hasPermission(Permission.SEND_VANISHED))
)
)
return new ReplyOfflineError(recipient.get()).send(sender);

try {
new Message(Message.offlinePlayer(sender), recipient.get(), String.join(" ", args)).send();
new Message(Message.offlinePlayer(sender), recipient.get(), String.join(" ", args)).send(Message.Context.REPLY);
return true;
}
catch (final @NotNull InvalidPlayerError e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void channels(final @NotNull AsyncChatEvent event) {
if (channelRecipient.isEmpty()) return;
event.setCancelled(true);
try {
new Message(sender, channelRecipient.get(), event.message()).send(true);
new Message(sender, channelRecipient.get(), event.message()).send(Message.Context.CHANNEL);
}
catch (final @NotNull InvalidPlayerError e) {
e.log().send(sender);
Expand Down

0 comments on commit b1705dd

Please sign in to comment.