mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Make ChatUser an Audience
This commit is contained in:
1 parent
0483720640
commit
dae3af28f2
9 files changed
+22
-19
No files matched your search
@@ -140,7 +140,7 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
"server", event.getServer().get().getName(), "primaryrole", role);
|
"server", event.getServer().get().getName(), "primaryrole", role);
|
||||||
|
|
||||||
for (ChatUser user : getAudience(null)) {
|
for (ChatUser user : getAudience(null)) {
|
||||||
user.asAudience().sendMessage(component);
|
user.sendMessage(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +223,7 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
if (user.isShadowMuted()) {
|
if (user.isShadowMuted()) {
|
||||||
// TODO: move this into a ChatComponentEvent listener
|
// TODO: move this into a ChatComponentEvent listener
|
||||||
if (user.isOnline()) {
|
if (user.isOnline()) {
|
||||||
user.asAudience().sendMessage(componentEvent.getComponent());
|
user.sendMessage(componentEvent.getComponent());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Send message as normal
|
// Send message as normal
|
||||||
@@ -235,11 +235,11 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
float volume = (float)simpleChat.getConfig().getDouble("pings.volume");
|
float volume = (float)simpleChat.getConfig().getDouble("pings.volume");
|
||||||
float pitch = (float)simpleChat.getConfig().getDouble("pings.pitch");
|
float pitch = (float)simpleChat.getConfig().getDouble("pings.pitch");
|
||||||
|
|
||||||
chatUser.asAudience().playSound(Sound.of(key, source, volume, pitch));
|
chatUser.playSound(Sound.of(key, source, volume, pitch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chatUser.asAudience().sendMessage(componentEvent.getComponent());
|
chatUser.sendMessage(componentEvent.getComponent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
@Override
|
@Override
|
||||||
public void sendComponent(ChatUser player, Component component) {
|
public void sendComponent(ChatUser player, Component component) {
|
||||||
for (ChatUser user : getAudience(player)) {
|
for (ChatUser user : getAudience(player)) {
|
||||||
user.asAudience().sendMessage(component);
|
user.sendMessage(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(LegacyComponentSerializer.legacy().serialize(component));
|
System.out.println(LegacyComponentSerializer.legacy().serialize(component));
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class AliasedChannelCommand extends BaseCommand {
|
|||||||
if (args == null || args.length == 0) {
|
if (args == null || args.length == 0) {
|
||||||
user.setSelectedChannel(getChatChannel());
|
user.setSelectedChannel(getChatChannel());
|
||||||
|
|
||||||
user.asAudience().sendMessage(MiniMessage.instance().parse(
|
user.sendMessage(MiniMessage.instance().parse(
|
||||||
getChatChannel().getSwitchMessage(), "color", "<" + getChatChannel().getColor().toString() + ">",
|
getChatChannel().getSwitchMessage(), "color", "<" + getChatChannel().getColor().toString() + ">",
|
||||||
"channel", getChatChannel().getName()));
|
"channel", getChatChannel().getName()));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class ChannelCommand extends BaseCommand {
|
|||||||
if (args == null || args.length == 0) {
|
if (args == null || args.length == 0) {
|
||||||
user.setSelectedChannel(channel);
|
user.setSelectedChannel(channel);
|
||||||
|
|
||||||
user.asAudience().sendMessage(MiniMessage.instance().parse(
|
user.sendMessage(MiniMessage.instance().parse(
|
||||||
channel.getSwitchMessage(), "color", "<" + channel.getColor().toString() + ">",
|
channel.getSwitchMessage(), "color", "<" + channel.getColor().toString() + ">",
|
||||||
"channel", channel.getName()));
|
"channel", channel.getName()));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class IgnoreCommand extends BaseCommand {
|
|||||||
message = simpleChat.getConfig().getString("language.ignoring-user");
|
message = simpleChat.getConfig().getString("language.ignoring-user");
|
||||||
}
|
}
|
||||||
|
|
||||||
user.asAudience().sendMessage(MiniMessage.instance().parse(message));
|
user.sendMessage(MiniMessage.instance().parse(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ public class MeCommand extends BaseCommand {
|
|||||||
ChatUser user = simpleChat.getUserService().wrap(player);
|
ChatUser user = simpleChat.getUserService().wrap(player);
|
||||||
|
|
||||||
if (user.isShadowMuted()) {
|
if (user.isShadowMuted()) {
|
||||||
user.asAudience().sendMessage(component);
|
user.sendMessage(component);
|
||||||
} else {
|
} else {
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
if (simpleChat.getUserService().wrap(onlinePlayer).isIgnoringUser(user)) {
|
if (simpleChat.getUserService().wrap(onlinePlayer).isIgnoringUser(user)) {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class ReplyCommand extends BaseCommand {
|
|||||||
if (user.getReplyTarget() == null) {
|
if (user.getReplyTarget() == null) {
|
||||||
String message = simpleChat.getConfig().getString("language.no-reply-target");
|
String message = simpleChat.getConfig().getString("language.no-reply-target");
|
||||||
Component component = MiniMessage.instance().parse(message);
|
Component component = MiniMessage.instance().parse(message);
|
||||||
user.asAudience().sendMessage(component);
|
user.sendMessage(component);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class ToggleCommand extends BaseCommand {
|
|||||||
message = channel.getToggleOnMessage();
|
message = channel.getToggleOnMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
user.asAudience().sendMessage(MiniMessage.instance().parse(message,
|
user.sendMessage(MiniMessage.instance().parse(message,
|
||||||
"color", channel.getColor().toString(), "channel", channel.getName()));
|
"color", channel.getColor().toString(), "channel", channel.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ import org.bukkit.entity.Player;
|
|||||||
import javax.annotation.CheckForNull;
|
import javax.annotation.CheckForNull;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface ChatUser {
|
public interface ChatUser extends Audience {
|
||||||
|
|
||||||
Audience asAudience();
|
|
||||||
Player asPlayer();
|
Player asPlayer();
|
||||||
OfflinePlayer asOfflinePlayer();
|
OfflinePlayer asOfflinePlayer();
|
||||||
UUID getUUID();
|
UUID getUUID();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.draycia.simplechat.SimpleChat;
|
|||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.audience.ForwardingAudience;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.sound.Sound;
|
import net.kyori.adventure.sound.Sound;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -17,7 +18,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SimpleChatUser implements ChatUser {
|
public class SimpleChatUser implements ChatUser, ForwardingAudience {
|
||||||
|
|
||||||
private SimpleChat simpleChat;
|
private SimpleChat simpleChat;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
@@ -29,14 +30,17 @@ public class SimpleChatUser implements ChatUser {
|
|||||||
private boolean shadowMuted;
|
private boolean shadowMuted;
|
||||||
private UUID replyTarget = null;
|
private UUID replyTarget = null;
|
||||||
|
|
||||||
|
private Audience audience;
|
||||||
|
|
||||||
public SimpleChatUser(SimpleChat simpleChat, UUID uuid) {
|
public SimpleChatUser(SimpleChat simpleChat, UUID uuid) {
|
||||||
this.simpleChat = simpleChat;
|
this.simpleChat = simpleChat;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
this.audience = simpleChat.getAudiences().player(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Audience asAudience() {
|
public Audience audience() {
|
||||||
return simpleChat.getAudiences().player(uuid);
|
return audience;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -161,14 +165,14 @@ public class SimpleChatUser implements ChatUser {
|
|||||||
Component fromPlayerComponent = MiniMessage.instance().parse(fromPlayerFormat, "message", message,
|
Component fromPlayerComponent = MiniMessage.instance().parse(fromPlayerFormat, "message", message,
|
||||||
"sender", sender.asOfflinePlayer().getName());
|
"sender", sender.asOfflinePlayer().getName());
|
||||||
|
|
||||||
sender.asAudience().sendMessage(toPlayerComponent);
|
sender.sendMessage(toPlayerComponent);
|
||||||
|
|
||||||
if (sender.isShadowMuted()) {
|
if (sender.isShadowMuted()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isOnline()) {
|
if (this.isOnline()) {
|
||||||
this.asAudience().sendMessage(fromPlayerComponent);
|
this.sendMessage(fromPlayerComponent);
|
||||||
|
|
||||||
sender.setReplyTarget(this.getUUID());
|
sender.setReplyTarget(this.getUUID());
|
||||||
this.setReplyTarget(sender.getUUID());
|
this.setReplyTarget(sender.getUUID());
|
||||||
@@ -179,7 +183,7 @@ public class SimpleChatUser implements ChatUser {
|
|||||||
float volume = (float)simpleChat.getConfig().getDouble("pings.volume");
|
float volume = (float)simpleChat.getConfig().getDouble("pings.volume");
|
||||||
float pitch = (float)simpleChat.getConfig().getDouble("pings.pitch");
|
float pitch = (float)simpleChat.getConfig().getDouble("pings.pitch");
|
||||||
|
|
||||||
this.asAudience().playSound(Sound.of(key, source, volume, pitch));
|
this.playSound(Sound.of(key, source, volume, pitch));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: cross server msg support, don't forget to include /ignore support
|
// TODO: cross server msg support, don't forget to include /ignore support
|
||||||
|
|||||||
Reference in new issue
Block a user