mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Human pass over channels
This commit is contained in:
12 files changed
+200
-122
No files matched your search
@@ -13,12 +13,16 @@ import java.util.*;
|
||||
|
||||
public class ChannelRegistry implements Registry<ChatChannel> {
|
||||
|
||||
private final Map<String, ChatChannel> registry = new HashMap<>();
|
||||
private final List<AliasedChannelCommand> channelCommands = new ArrayList<>();
|
||||
@NonNull
|
||||
private final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
|
||||
|
||||
@NonNull
|
||||
private final List<@NonNull AliasedChannelCommand> channelCommands = new ArrayList<>();
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelRegistry(CarbonChat carbonChat) {
|
||||
public ChannelRegistry(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@@ -32,7 +36,7 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
||||
channelCommands.add(command);
|
||||
|
||||
if (value instanceof Listener) {
|
||||
Bukkit.getPluginManager().registerEvents((Listener)value, carbonChat);
|
||||
Bukkit.getPluginManager().registerEvents((Listener) value, carbonChat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +45,7 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Collection<ChatChannel> values() {
|
||||
public Collection<@NonNull ChatChannel> values() {
|
||||
return registry.values();
|
||||
}
|
||||
|
||||
@@ -56,7 +60,7 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
||||
registry.clear();
|
||||
|
||||
for (AliasedChannelCommand command : channelCommands) {
|
||||
carbonChat.getLogger().info("Unregistering command for channel: " + command.getChatChannel().getName());
|
||||
carbonChat.getLogger().info("Unregistering command for channel: " + command.getChatChannel().getName());
|
||||
CommandAPI.unregister(command.getCommandName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,120 +17,137 @@ public abstract class ChatChannel implements ForwardingAudience {
|
||||
/**
|
||||
* @return The color that represents this channel. Optionally used in formatting.
|
||||
*/
|
||||
public abstract @Nullable TextColor getChannelColor(ChatUser user);
|
||||
@Nullable
|
||||
public abstract TextColor getChannelColor(@NonNull ChatUser user);
|
||||
|
||||
/**
|
||||
* @return The MiniMessage styled format for the group in this channel.
|
||||
*/
|
||||
public abstract @Nullable String getFormat(String group);
|
||||
@Nullable
|
||||
public abstract String getFormat(@NonNull String group);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
public abstract Boolean isIgnorable();
|
||||
public abstract boolean isIgnorable();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return If this channel should be synced cross server
|
||||
*
|
||||
* @deprecated Use {@link #isCrossServer()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract Boolean shouldBungee();
|
||||
public abstract boolean shouldBungee();
|
||||
|
||||
/**
|
||||
* @return If this channel should be synced cross server
|
||||
*/
|
||||
public abstract Boolean isCrossServer();
|
||||
public abstract boolean isCrossServer();
|
||||
|
||||
/**
|
||||
* @return The name of this channel.
|
||||
*/
|
||||
@NonNull
|
||||
public abstract String getName();
|
||||
|
||||
@NonNull
|
||||
public abstract String getKey();
|
||||
|
||||
@Nullable
|
||||
public abstract @Nullable String getMessagePrefix();
|
||||
public abstract String getMessagePrefix();
|
||||
|
||||
public abstract @Nullable String getAliases();
|
||||
@Nullable
|
||||
public abstract String getAliases();
|
||||
|
||||
/**
|
||||
* @return The message to be sent to the player when switching to this channel.
|
||||
*/
|
||||
public abstract @Nullable String getSwitchMessage();
|
||||
@Nullable
|
||||
public abstract String getSwitchMessage();
|
||||
|
||||
public abstract @Nullable String getSwitchOtherMessage();
|
||||
@Nullable
|
||||
public abstract String getSwitchOtherMessage();
|
||||
|
||||
public abstract @Nullable String getSwitchFailureMessage();
|
||||
@Nullable
|
||||
public abstract String getSwitchFailureMessage();
|
||||
|
||||
public abstract @Nullable String getCannotIgnoreMessage();
|
||||
@Nullable
|
||||
public abstract String getCannotIgnoreMessage();
|
||||
|
||||
/**
|
||||
* @return The message to be send to the player when toggling this channel off.
|
||||
*/
|
||||
|
||||
public abstract @Nullable String getToggleOffMessage();
|
||||
@Nullable
|
||||
public abstract String getToggleOffMessage();
|
||||
|
||||
/**
|
||||
* @return The message to be send to the player when toggling this channel on.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract String getToggleOnMessage();
|
||||
|
||||
public abstract @Nullable String getToggleOnMessage();
|
||||
@Nullable
|
||||
public abstract String getToggleOtherOnMessage();
|
||||
|
||||
public abstract @Nullable String getToggleOtherOnMessage();
|
||||
@Nullable
|
||||
public abstract String getToggleOtherOffMessage();
|
||||
|
||||
public abstract @Nullable String getToggleOtherOffMessage();
|
||||
@Nullable
|
||||
public abstract String getCannotUseMessage();
|
||||
|
||||
public abstract @Nullable String getCannotUseMessage();
|
||||
public abstract boolean primaryGroupOnly();
|
||||
|
||||
public abstract Boolean primaryGroupOnly();
|
||||
public abstract boolean honorsRecipientList();
|
||||
|
||||
public abstract Boolean honorsRecipientList();
|
||||
public abstract boolean permissionGroupMatching();
|
||||
|
||||
public abstract Boolean permissionGroupMatching();
|
||||
public abstract boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target);
|
||||
|
||||
public abstract boolean testContext(ChatUser sender, ChatUser target);
|
||||
@Nullable
|
||||
public abstract Object getContext(@NonNull String key);
|
||||
|
||||
public abstract @Nullable Object getContext(String key);
|
||||
|
||||
public abstract @NonNull List<String> getGroupOverrides();
|
||||
@NonNull
|
||||
public abstract List<@NonNull String> getGroupOverrides();
|
||||
|
||||
/**
|
||||
* @return If the player can use this channel.
|
||||
*/
|
||||
public abstract Boolean canPlayerUse(ChatUser user);
|
||||
public abstract boolean canPlayerUse(@NonNull ChatUser user);
|
||||
|
||||
public abstract @NonNull Boolean canPlayerSee(ChatUser sender, ChatUser target, boolean checkSpying);
|
||||
public abstract boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying);
|
||||
|
||||
public abstract @NonNull Boolean canPlayerSee(ChatUser target, boolean checkSpying);
|
||||
public abstract boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying);
|
||||
|
||||
/**
|
||||
* @return If the channel should forward its formatting / formatted message to other servers
|
||||
*/
|
||||
public Boolean shouldForwardFormatting() {
|
||||
public boolean shouldForwardFormatting() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract @NonNull List<Pattern> getItemLinkPatterns();
|
||||
@NonNull
|
||||
public abstract List<@NonNull Pattern> getItemLinkPatterns();
|
||||
|
||||
/**
|
||||
* Parses the specified message, calls a {@link PreChatFormatEvent}, and sends the message to everyone who can view this channel.
|
||||
* @param user The player who is saying the message.
|
||||
*
|
||||
* @param user The player who is saying the message.
|
||||
* @param message The message to be sent.
|
||||
*/
|
||||
public abstract Component sendMessage(ChatUser user, String message, boolean fromBungee);
|
||||
@NonNull
|
||||
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromBungee);
|
||||
|
||||
public abstract Component sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromBungee);
|
||||
@NonNull
|
||||
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromBungee);
|
||||
|
||||
public abstract void sendComponent(ChatUser user, Component component);
|
||||
public abstract void sendComponent(@NonNull ChatUser user, @NonNull Component component);
|
||||
|
||||
public String processPlaceholders(ChatUser user, String input) { return input; }
|
||||
@Nullable
|
||||
public String processPlaceholders(@NonNull ChatUser user, @Nullable String input) { return input; }
|
||||
|
||||
public abstract boolean shouldCancelChatEvent();
|
||||
|
||||
|
||||
@@ -2,10 +2,14 @@ package net.draycia.carbon.channels.contexts;
|
||||
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public interface MessageContext {
|
||||
|
||||
@NonNull
|
||||
ChatUser getSender();
|
||||
|
||||
@NonNull
|
||||
ChatUser getTarget();
|
||||
|
||||
ChatChannel getChatChannel();
|
||||
|
||||
@@ -9,7 +9,8 @@ import java.util.function.Function;
|
||||
public class DistanceContext implements Function<MessageContext, Boolean> {
|
||||
|
||||
@Override
|
||||
public @NonNull Boolean apply(@NonNull MessageContext context) {
|
||||
@NonNull
|
||||
public Boolean apply(@NonNull MessageContext context) {
|
||||
if (!context.getSender().isOnline() || !context.getTarget().isOnline()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,16 +9,19 @@ import org.bukkit.event.Listener;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class EconomyContext implements Listener {
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
private final @NonNull Economy economy;
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@NonNull
|
||||
private final Economy economy;
|
||||
|
||||
public EconomyContext(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.economy = carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onChatReqBal(@NonNull PreChatFormatEvent event) {
|
||||
public void onChatReqBal(PreChatFormatEvent event) {
|
||||
Object requiredBalObject = event.getChannel().getContext("vault-balance");
|
||||
|
||||
Double requiredBal;
|
||||
@@ -47,7 +50,7 @@ public class EconomyContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChatCost(@NonNull PreChatFormatEvent event) {
|
||||
public void onChatCost(PreChatFormatEvent event) {
|
||||
Object costObject = event.getChannel().getContext("vault-cost");
|
||||
|
||||
Double cost;
|
||||
|
||||
@@ -3,14 +3,19 @@ package net.draycia.carbon.channels.contexts.impl;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.channels.contexts.MessageContext;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class SimpleMessageContext implements MessageContext {
|
||||
@NonNull
|
||||
private final ChatUser sender;
|
||||
|
||||
@NonNull
|
||||
private final ChatUser target;
|
||||
|
||||
private final ChatChannel chatChannel;
|
||||
private final Object value;
|
||||
|
||||
public SimpleMessageContext(ChatUser sender, ChatUser target, ChatChannel chatChannel, Object value) {
|
||||
public SimpleMessageContext(@NonNull ChatUser sender, @NonNull ChatUser target, ChatChannel chatChannel, Object value) {
|
||||
this.sender = sender;
|
||||
this.target = target;
|
||||
this.chatChannel = chatChannel;
|
||||
@@ -18,11 +23,13 @@ public class SimpleMessageContext implements MessageContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public ChatUser getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public ChatUser getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -15,13 +15,16 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class TownyContext implements Listener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
@NonNull
|
||||
private static final String KEY = "towny-town";
|
||||
|
||||
public TownyContext(CarbonChat carbonChat) {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public TownyContext(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
this.carbonChat.getContextManager().register("towny-town", (context) -> {
|
||||
this.carbonChat.getContextManager().register(KEY, (context) -> {
|
||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||
return isInSameTown(context.getSender(), context.getTarget());
|
||||
}
|
||||
@@ -31,7 +34,7 @@ public final class TownyContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(@NonNull ChannelSwitchEvent event) {
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
Object town = event.getChannel().getContext(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||
@@ -43,7 +46,7 @@ public final class TownyContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(@NonNull PreChatFormatEvent event) {
|
||||
public void onChannelMessage(PreChatFormatEvent event) {
|
||||
// TODO: event.setFailureMessage
|
||||
Object town = event.getChannel().getContext(KEY);
|
||||
|
||||
@@ -55,7 +58,7 @@ public final class TownyContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResidentRemove(@NonNull TownRemoveResidentEvent event) {
|
||||
public void onResidentRemove(TownRemoveResidentEvent event) {
|
||||
String name = event.getResident().getName();
|
||||
ChatUser user = carbonChat.getUserService().wrap(name);
|
||||
Object town = user.getSelectedChannel().getContext(KEY);
|
||||
@@ -66,7 +69,7 @@ public final class TownyContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(@NonNull PlayerJoinEvent event) {
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
Object town = user.getSelectedChannel().getContext(KEY);
|
||||
|
||||
|
||||
@@ -15,11 +15,13 @@ import net.draycia.carbon.storage.ChatUser;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class WorldGuardContext implements Listener {
|
||||
|
||||
@NonNull
|
||||
private static final String KEY = "worldguard-region";
|
||||
|
||||
public WorldGuardContext(@NonNull CarbonChat carbonChat) {
|
||||
@@ -29,7 +31,7 @@ public final class WorldGuardContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(@NonNull ChannelSwitchEvent event) {
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
// TODO: cancellation message
|
||||
Object value = event.getChannel().getContext(KEY);
|
||||
|
||||
@@ -39,7 +41,7 @@ public final class WorldGuardContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(@NonNull PreChatFormatEvent event) {
|
||||
public void onChannelMessage(PreChatFormatEvent event) {
|
||||
// TODO: cancellation message
|
||||
Object value = event.getChannel().getContext(KEY);
|
||||
|
||||
@@ -48,8 +50,8 @@ public final class WorldGuardContext implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInRegionOrRegions(Object value, @NonNull ChatUser user) {
|
||||
if ((value instanceof String)) {
|
||||
private boolean isInRegionOrRegions(@Nullable Object value, @NonNull ChatUser user) {
|
||||
if (value instanceof String) {
|
||||
return isInRegion((String) value, user);
|
||||
}
|
||||
|
||||
@@ -64,17 +66,17 @@ public final class WorldGuardContext implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target, Object value) {
|
||||
public boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target, @Nullable Object value) {
|
||||
boolean user1InRegion = false;
|
||||
boolean user2InRegion = false;
|
||||
|
||||
if ((value instanceof Boolean) && ((Boolean) value)) {
|
||||
if (value instanceof Boolean && (Boolean) value) {
|
||||
return isInSameRegion(sender, target);
|
||||
} else if (value instanceof String) {
|
||||
user1InRegion = isInRegion((String)value, sender);
|
||||
user2InRegion = isInRegion((String)value, target);
|
||||
user1InRegion = isInRegion((String) value, sender);
|
||||
user2InRegion = isInRegion((String) value, target);
|
||||
} else if (value instanceof List) {
|
||||
for (String item : (List<String>)value) {
|
||||
for (String item : (List<String>) value) {
|
||||
if (!user1InRegion) {
|
||||
user1InRegion = isInRegion(item, sender);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class mcMMOContext implements Listener {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public mcMMOContext(CarbonChat carbonChat) {
|
||||
public mcMMOContext(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
this.carbonChat.getContextManager().register("mcmmo-party", (context) -> {
|
||||
@@ -28,7 +29,7 @@ public final class mcMMOContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(@NonNull ChannelSwitchEvent event) {
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
Object party = event.getChannel().getContext("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||
@@ -40,7 +41,7 @@ public final class mcMMOContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(@NonNull PreChatFormatEvent event) {
|
||||
public void onChannelMessage(PreChatFormatEvent event) {
|
||||
Object party = event.getChannel().getContext("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||
@@ -54,7 +55,7 @@ public final class mcMMOContext implements Listener {
|
||||
private final McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPartyLeave(@NonNull McMMOPartyChangeEvent event) {
|
||||
public void onPartyLeave(McMMOPartyChangeEvent event) {
|
||||
if (event.getReason() != LEFT && event.getReason() != KICKED) {
|
||||
return;
|
||||
}
|
||||
@@ -68,7 +69,7 @@ public final class mcMMOContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(@NonNull PlayerJoinEvent event) {
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
Object party = user.getSelectedChannel().getContext("mcmmo-party");
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import net.draycia.carbon.events.ChatFormatEvent;
|
||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -18,41 +18,50 @@ import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
private final String key;
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private final ConfigurationSection config;
|
||||
|
||||
@NonNull
|
||||
private static final Pattern MESSAGE_PATTERN = Pattern.compile("<message>");
|
||||
|
||||
public CarbonChatChannel(String key, CarbonChat carbonChat, ConfigurationSection config) {
|
||||
@NonNull
|
||||
private final String key;
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@Nullable
|
||||
private final ConfigurationSection config;
|
||||
|
||||
public CarbonChatChannel(@NonNull String key, @NonNull CarbonChat carbonChat, @Nullable ConfigurationSection config) {
|
||||
this.key = key;
|
||||
this.carbonChat = carbonChat;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CarbonChat getCarbonChat() {
|
||||
return carbonChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testContext(ChatUser sender, ChatUser target) {
|
||||
public boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target) {
|
||||
return carbonChat.getContextManager().testContext(sender, target, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean canPlayerUse(@NonNull ChatUser user) {
|
||||
public boolean canPlayerUse(@NonNull ChatUser user) {
|
||||
return user.asPlayer().hasPermission("carbonchat.channels." + getName() + ".use");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<ChatUser> audiences() {
|
||||
public List<@NonNull ChatUser> audiences() {
|
||||
List<ChatUser> audience = new ArrayList<>();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
@@ -83,7 +92,9 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
}
|
||||
|
||||
public Component sendMessage(@NonNull ChatUser user, @NonNull Collection<ChatUser> recipients, String message, boolean fromRemote) {
|
||||
@Override
|
||||
@NonNull
|
||||
public Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromRemote) {
|
||||
updateUserNickname(user);
|
||||
|
||||
// Get player's formatting
|
||||
@@ -178,11 +189,13 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component sendMessage(@NonNull ChatUser user, String message, boolean fromRemote) {
|
||||
@NonNull
|
||||
public Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromRemote) {
|
||||
return this.sendMessage(user, this.audiences(), message, fromRemote);
|
||||
}
|
||||
|
||||
public @Nullable String getFormat(@NonNull ChatUser user) {
|
||||
@Nullable
|
||||
public String getFormat(@NonNull ChatUser user) {
|
||||
for (String group : this.getGroupOverrides()) {
|
||||
if (userHasGroup(user, group)) {
|
||||
String format = getFormat(group);
|
||||
@@ -200,7 +213,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean userHasGroup(@NonNull ChatUser user, String group) {
|
||||
private boolean userHasGroup(@NonNull ChatUser user, @NonNull String group) {
|
||||
if (user.isOnline()) {
|
||||
if (carbonChat.getPermission().playerInGroup(user.asPlayer(), group)) {
|
||||
return true;
|
||||
@@ -218,7 +231,8 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return false;
|
||||
}
|
||||
|
||||
private @Nullable String getFirstFoundUserFormat(@NonNull ChatUser user) {
|
||||
@Nullable
|
||||
private String getFirstFoundUserFormat(@NonNull ChatUser user) {
|
||||
String[] playerGroups;
|
||||
|
||||
if (user.isOnline()) {
|
||||
@@ -238,7 +252,8 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return getDefaultFormat();
|
||||
}
|
||||
|
||||
private @Nullable String getPrimaryGroupFormat(@NonNull ChatUser user) {
|
||||
@Nullable
|
||||
private String getPrimaryGroupFormat(@NonNull ChatUser user) {
|
||||
String primaryGroup;
|
||||
|
||||
if (user.isOnline()) {
|
||||
@@ -256,12 +271,14 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return getDefaultFormat();
|
||||
}
|
||||
|
||||
private @Nullable String getDefaultFormat() {
|
||||
@Nullable
|
||||
private String getDefaultFormat() {
|
||||
return getFormat(getDefaultFormatName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getFormat(String group) {
|
||||
@Nullable
|
||||
public String getFormat(@NonNull String group) {
|
||||
return getString("formats." + group);
|
||||
}
|
||||
|
||||
@@ -290,7 +307,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying) {
|
||||
public boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying) {
|
||||
Player targetPlayer = target.asPlayer();
|
||||
|
||||
if (checkSpying && targetPlayer.hasPermission("carbonchat.spy." + getName())) {
|
||||
@@ -310,7 +327,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public @NonNull Boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying) {
|
||||
public boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying) {
|
||||
Player targetPlayer = target.asPlayer();
|
||||
|
||||
if (!canPlayerSee(target, checkSpying)) {
|
||||
@@ -325,7 +342,8 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable TextColor getChannelColor(@NonNull ChatUser user) {
|
||||
@Nullable
|
||||
public TextColor getChannelColor(@NonNull ChatUser user) {
|
||||
TextColor userColor = user.getChannelSettings(this).getColor();
|
||||
|
||||
if (userColor != null) {
|
||||
@@ -347,12 +365,13 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return color;
|
||||
}
|
||||
|
||||
private @Nullable String getDefaultFormatName() {
|
||||
@Nullable
|
||||
private String getDefaultFormatName() {
|
||||
return getString("default-group");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isDefault() {
|
||||
public boolean isDefault() {
|
||||
if (config != null && config.contains("default")) {
|
||||
return config.getBoolean("default");
|
||||
}
|
||||
@@ -361,37 +380,39 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isIgnorable() {
|
||||
public boolean isIgnorable() {
|
||||
return getBoolean("ignorable");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Boolean shouldBungee() {
|
||||
public boolean shouldBungee() {
|
||||
return getBoolean("should-bungee");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isCrossServer() {
|
||||
public boolean isCrossServer() {
|
||||
return getBoolean("is-cross-server");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean honorsRecipientList() {
|
||||
public boolean honorsRecipientList() {
|
||||
return getBoolean("honors-recipient-list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean permissionGroupMatching() {
|
||||
public boolean permissionGroupMatching() {
|
||||
return getBoolean("permission-group-matching");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<String> getGroupOverrides() {
|
||||
@NonNull
|
||||
public List<@NonNull String> getGroupOverrides() {
|
||||
return getStringList("group-overrides");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getName() {
|
||||
String name = getString("name");
|
||||
return name == null ? key : name;
|
||||
@@ -408,62 +429,72 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getSwitchMessage() {
|
||||
@Nullable
|
||||
public String getSwitchMessage() {
|
||||
return getString("switch-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getSwitchOtherMessage() {
|
||||
@Nullable
|
||||
public String getSwitchOtherMessage() {
|
||||
return getString("switch-other-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getSwitchFailureMessage() {
|
||||
@Nullable
|
||||
public String getSwitchFailureMessage() {
|
||||
return getString("switch-failure-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getCannotIgnoreMessage() {
|
||||
@Nullable
|
||||
public String getCannotIgnoreMessage() {
|
||||
return getString("cannot-ignore-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getToggleOffMessage() {
|
||||
@Nullable
|
||||
public String getToggleOffMessage() {
|
||||
return getString("toggle-off-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getToggleOnMessage() {
|
||||
@Nullable
|
||||
public String getToggleOnMessage() {
|
||||
return getString("toggle-on-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getToggleOtherOnMessage() {
|
||||
@Nullable
|
||||
public String getToggleOtherOnMessage() {
|
||||
return getString("toggle-other-on");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getToggleOtherOffMessage() {
|
||||
@Nullable
|
||||
public String getToggleOtherOffMessage() {
|
||||
return getString("toggle-other-off");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getCannotUseMessage() {
|
||||
@Nullable
|
||||
public String getCannotUseMessage() {
|
||||
return getString("cannot-use-channel");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean shouldForwardFormatting() {
|
||||
public boolean shouldForwardFormatting() {
|
||||
return getBoolean("forward-format");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean primaryGroupOnly() {
|
||||
public boolean primaryGroupOnly() {
|
||||
return getBoolean("primary-group-only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<Pattern> getItemLinkPatterns() {
|
||||
@NonNull
|
||||
public List<@NonNull Pattern> getItemLinkPatterns() {
|
||||
ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
||||
|
||||
for (String entry : carbonChat.getConfig().getStringList("item-link-placeholders")) {
|
||||
@@ -474,8 +505,9 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object getContext(@NonNull String key) {
|
||||
ConfigurationSection section = config.getConfigurationSection("contexts");
|
||||
@Nullable
|
||||
public Object getContext(@NonNull String key) {
|
||||
ConfigurationSection section = config == null ? null : config.getConfigurationSection("contexts");
|
||||
|
||||
if (section == null) {
|
||||
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
|
||||
@@ -496,7 +528,8 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return section.get(key);
|
||||
}
|
||||
|
||||
private @Nullable String getString(@NonNull String key) {
|
||||
@Nullable
|
||||
private String getString(@NonNull String key) {
|
||||
if (config != null && config.contains(key)) {
|
||||
return config.getString(key);
|
||||
}
|
||||
@@ -510,7 +543,8 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return null;
|
||||
}
|
||||
|
||||
private @NonNull List<String> getStringList(@NonNull String key) {
|
||||
@NonNull
|
||||
private List<@NonNull String> getStringList(@NonNull String key) {
|
||||
if (config != null && config.contains(key)) {
|
||||
return config.getStringList(key);
|
||||
}
|
||||
@@ -553,12 +587,14 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getAliases() {
|
||||
@Nullable
|
||||
public String getAliases() {
|
||||
String aliases = getString("aliases");
|
||||
|
||||
if (aliases == null) {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
return channel.canPlayerUse(user) ? "true" : "false";
|
||||
return String.valueOf(channel.canPlayerUse(user));
|
||||
} else if (key.startsWith("can_see_")) {
|
||||
String value = key.replace("can_see_", "");
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
return channel.canPlayerSee(user, true) ? "true" : "false";
|
||||
return String.valueOf(channel.canPlayerSee(user, true));
|
||||
} else if (key.startsWith("ignoring_channel_")) {
|
||||
String value = key.replace("ignoring_channel_", "");
|
||||
|
||||
@@ -80,7 +80,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
return user.getChannelSettings(channel).isIgnored() ? "true" : "false";
|
||||
return String.valueOf(user.getChannelSettings(channel).isIgnored());
|
||||
} else if (key.startsWith("selected_channel")) {
|
||||
ChatChannel channel = carbonChat.getUserService().wrap(player).getSelectedChannel();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface Registry<T> {
|
||||
* @param key The key for the entry
|
||||
* @return The entry associated with the key
|
||||
*/
|
||||
@Nullable @Nullable
|
||||
@Nullable
|
||||
T get(@NonNull String key);
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user