Skip to content

Commit b0618e9

Browse files
committed
setting/getting/deleting dm channels
1 parent 00ee881 commit b0618e9

File tree

1 file changed

+30
-0
lines changed
  • src/main/java/pro/cloudnode/smp/cloudnodemsg/message

1 file changed

+30
-0
lines changed

src/main/java/pro/cloudnode/smp/cloudnodemsg/message/Message.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ else if (player.isOnline())
8888
}
8989

9090
public static final @NotNull NamespacedKey IGNORED_PLAYERS = new NamespacedKey(CloudnodeMSG.getInstance(), "ignored");
91+
public static final @NotNull NamespacedKey CHANNEL_RECIPIENT = new NamespacedKey(CloudnodeMSG.getInstance(), "channel-recipient");
9192

9293
/**
9394
* Get UUID set of ignored players from PDC string
@@ -133,4 +134,33 @@ public static void unignore(final @NotNull Player player, final @NotNull Offline
133134
ignoredPlayers.remove(ignored.getUniqueId());
134135
player.getPersistentDataContainer().set(IGNORED_PLAYERS, PersistentDataType.STRING, String.join(";", ignoredPlayers.stream().map(UUID::toString).toList()));
135136
}
137+
138+
/**
139+
* Create DM channel to player
140+
*
141+
* @param player The player (you)
142+
* @param recipient The other end of the channel
143+
*/
144+
public static void createChannel(final @NotNull Player player, final @NotNull OfflinePlayer recipient) {
145+
player.getPersistentDataContainer().set(CHANNEL_RECIPIENT, PersistentDataType.STRING, recipient.getUniqueId().toString());
146+
}
147+
148+
/**
149+
* Exit DM channel
150+
*
151+
* @param player The player (you)
152+
*/
153+
public static void exitChannel(final @NotNull Player player) {
154+
player.getPersistentDataContainer().remove(CHANNEL_RECIPIENT);
155+
}
156+
157+
/**
158+
* Get DM channel recipient
159+
*
160+
* @param player The player
161+
*/
162+
public static @NotNull Optional<@NotNull OfflinePlayer> getChannel(final @NotNull Player player) {
163+
return Optional.ofNullable(player.getPersistentDataContainer().get(CHANNEL_RECIPIENT, PersistentDataType.STRING))
164+
.map(uuid -> CloudnodeMSG.getInstance().getServer().getOfflinePlayer(UUID.fromString(uuid)));
165+
}
136166
}

0 commit comments

Comments
 (0)