From 5f22653aa457ae946f240e08bd84ccb27c1a8989 Mon Sep 17 00:00:00 2001 From: Tanguygab Date: Wed, 17 Mar 2021 20:30:39 +0100 Subject: [PATCH] finally added [item] to Chat --- build.gradle | 13 +++++++++--- .../shared/features/chat/ChatManager.java | 21 +++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index ba945fb..8ff2769 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,13 @@ import org.apache.tools.ant.filters.ReplaceTokens - -apply plugin: 'java' +plugins { + id 'java' + id'com.github.johnrengelman.shadow' version '6.1.0' +} group = 'io.github.tanguygab' version = '1.5.3' + repositories { mavenCentral() jcenter() @@ -37,9 +40,13 @@ dependencies { compileOnly 'com.discordsrv:discordsrv:1.21.1' compileOnly files('../TAB.jar') compileOnly files('../nms.jar') - compile files('../FloodgateBungee.jar') + compile 'org.apache.commons:commons-lang3:3.5' + compileOnly files('../FloodgateBungee.jar') +} +shadowJar { + archiveClassifier.set('') } processResources { diff --git a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/ChatManager.java b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/ChatManager.java index d183a80..c827eb7 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/ChatManager.java +++ b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/ChatManager.java @@ -16,6 +16,7 @@ import me.neznamy.tab.shared.packets.IChatBaseComponent; import me.neznamy.tab.shared.rgb.RGBUtils; import me.neznamy.tab.shared.rgb.TextColor; +import org.apache.commons.lang3.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Instrument; import org.bukkit.Note; @@ -120,13 +121,12 @@ public boolean onChat(TabPlayer p, String msg, boolean cancelled) { List list2 = new ArrayList<>(); for (IChatBaseComponent txt : comp.getExtra()) { - String msg2 = plinstance.parsePlaceholders(txt.toRawText(), p).replaceAll("%msg%", msg); - //[item] - if (txt.toRawText().contains("%msg%") && TAB.getInstance().getPlayer("Tanguygab") != null && plinstance.getPlatform().getType() == PlatformType.SPIGOT && msg.contains("[item]")) { + if (txt.toRawText().contains("%msg%") && plinstance.getPlatform().getType() == PlatformType.SPIGOT && msg.contains("[item]")) { txt = itemcheck(p, txt, msg); - p.sendMessage(txt); + } else { + String msg2 = plinstance.parsePlaceholders(txt.toRawText(), p).replaceAll("%msg%", msg); + txt = IChatBaseComponent.fromColoredText(msg2).setColor(txt.getColor()); } - txt = IChatBaseComponent.fromColoredText(msg2).setColor(txt.getColor()); TextColor color = null; for (IChatBaseComponent c : txt.getExtra()) { @@ -197,7 +197,7 @@ public boolean canSee(TabPlayer sender, TabPlayer viewer) { public IChatBaseComponent itemcheck(TabPlayer p, IChatBaseComponent comp, String msg) { List msglist = new ArrayList<>(); - String[] list = comp.getText().split("%msg%"); + String[] list = TABAdditions.getInstance().parsePlaceholders(comp.getText(),p).split("%msg%"); msglist.add(new IChatBaseComponent(list[0])); @@ -205,12 +205,14 @@ public IChatBaseComponent itemcheck(TabPlayer p, IChatBaseComponent comp, String IChatBaseComponent itemmsg = new IChatBaseComponent(""); List ar = new ArrayList<>(Arrays.asList(msg.split("\\[item]"))); + int itemcount = StringUtils.countMatches(msg,"[item]"); if (ar.isEmpty()) ar.add(""); for (String txt2 : ar) { + IChatBaseComponent txt3 = IChatBaseComponent.fromColoredText(txt2); + msglist.add(txt3); - msglist.add(IChatBaseComponent.fromColoredText(txt2)); - if ((ar.size() == 1 || ar.indexOf(txt2) != ar.size() - 1)) { + if (itemcount != 0) { IChatBaseComponent itemtxt = new IChatBaseComponent(); String type = item.getType().toString().replace("_", " ").toLowerCase(); String type2 = ""; @@ -222,14 +224,15 @@ public IChatBaseComponent itemcheck(TabPlayer p, IChatBaseComponent comp, String itemtxt = itemtxt.setText(type2); itemtxt = itemtxt.onHoverShowItem(((TABAdditionsSpigot) plinstance.getPlugin()).itemStack(item)); msglist.add(itemtxt); + itemcount = itemcount-1; } } if (list.length > 1) msglist.add(new IChatBaseComponent(list[1])); itemmsg.setExtra(msglist); - p.sendMessage(itemmsg); comp.setExtra(msglist); + comp.setText(""); return comp; }