Skip to content

Commit

Permalink
fixed %chat-status% returning No instead of On & /togglechat default …
Browse files Browse the repository at this point in the history
…translation colors inverted & code analysis stuff
  • Loading branch information
Tanguygab committed Sep 2, 2023
1 parent 222b475 commit 5e6ae68
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {

compileOnly 'com.discordsrv:discordsrv:1.26.2'
compileOnly 'net.essentialsx:EssentialsXDiscord:2.19.4'
compileOnly 'com.loohp:InteractiveChat:4.2.3.13'
compileOnly 'com.loohp:InteractiveChat:4.2.7.2'
compileOnly 'com.github.DevLeoko:AdvancedBan:2.3.0'
compileOnly 'dev.simplix:protocolize-api:2.2.6'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class TranslationFile extends YamlConfigurationFile {
private final String emojiHeader = getString("emojis.category.header","&7All emojis in this category &8(%owned%/%max%)&7:");
private final String emoji = getString("emojis.category.emoji", "&7 - %emojiraw%&8: &r%emoji%");

public final String chatOn = getString("chat.on", "&cYou will now receive new chat messages!");
public final String chatOff = getString("chat.off", "&aYou won't receive any new chat message!");
public final String chatOn = getString("chat.on", "&aYou will now receive new chat messages!");
public final String chatOff = getString("chat.off", "&cYou won't receive any new chat message!");
private final String chatCooldown = getString("chat.cooldown", "&cYou have to wait %seconds% more seconds!");
private final String chatCleared = getString("chat.cleared", "&aChat cleared by %name%!");
private final String CHAT_CMD_JOIN = getString("chat.commands-formats.join", "&7You joined %name%!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean getCondition(Player player) {
Property prop = p.getProperty("appearance-condition");
if (prop == null) return def;
String cond = prop.getCurrentRawValue();
if (cond.equals("")) return def;
if (cond.isEmpty()) return def;
return Condition.getCondition(cond).isMet(p);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean getCondition(TabPlayer p) {
Property prop = p.getProperty("nametag-condition");
if (prop == null) return def;
String cond = prop.getCurrentRawValue();
if (cond.equals("")) return def;
if (cond.isEmpty()) return def;
return Condition.getCondition(cond).isMet(p);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void announceBar(TabPlayer player, String actionbar) {
public void onJoin(TabPlayer player) {
player.loadPropertyFromConfig(this,"join-actionbar");
String prop = player.getProperty("join-actionbar").getCurrentRawValue();
if (prop.equals("")) return;
if (prop.isEmpty()) return;
announceBar(player,prop);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public BiFunction<TabPlayer,TabPlayer,Boolean> check(TabPlayer viewer, TabPlayer
* @return condition from string
*/
public static AdvancedConditions getCondition(String string) {
if (string == null || string.equals("")) return null;
if (string == null || string.isEmpty()) return null;
if (registeredConditions.containsKey(string))
return registeredConditions.get(string);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class Chat extends TabFeature implements UnLoadable, JoinListener, Comman
private final boolean discordEssX;
private final boolean discordSRV;

@Getter
private final boolean bukkitBridgeChatEnabled;

public Chat(ConfigurationFile config) {
Expand Down Expand Up @@ -104,14 +105,14 @@ public Chat(ConfigurationFile config) {
config.getBoolean("emojis.auto-complete",true),
config.getConfigurationSection("emojis.categories"),
config.getBoolean("emojis./emojis",true),
config.getBoolean("emojis./toggleemoji",true))
config.getBoolean("emojis./toggleemojis",true))
: null;
mentionManager = config.getBoolean("mention.enabled",true)
? new MentionManager(this,
config.getString("mention.input","@%player%"),
ChatUtils.componentToMM(config.getConfigurationSection("mention.output")),
config.getString("mention.sound","BLOCK_NOTE_BLOCK_PLING"),
config.getBoolean("mention./togglemention",true),
config.getBoolean("mention./togglementions",true),
config.getBoolean("mention.output-for-everyone",true),
config.getConfigurationSection("mention.custom-mentions"))
: null;
Expand Down Expand Up @@ -142,7 +143,7 @@ public Chat(ConfigurationFile config) {
cooldownTime = config.getDouble("cooldown",0);

toggleCmd = config.getBoolean("/togglechat",true);
toggled = ChatUtils.registerToggleCmd(toggleCmd,"chat-off","togglechat","chat-status",p->hasChatToggled((TabPlayer) p) ? "Off" : "No");
toggled = ChatUtils.registerToggleCmd(toggleCmd,"chat-off","togglechat","chat-status",p->hasChatToggled((TabPlayer) p) ? "Off" : "On");

ignoreCmd = config.getBoolean("/ignore",true);
if (ignoreCmd) {
Expand Down Expand Up @@ -187,10 +188,6 @@ public boolean hasChatToggled(TabPlayer player) {
return toggled.contains(player.getUniqueId());
}

public boolean isBukkitBridgeChatEnabled() {
return bukkitBridgeChatEnabled;
}

@Override
public void onJoin(@NotNull TabPlayer player) {
if (emojiManager != null && emojiManager.isAutoCompleteEnabled() && !emojiManager.hasCmdToggled(player))
Expand All @@ -200,7 +197,7 @@ public void onJoin(@NotNull TabPlayer player) {
@Override
public boolean onCommand(@NotNull TabPlayer p, String cmd) {
if (cmd.startsWith("/emojis") || cmd.equals("/toggleemojis")) return emojiManager != null && emojiManager.onCommand(p,cmd);
if (cmd.equals("/togglemention")) return mentionManager != null && mentionManager.onCommand(p,cmd);
if (cmd.equals("/togglementions")) return mentionManager != null && mentionManager.onCommand(p,cmd);
if (msgManager != null && (cmd.equals("/togglemsg") || msgManager.isReplyCmd(cmd,false) || msgManager.isMsgCmd(cmd,false)))
return msgManager.onCommand(p,cmd);
if (cmd.equals("/socialspy")) return p.hasPermission("tabadditions.chat.socialspy") && socialSpyManager != null && socialSpyManager.onCommand(p,cmd);
Expand Down Expand Up @@ -334,7 +331,7 @@ public boolean isIgnored(TabPlayer sender, TabPlayer viewer) {

private boolean canSee(TabPlayer sender, TabPlayer viewer, ChatFormat f) {
if (sender == viewer) return true;
if (viewer == null) return f.getChannel().equals("") && f.hasNoViewCondition();
if (viewer == null) return f.getChannel().isEmpty() && f.hasNoViewCondition();
if (!f.getChannel().equals(getFormat(viewer).getChannel())) return false;
return f.isViewConditionMet(sender, viewer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private String filter(String msg) {
}
private String formatItems(TabPlayer sender, String message, boolean offhand) {
String input = offhand ? itemOffHand : itemMainHand;
if (input.equals("") || !message.contains(input)) return message;
if (input.isEmpty() || !message.contains(input)) return message;

ChatItem item = TABAdditions.getInstance().getPlatform().getItem(sender, offhand);
if (item.getType().equals("AIR")) return message.replace(input,itemOutputAir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class ChatItem {

@Getter private final String type;
@Getter private final String name;
@Getter private final int amount;
@Getter private final String nbt;
private final String type;
private final String name;
private final int amount;
private final String nbt;

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ChatUtils {
private static final Pattern tabRGBPattern = Pattern.compile("#[0-9a-fA-F]{6}");

public static int countMatches(String str, String sub) {
if (str == null || str.length() == 0 || sub == null || sub.length() == 0) return 0;
if (str == null || str.isEmpty() || sub == null || sub.isEmpty()) return 0;
int count = 0;
for (int idx = 0; (idx = str.indexOf(sub,idx)) != -1; idx += sub.length()) ++count;
return count;
Expand All @@ -47,11 +47,11 @@ public static String componentToMM(Map<String,Object> component) {
.replace("url","open_url")
.replace("copy","copy_to_clipboard")
.replace("file","open_file");
if (!hover.equals("")) output.append("<hover:show_text:\"").append(hover).append("\">");
if (!click.equals("")) output.append("<click:").append(clickType).append(":\"").append(click).append("\">");
if (!hover.isEmpty()) output.append("<hover:show_text:\"").append(hover).append("\">");
if (!click.isEmpty()) output.append("<click:").append(clickType).append(":\"").append(click).append("\">");
output.append(text);
if (!click.equals("")) output.append("</click>");
if (!hover.equals("")) output.append("</hover>");
if (!click.isEmpty()) output.append("</click>");
if (!hover.isEmpty()) output.append("</hover>");
return output.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void onMsgCommand(TabPlayer sender, String player, String msg, boolean r
sender.sendMessage(reply ? translation.noPlayerToReplyTo : translation.providePlayer,true);
return;
}
if (msg.equals("")) {
if (msg.isEmpty()) {
sender.sendMessage(translation.pmEmpty, true);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import lombok.Getter;
import lombok.experimental.Accessors;

@Getter
public class FormatCommand extends ChatFormat {

@Getter @Accessors(fluent = true)
@Accessors(fluent = true)
private final boolean saveOnReload;
@Getter private final String prefix;
private final String prefix;

public FormatCommand(String name, String displayName, AdvancedConditions condition, AdvancedConditions viewCondition, String channel, String text, boolean saveOnReload, String prefix) {
super(name, displayName, condition, viewCondition, channel, text.replace("%chat-format%",displayName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import me.neznamy.tab.shared.platform.TabPlayer;
import java.util.Map;

@Getter
@AllArgsConstructor
public class EmojiCategory {

@Getter private final String name;
@Getter private final Map<String,String> emojis;
@Getter private final String output;
private final String name;
private final Map<String,String> emojis;
private final String output;

public boolean canUse(TabPlayer p) {
return p.hasPermission("tabadditions.chat.emoji.category."+name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String process(TabPlayer sender, TabPlayer viewer, String msg) {

for (String emoji : emojis.keySet()) {
int count = ChatUtils.countMatches(msg, emoji);
if (count == 0 || emoji.equals("")) continue;
if (count == 0 || emoji.isEmpty()) continue;
if (!category.canUse(sender,emoji)) {
if (untranslate && msg.contains(emojis.get(emoji)))
msg = msg.replace(emojis.get(emoji), emoji);
Expand Down Expand Up @@ -90,7 +90,7 @@ public String process(TabPlayer sender, TabPlayer viewer, String msg) {
}

public String getOutput(EmojiCategory category) {
return category == null || category.getOutput().equals("") ? output : category.getOutput();
return category == null || category.getOutput().isEmpty() ? output : category.getOutput();
}

public int ownedEmojis(TabPlayer p) {
Expand Down Expand Up @@ -122,7 +122,7 @@ public void unloadAutoComplete(TabPlayer p) {
public boolean onCommand(TabPlayer sender, String command) {
if (command.startsWith("/emojis") && emojisCmdEnabled) {
String cat = command.contains(" ") ? command.split(" ")[1] : "";
if (cat.equals("")) {
if (cat.isEmpty()) {
getEmojisCategories(sender);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public MentionManager(Chat chat, String input, String output, String sound, bool

public boolean isMentioned(String msg, TabPlayer sender, TabPlayer viewer) {
String input = plugin.parsePlaceholders(this.input,viewer);
if (input.equals("") || viewer == null) return false;
if (input.isEmpty() || viewer == null) return false;
if (!sender.hasPermission("tabadditions.chat.bypass.togglemention") && hasCmdToggled(viewer)) return false;
if (chat.isIgnored(sender,viewer)) return false;
return msg.toLowerCase().contains(input.toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class Title {

@Getter private final String title;
@Getter private final String subtitle;
private final String title;
private final String subtitle;
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void announceTitle(TabPlayer player, String title) {
public void onJoin(TabPlayer player) {
player.loadPropertyFromConfig(this,"join-title");
String prop = player.getProperty("join-title").getCurrentRawValue();
if (prop.equals("")) return;
if (prop.isEmpty()) return;
announceTitle(player,prop);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public BukkitAudiences getKyori() {
public void sendToDiscord(TabPlayer player, String msg, String channel, List<String> plugins) {
Player p = (Player) player.getPlayer();
if (plugins.contains("DiscordSRV") && isPluginEnabled("DiscordSRV")) sendDiscordSRV(p,msg,channel);
if (plugins.contains("EssentialsX") && isPluginEnabled("EssentialsDiscord") && !channel.equals("")) sendEssentialsX(p,msg);
if (plugins.contains("EssentialsX") && isPluginEnabled("EssentialsDiscord") && !channel.isEmpty()) sendEssentialsX(p,msg);
}
private void sendDiscordSRV(Player p, String msg, String channel) {
DiscordSRV discord = DiscordSRV.getPlugin();
String mainChannel = discord.getMainChatChannel();
String optionalChannel = discord.getOptionalChannel(channel);
discord.processChatMessage(p, msg, msg.equals("") || optionalChannel.equals(mainChannel) ? mainChannel : optionalChannel, false,null);
discord.processChatMessage(p, msg, msg.isEmpty() || optionalChannel.equals(mainChannel) ? mainChannel : optionalChannel, false,null);
}
private void sendEssentialsX(Player p, String msg) {
DiscordService api = plugin.getServer().getServicesManager().load(DiscordService.class);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/chat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mention:
click: "suggest:@%player%"
sound: block.note_block.pling
output-for-everyone: true
/togglemention: true
/togglementions: true
custom-mentions:
staff:
input: "@staff"
Expand All @@ -110,7 +110,7 @@ mention:
emojis:
enabled: true
/emojis: true
/toggleemoji: true
/toggleemojis: true
auto-complete: true #only works on 1.19.4+!
output:
text: "%emoji%"
Expand Down

0 comments on commit 5e6ae68

Please sign in to comment.