Skip to content

Commit

Permalink
2.1.0 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed Apr 27, 2020
1 parent d5dcc80 commit 80b17af
Show file tree
Hide file tree
Showing 17 changed files with 601 additions and 13,153 deletions.
2 changes: 2 additions & 0 deletions src/com/loohp/interactivechat/InteractiveChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.loohp.interactivechat.Metrics.Metrics;
import com.loohp.interactivechat.ObjectHolders.CommandPlaceholderGroup;
import com.loohp.interactivechat.Utils.MaterialUtils;
import com.loohp.interactivechat.Utils.RarityUtils;

public class InteractiveChat extends JavaPlugin {

Expand Down Expand Up @@ -181,6 +182,7 @@ public void onEnable() {
}

MaterialUtils.setupLang();
RarityUtils.setupRarity();

metrics.addCustomChart(new Metrics.SingleLineChart("total_placeholders", new Callable<Integer>() {
@Override
Expand Down
7 changes: 0 additions & 7 deletions src/com/loohp/interactivechat/Listeners/ChatPackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
import com.loohp.interactivechat.Modules.ProcessCommands;
import com.loohp.interactivechat.Modules.SenderFinder;
import com.loohp.interactivechat.ObjectHolders.ProcessCommandsReturn;
import com.loohp.interactivechat.Utils.CustomStringUtils;

import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TranslatableComponent;
import net.md_5.bungee.chat.ComponentSerializer;

public class ChatPackets {
Expand All @@ -55,11 +53,6 @@ public void onPacketSending(PacketEvent event) {
BaseComponent[] basecomponentarray = (wcc != null) ? ComponentSerializer.parse(wcc.getJson()) : (BaseComponent[]) packet.getModifier().read(1);
int field = (wcc != null) ? 0 : 1;
BaseComponent basecomponent = basecomponentarray[0];
for (BaseComponent base : CustomStringUtils.loadExtras(basecomponent)) {
if (base instanceof TranslatableComponent) {
return;
}
}
if (wcc == null) {
if (basecomponent.toPlainText().equals("")) {
return;
Expand Down
108 changes: 56 additions & 52 deletions src/com/loohp/interactivechat/Modules/CustomPlaceholderDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,70 +83,74 @@ public static BaseComponent processCustomPlaceholder(Player parseplayer, boolean
List<BaseComponent> basecomponentlist = CustomStringUtils.loadExtras(basecomponent);
List<BaseComponent> newlist = new ArrayList<BaseComponent>();
for (BaseComponent base : basecomponentlist) {
TextComponent textcomponent = (TextComponent) base;
String text = textcomponent.getText();
if (casesensitive) {
if (!text.contains(placeholder)) {
newlist.add(textcomponent);
continue;
}
if (!(base instanceof TextComponent)) {
newlist.add(base);
} else {
if (!text.toLowerCase().contains(placeholder.toLowerCase())) {
newlist.add(textcomponent);
continue;
TextComponent textcomponent = (TextComponent) base;
String text = textcomponent.getText();
if (casesensitive) {
if (!text.contains(placeholder)) {
newlist.add(textcomponent);
continue;
}
} else {
if (!text.toLowerCase().contains(placeholder.toLowerCase())) {
newlist.add(textcomponent);
continue;
}
}
}

String regex = casesensitive ? CustomStringUtils.escapeMetaCharacters(placeholder) : "(?i)(" + CustomStringUtils.escapeMetaCharacters(placeholder) + ")";
List<String> trim = new LinkedList<String>(Arrays.asList(text.split(regex, -1)));
if (trim.get(trim.size() - 1).equals("")) {
trim.remove(trim.size() - 1);
}
for (int i = 0; i < trim.size(); i++) {
TextComponent before = (TextComponent) textcomponent.duplicate();
before.setText(trim.get(i));
newlist.add(before);

boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
TextComponent message = new TextComponent(placeholder);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
newlist.add(message);
} else {
if (trim.get(i).endsWith("\\\\")) {
String regex = casesensitive ? CustomStringUtils.escapeMetaCharacters(placeholder) : "(?i)(" + CustomStringUtils.escapeMetaCharacters(placeholder) + ")";
List<String> trim = new LinkedList<String>(Arrays.asList(text.split(regex, -1)));
if (trim.get(trim.size() - 1).equals("")) {
trim.remove(trim.size() - 1);
}
for (int i = 0; i < trim.size(); i++) {
TextComponent before = (TextComponent) textcomponent.duplicate();
before.setText(trim.get(i));
newlist.add(before);

boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
TextComponent message = new TextComponent(placeholder);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
}
Player player = parseplayer;

String textComp = placeholder;
if (replaceEnabled) {
textComp = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, replaceText));
}
BaseComponent[] bcJson = ComponentSerializer.parse(JsonUtils.toJSON(textComp));
List<BaseComponent> baseJson = new ArrayList<BaseComponent>();
baseJson = CustomStringUtils.loadExtras(Arrays.asList(bcJson));

for (BaseComponent baseComponent : baseJson) {
TextComponent message = (TextComponent) baseComponent;
if (hoverEnabled) {
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(PlaceholderAPI.setPlaceholders(player, hoverText)).create()));
newlist.add(message);
} else {
if (trim.get(i).endsWith("\\\\")) {
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
}
Player player = parseplayer;

if (clickEnabled) {
String clicktext = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, clickValue));
message.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(clickAction), clicktext));
String textComp = placeholder;
if (replaceEnabled) {
textComp = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, replaceText));
}

newlist.add(message);
}
BaseComponent[] bcJson = ComponentSerializer.parse(JsonUtils.toJSON(textComp));
List<BaseComponent> baseJson = new ArrayList<BaseComponent>();
baseJson = CustomStringUtils.loadExtras(Arrays.asList(bcJson));

for (BaseComponent baseComponent : baseJson) {
TextComponent message = (TextComponent) baseComponent;
if (hoverEnabled) {
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(PlaceholderAPI.setPlaceholders(player, hoverText)).create()));
}

if (clickEnabled) {
String clicktext = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, clickValue));
message.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(clickAction), clicktext));
}

newlist.add(message);
}
}
}
}
}
}

TextComponent product = (TextComponent) newlist.get(0);
for (int i = 1; i < newlist.size(); i++) {
TextComponent product = new TextComponent("");
for (int i = 0; i < newlist.size(); i++) {
BaseComponent each = newlist.get(i);
product.addExtra(each);
}
Expand Down
178 changes: 91 additions & 87 deletions src/com/loohp/interactivechat/Modules/EnderchestDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,108 +66,112 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
List<BaseComponent> basecomponentlist = CustomStringUtils.loadExtras(basecomponent);
List<BaseComponent> newlist = new ArrayList<BaseComponent>();
for (BaseComponent base : basecomponentlist) {
TextComponent textcomponent = (TextComponent) base;
String text = textcomponent.getText();
if (casesensitive) {
if (!text.contains(placeholder)) {
newlist.add(textcomponent);
continue;
}
if (!(base instanceof TextComponent)) {
newlist.add(base);
} else {
if (!text.toLowerCase().contains(placeholder.toLowerCase())) {
newlist.add(textcomponent);
continue;
TextComponent textcomponent = (TextComponent) base;
String text = textcomponent.getText();
if (casesensitive) {
if (!text.contains(placeholder)) {
newlist.add(textcomponent);
continue;
}
} else {
if (!text.toLowerCase().contains(placeholder.toLowerCase())) {
newlist.add(textcomponent);
continue;
}
}
}

String regex = casesensitive ? CustomStringUtils.escapeMetaCharacters(placeholder) : "(?i)(" + CustomStringUtils.escapeMetaCharacters(placeholder) + ")";
List<String> trim = new LinkedList<String>(Arrays.asList(text.split(regex, -1)));
if (trim.get(trim.size() - 1).equals("")) {
trim.remove(trim.size() - 1);
}
for (int i = 0; i < trim.size(); i++) {
TextComponent before = (TextComponent) textcomponent.duplicate();
before.setText(trim.get(i));
newlist.add(before);

boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
TextComponent message = new TextComponent(placeholder);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
newlist.add(message);
} else {
if (trim.get(i).endsWith("\\\\")) {
String regex = casesensitive ? CustomStringUtils.escapeMetaCharacters(placeholder) : "(?i)(" + CustomStringUtils.escapeMetaCharacters(placeholder) + ")";
List<String> trim = new LinkedList<String>(Arrays.asList(text.split(regex, -1)));
if (trim.get(trim.size() - 1).equals("")) {
trim.remove(trim.size() - 1);
}
for (int i = 0; i < trim.size(); i++) {
TextComponent before = (TextComponent) textcomponent.duplicate();
before.setText(trim.get(i));
newlist.add(before);

boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
TextComponent message = new TextComponent(placeholder);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
}
if (optplayer.isPresent()) {
Player player = optplayer.get();
if (player.hasPermission("interactivechat.module.enderchest")) {

long time = InteractiveChat.keyTime.get(messageKey);

String replaceText = InteractiveChat.enderReplaceText;

String title = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, InteractiveChat.enderTitle));

if (!InteractiveChat.enderDisplay.containsKey(time)) {
Inventory inv = Bukkit.createInventory(null, 27, title);
for (int j = 0; j < player.getEnderChest().getSize(); j = j + 1) {
if (player.getEnderChest().getItem(j) != null) {
if (!player.getEnderChest().getItem(j).getType().equals(Material.AIR)) {
inv.setItem(j, player.getEnderChest().getItem(j).clone());
}
}
}
InteractiveChat.enderDisplay.put(time, inv);
HashMap<Long, Inventory> singleMap = new HashMap<Long, Inventory>();
singleMap.put(time, inv);
newlist.add(message);
} else {
if (trim.get(i).endsWith("\\\\")) {
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
}
if (optplayer.isPresent()) {
Player player = optplayer.get();
if (player.hasPermission("interactivechat.module.enderchest")) {

long time = InteractiveChat.keyTime.get(messageKey);

String replaceText = InteractiveChat.enderReplaceText;

String title = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, InteractiveChat.enderTitle));

if (!InteractiveChat.enderDisplay.containsKey(time)) {
Inventory inv = Bukkit.createInventory(null, 27, title);
for (int j = 0; j < player.getEnderChest().getSize(); j = j + 1) {
if (player.getEnderChest().getItem(j) != null) {
if (!player.getEnderChest().getItem(j).getType().equals(Material.AIR)) {
inv.setItem(j, player.getEnderChest().getItem(j).clone());
}
}
}
InteractiveChat.enderDisplay.put(time, inv);
HashMap<Long, Inventory> singleMap = new HashMap<Long, Inventory>();
singleMap.put(time, inv);
}

String textComp = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, replaceText));

BaseComponent[] bcJson = ComponentSerializer.parse(JsonUtils.toJSON(textComp));
List<BaseComponent> baseJson = new ArrayList<BaseComponent>();
baseJson = CustomStringUtils.loadExtras(Arrays.asList(bcJson));

List<String> hoverList = ConfigManager.getConfig().getStringList("ItemDisplay.EnderChest.HoverMessage");
String endertext = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, String.join("\n", hoverList)));

for (BaseComponent baseComponent : baseJson) {
TextComponent message = (TextComponent) baseComponent;
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(endertext).create()));
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/interactivechat viewender " + time));
newlist.add(message);
}
} else {
TextComponent message = new TextComponent(placeholder);

newlist.add(message);
}

String textComp = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, replaceText));

BaseComponent[] bcJson = ComponentSerializer.parse(JsonUtils.toJSON(textComp));
List<BaseComponent> baseJson = new ArrayList<BaseComponent>();
baseJson = CustomStringUtils.loadExtras(Arrays.asList(bcJson));

List<String> hoverList = ConfigManager.getConfig().getStringList("ItemDisplay.EnderChest.HoverMessage");
String endertext = ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, String.join("\n", hoverList)));

for (BaseComponent baseComponent : baseJson) {
TextComponent message = (TextComponent) baseComponent;
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(endertext).create()));
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/interactivechat viewender " + time));
newlist.add(message);
}
} else {
TextComponent message = new TextComponent(placeholder);
TextComponent message = null;
if (InteractiveChat.PlayerNotFoundReplaceEnable == true) {
message = new TextComponent(InteractiveChat.PlayerNotFoundReplaceText.replace("{Placeholer}", placeholder));
} else {
message = new TextComponent(placeholder);
}
if (InteractiveChat.PlayerNotFoundHoverEnable == true) {
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(InteractiveChat.PlayerNotFoundHoverText.replace("{Placeholer}", placeholder)).create()));
}
if (InteractiveChat.PlayerNotFoundClickEnable == true) {
String endertext = ChatColor.translateAlternateColorCodes('&', InteractiveChat.PlayerNotFoundClickValue.replace("{Placeholer}", placeholder));
message.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(InteractiveChat.PlayerNotFoundClickAction), endertext));
}

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

newlist.add(message);
}
}
}
}
}

TextComponent product = (TextComponent) newlist.get(0);
for (int i = 1; i < newlist.size(); i++) {
TextComponent product = new TextComponent("");
for (int i = 0; i < newlist.size(); i++) {
BaseComponent each = newlist.get(i);
product.addExtra(each);
}
Expand Down
Loading

0 comments on commit 80b17af

Please sign in to comment.