mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +00:00
Scrap LP hook and fix bugs
This commit is contained in:
1 parent
3a6f51ddc6
commit
9f98f6a42d
12 files changed
+97
-148
No files matched your search
@@ -2,10 +2,8 @@ package net.draycia.simplechat;
|
|||||||
|
|
||||||
import de.themoep.minedown.MineDown;
|
import de.themoep.minedown.MineDown;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
|
||||||
import net.draycia.simplechat.listeners.*;
|
import net.draycia.simplechat.listeners.*;
|
||||||
import net.draycia.simplechat.managers.*;
|
import net.draycia.simplechat.managers.*;
|
||||||
import net.draycia.simplechat.managers.luckperms.LuckPermsHookManager;
|
|
||||||
import net.draycia.simplechat.storage.UserService;
|
import net.draycia.simplechat.storage.UserService;
|
||||||
import net.draycia.simplechat.storage.impl.JSONUserService;
|
import net.draycia.simplechat.storage.impl.JSONUserService;
|
||||||
import net.draycia.simplechat.storage.impl.MySQLUserService;
|
import net.draycia.simplechat.storage.impl.MySQLUserService;
|
||||||
@@ -15,7 +13,6 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeCordComponentSerializer;
|
import net.kyori.adventure.text.serializer.bungeecord.BungeeCordComponentSerializer;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@@ -32,7 +29,6 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
private PluginMessageManager pluginMessageManager;
|
private PluginMessageManager pluginMessageManager;
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
private ChannelManager channelManager;
|
private ChannelManager channelManager;
|
||||||
private LuckPermsHookManager luckPermsHookManager = null;
|
|
||||||
private RedisManager redisManager = null;
|
private RedisManager redisManager = null;
|
||||||
|
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@@ -63,10 +59,6 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
commandManager = new CommandManager(this);
|
commandManager = new CommandManager(this);
|
||||||
channelManager = new ChannelManager(this);
|
channelManager = new ChannelManager(this);
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("LuckPerms")) {
|
|
||||||
luckPermsHookManager = new LuckPermsHookManager(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getConfig().getBoolean("redis.enabled")) {
|
if (getConfig().getBoolean("redis.enabled")) {
|
||||||
redisManager = new RedisManager(this);
|
redisManager = new RedisManager(this);
|
||||||
}
|
}
|
||||||
@@ -150,10 +142,6 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
return pluginMessageManager;
|
return pluginMessageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LuckPermsHookManager getLuckPermsHookManager() {
|
|
||||||
return luckPermsHookManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RedisManager getRedisManager() {
|
public RedisManager getRedisManager() {
|
||||||
return redisManager;
|
return redisManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ public abstract class ChatChannel {
|
|||||||
/**
|
/**
|
||||||
* @return If this is the default (typically Global) channel players use when they're in no other channel.
|
* @return If this is the default (typically Global) channel players use when they're in no other channel.
|
||||||
*/
|
*/
|
||||||
public abstract boolean isDefault();
|
public abstract Boolean isDefault();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If this channel can be toggled off and if players can ignore player messages in this channel.
|
* @return If this channel can be toggled off and if players can ignore player messages in this channel.
|
||||||
*/
|
*/
|
||||||
public abstract boolean isIgnorable();
|
public abstract Boolean isIgnorable();
|
||||||
|
|
||||||
public abstract boolean shouldBungee();
|
public abstract Boolean shouldBungee();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The name of this channel.
|
* @return The name of this channel.
|
||||||
@@ -44,7 +44,7 @@ public abstract class ChatChannel {
|
|||||||
/**
|
/**
|
||||||
* @return The distance other players must be within to the sender to see messages in this channel.
|
* @return The distance other players must be within to the sender to see messages in this channel.
|
||||||
*/
|
*/
|
||||||
public abstract double getDistance();
|
public abstract Double getDistance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The message to be sent to the player when switching to this channel.
|
* @return The message to be sent to the player when switching to this channel.
|
||||||
@@ -71,21 +71,21 @@ public abstract class ChatChannel {
|
|||||||
|
|
||||||
public abstract String getCannotUseMessage();
|
public abstract String getCannotUseMessage();
|
||||||
|
|
||||||
public abstract boolean firstMatchingGroup();
|
public abstract Boolean firstMatchingGroup();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If the player can use this channel.
|
* @return If the player can use this channel.
|
||||||
*/
|
*/
|
||||||
public abstract boolean canPlayerUse(ChatUser user);
|
public abstract Boolean canPlayerUse(ChatUser user);
|
||||||
|
|
||||||
public abstract boolean canPlayerSee(ChatUser sender, ChatUser target, boolean checkSpying);
|
public abstract Boolean canPlayerSee(ChatUser sender, ChatUser target, boolean checkSpying);
|
||||||
|
|
||||||
public abstract List<ChatUser> getAudience(ChatUser user);
|
public abstract List<ChatUser> getAudience(ChatUser user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If the channel should forward its formatting / formatted message to other servers
|
* @return If the channel should forward its formatting / formatted message to other servers
|
||||||
*/
|
*/
|
||||||
public boolean shouldForwardFormatting() {
|
public Boolean shouldForwardFormatting() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+61
-38
@@ -35,11 +35,12 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getDiscordFormatting() {
|
private String getDiscordFormatting() {
|
||||||
return getFormats().getOrDefault("discord-to-mc", "<gray>[<blue>Discord<gray>] <username><white>: <message>");
|
return getFormats().getOrDefault("discord-to-mc",
|
||||||
|
"<gray>[<blue>Discord<gray>] <username><white>: <message>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlayerUse(ChatUser user) {
|
public Boolean canPlayerUse(ChatUser user) {
|
||||||
return user.asPlayer().hasPermission("simplechat.channels." + getName() + ".use");
|
return user.asPlayer().hasPermission("simplechat.channels." + getName() + ".use");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +80,8 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
"message", formatEvent.getMessage());
|
"message", formatEvent.getMessage());
|
||||||
|
|
||||||
// Call custom chat event
|
// Call custom chat event
|
||||||
ChatComponentEvent componentEvent = new ChatComponentEvent(user, this, formattedMessage, formatEvent.getMessage(), getAudience(user));
|
ChatComponentEvent componentEvent = new ChatComponentEvent(user, this, formattedMessage,
|
||||||
|
formatEvent.getMessage(), getAudience(user));
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(componentEvent);
|
Bukkit.getPluginManager().callEvent(componentEvent);
|
||||||
|
|
||||||
@@ -100,7 +102,8 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
chatUser.sendMessage(componentEvent.getComponent());
|
chatUser.sendMessage(componentEvent.getComponent());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
prefix = prefix.replace("<color>", "<color:" + chatUser.getChannelSettings(this).getColor().asHexString() + ">");
|
prefix = prefix.replace("<color>", "<color:" +
|
||||||
|
chatUser.getChannelSettings(this).getColor().asHexString() + ">");
|
||||||
String format = formatEvent.getFormat();
|
String format = formatEvent.getFormat();
|
||||||
|
|
||||||
TextComponent newFormat = (TextComponent)simpleChat.processMessage(format,
|
TextComponent newFormat = (TextComponent)simpleChat.processMessage(format,
|
||||||
@@ -117,7 +120,8 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatComponentEvent newEvent = new ChatComponentEvent(user, this, newFormat, formatEvent.getMessage(), Collections.singletonList(chatUser), true);
|
ChatComponentEvent newEvent = new ChatComponentEvent(user, this, newFormat,
|
||||||
|
formatEvent.getMessage(), Collections.singletonList(chatUser), true);
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(newEvent);
|
Bukkit.getPluginManager().callEvent(newEvent);
|
||||||
|
|
||||||
@@ -197,7 +201,7 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return getFormat(group);
|
return getFormat(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canPlayerSee(ChatUser sender, ChatUser target, boolean checkSpying) {
|
public Boolean canPlayerSee(ChatUser sender, ChatUser target, boolean checkSpying) {
|
||||||
Player targetPlayer = target.asPlayer();
|
Player targetPlayer = target.asPlayer();
|
||||||
|
|
||||||
if (checkSpying && targetPlayer.hasPermission("simplechat.spy." + getName())) {
|
if (checkSpying && targetPlayer.hasPermission("simplechat.spy." + getName())) {
|
||||||
@@ -245,7 +249,8 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
public Map<String, String> getFormats() {
|
public Map<String, String> getFormats() {
|
||||||
HashMap<String, String> formats = new HashMap<>();
|
HashMap<String, String> formats = new HashMap<>();
|
||||||
|
|
||||||
ConfigurationSection section = simpleChat.getConfig().getConfigurationSection("channels").getConfigurationSection(getKey());
|
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
|
||||||
|
ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
|
||||||
ConfigurationSection formatSection = section.getConfigurationSection("formats");
|
ConfigurationSection formatSection = section.getConfigurationSection("formats");
|
||||||
|
|
||||||
if (formatSection == null) {
|
if (formatSection == null) {
|
||||||
@@ -261,84 +266,84 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextColor getColor() {
|
public TextColor getColor() {
|
||||||
return TextColor.fromHexString((String) getSetting("color"));
|
return TextColor.fromHexString(getSetting("color"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFormat(String group) {
|
public String getFormat(String group) {
|
||||||
return getFormats().getOrDefault(group, getFormats().getOrDefault("default", "<white><%player_displayname%<white>> <message>"));
|
return getFormats().getOrDefault(group, getFormats().getOrDefault("default",
|
||||||
|
"<white><%player_displayname%<white>> <message>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDefault() {
|
public Boolean isDefault() {
|
||||||
return (Boolean) getSetting("default");
|
return getSetting("default") == null ? false : getSetting("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isIgnorable() {
|
public Boolean isIgnorable() {
|
||||||
return (Boolean)getSetting("ignorable");
|
return getSetting("ignorable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldBungee() {
|
public Boolean shouldBungee() {
|
||||||
return (Boolean) getSetting("should-bungee");
|
return getSetting("should-bungee");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
String name = (String) getSetting("name");
|
String name = getSetting("name");
|
||||||
return name == null ? key : name;
|
return name == null ? key : name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getDistance() {
|
public Double getDistance() {
|
||||||
return (Integer) getSetting("distance");
|
return this.getSetting("distance");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSwitchMessage() {
|
public String getSwitchMessage() {
|
||||||
return (String) getSetting("switch-message");
|
return getSetting("switch-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSwitchOtherMessage() {
|
public String getSwitchOtherMessage() {
|
||||||
return (String) getSetting("switch-other-message");
|
return getSetting("switch-other-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getToggleOffMessage() {
|
public String getToggleOffMessage() {
|
||||||
return (String) getSetting("toggle-off-message");
|
return getSetting("toggle-off-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getToggleOnMessage() {
|
public String getToggleOnMessage() {
|
||||||
return (String) getSetting("toggle-on-message");
|
return getSetting("toggle-on-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getToggleOtherOnMessage() {
|
public String getToggleOtherOnMessage() {
|
||||||
return (String) getSetting("toggle-other-on");
|
return getSetting("toggle-other-on");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getToggleOtherOffMessage() {
|
public String getToggleOtherOffMessage() {
|
||||||
return (String) getSetting("toggle-other-off");
|
return getSetting("toggle-other-off");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCannotUseMessage() {
|
public String getCannotUseMessage() {
|
||||||
return (String) getSetting("cannot-use-channel");
|
return getSetting("cannot-use-channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldForwardFormatting() {
|
public Boolean shouldForwardFormatting() {
|
||||||
return (Boolean) getSetting("forward-format");
|
return getSetting("forward-format");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean firstMatchingGroup() {
|
public Boolean firstMatchingGroup() {
|
||||||
return (Boolean) getSetting("first-matching-group");
|
return getSetting("first-matching-group");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -352,20 +357,38 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return itemPatterns;
|
return itemPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getSetting(String key) {
|
private <T> T getSetting(String key) {
|
||||||
ConfigurationSection section = simpleChat.getConfig().getConfigurationSection("channels").getConfigurationSection(getKey());
|
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
|
||||||
|
ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
|
||||||
|
|
||||||
if (section.contains(key)) {
|
if (section != null && section.contains(key)) {
|
||||||
return section.get(key);
|
return (T)section.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
|
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
|
||||||
|
|
||||||
if (defaultSection.contains(key)) {
|
if (defaultSection != null && defaultSection.contains(key)) {
|
||||||
return defaultSection.get(key);
|
return (T)defaultSection.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> T getSetting(String key, T def) {
|
||||||
|
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
|
||||||
|
ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
|
||||||
|
|
||||||
|
if (section != null && section.contains(key)) {
|
||||||
|
return (T)section.get(key, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
|
||||||
|
|
||||||
|
if (defaultSection != null && defaultSection.contains(key)) {
|
||||||
|
return (T)defaultSection.get(key, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -375,7 +398,7 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAliases() {
|
public String getAliases() {
|
||||||
String aliases = (String)getSetting("aliases");
|
String aliases = getSetting("aliases");
|
||||||
|
|
||||||
if (aliases == null) {
|
if (aliases == null) {
|
||||||
return getKey();
|
return getKey();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.draycia.simplechat.events;
|
|||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
import net.draycia.simplechat.util.Registry;
|
import net.draycia.simplechat.util.Registry;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@@ -27,6 +28,8 @@ public class ChannelRegisterEvent extends Event {
|
|||||||
private Registry<ChatChannel> registry;
|
private Registry<ChatChannel> registry;
|
||||||
|
|
||||||
public ChannelRegisterEvent(List<ChatChannel> registeredChannels, Registry<ChatChannel> registry) {
|
public ChannelRegisterEvent(List<ChatChannel> registeredChannels, Registry<ChatChannel> registry) {
|
||||||
|
super(Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.registeredChannels = registeredChannels;
|
this.registeredChannels = registeredChannels;
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.draycia.simplechat.events;
|
|||||||
|
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@@ -24,6 +25,8 @@ public class ChannelSwitchEvent extends Event {
|
|||||||
private ChatUser user;
|
private ChatUser user;
|
||||||
|
|
||||||
public ChannelSwitchEvent(ChatChannel channel, ChatUser user) {
|
public ChannelSwitchEvent(ChatChannel channel, ChatUser user) {
|
||||||
|
super(Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -3,6 +3,7 @@ package net.draycia.simplechat.events;
|
|||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@@ -27,7 +28,7 @@ public class ChatComponentEvent extends Event implements Cancellable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ChatComponentEvent(ChatUser user, ChatChannel chatChannel, TextComponent component, String originalMessage, List<ChatUser> recipients, boolean customPlayerFormat) {
|
public ChatComponentEvent(ChatUser user, ChatChannel chatChannel, TextComponent component, String originalMessage, List<ChatUser> recipients, boolean customPlayerFormat) {
|
||||||
super(true);
|
super(Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.draycia.simplechat.events;
|
|||||||
|
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@@ -18,7 +19,7 @@ public class ChatFormatEvent extends Event implements Cancellable {
|
|||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public ChatFormatEvent(ChatUser user, ChatChannel chatChannel, String format, String message) {
|
public ChatFormatEvent(ChatUser user, ChatChannel chatChannel, String format, String message) {
|
||||||
super(true);
|
super(Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.draycia.simplechat.events;
|
|||||||
|
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@@ -27,6 +28,8 @@ public class PrivateMessageEvent extends Event {
|
|||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
public PrivateMessageEvent(ChatUser sender, ChatUser target, Component senderComponent, Component targetComponent, String message) {
|
public PrivateMessageEvent(ChatUser sender, ChatUser target, Component senderComponent, Component targetComponent, String message) {
|
||||||
|
super(Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.senderComponent = senderComponent;
|
this.senderComponent = senderComponent;
|
||||||
|
|||||||
@@ -37,11 +37,17 @@ public class ChannelManager {
|
|||||||
channels.add(channel);
|
channels.add(channel);
|
||||||
|
|
||||||
if (channel.isDefault()) {
|
if (channel.isDefault()) {
|
||||||
|
simpleChat.getLogger().info("Default channel found: " + channel.getName());
|
||||||
defaultChannelKey = channel.getKey();
|
defaultChannelKey = channel.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ChatChannel channel : channels) {
|
||||||
|
simpleChat.getLogger().info("Registering channel: " + channel.getName());
|
||||||
|
getRegistry().register(channel.getKey(), channel);
|
||||||
|
}
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(channels, getRegistry()));
|
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(channels, getRegistry()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-46
@@ -1,46 +0,0 @@
|
|||||||
package net.draycia.simplechat.managers.luckperms;
|
|
||||||
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
|
||||||
import net.draycia.simplechat.managers.luckperms.contexts.CanSeeChannelCalculator;
|
|
||||||
import net.luckperms.api.LuckPerms;
|
|
||||||
import net.luckperms.api.context.ContextCalculator;
|
|
||||||
import net.luckperms.api.context.ContextManager;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class LuckPermsHookManager {
|
|
||||||
|
|
||||||
private final SimpleChat simpleChat;
|
|
||||||
private final ContextManager contextManager;
|
|
||||||
private final List<ContextCalculator<Player>> registeredCalculators = new ArrayList<>();
|
|
||||||
|
|
||||||
public LuckPermsHookManager(SimpleChat simpleChat) {
|
|
||||||
this.simpleChat = simpleChat;
|
|
||||||
|
|
||||||
LuckPerms luckPerms = this.simpleChat.getServer().getServicesManager().load(LuckPerms.class);
|
|
||||||
|
|
||||||
if (luckPerms == null) {
|
|
||||||
throw new IllegalStateException("LuckPerms API not loaded.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.contextManager = luckPerms.getContextManager();
|
|
||||||
|
|
||||||
register(() -> new CanSeeChannelCalculator(simpleChat));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void register(Supplier<ContextCalculator<Player>> calculatorSupplier) {
|
|
||||||
ContextCalculator<Player> calculator = calculatorSupplier.get();
|
|
||||||
|
|
||||||
this.contextManager.registerCalculator(calculator);
|
|
||||||
this.registeredCalculators.add(calculator);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unregisterContexts() {
|
|
||||||
this.registeredCalculators.forEach(this.contextManager::unregisterCalculator);
|
|
||||||
this.registeredCalculators.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-41
@@ -1,41 +0,0 @@
|
|||||||
package net.draycia.simplechat.managers.luckperms.contexts;
|
|
||||||
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
|
||||||
import net.luckperms.api.context.ContextCalculator;
|
|
||||||
import net.luckperms.api.context.ContextConsumer;
|
|
||||||
import net.luckperms.api.context.ImmutableContextSet;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class CanSeeChannelCalculator implements ContextCalculator<Player> {
|
|
||||||
|
|
||||||
private static final String KEY = "can-see-channel";
|
|
||||||
|
|
||||||
private SimpleChat simpleChat;
|
|
||||||
|
|
||||||
public CanSeeChannelCalculator(SimpleChat simpleChat) {
|
|
||||||
this.simpleChat = simpleChat;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void calculate(Player player, ContextConsumer consumer) {
|
|
||||||
for (ChatChannel channel : simpleChat.getChannelManager().getRegistry().values()) {
|
|
||||||
boolean canUse = channel.canPlayerUse(simpleChat.getUserService().wrap(player));
|
|
||||||
|
|
||||||
consumer.accept(KEY + ":" + channel.getKey(), canUse ? "true" : "false");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public net.luckperms.api.context.ContextSet estimatePotentialContexts() {
|
|
||||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
|
||||||
|
|
||||||
for (ChatChannel channel : simpleChat.getChannelManager().getRegistry().values()) {
|
|
||||||
builder.add(KEY + ":" + channel.getKey(), "true");
|
|
||||||
builder.add(KEY + ":" + channel.getKey(), "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+9
-1
@@ -118,13 +118,20 @@ public class MySQLUserService extends UserService {
|
|||||||
List<DbRow> channelSettings = database.getResults("SELECT * from sc_channel_settings WHERE uuid = ?;", uuid.toString());
|
List<DbRow> channelSettings = database.getResults("SELECT * from sc_channel_settings WHERE uuid = ?;", uuid.toString());
|
||||||
List<DbRow> ignoredUsers = database.getResults("SELECT * from sc_ignored_users WHERE uuid = ?;", uuid.toString());
|
List<DbRow> ignoredUsers = database.getResults("SELECT * from sc_ignored_users WHERE uuid = ?;", uuid.toString());
|
||||||
|
|
||||||
user.setSelectedChannel(simpleChat.getChannelManager().getRegistry().get(users.getString("channel")));
|
ChatChannel channel = simpleChat.getChannelManager().getChannelOrDefault(users.getString("channel"));
|
||||||
|
|
||||||
|
if (channel != null) {
|
||||||
|
user.setSelectedChannel(channel);
|
||||||
|
}
|
||||||
|
|
||||||
user.setMuted(users.<Boolean>get("muted"));
|
user.setMuted(users.<Boolean>get("muted"));
|
||||||
user.setShadowMuted(users.<Boolean>get("shadowmuted"));
|
user.setShadowMuted(users.<Boolean>get("shadowmuted"));
|
||||||
user.setSpyingWhispers(users.<Boolean>get("spyingwhispers"));
|
user.setSpyingWhispers(users.<Boolean>get("spyingwhispers"));
|
||||||
|
|
||||||
for (DbRow channelSetting : channelSettings) {
|
for (DbRow channelSetting : channelSettings) {
|
||||||
ChatChannel chatChannel = simpleChat.getChannelManager().getRegistry().get(channelSetting.getString("channel"));
|
ChatChannel chatChannel = simpleChat.getChannelManager().getRegistry().get(channelSetting.getString("channel"));
|
||||||
|
|
||||||
|
if (chatChannel != null) {
|
||||||
UserChannelSettings settings = user.getChannelSettings(chatChannel);
|
UserChannelSettings settings = user.getChannelSettings(chatChannel);
|
||||||
|
|
||||||
settings.setSpying(channelSetting.<Boolean>get("spying"));
|
settings.setSpying(channelSetting.<Boolean>get("spying"));
|
||||||
@@ -136,6 +143,7 @@ public class MySQLUserService extends UserService {
|
|||||||
settings.setColor(TextColor.fromHexString(color));
|
settings.setColor(TextColor.fromHexString(color));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (DbRow ignoredUser : ignoredUsers) {
|
for (DbRow ignoredUser : ignoredUsers) {
|
||||||
user.setIgnoringUser(UUID.fromString(ignoredUser.getString("user")), true);
|
user.setIgnoringUser(UUID.fromString(ignoredUser.getString("user")), true);
|
||||||
|
|||||||
Reference in new issue
Block a user