mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-23 10:39:05 +00:00
Update hex color support for message remover.
Does not support 1.7 at this time.
This commit is contained in:
parent
93be4b8b54
commit
719ee85268
@ -138,7 +138,6 @@ ignorechat: false
|
|||||||
# The message shown to players alerting them no one is in the channel to hear them
|
# The message shown to players alerting them no one is in the channel to hear them
|
||||||
emptychannelalert: "&6No one is listening to you."
|
emptychannelalert: "&6No one is listening to you."
|
||||||
|
|
||||||
# Known issue: hex colors do not work here!
|
|
||||||
messageremoverpermissions: '&cYou need additional permissions to view this message!'
|
messageremoverpermissions: '&cYou need additional permissions to view this message!'
|
||||||
messageremovertext: '&c&o<message removed>'
|
messageremovertext: '&c&o<message removed>'
|
||||||
|
|
||||||
@ -205,7 +204,6 @@ venturegui:
|
|||||||
command: '/removemessage {hash} {channel}'
|
command: '/removemessage {hash} {channel}'
|
||||||
slot: 7
|
slot: 7
|
||||||
|
|
||||||
# Known issue: Only one color code is allowed here! More than one will cause an error!
|
|
||||||
guiicon: '&c [✓]'
|
guiicon: '&c [✓]'
|
||||||
guitext: '&cOpen Moderation GUI'
|
guitext: '&cOpen Moderation GUI'
|
||||||
guirows: 1
|
guirows: 1
|
||||||
|
@ -138,7 +138,6 @@ ignorechat: false
|
|||||||
# The message shown to players alerting them no one is in the channel to hear them
|
# The message shown to players alerting them no one is in the channel to hear them
|
||||||
emptychannelalert: "&6No one is listening to you."
|
emptychannelalert: "&6No one is listening to you."
|
||||||
|
|
||||||
# Known issue: hex colors do not work here!
|
|
||||||
messageremoverpermissions: '&cYou need additional permissions to view this message!'
|
messageremoverpermissions: '&cYou need additional permissions to view this message!'
|
||||||
messageremovertext: '&c&o<message removed>'
|
messageremovertext: '&c&o<message removed>'
|
||||||
|
|
||||||
@ -205,7 +204,6 @@ venturegui:
|
|||||||
command: '/removemessage {hash} {channel}'
|
command: '/removemessage {hash} {channel}'
|
||||||
slot: 7
|
slot: 7
|
||||||
|
|
||||||
# Known issue: Only one color code is allowed here! More than one will cause an error!
|
|
||||||
guiicon: '&c [✓]'
|
guiicon: '&c [✓]'
|
||||||
guitext: '&cOpen Moderation GUI'
|
guitext: '&cOpen Moderation GUI'
|
||||||
guirows: 1
|
guirows: 1
|
||||||
|
@ -7,11 +7,13 @@ import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
|||||||
public class ChatMessage {
|
public class ChatMessage {
|
||||||
private WrappedChatComponent component;
|
private WrappedChatComponent component;
|
||||||
private String message;
|
private String message;
|
||||||
|
private String coloredMessage;
|
||||||
private int hash;
|
private int hash;
|
||||||
|
|
||||||
public ChatMessage(WrappedChatComponent component, String message, int hash) {
|
public ChatMessage(WrappedChatComponent component, String message, String coloredMessage, int hash) {
|
||||||
this.component = component;
|
this.component = component;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
this.coloredMessage = coloredMessage;
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +29,10 @@ public class ChatMessage {
|
|||||||
return this.message;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getColoredMessage() {
|
||||||
|
return this.coloredMessage;
|
||||||
|
}
|
||||||
|
|
||||||
public int getHash() {
|
public int getHash() {
|
||||||
return this.hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ import com.comphenix.protocol.events.PacketContainer;
|
|||||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||||
|
|
||||||
public class Removemessage extends MineverseCommand {
|
public class Removemessage extends MineverseCommand {
|
||||||
private PacketContainer emptyLinePacketContainer = Format.createPacketPlayOutChat("{\"extra\":[\" \"],\"text\":\"\"}");
|
|
||||||
private MineverseChat plugin = MineverseChat.getInstance();
|
private MineverseChat plugin = MineverseChat.getInstance();
|
||||||
private WrappedChatComponent messageDeletedComponentPlayer;
|
private PacketContainer emptyLinePacketContainer = Format.createPacketPlayOutChat("{\"extra\":[\" \"],\"text\":\"\"}");
|
||||||
|
private WrappedChatComponent messageDeletedComponentPlayer = WrappedChatComponent.fromJson("{\"text\":\"\",\"extra\":[{\"text\":\"\",\"extra\":[" + Format.convertToJsonColors(Format.FormatStringAll(plugin.getConfig().getString("messageremovertext"))) + "],\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + Format.convertToJsonColors(Format.FormatStringAll(plugin.getConfig().getString("messageremoverpermissions"))) + "]}}}]}");;
|
||||||
|
|
||||||
public Removemessage(String name) {
|
public Removemessage(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
@ -118,17 +118,10 @@ public class Removemessage extends MineverseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WrappedChatComponent getMessageDeletedChatComponentPlayer() {
|
public WrappedChatComponent getMessageDeletedChatComponentPlayer() {
|
||||||
if(this.messageDeletedComponentPlayer == null) {
|
|
||||||
this.messageDeletedComponentPlayer = WrappedChatComponent.fromJson("{\"text\":\"\",\"extra\":[{\"text\":\"" + Format.FormatStringAll(plugin.getConfig().getString("messageremovertext")) + "\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Format.FormatStringAll(plugin.getConfig().getString("messageremoverpermissions")) + "\"}]}}}]}");
|
|
||||||
}
|
|
||||||
return this.messageDeletedComponentPlayer;
|
return this.messageDeletedComponentPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WrappedChatComponent getMessageDeletedChatComponentAdmin(ChatMessage message) {
|
public WrappedChatComponent getMessageDeletedChatComponentAdmin(ChatMessage message) {
|
||||||
String oMessage = message.getComponent().getJson().substring(1, message.getComponent().getJson().length() - 11);
|
return WrappedChatComponent.fromJson("[{\"text\":\"\",\"extra\":[{\"text\":\"\",\"extra\":[" + Format.convertToJsonColors(Format.FormatStringAll(plugin.getConfig().getString("messageremovertext"))) + "],\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\"," + message.getColoredMessage() + "}}}]}]");
|
||||||
if(message.getMessage().contains(ChatColor.stripColor(Format.FormatStringAll(plugin.getConfig().getString("guiicon"))))) {
|
|
||||||
oMessage = oMessage.substring(0, oMessage.length() - ChatColor.stripColor(Format.FormatStringAll(plugin.getConfig().getString("guiicon"))).length() - 3) + "\"}]";
|
|
||||||
}
|
|
||||||
return WrappedChatComponent.fromJson(Format.FormatStringAll("{\"text\":\"\",\"extra\":[{\"text\":\"" + Format.FormatStringAll(plugin.getConfig().getString("messageremovertext")) + "\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"&7Message: \"," + oMessage + "}}}]}"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -65,10 +65,11 @@ public class PacketListener extends PacketAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String message = Format.toPlainText(chat.getHandle(), chat.getHandleType());
|
String message = Format.toPlainText(chat.getHandle(), chat.getHandleType());
|
||||||
|
String coloredMessage = Format.toColoredText(chat.getHandle(), chat.getHandleType());
|
||||||
if(message == null) {
|
if(message == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int hash = message.hashCode();
|
int hash = message.hashCode();
|
||||||
mcp.addMessage(new ChatMessage(chat, message, hash));
|
mcp.addMessage(new ChatMessage(chat, message, coloredMessage, hash));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,6 +14,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
@ -266,7 +267,7 @@ public class Format {
|
|||||||
* @param s
|
* @param s
|
||||||
* @return {@link String}
|
* @return {@link String}
|
||||||
*/
|
*/
|
||||||
private static String convertToJsonColors(String s) {
|
public static String convertToJsonColors(String s) {
|
||||||
return convertToJsonColors(s, "");
|
return convertToJsonColors(s, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -489,6 +490,51 @@ public class Format {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static String toColoredText(Object o, Class<?> c) {
|
||||||
|
if (VersionHandler.is1_7_10()) {
|
||||||
|
return "This method is not currently supported in 1.7";
|
||||||
|
}
|
||||||
|
List<Object> finalList = new ArrayList<>();
|
||||||
|
StringBuilder stringbuilder = new StringBuilder();
|
||||||
|
stringbuilder.append("\"extra\":[");
|
||||||
|
try {
|
||||||
|
splitComponents(finalList, o, c);
|
||||||
|
for (Object component : finalList) {
|
||||||
|
try {
|
||||||
|
String text = (String) component.getClass().getMethod("getText").invoke(component);
|
||||||
|
Object chatModifier = component.getClass().getMethod("getChatModifier").invoke(component);
|
||||||
|
String color = chatModifier.getClass().getMethod("getColor").invoke(chatModifier).toString();
|
||||||
|
boolean bold = (boolean) chatModifier.getClass().getMethod("isBold").invoke(chatModifier);
|
||||||
|
boolean strikethrough = (boolean) chatModifier.getClass().getMethod("isStrikethrough").invoke(chatModifier);
|
||||||
|
boolean italic = (boolean) chatModifier.getClass().getMethod("isItalic").invoke(chatModifier);
|
||||||
|
boolean underlined = (boolean) chatModifier.getClass().getMethod("isUnderlined").invoke(chatModifier);
|
||||||
|
boolean obfuscated = (boolean) chatModifier.getClass().getMethod("isRandom").invoke(chatModifier);
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("text", text);
|
||||||
|
jsonObject.put("color", color);
|
||||||
|
jsonObject.put("bold", bold);
|
||||||
|
jsonObject.put("strikethrough", strikethrough);
|
||||||
|
jsonObject.put("italic", italic);
|
||||||
|
jsonObject.put("underlined", underlined);
|
||||||
|
jsonObject.put("obfuscated", obfuscated);
|
||||||
|
stringbuilder.append(jsonObject.toJSONString() + ",");
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
return "Something went wrong. Could not access color.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
String coloredText = stringbuilder.toString();
|
||||||
|
if(coloredText.endsWith(",")) {
|
||||||
|
coloredText = coloredText.substring(0, coloredText.length() - 1);
|
||||||
|
}
|
||||||
|
coloredText += "]";
|
||||||
|
return coloredText;
|
||||||
|
}
|
||||||
|
|
||||||
public static String toPlainText(Object o, Class<?> c) {
|
public static String toPlainText(Object o, Class<?> c) {
|
||||||
List<Object> finalList = new ArrayList<>();
|
List<Object> finalList = new ArrayList<>();
|
||||||
StringBuilder stringbuilder = new StringBuilder();
|
StringBuilder stringbuilder = new StringBuilder();
|
||||||
@ -516,11 +562,10 @@ public class Format {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void splitComponents(List<Object> finalList, Object o, Class<?> c) throws Exception {
|
private static void splitComponents(List<Object> finalList, Object o, Class<?> c) throws Exception {
|
||||||
// if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
|
||||||
// for(Method m : c.getMethods()) {
|
// for(Method m : c.getMethods()) {
|
||||||
// System.out.println(m.getName());
|
// System.out.println(m.getName());
|
||||||
// }
|
// }
|
||||||
// }
|
|
||||||
if (VersionHandler.is1_7() || VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10()
|
if (VersionHandler.is1_7() || VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10()
|
||||||
|| VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13()
|
|| VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13()
|
||||||
|| (VersionHandler.is1_14() && !VersionHandler.is1_14_4())) {
|
|| (VersionHandler.is1_14() && !VersionHandler.is1_14_4())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user