mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Merge branch 'master' of https://github.com/Draycia/Carbon into channel-list-update
This commit is contained in:
12 files changed
+97
-66
No files matched your search
@@ -39,14 +39,17 @@ dependencies {
|
||||
compile 'net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-text-minimessage:3.0.0-SNAPSHOT'
|
||||
compile 'de.themoep:minedown-adventure:1.6.1-SNAPSHOT'
|
||||
|
||||
compile 'co.aikar:idb-bukkit:1.0.0-SNAPSHOT'
|
||||
compile 'com.zaxxer:HikariCP:2.4.1'
|
||||
|
||||
compile 'io.github.leonardosnt:bungeechannelapi:1.0.0-SNAPSHOT'
|
||||
compile 'io.lettuce:lettuce-core:6.0.0.M1'
|
||||
|
||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.143'
|
||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
|
||||
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.1.11'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||
|
||||
@@ -43,7 +43,12 @@ public final class CarbonChat extends JavaPlugin {
|
||||
private YamlConfiguration languageConfig;
|
||||
|
||||
public static final LegacyComponentSerializer LEGACY =
|
||||
LegacyComponentSerializer.builder().extractUrls().character('§').build();
|
||||
LegacyComponentSerializer.builder()
|
||||
.extractUrls()
|
||||
.hexColors()
|
||||
.character('§')
|
||||
.useUnusualXRepeatedCharacterHexFormat()
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -60,21 +65,8 @@ public final class CarbonChat extends JavaPlugin {
|
||||
saveResource("language.yml", false);
|
||||
}
|
||||
|
||||
modConfig = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
modConfig.load(new File(getDataFolder(), "moderation.yml"));
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
languageConfig = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
languageConfig.load(new File(getDataFolder(), "language.yml"));
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
loadModConfig();
|
||||
loadLanguage();
|
||||
|
||||
// Setup Adventure
|
||||
adventureManager = new AdventureManager(this);
|
||||
@@ -157,6 +149,22 @@ public final class CarbonChat extends JavaPlugin {
|
||||
pluginManager.registerEvents(new ShadowMuteHandler(this), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
|
||||
loadModConfig();
|
||||
loadLanguage();
|
||||
}
|
||||
|
||||
private void loadModConfig() {
|
||||
modConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "moderation.yml"));
|
||||
}
|
||||
|
||||
private void loadLanguage() {
|
||||
languageConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "language.yml"));
|
||||
}
|
||||
|
||||
private void registerContexts() {
|
||||
getContextManager().register("distance", new DistanceContext());
|
||||
}
|
||||
|
||||
@@ -110,9 +110,9 @@ public abstract class ChatChannel implements ForwardingAudience {
|
||||
* @param user The player who is saying the message.
|
||||
* @param message The message to be sent.
|
||||
*/
|
||||
public abstract void sendMessage(ChatUser user, String message, boolean fromBungee);
|
||||
public abstract Component sendMessage(ChatUser user, String message, boolean fromBungee);
|
||||
|
||||
public abstract void sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromBungee);
|
||||
public abstract Component sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromBungee);
|
||||
|
||||
public abstract void sendComponent(ChatUser user, Component component);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromRemote) {
|
||||
public Component sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromRemote) {
|
||||
updateUserNickname(user);
|
||||
|
||||
// Get player's formatting
|
||||
@@ -99,20 +99,20 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
// Return if cancelled or message is emptied
|
||||
|
||||
if (preFormatEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (preFormatEvent.getMessage().trim().isEmpty()) {
|
||||
return;
|
||||
if (preFormatEvent.isCancelled() || preFormatEvent.getMessage().trim().isEmpty()) {
|
||||
return TextComponent.empty();
|
||||
}
|
||||
|
||||
String displayName;
|
||||
|
||||
if (user.isOnline()) {
|
||||
displayName = user.asPlayer().getDisplayName();
|
||||
if (user.getNickname() != null) {
|
||||
displayName = user.getNickname();
|
||||
} else {
|
||||
displayName = user.asOfflinePlayer().getName();
|
||||
if (user.isOnline()) {
|
||||
displayName = user.asPlayer().getDisplayName();
|
||||
} else {
|
||||
displayName = user.asOfflinePlayer().getName();
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through players who should receive messages in this channel
|
||||
@@ -122,14 +122,10 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
Bukkit.getPluginManager().callEvent(formatEvent);
|
||||
|
||||
// Again, return if cancelled or message is emptied
|
||||
if (formatEvent.isCancelled()) {
|
||||
if (formatEvent.isCancelled() || formatEvent.getMessage().trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (formatEvent.getMessage().trim().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TextComponent formattedMessage = (TextComponent) carbonChat.getAdventureManager().processMessage(formatEvent.getFormat(),
|
||||
"br", "\n",
|
||||
"displayname", displayName,
|
||||
@@ -171,20 +167,19 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
Bukkit.getPluginManager().callEvent(consoleEvent);
|
||||
|
||||
// Log message to console
|
||||
System.out.println(CarbonChat.LEGACY.serialize(consoleEvent.getComponent()));
|
||||
|
||||
// Route message to bungee / discord (if message originates from this server)
|
||||
// Use instanceof and not isOnline, if this message originates from another then the instanceof will
|
||||
// fail, but isOnline may succeed if the player is online on both servers (somehow).
|
||||
if (user.isOnline() && !fromRemote && shouldBungee()) {
|
||||
sendMessageToBungee(user.asPlayer(), consoleEvent.getComponent());
|
||||
}
|
||||
|
||||
return consoleEvent.getComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(ChatUser user, String message, boolean fromRemote) {
|
||||
this.sendMessage(user, this.audiences(), message, fromRemote);
|
||||
public Component sendMessage(ChatUser user, String message, boolean fromRemote) {
|
||||
return this.sendMessage(user, this.audiences(), message, fromRemote);
|
||||
}
|
||||
|
||||
public String getFormat(ChatUser user) {
|
||||
@@ -285,8 +280,6 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
user.sendMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(CarbonChat.LEGACY.serialize(component));
|
||||
}
|
||||
|
||||
public void sendMessageToBungee(Player player, Component component) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import co.aikar.commands.annotation.*;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -39,7 +40,10 @@ public class AliasedChannelCommand extends BaseCommand {
|
||||
"channel", getChatChannel().getName()));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
getChatChannel().sendMessage(user, String.join(" ", args), false);
|
||||
Component component = getChatChannel().sendMessage(user, String.join(" ", args), false);
|
||||
|
||||
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
|
||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import co.aikar.commands.annotation.*;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -31,7 +32,10 @@ public class ChannelCommand extends BaseCommand {
|
||||
"channel", channel.getName()));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
channel.sendMessage(user, String.join(" ", args), false);
|
||||
Component component = channel.sendMessage(user, String.join(" ", args), false);
|
||||
|
||||
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
|
||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,24 +24,31 @@ public class IgnoreCommand extends BaseCommand {
|
||||
|
||||
if (user.isIgnoringUser(targetUser)) {
|
||||
user.setIgnoringUser(targetUser, false);
|
||||
user.sendMessage(processMessage(player, carbonChat.getLanguage().getString("not-ignoring-user")));
|
||||
user.sendMessage(processMessage(player, carbonChat.getLanguage().getString("not-ignoring-user"),
|
||||
"br", "\n", "player", targetUser.asOfflinePlayer().getName()));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
Permission permission = carbonChat.getPermission();
|
||||
String format;
|
||||
|
||||
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.ignore.exempt")) {
|
||||
user.sendMessage(processMessage(player, carbonChat.getLanguage().getString("ignore-exempt")));
|
||||
format = carbonChat.getLanguage().getString("ignore-exempt");
|
||||
} else {
|
||||
user.setIgnoringUser(targetUser, true);
|
||||
user.sendMessage(processMessage(player, carbonChat.getLanguage().getString("ignoring-user")));
|
||||
format = carbonChat.getLanguage().getString("ignoring-user");
|
||||
}
|
||||
|
||||
Component message = processMessage(player, format, "br", "\n",
|
||||
"sender", player.getDisplayName(), "player", targetUser.asOfflinePlayer().getName());
|
||||
|
||||
user.sendMessage(message);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Component processMessage(Player player, String message) {
|
||||
return carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n");
|
||||
private Component processMessage(Player player, String message, String... args) {
|
||||
return carbonChat.getAdventureManager().processMessageWithPapi(player, message, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package net.draycia.carbon.listeners;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -13,7 +14,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BukkitChatListener implements Listener {
|
||||
|
||||
@@ -68,10 +68,22 @@ public class BukkitChatListener implements Listener {
|
||||
event.getRecipients().clear();
|
||||
|
||||
if (event.isAsynchronous()) {
|
||||
selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||
|
||||
event.setFormat(CarbonChat.LEGACY.serialize(component)
|
||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||
|
||||
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
|
||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
||||
|
||||
if (carbonChat.getConfig().getBoolean("show-tips")) {
|
||||
carbonChat.getLogger().info("Tip: Sync chat event! I cannot set the message format due to this. :(");
|
||||
carbonChat.getLogger().info("Tip: To 'solve' this, do a binary search and see which plugin is triggering");
|
||||
carbonChat.getLogger().info("Tip: sync chat events and causing this, and let that plugin author know.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.draycia.carbon.listeners;
|
||||
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -23,8 +23,7 @@ public class UserFormattingListener implements Listener {
|
||||
suppressFormatting(event);
|
||||
} else {
|
||||
// Swap the &-style codes for minimessage-compatible strings
|
||||
event.setMessage(MiniMessage.get().serialize(
|
||||
LegacyComponentSerializer.legacyAmpersand().deserialize(event.getMessage())));
|
||||
event.setMessage(MiniMessage.get().serialize(CarbonChat.LEGACY.deserialize(event.getMessage())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.draycia.carbon.messaging.impl.BungeeMessageService;
|
||||
import net.draycia.carbon.messaging.impl.EmptyMessageService;
|
||||
import net.draycia.carbon.messaging.impl.RedisMessageService;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
@@ -124,7 +125,12 @@ public class MessageManager {
|
||||
ChatUser user = carbonChat.getUserService().wrap(uuid);
|
||||
|
||||
if (channel != null) {
|
||||
channel.sendComponent(user, gsonSerializer.deserialize(byteArray.readUTF()));
|
||||
Component component = gsonSerializer.deserialize(byteArray.readUTF());
|
||||
|
||||
channel.sendComponent(user, component);
|
||||
|
||||
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
|
||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -76,16 +76,15 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNickname(String nickname, boolean fromRemote) {
|
||||
if (nickname != null) {
|
||||
Component component = carbonChat.getAdventureManager().processMessage(nickname);
|
||||
nickname = CarbonChat.LEGACY.serialize(component);
|
||||
}
|
||||
|
||||
final String newNickname = nickname;
|
||||
public void setNickname(String newNickname, boolean fromRemote) {
|
||||
this.nickname = newNickname;
|
||||
|
||||
if (isOnline()) {
|
||||
if (newNickname != null) {
|
||||
Component component = carbonChat.getAdventureManager().processMessage(nickname);
|
||||
newNickname = CarbonChat.LEGACY.serialize(component);
|
||||
}
|
||||
|
||||
this.asPlayer().setDisplayName(newNickname);
|
||||
|
||||
if (carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
||||
@@ -98,7 +97,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
carbonChat.getMessageManager().sendMessage("nickname-reset", this.getUUID(), (byteArray) -> {});
|
||||
} else {
|
||||
carbonChat.getMessageManager().sendMessage("nickname", this.getUUID(), (byteArray) -> {
|
||||
byteArray.writeUTF(newNickname);
|
||||
byteArray.writeUTF(this.nickname);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,16 +45,12 @@ default:
|
||||
# -1 to disable, 0 to set to world only, 1+ to set the distance.
|
||||
# EG. distance: 250 would require the players to be within 250 blocks to see each other's messages
|
||||
distance: -1
|
||||
# mcmmo-party only works when the CarbonChatMCMMO addon is installed.
|
||||
# Requires both players to be in the same party to see the message.
|
||||
mcmmo-party: false
|
||||
# worldguard-region only works when the CarbonChatWorldGuard addon is installed.
|
||||
# Requires both players to be in the same region to see the message.
|
||||
worldguard-region: false
|
||||
# towny-town only works when the CarbonChatTowny addon is installed.
|
||||
# Requires both players to be in the same town to see the message.
|
||||
towny-town: false
|
||||
# filter only works when CarbonChatModeration is installed.
|
||||
# Modifies / prevents messages depending on how filters are setup.
|
||||
filter: true
|
||||
# requires a minimum balance to chat. 0 to disable. Requires a vault-compatible economy plugin
|
||||
|
||||
Reference in new issue
Block a user