Skip to content

Commit

Permalink
2.1.9 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed May 6, 2020
1 parent 25e6fbd commit b71430c
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 116 deletions.
1 change: 0 additions & 1 deletion src/com/loohp/interactivechat/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("interactivechat.reload")) {
ConfigManager.reloadConfig();
ConfigManager.loadConfig();
MaterialUtils.reloadLang();
sender.sendMessage(InteractiveChat.ReloadPlugin);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/com/loohp/interactivechat/Listeners/ChatPackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void onPacketSending(PacketEvent event) {
}

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

if (InteractiveChat.AllowMention && sender.isPresent()) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/loohp/interactivechat/Listeners/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void checkChatforChatManager(AsyncPlayerChatEvent event) {
InteractiveChat.messages.put(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', event.getMessage())), event.getPlayer().getUniqueId());
}

@EventHandler(priority=EventPriority.LOWEST)
@EventHandler(priority=EventPriority.LOW)
public void onMention(AsyncPlayerChatEvent event) {
String message = event.getMessage();
Player sender = event.getPlayer();
Expand Down
37 changes: 17 additions & 20 deletions src/com/loohp/interactivechat/Modules/EnderchestDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@

public class EnderchestDisplay {

private static String placeholder = InteractiveChat.enderPlaceholder;
private static boolean casesensitive = InteractiveChat.enderCaseSensitive;
private static HashMap<Player, HashMap<String, Long>> placeholderCooldowns = InteractiveChat.placeholderCooldowns;
private static HashMap<Player, Long> universalCooldowns = InteractiveChat.universalCooldowns;
private static long cooldown = ConfigManager.getConfig().getLong("ItemDisplay.EnderChest.Cooldown") * 1000;

public static BaseComponent process(BaseComponent basecomponent, Optional<Player> optplayer, String messageKey, long unix) {
boolean contain = (casesensitive) ? (basecomponent.toPlainText().contains(placeholder)) : (basecomponent.toPlainText().toLowerCase().contains(placeholder.toLowerCase()));
if (!InteractiveChat.cooldownbypass.get(unix).contains(placeholder) && contain) {
boolean contain = (InteractiveChat.enderCaseSensitive) ? (basecomponent.toPlainText().contains(InteractiveChat.enderPlaceholder)) : (basecomponent.toPlainText().toLowerCase().contains(InteractiveChat.enderPlaceholder.toLowerCase()));
if (!InteractiveChat.cooldownbypass.get(unix).contains(InteractiveChat.enderPlaceholder) && contain) {
if (optplayer.isPresent()) {
Player player = optplayer.get();
Long uc = universalCooldowns.get(player);
Expand All @@ -51,16 +48,16 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
placeholderCooldowns.put(player, new HashMap<String, Long>());
}
HashMap<String, Long> spmap = placeholderCooldowns.get(player);
if (spmap.containsKey(placeholder)) {
if (spmap.get(placeholder) > unix) {
if (spmap.containsKey(InteractiveChat.enderPlaceholder)) {
if (spmap.get(InteractiveChat.enderPlaceholder) > unix) {
if (!player.hasPermission("interactivechat.cooldown.bypass")) {
return basecomponent;
}
}
}
spmap.put(placeholder, unix + cooldown);
spmap.put(InteractiveChat.enderPlaceholder, unix + ConfigManager.getConfig().getLong("ItemDisplay.EnderChest.Cooldown") * 1000);
}
InteractiveChat.cooldownbypass.get(unix).add(placeholder);
InteractiveChat.cooldownbypass.get(unix).add(InteractiveChat.enderPlaceholder);
InteractiveChat.cooldownbypass.put(unix, InteractiveChat.cooldownbypass.get(unix));
}

Expand All @@ -72,19 +69,19 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
} else {
TextComponent textcomponent = (TextComponent) base;
String text = textcomponent.getText();
if (casesensitive) {
if (!text.contains(placeholder)) {
if (InteractiveChat.enderCaseSensitive) {
if (!text.contains(InteractiveChat.enderPlaceholder)) {
newlist.add(textcomponent);
continue;
}
} else {
if (!text.toLowerCase().contains(placeholder.toLowerCase())) {
if (!text.toLowerCase().contains(InteractiveChat.enderPlaceholder.toLowerCase())) {
newlist.add(textcomponent);
continue;
}
}

String regex = casesensitive ? CustomStringUtils.escapeMetaCharacters(placeholder) : "(?i)(" + CustomStringUtils.escapeMetaCharacters(placeholder) + ")";
String regex = InteractiveChat.enderCaseSensitive ? CustomStringUtils.escapeMetaCharacters(InteractiveChat.enderPlaceholder) : "(?i)(" + CustomStringUtils.escapeMetaCharacters(InteractiveChat.enderPlaceholder) + ")";
List<String> trim = new LinkedList<String>(Arrays.asList(text.split(regex, -1)));
if (trim.get(trim.size() - 1).equals("")) {
trim.remove(trim.size() - 1);
Expand All @@ -94,11 +91,11 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
before.setText(trim.get(i));
newlist.add(before);

boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
boolean endwith = InteractiveChat.enderCaseSensitive ? text.endsWith(InteractiveChat.enderPlaceholder) : text.toLowerCase().endsWith(InteractiveChat.enderPlaceholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText());
TextComponent message = new TextComponent(placeholder);
TextComponent message = new TextComponent(InteractiveChat.enderPlaceholder);
message = (TextComponent) ChatColorUtils.applyColor(message, color);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
newlist.add(message);
Expand Down Expand Up @@ -146,22 +143,22 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
newlist.add(message);
}
} else {
TextComponent message = new TextComponent(placeholder);
TextComponent message = new TextComponent(InteractiveChat.enderPlaceholder);

newlist.add(message);
}
} else {
TextComponent message = null;
if (InteractiveChat.PlayerNotFoundReplaceEnable == true) {
message = new TextComponent(InteractiveChat.PlayerNotFoundReplaceText.replace("{Placeholer}", placeholder));
message = new TextComponent(InteractiveChat.PlayerNotFoundReplaceText.replace("{Placeholer}", InteractiveChat.enderPlaceholder));
} else {
message = new TextComponent(placeholder);
message = new TextComponent(InteractiveChat.enderPlaceholder);
}
if (InteractiveChat.PlayerNotFoundHoverEnable == true) {
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(InteractiveChat.PlayerNotFoundHoverText.replace("{Placeholer}", placeholder)).create()));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(InteractiveChat.PlayerNotFoundHoverText.replace("{Placeholer}", InteractiveChat.enderPlaceholder)).create()));
}
if (InteractiveChat.PlayerNotFoundClickEnable == true) {
String endertext = ChatColor.translateAlternateColorCodes('&', InteractiveChat.PlayerNotFoundClickValue.replace("{Placeholer}", placeholder));
String endertext = ChatColor.translateAlternateColorCodes('&', InteractiveChat.PlayerNotFoundClickValue.replace("{Placeholer}", InteractiveChat.enderPlaceholder));
message.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(InteractiveChat.PlayerNotFoundClickAction), endertext));
}

Expand Down
37 changes: 17 additions & 20 deletions src/com/loohp/interactivechat/Modules/InventoryDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@

public class InventoryDisplay {

private static String placeholder = InteractiveChat.invPlaceholder;
private static boolean casesensitive = InteractiveChat.invCaseSensitive;
private static HashMap<Player, HashMap<String, Long>> placeholderCooldowns = InteractiveChat.placeholderCooldowns;
private static HashMap<Player, Long> universalCooldowns = InteractiveChat.universalCooldowns;
private static long cooldown = ConfigManager.getConfig().getLong("ItemDisplay.Inventory.Cooldown") * 1000;

public static BaseComponent process(BaseComponent basecomponent, Optional<Player> optplayer, String messageKey, long unix) {
boolean contain = (casesensitive) ? (basecomponent.toPlainText().contains(placeholder)) : (basecomponent.toPlainText().toLowerCase().contains(placeholder.toLowerCase()));
if (!InteractiveChat.cooldownbypass.get(unix).contains(placeholder) && contain) {
boolean contain = (InteractiveChat.invCaseSensitive) ? (basecomponent.toPlainText().contains(InteractiveChat.invPlaceholder)) : (basecomponent.toPlainText().toLowerCase().contains(InteractiveChat.invPlaceholder.toLowerCase()));
if (!InteractiveChat.cooldownbypass.get(unix).contains(InteractiveChat.invPlaceholder) && contain) {
if (optplayer.isPresent()) {
Player player = optplayer.get();
Long uc = universalCooldowns.get(player);
Expand All @@ -51,16 +48,16 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
placeholderCooldowns.put(player, new HashMap<String, Long>());
}
HashMap<String, Long> spmap = placeholderCooldowns.get(player);
if (spmap.containsKey(placeholder)) {
if (spmap.get(placeholder) > unix) {
if (spmap.containsKey(InteractiveChat.invPlaceholder)) {
if (spmap.get(InteractiveChat.invPlaceholder) > unix) {
if (!player.hasPermission("interactivechat.cooldown.bypass")) {
return basecomponent;
}
}
}
spmap.put(placeholder, unix + cooldown);
spmap.put(InteractiveChat.invPlaceholder, unix + ConfigManager.getConfig().getLong("ItemDisplay.Inventory.Cooldown") * 1000);
}
InteractiveChat.cooldownbypass.get(unix).add(placeholder);
InteractiveChat.cooldownbypass.get(unix).add(InteractiveChat.invPlaceholder);
InteractiveChat.cooldownbypass.put(unix, InteractiveChat.cooldownbypass.get(unix));
}

Expand All @@ -72,19 +69,19 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
} else {
TextComponent textcomponent = (TextComponent) base;
String text = textcomponent.getText();
if (casesensitive) {
if (!text.contains(placeholder)) {
if (InteractiveChat.invCaseSensitive) {
if (!text.contains(InteractiveChat.invPlaceholder)) {
newlist.add(textcomponent);
continue;
}
} else {
if (!text.toLowerCase().contains(placeholder.toLowerCase())) {
if (!text.toLowerCase().contains(InteractiveChat.invPlaceholder.toLowerCase())) {
newlist.add(textcomponent);
continue;
}
}

String regex = casesensitive ? CustomStringUtils.escapeMetaCharacters(placeholder) : "(?i)(" + CustomStringUtils.escapeMetaCharacters(placeholder) + ")";
String regex = InteractiveChat.invCaseSensitive ? CustomStringUtils.escapeMetaCharacters(InteractiveChat.invPlaceholder) : "(?i)(" + CustomStringUtils.escapeMetaCharacters(InteractiveChat.invPlaceholder) + ")";
List<String> trim = new LinkedList<String>(Arrays.asList(text.split(regex, -1)));
if (trim.get(trim.size() - 1).equals("")) {
trim.remove(trim.size() - 1);
Expand All @@ -94,11 +91,11 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
before.setText(trim.get(i));
newlist.add(before);

boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
boolean endwith = InteractiveChat.invCaseSensitive ? text.endsWith(InteractiveChat.invPlaceholder) : text.toLowerCase().endsWith(InteractiveChat.invPlaceholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText());
TextComponent message = new TextComponent(placeholder);
TextComponent message = new TextComponent(InteractiveChat.invPlaceholder);
message = (TextComponent) ChatColorUtils.applyColor(message, color);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
newlist.add(message);
Expand Down Expand Up @@ -147,22 +144,22 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
}

} else {
TextComponent message = new TextComponent(placeholder);
TextComponent message = new TextComponent(InteractiveChat.invPlaceholder);

newlist.add(message);
}
} else {
TextComponent message = null;
if (InteractiveChat.PlayerNotFoundReplaceEnable == true) {
message = new TextComponent(InteractiveChat.PlayerNotFoundReplaceText.replace("{Placeholer}", placeholder));
message = new TextComponent(InteractiveChat.PlayerNotFoundReplaceText.replace("{Placeholer}", InteractiveChat.invPlaceholder));
} else {
message = new TextComponent(placeholder);
message = new TextComponent(InteractiveChat.invPlaceholder);
}
if (InteractiveChat.PlayerNotFoundHoverEnable == true) {
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(InteractiveChat.PlayerNotFoundHoverText.replace("{Placeholer}", placeholder)).create()));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(InteractiveChat.PlayerNotFoundHoverText.replace("{Placeholer}", InteractiveChat.invPlaceholder)).create()));
}
if (InteractiveChat.PlayerNotFoundClickEnable == true) {
String invtext = ChatColor.translateAlternateColorCodes('&', InteractiveChat.PlayerNotFoundClickValue.replace("{Placeholer}", placeholder));
String invtext = ChatColor.translateAlternateColorCodes('&', InteractiveChat.PlayerNotFoundClickValue.replace("{Placeholer}", InteractiveChat.invPlaceholder));
message.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(InteractiveChat.PlayerNotFoundClickAction), invtext));
}

Expand Down
Loading

0 comments on commit b71430c

Please sign in to comment.