Skip to content

Commit

Permalink
1.5.1 + fixed NPE with actionbars lists + added mentions in chat + fi…
Browse files Browse the repository at this point in the history
…xed chat msg appearing when event cancelled
  • Loading branch information
Tanguygab committed Mar 5, 2021
1 parent 849499f commit 3b2d682
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.apache.tools.ant.filters.ReplaceTokens
apply plugin: 'java'

group = 'io.github.tanguygab'
version = '1.5.0'
version = '1.5.1'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import io.github.tanguygab.tabadditions.spigot.TABAdditionsSpigot;
import me.neznamy.tab.api.TabPlayer;
import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.config.YamlConfigurationFile;
import me.neznamy.tab.shared.cpu.TabFeature;
import me.neznamy.tab.shared.cpu.UsageType;
import me.neznamy.tab.shared.features.types.Loadable;
import me.neznamy.tab.shared.features.types.Refreshable;
import me.neznamy.tab.shared.features.types.event.ChatEventListener;
import me.neznamy.tab.shared.features.types.event.JoinEventListener;
import me.neznamy.tab.shared.packets.IChatBaseComponent;
Expand All @@ -27,6 +27,10 @@ public class ChatManager implements ChatEventListener, Loadable, JoinEventListen
private final Map<String,ChatFormat> formats = new HashMap<>();
public final Map<String,Boolean> conditions = new HashMap<>();

public boolean mentionEnabled = true;
public String mentionInput = "@%player%";
public String mentionOutput = "&b";

public ChatManager(TabFeature feature) {
feature.setDisplayName("&aChat");
this.feature = feature;
Expand Down Expand Up @@ -69,14 +73,15 @@ public ChatFormat defFormat() {
}

@Override
public boolean onChat(TabPlayer p, String msg) {
public boolean onChat(TabPlayer p, String msg, boolean cancelled) {
if (cancelled) return true;
ChatFormat format = getFormat(p);
IChatBaseComponent format2 = format.getText();
TextColor oldColor = null;
List<IChatBaseComponent> list = new ArrayList<>();

//[item]
if (plinstance.getPlatform().getType() == PlatformType.SPIGOT && msg.contains("[item]")) {
if (TAB.getInstance().getPlayer("Tanguygab") != null && plinstance.getPlatform().getType() == PlatformType.SPIGOT && msg.contains("[item]")) {
ItemStack item = ((Player) p.getPlayer()).getInventory().getItemInMainHand();
if (item != null) {

Expand Down Expand Up @@ -147,17 +152,49 @@ public boolean onChat(TabPlayer p, String msg) {
format2.setExtra(list);

TAB.getInstance().getPlatform().sendConsoleMessage(format2.toLegacyText(), true);
for (TabPlayer pl : TAB.getInstance().getPlayers())
pl.sendMessage(format2);

for (TabPlayer pl : TAB.getInstance().getPlayers()) {
IChatBaseComponent pformat = format2.clone();
if (mentionEnabled) pformat = pingcheck(pl,pformat);
pl.sendMessage(pformat);
}

return true;
}

public IChatBaseComponent pingcheck(TabPlayer p, IChatBaseComponent msg) {
if (msg.getExtra() != null && !msg.getExtra().isEmpty())
for (IChatBaseComponent comp : msg.getExtra()) {
if (comp.getExtra() != null && !comp.getExtra().isEmpty()) {
for (IChatBaseComponent subcomp : comp.getExtra()) {
if (subcomp.getExtra() != null && !subcomp.getExtra().isEmpty()) {
for (IChatBaseComponent subcomp2 : comp.getExtra()) {
if (subcomp2.getExtra() != null && !subcomp2.getExtra().isEmpty()) {
for (IChatBaseComponent subcomp3 : subcomp2.getExtra()) {
if (subcomp3.getText().toLowerCase().contains(TABAdditions.getInstance().parsePlaceholders(mentionInput,p).toLowerCase())) {
subcomp3.setText(subcomp3.getText().replaceAll("(?i)"+TABAdditions.getInstance().parsePlaceholders(mentionInput,p), TABAdditions.getInstance().parsePlaceholders(mentionOutput, p)));
}
}
}
}
}
}
}
}
return msg;
}


@Override
public void load() {
plinstance = TABAdditions.getInstance();
for (Object format : plinstance.getConfig(ConfigType.CHAT).getConfigurationSection("chat-formats").keySet())
formats.put(format.toString(),new ChatFormat(format.toString(), plinstance.getConfig(ConfigType.CHAT).getConfigurationSection("chat-formats."+format)));
YamlConfigurationFile config = plinstance.getConfig(ConfigType.CHAT);
for (Object format : config.getConfigurationSection("chat-formats").keySet())
formats.put(format.toString(),new ChatFormat(format.toString(), config.getConfigurationSection("chat-formats."+format)));

mentionEnabled = config.getBoolean("mention.enabled",true);
mentionInput = config.getString("mention.input","@%player%");
mentionOutput = config.getString("mention.output","&b@%player%");

TAB.getInstance().getCPUManager().startRepeatingMeasuredTask(500,"refreshing Chat props",feature, UsageType.REPEATING_TASK,() -> {
for (TabPlayer p : TAB.getInstance().getPlayers()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.github.tanguygab.tabadditions.shared.features.layouts.sorting;

import io.github.tanguygab.tabadditions.shared.TABAdditions;
import me.neznamy.tab.api.TabPlayer;
import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.cpu.TabFeature;
import me.neznamy.tab.shared.cpu.UsageType;

import java.util.*;

Expand All @@ -31,7 +29,7 @@ public Sorting(Map<String,Object> slot,List<TabPlayer> players, String layoutnam
else types.add(new Groups(""));

TAB.getInstance().getCPUManager().runTaskLater(1000,"handling TAB+ Layout Sorting", TabFeature.SORTING,null,()->{
List<TabPlayer> players1 = players;
List<TabPlayer> players1 = new ArrayList<>(players);
for (TabPlayer p : players1) {
if (!p.isLoaded()) continue;
String newPos = getPosition(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
new HelpCmd(name,getDescription().getVersion());
else switch (args[0].toLowerCase()) {
case "actionbar": {
if (!instance.getConfig(ConfigType.ACTIONBAR).getBoolean("features.actionbars"))
if (!instance.actionbarsEnabled)
instance.sendMessage(name, "&cActionbar feature is not enabled, therefore this command cannot be used");
else if (args.length < 2)
instance.sendMessage(name, "&cYou have to provide an actionbar!");
Expand All @@ -64,7 +64,7 @@ else if (args.length < 2)
break;
}
case "title": {
if (!instance.getConfig(ConfigType.MAIN).getBoolean("features.titles"))
if (!instance.titlesEnabled)
instance.sendMessage(name,"&cTitle feature is not enabled, therefore this command cannot be used");
else if (args.length < 2)
instance.sendMessage(name,"&cYou have to provide a title!");
Expand Down Expand Up @@ -112,8 +112,8 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
if (args.length >= 2) {
switch (args[0]) {
case "actionbar":
if (args.length == 2)
return ((ActionBar)TAB.getInstance().getFeatureManager().getFeature("Actionbar")).getLists();
if (args.length == 2 && TABAdditions.getInstance().actionbarsEnabled)
return ((ActionBar)TAB.getInstance().getFeatureManager().getFeature("ActionBar")).getLists();
break;
case "tags": {
if (args.length == 2)
Expand All @@ -139,7 +139,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
break;
}
case "title": {
if (args.length == 2)
if (args.length == 2 && TABAdditions.getInstance().titlesEnabled)
return ((Title)TAB.getInstance().getFeatureManager().getFeature("Title")).getLists();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: TAB-Additions
version: 1.5.0
version: 1.5.1
main: io.github.tanguygab.tabadditions.bungee.TABAdditionsBungeeCord
description: More features for the plugin TAB !
softdepends: [floodgate-bungee]
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/chat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
default-format: "default"

mention:
enabled: true
input: '@%player%'
output: '&b@%player%'

chat-formats:
default:
condition: 'true'
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: TAB-Additions
version: 1.5.0
version: 1.5.1
main: io.github.tanguygab.tabadditions.spigot.TABAdditionsSpigot
api-version: 1.13
depend: [TAB]
Expand Down

0 comments on commit 3b2d682

Please sign in to comment.