Skip to content

Commit

Permalink
5.4.5
Browse files Browse the repository at this point in the history
Fixed proximity chat
Fixed spam filter and discord webhooks being sent twice sometimes.
Please remove - msg from msg command aliases inside your config
  • Loading branch information
Emibergo02 committed Nov 5, 2024
1 parent 3900daf commit 2a5e1b5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {


group = 'dev.unnm3d'
version = '5.4.2'
version = '5.4.5'


repositories {
Expand Down Expand Up @@ -36,7 +36,7 @@ dependencies {
implementation 'xyz.xenondevs.invui:inventory-access-r19:1.35'
implementation 'xyz.xenondevs.invui:inventory-access-r20:1.35'
implementation 'xyz.xenondevs.invui:inventory-access-r21:1.35'
implementation 'dev.jorel:commandapi-bukkit-shade:9.5.3'
implementation 'dev.jorel:commandapi-bukkit-shade:9.6.1'
implementation 'com.github.Anon8281:UniversalScheduler:0.1.6'


Expand Down
8 changes: 7 additions & 1 deletion src/main/java/dev/unnm3d/redischat/RedisChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import dev.unnm3d.redischat.api.DataManager;
import dev.unnm3d.redischat.channels.ChannelCommand;
import dev.unnm3d.redischat.channels.ChannelManager;
import dev.unnm3d.redischat.chat.*;
import dev.unnm3d.redischat.chat.ComponentProvider;
import dev.unnm3d.redischat.chat.PlaceholderManager;
import dev.unnm3d.redischat.chat.RedisChatPAPI;
import dev.unnm3d.redischat.chat.listeners.ChatListenerWithPriority;
import dev.unnm3d.redischat.chat.listeners.JoinQuitManager;
import dev.unnm3d.redischat.chat.listeners.UtilsListener;
Expand Down Expand Up @@ -374,6 +376,10 @@ private void loadCommandAPICommand(CommandAPICommand commandAPICommand) {
}

CommandAPI.unregister(commandAPICommand.getName(), true);
for (String alias : commandAPICommand.getAliases()) {
if (alias.equals(commandAPICommand.getName())) continue;
CommandAPI.unregister(alias, true);
}
commandAPICommand.register();
registeredCommands.add(commandAPICommand);
getLogger().info("Command " + commandAPICommand.getName() + " registered on CommandAPI!");
Expand Down
42 changes: 19 additions & 23 deletions src/main/java/dev/unnm3d/redischat/channels/ChannelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -137,23 +136,17 @@ public void broadcastMessage(Channel channel, String message) {
/**
* Send a message to a specific ChannelAudience
*
* @param player The player that is sending the message
* @param receiver The receiver audience of the message
* @param message The message to be sent
* @param player The player that is sending the message
* @param currentChannel The receiver channel audience of the message
* @param message The message to be sent
*/
public void outgoingMessage(CommandSender player, ChannelAudience receiver, @NotNull String message) {
//Get channel or public channel by default
final Optional<Channel> currentChannel = getChannel(receiver.getName(), player);
if (currentChannel.isEmpty()) {
plugin.getLogger().warning("Channel not found for: " + receiver.getName());
return;
}
public void outgoingMessage(CommandSender player, Channel currentChannel, @NotNull String message) {

ChatMessage chatMessage = new ChatMessage(
new ChannelAudience(AudienceType.PLAYER, player.getName()),
currentChannel.get().getFormat(),
currentChannel.getFormat(),
message,
receiver
currentChannel
);

//Filter and send filter message if present
Expand Down Expand Up @@ -192,7 +185,10 @@ public void outgoingMessage(CommandSender player, ChannelAudience receiver, @Not
chatMessage.setFormat(MiniMessage.miniMessage().serialize(event.getFormat()));
chatMessage.setContent(MiniMessage.miniMessage().serialize(event.getContent()));

if (currentChannel.get().getProximityDistance() >= 0) {// Send to local server
if (!chatMessage.getSender().isDiscord())
plugin.getDiscordHook().sendDiscordMessage(chatMessage);

if (currentChannel.getProximityDistance() >= 0) {// Send to local server
sendGenericChat(chatMessage);
return;
}
Expand All @@ -210,7 +206,7 @@ public void outgoingMessage(CommandSender player, ChannelAudience receiver, @Not
public void outgoingMessage(CommandSender player, @NotNull final String finalMessage) {
CompletableFuture.runAsync(() -> {
String channelName = plugin.getChannelManager().getActiveChannel(player.getName());
ChannelAudience audience;
Channel audience;
String message = finalMessage;

if (plugin.config.enableStaffChat &&
Expand All @@ -222,12 +218,12 @@ public void outgoingMessage(CommandSender player, @NotNull final String finalMes
}

if (channelName == null) {
audience = new ChannelAudience(KnownChatEntities.GENERAL_CHANNEL.toString());
audience = getPublicChannel(player);
} else if (channelName.equals(KnownChatEntities.VOID_CHAT.toString())) {
getComponentProvider().sendMessage(player, plugin.messages.channelNoPermission);
return;
} else {
audience = new ChannelAudience(channelName);
audience = getChannel(channelName, player).orElse(getPublicChannel(player));
}

if (plugin.config.debug) {
Expand Down Expand Up @@ -317,8 +313,6 @@ public void sendGenericChat(@NotNull ChatMessage chatMessage) {
getComponentProvider().logComponent(miniMessage.deserialize(
chatMessage.getFormat().replace("{message}", chatMessage.getContent())));

if (!chatMessage.getSender().isDiscord())
plugin.getDiscordHook().sendDiscordMessage(chatMessage);

for (Player recipient : recipients) {
final FilterResult result = filterManager.filterMessage(recipient, chatMessage, AbstractFilter.Direction.INCOMING);
Expand Down Expand Up @@ -374,10 +368,12 @@ public void sendGenericChat(@NotNull ChatMessage chatMessage) {

private boolean checkProximity(Player recipient, ChatMessage chatMessage) {
if (chatMessage.getReceiver().getProximityDistance() <= 0) return true;
final Player sender = Bukkit.getPlayer(chatMessage.getSender().getName());
if (sender == null) return false;
if (!sender.getWorld().equals(recipient.getWorld())) return false;
return !(sender.getLocation().distance(recipient.getLocation()) > chatMessage.getReceiver().getProximityDistance());
final Optional<? extends Player> sender = plugin.getServer().getOnlinePlayers().stream()
.filter(p -> p.getName().equals(chatMessage.getSender().getName()))
.findAny();
if (sender.isEmpty()) return false;
if (!sender.get().getWorld().equals(recipient.getWorld())) return false;
return sender.get().getLocation().distance(recipient.getLocation()) < chatMessage.getReceiver().getProximityDistance();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.unnm3d.redischat.chat.filters.incoming;

import de.exlll.configlib.Comment;
import de.exlll.configlib.Configuration;
import dev.unnm3d.redischat.RedisChat;
import dev.unnm3d.redischat.api.objects.AudienceType;
Expand Down Expand Up @@ -54,14 +53,12 @@ public FilterResult applyWithPrevious(CommandSender receiver, @NotNull ChatMessa
public static class IgnorePlayerFilterProperties extends FiltersConfig.FilterSettings {
private boolean ignoreChannelMessages;
private boolean sendWarnWhenIgnoring;
@Comment("Do not send more than one warning message per player every x messages ignored")
private int warnAgainMessages;


public IgnorePlayerFilterProperties() {
super(true, 4, Set.of(AudienceType.PLAYER, AudienceType.CHANNEL), Set.of());
this.ignoreChannelMessages = true;
this.sendWarnWhenIgnoring = true;
this.warnAgainMessages = 5;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import dev.unnm3d.redischat.Permissions;
import dev.unnm3d.redischat.RedisChat;
import dev.unnm3d.redischat.chat.filters.AbstractFilter;
import dev.unnm3d.redischat.chat.filters.FilterResult;
import dev.unnm3d.redischat.api.objects.Channel;
import dev.unnm3d.redischat.api.objects.ChatMessage;
import dev.unnm3d.redischat.chat.filters.AbstractFilter;
import dev.unnm3d.redischat.chat.filters.FilterResult;
import dev.unnm3d.redischat.settings.FiltersConfig;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
Expand All @@ -26,8 +26,9 @@ public FilterResult applyWithPrevious(CommandSender sender, @NotNull ChatMessage
if (!message.getReceiver().isChannel()) return new FilterResult(message, false, Optional.empty());

if (!sender.hasPermission(Permissions.BYPASS_RATE_LIMIT.getPermission())) {
Optional<Channel> channel = plugin.getChannelManager().getChannel(message.getReceiver().getName(), null);
if (channel.isPresent() && plugin.getDataManager().isRateLimited(sender.getName(), channel.get())) {
final Channel channel = plugin.getChannelManager().getChannel(message.getReceiver().getName(), null)
.orElse(plugin.getChannelManager().getPublicChannel(null));
if (channel != null && plugin.getDataManager().isRateLimited(sender.getName(), channel)) {
return new FilterResult(message, true, Optional.of(
plugin.getComponentProvider().parse(sender,
plugin.messages.rate_limited,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/unnm3d/redischat/settings/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public final class Config implements ConfigValidator {
public boolean interactiveChatNostalgia = true;
@Comment("Command aliases (works for msg, mail, reply, staffchat and channel)")
public Map<String, List<String>> commandAliases = new HashMap<>(Map.of(
"msg", List.of("rmsg", "whisper", "msg", "pm", "w"),
"msg", List.of("rmsg", "whisper", "tell", "w"),
"rmail", List.of("mail", "mails"),
"reply", List.of("r"),
"channel", List.of("ch", "channels"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/unnm3d/redischat/settings/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public final class Messages {
public String muted_player = "<yellow>RedisChat</yellow> <gray>»</gray> <aqua>You muted %player% on channel %channel%!</aqua>";
public String unmuted_player = "<yellow>RedisChat</yellow> <gray>»</gray> <aqua>You unmuted %player% on channel %channel%!</aqua>";
public String muted_on_channel = "<yellow>RedisChat</yellow> <gray>»</gray> <aqua>You've been muted in this channel (%channel%)!</aqua>";
public String ignored_player_receiver = "<click:run_command:'/ignore list'><hover:show_text:'Click to see ignored players'><color:#545454>Ignored message</color></hover></click>";
public String ignored_player_receiver = "<click:run_command:'/ignore list'><hover:show_text:'Click to see ignored players'><color:#545454>Ignored message from %player%</color></hover></click>";
public String ignored_player_sender = "<click:run_command:'/ignore list'><color:#545454>You are ignoring this player, Click to see ignored players</color></click>";
public String invalid_color = "<yellow>RedisChat</yellow> <gray>»</gray> <red>Invalid color!</red>";
public String color_set= "<yellow>RedisChat</yellow> <gray>»</gray> <green>You successfully set your chat color!</green>";
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/dev/unnm3d/redischat/JsonTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public void testChannelSerialization() {
.rateLimit(10)
.rateLimitPeriod(1000)
.discordWebhook("webhook")
.proximityDistance(-1)
.proximityDistance(50)
.filtered(false)
.permission("perm1")
.notificationSound("sound")
.build();
Channel nc2 = gson.fromJson(gson.toJson(nc), Channel.class);
assertEquals(nc, nc2);
System.out.println(nc);
System.out.println(nc2);
System.out.println(nc.getProximityDistance());
System.out.println(nc2.getProximityDistance());
}

@Test
Expand Down

0 comments on commit 2a5e1b5

Please sign in to comment.