Skip to content

Commit

Permalink
Merge pull request #173 from Brikster/dev
Browse files Browse the repository at this point in the history
Release 2.19.11
  • Loading branch information
Brikster authored Jun 16, 2022
2 parents 5645f59 + 7388db5 commit 563c3dc
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group = 'ru.mrbrikster'
version = '2.19.10'
version = '2.19.11'
}

subprojects {
Expand Down
23 changes: 19 additions & 4 deletions spigot/src/main/java/ru/mrbrikster/chatty/chat/ChatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ru.mrbrikster.chatty.Chatty;
import ru.mrbrikster.chatty.api.events.ChattyMessageEvent;
import ru.mrbrikster.chatty.bungee.BungeeBroadcaster;
import ru.mrbrikster.chatty.chat.event.ChattyAsyncPlayerChatEvent;
import ru.mrbrikster.chatty.dependencies.DependencyManager;
import ru.mrbrikster.chatty.dependencies.PlayerTagManager;
import ru.mrbrikster.chatty.dependencies.VaultHook;
Expand All @@ -32,6 +33,7 @@
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.UnknownFormatConversionException;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -97,9 +99,17 @@ public void execute(@NotNull Listener listener, @NotNull Event event) {
private void onChat(AsyncPlayerChatEvent event) {
final Player player = event.getPlayer();

Pair<Chat, String> chatMessagePair = getChat(player, event.getMessage());
Chat chat = chatMessagePair.getA();
String message = chatMessagePair.getB();
Chat chat;
String message;

if (event instanceof ChattyAsyncPlayerChatEvent) {
chat = ((ChattyAsyncPlayerChatEvent) event).getChat();
message = event.getMessage();
} else {
Pair<Chat, String> chatMessagePair = getChat(player, event.getMessage());
chat = chatMessagePair.getA();
message = chatMessagePair.getB();
}

if (chat == null) {
event.setCancelled(true);
Expand Down Expand Up @@ -384,7 +394,12 @@ private void performJsonMessage(AsyncPlayerChatEvent event, Chat chat) {
String strippedHexFormat = TextUtil.stripHex(format);

if (!strippedHexFormat.equals(format)) {
event.setFormat(strippedHexFormat);
try {
event.setFormat(strippedHexFormat);
}
catch (UnknownFormatConversionException exception) {
//do nothing if strippedHexFormat is broken
}
}
}

Expand Down
31 changes: 25 additions & 6 deletions spigot/src/main/java/ru/mrbrikster/chatty/chat/ChatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import net.amoebaman.util.ArrayWrapper;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import ru.mrbrikster.baseplugin.commands.BukkitCommand;
import ru.mrbrikster.baseplugin.config.Configuration;
import ru.mrbrikster.baseplugin.config.ConfigurationNode;
import ru.mrbrikster.chatty.Chatty;
import ru.mrbrikster.chatty.chat.Chat.ChatBuilder;
import ru.mrbrikster.chatty.chat.event.ChattyAsyncPlayerChatEvent;
import ru.mrbrikster.chatty.util.Sound;

import lombok.Getter;
Expand All @@ -20,10 +23,7 @@
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.regex.Pattern;

public class ChatManager {
Expand Down Expand Up @@ -121,8 +121,27 @@ public void handle(CommandSender sender, String label, String[] args) {
}

if (chat.isWriteAllowed((Player) sender)) {
jsonStorage.setProperty((Player) sender, "chat", new JsonPrimitive(chat.getName()));
sender.sendMessage(Chatty.instance().messages().get("chat-command.chat-switched").replace("{chat}", chat.getDisplayName()));
if (args.length == 0) {
jsonStorage.setProperty((Player) sender, "chat", new JsonPrimitive(chat.getName()));
sender.sendMessage(Chatty.instance().messages().get("chat-command.chat-switched").replace("{chat}", chat.getDisplayName()));
} else {
Bukkit.getScheduler().runTaskAsynchronously(Chatty.instance(), () -> {
AsyncPlayerChatEvent event = new ChattyAsyncPlayerChatEvent(
(Player) sender,
String.join(" ", args),
chat);

Bukkit.getPluginManager().callEvent(event);

if (!event.isCancelled()) {
for (Player recipient : event.getRecipients()) {
recipient.sendMessage(String.format(event.getFormat(),
event.getPlayer().getDisplayName(),
event.getMessage()));
}
}
});
}
} else {
sender.sendMessage(Chatty.instance().messages().get("chat-command.no-chat-permission"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.mrbrikster.chatty.chat.event;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.jetbrains.annotations.NotNull;
import ru.mrbrikster.chatty.chat.Chat;

import lombok.Getter;

import java.util.HashSet;

public class ChattyAsyncPlayerChatEvent extends AsyncPlayerChatEvent {

private @Getter final Chat chat;

/**.
* @param who the chat sender
* @param message the message sent
* @param chat the chat to send message
*/
public ChattyAsyncPlayerChatEvent(@NotNull Player who, @NotNull String message, Chat chat) {
super(true, who, message, new HashSet<>(Bukkit.getOnlinePlayers()));

this.chat = chat;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import ru.mrbrikster.chatty.Chatty;
import ru.mrbrikster.chatty.chat.JsonStorage;
import ru.mrbrikster.chatty.dependencies.PlayerTagManager;
import ru.mrbrikster.chatty.json.fanciful.FancyMessage;
import ru.mrbrikster.chatty.json.FormattedMessage;
import ru.mrbrikster.chatty.moderation.AdvertisementModerationMethod;
import ru.mrbrikster.chatty.moderation.ModerationManager;
import ru.mrbrikster.chatty.moderation.SwearModerationMethod;
Expand Down Expand Up @@ -119,8 +119,8 @@ protected void handlePrivateMessage(@NotNull CommandSender sender, @NotNull Comm
recipientFormat = TextUtil.stripHex(recipientFormat);
recipient.sendMessage(recipientFormat);
} else {
new FancyMessage(recipientFormat)
.send(recipient, sender instanceof Player ? ((Player) sender) : null);
FormattedMessage formattedMessage = new FormattedMessage(recipientFormat);
formattedMessage.toFancyMessage().send((Player) recipient, (Player) sender);

String soundName = configuration.getNode("pm.sound").getAsString(null);
if (soundName != null) {
Expand Down
2 changes: 1 addition & 1 deletion spigot/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ general:
# *cooldown* - message cooldown in seconds (bypass permission - chatty.cooldown.<chat>).
# *money* - message price (depends on Vault).
# *permission* - check permissions for this chat? Default: true.
# *command* - Command that is used to switch to chat to use it by default if symbol is not specified. Default: empty.
# *command* - Command that is used to switch chat to use it by default if symbol is not specified OR to write at chat: /<command> <message>. Default: empty.
# *aliases* - Aliases for command. Default: empty.
chats:
local:
Expand Down
16 changes: 8 additions & 8 deletions spigot/src/main/resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ messages:
not-enough-money: '&cYou need {money} money to send message in this chat.'

clearchat-command:
usage: '&cUsing: /{label} [all]'
usage: '&cUsage: /{label} [all]'
clear-chat-for-all: '&aChat cleared by {player}.'
clear-chat-for-yourself: '&aChat cleared.'

msg-command:
usage: '&cUsing: /{label} <player> <message>'
usage: '&cUsage: /{label} <player> <message>'
player-not-found: '&cPlayer not found.'
cannot-message-yourself: '&cYou cannot message yourself.'

reply-command:
usage: '&cUsing: /{label} <message>'
usage: '&cUsage: /{label} <message>'
target-not-found: '&cPlayer not found.'

ignore-command:
usage: '&cUsing: /{label} <player>'
usage: '&cUsage: /{label} <player>'
player-not-found: '&cPlayer not found.'
ignore-list: '&eYou''re now ignoring: &6{players}.'
ignore-list-delimiter: '&8, &6'
Expand All @@ -34,17 +34,17 @@ messages:
cannot-ignore-yourself: '&cYou cannot ignore yourself.'

swears-command:
usage: '&cUsing: /{label} add <word>'
usage: '&cUsage: /{label} add <word>'
add-word: '&aYou added word {word} to whitelist.'

chat-command:
usage: '&cUsing: /{label} <chat>'
usage: '&cUsage: /{label} <chat>'
chat-not-found: '&cChat with this name was not found.'
chat-switched: '&aYou have switched to chat "{chat}".'
no-chat-permission: '&cYou don''have permission for this chat.'

prefix-command:
usage: '&cUsing: /{label} <player> <<prefix>|clear>'
usage: '&cUsage: /{label} <player> <<prefix>|clear>'
no-permissions-others: '&cYou don''t have permission to changing prefixes of other players.'
player-not-found: '&cPlayer not found.'
length-limit-min: '&cPrefix cannot be shorter than {limit} symbols.'
Expand All @@ -53,7 +53,7 @@ messages:
prefix-set: '&aYou set prefix &r{prefix} &afor player {player}.'

suffix-command:
usage: '&cUsing: /{label} <player> <<suffix>|clear>'
usage: '&cUsage: /{label} <player> <<suffix>|clear>'
no-permissions-others: '&cYou don''t have permission to changing suffixes of other players.'
player-not-found: '&cPlayer not found.'
length-limit-min: '&cSuffix cannot be shorter than {limit} symbols.'
Expand Down

0 comments on commit 563c3dc

Please sign in to comment.