use of com.loohp.interactivechat.objectholders.CooldownResult in project InteractiveChat by LOOHP.
the class ChatEvents method checkCommand.
private void checkCommand(PlayerCommandPreprocessEvent event) {
if (!InteractiveChat.bungeecordMode) {
event.setMessage(Registry.ID_PATTERN.matcher(event.getMessage()).replaceAll(""));
}
boolean flag = true;
String command = event.getMessage();
for (String parsecommand : InteractiveChat.commandList) {
if (command.matches(parsecommand)) {
if (flag) {
translateAltColorCode(event);
command = event.getMessage();
flag = false;
}
CooldownResult cooldownResult = InteractiveChat.placeholderCooldownManager.checkMessage(event.getPlayer().getUniqueId(), command);
if (!cooldownResult.getOutcome().isAllowed()) {
event.setCancelled(true);
Component cancelmessage;
switch(cooldownResult.getOutcome()) {
case DENY_PLACEHOLDER:
cancelmessage = LegacyComponentSerializer.legacySection().deserialize(ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.placeholderCooldownMessage.replace("{Time}", TimeUtils.getReadableTimeBetween(System.currentTimeMillis(), cooldownResult.getCooldownExpireTime())))));
cancelmessage = ComponentReplacing.replace(cancelmessage, "\\{Keyword\\}", Component.text(cooldownResult.getPlaceholder().getName()).hoverEvent(HoverEvent.showText(LegacyComponentSerializer.legacySection().deserialize(cooldownResult.getPlaceholder().getDescription()))));
break;
case DENY_UNIVERSAL:
cancelmessage = LegacyComponentSerializer.legacySection().deserialize(ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.universalCooldownMessage.replace("{Time}", TimeUtils.getReadableTimeBetween(System.currentTimeMillis(), cooldownResult.getCooldownExpireTime())))));
break;
default:
cancelmessage = Component.empty();
break;
}
InteractiveChatAPI.sendMessageUnprocessed(event.getPlayer(), cancelmessage);
return;
}
int count = 0;
for (ICPlaceholder icplaceholder : InteractiveChat.placeholderList.values()) {
Matcher matcher = icplaceholder.getKeyword().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) == '\\')) {
if (icplaceholder.getKeyword().equals(InteractiveChat.itemPlaceholder) && !InteractiveChat.itemAirAllow && PlayerUtils.getHeldItem(event.getPlayer()).getType().equals(Material.AIR) && PlayerUtils.hasPermission(event.getPlayer().getUniqueId(), "interactivechat.module.item", false, 200)) {
event.setCancelled(true);
String cancelmessage = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.itemAirErrorMessage));
event.getPlayer().sendMessage(cancelmessage);
return;
}
Matcher matcher1 = icplaceholder.getKeyword().matcher(command);
while (matcher1.find()) {
int startPos = matcher1.start();
if ((startPos < 1 || command.charAt(startPos - 1) != '\\') || (startPos > 1 && command.charAt(startPos - 1) == '\\' && command.charAt(startPos - 2) == '\\')) {
count++;
}
}
}
}
}
if (InteractiveChat.maxPlaceholders >= 0 && count > InteractiveChat.maxPlaceholders) {
event.setCancelled(true);
String cancelmessage = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.limitReachMessage));
event.getPlayer().sendMessage(cancelmessage);
return;
} else if (count <= 0) {
return;
}
if (InteractiveChat.tagEveryIdentifiableMessage) {
String uuidmatch = " <cmd=" + event.getPlayer().getUniqueId() + ">";
event.setMessage(command + uuidmatch);
break;
} else {
if (!Registry.ID_PATTERN.matcher(command).find()) {
for (ICPlaceholder icplaceholder : InteractiveChat.placeholderList.values()) {
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=" + event.getPlayer().getUniqueId() + ":" + Registry.ID_ESCAPE_PATTERN.matcher(command.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
command = command.substring(0, matcher.start()) + uuidmatch + command.substring(matcher.end());
event.setMessage(command);
break;
}
}
}
break;
}
}
}
}
}
use of com.loohp.interactivechat.objectholders.CooldownResult in project InteractiveChat by LOOHP.
the class ChatEvents method checkChatMessage.
private void checkChatMessage(AsyncPlayerChatEvent event) {
String message = event.getMessage();
Player player = event.getPlayer();
CooldownResult cooldownResult = InteractiveChat.placeholderCooldownManager.checkMessage(event.getPlayer().getUniqueId(), message);
if (!cooldownResult.getOutcome().isAllowed()) {
event.setCancelled(true);
Component cancelmessage;
switch(cooldownResult.getOutcome()) {
case DENY_PLACEHOLDER:
cancelmessage = LegacyComponentSerializer.legacySection().deserialize(ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.placeholderCooldownMessage.replace("{Time}", TimeUtils.getReadableTimeBetween(System.currentTimeMillis(), cooldownResult.getCooldownExpireTime())))));
cancelmessage = ComponentReplacing.replace(cancelmessage, "\\{Keyword\\}", Component.text(cooldownResult.getPlaceholder().getName()).hoverEvent(HoverEvent.showText(LegacyComponentSerializer.legacySection().deserialize(cooldownResult.getPlaceholder().getDescription()))));
break;
case DENY_UNIVERSAL:
cancelmessage = LegacyComponentSerializer.legacySection().deserialize(ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.universalCooldownMessage.replace("{Time}", TimeUtils.getReadableTimeBetween(System.currentTimeMillis(), cooldownResult.getCooldownExpireTime())))));
break;
default:
cancelmessage = Component.empty();
break;
}
InteractiveChatAPI.sendMessageUnprocessed(player, cancelmessage);
return;
}
int count = 0;
for (ICPlaceholder icplaceholder : InteractiveChat.placeholderList.values()) {
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) == '\\')) {
if (icplaceholder.getKeyword().equals(InteractiveChat.itemPlaceholder) && !InteractiveChat.itemAirAllow && PlayerUtils.getHeldItem(event.getPlayer()).getType().equals(Material.AIR) && PlayerUtils.hasPermission(event.getPlayer().getUniqueId(), "interactivechat.module.item", false, 200)) {
event.setCancelled(true);
String cancelmessage = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.itemAirErrorMessage));
event.getPlayer().sendMessage(cancelmessage);
return;
}
Matcher matcher1 = icplaceholder.getKeyword().matcher(message);
while (matcher1.find()) {
int startPos = matcher1.start();
if ((startPos < 1 || message.charAt(startPos - 1) != '\\') || (startPos > 1 && message.charAt(startPos - 1) == '\\' && message.charAt(startPos - 2) == '\\')) {
count++;
}
}
}
}
}
if (InteractiveChat.maxPlaceholders >= 0 && count > InteractiveChat.maxPlaceholders) {
event.setCancelled(true);
String cancelmessage = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.limitReachMessage));
event.getPlayer().sendMessage(cancelmessage);
return;
} else {
if (InteractiveChat.tagEveryIdentifiableMessage) {
String uuidmatch = " <chat=" + event.getPlayer().getUniqueId() + ">";
message = message + uuidmatch;
} else if (count > 0) {
if (InteractiveChat.useAccurateSenderFinder && !message.startsWith("/") && !Registry.ID_PATTERN.matcher(message).find()) {
for (ICPlaceholder icplaceholder : InteractiveChat.placeholderList.values()) {
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=" + event.getPlayer().getUniqueId() + ":" + Registry.ID_ESCAPE_PATTERN.matcher(message.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
message = message.substring(0, matcher.start()) + uuidmatch + message.substring(matcher.end());
break;
}
}
}
}
}
}
event.setMessage(message);
String mapKey = ChatColorUtils.stripColor(ChatColorUtils.translateAlternateColorCodes('&', event.getMessage()));
InteractiveChat.messages.put(mapKey, player.getUniqueId());
Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> InteractiveChat.messages.remove(mapKey), 60);
if (InteractiveChat.bungeecordMode) {
try {
BungeeMessageSender.addMessage(System.currentTimeMillis(), ChatColorUtils.stripColor(ChatColorUtils.translateAlternateColorCodes('&', event.getMessage())), event.getPlayer().getUniqueId());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations