Skip to content

Commit

Permalink
finally added [item] to Chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanguygab committed Mar 17, 2021
1 parent 033b777 commit 5f22653
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,13 +121,12 @@ public boolean onChat(TabPlayer p, String msg, boolean cancelled) {

List<IChatBaseComponent> 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()) {
Expand Down Expand Up @@ -197,20 +197,22 @@ public boolean canSee(TabPlayer sender, TabPlayer viewer) {
public IChatBaseComponent itemcheck(TabPlayer p, IChatBaseComponent comp, String msg) {

List<IChatBaseComponent> 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]));


ItemStack item = ((Player) p.getPlayer()).getInventory().getItemInMainHand();

IChatBaseComponent itemmsg = new IChatBaseComponent("");
List<String> 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 = "";
Expand All @@ -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;
}

Expand Down

0 comments on commit 5f22653

Please sign in to comment.