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;
|
package com.redstoner.modules.chat;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -7,6 +8,7 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -29,7 +31,6 @@ import com.redstoner.modules.datamanager.DataManager;
|
|||||||
import com.redstoner.modules.ignore.Ignore;
|
import com.redstoner.modules.ignore.Ignore;
|
||||||
|
|
||||||
import net.nemez.chatapi.ChatAPI;
|
import net.nemez.chatapi.ChatAPI;
|
||||||
import net.nemez.chatapi.click.Message;
|
|
||||||
|
|
||||||
@Commands(CommandHolderType.File)
|
@Commands(CommandHolderType.File)
|
||||||
@AutoRegisterListener
|
@AutoRegisterListener
|
||||||
@@ -46,7 +47,6 @@ public class Chat implements Module, Listener {
|
|||||||
defaults.put("shrug", " %n %c§7→§r %m ¯\\_(ツ)_/¯");
|
defaults.put("shrug", " %n %c§7→§r %m ¯\\_(ツ)_/¯");
|
||||||
defaults.put("print", "%m");
|
defaults.put("print", "%m");
|
||||||
defaults.put("%c", "§c*");
|
defaults.put("%c", "§c*");
|
||||||
defaults.put("%c-hover", "§cChat Only");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -203,27 +203,42 @@ public class Chat implements Module, Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String raw = (String) DataManager.getConfigOrDefault(format, defaults.get(format));
|
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);
|
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")));
|
||||||
|
|
||||||
String part1 = formatted.substring(0, formatted.indexOf("%c"));
|
if (ModuleLoader.exists("Mentio")) {
|
||||||
String part2 = formatted.substring(formatted.indexOf("%c") + 2);
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
String indicatior = (String) DataManager.getConfigOrDefault("%c", defaults.get("%c"));
|
if (filter.sendTo(player)) {
|
||||||
String indicatiorHover = (String) DataManager.getConfigOrDefault("%c-hover", defaults.get("%c-hover"));
|
ChatAPI.createMessage(player, sender).appendText(getMentioMessage(sender, player, formatted, message)).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Utils.broadcast("", ChatAPI.colorify(sender, formatted.replace("%m", message)), filter);
|
||||||
|
|
||||||
Message msg = ChatAPI.createMessage(null)
|
|
||||||
.appendText(part1)
|
|
||||||
.appendTextHover(indicatior, indicatiorHover)
|
|
||||||
.appendText(part2);
|
|
||||||
Utils.broadcast("", msg, filter);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.broadcast("", ChatAPI.colorify(sender, formatted.replace("%c", "")), filter);
|
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);
|
||||||
|
|
||||||
return 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) {
|
public BroadcastFilter wrap(BroadcastFilter filter, AsyncPlayerChatEvent event) {
|
||||||
|
|||||||
@@ -3,16 +3,10 @@ package com.redstoner.modules.mentio;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
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.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
@@ -20,14 +14,12 @@ import com.nemez.cmdmgr.Command;
|
|||||||
import com.redstoner.annotations.AutoRegisterListener;
|
import com.redstoner.annotations.AutoRegisterListener;
|
||||||
import com.redstoner.annotations.Commands;
|
import com.redstoner.annotations.Commands;
|
||||||
import com.redstoner.annotations.Version;
|
import com.redstoner.annotations.Version;
|
||||||
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
|
||||||
import com.redstoner.misc.CommandHolderType;
|
import com.redstoner.misc.CommandHolderType;
|
||||||
import com.redstoner.misc.JsonManager;
|
import com.redstoner.misc.JsonManager;
|
||||||
import com.redstoner.misc.Main;
|
import com.redstoner.misc.Main;
|
||||||
import com.redstoner.modules.Module;
|
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)
|
@Commands(CommandHolderType.File)
|
||||||
@AutoRegisterListener
|
@AutoRegisterListener
|
||||||
@@ -36,10 +28,12 @@ public class Mentio implements Module, Listener
|
|||||||
{
|
{
|
||||||
private File mentioLocation = new File(Main.plugin.getDataFolder(), "mentio.json");
|
private File mentioLocation = new File(Main.plugin.getDataFolder(), "mentio.json");
|
||||||
private JSONObject mentios;
|
private JSONObject mentios;
|
||||||
|
public static Mentio instance;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onEnable()
|
public boolean onEnable()
|
||||||
{
|
{
|
||||||
|
instance = this;
|
||||||
loadMentios();
|
loadMentios();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -120,44 +114,38 @@ public class Mentio implements Module, Listener
|
|||||||
return mentios;
|
return mentios;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
public String motifyMessageWithMentio(CommandSender permholder, Player player, String message)
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
{
|
||||||
if (event.isCancelled())
|
|
||||||
return;
|
|
||||||
for (Player player : event.getRecipients())
|
|
||||||
{
|
|
||||||
if (ModuleLoader.exists("Ignore") ? !Ignore.getIgnoredBy(event.getPlayer()).sendTo(player) : false)
|
|
||||||
return;
|
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString());
|
JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString());
|
||||||
playerMentios = defaultMentio(playerMentios, player);
|
playerMentios = defaultMentio(playerMentios, player);
|
||||||
|
|
||||||
for (Object raw : playerMentios)
|
for (Object raw : playerMentios)
|
||||||
{
|
{
|
||||||
String mentio = (String) raw;
|
String mentio = (String) raw;
|
||||||
if (event.getMessage().toLowerCase().contains(mentio.toLowerCase()))
|
|
||||||
|
String messageLC = message.toLowerCase();
|
||||||
|
String mentioLC = mentio.toLowerCase();
|
||||||
|
if (messageLC.contains(mentioLC))
|
||||||
{
|
{
|
||||||
event.getRecipients().remove(player);
|
char color = 'r';
|
||||||
String temp = event.getMessage().replaceAll("(?i)" + Pattern.quote(mentio) + ".*", "");
|
int index = messageLC.indexOf(mentioLC);
|
||||||
String lastColorCodes = "§r";
|
for (int i = index; i > 0; i--) {
|
||||||
char lastChar = ' ';
|
char next = messageLC.charAt(i-1);
|
||||||
for (char c : temp.toCharArray())
|
char cur = messageLC.charAt(i);
|
||||||
{
|
if((next == '§' || next == '&') && ("" + cur).matches("[a-f0-9r]")) {
|
||||||
if (lastChar == ChatColor.COLOR_CHAR)
|
color = cur;
|
||||||
lastColorCodes += "§" + c;
|
break;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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()
|
private void loadMentios()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user