Made chat and all chat commands use the Mentio Module
*Mentio now no longer handles chat. *ChatOnly indicator no longer has a hover text describing it.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.redstoner.modules.chat;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -7,6 +8,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -29,7 +31,6 @@ import com.redstoner.modules.datamanager.DataManager;
|
||||
import com.redstoner.modules.ignore.Ignore;
|
||||
|
||||
import net.nemez.chatapi.ChatAPI;
|
||||
import net.nemez.chatapi.click.Message;
|
||||
|
||||
@Commands(CommandHolderType.File)
|
||||
@AutoRegisterListener
|
||||
@@ -46,7 +47,6 @@ public class Chat implements Module, Listener {
|
||||
defaults.put("shrug", " %n %c§7→§r %m ¯\\_(ツ)_/¯");
|
||||
defaults.put("print", "%m");
|
||||
defaults.put("%c", "§c*");
|
||||
defaults.put("%c-hover", "§cChat Only");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,28 +203,43 @@ public class Chat implements Module, Listener {
|
||||
}
|
||||
|
||||
String raw = (String) DataManager.getConfigOrDefault(format, defaults.get(format));
|
||||
String formatted = raw.replace("%n", name).replace("%m", message);
|
||||
String formatted = raw.replace("%n", name);
|
||||
BroadcastFilter filter = wrap(ModuleLoader.exists("Ignore") ? Ignore.getIgnoredBy(sender) : null, event);
|
||||
|
||||
if (isChatOnly) {
|
||||
formatted = !isChatOnly? formatted.replaceAll("%c", "") : formatted.replace("%c", (String) DataManager.getConfigOrDefault("%c", defaults.get("%c")));
|
||||
|
||||
if (ModuleLoader.exists("Mentio")) {
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
if (filter.sendTo(player)) {
|
||||
ChatAPI.createMessage(player, sender).appendText(getMentioMessage(sender, player, formatted, message)).send();
|
||||
}
|
||||
|
||||
String part1 = formatted.substring(0, formatted.indexOf("%c"));
|
||||
String part2 = formatted.substring(formatted.indexOf("%c") + 2);
|
||||
String indicatior = (String) DataManager.getConfigOrDefault("%c", defaults.get("%c"));
|
||||
String indicatiorHover = (String) DataManager.getConfigOrDefault("%c-hover", defaults.get("%c-hover"));
|
||||
|
||||
Message msg = ChatAPI.createMessage(null)
|
||||
.appendText(part1)
|
||||
.appendTextHover(indicatior, indicatiorHover)
|
||||
.appendText(part2);
|
||||
Utils.broadcast("", msg, filter);
|
||||
return true;
|
||||
}
|
||||
|
||||
Utils.broadcast("", ChatAPI.colorify(sender, formatted.replace("%c", "")), filter);
|
||||
|
||||
else
|
||||
Utils.broadcast("", ChatAPI.colorify(sender, formatted.replace("%m", message)), filter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getMentioMessage(CommandSender sender, Player player, String format, String message) {
|
||||
try {
|
||||
Module mod = ModuleLoader.getModule("Mentio");
|
||||
Method m = mod.getClass().getDeclaredMethod("motifyMessageWithMentio", CommandSender.class, Player.class, String.class);
|
||||
m.setAccessible(true);
|
||||
|
||||
String msg = (String) m.invoke(mod, sender, player, message);
|
||||
|
||||
if (msg != null) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
|
||||
return format.replace("%m", msg);
|
||||
}
|
||||
else
|
||||
return format.replace("%m", message);
|
||||
|
||||
} catch (Exception e) {
|
||||
return format.replace("%m", message);
|
||||
}
|
||||
}
|
||||
|
||||
public BroadcastFilter wrap(BroadcastFilter filter, AsyncPlayerChatEvent event) {
|
||||
if (event == null) return filter;
|
||||
|
||||
@@ -3,16 +3,10 @@ package com.redstoner.modules.mentio;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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 org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -20,14 +14,12 @@ 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.CommandHolderType;
|
||||
import com.redstoner.misc.JsonManager;
|
||||
import com.redstoner.misc.Main;
|
||||
import com.redstoner.modules.Module;
|
||||
import com.redstoner.modules.ignore.Ignore;
|
||||
|
||||
import net.nemez.chatapi.click.Message;
|
||||
import net.nemez.chatapi.ChatAPI;
|
||||
|
||||
@Commands(CommandHolderType.File)
|
||||
@AutoRegisterListener
|
||||
@@ -36,10 +28,12 @@ public class Mentio implements Module, Listener
|
||||
{
|
||||
private File mentioLocation = new File(Main.plugin.getDataFolder(), "mentio.json");
|
||||
private JSONObject mentios;
|
||||
public static Mentio instance;
|
||||
|
||||
@Override
|
||||
public boolean onEnable()
|
||||
{
|
||||
instance = this;
|
||||
loadMentios();
|
||||
return true;
|
||||
}
|
||||
@@ -120,43 +114,37 @@ public class Mentio implements Module, Listener
|
||||
return mentios;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
public String motifyMessageWithMentio(CommandSender permholder, Player player, String message)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
for (Player player : event.getRecipients())
|
||||
UUID uuid = player.getUniqueId();
|
||||
JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString());
|
||||
playerMentios = defaultMentio(playerMentios, player);
|
||||
|
||||
for (Object raw : playerMentios)
|
||||
{
|
||||
if (ModuleLoader.exists("Ignore") ? !Ignore.getIgnoredBy(event.getPlayer()).sendTo(player) : false)
|
||||
return;
|
||||
UUID uuid = player.getUniqueId();
|
||||
JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString());
|
||||
playerMentios = defaultMentio(playerMentios, player);
|
||||
for (Object raw : playerMentios)
|
||||
{
|
||||
String mentio = (String) raw;
|
||||
if (event.getMessage().toLowerCase().contains(mentio.toLowerCase()))
|
||||
{
|
||||
event.getRecipients().remove(player);
|
||||
String temp = event.getMessage().replaceAll("(?i)" + Pattern.quote(mentio) + ".*", "");
|
||||
String lastColorCodes = "§r";
|
||||
char lastChar = ' ';
|
||||
for (char c : temp.toCharArray())
|
||||
{
|
||||
if (lastChar == ChatColor.COLOR_CHAR)
|
||||
lastColorCodes += "§" + c;
|
||||
lastChar = c;
|
||||
}
|
||||
Message m = new Message(player, event.getPlayer());
|
||||
m.appendText(event.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s",
|
||||
event.getMessage().replaceFirst("(?i)(" + Pattern.quote(mentio) + ")([^ ]*)",
|
||||
"§a§o$1$2" + lastColorCodes)));
|
||||
m.send();
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
|
||||
return;
|
||||
String mentio = (String) raw;
|
||||
|
||||
String messageLC = message.toLowerCase();
|
||||
String mentioLC = mentio.toLowerCase();
|
||||
if (messageLC.contains(mentioLC))
|
||||
{
|
||||
char color = 'r';
|
||||
int index = messageLC.indexOf(mentioLC);
|
||||
for (int i = index; i > 0; i--) {
|
||||
char next = messageLC.charAt(i-1);
|
||||
char cur = messageLC.charAt(i);
|
||||
if((next == '§' || next == '&') && ("" + cur).matches("[a-f0-9r]")) {
|
||||
color = cur;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ChatAPI.colorify(permholder, message.substring(0, index)
|
||||
+ "§a§o" + message.substring(index, index + mentio.length()) + "§r" + (permholder.hasPermission(ChatAPI.PERMISSION_CHAT_COLOR)? "&" + color : ""))
|
||||
+ message.substring(index + mentio.length());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private void loadMentios()
|
||||
|
||||
Reference in New Issue
Block a user