Skip to content

Commit

Permalink
3rd Attempt at fixing #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Refrac committed May 26, 2024
1 parent 6ed13f5 commit 30a0bbf
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 32 deletions.
2 changes: 1 addition & 1 deletion SimpleStaffChat-Bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.refracdevelopment</groupId>
<artifactId>SimpleStaffChat</artifactId>
<version>4.3.2</version>
<version>4.3.2-beta</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public static Component adventureTranslate(String message) {
return component;
}

/**
* Translate a string from legacy to Adventure API.
*
* @param input The string that needs translating.
* @return String which is in an adventure format.
*
* @Author: EternalCodeTeam (https://github.com/EternalCodeTeam/ChatFormatter/)
*/
private static String legacyToAdventure(String input) {
String result = HEX_PATTERN.matcher(input).replaceAll(matchResult -> {
String hex = matchResult.group(1);
Expand Down
2 changes: 1 addition & 1 deletion SimpleStaffChat-Spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.refracdevelopment</groupId>
<artifactId>SimpleStaffChat</artifactId>
<version>4.3.2</version>
<version>4.3.2-beta</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onJoin(PlayerJoinEvent event) {
if (!player.hasPermission(Permissions.STAFFCHAT_JOIN))
return;

RyMessageUtils.broadcast(player, Permissions.STAFFCHAT_SEE, this.plugin.getSettings().JOIN_FORMAT);
RyMessageUtils.sendStaffChat(player, Permissions.STAFFCHAT_SEE, this.plugin.getSettings().JOIN_FORMAT);

RyMessageUtils.sendConsole(true, this.plugin.getSettings().JOIN_FORMAT);
DiscordImpl.sendJoin(JoinType.JOIN, player);
Expand All @@ -52,7 +52,7 @@ public void onQuit(PlayerQuitEvent event) {
if (!player.hasPermission(Permissions.STAFFCHAT_QUIT))
return;

RyMessageUtils.broadcast(player, Permissions.STAFFCHAT_SEE, this.plugin.getSettings().QUIT_FORMAT);
RyMessageUtils.sendStaffChat(player, Permissions.STAFFCHAT_SEE, this.plugin.getSettings().QUIT_FORMAT);

RyMessageUtils.sendConsole(true, this.plugin.getSettings().QUIT_FORMAT);
DiscordImpl.sendJoin(JoinType.LEAVE, player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@ public void sendStaffChat(CommandSender commandSender, String format, String mes
return;
}

SimpleStaffChat.getInstance().getServer().getOnlinePlayers().forEach(onlinePlayer -> {
if (onlinePlayer.hasPermission(Permissions.STAFFCHAT_SEE) && !staffChatMuted.contains(onlinePlayer.getUniqueId())) {
RyMessageUtils.sendPlayer(onlinePlayer, format
.replace("%server%", SimpleStaffChat.getInstance().getSettings().SERVER_NAME)
.replace("%player%", player.getName())
);
}
});
RyMessageUtils.sendStaffChat(player, Permissions.STAFFCHAT_SEE, format
.replace("%server%", SimpleStaffChat.getInstance().getSettings().SERVER_NAME)
.replace("%player%", player.getName())
);

RyMessageUtils.sendConsole(true, format
.replace("%server%", SimpleStaffChat.getInstance().getSettings().SERVER_NAME)
Expand Down Expand Up @@ -80,14 +76,10 @@ public void sendDevChat(CommandSender commandSender, String format, String messa
return;
}

SimpleStaffChat.getInstance().getServer().getOnlinePlayers().forEach(onlinePlayer -> {
if (onlinePlayer.hasPermission(Permissions.DEVCHAT_SEE) && !devChatMuted.contains(onlinePlayer.getUniqueId())) {
RyMessageUtils.sendPlayer(onlinePlayer, format
.replace("%server%", SimpleStaffChat.getInstance().getSettings().SERVER_NAME)
.replace("%player%", player.getName())
);
}
});
RyMessageUtils.sendDevChat(player, Permissions.DEVCHAT_SEE, format
.replace("%server%", SimpleStaffChat.getInstance().getSettings().SERVER_NAME)
.replace("%player%", player.getName())
);

RyMessageUtils.sendConsole(true, format
.replace("%server%", SimpleStaffChat.getInstance().getSettings().SERVER_NAME)
Expand Down Expand Up @@ -127,14 +119,10 @@ public void sendAdminChat(CommandSender commandSender, String format, String mes
return;
}

SimpleStaffChat.getInstance().getServer().getOnlinePlayers().forEach(onlinePlayer -> {
if (onlinePlayer.hasPermission(Permissions.ADMINCHAT_SEE) && !adminChatMuted.contains(onlinePlayer.getUniqueId())) {
RyMessageUtils.sendPlayer(onlinePlayer, format
.replace("%server%", SimpleStaffChat.getInstance().getSettings().SERVER_NAME)
.replace("%player%", player.getName())
);
}
});
RyMessageUtils.sendAdminChat(player, Permissions.ADMINCHAT_SEE, format
.replace("%server%", SimpleStaffChat.getInstance().getSettings().SERVER_NAME)
.replace("%player%", player.getName())
);

RyMessageUtils.sendConsole(true, format
.replace("%server%", SimpleStaffChat.getInstance().getSettings().SERVER_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Setter;
import me.clip.placeholderapi.PlaceholderAPI;
import me.refracdevelopment.simplestaffchat.SimpleStaffChat;
import me.refracdevelopment.simplestaffchat.utilities.Methods;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand Down Expand Up @@ -206,6 +207,8 @@ 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) {
message = Placeholders.setPlaceholders(sender, message);

if (getAudiences() != null) {
getAudiences().sender(sender).sendMessage(translate(message));
} else {
Expand All @@ -221,6 +224,8 @@ public static void sendSender(@NotNull CommandSender sender, @NotNull String mes
*/
public static void sendSender(@NotNull CommandSender sender, @NotNull String... messages) {
for (String message : messages) {
message = Placeholders.setPlaceholders(sender, message);

if (getAudiences() != null) {
getAudiences().sender(sender).sendMessage(translate(message));
} else {
Expand All @@ -237,6 +242,8 @@ public static void sendSender(@NotNull CommandSender sender, @NotNull String...
*/
public static void sendSender(@NotNull CommandSender sender, @NotNull List<String> messages) {
for (String message : messages) {
message = Placeholders.setPlaceholders(sender, message);

if (getAudiences() != null) {
getAudiences().sender(sender).sendMessage(translate(message));
} else {
Expand Down Expand Up @@ -304,9 +311,47 @@ public static void sendConsole(boolean prefix, List<String> messages) {
* @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) {
public static void sendStaffChat(Player player, String permission, String message) {
for (Player online : Bukkit.getOnlinePlayers()) {
if (online.hasPermission(permission)) {
if (online.hasPermission(permission) && !Methods.getStaffChatMuted().contains(online.getUniqueId())) {
if (getAudiences() != null) {
getAudiences().player(online).sendMessage(translate(player, message));
} else {
online.sendMessage(translate(player, message));
}
}
}
}

/**
* 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 sendDevChat(Player player, String permission, String message) {
for (Player online : Bukkit.getOnlinePlayers()) {
if (online.hasPermission(permission) && !Methods.getDevChatMuted().contains(online.getUniqueId())) {
if (getAudiences() != null) {
getAudiences().player(online).sendMessage(translate(player, message));
} else {
online.sendMessage(translate(player, message));
}
}
}
}

/**
* 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 sendAdminChat(Player player, String permission, String message) {
for (Player online : Bukkit.getOnlinePlayers()) {
if (online.hasPermission(permission) && !Methods.getAdminChatMuted().contains(online.getUniqueId())) {
if (getAudiences() != null) {
getAudiences().player(online).sendMessage(translate(player, message));
} else {
Expand Down
2 changes: 1 addition & 1 deletion SimpleStaffChat-Velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.refracdevelopment</groupId>
<artifactId>SimpleStaffChat</artifactId>
<version>4.3.2</version>
<version>4.3.2-beta</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ public static Component translate(String message) {
return component;
}

/**
* Translate a string from legacy to Adventure API.
*
* @param input The string that needs translating.
* @return String which is in an adventure format.
*
* @Author: EternalCodeTeam (https://github.com/EternalCodeTeam/ChatFormatter/)
*/
private static String legacyToAdventure(String input) {
String result = HEX_PATTERN.matcher(input).replaceAll(matchResult -> {
String hex = matchResult.group(1);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.refracdevelopment</groupId>
<artifactId>SimpleStaffChat</artifactId>
<version>4.3.2</version>
<version>4.3.2-beta</version>
<packaging>pom</packaging>

<name>SimpleStaffChat</name>
Expand Down

0 comments on commit 30a0bbf

Please sign in to comment.