Making progress...
This commit is contained in:
parent
578d37c777
commit
4c8f6f024e
4 changed files with 47 additions and 54 deletions
|
@ -2,11 +2,7 @@ package io.github.norbipeti.thebuttonmcchat;
|
||||||
|
|
||||||
import io.github.norbipeti.thebuttonmcchat.commands.UnlolCommand;
|
import io.github.norbipeti.thebuttonmcchat.commands.UnlolCommand;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -22,6 +18,8 @@ import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
|
||||||
public class ChatProcessing {
|
public class ChatProcessing {
|
||||||
|
private static boolean pingedconsole = false;
|
||||||
|
|
||||||
// Returns e.setCancelled
|
// Returns e.setCancelled
|
||||||
public static boolean ProcessChat(CommandSender sender, String message) {
|
public static boolean ProcessChat(CommandSender sender, String message) {
|
||||||
if (PlayerListener.essentials == null)
|
if (PlayerListener.essentials == null)
|
||||||
|
@ -74,7 +72,7 @@ public class ChatProcessing {
|
||||||
colormode = ChatFormatter.Color.Green;
|
colormode = ChatFormatter.Color.Green;
|
||||||
// If greentext, ignore channel or player colors
|
// If greentext, ignore channel or player colors
|
||||||
|
|
||||||
formatters.add(new ChatFormatter(Pattern.compile(".+"), colormode, ""));
|
formatters.add(new ChatFormatter(Pattern.compile("(.+)"), colormode, ""));
|
||||||
|
|
||||||
String formattedmessage = message;
|
String formattedmessage = message;
|
||||||
formattedmessage = formattedmessage.replace("\\", "\\\\");
|
formattedmessage = formattedmessage.replace("\\", "\\\\");
|
||||||
|
@ -97,8 +95,8 @@ public class ChatProcessing {
|
||||||
|
|
||||||
// URLs + Rainbow text
|
// URLs + Rainbow text
|
||||||
formatters.add(new ChatFormatter(Pattern
|
formatters.add(new ChatFormatter(Pattern
|
||||||
.compile("http[\\w:/?=$\\-_.+!*'(),]+"),
|
.compile("(http[\\w:/?=$\\-_.+!*'(),]+)"),
|
||||||
ChatFormatter.Format.Underlined, "", true));
|
ChatFormatter.Format.Underlined, "", "$1"));
|
||||||
// TODO: Only format name mentions outisde open_url
|
// TODO: Only format name mentions outisde open_url
|
||||||
/*
|
/*
|
||||||
* formattedmessage = formattedmessage .replace( item, String.format(
|
* formattedmessage = formattedmessage .replace( item, String.format(
|
||||||
|
@ -193,24 +191,28 @@ public class ChatProcessing {
|
||||||
return true; // TODO
|
return true; // TODO
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
pingedconsole = false;
|
||||||
formatters.add(new ChatFormatter(Pattern.compile("(?i)"
|
formatters.add(new ChatFormatter(Pattern.compile("(?i)"
|
||||||
+ Pattern.quote("@console")), ChatFormatter.Color.Aqua, ""));
|
+ Pattern.quote("@console")), ChatFormatter.Color.Aqua, "", (
|
||||||
|
String match) -> {
|
||||||
if (!hadurls) {
|
if (!pingedconsole) {
|
||||||
|
|
||||||
if (formattedmessage.matches("(?i).*" + Pattern.quote("@console")
|
|
||||||
+ ".*")) {
|
|
||||||
formattedmessage = formattedmessage.replaceAll(
|
|
||||||
"(?i)" + Pattern.quote("@console"), "§b@console§r");
|
|
||||||
formattedmessage = formattedmessage
|
|
||||||
.replaceAll(
|
|
||||||
"(?i)" + Pattern.quote("@console"),
|
|
||||||
String.format(
|
|
||||||
"\",\"color\":\"%s\"},{\"text\":\"§b@console§r\",\"color\":\"blue\"},{\"text\":\"",
|
|
||||||
colormode));
|
|
||||||
System.out.println("\007");
|
System.out.println("\007");
|
||||||
|
pingedconsole = true;
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
|
}));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if (!hadurls) {
|
||||||
|
*
|
||||||
|
* if (formattedmessage.matches("(?i).*" + Pattern.quote("@console") +
|
||||||
|
* ".*")) { formattedmessage = formattedmessage.replaceAll( "(?i)" +
|
||||||
|
* Pattern.quote("@console"), "§b@console§r"); formattedmessage =
|
||||||
|
* formattedmessage .replaceAll( "(?i)" + Pattern.quote("@console"),
|
||||||
|
* String.format(
|
||||||
|
* "\",\"color\":\"%s\"},{\"text\":\"§b@console§r\",\"color\":\"blue\"},{\"text\":\""
|
||||||
|
* , colormode)); System.out.println("\007"); } }
|
||||||
|
*/
|
||||||
|
|
||||||
StringBuilder json = new StringBuilder();
|
StringBuilder json = new StringBuilder();
|
||||||
json.append("[\"\",");
|
json.append("[\"\",");
|
||||||
|
@ -244,35 +246,29 @@ public class ChatProcessing {
|
||||||
: "")));
|
: "")));
|
||||||
json.append("{\"text\":\"> \",\"color\":\"white\"},");
|
json.append("{\"text\":\"> \",\"color\":\"white\"},");
|
||||||
|
|
||||||
formatters.add(new ChatFormatter("#(\w+)", ChatFormatter.Color.Blue, "", "https://twitter.com/hashtag/$1"));
|
formatters
|
||||||
|
.add(new ChatFormatter(Pattern.compile("#(\\w+)"),
|
||||||
/*int index = -1;
|
ChatFormatter.Color.Blue, "",
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
"https://twitter.com/hashtag/$1"));
|
||||||
while ((index = message.indexOf("#", index + 1)) != -1) {
|
|
||||||
int index2 = message.indexOf(" ", index + 1);
|
|
||||||
if (index2 == -1)
|
|
||||||
index2 = message.length();
|
|
||||||
int index3 = message.indexOf("#", index + 1);
|
|
||||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
|
||||||
// space
|
|
||||||
index2 = index3;
|
|
||||||
String original = message.substring(index + 1, index2);
|
|
||||||
list.add(original);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hadurls) {
|
/*
|
||||||
for (String original : list)
|
* int index = -1; ArrayList<String> list = new ArrayList<String>();
|
||||||
// Hashtags
|
* while ((index = message.indexOf("#", index + 1)) != -1) { int index2
|
||||||
formattedmessage = formattedmessage
|
* = message.indexOf(" ", index + 1); if (index2 == -1) index2 =
|
||||||
.replace(
|
* message.length(); int index3 = message.indexOf("#", index + 1); if
|
||||||
"#" + original,
|
* (index3 != -1 && index3 < index2) // A # occurs before a // space
|
||||||
String.format(
|
* index2 = index3; String original = message.substring(index + 1,
|
||||||
"\",\"color\":\"%s\"},{\"text\":\"#%s\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}},{\"text\":\"",
|
* index2); list.add(original); }
|
||||||
colormode, original, original));
|
*
|
||||||
}*/
|
* if (!hadurls) { for (String original : list) // Hashtags
|
||||||
|
* formattedmessage = formattedmessage .replace( "#" + original,
|
||||||
|
* String.format(
|
||||||
|
* "\",\"color\":\"%s\"},{\"text\":\"#%s\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}},{\"text\":\""
|
||||||
|
* , colormode, original, original)); }
|
||||||
|
*/
|
||||||
|
|
||||||
json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]",
|
json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]",
|
||||||
formattedmessage, colormode));
|
ChatFormatter.Combine(formatters, formattedmessage), colormode));
|
||||||
String jsonstr = json.toString();
|
String jsonstr = json.toString();
|
||||||
if (jsonstr.length() >= 32767) {
|
if (jsonstr.length() >= 32767) {
|
||||||
sender.sendMessage("§cError: Message too large. Try shortening it, or remove hashtags and other formatting.");
|
sender.sendMessage("§cError: Message too large. Try shortening it, or remove hashtags and other formatting.");
|
||||||
|
@ -310,7 +306,7 @@ public class ChatProcessing {
|
||||||
player.sendMessage("§cYou aren't in a town or an error occured.");
|
player.sendMessage("§cYou aren't in a town or an error occured.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
index = PluginMain.Instance.Towns.indexOf(town);
|
int index = PluginMain.Instance.Towns.indexOf(town);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
PluginMain.Instance.Towns.add(town);
|
PluginMain.Instance.Towns.add(town);
|
||||||
index = PluginMain.Instance.Towns.size() - 1;
|
index = PluginMain.Instance.Towns.size() - 1;
|
||||||
|
@ -365,7 +361,7 @@ public class ChatProcessing {
|
||||||
player.sendMessage("§cYour town isn't in a nation or an error occured.");
|
player.sendMessage("§cYour town isn't in a nation or an error occured.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
index = PluginMain.Instance.Nations.indexOf(nation);
|
int index = PluginMain.Instance.Nations.indexOf(nation);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
PluginMain.Instance.Nations.add(nation);
|
PluginMain.Instance.Nations.add(nation);
|
||||||
index = PluginMain.Instance.Nations.size() - 1;
|
index = PluginMain.Instance.Nations.size() - 1;
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class MaybeOfflinePlayer {
|
||||||
public boolean SendingLink = false;
|
public boolean SendingLink = false;
|
||||||
public int FDeaths;
|
public int FDeaths;
|
||||||
public boolean RainbowPresserColorMode = false;
|
public boolean RainbowPresserColorMode = false;
|
||||||
public ChatFormatter.Color OtherColorMode = "";
|
public ChatFormatter.Color OtherColorMode = null;
|
||||||
public boolean ChatOnly = false;
|
public boolean ChatOnly = false;
|
||||||
public boolean FlairCheater = false;
|
public boolean FlairCheater = false;
|
||||||
public int LoginWarningCount = 0;
|
public int LoginWarningCount = 0;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package io.github.norbipeti.thebuttonmcchat.commands.ucmds;
|
package io.github.norbipeti.thebuttonmcchat.commands.ucmds;
|
||||||
|
|
||||||
import io.github.norbipeti.thebuttonmcchat.ChatFormatter;
|
import io.github.norbipeti.thebuttonmcchat.ChatFormatter;
|
||||||
import io.github.norbipeti.thebuttonmcchat.ChatFormatter.Color;
|
|
||||||
import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer;
|
import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer;
|
||||||
import io.github.norbipeti.thebuttonmcchat.PluginMain;
|
import io.github.norbipeti.thebuttonmcchat.PluginMain;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package io.github.norbipeti.thebuttonmcchat.commands.ucmds;
|
package io.github.norbipeti.thebuttonmcchat.commands.ucmds;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import io.github.norbipeti.thebuttonmcchat.commands.CommandCaller;
|
import io.github.norbipeti.thebuttonmcchat.commands.CommandCaller;
|
||||||
import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase;
|
import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue