use of com.loohp.interactivechat.objectholders.ICPlaceholder in project InteractiveChat by LOOHP.
the class InteractiveChatBungee method onBungeeChat.
@EventHandler(priority = EventPriority.HIGH)
public void onBungeeChat(ChatEvent event) {
if (event.isCancelled()) {
return;
}
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
UUID uuid = player.getUniqueId();
String message = event.getMessage();
String newMessage = event.getMessage();
boolean hasInteractiveChat = false;
Server server = player.getServer();
if (server != null) {
BackendInteractiveChatData data = serverInteractiveChatInfo.get(server.getInfo().getName());
if (data != null) {
hasInteractiveChat = data.hasInteractiveChat();
}
}
boolean usage = false;
outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
for (ICPlaceholder icplaceholder : serverPlaceholders) {
Matcher matcher = icplaceholder.getKeyword().matcher(message);
if (matcher.find()) {
int start = matcher.start();
if ((start < 1 || message.charAt(start - 1) != '\\') || (start > 1 && message.charAt(start - 1) == '\\' && message.charAt(start - 2) == '\\')) {
usage = true;
break outer;
}
}
}
}
if (newMessage.startsWith("/")) {
if (usage && hasInteractiveChat) {
for (String parsecommand : InteractiveChatBungee.parseCommands) {
if (newMessage.matches(parsecommand)) {
String command = newMessage.trim();
outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
for (ICPlaceholder icplaceholder : serverPlaceholders) {
Pattern placeholder = icplaceholder.getKeyword();
Matcher matcher = placeholder.matcher(command);
if (matcher.find()) {
int start = matcher.start();
if ((start < 1 || command.charAt(start - 1) != '\\') || (start > 1 && command.charAt(start - 1) == '\\' && command.charAt(start - 2) == '\\')) {
String uuidmatch = "<cmd=" + uuid + ":" + Registry.ID_ESCAPE_PATTERN.matcher(command.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
command = command.substring(0, matcher.start()) + uuidmatch + command.substring(matcher.end());
if (command.length() > 256) {
command = command.substring(0, 256);
}
event.setMessage(command);
break outer;
}
}
}
}
break;
}
}
}
} else {
if (usage && InteractiveChatBungee.useAccurateSenderFinder && hasInteractiveChat) {
outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
for (ICPlaceholder icplaceholder : serverPlaceholders) {
Pattern placeholder = icplaceholder.getKeyword();
Matcher matcher = placeholder.matcher(message);
if (matcher.find()) {
int start = matcher.start();
if ((start < 1 || message.charAt(start - 1) != '\\') || (start > 1 && message.charAt(start - 1) == '\\' && message.charAt(start - 2) == '\\')) {
String uuidmatch = "<chat=" + uuid + ":" + Registry.ID_ESCAPE_PATTERN.matcher(message.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
message = message.substring(0, matcher.start()) + uuidmatch + message.substring(matcher.end());
if (message.length() > 256) {
message = message.substring(0, 256);
}
event.setMessage(message);
break outer;
}
}
}
}
}
ProxyServer.getInstance().getScheduler().schedule(plugin, () -> {
Map<String, Long> messages = forwardedMessages.get(uuid);
if (messages != null && messages.remove(newMessage) != null) {
try {
PluginMessageSendingBungee.sendMessagePair(uuid, newMessage);
} catch (IOException e) {
e.printStackTrace();
}
}
}, 100, TimeUnit.MILLISECONDS);
}
}
Aggregations