Skip to content

Commit

Permalink
Add %empty% placeholder for disabling messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Refrac committed Aug 13, 2024
1 parent 1c16227 commit d4cd2ec
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 42 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ SimpleStaffChat is a plugin that allows you to send messages to your staff membe

### Issue Reporting/Support

Please report all issues/support questions to the [Issues](https://github.com/RefracDevelopment/SimpleStaffChat2/issues) tab or [Discord](https://discord.gg/EFeSKPg739).
Please report all issues/support questions to the [Issues](https://github.com/RefracDevelopment/SimpleStaffChat2/issues)
tab or [Discord](https://discord.gg/EFeSKPg739).

### Suggestions

Suggestion can be posted in [Issues](https://github.com/RefracDevelopment/SimpleStaffChat2/issues) or [Discord](https://discord.gg/EFeSKPg739) which is reviewed by project maintainers, but feel free to make a pull request to add cool features without posting there!
Suggestion can be posted in [Issues](https://github.com/RefracDevelopment/SimpleStaffChat2/issues)
or [Discord](https://discord.gg/EFeSKPg739) which is reviewed by project maintainers, but feel free to make a pull
request to add cool features without posting there!

### License

Please view the [LICENSE](LICENSE) file for more information on the license of this source code.

[icon from flaticon](https://www.flaticon.com/)
4 changes: 2 additions & 2 deletions SimpleStaffChat-Bungee/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package me.refracdevelopment.simplestaffchat.config;

import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import lombok.Getter;
import me.refracdevelopment.simplestaffchat.SimpleStaffChat;
import me.refracdevelopment.simplestaffchat.utilities.chat.RyMessageUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.util.*;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

@UtilityClass
public class Methods {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ public static Component adventureTranslate(String message) {
* Translate a string from legacy to Adventure API.
*
* @param input The string that needs translating.
* @return String which is in an adventure format.
*
* @return String which is in an adventure format.
* @Author: EternalCodeTeam (https://github.com/EternalCodeTeam/ChatFormatter/)
*/
private static String legacyToAdventure(String input) {
Expand Down Expand Up @@ -183,6 +182,9 @@ public static List<Component> adventureTranslate(List<String> messages) {
* @param message The message you wish to send the player.
*/
public static void sendPlayer(ProxiedPlayer player, String message) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

if (getAudiences() != null) {
getAudiences().player(player).sendMessage(adventureTranslate(player, message));
} else {
Expand All @@ -199,6 +201,9 @@ public static void sendPlayer(ProxiedPlayer player, String message) {
*/
public static void sendPlayer(ProxiedPlayer player, String... messages) {
for (String message : messages) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

if (getAudiences() != null) {
getAudiences().player(player).sendMessage(adventureTranslate(player, message));
} else {
Expand All @@ -216,6 +221,9 @@ public static void sendPlayer(ProxiedPlayer player, String... messages) {
*/
public static void sendPlayer(ProxiedPlayer player, List<String> messages) {
for (String message : messages) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

if (getAudiences() != null) {
getAudiences().player(player).sendMessage(adventureTranslate(player, message));
} else {
Expand All @@ -232,6 +240,9 @@ public static void sendPlayer(ProxiedPlayer player, List<String> messages) {
* @param message The message you wish to send to the sender.
*/
public static void sendSender(CommandSender sender, String message) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

message = Placeholders.setPlaceholders(sender, message);

if (getAudiences() != null) {
Expand All @@ -250,6 +261,9 @@ public static void sendSender(CommandSender sender, String message) {
*/
public static void sendSender(CommandSender sender, String... messages) {
for (String message : messages) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

message = Placeholders.setPlaceholders(sender, message);

if (getAudiences() != null) {
Expand All @@ -269,6 +283,9 @@ public static void sendSender(CommandSender sender, String... messages) {
*/
public static void sendSender(CommandSender sender, List<String> messages) {
for (String message : messages) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

message = Placeholders.setPlaceholders(sender, message);

if (getAudiences() != null) {
Expand Down Expand Up @@ -343,6 +360,9 @@ public static void sendConsole(boolean prefix, List<String> messages) {
* @param message The message you wish to be broadcast.
*/
public static void broadcast(ProxiedPlayer player, String permission, String message) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

for (ProxiedPlayer online : ProxyServer.getInstance().getPlayers()) {
if (online.hasPermission(permission)) {
if (getAudiences() != null) {
Expand All @@ -362,6 +382,9 @@ public static void broadcast(ProxiedPlayer player, String permission, String mes
* @param message The message you wish to be broadcast.
*/
public static void broadcast(ProxiedPlayer player, String message) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

if (getAudiences() != null) {
getAudiences().players().sendMessage(adventureTranslate(player, message));
} else {
Expand All @@ -376,6 +399,9 @@ public static void broadcast(ProxiedPlayer player, String message) {
* @param message The message you wish to be sent to the players.
*/
public static void broadcast(String message) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

if (getAudiences() != null) {
getAudiences().players().sendMessage(adventureTranslate(message));
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package me.refracdevelopment.simplestaffchat.manager.config;

import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import me.refracdevelopment.simplestaffchat.SimpleStaffChat;
import me.refracdevelopment.simplestaffchat.utilities.chat.RyMessageUtils;
import org.bukkit.Bukkit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.*;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

@UtilityClass
public final class Methods {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.experimental.UtilityClass;
import me.refracdevelopment.simplestaffchat.SimpleStaffChat;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

@UtilityClass
public class Placeholders {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static Component translate(Player player, String message) {
message = Placeholders.setPlaceholders(player, message);

if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
message = PlaceholderAPI.setPlaceholders(player, message);
message = PlaceholderAPI.setPlaceholders(player, message);

return translate(message);
}
Expand Down Expand Up @@ -112,8 +112,7 @@ public static Component translate(String message) {
* Translate a string from legacy to Adventure API.
*
* @param input The string that needs translating.
* @return String which is in an adventure format.
*
* @return String which is in an adventure format.
* @Author: EternalCodeTeam (https://github.com/EternalCodeTeam/ChatFormatter/)
*/
private static String legacyToAdventure(String input) {
Expand Down Expand Up @@ -153,7 +152,10 @@ public static List<Component> translate(@NotNull List<String> messages) {
* @param message The message you wish to send the player.
*/
public static void sendPlayer(@NotNull Player player, @NotNull String message) {
player.sendMessage(translate(player, message));
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%") || message.isEmpty())
return;

player.sendMessage(translate(player, getPrefix() + message));
}

/**
Expand All @@ -164,7 +166,10 @@ public static void sendPlayer(@NotNull Player player, @NotNull String message) {
*/
public static void sendPlayer(@NotNull Player player, @NotNull String... messages) {
for (String message : messages) {
player.sendMessage(translate(player, message));
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

player.sendMessage(translate(player, getPrefix() + message));
}
}

Expand All @@ -176,7 +181,10 @@ public static void sendPlayer(@NotNull Player player, @NotNull String... message
*/
public static void sendPlayer(Player player, @NotNull List<String> messages) {
for (String message : messages) {
player.sendMessage(translate(player, message));
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

player.sendMessage(translate(player, getPrefix() + message));
}
}

Expand All @@ -187,9 +195,12 @@ public static void sendPlayer(Player player, @NotNull List<String> messages) {
* @param message The message you wish to send to the sender.
*/
public static void sendSender(@NotNull CommandSender sender, @NotNull String message) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

message = Placeholders.setPlaceholders(sender, message);

sender.sendMessage(translate(message));
sender.sendMessage(translate(getPrefix() + message));
}

/**
Expand All @@ -200,9 +211,12 @@ public static void sendSender(@NotNull CommandSender sender, @NotNull String mes
*/
public static void sendSender(@NotNull CommandSender sender, @NotNull String... messages) {
for (String message : messages) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

message = Placeholders.setPlaceholders(sender, message);

sender.sendMessage(translate(message));
sender.sendMessage(translate(getPrefix() + message));
}
}

Expand All @@ -214,9 +228,12 @@ public static void sendSender(@NotNull CommandSender sender, @NotNull String...
*/
public static void sendSender(@NotNull CommandSender sender, @NotNull List<String> messages) {
for (String message : messages) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

message = Placeholders.setPlaceholders(sender, message);

sender.sendMessage(translate(message));
sender.sendMessage(translate(getPrefix() + message));
}
}

Expand Down Expand Up @@ -305,6 +322,24 @@ public static void sendAdminChat(Player player, String permission, String messag
}
}

/**
* Send a permission based broadcast to all online players.
*
* @param player The player who is making the broadcast.
* @param permission The permission the players require to see the broadcast.
* @param message The message you wish to be broadcast.
*/
public static void broadcast(Player player, String permission, String message) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

for (Player online : Bukkit.getOnlinePlayers()) {
if (online.hasPermission(permission)) {
online.sendMessage(translate(player, "%prefix%" + message));
}
}
}

/**
* Send a permission based broadcast to all online players.
*
Expand All @@ -313,9 +348,12 @@ public static void sendAdminChat(Player player, String permission, String messag
* @param message The message you wish to be broadcast.
*/
public static void broadcast(Player player, Permission permission, String message) {
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

for (Player online : Bukkit.getOnlinePlayers()) {
if (online.hasPermission(permission)) {
online.sendMessage(translate(player, message));
online.sendMessage(translate(player, "%prefix%" + message));
}
}
}
Expand All @@ -326,7 +364,12 @@ public static void broadcast(Player player, Permission permission, String messag
* @param message The message you wish to be sent to the players.
*/
public static void broadcast(String message) {
Bukkit.getConsoleSender().sendMessage(translate(message));
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

for (Player online : Bukkit.getOnlinePlayers()) {
online.sendMessage(translate("%prefix%" + message));
}
}

/**
Expand All @@ -336,7 +379,12 @@ public static void broadcast(String message) {
* @param message The message you wish to be sent to players.
*/
public static void broadcast(Player player, String message) {
Bukkit.getConsoleSender().sendMessage(translate(player, message));
if (message.equalsIgnoreCase("%empty%") || message.contains("%empty%"))
return;

for (Player online : Bukkit.getOnlinePlayers()) {
online.sendMessage(translate(player, "%prefix%" + message));
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions SimpleStaffChat-Velocity/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import com.velocitypowered.api.plugin.PluginContainer;
import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import lombok.Getter;
import me.refracdevelopment.simplestaffchat.SimpleStaffChat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import me.refracdevelopment.simplestaffchat.SimpleStaffChat;
import me.refracdevelopment.simplestaffchat.utilities.chat.RyMessageUtils;

import java.util.*;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

@UtilityClass
public class Methods {
Expand Down
Loading

0 comments on commit d4cd2ec

Please sign in to comment.