summaryrefslogtreecommitdiff
path: root/src/main/java/com/redstoner/modules/chat
diff options
context:
space:
mode:
authorDavid <david@panic.tk>2018-11-07 23:50:06 +0100
committerDavid <david@panic.tk>2018-11-07 23:50:06 +0100
commit604cf01967ede98bf5024e4926bb0777fc4e8eee (patch)
treee2fa63d7e683769ee3bf3eddc75280648e92eb04 /src/main/java/com/redstoner/modules/chat
parente86c52ef7c0e1e33c6af0e8674b038976bec11cc (diff)
Converted Modules to gradle
Diffstat (limited to 'src/main/java/com/redstoner/modules/chat')
-rw-r--r--src/main/java/com/redstoner/modules/chat/Chat.cmd81
-rw-r--r--src/main/java/com/redstoner/modules/chat/Chat.java215
2 files changed, 296 insertions, 0 deletions
diff --git a/src/main/java/com/redstoner/modules/chat/Chat.cmd b/src/main/java/com/redstoner/modules/chat/Chat.cmd
new file mode 100644
index 0000000..3091609
--- /dev/null
+++ b/src/main/java/com/redstoner/modules/chat/Chat.cmd
@@ -0,0 +1,81 @@
+command me {
+ perm utils.me;
+ [string:text...] {
+ help /me's in chat.;
+ run me text;
+ }
+}
+command action {
+ perm utils.action;
+ [string:text...] {
+ help /action's in chat.;
+ run action text;
+ }
+}
+command chat {
+ alias speak;
+ [string:message...] {
+ perm utils.chat;
+ run chat message;
+ help A way to speak in normal chat with normal formatting if you have ACT or CGT on.;
+ }
+}
+command chatn {
+ alias speakn;
+ [string:name] [string:message...] {
+ perm utils.chatn;
+ run chatn name message;
+ help A way to speak in normal chat with normal formatting for console users.;
+ }
+}
+command shrug {
+ [string:message...] {
+ perm utils.shrug;
+ run shrug message;
+ help Appends the shrug emoticon to the end of your message.;
+ }
+ [empty] {
+ perm utils.shrug;
+ run shrugnoarg;
+ help Just the shrug emoticon.;
+ }
+}
+command say {
+ [string:message...] {
+ perm utils.say;
+ run say message;
+ help A replacement for the default say command to make the format be more consistant.;
+ }
+}
+command sayn {
+ [string:name] [string:message...] {
+ perm utils.sayn;
+ type console;
+ run sayn name message;
+ help A replacement for the default say command to make the format be more consistant.;
+ }
+}
+
+command mute {
+ [string:player] {
+ perm utils.chat.admin;
+ run mute player;
+ help Mutes a player.;
+ }
+}
+
+command print {
+ [string:message...] {
+ perm utils.print;
+ run print message;
+ help A way to just print something in to chat with all the formatting things a user has.;
+ }
+}
+
+command unmute {
+ [string:player] {
+ perm utils.chat.admin;
+ run unmute player;
+ help Unmutes a player.;
+ }
+}
diff --git a/src/main/java/com/redstoner/modules/chat/Chat.java b/src/main/java/com/redstoner/modules/chat/Chat.java
new file mode 100644
index 0000000..1c7f8a1
--- /dev/null
+++ b/src/main/java/com/redstoner/modules/chat/Chat.java
@@ -0,0 +1,215 @@
+package com.redstoner.modules.chat;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+
+import com.nemez.cmdmgr.Command;
+import com.redstoner.annotations.AutoRegisterListener;
+import com.redstoner.annotations.Commands;
+import com.redstoner.annotations.Version;
+import com.redstoner.coremods.moduleLoader.ModuleLoader;
+import com.redstoner.misc.BroadcastFilter;
+import com.redstoner.misc.CommandHolderType;
+import com.redstoner.misc.Utils;
+import com.redstoner.modules.Module;
+import com.redstoner.modules.datamanager.DataManager;
+import com.redstoner.modules.ignore.Ignore;
+
+import net.nemez.chatapi.ChatAPI;
+
+@Commands(CommandHolderType.File)
+@AutoRegisterListener
+@Version(major = 4, minor = 1, revision = 1, compatible = 4)
+public class Chat implements Module, Listener
+{
+ private final Map<String, String> defaults = new HashMap<>();
+
+ public Chat()
+ {
+ defaults.put("chat", " %n §7→§r %m");
+ defaults.put("me", " §7- %n §7⇦ %m");
+ defaults.put("action", " §7- %n §7⇦ %m");
+ defaults.put("say", " §7[§9%n§7]:§r %m");
+ defaults.put("shrug", " %n §7→§r %m ¯\\_(ツ)_/¯");
+ defaults.put("print", "%m");
+ }
+
+ @Override
+ public void firstLoad()
+ {
+ Module.super.firstLoad();
+ DataManager.setConfig("chat", defaults.get("chat"));
+ DataManager.setConfig("me", defaults.get("me"));
+ DataManager.setConfig("action", defaults.get("action"));
+ DataManager.setConfig("say", defaults.get("say"));
+ DataManager.setConfig("shrug", defaults.get("shrug"));
+ DataManager.setConfig("print", defaults.get("print"));
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPlayerChat(AsyncPlayerChatEvent event)
+ {
+ if (event.isCancelled())
+ return;
+ Player player = event.getPlayer();
+ String message = event.getMessage();
+ event.setCancelled(true);
+ broadcastFormatted("chat", player, message, event);
+ }
+
+ @Command(hook = "me")
+ public boolean me(CommandSender sender, String message)
+ {
+ broadcastFormatted("me", sender, message);
+ return true;
+ }
+
+ @Command(hook = "chat")
+ public boolean chat(CommandSender sender, String message)
+ {
+ broadcastFormatted("chat", sender, message);
+ return true;
+ }
+
+ @Command(hook = "chatn")
+ public boolean chatn(CommandSender sender, String name, String message)
+ {
+ broadcastFormatted("chat", sender, message, name);
+ return true;
+ }
+
+ @Command(hook = "action")
+ public boolean action(CommandSender sender, String message)
+ {
+ broadcastFormatted("action", sender, message);
+ return true;
+ }
+
+ @Command(hook = "say")
+ public boolean say(CommandSender sender, String message)
+ {
+ String name;
+ if (sender instanceof Player)
+ name = ((Player) sender).getName();
+ else
+ name = "§9CONSOLE";
+ broadcastFormatted("say", sender, message, name);
+ return true;
+ }
+
+ @Command(hook = "sayn")
+ public boolean say(CommandSender sender, String name, String message)
+ {
+ broadcastFormatted("say", sender, message, name);
+ return true;
+ }
+
+ @Command(hook = "shrug")
+ public boolean shrug(CommandSender sender, String message)
+ {
+ broadcastFormatted("shrug", sender, message);
+ return true;
+ }
+
+ @Command(hook = "shrugnoarg")
+ public boolean shrug(CommandSender sender)
+ {
+ broadcastFormatted("shrug", sender, "");
+ return true;
+ }
+
+ @Command(hook = "print")
+ public boolean print(CommandSender sender, String message)
+ {
+ broadcastFormatted("print", sender, message);
+ return true;
+ }
+
+ @Command(hook = "mute")
+ public boolean mute(CommandSender sender, String player)
+ {
+ Player p = Bukkit.getPlayer(player);
+ if (p == null)
+ {
+ getLogger().message(sender, true, "That player couldn't be found!");
+ return true;
+ }
+ DataManager.setData(p, "muted", true);
+ getLogger().message(sender, "Muted player &e" + Utils.getName(p) + "&7!");
+ getLogger().message(p, "You have been &cmuted&7!");
+ return true;
+ }
+
+ @Command(hook = "unmute")
+ public boolean unmute(CommandSender sender, String player)
+ {
+ Player p = Bukkit.getPlayer(player);
+ if (p == null)
+ {
+ getLogger().message(sender, true, "That player couldn't be found!");
+ return true;
+ }
+ DataManager.setData(p, "muted", false);
+ getLogger().message(sender, "Unmuted player &e" + Utils.getName(p) + "&7!");
+ getLogger().message(p, "You have been &aunmuted&7!");
+ return true;
+ }
+
+ public boolean broadcastFormatted(String format, CommandSender sender, String message)
+ {
+ return broadcastFormatted(format, sender, message, Utils.getName(sender), null);
+ }
+
+ public boolean broadcastFormatted(String format, CommandSender sender, String message, String name)
+ {
+ return broadcastFormatted(format, sender, message, name, null);
+ }
+
+ public boolean broadcastFormatted(String format, CommandSender sender, String message, AsyncPlayerChatEvent event)
+ {
+ return broadcastFormatted(format, sender, message, Utils.getName(sender), event);
+ }
+
+ public boolean broadcastFormatted(String format, CommandSender sender, String message, String name,
+ AsyncPlayerChatEvent event)
+ {
+ if ((boolean) DataManager.getOrDefault(sender, "muted", false))
+ {
+ getLogger().message(sender, true, "You have been muted!");
+ getLogger().info(" &7User &e" + Utils.getName(sender) + " &7tried to &e" + format + " &7(&e" + message
+ + "&7) while being &cmuted&7.");
+ return false;
+ }
+ String raw = (String) DataManager.getConfigOrDefault(format, defaults.get(format));
+ String formatted = raw.replace("%n", name).replace("%m", message);
+ Utils.broadcast("", ChatAPI.colorify(sender, formatted),
+ wrap(ModuleLoader.exists("Ignore") ? Ignore.getIgnoredBy(sender) : null, event));
+ return true;
+ }
+
+ public BroadcastFilter wrap(BroadcastFilter filter, AsyncPlayerChatEvent event)
+ {
+ if (event == null)
+ return filter;
+ else
+ return new BroadcastFilter()
+ {
+ @Override
+ public boolean sendTo(CommandSender recipient)
+ {
+ if (recipient instanceof ConsoleCommandSender)
+ return true;
+ return filter.sendTo(recipient) && event.getRecipients().contains(recipient);
+ }
+ };
+ }
+}