diff --git a/api/src/main/java/com/alttd/chat/objects/ChatUser.java b/api/src/main/java/com/alttd/chat/objects/ChatUser.java index e76c4ff..fce0860 100755 --- a/api/src/main/java/com/alttd/chat/objects/ChatUser.java +++ b/api/src/main/java/com/alttd/chat/objects/ChatUser.java @@ -26,6 +26,7 @@ public class ChatUser { private List mails; // mails aren't finalized yet, so for now a table sender, reciever, sendtime, readtime(if emtpy mail isn't read yet?, could also do a byte to control this), the actual message private List ignoredPlayers; // a list of UUID, a new table non unique, where one is is the player select * from ignores where ignoredby = thisplayer? where the result is the uuid of the player ignored by this player? private List ignoredBy; // a list of UUID, same table as above but select * from ignores where ignored = thisplayer? result should be the other user that ignored this player? + private boolean isMuted; public ChatUser(UUID uuid, int partyId, Channel toggledChannel) { this.uuid = uuid; @@ -49,6 +50,7 @@ public class ChatUser { ignoredPlayers = Queries.getIgnoredUsers(uuid); ignoredBy = new ArrayList<>(); // todo load ignoredPlayers spy = true; + isMuted = false; // TODO load from db } public UUID getUuid() { @@ -146,4 +148,13 @@ public class ChatUser { public void toggleSpy() { this.spy = !spy; } + + public boolean isMuted() { + return isMuted; + } + + public void setMuted(boolean muted) { + this.isMuted = muted; + } + } diff --git a/galaxy/build.gradle.kts b/galaxy/build.gradle.kts index 2dbbb06..249b56e 100644 --- a/galaxy/build.gradle.kts +++ b/galaxy/build.gradle.kts @@ -6,7 +6,7 @@ plugins { dependencies { implementation(project(":api")) // API compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT") // Galaxy - compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") + compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy } tasks { diff --git a/galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java b/galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java index 4d1c18b..9953146 100755 --- a/galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java +++ b/galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java @@ -4,20 +4,18 @@ import com.alttd.chat.ChatPlugin; import com.alttd.chat.config.Config; import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.RegexManager; -import com.alttd.chat.objects.channels.CustomChannel; import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.Party; +import com.alttd.chat.objects.channels.CustomChannel; import com.alttd.chat.util.GalaxyUtility; import com.alttd.chat.util.Utility; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; -import litebans.api.Database; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -254,7 +252,10 @@ public class ChatHandler { // Start - move these to util private boolean isMuted(Player player, String message, String prefix) { - if (Database.get().isPlayerMuted(player.getUniqueId(), null) || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) { + ChatUser user = ChatUserManager.getChatUser(player.getUniqueId()); + if (user == null) return false; + if (user.isMuted() || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) { +// if (Database.get().isPlayerMuted(player.getUniqueId(), null) || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) { GalaxyUtility.sendBlockedNotification(prefix, player, message, ""); return true; } diff --git a/galaxy/src/main/java/com/alttd/chat/listeners/PluginMessage.java b/galaxy/src/main/java/com/alttd/chat/listeners/PluginMessage.java index 39f7b9c..5c11968 100755 --- a/galaxy/src/main/java/com/alttd/chat/listeners/PluginMessage.java +++ b/galaxy/src/main/java/com/alttd/chat/listeners/PluginMessage.java @@ -162,6 +162,13 @@ public class PluginMessage implements PluginMessageListener { case "reloadconfig": ChatPlugin.getInstance().ReloadConfig(); break; + case "chatpunishments": + UUID uuid = UUID.fromString(in.readUTF()); + boolean mute = in.readBoolean(); + ChatUser user = ChatUserManager.getChatUser(uuid); + if (user == null) return; + user.setMuted(mute); + break; default: break; } diff --git a/velocity/build.gradle.kts b/velocity/build.gradle.kts index 1978bef..36c8110 100644 --- a/velocity/build.gradle.kts +++ b/velocity/build.gradle.kts @@ -13,6 +13,7 @@ dependencies { exclude("net.kyori") exclude("net.kyori.examination") } + compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") } tasks { diff --git a/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java b/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java index f546334..169b9d9 100755 --- a/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java +++ b/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java @@ -9,6 +9,7 @@ import com.alttd.chat.database.DatabaseConnection; import com.alttd.velocitychat.handlers.ChatHandler; import com.alttd.velocitychat.handlers.ServerHandler; import com.alttd.velocitychat.listeners.ChatListener; +import com.alttd.velocitychat.listeners.LiteBansListener; import com.alttd.velocitychat.listeners.ProxyPlayerListener; import com.alttd.velocitychat.listeners.PluginMessageListener; import com.alttd.chat.util.ALogger; @@ -31,7 +32,7 @@ import java.nio.file.Path; @Plugin(id = "chatplugin", name = "ChatPlugin", version = "1.0.0", description = "A chat plugin for Altitude Minecraft Server", authors = {"destro174", "teri"}, - dependencies = {@Dependency(id = "luckperms")} + dependencies = {@Dependency(id = "luckperms"), @Dependency(id = "litebans")} ) public class VelocityChat { @@ -65,6 +66,7 @@ public class VelocityChat { chatHandler = new ChatHandler(); server.getEventManager().register(this, new ChatListener()); server.getEventManager().register(this, new ProxyPlayerListener()); + new LiteBansListener().init(); // init the litebans api listeners String[] channels = Config.MESSAGECHANNEL.split(":");// todo add a check for this? channelIdentifier = MinecraftChannelIdentifier.create(channels[0], channels[1]); server.getChannelRegistrar().register(channelIdentifier); diff --git a/velocity/src/main/java/com/alttd/velocitychat/handlers/ChatHandler.java b/velocity/src/main/java/com/alttd/velocitychat/handlers/ChatHandler.java index 2a7f43c..2b91aac 100755 --- a/velocity/src/main/java/com/alttd/velocitychat/handlers/ChatHandler.java +++ b/velocity/src/main/java/com/alttd/velocitychat/handlers/ChatHandler.java @@ -156,4 +156,11 @@ public class ChatHandler { .filter(p -> !ignoredPlayers.contains(p.getUniqueId())) .forEach(p -> p.sendMessage(message)); } + + public void mutePlayer(String uuid, boolean muted) { + ByteArrayDataOutput buf = ByteStreams.newDataOutput(); + buf.writeUTF("chatpunishments"); + buf.writeUTF(uuid); + buf.writeBoolean(muted); + } } \ No newline at end of file diff --git a/velocity/src/main/java/com/alttd/velocitychat/listeners/LiteBansListener.java b/velocity/src/main/java/com/alttd/velocitychat/listeners/LiteBansListener.java new file mode 100644 index 0000000..798ec21 --- /dev/null +++ b/velocity/src/main/java/com/alttd/velocitychat/listeners/LiteBansListener.java @@ -0,0 +1,28 @@ +package com.alttd.velocitychat.listeners; + +import com.alttd.velocitychat.VelocityChat; +import litebans.api.Entry; +import litebans.api.Events; + +public class LiteBansListener extends Events.Listener { + + public void init() { + Events.get().register(this); + } + + @Override + public void entryAdded(Entry entry) { + if (!entry.getType().equals("mute")) return; + String uuid = entry.getUuid(); + if (uuid == null) return; // sanity check + VelocityChat.getPlugin().getChatHandler().mutePlayer(uuid, entry.isActive()); + } + + @Override + public void entryRemoved(Entry entry) { + if (!entry.getType().equals("mute")) return; + String uuid = entry.getUuid(); + if (uuid == null) return; // sanity check + VelocityChat.getPlugin().getChatHandler().mutePlayer(uuid, entry.isActive()); + } +} diff --git a/velocity/src/main/java/com/alttd/velocitychat/listeners/ProxyPlayerListener.java b/velocity/src/main/java/com/alttd/velocitychat/listeners/ProxyPlayerListener.java index b15f4cb..136f04e 100755 --- a/velocity/src/main/java/com/alttd/velocitychat/listeners/ProxyPlayerListener.java +++ b/velocity/src/main/java/com/alttd/velocitychat/listeners/ProxyPlayerListener.java @@ -15,6 +15,7 @@ import com.velocitypowered.api.event.connection.LoginEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; +import litebans.api.Events; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; @@ -102,4 +103,5 @@ public class ProxyPlayerListener { } } } + }