Skip to content

Commit

Permalink
2.2.5 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed May 27, 2020
1 parent c0cb4fd commit e5b3c9f
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 96 deletions.
11 changes: 6 additions & 5 deletions src/com/loohp/interactivechat/API/InteractiveChatAPI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.loohp.interactivechat.API;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
Expand Down Expand Up @@ -29,7 +30,7 @@ public static void setPlayerMentionCooldown(Player player, long time) {
InteractiveChat.mentionCooldown.put(player, time);
}

public static HashMap<Player, Long> getMentionCooldownMap() {
public static Map<Player, Long> getMentionCooldownMap() {
return InteractiveChat.mentionCooldown;
}

Expand All @@ -44,7 +45,7 @@ public static long getPlayerPlaceholderCooldown(Player player, String placeholde

public static void setPlayerPlaceholderCooldown(Player player, String placeholder, long time) {
if (!InteractiveChat.placeholderCooldowns.containsKey(player)) {
InteractiveChat.placeholderCooldowns.put(player, new HashMap<String, Long>());
InteractiveChat.placeholderCooldowns.put(player, new ConcurrentHashMap<String, Long>());
}
InteractiveChat.placeholderCooldowns.get(player).put(placeholder, time);
}
Expand Down Expand Up @@ -81,11 +82,11 @@ public static boolean isPlaceholderOnCooldown(Player player, String placeholder,
return false;
}

public static HashMap<Long, Inventory> getInventoryShareList() {
public static Map<Long, Inventory> getInventoryShareList() {
return InteractiveChat.inventoryDisplay;
}

public static HashMap<Long, Inventory> getEnderShareList() {
public static Map<Long, Inventory> getEnderShareList() {
return InteractiveChat.enderDisplay;
}
}
1 change: 1 addition & 0 deletions src/com/loohp/interactivechat/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,6 @@ public static void loadConfig() {
InteractiveChat.mentionDuration = getConfig().getLong("Chat.MentionedTitleDuration");

InteractiveChat.UpdaterEnabled = InteractiveChat.plugin.getConfig().getBoolean("Options.Updater");
InteractiveChat.cancelledMessage = InteractiveChat.plugin.getConfig().getBoolean("Options.ShowCancelledNotice");
}
}
28 changes: 14 additions & 14 deletions src/com/loohp/interactivechat/InteractiveChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -95,39 +94,40 @@ public class InteractiveChat extends JavaPlugin {
public static String InvExpired = "&cThis inventory view has expired!";
public static String ReloadPlugin = "&aInteractive Chat has been reloaded!";

public static HashMap<String, UUID> messages = new HashMap<String, UUID>();
public static HashMap<String, Long> keyTime = new HashMap<String, Long>();
public static HashMap<String, Player> keyPlayer = new HashMap<String, Player>();
public static ConcurrentHashMap<String, UUID> messages = new ConcurrentHashMap<String, UUID>();
public static ConcurrentHashMap<String, Long> keyTime = new ConcurrentHashMap<String, Long>();
public static ConcurrentHashMap<String, Player> keyPlayer = new ConcurrentHashMap<String, Player>();

public static HashMap<Long, HashSet<String>> cooldownbypass = new HashMap<Long, HashSet<String>>();
public static ConcurrentHashMap<Long, HashSet<String>> cooldownbypass = new ConcurrentHashMap<Long, HashSet<String>>();

public static HashMap<Long, Inventory> itemDisplay = new HashMap<Long, Inventory>();
public static HashMap<Long, Inventory> inventoryDisplay = new HashMap<Long, Inventory>();
public static HashMap<Long, Inventory> enderDisplay = new HashMap<Long, Inventory>();
public static ConcurrentHashMap<Long, Inventory> itemDisplay = new ConcurrentHashMap<Long, Inventory>();
public static ConcurrentHashMap<Long, Inventory> inventoryDisplay = new ConcurrentHashMap<Long, Inventory>();
public static ConcurrentHashMap<Long, Inventory> enderDisplay = new ConcurrentHashMap<Long, Inventory>();

public static HashMap<Player, HashMap<String, Long>> placeholderCooldowns = new HashMap<Player, HashMap<String, Long>>();
public static HashMap<Player, Long> universalCooldowns = new HashMap<Player, Long>();
public static ConcurrentHashMap<Player, ConcurrentHashMap<String, Long>> placeholderCooldowns = new ConcurrentHashMap<Player, ConcurrentHashMap<String, Long>>();
public static ConcurrentHashMap<Player, Long> universalCooldowns = new ConcurrentHashMap<Player, Long>();

public static List<String> placeholderList = new ArrayList<String>();
public static int maxPlacholders = -1;
public static String limitReachMessage = "&cPlease do now use excessive amount of placeholders in one message!";

public static HashMap<Player, Long> mentionCooldown = new HashMap<Player, Long>();
public static HashMap<UUID, MentionPair> mentionPair = new HashMap<UUID, MentionPair>();
public static ConcurrentHashMap<Player, Long> mentionCooldown = new ConcurrentHashMap<Player, Long>();
public static ConcurrentHashMap<UUID, MentionPair> mentionPair = new ConcurrentHashMap<UUID, MentionPair>();
public static String mentionHightlight = "&e{MentionedPlayer}";
public static String mentionHover = "&e{MentionedPlayer}";
public static long mentionDuration = 2;

public static List<String> commandList = new ArrayList<String>();
public static HashMap<String, CommandPlaceholderInfo> commandPlaceholderMatch = new HashMap<String, CommandPlaceholderInfo>();
public static ConcurrentHashMap<String, CommandPlaceholderInfo> commandPlaceholderMatch = new ConcurrentHashMap<String, CommandPlaceholderInfo>();

public static ConcurrentHashMap<Player, String> essenNick = new ConcurrentHashMap<Player, String>();

public static boolean FilterUselessColorCodes = true;

public static HashMap<String, String> aliasesMapping = new HashMap<String, String>();
public static ConcurrentHashMap<String, String> aliasesMapping = new ConcurrentHashMap<String, String>();

public static boolean UpdaterEnabled = true;
public static boolean cancelledMessage = true;

@Override
public void onEnable() {
Expand Down
50 changes: 32 additions & 18 deletions src/com/loohp/interactivechat/Listeners/ChatPackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.loohp.interactivechat.Modules.ProcessCommands;
import com.loohp.interactivechat.Modules.SenderFinder;
import com.loohp.interactivechat.ObjectHolders.ProcessCommandsReturn;
import com.loohp.interactivechat.Utils.ChatColorFilter;
import com.loohp.interactivechat.Utils.ChatComponentUtils;
import com.loohp.interactivechat.Utils.JsonUtils;
import com.loohp.interactivechat.Utils.MCVersion;
Expand All @@ -40,13 +41,15 @@ public static void chatMessageListener() {
InteractiveChat.protocolManager.addPacketListener(new PacketAdapter(InteractiveChat.plugin, ListenerPriority.MONITOR, PacketType.Play.Server.CHAT) {
@Override
public void onPacketSending(PacketEvent event) {
int debug = 0;
try {
if (!event.getPacketType().equals(PacketType.Play.Server.CHAT)) {
return;
}

debug++;
PacketContainer packet = event.getPacket();
Player reciever = event.getPlayer();

debug++;
if (!InteractiveChat.version.isLegacy() || InteractiveChat.version.equals(MCVersion.V1_12)) {
ChatType type = packet.getChatTypes().read(0);
if (type.equals(ChatType.GAME_INFO)) {
Expand All @@ -58,46 +61,51 @@ public void onPacketSending(PacketEvent event) {
return;
}
}

debug++;
WrappedChatComponent wcc = packet.getChatComponents().read(0);
Object field1 = packet.getModifier().read(1);
if (wcc == null && field1 == null) {
return;
}
debug++;
BaseComponent[] basecomponentarray = (wcc != null) ? ComponentSerializer.parse(wcc.getJson()) : (BaseComponent[]) field1;
int field = (wcc != null) ? 0 : 1;
BaseComponent basecomponent = basecomponentarray[0];
BaseComponent basecomponent = ComponentSerializer.parse(ChatColorFilter.filterIllegalColorCodes(ComponentSerializer.toString(basecomponentarray)))[0];
debug++;
try {
if (basecomponent.toLegacyText().equals("")) {
return;
}
} catch (Exception e) {
return;
}

debug++;
if ((InteractiveChat.version.isOld()) && JsonUtils.containsKey(ComponentSerializer.toString(basecomponent), "translate")) {
return;
}

debug++;
String rawMessageKey = basecomponent.toPlainText();
if (!InteractiveChat.keyTime.containsKey(rawMessageKey)) {
InteractiveChat.keyTime.put(rawMessageKey, System.currentTimeMillis());
}
debug++;
long unix = InteractiveChat.keyTime.get(rawMessageKey);
if (!InteractiveChat.cooldownbypass.containsKey(unix)) {
InteractiveChat.cooldownbypass.put(unix, new HashSet<String>());
}
debug++;
ProcessCommandsReturn commandsender = ProcessCommands.process(basecomponent);
Optional<Player> sender = commandsender.getSender() != null ? Optional.of(commandsender.getSender()) : SenderFinder.getSender(basecomponent, rawMessageKey);
basecomponent = commandsender.getBaseComponent();
if (sender.isPresent()) {
InteractiveChat.keyPlayer.put(rawMessageKey, sender.get());
}
debug++;
Bukkit.getScheduler().runTaskLaterAsynchronously(InteractiveChat.plugin, () -> {
InteractiveChat.keyTime.remove(rawMessageKey);
InteractiveChat.keyPlayer.remove(rawMessageKey);
}, 5);

debug++;
UUID preEventSenderUUID = sender.isPresent() ? sender.get().getUniqueId() : null;
PrePacketComponentProcessEvent preEvent = new PrePacketComponentProcessEvent(event.isAsync(), reciever, basecomponent, field, preEventSenderUUID);
Bukkit.getPluginManager().callEvent(preEvent);
Expand All @@ -107,53 +115,59 @@ public void onPacketSending(PacketEvent event) {
sender = Optional.of(newsender);
}
}

debug++;
if (InteractiveChat.usePlayerName) {
basecomponent = PlayernameDisplay.process(basecomponent, rawMessageKey, sender, unix);
}

debug++;
if (InteractiveChat.AllowMention && sender.isPresent()) {
basecomponent = MentionDisplay.process(basecomponent, reciever, sender.get(), rawMessageKey, unix, event.isAsync());
}

debug++;
if (InteractiveChat.useItem) {
basecomponent = ItemDisplay.process(basecomponent, sender, reciever, rawMessageKey, unix);
}

debug++;
if (InteractiveChat.useInventory) {
basecomponent = InventoryDisplay.process(basecomponent, sender, rawMessageKey, unix);
}

debug++;
if (InteractiveChat.useEnder) {
basecomponent = EnderchestDisplay.process(basecomponent, sender, rawMessageKey, unix);
}

debug++;
basecomponent = CustomPlaceholderDisplay.process(basecomponent, sender, reciever, rawMessageKey, unix);

debug++;
basecomponentarray[0] = InteractiveChat.FilterUselessColorCodes ? ChatComponentUtils.cleanUpLegacyText(basecomponent, reciever) : ChatComponentUtils.respectClientColorSettingsWithoutCleanUp(basecomponent, reciever);
String json = ComponentSerializer.toString(basecomponentarray);
boolean longerThanMaxLength = false;
if ((InteractiveChat.version.isLegacy() || InteractiveChat.protocolManager.getProtocolVersion(reciever) < 393) && json.length() > 32767) {
longerThanMaxLength = true;
}
debug++;
if (field == 0) {
packet.getChatComponents().write(0, WrappedChatComponent.fromJson(json));
} else {
packet.getModifier().write(1, basecomponentarray);
}

debug++;
UUID postEventSenderUUID = sender.isPresent() ? sender.get().getUniqueId() : null;
PostPacketComponentProcessEvent postEvent = new PostPacketComponentProcessEvent(event.isAsync(), reciever, packet, postEventSenderUUID, longerThanMaxLength);
Bukkit.getPluginManager().callEvent(postEvent);
debug++;
if (postEvent.isCancelled()) {
event.setReadOnly(false);
event.setCancelled(true);
event.setReadOnly(true);
if (longerThanMaxLength) {
if (longerThanMaxLength && InteractiveChat.cancelledMessage) {
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[InteractiveChat] " + ChatColor.RED + "Cancelled a chat packet bounded to " + reciever.getName() + " that is " + json.length() + " characters long (Max 32767) [THIS IS NOT A BUG]");
}
}
}
debug++;
} catch (Exception e) {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "IC DEBUG " + event.getPlayer().getName() + " " + debug);
e.printStackTrace();
}
}
});
}
Expand Down
28 changes: 6 additions & 22 deletions src/com/loohp/interactivechat/Listeners/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,13 @@ private void checkMention(AsyncPlayerChatEvent event) {
for (String name : playernames) {
int index = message.toLowerCase().indexOf(name.toLowerCase());
if (index >= 0) {
char escape = (index - 1) < 0 ? ' ' : message.charAt(index - 1);
char before = (index - 1) < 0 ? ' ' : message.charAt(index - 1);
char after = (index + name.length()) >= message.length() ? ' ' : message.charAt(index + name.length());
if (String.valueOf(escape).matches("[ \\\\]") && String.valueOf(after).matches("[ \\\\]")) {
char escapeescape = (index - 2) < 0 ? ' ' : message.charAt(index - 2);
if ((escape != '\\') || ((escape == '\\' && escapeescape == '\\'))) {
if (escapeescape == '\\') {
StringBuilder sb = new StringBuilder(message);
sb.deleteCharAt(index - 2);
event.setMessage(sb.toString());
message = event.getMessage();
}
if (!player.equals(sender)) {
InteractiveChat.mentionPair.put(player.getUniqueId(), new MentionPair(sender.getUniqueId(), player.getUniqueId(), InteractiveChat.mentionPair));
}
break;
} else {
if (escape == '\\') {
StringBuilder sb = new StringBuilder(message);
sb.deleteCharAt(index - 1);
event.setMessage(sb.toString());
message = event.getMessage();
}
}
if (String.valueOf(before).matches("[^a-zA-Z0-9]") && String.valueOf(after).matches("[^a-zA-Z0-9]")) {
if (!player.equals(sender)) {
InteractiveChat.mentionPair.put(player.getUniqueId(), new MentionPair(sender.getUniqueId(), player.getUniqueId(), InteractiveChat.mentionPair));
}
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
Expand All @@ -28,8 +28,8 @@

public class CustomPlaceholderDisplay {

private static HashMap<Player, HashMap<String, Long>> placeholderCooldowns = InteractiveChat.placeholderCooldowns;
private static HashMap<Player, Long> universalCooldowns = InteractiveChat.universalCooldowns;
private static ConcurrentHashMap<Player, ConcurrentHashMap<String, Long>> placeholderCooldowns = InteractiveChat.placeholderCooldowns;
private static ConcurrentHashMap<Player, Long> universalCooldowns = InteractiveChat.universalCooldowns;
private static Random random = new Random();

public static BaseComponent process(BaseComponent basecomponent, Optional<Player> optplayer, Player reciever, String messageKey, long unix) {
Expand Down Expand Up @@ -70,9 +70,9 @@ public static BaseComponent processCustomPlaceholder(Player parseplayer, boolean
}

if (!placeholderCooldowns.containsKey(player)) {
placeholderCooldowns.put(player, new HashMap<String, Long>());
placeholderCooldowns.put(player, new ConcurrentHashMap<String, Long>());
}
HashMap<String, Long> spmap = placeholderCooldowns.get(player);
ConcurrentHashMap<String, Long> spmap = placeholderCooldowns.get(player);
if (spmap.containsKey(placeholder)) {
if (spmap.get(placeholder) > unix) {
if (!player.hasPermission("interactivechat.cooldown.bypass")) {
Expand Down
9 changes: 5 additions & 4 deletions src/com/loohp/interactivechat/Modules/EnderchestDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand All @@ -29,8 +30,8 @@

public class EnderchestDisplay {

private static HashMap<Player, HashMap<String, Long>> placeholderCooldowns = InteractiveChat.placeholderCooldowns;
private static HashMap<Player, Long> universalCooldowns = InteractiveChat.universalCooldowns;
private static ConcurrentHashMap<Player, ConcurrentHashMap<String, Long>> placeholderCooldowns = InteractiveChat.placeholderCooldowns;
private static ConcurrentHashMap<Player, Long> universalCooldowns = InteractiveChat.universalCooldowns;

public static BaseComponent process(BaseComponent basecomponent, Optional<Player> optplayer, String messageKey, long unix) {
boolean contain = (InteractiveChat.enderCaseSensitive) ? (basecomponent.toPlainText().contains(InteractiveChat.enderPlaceholder)) : (basecomponent.toPlainText().toLowerCase().contains(InteractiveChat.enderPlaceholder.toLowerCase()));
Expand All @@ -45,9 +46,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
}

if (!placeholderCooldowns.containsKey(player)) {
placeholderCooldowns.put(player, new HashMap<String, Long>());
placeholderCooldowns.put(player, new ConcurrentHashMap<String, Long>());
}
HashMap<String, Long> spmap = placeholderCooldowns.get(player);
ConcurrentHashMap<String, Long> spmap = placeholderCooldowns.get(player);
if (spmap.containsKey(InteractiveChat.enderPlaceholder)) {
if (spmap.get(InteractiveChat.enderPlaceholder) > unix) {
if (!player.hasPermission("interactivechat.cooldown.bypass")) {
Expand Down
Loading

0 comments on commit e5b3c9f

Please sign in to comment.