diff --git a/base/src/main/java/vakiliner/chatcomponentapi/base/ChatBanEntry.java b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatBanEntry.java new file mode 100644 index 0000000..6e2fda5 --- /dev/null +++ b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatBanEntry.java @@ -0,0 +1,11 @@ +package vakiliner.chatcomponentapi.base; + +import java.util.Date; + +public interface ChatBanEntry extends ChatStoredUserEntry { + String getSource(); + + Date getExpires(); + + String getReason(); +} \ No newline at end of file diff --git a/base/src/main/java/vakiliner/chatcomponentapi/base/ChatBanList.java b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatBanList.java new file mode 100644 index 0000000..d74d1be --- /dev/null +++ b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatBanList.java @@ -0,0 +1,7 @@ +package vakiliner.chatcomponentapi.base; + +import java.util.Date; + +public interface ChatBanList extends ChatStoredUserList { + ChatBanEntry add(Key key, String reason, String source, Date expires); +} \ No newline at end of file diff --git a/base/src/main/java/vakiliner/chatcomponentapi/base/ChatIpBanList.java b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatIpBanList.java new file mode 100644 index 0000000..1b475ce --- /dev/null +++ b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatIpBanList.java @@ -0,0 +1,5 @@ +package vakiliner.chatcomponentapi.base; + +public interface ChatIpBanList extends ChatBanList { + boolean isBanned(String ip); +} \ No newline at end of file diff --git a/base/src/main/java/vakiliner/chatcomponentapi/base/ChatPlayerList.java b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatPlayerList.java new file mode 100644 index 0000000..3402bab --- /dev/null +++ b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatPlayerList.java @@ -0,0 +1,32 @@ +package vakiliner.chatcomponentapi.base; + +import java.util.Collection; +import java.util.UUID; +import vakiliner.chatcomponentapi.common.ChatMessageType; +import vakiliner.chatcomponentapi.component.ChatComponent; + +public interface ChatPlayerList { + ChatServer getServer(); + + ChatIpBanList getIpBanList(); + + ChatUserBanList getUserBanList(); + + int getPlayerCount(); + + int getMaxPlayers(); + + int getViewDistance(); + + Collection getPlayers(); + + ChatPlayer getPlayer(UUID uuid); + + ChatPlayer getPlayer(String name); + + default void broadcastMessage(ChatComponent component) { + this.broadcastMessage(component, ChatMessageType.SYSTEM, null); + } + + void broadcastMessage(ChatComponent component, ChatMessageType type, UUID uuid); +} \ No newline at end of file diff --git a/base/src/main/java/vakiliner/chatcomponentapi/base/ChatServer.java b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatServer.java index 7db2c7b..75aa103 100644 --- a/base/src/main/java/vakiliner/chatcomponentapi/base/ChatServer.java +++ b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatServer.java @@ -1,5 +1,7 @@ package vakiliner.chatcomponentapi.base; public interface ChatServer { + ChatPlayerList getPlayerList(); + public void execute(IChatPlugin plugin, Runnable runnable); } \ No newline at end of file diff --git a/base/src/main/java/vakiliner/chatcomponentapi/base/ChatStoredUserEntry.java b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatStoredUserEntry.java new file mode 100644 index 0000000..311960b --- /dev/null +++ b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatStoredUserEntry.java @@ -0,0 +1,4 @@ +package vakiliner.chatcomponentapi.base; + +public interface ChatStoredUserEntry { +} \ No newline at end of file diff --git a/base/src/main/java/vakiliner/chatcomponentapi/base/ChatStoredUserList.java b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatStoredUserList.java new file mode 100644 index 0000000..694f524 --- /dev/null +++ b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatStoredUserList.java @@ -0,0 +1,15 @@ +package vakiliner.chatcomponentapi.base; + +import java.util.Collection; + +public interface ChatStoredUserList { + Entry add(Key key); + + Entry get(Key key); + + void remove(Key key); + + Collection getEntries(); + + boolean isEmpty(); +} \ No newline at end of file diff --git a/base/src/main/java/vakiliner/chatcomponentapi/base/ChatUserBanList.java b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatUserBanList.java new file mode 100644 index 0000000..18e7c34 --- /dev/null +++ b/base/src/main/java/vakiliner/chatcomponentapi/base/ChatUserBanList.java @@ -0,0 +1,7 @@ +package vakiliner.chatcomponentapi.base; + +import com.mojang.authlib.GameProfile; + +public interface ChatUserBanList extends ChatBanList { + boolean isBanned(GameProfile gameProfile); +} \ No newline at end of file diff --git a/base/src/main/java/vakiliner/chatcomponentapi/util/ParseCollection.java b/base/src/main/java/vakiliner/chatcomponentapi/util/ParseCollection.java new file mode 100644 index 0000000..9b7a14b --- /dev/null +++ b/base/src/main/java/vakiliner/chatcomponentapi/util/ParseCollection.java @@ -0,0 +1,40 @@ +package vakiliner.chatcomponentapi.util; + +import java.util.AbstractCollection; +import java.util.Collection; +import java.util.Iterator; +import java.util.function.Function; + +public class ParseCollection extends AbstractCollection { + protected final Collection original; + protected final Function i2o; + + public ParseCollection(Collection original, Function i2o) { + this.original = original; + this.i2o = i2o; + } + + public Collection getImpl() { + return original; + } + + public Iterator iterator() { + return new ParseIterator<>(this.original.iterator(), this.i2o); + } + + public int size() { + return this.original.size(); + } + + public boolean isEmpty() { + return this.original.isEmpty(); + } + + public boolean add(Output e) { + throw new UnsupportedOperationException(); + } + + public void clear() { + this.original.clear(); + } +} \ No newline at end of file diff --git a/base/src/main/java/vakiliner/chatcomponentapi/util/ParseIterator.java b/base/src/main/java/vakiliner/chatcomponentapi/util/ParseIterator.java new file mode 100644 index 0000000..fe9a530 --- /dev/null +++ b/base/src/main/java/vakiliner/chatcomponentapi/util/ParseIterator.java @@ -0,0 +1,30 @@ +package vakiliner.chatcomponentapi.util; + +import java.util.Iterator; +import java.util.function.Function; + +public class ParseIterator implements Iterator { + protected final Iterator original; + protected final Function i2o; + + public ParseIterator(Iterator original, Function i2o) { + this.original = original; + this.i2o = i2o; + } + + public Iterator getImpl() { + return this.original; + } + + public boolean hasNext() { + return this.original.hasNext(); + } + + public Output next() { + return this.i2o.apply(this.original.next()); + } + + public void remove() { + this.original.remove(); + } +} \ No newline at end of file diff --git a/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatBanEntry.java b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatBanEntry.java new file mode 100644 index 0000000..e225ddd --- /dev/null +++ b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatBanEntry.java @@ -0,0 +1,31 @@ +package vakiliner.chatcomponentapi.craftbukkit; + +import java.util.Date; +import org.bukkit.BanEntry; +import vakiliner.chatcomponentapi.base.ChatBanEntry; + +public class BukkitChatBanEntry implements ChatBanEntry { + protected final BukkitParser parser; + protected final BanEntry banEntry; + + public BukkitChatBanEntry(BukkitParser parser, BanEntry banEntry) { + this.parser = parser; + this.banEntry = banEntry; + } + + public BanEntry getImpl() { + return this.banEntry; + } + + public String getReason() { + return this.banEntry.getReason(); + } + + public String getSource() { + return this.banEntry.getSource(); + } + + public Date getExpires() { + return this.banEntry.getExpiration(); + } +} \ No newline at end of file diff --git a/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatBanList.java b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatBanList.java new file mode 100644 index 0000000..5aae073 --- /dev/null +++ b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatBanList.java @@ -0,0 +1,50 @@ +package vakiliner.chatcomponentapi.craftbukkit; + +import java.util.Collection; +import java.util.Date; +import org.bukkit.BanList; +import vakiliner.chatcomponentapi.base.ChatBanEntry; +import vakiliner.chatcomponentapi.base.ChatBanList; +import vakiliner.chatcomponentapi.util.ParseCollection; + +public abstract class BukkitChatBanList implements ChatBanList { + protected final BukkitParser parser; + protected final BanList banList; + + public BukkitChatBanList(BukkitParser parser, BanList banList) { + this.parser = parser; + this.banList = banList; + } + + public BanList getImpl() { + return this.banList; + } + + public ChatBanEntry add(String key) { + return this.add(key, null, null, null); + } + + public ChatBanEntry add(String key, String reason, String source, Date expires) { + return this.parser.toChatBanEntry(this.banList.addBan(key, reason, expires, source)); + } + + public ChatBanEntry get(String key) { + return this.parser.toChatBanEntry(this.banList.getBanEntry(key)); + } + + public void remove(String key) { + this.banList.pardon(key); + } + + public boolean isBanned(String key) { + return this.banList.isBanned(key); + } + + public Collection getEntries() { + return new ParseCollection<>(this.banList.getBanEntries(), this.parser::toChatBanEntry); + } + + public boolean isEmpty() { + return this.banList.getBanEntries().isEmpty(); + } +} \ No newline at end of file diff --git a/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatIpBanList.java b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatIpBanList.java new file mode 100644 index 0000000..7319f14 --- /dev/null +++ b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatIpBanList.java @@ -0,0 +1,10 @@ +package vakiliner.chatcomponentapi.craftbukkit; + +import org.bukkit.BanList; +import vakiliner.chatcomponentapi.base.ChatIpBanList; + +public class BukkitChatIpBanList extends BukkitChatBanList implements ChatIpBanList { + public BukkitChatIpBanList(BukkitParser parser, BanList banList) { + super(parser, banList); + } +} \ No newline at end of file diff --git a/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatServer.java b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatServer.java index 2594e97..3fcb9cc 100644 --- a/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatServer.java +++ b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatServer.java @@ -1,11 +1,21 @@ package vakiliner.chatcomponentapi.craftbukkit; +import java.util.Collection; import java.util.Objects; +import java.util.UUID; import org.bukkit.Server; +import org.bukkit.BanList.Type; +import vakiliner.chatcomponentapi.base.ChatIpBanList; +import vakiliner.chatcomponentapi.base.ChatPlayer; +import vakiliner.chatcomponentapi.base.ChatPlayerList; import vakiliner.chatcomponentapi.base.ChatServer; +import vakiliner.chatcomponentapi.base.ChatUserBanList; import vakiliner.chatcomponentapi.base.IChatPlugin; +import vakiliner.chatcomponentapi.common.ChatMessageType; +import vakiliner.chatcomponentapi.component.ChatComponent; +import vakiliner.chatcomponentapi.util.ParseCollection; -public class BukkitChatServer implements ChatServer { +public class BukkitChatServer implements ChatServer, ChatPlayerList { protected final BukkitParser parser; protected final Server server; @@ -18,6 +28,50 @@ public Server getImpl() { return this.server; } + public ChatServer getServer() { + return this; + } + + public ChatPlayerList getPlayerList() { + return this; + } + + public ChatIpBanList getIpBanList() { + return this.parser.toChatIpBanList(this.server.getBanList(Type.IP)); + } + + public ChatUserBanList getUserBanList() { + return this.parser.toChatUserBanList(this.server.getBanList(Type.NAME)); + } + + public int getPlayerCount() { + return this.server.getOnlinePlayers().size(); + } + + public int getMaxPlayers() { + return this.server.getMaxPlayers(); + } + + public int getViewDistance() { + return this.server.getViewDistance(); + } + + public Collection getPlayers() { + return new ParseCollection<>(this.server.getOnlinePlayers(), this.parser::toChatPlayer); + } + + public ChatPlayer getPlayer(UUID uuid) { + return this.parser.toChatPlayer(this.server.getPlayer(uuid)); + } + + public ChatPlayer getPlayer(String name) { + return this.parser.toChatPlayer(this.server.getPlayerExact(name)); + } + + public void broadcastMessage(ChatComponent component, ChatMessageType type, UUID uuid) { + this.parser.broadcastMessage(this.server, component, type, uuid); + } + public void execute(IChatPlugin plugin, Runnable runnable) { this.parser.execute(this.server.getScheduler(), plugin, runnable); } diff --git a/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatUserBanList.java b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatUserBanList.java new file mode 100644 index 0000000..c26b81d --- /dev/null +++ b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitChatUserBanList.java @@ -0,0 +1,33 @@ +package vakiliner.chatcomponentapi.craftbukkit; + +import java.util.Date; +import org.bukkit.BanList; +import com.mojang.authlib.GameProfile; +import vakiliner.chatcomponentapi.base.ChatBanEntry; +import vakiliner.chatcomponentapi.base.ChatUserBanList; + +public class BukkitChatUserBanList extends BukkitChatBanList implements ChatUserBanList { + public BukkitChatUserBanList(BukkitParser parser, BanList banList) { + super(parser, banList); + } + + public ChatBanEntry add(GameProfile key) { + return this.add(key.getName()); + } + + public ChatBanEntry add(GameProfile key, String reason, String source, Date expires) { + return this.add(key.getName(), reason, source, expires); + } + + public ChatBanEntry get(GameProfile key) { + return this.get(key.getName()); + } + + public void remove(GameProfile key) { + this.remove(key.getName()); + } + + public boolean isBanned(GameProfile gameProfile) { + return this.isBanned(gameProfile.getName()); + } +} \ No newline at end of file diff --git a/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitParser.java b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitParser.java index b603a4e..b385c1b 100644 --- a/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitParser.java +++ b/craftbukkit/src/main/java/vakiliner/chatcomponentapi/craftbukkit/BukkitParser.java @@ -1,20 +1,29 @@ package vakiliner.chatcomponentapi.craftbukkit; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; +import org.bukkit.BanEntry; +import org.bukkit.BanList; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.permissions.Permissible; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scoreboard.Team; import vakiliner.chatcomponentapi.base.BaseParser; +import vakiliner.chatcomponentapi.base.ChatBanEntry; import vakiliner.chatcomponentapi.base.ChatCommandSender; +import vakiliner.chatcomponentapi.base.ChatIpBanList; import vakiliner.chatcomponentapi.base.ChatOfflinePlayer; import vakiliner.chatcomponentapi.base.ChatPlayer; +import vakiliner.chatcomponentapi.base.ChatPlayerList; import vakiliner.chatcomponentapi.base.ChatServer; import vakiliner.chatcomponentapi.base.ChatTeam; +import vakiliner.chatcomponentapi.base.ChatUserBanList; import vakiliner.chatcomponentapi.base.IChatPlugin; import vakiliner.chatcomponentapi.common.ChatMessageType; import vakiliner.chatcomponentapi.common.ChatTextFormat; @@ -30,10 +39,33 @@ public boolean supportsFontInStyle() { } public void sendMessage(CommandSender sender, ChatComponent component, ChatMessageType type, UUID uuid) { - if (type == ChatMessageType.CHAT) { - sender.sendMessage(uuid, component.toLegacyText()); + this.sendMessage(sender, component.toLegacyText(), type == ChatMessageType.CHAT, uuid); + } + + private void sendMessage(CommandSender sender, String message, boolean chat, UUID uuid) { + if (chat) { + sender.sendMessage(uuid, message); } else { - sender.sendMessage(component.toLegacyText()); + sender.sendMessage(message); + } + } + + public void broadcastMessage(Server server, ChatComponent component, ChatMessageType type, UUID uuid) { + Set recipients = new HashSet<>(); + Set permissibles = server.getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_USERS); + for (Permissible permissible : permissibles) { + if (permissible instanceof CommandSender && permissible.hasPermission(Server.BROADCAST_CHANNEL_USERS)) { + recipients.add((CommandSender) permissible); + } + } + this.broadcast(recipients, component, type, uuid); + } + + public void broadcast(Iterable recipients, ChatComponent chatComponent, ChatMessageType chatMessageType, UUID uuid) { + String message = chatComponent.toLegacyText(); + boolean chat = chatMessageType == ChatMessageType.CHAT; + for (CommandSender recipient : recipients) { + this.sendMessage(recipient, message, chat, uuid); } } @@ -86,4 +118,20 @@ public ChatTeam toChatTeam(Team team) { public ChatServer toChatServer(Server server) { return server != null ? new BukkitChatServer(this, server) : null; } + + public ChatPlayerList toChatPlayerList(Server server) { + return server != null ? new BukkitChatServer(this, server) : null; + } + + public ChatIpBanList toChatIpBanList(BanList banList) { + return banList != null ? new BukkitChatIpBanList(this, banList) : null; + } + + public ChatUserBanList toChatUserBanList(BanList banList) { + return banList != null ? new BukkitChatUserBanList(this, banList) : null; + } + + public ChatBanEntry toChatBanEntry(BanEntry banEntry) { + return banEntry != null ? new BukkitChatBanEntry(this, banEntry) : null; + } } \ No newline at end of file diff --git a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatBanEntry.java b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatBanEntry.java new file mode 100644 index 0000000..e3af04e --- /dev/null +++ b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatBanEntry.java @@ -0,0 +1,23 @@ +package vakiliner.chatcomponentapi.fabric; + +import java.util.Date; +import net.minecraft.server.players.BanListEntry; +import vakiliner.chatcomponentapi.base.ChatBanEntry; + +public class FabricChatBanEntry> extends FabricChatStoredUserEntry implements ChatBanEntry { + public FabricChatBanEntry(FabricParser parser, Entry entry) { + super(parser, entry); + } + + public String getReason() { + return this.entry.getReason(); + } + + public String getSource() { + return this.entry.getSource(); + } + + public Date getExpires() { + return this.entry.getExpires(); + } +} \ No newline at end of file diff --git a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatIpBanList.java b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatIpBanList.java new file mode 100644 index 0000000..d723a9c --- /dev/null +++ b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatIpBanList.java @@ -0,0 +1,38 @@ +package vakiliner.chatcomponentapi.fabric; + +import java.net.SocketAddress; +import java.util.Date; +import net.minecraft.server.players.IpBanList; +import net.minecraft.server.players.IpBanListEntry; +import vakiliner.chatcomponentapi.base.ChatBanEntry; +import vakiliner.chatcomponentapi.base.ChatIpBanList; + +public class FabricChatIpBanList extends FabricChatStoredUserList implements ChatIpBanList { + public FabricChatIpBanList(FabricParser parser, IpBanList list) { + super(parser, list, parser::toChatBanEntry); + } + + public ChatBanEntry add(String key) { + IpBanListEntry entry = new IpBanListEntry(key); + this.list.add(entry); + return this.i2o.apply(entry); + } + + public ChatBanEntry add(String key, String reason, String source, Date expires) { + IpBanListEntry entry = new IpBanListEntry(key, null, source, expires, reason); + this.list.add(entry); + return this.i2o.apply(entry); + } + + public ChatBanEntry get(SocketAddress address) { + return this.i2o.apply(this.list.get(address)); + } + + public boolean isBanned(SocketAddress address) { + return this.list.isBanned(address); + } + + public boolean isBanned(String ip) { + return this.list.isBanned(ip); + } +} \ No newline at end of file diff --git a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatPlayerList.java b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatPlayerList.java new file mode 100644 index 0000000..d6ed4a0 --- /dev/null +++ b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatPlayerList.java @@ -0,0 +1,79 @@ +package vakiliner.chatcomponentapi.fabric; + +import java.util.Collection; +import java.util.Objects; +import java.util.UUID; +import net.minecraft.server.players.PlayerList; +import vakiliner.chatcomponentapi.base.ChatIpBanList; +import vakiliner.chatcomponentapi.base.ChatPlayer; +import vakiliner.chatcomponentapi.base.ChatPlayerList; +import vakiliner.chatcomponentapi.base.ChatServer; +import vakiliner.chatcomponentapi.base.ChatUserBanList; +import vakiliner.chatcomponentapi.common.ChatMessageType; +import vakiliner.chatcomponentapi.component.ChatComponent; +import vakiliner.chatcomponentapi.util.ParseCollection; + +public class FabricChatPlayerList implements ChatPlayerList { + protected final FabricParser parser; + protected final PlayerList playerList; + + public FabricChatPlayerList(FabricParser parser, PlayerList playerList) { + this.parser = Objects.requireNonNull(parser); + this.playerList = Objects.requireNonNull(playerList); + } + + public PlayerList getPlayerList() { + return this.playerList; + } + + public ChatServer getServer() { + return this.parser.toChatServer(this.playerList.getServer()); + } + + public ChatIpBanList getIpBanList() { + return this.parser.toChatIpBanList(this.playerList.getIpBans()); + } + + public ChatUserBanList getUserBanList() { + return this.parser.toChatUserBanList(this.playerList.getBans()); + } + + public int getPlayerCount() { + return this.playerList.getPlayerCount(); + } + + public int getMaxPlayers() { + return this.playerList.getMaxPlayers(); + } + + public int getViewDistance() { + return this.playerList.getViewDistance(); + } + + public Collection getPlayers() { + return new ParseCollection<>(this.playerList.getPlayers(), this.parser::toChatPlayer); + } + + public ChatPlayer getPlayer(UUID uuid) { + return this.parser.toChatPlayer(this.playerList.getPlayer(uuid)); + } + + public ChatPlayer getPlayer(String name) { + return this.parser.toChatPlayer(this.playerList.getPlayerByName(name)); + } + + public void broadcastMessage(ChatComponent component, ChatMessageType type, UUID uuid) { + this.parser.broadcastMessage(this.playerList, component, type, uuid); + } + + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj != null && this.getClass() == obj.getClass()) { + FabricChatPlayerList other = (FabricChatPlayerList) obj; + return this.parser.equals(other.parser) && this.playerList.equals(other.playerList); + } else { + return false; + } + } +} \ No newline at end of file diff --git a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatServer.java b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatServer.java index b4991c6..3718796 100644 --- a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatServer.java +++ b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatServer.java @@ -2,6 +2,7 @@ import java.util.Objects; import net.minecraft.server.MinecraftServer; +import vakiliner.chatcomponentapi.base.ChatPlayerList; import vakiliner.chatcomponentapi.base.ChatServer; import vakiliner.chatcomponentapi.base.IChatPlugin; @@ -18,6 +19,10 @@ public MinecraftServer getImpl() { return this.server; } + public ChatPlayerList getPlayerList() { + return this.parser.toChatPlayerList(this.server.getPlayerList()); + } + public void execute(IChatPlugin plugin, Runnable runnable) { this.parser.execute(this.server, plugin, runnable); } diff --git a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatStoredUserEntry.java b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatStoredUserEntry.java new file mode 100644 index 0000000..a820042 --- /dev/null +++ b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatStoredUserEntry.java @@ -0,0 +1,30 @@ +package vakiliner.chatcomponentapi.fabric; + +import net.minecraft.server.players.StoredUserEntry; +import vakiliner.chatcomponentapi.base.ChatStoredUserEntry; + +public class FabricChatStoredUserEntry> implements ChatStoredUserEntry { + protected final FabricParser parser; + protected final Entry entry; + + public FabricChatStoredUserEntry(FabricParser parser, Entry entry) { + this.parser = parser; + this.entry = entry; + } + + public Entry getImpl() { + return this.entry; + } + + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj != null && this.getClass() == obj.getClass()) { + @SuppressWarnings("rawtypes") + FabricChatStoredUserEntry other = (FabricChatStoredUserEntry) obj; + return this.parser.equals(other.parser) && this.entry.equals(other.entry); + } else { + return false; + } + } +} \ No newline at end of file diff --git a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatStoredUserList.java b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatStoredUserList.java new file mode 100644 index 0000000..efb8662 --- /dev/null +++ b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatStoredUserList.java @@ -0,0 +1,49 @@ +package vakiliner.chatcomponentapi.fabric; + +import java.util.Collection; +import java.util.function.Function; +import net.minecraft.server.players.StoredUserEntry; +import net.minecraft.server.players.StoredUserList; +import vakiliner.chatcomponentapi.base.ChatStoredUserEntry; +import vakiliner.chatcomponentapi.base.ChatStoredUserList; +import vakiliner.chatcomponentapi.util.ParseCollection; + +public abstract class FabricChatStoredUserList, Output extends ChatStoredUserEntry, Input extends StoredUserEntry> implements ChatStoredUserList { + protected final FabricParser parser; + protected final List list; + protected final Function i2o; + + public FabricChatStoredUserList(FabricParser parser, List list, Function i2o) { + this.parser = parser; + this.list = list; + this.i2o = i2o; + } + + public Output get(Key key) { + return this.i2o.apply(this.list.get(key)); + } + + public void remove(Key key) { + this.list.remove(key); + } + + public Collection getEntries() { + return new ParseCollection<>(this.list.getEntries(), this.i2o); + } + + public boolean isEmpty() { + return this.list.isEmpty(); + } + + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj != null && this.getClass() == obj.getClass()) { + @SuppressWarnings("rawtypes") + FabricChatStoredUserList other = (FabricChatStoredUserList) obj; + return this.parser.equals(other.parser) && this.list.equals(other.list); + } else { + return false; + } + } +} \ No newline at end of file diff --git a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatUserBanList.java b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatUserBanList.java new file mode 100644 index 0000000..8dcc289 --- /dev/null +++ b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricChatUserBanList.java @@ -0,0 +1,30 @@ +package vakiliner.chatcomponentapi.fabric; + +import java.util.Date; +import com.mojang.authlib.GameProfile; +import net.minecraft.server.players.UserBanList; +import net.minecraft.server.players.UserBanListEntry; +import vakiliner.chatcomponentapi.base.ChatBanEntry; +import vakiliner.chatcomponentapi.base.ChatUserBanList; + +public class FabricChatUserBanList extends FabricChatStoredUserList implements ChatUserBanList { + public FabricChatUserBanList(FabricParser parser, UserBanList list) { + super(parser, list, parser::toChatBanEntry); + } + + public ChatBanEntry add(GameProfile key) { + UserBanListEntry entry = new UserBanListEntry(key); + this.list.add(entry); + return this.i2o.apply(entry); + } + + public ChatBanEntry add(GameProfile key, String reason, String source, Date expires) { + UserBanListEntry entry = new UserBanListEntry(key, null, source, expires, reason); + this.list.add(entry); + return this.i2o.apply(entry); + } + + public boolean isBanned(GameProfile gameProfile) { + return this.list.isBanned(gameProfile); + } +} \ No newline at end of file diff --git a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricParser.java b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricParser.java index 5c78283..dee7896 100644 --- a/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricParser.java +++ b/fabric/src/main/java/vakiliner/chatcomponentapi/fabric/FabricParser.java @@ -19,18 +19,26 @@ import net.minecraft.network.chat.TextColor; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundChatPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.players.BanListEntry; +import net.minecraft.server.players.IpBanList; import net.minecraft.server.players.PlayerList; +import net.minecraft.server.players.UserBanList; import net.minecraft.world.item.ItemStack; import net.minecraft.world.scores.PlayerTeam; import vakiliner.chatcomponentapi.base.BaseParser; +import vakiliner.chatcomponentapi.base.ChatBanEntry; import vakiliner.chatcomponentapi.base.ChatCommandSender; +import vakiliner.chatcomponentapi.base.ChatIpBanList; import vakiliner.chatcomponentapi.base.ChatOfflinePlayer; import vakiliner.chatcomponentapi.base.ChatPlayer; +import vakiliner.chatcomponentapi.base.ChatPlayerList; import vakiliner.chatcomponentapi.base.ChatServer; import vakiliner.chatcomponentapi.base.ChatTeam; +import vakiliner.chatcomponentapi.base.ChatUserBanList; import vakiliner.chatcomponentapi.base.IChatPlugin; import vakiliner.chatcomponentapi.common.ChatId; import vakiliner.chatcomponentapi.common.ChatMessageType; @@ -65,9 +73,10 @@ public void sendMessage(CommandSource commandSource, ChatComponent component, Ch } } - @Deprecated public void broadcastMessage(PlayerList playerList, ChatComponent component, ChatMessageType type, UUID uuid) { - playerList.broadcastMessage(fabric(component), fabric(type), uuid); + if (uuid == null) uuid = Util.NIL_UUID; + this.sendMessage(playerList.getServer(), component, type, uuid); + playerList.broadcastAll(new ClientboundChatPacket(fabric(component), fabric(type), uuid)); } public void execute(MinecraftServer server, IChatPlugin plugin, Runnable runnable) { @@ -271,4 +280,20 @@ public ChatTeam toChatTeam(PlayerTeam team) { public ChatServer toChatServer(MinecraftServer server) { return server != null ? new FabricChatServer(this, server) : null; } + + public ChatPlayerList toChatPlayerList(PlayerList playerList) { + return playerList != null ? new FabricChatPlayerList(this, playerList) : null; + } + + public ChatIpBanList toChatIpBanList(IpBanList ipBanList) { + return ipBanList != null ? new FabricChatIpBanList(this, ipBanList) : null; + } + + public ChatUserBanList toChatUserBanList(UserBanList userBanList) { + return userBanList != null ? new FabricChatUserBanList(this, userBanList) : null; + } + + public ChatBanEntry toChatBanEntry(BanListEntry banListEntry) { + return banListEntry != null ? new FabricChatBanEntry<>(this, banListEntry) : null; + } } \ No newline at end of file diff --git a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatBanEntry.java b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatBanEntry.java new file mode 100644 index 0000000..9f02636 --- /dev/null +++ b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatBanEntry.java @@ -0,0 +1,23 @@ +package vakiliner.chatcomponentapi.forge; + +import java.util.Date; +import net.minecraft.server.management.BanEntry; +import vakiliner.chatcomponentapi.base.ChatBanEntry; + +public class ForgeChatBanEntry> extends ForgeChatStoredUserEntry implements ChatBanEntry { + public ForgeChatBanEntry(ForgeParser parser, Entry entry) { + super(parser, entry); + } + + public String getReason() { + return this.entry.getReason(); + } + + public String getSource() { + return this.entry.getSource(); + } + + public Date getExpires() { + return this.entry.getExpires(); + } +} \ No newline at end of file diff --git a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatIpBanList.java b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatIpBanList.java new file mode 100644 index 0000000..94339d4 --- /dev/null +++ b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatIpBanList.java @@ -0,0 +1,38 @@ +package vakiliner.chatcomponentapi.forge; + +import java.net.SocketAddress; +import java.util.Date; +import net.minecraft.server.management.IPBanEntry; +import net.minecraft.server.management.IPBanList; +import vakiliner.chatcomponentapi.base.ChatBanEntry; +import vakiliner.chatcomponentapi.base.ChatIpBanList; + +public class ForgeChatIpBanList extends ForgeChatStoredUserList implements ChatIpBanList { + public ForgeChatIpBanList(ForgeParser parser, IPBanList list) { + super(parser, list, parser::toChatBanEntry); + } + + public ChatBanEntry add(String key) { + IPBanEntry entry = new IPBanEntry(key); + this.list.add(entry); + return this.i2o.apply(entry); + } + + public ChatBanEntry add(String key, String reason, String source, Date expires) { + IPBanEntry entry = new IPBanEntry(key, null, source, expires, reason); + this.list.add(entry); + return this.i2o.apply(entry); + } + + public ChatBanEntry get(SocketAddress address) { + return this.i2o.apply(this.list.get(address)); + } + + public boolean isBanned(SocketAddress address) { + return this.list.isBanned(address); + } + + public boolean isBanned(String ip) { + return this.list.isBanned(ip); + } +} \ No newline at end of file diff --git a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatPlayerList.java b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatPlayerList.java new file mode 100644 index 0000000..3770ecb --- /dev/null +++ b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatPlayerList.java @@ -0,0 +1,79 @@ +package vakiliner.chatcomponentapi.forge; + +import java.util.Collection; +import java.util.Objects; +import java.util.UUID; +import net.minecraft.server.management.PlayerList; +import vakiliner.chatcomponentapi.base.ChatIpBanList; +import vakiliner.chatcomponentapi.base.ChatPlayer; +import vakiliner.chatcomponentapi.base.ChatPlayerList; +import vakiliner.chatcomponentapi.base.ChatServer; +import vakiliner.chatcomponentapi.base.ChatUserBanList; +import vakiliner.chatcomponentapi.common.ChatMessageType; +import vakiliner.chatcomponentapi.component.ChatComponent; +import vakiliner.chatcomponentapi.util.ParseCollection; + +public class ForgeChatPlayerList implements ChatPlayerList { + protected final ForgeParser parser; + protected final PlayerList playerList; + + public ForgeChatPlayerList(ForgeParser parser, PlayerList playerList) { + this.parser = Objects.requireNonNull(parser); + this.playerList = Objects.requireNonNull(playerList); + } + + public PlayerList getPlayerList() { + return this.playerList; + } + + public ChatServer getServer() { + return this.parser.toChatServer(this.playerList.getServer()); + } + + public ChatIpBanList getIpBanList() { + return this.parser.toChatIpBanList(this.playerList.getIpBans()); + } + + public ChatUserBanList getUserBanList() { + return this.parser.toChatUserBanList(this.playerList.getBans()); + } + + public int getPlayerCount() { + return this.playerList.getPlayerCount(); + } + + public int getMaxPlayers() { + return this.playerList.getMaxPlayers(); + } + + public int getViewDistance() { + return this.playerList.getViewDistance(); + } + + public Collection getPlayers() { + return new ParseCollection<>(this.playerList.getPlayers(), this.parser::toChatPlayer); + } + + public ChatPlayer getPlayer(UUID uuid) { + return this.parser.toChatPlayer(this.playerList.getPlayer(uuid)); + } + + public ChatPlayer getPlayer(String name) { + return this.parser.toChatPlayer(this.playerList.getPlayerByName(name)); + } + + public void broadcastMessage(ChatComponent component, ChatMessageType type, UUID uuid) { + this.parser.broadcastMessage(this.playerList, component, type, uuid); + } + + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj != null && this.getClass() == obj.getClass()) { + ForgeChatPlayerList other = (ForgeChatPlayerList) obj; + return this.parser.equals(other.parser) && this.playerList.equals(other.playerList); + } else { + return false; + } + } +} \ No newline at end of file diff --git a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatServer.java b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatServer.java index 01a11e4..b641a48 100644 --- a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatServer.java +++ b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatServer.java @@ -2,6 +2,7 @@ import java.util.Objects; import net.minecraft.server.MinecraftServer; +import vakiliner.chatcomponentapi.base.ChatPlayerList; import vakiliner.chatcomponentapi.base.ChatServer; import vakiliner.chatcomponentapi.base.IChatPlugin; @@ -18,6 +19,10 @@ public MinecraftServer getImpl() { return this.server; } + public ChatPlayerList getPlayerList() { + return this.parser.toChatPlayerList(this.server.getPlayerList()); + } + public void execute(IChatPlugin plugin, Runnable runnable) { this.parser.execute(this.server, plugin, runnable); } diff --git a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatStoredUserEntry.java b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatStoredUserEntry.java new file mode 100644 index 0000000..e8480e4 --- /dev/null +++ b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatStoredUserEntry.java @@ -0,0 +1,30 @@ +package vakiliner.chatcomponentapi.forge; + +import net.minecraft.server.management.UserListEntry; +import vakiliner.chatcomponentapi.base.ChatStoredUserEntry; + +public class ForgeChatStoredUserEntry> implements ChatStoredUserEntry { + protected final ForgeParser parser; + protected final Entry entry; + + public ForgeChatStoredUserEntry(ForgeParser parser, Entry entry) { + this.parser = parser; + this.entry = entry; + } + + public Entry getImpl() { + return this.entry; + } + + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj != null && this.getClass() == obj.getClass()) { + @SuppressWarnings("rawtypes") + ForgeChatStoredUserEntry other = (ForgeChatStoredUserEntry) obj; + return this.parser.equals(other.parser) && this.entry.equals(other.entry); + } else { + return false; + } + } +} \ No newline at end of file diff --git a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatStoredUserList.java b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatStoredUserList.java new file mode 100644 index 0000000..6d95a5b --- /dev/null +++ b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatStoredUserList.java @@ -0,0 +1,49 @@ +package vakiliner.chatcomponentapi.forge; + +import java.util.Collection; +import java.util.function.Function; +import net.minecraft.server.management.UserList; +import net.minecraft.server.management.UserListEntry; +import vakiliner.chatcomponentapi.base.ChatStoredUserEntry; +import vakiliner.chatcomponentapi.base.ChatStoredUserList; +import vakiliner.chatcomponentapi.util.ParseCollection; + +public abstract class ForgeChatStoredUserList, Output extends ChatStoredUserEntry, Input extends UserListEntry> implements ChatStoredUserList { + protected final ForgeParser parser; + protected final List list; + protected final Function i2o; + + public ForgeChatStoredUserList(ForgeParser parser, List list, Function i2o) { + this.parser = parser; + this.list = list; + this.i2o = i2o; + } + + public Output get(Key key) { + return this.i2o.apply(this.list.get(key)); + } + + public void remove(Key key) { + this.list.remove(key); + } + + public Collection getEntries() { + return new ParseCollection<>(this.list.getEntries(), this.i2o); + } + + public boolean isEmpty() { + return this.list.isEmpty(); + } + + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj != null && this.getClass() == obj.getClass()) { + @SuppressWarnings("rawtypes") + ForgeChatStoredUserList other = (ForgeChatStoredUserList) obj; + return this.parser.equals(other.parser) && this.list.equals(other.list); + } else { + return false; + } + } +} \ No newline at end of file diff --git a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatUserBanList.java b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatUserBanList.java new file mode 100644 index 0000000..7e99da7 --- /dev/null +++ b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeChatUserBanList.java @@ -0,0 +1,30 @@ +package vakiliner.chatcomponentapi.forge; + +import java.util.Date; +import com.mojang.authlib.GameProfile; +import net.minecraft.server.management.BanList; +import net.minecraft.server.management.ProfileBanEntry; +import vakiliner.chatcomponentapi.base.ChatBanEntry; +import vakiliner.chatcomponentapi.base.ChatUserBanList; + +public class ForgeChatUserBanList extends ForgeChatStoredUserList implements ChatUserBanList { + public ForgeChatUserBanList(ForgeParser parser, BanList list) { + super(parser, list, parser::toChatBanEntry); + } + + public ChatBanEntry add(GameProfile key) { + ProfileBanEntry entry = new ProfileBanEntry(key); + this.list.add(entry); + return this.i2o.apply(entry); + } + + public ChatBanEntry add(GameProfile key, String reason, String source, Date expires) { + ProfileBanEntry entry = new ProfileBanEntry(key, null, source, expires, reason); + this.list.add(entry); + return this.i2o.apply(entry); + } + + public boolean isBanned(GameProfile gameProfile) { + return this.list.isBanned(gameProfile); + } +} \ No newline at end of file diff --git a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeParser.java b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeParser.java index f72a893..88c1ed2 100644 --- a/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeParser.java +++ b/forge/src/main/java/vakiliner/chatcomponentapi/forge/ForgeParser.java @@ -8,8 +8,13 @@ import net.minecraft.command.ICommandSource; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.network.play.server.SChatPacket; import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.management.BanEntry; +import net.minecraft.server.management.BanList; +import net.minecraft.server.management.IPBanList; +import net.minecraft.server.management.PlayerList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Util; import net.minecraft.util.registry.Registry; @@ -24,11 +29,15 @@ import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.HoverEvent; import vakiliner.chatcomponentapi.base.BaseParser; +import vakiliner.chatcomponentapi.base.ChatBanEntry; import vakiliner.chatcomponentapi.base.ChatCommandSender; +import vakiliner.chatcomponentapi.base.ChatIpBanList; import vakiliner.chatcomponentapi.base.ChatOfflinePlayer; import vakiliner.chatcomponentapi.base.ChatPlayer; +import vakiliner.chatcomponentapi.base.ChatPlayerList; import vakiliner.chatcomponentapi.base.ChatServer; import vakiliner.chatcomponentapi.base.ChatTeam; +import vakiliner.chatcomponentapi.base.ChatUserBanList; import vakiliner.chatcomponentapi.base.IChatPlugin; import vakiliner.chatcomponentapi.common.ChatId; import vakiliner.chatcomponentapi.common.ChatMessageType; @@ -54,14 +63,20 @@ public boolean supportsFontInStyle() { } public void sendMessage(ICommandSource commandSource, ChatComponent component, ChatMessageType type, UUID uuid) { + if (uuid == null) uuid = Util.NIL_UUID; if (commandSource instanceof ServerPlayerEntity) { - ServerPlayerEntity player = (ServerPlayerEntity) commandSource; - player.sendMessage(forge(component), forge(type), uuid != null ? uuid : Util.NIL_UUID); + ((ServerPlayerEntity) commandSource).sendMessage(forge(component), forge(type), uuid); } else { - commandSource.sendMessage(forge(component, commandSource instanceof MinecraftServer), uuid != null ? uuid : Util.NIL_UUID); + commandSource.sendMessage(forge(component, commandSource instanceof MinecraftServer), uuid); } } + public void broadcastMessage(PlayerList playerList, ChatComponent component, ChatMessageType type, UUID uuid) { + if (uuid == null) uuid = Util.NIL_UUID; + this.sendMessage(playerList.getServer(), component, type, uuid); + playerList.broadcastAll(new SChatPacket(forge(component), forge(type), uuid)); + } + public void execute(MinecraftServer server, IChatPlugin plugin, Runnable runnable) { if (plugin instanceof IForgeChatPlugin) { server.execute(runnable); @@ -259,4 +274,20 @@ public ChatTeam toChatTeam(ScorePlayerTeam team) { public ChatServer toChatServer(MinecraftServer server) { return server != null ? new ForgeChatServer(this, server) : null; } + + public ChatPlayerList toChatPlayerList(PlayerList playerList) { + return playerList != null ? new ForgeChatPlayerList(this, playerList) : null; + } + + public ChatIpBanList toChatIpBanList(IPBanList ipBanList) { + return ipBanList != null ? new ForgeChatIpBanList(this, ipBanList) : null; + } + + public ChatUserBanList toChatUserBanList(BanList userBanList) { + return userBanList != null ? new ForgeChatUserBanList(this, userBanList) : null; + } + + public ChatBanEntry toChatBanEntry(BanEntry banListEntry) { + return banListEntry != null ? new ForgeChatBanEntry<>(this, banListEntry) : null; + } } \ No newline at end of file diff --git a/paper/src/main/java/vakiliner/chatcomponentapi/paper/PaperParser.java b/paper/src/main/java/vakiliner/chatcomponentapi/paper/PaperParser.java index c539fd6..41c5a28 100644 --- a/paper/src/main/java/vakiliner/chatcomponentapi/paper/PaperParser.java +++ b/paper/src/main/java/vakiliner/chatcomponentapi/paper/PaperParser.java @@ -43,11 +43,24 @@ public class PaperParser extends SpigotParser { public void sendMessage(CommandSender sender, ChatComponent component, ChatMessageType type, UUID uuid) { - boolean isConsole = sender instanceof ConsoleCommandSender; - if (uuid != null) { - sender.sendMessage(Identity.identity(uuid), paper(component, isConsole), paper(type)); + this.sendMessage(sender, paper(component, sender instanceof ConsoleCommandSender), paper(type), uuid != null ? Identity.identity(uuid) : null); + } + + private void sendMessage(CommandSender sender, Component component, MessageType type, Identity identity) { + if (identity != null) { + sender.sendMessage(identity, component, type); } else { - sender.sendMessage(paper(component, isConsole), paper(type)); + sender.sendMessage(component, type); + } + } + + public void broadcast(Iterable recipients, ChatComponent chatComponent, ChatMessageType chatMessageType, UUID uuid) { + Component component = paper(chatComponent, false); + Component consoleComponent = paper(chatComponent, true); + MessageType type = paper(chatMessageType); + Identity identity = uuid != null ? Identity.identity(uuid) : null; + for (CommandSender recipient : recipients) { + this.sendMessage(recipient, recipient instanceof ConsoleCommandSender ? consoleComponent : component, type, identity); } } diff --git a/spigot/src/main/java/vakiliner/chatcomponentapi/spigot/SpigotParser.java b/spigot/src/main/java/vakiliner/chatcomponentapi/spigot/SpigotParser.java index a831d90..333f14f 100644 --- a/spigot/src/main/java/vakiliner/chatcomponentapi/spigot/SpigotParser.java +++ b/spigot/src/main/java/vakiliner/chatcomponentapi/spigot/SpigotParser.java @@ -8,6 +8,7 @@ import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; @@ -19,7 +20,6 @@ import net.md_5.bungee.api.chat.hover.content.Item; import net.md_5.bungee.api.chat.hover.content.Text; import vakiliner.chatcomponentapi.common.ChatId; -import vakiliner.chatcomponentapi.common.ChatMessageType; import vakiliner.chatcomponentapi.common.ChatTextColor; import vakiliner.chatcomponentapi.component.ChatClickEvent; import vakiliner.chatcomponentapi.component.ChatComponent; @@ -33,24 +33,36 @@ import vakiliner.chatcomponentapi.craftbukkit.BukkitParser; public class SpigotParser extends BukkitParser { - public void sendMessage(CommandSender sender, ChatComponent component, ChatMessageType type, UUID uuid) { + public void sendMessage(CommandSender sender, ChatComponent component, vakiliner.chatcomponentapi.common.ChatMessageType type, UUID uuid) { + this.sendMessage(sender, spigot(component, sender instanceof ConsoleCommandSender), spigot(type), uuid); + } + + private void sendMessage(CommandSender sender, BaseComponent component, ChatMessageType type, UUID uuid) { if (sender instanceof Player) { Player player = (Player) sender; if (uuid != null) { - player.spigot().sendMessage(spigot(type), uuid, spigot(component)); + player.spigot().sendMessage(type, uuid, component); } else { - player.spigot().sendMessage(spigot(type), spigot(component)); + player.spigot().sendMessage(type, component); } } else { - boolean isConsole = sender instanceof ConsoleCommandSender; if (uuid != null) { - sender.spigot().sendMessage(uuid, spigot(component, isConsole)); + sender.spigot().sendMessage(uuid, component); } else { - sender.spigot().sendMessage(spigot(component, isConsole)); + sender.spigot().sendMessage(component); } } } + public void broadcast(Iterable recipients, ChatComponent chatComponent, vakiliner.chatcomponentapi.common.ChatMessageType chatMessageType, UUID uuid) { + BaseComponent component = spigot(chatComponent, false); + BaseComponent consoleComponent = spigot(chatComponent, true); + ChatMessageType type = spigot(chatMessageType); + for (CommandSender recipient : recipients) { + this.sendMessage(recipient, recipient instanceof ConsoleCommandSender ? consoleComponent : component, type, uuid); + } + } + public static BaseComponent spigot(ChatComponent raw) { return spigot(raw, false); } @@ -178,12 +190,12 @@ public static Object spigotContent2(Content raw) { } } - public static net.md_5.bungee.api.ChatMessageType spigot(ChatMessageType type) { - return type != null ? net.md_5.bungee.api.ChatMessageType.valueOf(type.name()) : null; + public static ChatMessageType spigot(vakiliner.chatcomponentapi.common.ChatMessageType type) { + return type != null ? ChatMessageType.valueOf(type.name()) : null; } - public static ChatMessageType spigot(net.md_5.bungee.api.ChatMessageType type) { - return type != null ? ChatMessageType.valueOf(type.name()) : null; + public static vakiliner.chatcomponentapi.common.ChatMessageType spigot(ChatMessageType type) { + return type != null ? vakiliner.chatcomponentapi.common.ChatMessageType.valueOf(type.name()) : null; } protected static ChatStyle spigotStyle(BaseComponent component) {