mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
more progress
This commit is contained in:
1 parent
29bdcc8061
commit
9f496be5f3
66 files changed
+1179
-1153
No files matched your search
@@ -26,21 +26,21 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelRegistry(@NonNull CarbonChat carbonChat) {
|
||||
public ChannelRegistry(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register(@NonNull String key, @NonNull ChatChannel value) {
|
||||
boolean registerSuccessful = registry.putIfAbsent(key, value) == null;
|
||||
public boolean register(@NonNull final String key, @NonNull final ChatChannel value) {
|
||||
final boolean registerSuccessful = this.registry.putIfAbsent(key, value) == null;
|
||||
|
||||
if (registerSuccessful) {
|
||||
AliasedChannelCommand command = new AliasedChannelCommand(carbonChat, value);
|
||||
final AliasedChannelCommand command = new AliasedChannelCommand(this.carbonChat, value);
|
||||
|
||||
channelCommands.add(command);
|
||||
this.channelCommands.add(command);
|
||||
|
||||
if (value instanceof Listener) {
|
||||
Bukkit.getPluginManager().registerEvents((Listener) value, carbonChat);
|
||||
Bukkit.getPluginManager().registerEvents((Listener) value, this.carbonChat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,22 +50,22 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
||||
@Override
|
||||
@NonNull
|
||||
public Collection<@NonNull ChatChannel> values() {
|
||||
return registry.values();
|
||||
return this.registry.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatChannel get(@NonNull String key) {
|
||||
return registry.get(key);
|
||||
public ChatChannel channel(@NonNull final String key) {
|
||||
return this.registry.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAll() {
|
||||
registry.clear();
|
||||
this.registry.clear();
|
||||
|
||||
for (AliasedChannelCommand command : channelCommands) {
|
||||
carbonChat.getLogger().info("Unregistering command for channel: " + command.getChatChannel().getName());
|
||||
CommandAPI.unregister(command.getCommandName());
|
||||
for (final AliasedChannelCommand command : this.channelCommands) {
|
||||
this.carbonChat.getLogger().info("Unregistering command for channel: " + command.chatChannel().name());
|
||||
CommandAPI.unregister(command.commandName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,17 +14,20 @@ import java.util.regex.Pattern;
|
||||
|
||||
public abstract class ChatChannel implements ForwardingAudience {
|
||||
|
||||
@NonNull
|
||||
public abstract List<ChatUser> audiences();
|
||||
|
||||
/**
|
||||
* @return The color that represents this channel. Optionally used in formatting.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract TextColor getChannelColor(@NonNull ChatUser user);
|
||||
public abstract TextColor channelColor(@NonNull ChatUser user);
|
||||
|
||||
/**
|
||||
* @return The MiniMessage styled format for the group in this channel.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract String getFormat(@NonNull String group);
|
||||
public abstract String format(@NonNull String group);
|
||||
|
||||
/**
|
||||
* @return If this is the default (typically Global) channel players use when they're in no other channel.
|
||||
@@ -34,70 +37,70 @@ public abstract class ChatChannel implements ForwardingAudience {
|
||||
/**
|
||||
* @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 ignorable();
|
||||
|
||||
/**
|
||||
* @return If this channel should be synced cross server
|
||||
* @deprecated Use {@link #isCrossServer()} instead
|
||||
* @deprecated Use {@link #crossServer()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract boolean shouldBungee();
|
||||
public abstract boolean bungee();
|
||||
|
||||
/**
|
||||
* @return If this channel should be synced cross server
|
||||
*/
|
||||
public abstract boolean isCrossServer();
|
||||
public abstract boolean crossServer();
|
||||
|
||||
/**
|
||||
* @return The name of this channel.
|
||||
*/
|
||||
@NonNull
|
||||
public abstract String getName();
|
||||
public abstract String name();
|
||||
|
||||
@NonNull
|
||||
public abstract String getKey();
|
||||
public abstract String key();
|
||||
|
||||
@Nullable
|
||||
public abstract String getMessagePrefix();
|
||||
public abstract String messagePrefix();
|
||||
|
||||
@Nullable
|
||||
public abstract String getAliases();
|
||||
public abstract String aliases();
|
||||
|
||||
/**
|
||||
* @return The message to be sent to the player when switching to this channel.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract String getSwitchMessage();
|
||||
public abstract String switchMessage();
|
||||
|
||||
@Nullable
|
||||
public abstract String getSwitchOtherMessage();
|
||||
public abstract String switchOtherMessage();
|
||||
|
||||
@Nullable
|
||||
public abstract String getSwitchFailureMessage();
|
||||
public abstract String switchFailureMessage();
|
||||
|
||||
@Nullable
|
||||
public abstract String getCannotIgnoreMessage();
|
||||
public abstract String cannotIgnoreMessage();
|
||||
|
||||
/**
|
||||
* @return The message to be send to the player when toggling this channel off.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract String getToggleOffMessage();
|
||||
public abstract String toggleOffMessage();
|
||||
|
||||
/**
|
||||
* @return The message to be send to the player when toggling this channel on.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract String getToggleOnMessage();
|
||||
public abstract String toggleOnMessage();
|
||||
|
||||
@Nullable
|
||||
public abstract String getToggleOtherOnMessage();
|
||||
public abstract String toggleOtherOnMessage();
|
||||
|
||||
@Nullable
|
||||
public abstract String getToggleOtherOffMessage();
|
||||
public abstract String toggleOtherOffMessage();
|
||||
|
||||
@Nullable
|
||||
public abstract String getCannotUseMessage();
|
||||
public abstract String cannotUseMessage();
|
||||
|
||||
public abstract boolean primaryGroupOnly();
|
||||
|
||||
@@ -105,13 +108,18 @@ public abstract class ChatChannel implements ForwardingAudience {
|
||||
|
||||
public abstract boolean permissionGroupMatching();
|
||||
|
||||
public abstract boolean shouldCancelChatEvent();
|
||||
|
||||
public abstract boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target);
|
||||
|
||||
@NonNull
|
||||
public abstract List<@NonNull Pattern> itemLinkPatterns();
|
||||
|
||||
@Nullable
|
||||
public abstract Object getContext(@NonNull String key);
|
||||
public abstract Object context(@NonNull String key);
|
||||
|
||||
@NonNull
|
||||
public abstract List<@NonNull String> getGroupOverrides();
|
||||
public abstract List<@NonNull String> groupOverrides();
|
||||
|
||||
/**
|
||||
* @return If the player can use this channel.
|
||||
@@ -122,16 +130,6 @@ public abstract class ChatChannel implements ForwardingAudience {
|
||||
|
||||
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() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@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.
|
||||
*
|
||||
@@ -147,10 +145,8 @@ public abstract class ChatChannel implements ForwardingAudience {
|
||||
public abstract void sendComponent(@NonNull ChatUser user, @NonNull Component component);
|
||||
|
||||
@Nullable
|
||||
public String processPlaceholders(@NonNull ChatUser user, @Nullable String input) {
|
||||
public String processPlaceholders(@NonNull final ChatUser user, @Nullable final String input) {
|
||||
return input;
|
||||
}
|
||||
|
||||
public abstract boolean shouldCancelChatEvent();
|
||||
|
||||
}
|
||||
@@ -7,45 +7,45 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
public interface MessageContext {
|
||||
|
||||
@NonNull
|
||||
ChatUser getSender();
|
||||
ChatUser sender();
|
||||
|
||||
@NonNull
|
||||
ChatUser getTarget();
|
||||
ChatUser target();
|
||||
|
||||
ChatChannel getChatChannel();
|
||||
ChatChannel chatChannel();
|
||||
|
||||
Object getValue();
|
||||
Object value();
|
||||
|
||||
default boolean isDouble() {
|
||||
return getValue() instanceof Double;
|
||||
return this.value() instanceof Double;
|
||||
}
|
||||
|
||||
default boolean isString() {
|
||||
return getValue() instanceof String;
|
||||
return this.value() instanceof String;
|
||||
}
|
||||
|
||||
default boolean isInteger() {
|
||||
return getValue() instanceof Integer;
|
||||
return this.value() instanceof Integer;
|
||||
}
|
||||
|
||||
default boolean isBoolean() {
|
||||
return getValue() instanceof Boolean;
|
||||
return this.value() instanceof Boolean;
|
||||
}
|
||||
|
||||
default Double asDouble() {
|
||||
return (Double) getValue();
|
||||
return (Double) this.value();
|
||||
}
|
||||
|
||||
default String asString() {
|
||||
return (String) getValue();
|
||||
return (String) this.value();
|
||||
}
|
||||
|
||||
default Integer asInteger() {
|
||||
return (Integer) getValue();
|
||||
return (Integer) this.value();
|
||||
}
|
||||
|
||||
default Boolean asBoolean() {
|
||||
return (Boolean) getValue();
|
||||
return (Boolean) this.value();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,8 +10,8 @@ public class DistanceContext implements Function<MessageContext, Boolean> {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Boolean apply(@NonNull MessageContext context) {
|
||||
if (!context.getSender().online() || !context.getTarget().online()) {
|
||||
public Boolean apply(@NonNull final MessageContext context) {
|
||||
if (!context.sender().online() || !context.target().online()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@ public class DistanceContext implements Function<MessageContext, Boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
Location senderLocation = context.getSender().player().getLocation();
|
||||
Location targetLocation = context.getTarget().player().getLocation();
|
||||
final Location senderLocation = context.sender().player().getLocation();
|
||||
final Location targetLocation = context.target().player().getLocation();
|
||||
|
||||
if (!senderLocation.getWorld().equals(targetLocation.getWorld())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.isDouble()) {
|
||||
Double value = context.asDouble();
|
||||
final Double value = context.asDouble();
|
||||
|
||||
if (value > 0) {
|
||||
return senderLocation.distance(targetLocation) <= value;
|
||||
|
||||
@@ -15,16 +15,16 @@ public class EconomyContext implements Listener {
|
||||
@NonNull
|
||||
private final Economy economy;
|
||||
|
||||
public EconomyContext(@NonNull CarbonChat carbonChat) {
|
||||
public EconomyContext(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.economy = carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
|
||||
this.economy = this.carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChatReqBal(PreChatFormatEvent event) {
|
||||
Object requiredBalObject = event.getChannel().getContext("vault-balance");
|
||||
public void onChatReqBal(final PreChatFormatEvent event) {
|
||||
final Object requiredBalObject = event.channel().context("vault-balance");
|
||||
|
||||
Double requiredBal;
|
||||
final Double requiredBal;
|
||||
|
||||
if (requiredBalObject instanceof Double) {
|
||||
requiredBal = (Double) requiredBalObject;
|
||||
@@ -38,22 +38,22 @@ public class EconomyContext implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getUser().player();
|
||||
final Player player = event.user().player();
|
||||
|
||||
if (!economy.has(player, requiredBal)) {
|
||||
if (!this.economy.has(player, requiredBal)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
event.getUser().sendMessage(carbonChat.getAdventureManager()
|
||||
.processMessageWithPapi(player, event.getChannel().getCannotUseMessage()));
|
||||
event.user().sendMessage(this.carbonChat.getAdventureManager()
|
||||
.processMessageWithPapi(player, event.channel().cannotUseMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChatCost(PreChatFormatEvent event) {
|
||||
Object costObject = event.getChannel().getContext("vault-cost");
|
||||
public void onChatCost(final PreChatFormatEvent event) {
|
||||
final Object costObject = event.channel().context("vault-cost");
|
||||
|
||||
Double cost;
|
||||
final Double cost;
|
||||
|
||||
if (costObject instanceof Double) {
|
||||
cost = (Double) costObject;
|
||||
@@ -67,17 +67,17 @@ public class EconomyContext implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getUser().player();
|
||||
final Player player = event.user().player();
|
||||
|
||||
if (!economy.has(player, cost)) {
|
||||
if (!this.economy.has(player, cost)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
event.getUser().sendMessage(carbonChat.getAdventureManager()
|
||||
.processMessageWithPapi(player, event.getChannel().getCannotUseMessage()));
|
||||
event.user().sendMessage(this.carbonChat.getAdventureManager()
|
||||
.processMessageWithPapi(player, event.channel().cannotUseMessage()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
economy.withdrawPlayer(player, cost);
|
||||
this.economy.withdrawPlayer(player, cost);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import net.draycia.carbon.storage.ChatUser;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class SimpleMessageContext implements MessageContext {
|
||||
|
||||
@NonNull
|
||||
private final ChatUser sender;
|
||||
|
||||
@@ -15,7 +16,8 @@ public class SimpleMessageContext implements MessageContext {
|
||||
private final ChatChannel chatChannel;
|
||||
private final Object value;
|
||||
|
||||
public SimpleMessageContext(@NonNull ChatUser sender, @NonNull ChatUser target, ChatChannel chatChannel, Object value) {
|
||||
public SimpleMessageContext(@NonNull final ChatUser sender, @NonNull final ChatUser target,
|
||||
@NonNull final ChatChannel chatChannel, @NonNull final Object value) {
|
||||
this.sender = sender;
|
||||
this.target = target;
|
||||
this.chatChannel = chatChannel;
|
||||
@@ -24,23 +26,24 @@ public class SimpleMessageContext implements MessageContext {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public ChatUser getSender() {
|
||||
return sender;
|
||||
public ChatUser sender() {
|
||||
return this.sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public ChatUser getTarget() {
|
||||
return target;
|
||||
public ChatUser target() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatChannel getChatChannel() {
|
||||
return chatChannel;
|
||||
public ChatChannel chatChannel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
public Object value() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,12 +21,12 @@ public final class TownyContext implements Listener {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public TownyContext(@NonNull CarbonChat carbonChat) {
|
||||
public TownyContext(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
this.carbonChat.getContextManager().register(KEY, (context) -> {
|
||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||
return isInSameTown(context.getSender(), context.getTarget());
|
||||
this.carbonChat.getContextManager().register(KEY, context -> {
|
||||
if ((context.value() instanceof Boolean) && ((Boolean) context.value())) {
|
||||
return this.isInSameTown(context.sender(), context.target());
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -34,34 +34,34 @@ public final class TownyContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
Object town = event.getChannel().getContext(KEY);
|
||||
public void onChannelSwitch(final ChannelSwitchEvent event) {
|
||||
final Object town = event.channel().context(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||
if (!isInTown(event.getUser())) {
|
||||
if (!this.isInTown(event.user())) {
|
||||
event.setCancelled(true);
|
||||
event.setFailureMessage(carbonChat.getConfig().getString("contexts.Towny.cancellation-message"));
|
||||
event.failureMessage(this.carbonChat.getConfig().getString("contexts.Towny.cancellation-message"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(PreChatFormatEvent event) {
|
||||
public void onChannelMessage(final PreChatFormatEvent event) {
|
||||
// TODO: event.setFailureMessage
|
||||
Object town = event.getChannel().getContext(KEY);
|
||||
final Object town = event.channel().context(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||
if (!isInTown(event.getUser())) {
|
||||
if (!this.isInTown(event.user())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResidentRemove(TownRemoveResidentEvent event) {
|
||||
String name = event.getResident().getName();
|
||||
ChatUser user = carbonChat.getUserService().wrap(name);
|
||||
Object town = user.selectedChannel().getContext(KEY);
|
||||
public void onResidentRemove(final TownRemoveResidentEvent event) {
|
||||
final String name = event.getResident().getName();
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(name);
|
||||
final Object town = user.selectedChannel().context(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||
user.clearSelectedChannel();
|
||||
@@ -69,38 +69,38 @@ public final class TownyContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
Object town = user.selectedChannel().getContext(KEY);
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer());
|
||||
final Object town = user.selectedChannel().context(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town) && !isInTown(user)) {
|
||||
if ((town instanceof Boolean) && ((Boolean) town) && !this.isInTown(user)) {
|
||||
user.clearSelectedChannel();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInTown(@NonNull ChatUser user) {
|
||||
public boolean isInTown(@NonNull final ChatUser user) {
|
||||
try {
|
||||
return TownyAPI.getInstance().getDataSource().getResident(user.player().getName()).hasTown();
|
||||
} catch (NotRegisteredException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final NotRegisteredException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInSameTown(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
||||
public boolean isInSameTown(@NonNull final ChatUser user1, @NonNull final ChatUser user2) {
|
||||
if (!user1.online() || !user2.online()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Resident resident = TownyAPI.getInstance().getDataSource().getResident(user1.player().getName());
|
||||
final Resident resident = TownyAPI.getInstance().getDataSource().getResident(user1.player().getName());
|
||||
|
||||
if (resident.hasTown()) {
|
||||
return resident.getTown().hasResident(user2.player().getName());
|
||||
}
|
||||
} catch (NotRegisteredException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final NotRegisteredException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -24,40 +24,40 @@ public final class WorldGuardContext implements Listener {
|
||||
@NonNull
|
||||
private static final String KEY = "worldguard-region";
|
||||
|
||||
public WorldGuardContext(@NonNull CarbonChat carbonChat) {
|
||||
carbonChat.getContextManager().register(KEY, (context) -> {
|
||||
return this.testContext(context.getSender(), context.getTarget(), context.getValue());
|
||||
public WorldGuardContext(@NonNull final CarbonChat carbonChat) {
|
||||
carbonChat.getContextManager().register(KEY, context -> {
|
||||
return this.testContext(context.sender(), context.target(), context.value());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
public void onChannelSwitch(final ChannelSwitchEvent event) {
|
||||
// TODO: cancellation message
|
||||
Object value = event.getChannel().getContext(KEY);
|
||||
final Object value = event.channel().context(KEY);
|
||||
|
||||
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
||||
if ((value instanceof String || value instanceof List) && !this.isInRegionOrRegions(value, event.user())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(PreChatFormatEvent event) {
|
||||
public void onChannelMessage(final PreChatFormatEvent event) {
|
||||
// TODO: cancellation message
|
||||
Object value = event.getChannel().getContext(KEY);
|
||||
final Object value = event.channel().context(KEY);
|
||||
|
||||
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
||||
if ((value instanceof String || value instanceof List) && !this.isInRegionOrRegions(value, event.user())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInRegionOrRegions(@Nullable Object value, @NonNull ChatUser user) {
|
||||
private boolean isInRegionOrRegions(@Nullable final Object value, @NonNull final ChatUser user) {
|
||||
if (value instanceof String) {
|
||||
return isInRegion((String) value, user);
|
||||
return this.isInRegion((String) value, user);
|
||||
}
|
||||
|
||||
if (value instanceof List) {
|
||||
for (String region : ((List<String>) value)) {
|
||||
if (isInRegion(region, user)) {
|
||||
for (final String region : (List<String>) value) {
|
||||
if (this.isInRegion(region, user)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -66,23 +66,23 @@ public final class WorldGuardContext implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target, @Nullable Object value) {
|
||||
public boolean testContext(@NonNull final ChatUser sender, @NonNull final ChatUser target, @Nullable final Object value) {
|
||||
boolean user1InRegion = false;
|
||||
boolean user2InRegion = false;
|
||||
|
||||
if (value instanceof Boolean && (Boolean) value) {
|
||||
return isInSameRegion(sender, target);
|
||||
return this.isInSameRegion(sender, target);
|
||||
} else if (value instanceof String) {
|
||||
user1InRegion = isInRegion((String) value, sender);
|
||||
user2InRegion = isInRegion((String) value, target);
|
||||
user1InRegion = this.isInRegion((String) value, sender);
|
||||
user2InRegion = this.isInRegion((String) value, target);
|
||||
} else if (value instanceof List) {
|
||||
for (String item : (List<String>) value) {
|
||||
for (final String item : (List<String>) value) {
|
||||
if (!user1InRegion) {
|
||||
user1InRegion = isInRegion(item, sender);
|
||||
user1InRegion = this.isInRegion(item, sender);
|
||||
}
|
||||
|
||||
if (!user2InRegion) {
|
||||
user2InRegion = isInRegion(item, target);
|
||||
user2InRegion = this.isInRegion(item, target);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -92,21 +92,21 @@ public final class WorldGuardContext implements Listener {
|
||||
return user1InRegion && user2InRegion;
|
||||
}
|
||||
|
||||
public boolean isInSameRegion(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
||||
public boolean isInSameRegion(@NonNull final ChatUser user1, @NonNull final ChatUser user2) {
|
||||
if (!user1.online() || !user2.online()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Location user1Location = BukkitAdapter.adapt(user1.player().getLocation());
|
||||
Location user2Location = BukkitAdapter.adapt(user2.player().getLocation());
|
||||
final Location user1Location = BukkitAdapter.adapt(user1.player().getLocation());
|
||||
final Location user2Location = BukkitAdapter.adapt(user2.player().getLocation());
|
||||
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery regionQuery = container.createQuery();
|
||||
final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
final RegionQuery regionQuery = container.createQuery();
|
||||
|
||||
ApplicableRegionSet user1Regions = regionQuery.getApplicableRegions(user1Location);
|
||||
ApplicableRegionSet user2Regions = regionQuery.getApplicableRegions(user2Location);
|
||||
final ApplicableRegionSet user1Regions = regionQuery.getApplicableRegions(user1Location);
|
||||
final ApplicableRegionSet user2Regions = regionQuery.getApplicableRegions(user2Location);
|
||||
|
||||
for (ProtectedRegion region : user1Regions) {
|
||||
for (final ProtectedRegion region : user1Regions) {
|
||||
if (user2Regions.getRegions().contains(region)) {
|
||||
return true;
|
||||
}
|
||||
@@ -115,16 +115,16 @@ public final class WorldGuardContext implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInRegion(@NonNull String region, @NonNull ChatUser user) {
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
World world = BukkitAdapter.adapt(user.player().getWorld());
|
||||
ProtectedRegion protection = container.get(world).getRegion(region);
|
||||
public boolean isInRegion(@NonNull final String region, @NonNull final ChatUser user) {
|
||||
final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
final World world = BukkitAdapter.adapt(user.player().getWorld());
|
||||
final ProtectedRegion protection = container.get(world).getRegion(region);
|
||||
|
||||
return isInRegion(protection, user);
|
||||
return this.isInRegion(protection, user);
|
||||
}
|
||||
|
||||
public boolean isInRegion(@NonNull ProtectedRegion region, @NonNull ChatUser user) {
|
||||
Location location = BukkitAdapter.adapt(user.player().getLocation());
|
||||
public boolean isInRegion(@NonNull final ProtectedRegion region, @NonNull final ChatUser user) {
|
||||
final org.bukkit.Location location = user.player().getLocation();
|
||||
|
||||
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ public final class mcMMOContext implements Listener {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public mcMMOContext(@NonNull CarbonChat carbonChat) {
|
||||
public mcMMOContext(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
this.carbonChat.getContextManager().register("mcmmo-party", (context) -> {
|
||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||
return isInSameParty(context.getSender(), context.getTarget());
|
||||
this.carbonChat.getContextManager().register("mcmmo-party", context -> {
|
||||
if ((context.value() instanceof Boolean) && ((Boolean) context.value())) {
|
||||
return this.isInSameParty(context.sender(), context.target());
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -29,39 +29,39 @@ public final class mcMMOContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
Object party = event.getChannel().getContext("mcmmo-party");
|
||||
public void onChannelSwitch(final ChannelSwitchEvent event) {
|
||||
final Object party = event.channel().context("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||
if (!isInParty(event.getUser())) {
|
||||
if (!this.isInParty(event.user())) {
|
||||
event.setCancelled(true);
|
||||
event.setFailureMessage(carbonChat.getConfig().getString("contexts.mcMMO.cancellation-message"));
|
||||
event.failureMessage(this.carbonChat.getConfig().getString("contexts.mcMMO.cancellation-message"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(PreChatFormatEvent event) {
|
||||
Object party = event.getChannel().getContext("mcmmo-party");
|
||||
public void onChannelMessage(final PreChatFormatEvent event) {
|
||||
final Object party = event.channel().context("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||
if (!isInParty(event.getUser())) {
|
||||
if (!this.isInParty(event.user())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
|
||||
private final McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
|
||||
private static final McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
|
||||
private static final McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPartyLeave(McMMOPartyChangeEvent event) {
|
||||
public void onPartyLeave(final McMMOPartyChangeEvent event) {
|
||||
if (event.getReason() != LEFT && event.getReason() != KICKED) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
Object party = user.selectedChannel().getContext("mcmmo-party");
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer());
|
||||
final Object party = user.selectedChannel().context("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||
user.clearSelectedChannel();
|
||||
@@ -69,20 +69,20 @@ public final class mcMMOContext implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
Object party = user.selectedChannel().getContext("mcmmo-party");
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer());
|
||||
final Object party = user.selectedChannel().context("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party) && !isInParty(user)) {
|
||||
if ((party instanceof Boolean) && ((Boolean) party) && !this.isInParty(user)) {
|
||||
user.clearSelectedChannel();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInParty(@NonNull ChatUser user) {
|
||||
public boolean isInParty(@NonNull final ChatUser user) {
|
||||
return PartyAPI.inParty(user.player());
|
||||
}
|
||||
|
||||
public boolean isInSameParty(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
||||
public boolean isInSameParty(@NonNull final ChatUser user1, @NonNull final ChatUser user2) {
|
||||
if (!user1.online() || !user2.online()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -51,12 +51,12 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
@Override
|
||||
public boolean testContext(@NonNull final ChatUser sender, @NonNull final ChatUser target) {
|
||||
return carbonChat.getContextManager().testContext(sender, target, this);
|
||||
return this.carbonChat.getContextManager().testContext(sender, target, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(@NonNull final ChatUser user) {
|
||||
return user.player().hasPermission("carbonchat.channels." + getName() + ".use");
|
||||
return user.player().hasPermission("carbonchat.channels." + name() + ".use");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,7 +65,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
List<ChatUser> audience = new ArrayList<>();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
ChatUser playerUser = carbonChat.getUserService().wrap(player);
|
||||
ChatUser playerUser = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (canPlayerSee(playerUser, true)) {
|
||||
audience.add(playerUser);
|
||||
@@ -80,7 +80,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
String nickname = user.nickname();
|
||||
|
||||
if (nickname != null) {
|
||||
Component component = carbonChat.getAdventureManager().processMessage(nickname);
|
||||
Component component = this.carbonChat.getAdventureManager().processMessage(nickname);
|
||||
nickname = CarbonChat.LEGACY.serialize(component);
|
||||
|
||||
user.player().setDisplayName(nickname);
|
||||
@@ -106,7 +106,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
// Return if cancelled or message is emptied
|
||||
|
||||
if (preFormatEvent.isCancelled() || preFormatEvent.getMessage().trim().isEmpty()) {
|
||||
if (preFormatEvent.isCancelled() || preFormatEvent.message().trim().isEmpty()) {
|
||||
return TextComponent.empty();
|
||||
}
|
||||
|
||||
@@ -125,67 +125,67 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
// Iterate through players who should receive messages in this channel
|
||||
for (ChatUser target : recipients) {
|
||||
// Call second format event. Used for relational stuff (placeholders etc)
|
||||
ChatFormatEvent formatEvent = new ChatFormatEvent(user, target, this, preFormatEvent.getFormat(), preFormatEvent.getMessage());
|
||||
ChatFormatEvent formatEvent = new ChatFormatEvent(user, target, this, preFormatEvent.format(), preFormatEvent.message());
|
||||
Bukkit.getPluginManager().callEvent(formatEvent);
|
||||
|
||||
// Again, return if cancelled or message is emptied
|
||||
if (formatEvent.isCancelled() || formatEvent.getMessage().trim().isEmpty()) {
|
||||
if (formatEvent.isCancelled() || formatEvent.message().trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TextColor targetColor = getChannelColor(target);
|
||||
TextColor targetColor = channelColor(target);
|
||||
|
||||
TextComponent formatComponent = (TextComponent) carbonChat.getAdventureManager().processMessage(formatEvent.getFormat(),
|
||||
TextComponent formatComponent = (TextComponent) this.carbonChat.getAdventureManager().processMessage(formatEvent.format(),
|
||||
"br", "\n",
|
||||
"displayname", displayName,
|
||||
"color", "<" + targetColor.asHexString() + ">",
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"server", carbonChat.getConfig().getString("server-name", "Server"),
|
||||
"message", formatEvent.getMessage());
|
||||
"server", this.carbonChat.getConfig().getString("server-name", "Server"),
|
||||
"message", formatEvent.message());
|
||||
|
||||
if (isUserSpying(user, target)) {
|
||||
String prefix = processPlaceholders(user, carbonChat.getConfig().getString("spy-prefix"));
|
||||
String prefix = processPlaceholders(user, this.carbonChat.getConfig().getString("spy-prefix"));
|
||||
|
||||
formatComponent = (TextComponent) MiniMessage.get().parse(prefix, "color",
|
||||
targetColor.asHexString()).append(formatComponent);
|
||||
}
|
||||
|
||||
ChatComponentEvent newEvent = new ChatComponentEvent(user, target, this, formatComponent,
|
||||
formatEvent.getMessage());
|
||||
formatEvent.message());
|
||||
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
|
||||
target.sendMessage(newEvent.getComponent());
|
||||
target.sendMessage(newEvent.component());
|
||||
}
|
||||
|
||||
ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.getFormat(),
|
||||
preFormatEvent.getMessage());
|
||||
ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.format(),
|
||||
preFormatEvent.message());
|
||||
|
||||
Bukkit.getPluginManager().callEvent(consoleFormatEvent);
|
||||
|
||||
TextColor targetColor = getChannelColor(user);
|
||||
TextColor targetColor = channelColor(user);
|
||||
|
||||
TextComponent consoleFormat = (TextComponent) carbonChat.getAdventureManager().processMessage(consoleFormatEvent.getFormat(),
|
||||
TextComponent consoleFormat = (TextComponent) this.carbonChat.getAdventureManager().processMessage(consoleFormatEvent.format(),
|
||||
"br", "\n",
|
||||
"displayname", displayName,
|
||||
"color", "<" + targetColor.asHexString() + ">",
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"server", carbonChat.getConfig().getString("server-name", "Server"),
|
||||
"message", consoleFormatEvent.getMessage());
|
||||
"server", this.carbonChat.getConfig().getString("server-name", "Server"),
|
||||
"message", consoleFormatEvent.message());
|
||||
|
||||
ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleFormat,
|
||||
consoleFormatEvent.getMessage());
|
||||
consoleFormatEvent.message());
|
||||
|
||||
Bukkit.getPluginManager().callEvent(consoleEvent);
|
||||
|
||||
// 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.online() && !fromRemote && (shouldBungee() || isCrossServer())) {
|
||||
sendMessageToBungee(user.player(), consoleEvent.getComponent());
|
||||
if (user.online() && !fromRemote && (bungee() || crossServer())) {
|
||||
sendMessageToBungee(user.player(), consoleEvent.component());
|
||||
}
|
||||
|
||||
return consoleEvent.getComponent();
|
||||
return consoleEvent.component();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -196,9 +196,9 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
@Nullable
|
||||
public String getFormat(@NonNull ChatUser user) {
|
||||
for (String group : this.getGroupOverrides()) {
|
||||
for (String group : this.groupOverrides()) {
|
||||
if (userHasGroup(user, group)) {
|
||||
String format = getFormat(group);
|
||||
String format = format(group);
|
||||
|
||||
if (format != null) {
|
||||
return format;
|
||||
@@ -236,13 +236,13 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
String[] playerGroups;
|
||||
|
||||
if (user.online()) {
|
||||
playerGroups = carbonChat.getPermission().getPlayerGroups(user.player());
|
||||
playerGroups = this.carbonChat.getPermission().getPlayerGroups(user.player());
|
||||
} else {
|
||||
playerGroups = carbonChat.getPermission().getPlayerGroups(null, user.offlinePlayer());
|
||||
playerGroups = this.carbonChat.getPermission().getPlayerGroups(null, user.offlinePlayer());
|
||||
}
|
||||
|
||||
for (String group : playerGroups) {
|
||||
String groupFormat = getFormat(group);
|
||||
String groupFormat = format(group);
|
||||
|
||||
if (groupFormat != null) {
|
||||
return groupFormat;
|
||||
@@ -257,12 +257,12 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
String primaryGroup;
|
||||
|
||||
if (user.online()) {
|
||||
primaryGroup = carbonChat.getPermission().getPrimaryGroup(user.player());
|
||||
primaryGroup = this.carbonChat.getPermission().getPrimaryGroup(user.player());
|
||||
} else {
|
||||
primaryGroup = carbonChat.getPermission().getPrimaryGroup(null, user.offlinePlayer());
|
||||
primaryGroup = this.carbonChat.getPermission().getPrimaryGroup(null, user.offlinePlayer());
|
||||
}
|
||||
|
||||
String primaryGroupFormat = getFormat(primaryGroup);
|
||||
String primaryGroupFormat = format(primaryGroup);
|
||||
|
||||
if (primaryGroupFormat != null) {
|
||||
return primaryGroupFormat;
|
||||
@@ -273,18 +273,18 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
@Nullable
|
||||
private String getDefaultFormat() {
|
||||
return getFormat(getDefaultFormatName());
|
||||
return format(getDefaultFormatName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFormat(@NonNull String group) {
|
||||
public String format(@NonNull String group) {
|
||||
return getString("formats." + group);
|
||||
}
|
||||
|
||||
private boolean isUserSpying(@NonNull ChatUser sender, @NonNull ChatUser target) {
|
||||
if (!canPlayerSee(sender, target, false)) {
|
||||
return target.getChannelSettings(this).spying();
|
||||
return target.channelSettings(this).spying();
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -293,16 +293,16 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
@Override
|
||||
public void sendComponent(@NonNull ChatUser player, @NonNull Component component) {
|
||||
for (ChatUser user : audiences()) {
|
||||
if (!user.isIgnoringUser(player)) {
|
||||
if (!user.ignoringUser(player)) {
|
||||
user.sendMessage(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessageToBungee(@NonNull Player player, @NonNull Component component) {
|
||||
carbonChat.getMessageManager().sendMessage("channel-component", player.getUniqueId(), (byteArray) -> {
|
||||
byteArray.writeUTF(this.getKey());
|
||||
byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(component));
|
||||
this.carbonChat.getMessageManager().sendMessage("channel-component", player.getUniqueId(), (byteArray) -> {
|
||||
byteArray.writeUTF(this.key());
|
||||
byteArray.writeUTF(carbonChat.getAdventureManager().audiences().gsonSerializer().serialize(component));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -310,18 +310,18 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
public boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying) {
|
||||
Player targetPlayer = target.player();
|
||||
|
||||
if (checkSpying && targetPlayer.hasPermission("carbonchat.spy." + getName())) {
|
||||
if (target.getChannelSettings(this).spying()) {
|
||||
if (checkSpying && targetPlayer.hasPermission("carbonchat.spy." + name())) {
|
||||
if (target.channelSettings(this).spying()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!targetPlayer.hasPermission("carbonchat.channels." + getName() + ".see")) {
|
||||
if (!targetPlayer.hasPermission("carbonchat.channels." + name() + ".see")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isIgnorable()) {
|
||||
return !target.getChannelSettings(this).ignored();
|
||||
if (ignorable()) {
|
||||
return !target.channelSettings(this).ignored();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -334,8 +334,8 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isIgnorable()) {
|
||||
return !target.isIgnoringUser(sender) || targetPlayer.hasPermission("carbonchat.ignore.exempt");
|
||||
if (ignorable()) {
|
||||
return !target.ignoringUser(sender) || targetPlayer.hasPermission("carbonchat.ignore.exempt");
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -343,8 +343,8 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TextColor getChannelColor(@NonNull ChatUser user) {
|
||||
TextColor userColor = user.getChannelSettings(this).color();
|
||||
public TextColor channelColor(@NonNull ChatUser user) {
|
||||
TextColor userColor = user.channelSettings(this).color();
|
||||
|
||||
if (userColor != null) {
|
||||
System.out.println("user color found!");
|
||||
@@ -355,9 +355,9 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
TextColor color = CarbonUtils.parseColor(user, input);
|
||||
|
||||
if (color == null && carbonChat.getConfig().getBoolean("show-tips")) {
|
||||
carbonChat.getLogger().warning("Tip: Channel color found (" + color + ") is invalid!");
|
||||
carbonChat.getLogger().warning("Falling back to #FFFFFF");
|
||||
if (color == null && this.carbonChat.getConfig().getBoolean("show-tips")) {
|
||||
this.carbonChat.getLogger().warning("Tip: Channel color found (" + color + ") is invalid!");
|
||||
this.carbonChat.getLogger().warning("Falling back to #FFFFFF");
|
||||
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
@@ -380,18 +380,18 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIgnorable() {
|
||||
public boolean ignorable() {
|
||||
return getBoolean("ignorable");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean shouldBungee() {
|
||||
public boolean bungee() {
|
||||
return getBoolean("should-bungee");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCrossServer() {
|
||||
public boolean crossServer() {
|
||||
return getBoolean("is-cross-server");
|
||||
}
|
||||
|
||||
@@ -407,20 +407,20 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<@NonNull String> getGroupOverrides() {
|
||||
public List<@NonNull String> groupOverrides() {
|
||||
return getStringList("group-overrides");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getName() {
|
||||
public String name() {
|
||||
String name = getString("name");
|
||||
return name == null ? key : name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getMessagePrefix() {
|
||||
public String messagePrefix() {
|
||||
if (config != null && config.contains("message-prefix")) {
|
||||
return config.getString("message-prefix");
|
||||
}
|
||||
@@ -430,63 +430,58 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getSwitchMessage() {
|
||||
public String switchMessage() {
|
||||
return getString("switch-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getSwitchOtherMessage() {
|
||||
public String switchOtherMessage() {
|
||||
return getString("switch-other-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getSwitchFailureMessage() {
|
||||
public String switchFailureMessage() {
|
||||
return getString("switch-failure-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getCannotIgnoreMessage() {
|
||||
public String cannotIgnoreMessage() {
|
||||
return getString("cannot-ignore-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getToggleOffMessage() {
|
||||
public String toggleOffMessage() {
|
||||
return getString("toggle-off-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getToggleOnMessage() {
|
||||
public String toggleOnMessage() {
|
||||
return getString("toggle-on-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getToggleOtherOnMessage() {
|
||||
public String toggleOtherOnMessage() {
|
||||
return getString("toggle-other-on");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getToggleOtherOffMessage() {
|
||||
public String toggleOtherOffMessage() {
|
||||
return getString("toggle-other-off");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getCannotUseMessage() {
|
||||
public String cannotUseMessage() {
|
||||
return getString("cannot-use-channel");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldForwardFormatting() {
|
||||
return getBoolean("forward-format");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean primaryGroupOnly() {
|
||||
return getBoolean("primary-group-only");
|
||||
@@ -494,10 +489,10 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<@NonNull Pattern> getItemLinkPatterns() {
|
||||
public List<@NonNull Pattern> itemLinkPatterns() {
|
||||
ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
||||
|
||||
for (String entry : carbonChat.getConfig().getStringList("item-link-placeholders")) {
|
||||
for (String entry : this.carbonChat.getConfig().getStringList("item-link-placeholders")) {
|
||||
itemPatterns.add(Pattern.compile(Pattern.quote(entry)));
|
||||
}
|
||||
|
||||
@@ -506,11 +501,11 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getContext(@NonNull String key) {
|
||||
public Object context(@NonNull String key) {
|
||||
ConfigurationSection section = config == null ? null : config.getConfigurationSection("contexts");
|
||||
|
||||
if (section == null) {
|
||||
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
|
||||
ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
|
||||
|
||||
if (defaultSection == null) {
|
||||
return null;
|
||||
@@ -534,7 +529,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return config.getString(key);
|
||||
}
|
||||
|
||||
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
|
||||
ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
|
||||
|
||||
if (defaultSection != null && defaultSection.contains(key)) {
|
||||
return defaultSection.getString(key);
|
||||
@@ -549,7 +544,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return config.getStringList(key);
|
||||
}
|
||||
|
||||
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
|
||||
ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
|
||||
|
||||
if (defaultSection != null && defaultSection.contains(key)) {
|
||||
return defaultSection.getStringList(key);
|
||||
@@ -563,7 +558,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return config.getBoolean(key);
|
||||
}
|
||||
|
||||
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
|
||||
ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
|
||||
|
||||
if (defaultSection != null && defaultSection.contains(key)) {
|
||||
return defaultSection.getBoolean(key);
|
||||
@@ -577,7 +572,7 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
return config.getDouble(key);
|
||||
}
|
||||
|
||||
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
|
||||
ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
|
||||
|
||||
if (defaultSection != null && defaultSection.contains(key)) {
|
||||
return defaultSection.getDouble(key);
|
||||
@@ -588,17 +583,17 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getKey() {
|
||||
public String key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getAliases() {
|
||||
public String aliases() {
|
||||
String aliases = getString("aliases");
|
||||
|
||||
if (aliases == null) {
|
||||
return getKey();
|
||||
return key();
|
||||
}
|
||||
|
||||
return aliases;
|
||||
|
||||
@@ -24,66 +24,66 @@ public class AliasedChannelCommand {
|
||||
@NonNull
|
||||
private final String commandName;
|
||||
|
||||
public AliasedChannelCommand(@NonNull CarbonChat carbonChat, @NonNull ChatChannel chatChannel) {
|
||||
public AliasedChannelCommand(@NonNull final CarbonChat carbonChat, @NonNull final ChatChannel chatChannel) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.chatChannel = chatChannel;
|
||||
|
||||
this.commandName = chatChannel.getKey();
|
||||
this.commandName = chatChannel.key();
|
||||
|
||||
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(this.commandName)
|
||||
.withArguments(setChannelArguments)
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel"))
|
||||
.executesPlayer(this::setChannel)
|
||||
.executesPlayer(this::channel)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
||||
sendMessageArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(this.commandName)
|
||||
.withArguments(sendMessageArguments)
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
|
||||
.executesPlayer(this::sendMessage)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void setChannel(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
private void channel(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (user.getChannelSettings(getChatChannel()).ignored()) {
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, getChatChannel().getCannotUseMessage(),
|
||||
if (user.channelSettings(this.chatChannel()).ignored()) {
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, this.chatChannel().cannotUseMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + getChatChannel().getChannelColor(user).toString() + ">",
|
||||
"channel", getChatChannel().getName()));
|
||||
"color", "<" + this.chatChannel().channelColor(user).toString() + ">",
|
||||
"channel", this.chatChannel().name()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
user.selectedChannel(getChatChannel());
|
||||
user.selectedChannel(this.chatChannel());
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, getChatChannel().getSwitchMessage(),
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, this.chatChannel().switchMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + getChatChannel().getChannelColor(user).toString() + ">",
|
||||
"channel", getChatChannel().getName()));
|
||||
"color", "<" + this.chatChannel().channelColor(user).toString() + ">",
|
||||
"channel", this.chatChannel().name()));
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
String message = (String) args[0];
|
||||
private void sendMessage(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
final String message = (String) args[0];
|
||||
|
||||
Component component = getChatChannel().sendMessage(user, message, false);
|
||||
final Component component = this.chatChannel().sendMessage(user, message, false);
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||
this.carbonChat.getAdventureManager().audiences().console().sendMessage(component);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatChannel getChatChannel() {
|
||||
return chatChannel;
|
||||
public ChatChannel chatChannel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getCommandName() {
|
||||
return commandName;
|
||||
public String commandName() {
|
||||
return this.commandName;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class ChannelCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public ChannelCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -30,17 +30,17 @@ public class ChannelCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||
setChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(setChannelArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel"))
|
||||
.executesPlayer(this::setChannel)
|
||||
.executesPlayer(this::channel)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
||||
sendMessageArguments.put("channel", CarbonUtils.channelArgument());
|
||||
sendMessageArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
@@ -52,35 +52,35 @@ public class ChannelCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void setChannel(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
ChatChannel channel = (ChatChannel) args[0];
|
||||
private void channel(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
final ChatChannel channel = (ChatChannel) args[0];
|
||||
|
||||
if (user.getChannelSettings(channel).ignored()) {
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getCannotUseMessage(),
|
||||
if (user.channelSettings(channel).ignored()) {
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, channel.cannotUseMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
||||
"channel", channel.getName()));
|
||||
"color", "<" + channel.channelColor(user).toString() + ">",
|
||||
"channel", channel.name()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
user.selectedChannel(channel);
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(),
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, channel.switchMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
||||
"channel", channel.getName()));
|
||||
"color", "<" + channel.channelColor(user).toString() + ">",
|
||||
"channel", channel.name()));
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
ChatChannel channel = (ChatChannel) args[0];
|
||||
String message = (String) args[1];
|
||||
private void sendMessage(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
final ChatChannel channel = (ChatChannel) args[0];
|
||||
final String message = (String) args[1];
|
||||
|
||||
Component component = channel.sendMessage(user, message, false);
|
||||
final Component component = channel.sendMessage(user, message, false);
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||
this.carbonChat.getAdventureManager().audiences().console().sendMessage(component);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class ChannelListCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelListCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public ChannelListCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -36,7 +36,7 @@ public class ChannelListCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(channelArguments)
|
||||
@@ -45,7 +45,7 @@ public class ChannelListCommand {
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||
argumentsOther.put("player", CarbonUtils.onlineChatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -56,31 +56,32 @@ public class ChannelListCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
public void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
public void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final Iterator<ChatChannel> allChannels = this.carbonChat.getChannelManager().registry().values().iterator();
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
getListAndSend(player, user, allChannels);
|
||||
this.listAndSend(player, user, allChannels);
|
||||
}
|
||||
|
||||
public void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||
Audience cmdSender = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||
ChatUser user = (ChatUser) args[0];
|
||||
public void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final Audience cmdSender = this.carbonChat.getAdventureManager().audiences().audience(sender);
|
||||
final ChatUser user = (ChatUser) args[0];
|
||||
|
||||
if (!user.online()) {
|
||||
String mustBeOnline = carbonChat.getLanguage().getString("user-must-be-online");
|
||||
cmdSender.sendMessage(carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.offlinePlayer().getName()));
|
||||
final String mustBeOnline = this.carbonChat.getLanguage().getString("user-must-be-online");
|
||||
cmdSender.sendMessage(this.carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.offlinePlayer().getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||
getListAndSend(sender, user, allChannels);
|
||||
final Iterator<ChatChannel> allChannels = this.carbonChat.getChannelManager().registry().values().iterator();
|
||||
this.listAndSend(sender, user, allChannels);
|
||||
}
|
||||
|
||||
private void getListAndSend(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull Iterator<ChatChannel> allChannels) {
|
||||
private void listAndSend(@NonNull final CommandSender sender, @NonNull final ChatUser user,
|
||||
@NonNull final Iterator<ChatChannel> allChannels) {
|
||||
ChatChannel channel;
|
||||
List<ChatChannel> canSee = new ArrayList<>();
|
||||
List<ChatChannel> cannotSee = new ArrayList<>();
|
||||
final List<ChatChannel> canSee = new ArrayList<>();
|
||||
final List<ChatChannel> cannotSee = new ArrayList<>();
|
||||
|
||||
while (allChannels.hasNext()) {
|
||||
channel = allChannels.next();
|
||||
@@ -92,42 +93,41 @@ public class ChannelListCommand {
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
||||
TextComponent.Builder availableList = TextComponent.builder("");
|
||||
final Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
||||
final TextComponent.Builder availableList = TextComponent.builder("");
|
||||
|
||||
makeList(visibleChannels, availableList);
|
||||
this.makeList(visibleChannels, availableList);
|
||||
|
||||
String availableFormat = carbonChat.getLanguage().getString("available-channels-list");
|
||||
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
||||
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
||||
final String availableFormat = this.carbonChat.getLanguage().getString("available-channels-list");
|
||||
Component availableComponent = this.carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
||||
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), ac -> availableList);
|
||||
|
||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||
final Audience audience = this.carbonChat.getAdventureManager().audiences().audience(sender);
|
||||
|
||||
audience.sendMessage(availableComponent);
|
||||
|
||||
if (sender.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
|
||||
final Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
||||
final TextComponent.Builder unavailableList = TextComponent.builder("");
|
||||
|
||||
Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
||||
TextComponent.Builder unavailableList = TextComponent.builder("");
|
||||
this.makeList(invisibleChannels, unavailableList);
|
||||
|
||||
makeList(invisibleChannels, unavailableList);
|
||||
|
||||
String unavailableFormat = carbonChat.getLanguage().getString("unavailable-channels-list");
|
||||
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
||||
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
||||
final String unavailableFormat = this.carbonChat.getLanguage().getString("unavailable-channels-list");
|
||||
Component unavailableComponent = this.carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
||||
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), uac -> unavailableList);
|
||||
|
||||
audience.sendMessage(unavailableComponent);
|
||||
}
|
||||
}
|
||||
|
||||
private void makeList(@NonNull Iterator<@NonNull ChatChannel> iterator, TextComponent.@NonNull Builder list) {
|
||||
String listSeparator = carbonChat.getLanguage().getString("channel-list-separator", ", ");
|
||||
private void makeList(@NonNull final Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
|
||||
final String listSeparator = this.carbonChat.getLanguage().getString("channel-list-separator", ", ");
|
||||
// TODO: Larry, why did you double assign the listSeparatorComponent?
|
||||
Component listSeparatorComponent = TextComponent.of(listSeparator);
|
||||
final Component listSeparatorComponent = TextComponent.of(listSeparator);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
ChatChannel channel = iterator.next();
|
||||
list.append(TextComponent.of(channel.getName()));
|
||||
list.append(TextComponent.of(iterator.next().name()));
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
list.append(listSeparatorComponent);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class ChatReloadCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChatReloadCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public ChatReloadCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -30,14 +30,14 @@ public class ChatReloadCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||
carbonChat.reloadConfig();
|
||||
carbonChat.reloadFilters();
|
||||
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
this.carbonChat.reloadConfig();
|
||||
this.carbonChat.reloadFilters();
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(carbonChat.getLanguage().getString("reloaded"),
|
||||
"br", "\n");
|
||||
final Component message = this.carbonChat.getAdventureManager()
|
||||
.processMessage(this.carbonChat.getLanguage().getString("reloaded"), "br", "\n");
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(message);
|
||||
this.carbonChat.getAdventureManager().audiences().audience(sender).sendMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
@@ -18,7 +17,7 @@ public class ClearChatCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ClearChatCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public ClearChatCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -34,25 +33,25 @@ public class ClearChatCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||
String format = carbonChat.getModConfig().getString("clear-chat.message", "");
|
||||
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n");
|
||||
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final String format = this.carbonChat.getModConfig().getString("clear-chat.message", "");
|
||||
final Component component = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n");
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
ChatUser audience = carbonChat.getUserService().wrap(player);
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
final ChatUser audience = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (player.hasPermission("carbonchat.clearchat.exempt")) {
|
||||
String message = carbonChat.getLanguage().getString("clear-exempt");
|
||||
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
|
||||
final String message = this.carbonChat.getLanguage().getString("clear-exempt");
|
||||
audience.sendMessage(this.carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
|
||||
} else {
|
||||
for (int i = 0; i < carbonChat.getModConfig().getInt("clear-chat.message-count", 100); i++) {
|
||||
for (int i = 0; i < this.carbonChat.getModConfig().getInt("clear-chat.message-count", 100); i++) {
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
if (player.hasPermission("carbonchat.clearchat.notify")) {
|
||||
String message = carbonChat.getLanguage().getString("clear-notify");
|
||||
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
|
||||
final String message = this.carbonChat.getLanguage().getString("clear-notify");
|
||||
audience.sendMessage(this.carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class IgnoreCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public IgnoreCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public IgnoreCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -30,7 +30,7 @@ public class IgnoreCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -41,28 +41,28 @@ public class IgnoreCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
ChatUser targetUser = (ChatUser) args[0];
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser targetUser = (ChatUser) args[0];
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (user.isIgnoringUser(targetUser)) {
|
||||
user.setIgnoringUser(targetUser, false);
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
||||
carbonChat.getLanguage().getString("not-ignoring-user"),
|
||||
if (user.ignoringUser(targetUser)) {
|
||||
user.ignoringUser(targetUser, false);
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player,
|
||||
this.carbonChat.getLanguage().getString("not-ignoring-user"),
|
||||
"br", "\n", "player", targetUser.offlinePlayer().getName()));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
Permission permission = carbonChat.getPermission();
|
||||
String format;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||
final Permission permission = this.carbonChat.getPermission();
|
||||
final String format;
|
||||
|
||||
if (permission.playerHas(null, targetUser.offlinePlayer(), "carbonchat.ignore.exempt")) {
|
||||
format = carbonChat.getLanguage().getString("ignore-exempt");
|
||||
format = this.carbonChat.getLanguage().getString("ignore-exempt");
|
||||
} else {
|
||||
user.setIgnoringUser(targetUser, true);
|
||||
format = carbonChat.getLanguage().getString("ignoring-user");
|
||||
user.ignoringUser(targetUser, true);
|
||||
format = this.carbonChat.getLanguage().getString("ignoring-user");
|
||||
}
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessageWithPapi(player, format,
|
||||
final Component message = this.carbonChat.getAdventureManager().processMessageWithPapi(player, format,
|
||||
"br", "\n", "sender", player.getDisplayName(), "player",
|
||||
targetUser.offlinePlayer().getName());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class MeCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MeCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public MeCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -30,7 +30,7 @@ public class MeCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -41,28 +41,28 @@ public class MeCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
String message = ((String) args[0]).replace("</pre>", "");
|
||||
String format = PlaceholderAPI.setPlaceholders(player, carbonChat.getLanguage().getString("me"));
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final String message = ((String) args[0]).replace("</pre>", "");
|
||||
String format = PlaceholderAPI.setPlaceholders(player, this.carbonChat.getLanguage().getString("me"));
|
||||
|
||||
if (!player.hasPermission("carbonchat.me.formatting")) {
|
||||
format = format.replace("<message>", "<pre><message></pre>");
|
||||
}
|
||||
|
||||
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
final Component component = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"displayname", player.getDisplayName(), "message", message);
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (user.isShadowMuted()) {
|
||||
if (user.shadowMuted()) {
|
||||
user.sendMessage(component);
|
||||
} else {
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (carbonChat.getUserService().wrap(onlinePlayer).isIgnoringUser(user)) {
|
||||
for (final Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (this.carbonChat.getUserService().wrap(onlinePlayer).ignoringUser(user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().player(onlinePlayer).sendMessage(component);
|
||||
this.carbonChat.getAdventureManager().audiences().player(onlinePlayer).sendMessage(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MessageCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MessageCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public MessageCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -28,7 +28,7 @@ public class MessageCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
arguments.put("message", new GreedyStringArgument());
|
||||
|
||||
@@ -40,11 +40,11 @@ public class MessageCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
ChatUser targetUser = (ChatUser) args[0];
|
||||
String message = (String) args[1];
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser targetUser = (ChatUser) args[0];
|
||||
final String message = (String) args[1];
|
||||
|
||||
ChatUser sender = carbonChat.getUserService().wrap(player);
|
||||
final ChatUser sender = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
targetUser.sendMessage(sender, message);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class MuteCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MuteCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public MuteCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -31,7 +31,7 @@ public class MuteCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -42,31 +42,31 @@ public class MuteCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||
ChatUser user = (ChatUser) args[0];
|
||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = (ChatUser) args[0];
|
||||
final Audience audience = this.carbonChat.getAdventureManager().audiences().audience(sender);
|
||||
|
||||
if (user.isShadowMuted()) {
|
||||
user.setMuted(false);
|
||||
String format = carbonChat.getLanguage().getString("no-longer-muted");
|
||||
if (user.shadowMuted()) {
|
||||
user.muted(false);
|
||||
final String format = this.carbonChat.getLanguage().getString("no-longer-muted");
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
final Component message = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", user.offlinePlayer().getName());
|
||||
|
||||
audience.sendMessage(message);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
Permission permission = carbonChat.getPermission();
|
||||
String format;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||
final Permission permission = this.carbonChat.getPermission();
|
||||
final String format;
|
||||
|
||||
if (permission.playerHas(null, user.offlinePlayer(), "carbonchat.mute.exempt")) {
|
||||
format = carbonChat.getLanguage().getString("mute-exempt");
|
||||
format = this.carbonChat.getLanguage().getString("mute-exempt");
|
||||
} else {
|
||||
user.setMuted(true);
|
||||
format = carbonChat.getLanguage().getString("is-now-muted");
|
||||
user.muted(true);
|
||||
format = this.carbonChat.getLanguage().getString("is-now-muted");
|
||||
}
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
final Component message = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", user.offlinePlayer().getName());
|
||||
|
||||
audience.sendMessage(message);
|
||||
|
||||
@@ -21,7 +21,7 @@ public class NicknameCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public NicknameCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public NicknameCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -30,7 +30,7 @@ public class NicknameCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> selfArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> selfArguments = new LinkedHashMap<>();
|
||||
selfArguments.put("nickname", new StringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -40,7 +40,7 @@ public class NicknameCommand {
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> otherArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> otherArguments = new LinkedHashMap<>();
|
||||
otherArguments.put("player", CarbonUtils.chatUserArgument());
|
||||
otherArguments.put("nickname", new StringArgument());
|
||||
|
||||
@@ -52,9 +52,9 @@ public class NicknameCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
private void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
String nickname = (String) args[0];
|
||||
ChatUser sender = carbonChat.getUserService().wrap(player);
|
||||
final ChatUser sender = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (nickname.equalsIgnoreCase("off") || nickname.equalsIgnoreCase(player.getName())) {
|
||||
nickname = null;
|
||||
@@ -62,22 +62,22 @@ public class NicknameCommand {
|
||||
|
||||
sender.nickname(nickname);
|
||||
|
||||
String message;
|
||||
final String message;
|
||||
|
||||
if (nickname == null) {
|
||||
message = carbonChat.getLanguage().getString("nickname-reset");
|
||||
message = this.carbonChat.getLanguage().getString("nickname-reset");
|
||||
} else {
|
||||
message = carbonChat.getLanguage().getString("nickname-set");
|
||||
message = this.carbonChat.getLanguage().getString("nickname-set");
|
||||
}
|
||||
|
||||
sender.sendMessage(carbonChat.getAdventureManager().processMessage(
|
||||
sender.sendMessage(this.carbonChat.getAdventureManager().processMessage(
|
||||
message, "nickname", nickname == null ? "" : nickname,
|
||||
"user", sender.offlinePlayer().getName()));
|
||||
}
|
||||
|
||||
private void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||
Audience user = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||
ChatUser target = (ChatUser) args[0];
|
||||
private void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final Audience user = this.carbonChat.getAdventureManager().audiences().audience(sender);
|
||||
final ChatUser target = (ChatUser) args[0];
|
||||
String nickname = (String) args[1];
|
||||
|
||||
if (nickname.equalsIgnoreCase("off") ||
|
||||
@@ -87,15 +87,15 @@ public class NicknameCommand {
|
||||
|
||||
target.nickname(nickname);
|
||||
|
||||
String message;
|
||||
final String message;
|
||||
|
||||
if (nickname == null) {
|
||||
message = carbonChat.getLanguage().getString("other-nickname-reset");
|
||||
message = this.carbonChat.getLanguage().getString("other-nickname-reset");
|
||||
} else {
|
||||
message = carbonChat.getLanguage().getString("other-nickname-set");
|
||||
message = this.carbonChat.getLanguage().getString("other-nickname-set");
|
||||
}
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessage(
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessage(
|
||||
message, "nickname", nickname == null ? "" : nickname,
|
||||
"user", target.offlinePlayer().getName()));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ReplyCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ReplyCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public ReplyCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -28,7 +28,7 @@ public class ReplyCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -39,26 +39,30 @@ public class ReplyCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
String input = (String) args[0];
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final String input = (String) args[0];
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (input.isEmpty()) {
|
||||
final String message = this.carbonChat.getLanguage().getString("reply-message-blank");
|
||||
final Component component = this.carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
||||
|
||||
if (input == null || input.isEmpty()) {
|
||||
String message = carbonChat.getLanguage().getString("reply-message-blank");
|
||||
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
||||
user.sendMessage(component);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.getReplyTarget() == null) {
|
||||
String message = carbonChat.getLanguage().getString("no-reply-target");
|
||||
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
||||
if (user.replyTarget() == null) {
|
||||
final String message = this.carbonChat.getLanguage().getString("no-reply-target");
|
||||
final Component component = this.carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
||||
|
||||
user.sendMessage(component);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ChatUser targetUser = carbonChat.getUserService().wrap(user.getReplyTarget());
|
||||
final ChatUser targetUser = this.carbonChat.getUserService().wrap(user.replyTarget());
|
||||
|
||||
targetUser.sendMessage(user, input);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class SetColorCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SetColorCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public SetColorCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -30,9 +30,9 @@ public class SetColorCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("channel", new LiteralArgument(channel.getKey()));
|
||||
for (final ChatChannel channel : this.carbonChat.getChannelManager().registry().values()) {
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("channel", new LiteralArgument(channel.key()));
|
||||
arguments.put("color", CarbonUtils.textColorArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -40,26 +40,26 @@ public class SetColorCommand {
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.setcolor"))
|
||||
.executesPlayer((player, args) -> {
|
||||
TextColor color = (TextColor) args[0];
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
final TextColor color = (TextColor) args[0];
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (!player.hasPermission("carbonchat.setcolor." + channel.getKey())) {
|
||||
if (!player.hasPermission("carbonchat.setcolor." + channel.key())) {
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
||||
carbonChat.getLanguage().getString("cannot-set-color"),
|
||||
this.carbonChat.getLanguage().getString("cannot-set-color"),
|
||||
"br", "\n", "input", color.asHexString(),
|
||||
"channel", channel.getName()));
|
||||
"channel", channel.name()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
UserChannelSettings settings = user.getChannelSettings(channel);
|
||||
final UserChannelSettings settings = user.channelSettings(channel);
|
||||
|
||||
settings.color(color);
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
||||
carbonChat.getLanguage().getString("channel-color-set"),
|
||||
this.carbonChat.getLanguage().getString("channel-color-set"),
|
||||
"br", "\n", "color", "<color:" + color.asHexString() + ">", "channel",
|
||||
channel.getName(), "hex", color.asHexString()));
|
||||
channel.name(), "hex", color.asHexString()));
|
||||
})
|
||||
.register();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class ShadowMuteCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ShadowMuteCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public ShadowMuteCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -31,7 +31,7 @@ public class ShadowMuteCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -42,31 +42,31 @@ public class ShadowMuteCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||
ChatUser user = (ChatUser) args[0];
|
||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = (ChatUser) args[0];
|
||||
final Audience audience = this.carbonChat.getAdventureManager().audiences().audience(sender);
|
||||
|
||||
if (user.isShadowMuted()) {
|
||||
user.setShadowMuted(false);
|
||||
String format = carbonChat.getLanguage().getString("no-longer-shadow-muted");
|
||||
if (user.shadowMuted()) {
|
||||
user.shadowMuted(false);
|
||||
final String format = this.carbonChat.getLanguage().getString("no-longer-shadow-muted");
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
final Component message = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", user.offlinePlayer().getName());
|
||||
|
||||
audience.sendMessage(message);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
Permission permission = carbonChat.getPermission();
|
||||
String format;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||
final Permission permission = this.carbonChat.getPermission();
|
||||
final String format;
|
||||
|
||||
if (permission.playerHas(null, user.offlinePlayer(), "carbonchat.shadowmute.exempt")) {
|
||||
format = carbonChat.getLanguage().getString("shadow-mute-exempt");
|
||||
format = this.carbonChat.getLanguage().getString("shadow-mute-exempt");
|
||||
} else {
|
||||
user.setShadowMuted(true);
|
||||
format = carbonChat.getLanguage().getString("is-now-shadow-muted");
|
||||
user.shadowMuted(true);
|
||||
format = this.carbonChat.getLanguage().getString("is-now-shadow-muted");
|
||||
}
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
final Component message = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", user.offlinePlayer().getName());
|
||||
|
||||
audience.sendMessage(message);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class SpyChannelCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SpyChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public SpyChannelCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -31,7 +31,7 @@ public class SpyChannelCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -41,7 +41,7 @@ public class SpyChannelCommand {
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> whisperArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> whisperArguments = new LinkedHashMap<>();
|
||||
whisperArguments.put("channel", new LiteralArgument("whispers"));
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -51,7 +51,7 @@ public class SpyChannelCommand {
|
||||
.executesPlayer(this::executeWhispers)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> everythingArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> everythingArguments = new LinkedHashMap<>();
|
||||
everythingArguments.put("channel", new LiteralArgument("*"));
|
||||
everythingArguments.put("should-spy", new BooleanArgument());
|
||||
|
||||
@@ -63,68 +63,68 @@ public class SpyChannelCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
ChatChannel chatChannel = (ChatChannel) args[0];
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatChannel chatChannel = (ChatChannel) args[0];
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
String message;
|
||||
final String message;
|
||||
|
||||
UserChannelSettings settings = user.getChannelSettings(chatChannel);
|
||||
final UserChannelSettings settings = user.channelSettings(chatChannel);
|
||||
|
||||
if (settings.spying()) {
|
||||
settings.spying(false);
|
||||
message = carbonChat.getLanguage().getString("spy-toggled-off");
|
||||
message = this.carbonChat.getLanguage().getString("spy-toggled-off");
|
||||
} else {
|
||||
settings.spying(true);
|
||||
message = carbonChat.getLanguage().getString("spy-toggled-on");
|
||||
message = this.carbonChat.getLanguage().getString("spy-toggled-on");
|
||||
}
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
|
||||
"color", "<color:" + chatChannel.getChannelColor(user).toString() + ">", "channel", chatChannel.getName()));
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
|
||||
"color", "<color:" + chatChannel.channelColor(user).toString() + ">", "channel", chatChannel.name()));
|
||||
}
|
||||
|
||||
private void executeWhispers(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
private void executeWhispers(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
String message;
|
||||
final String message;
|
||||
|
||||
if (user.isSpyingWhispers()) {
|
||||
user.setSpyingWhispers(false);
|
||||
message = carbonChat.getLanguage().getString("spy-whispers-off");
|
||||
if (user.spyingwhispers()) {
|
||||
user.spyingWhispers(false);
|
||||
message = this.carbonChat.getLanguage().getString("spy-whispers-off");
|
||||
} else {
|
||||
user.setSpyingWhispers(true);
|
||||
message = carbonChat.getLanguage().getString("spy-whispers-on");
|
||||
user.spyingWhispers(true);
|
||||
message = this.carbonChat.getLanguage().getString("spy-whispers-on");
|
||||
}
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
||||
}
|
||||
|
||||
private void executeEverything(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
Boolean shouldSpy = (Boolean) args[0];
|
||||
private void executeEverything(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final Boolean shouldSpy = (Boolean) args[0];
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
String message;
|
||||
final String message;
|
||||
|
||||
if (shouldSpy) {
|
||||
user.setSpyingWhispers(true);
|
||||
user.spyingWhispers(true);
|
||||
|
||||
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||
user.getChannelSettings(channel).spying(true);
|
||||
for (final ChatChannel channel : this.carbonChat.getChannelManager().registry().values()) {
|
||||
user.channelSettings(channel).spying(true);
|
||||
}
|
||||
|
||||
message = carbonChat.getLanguage().getString("spy-everything-off");
|
||||
message = this.carbonChat.getLanguage().getString("spy-everything-off");
|
||||
} else {
|
||||
user.setSpyingWhispers(false);
|
||||
user.spyingWhispers(false);
|
||||
|
||||
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||
user.getChannelSettings(channel).spying(false);
|
||||
for (final ChatChannel channel : this.carbonChat.getChannelManager().registry().values()) {
|
||||
user.channelSettings(channel).spying(false);
|
||||
}
|
||||
|
||||
message = carbonChat.getLanguage().getString("spy-everything-on");
|
||||
message = this.carbonChat.getLanguage().getString("spy-everything-on");
|
||||
}
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class SudoChannelCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SudoChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public SudoChannelCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -30,7 +30,7 @@ public class SudoChannelCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
|
||||
setOtherChannelArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
||||
setOtherChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
@@ -39,11 +39,11 @@ public class SudoChannelCommand {
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel.others"))
|
||||
.executes((sender, args) -> {
|
||||
this.setOtherChannel(sender, (ChatUser) args[0], (ChatChannel) args[1]);
|
||||
this.otherChannel(sender, (ChatUser) args[0], (ChatChannel) args[1]);
|
||||
})
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
|
||||
sendMessageOtherArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
||||
sendMessageOtherArguments.put("channel", CarbonUtils.channelArgument());
|
||||
sendMessageOtherArguments.put("message", new GreedyStringArgument());
|
||||
@@ -58,24 +58,26 @@ public class SudoChannelCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void setOtherChannel(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull ChatChannel channel) {
|
||||
private void otherChannel(@NonNull final CommandSender sender, @NonNull final ChatUser user, @NonNull final ChatChannel channel) {
|
||||
user.selectedChannel(channel);
|
||||
|
||||
String message = channel.getSwitchMessage();
|
||||
String otherMessage = channel.getSwitchOtherMessage();
|
||||
final String message = channel.switchMessage();
|
||||
final String otherMessage = channel.switchOtherMessage();
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
|
||||
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessage(message, "br", "\n",
|
||||
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
|
||||
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName(),
|
||||
"player", user.offlinePlayer().getName()));
|
||||
this.carbonChat.getAdventureManager().audiences().audience(sender).sendMessage(
|
||||
this.carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
|
||||
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name(),
|
||||
"player", user.offlinePlayer().getName()));
|
||||
}
|
||||
|
||||
private void sendMessageOther(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull ChatChannel channel, @NonNull String message) {
|
||||
Component component = channel.sendMessage(user, message, false);
|
||||
private void sendMessageOther(@NonNull final CommandSender sender, @NonNull final ChatUser user,
|
||||
@NonNull final ChatChannel channel, @NonNull final String message) {
|
||||
final Component component = channel.sendMessage(user, message, false);
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||
this.carbonChat.getAdventureManager().audiences().console().sendMessage(component);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class ToggleCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ToggleCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||
public ToggleCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
@@ -30,7 +30,7 @@ public class ToggleCommand {
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
@@ -40,7 +40,7 @@ public class ToggleCommand {
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||
final LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||
argumentsOther.put("players", CarbonUtils.chatUserArgument());
|
||||
argumentsOther.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
@@ -52,52 +52,53 @@ public class ToggleCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
ChatChannel channel = (ChatChannel) args[0];
|
||||
private void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
final ChatChannel channel = (ChatChannel) args[0];
|
||||
|
||||
String message;
|
||||
final String message;
|
||||
|
||||
UserChannelSettings settings = user.getChannelSettings(channel);
|
||||
final UserChannelSettings settings = user.channelSettings(channel);
|
||||
|
||||
if (!channel.isIgnorable()) {
|
||||
message = channel.getCannotIgnoreMessage();
|
||||
if (!channel.ignorable()) {
|
||||
message = channel.cannotIgnoreMessage();
|
||||
} else if (settings.ignored()) {
|
||||
settings.ignoring(false);
|
||||
message = channel.getToggleOffMessage();
|
||||
message = channel.toggleOffMessage();
|
||||
} else {
|
||||
settings.ignoring(true);
|
||||
message = channel.getToggleOnMessage();
|
||||
message = channel.toggleOnMessage();
|
||||
}
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
|
||||
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
|
||||
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
|
||||
}
|
||||
|
||||
private void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||
ChatUser user = (ChatUser) args[0];
|
||||
ChatChannel channel = (ChatChannel) args[1];
|
||||
private void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = (ChatUser) args[0];
|
||||
final ChatChannel channel = (ChatChannel) args[1];
|
||||
|
||||
String message;
|
||||
String otherMessage;
|
||||
final String message;
|
||||
final String otherMessage;
|
||||
|
||||
UserChannelSettings settings = user.getChannelSettings(channel);
|
||||
final UserChannelSettings settings = user.channelSettings(channel);
|
||||
|
||||
if (settings.ignored()) {
|
||||
settings.ignoring(false);
|
||||
message = channel.getToggleOffMessage();
|
||||
otherMessage = channel.getToggleOtherOffMessage();
|
||||
message = channel.toggleOffMessage();
|
||||
otherMessage = channel.toggleOtherOffMessage();
|
||||
} else {
|
||||
settings.ignoring(true);
|
||||
message = channel.getToggleOnMessage();
|
||||
otherMessage = channel.getToggleOtherOnMessage();
|
||||
message = channel.toggleOnMessage();
|
||||
otherMessage = channel.toggleOtherOnMessage();
|
||||
}
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
|
||||
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessage(message, "br", "\n",
|
||||
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage,
|
||||
"br", "\n", "color", "<color:" + channel.getChannelColor(user).toString() + ">",
|
||||
"channel", channel.getName(), "player", user.offlinePlayer().getName()));
|
||||
this.carbonChat.getAdventureManager().audiences().audience(sender).sendMessage(
|
||||
this.carbonChat.getAdventureManager().processMessage(otherMessage,
|
||||
"br", "\n", "color", "<color:" + channel.channelColor(user).toString() + ">",
|
||||
"channel", channel.name(), "player", user.offlinePlayer().getName()));
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ public class ChannelRegisterEvent extends Event {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@SuppressWarnings("checkstyle:MethodName")
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
@@ -37,19 +38,19 @@ public class ChannelRegisterEvent extends Event {
|
||||
@NonNull
|
||||
private final Registry<ChatChannel> registry;
|
||||
|
||||
public ChannelRegisterEvent(@NonNull List<@NonNull ChatChannel> registeredChannels, @NonNull Registry<ChatChannel> registry) {
|
||||
public ChannelRegisterEvent(@NonNull final List<@NonNull ChatChannel> registeredChannels, @NonNull final Registry<ChatChannel> registry) {
|
||||
super(!Bukkit.isPrimaryThread());
|
||||
|
||||
this.registeredChannels = registeredChannels;
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public void register(@NonNull ChatChannel chatChannel) {
|
||||
registry.register(chatChannel.getKey(), chatChannel);
|
||||
public void register(@NonNull final ChatChannel chatChannel) {
|
||||
this.registry.register(chatChannel.key(), chatChannel);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull ChatChannel> getRegisteredChannels() {
|
||||
return registeredChannels;
|
||||
public List<@NonNull ChatChannel> registeredChannels() {
|
||||
return this.registeredChannels;
|
||||
}
|
||||
}
|
||||
@@ -25,17 +25,18 @@ public class ChannelSwitchEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@SuppressWarnings("checkstyle:MethodName")
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ public class ChannelSwitchEvent extends Event implements Cancellable {
|
||||
@Nullable
|
||||
private String failureMessage;
|
||||
|
||||
public ChannelSwitchEvent(@NonNull ChatChannel channel, @NonNull ChatUser user, @Nullable String failureMessage) {
|
||||
public ChannelSwitchEvent(@NonNull final ChatChannel channel, @NonNull final ChatUser user, @Nullable final String failureMessage) {
|
||||
super(!Bukkit.isPrimaryThread());
|
||||
|
||||
this.channel = channel;
|
||||
@@ -60,21 +61,21 @@ public class ChannelSwitchEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatUser getUser() {
|
||||
return user;
|
||||
public ChatUser user() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatChannel getChannel() {
|
||||
return channel;
|
||||
public ChatChannel channel() {
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getFailureMessage() {
|
||||
return failureMessage;
|
||||
public String failureMessage() {
|
||||
return this.failureMessage;
|
||||
}
|
||||
|
||||
public void setFailureMessage(@Nullable String failureMessage) {
|
||||
public void failureMessage(@Nullable final String failureMessage) {
|
||||
this.failureMessage = failureMessage;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,10 @@ public class ChatComponentEvent extends Event implements Cancellable {
|
||||
@NonNull
|
||||
private final String originalMessage;
|
||||
|
||||
public ChatComponentEvent(@NonNull ChatUser sender, @Nullable ChatUser target, @NonNull ChatChannel chatChannel, @NonNull TextComponent component, @NonNull String originalMessage) {
|
||||
public ChatComponentEvent(@NonNull final ChatUser sender, @Nullable final ChatUser target,
|
||||
@NonNull final ChatChannel chatChannel, @NonNull final TextComponent component,
|
||||
@NonNull final String originalMessage) {
|
||||
|
||||
super(!Bukkit.isPrimaryThread());
|
||||
|
||||
this.sender = sender;
|
||||
@@ -43,11 +46,11 @@ public class ChatComponentEvent extends Event implements Cancellable {
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
return this.isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.isCancelled = cancelled;
|
||||
}
|
||||
|
||||
@@ -58,41 +61,42 @@ public class ChatComponentEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@SuppressWarnings("checkstyle:MethodName")
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS_LIST;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatUser getSender() {
|
||||
return sender;
|
||||
public ChatUser sender() {
|
||||
return this.sender;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ChatUser getTarget() {
|
||||
return target;
|
||||
public ChatUser target() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatChannel getChannel() {
|
||||
return chatChannel;
|
||||
public ChatChannel channel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
public void setChannel(@NonNull ChatChannel chatChannel) {
|
||||
public void channel(@NonNull final ChatChannel chatChannel) {
|
||||
this.chatChannel = chatChannel;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TextComponent getComponent() {
|
||||
return component;
|
||||
public TextComponent component() {
|
||||
return this.component;
|
||||
}
|
||||
|
||||
public void setComponent(@NonNull TextComponent component) {
|
||||
public void component(@NonNull final TextComponent component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getOriginalMessage() {
|
||||
return originalMessage;
|
||||
public String originalMessage() {
|
||||
return this.originalMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,9 @@ public class ChatFormatEvent extends Event implements Cancellable {
|
||||
@NonNull
|
||||
private String message;
|
||||
|
||||
public ChatFormatEvent(@NonNull ChatUser sender, @Nullable ChatUser target, @NonNull ChatChannel chatChannel, @Nullable String format, @NonNull String message) {
|
||||
public ChatFormatEvent(@NonNull final ChatUser sender, @Nullable final ChatUser target,
|
||||
@NonNull final ChatChannel chatChannel, @Nullable final String format,
|
||||
@NonNull final String message) {
|
||||
super(!Bukkit.isPrimaryThread());
|
||||
|
||||
this.sender = sender;
|
||||
@@ -43,11 +45,11 @@ public class ChatFormatEvent extends Event implements Cancellable {
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
return this.isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.isCancelled = cancelled;
|
||||
}
|
||||
|
||||
@@ -58,44 +60,45 @@ public class ChatFormatEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@SuppressWarnings("checkstyle:MethodName")
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS_LIST;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatUser getSender() {
|
||||
return sender;
|
||||
public ChatUser sender() {
|
||||
return this.sender;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ChatUser getTarget() {
|
||||
return target;
|
||||
public ChatUser target() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatChannel getChannel() {
|
||||
return chatChannel;
|
||||
public ChatChannel channel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
public void setChannel(@NonNull ChatChannel chatChannel) {
|
||||
public void channel(@NonNull final ChatChannel chatChannel) {
|
||||
this.chatChannel = chatChannel;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getFormat() {
|
||||
return format;
|
||||
public String format() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public void setFormat(@Nullable String format) {
|
||||
public void format(@Nullable final String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getMessage() {
|
||||
return message;
|
||||
public String message() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(@NonNull String message) {
|
||||
public void message(@NonNull final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,8 @@ public class PreChatFormatEvent extends Event implements Cancellable {
|
||||
@NonNull
|
||||
private String message;
|
||||
|
||||
public PreChatFormatEvent(@NonNull ChatUser user, @NonNull ChatChannel chatChannel, @Nullable String format, @NonNull String message) {
|
||||
public PreChatFormatEvent(@NonNull final ChatUser user, @NonNull final ChatChannel chatChannel,
|
||||
@Nullable final String format, @NonNull final String message) {
|
||||
super(!Bukkit.isPrimaryThread());
|
||||
|
||||
this.user = user;
|
||||
@@ -38,11 +39,11 @@ public class PreChatFormatEvent extends Event implements Cancellable {
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
return this.isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.isCancelled = cancelled;
|
||||
}
|
||||
|
||||
@@ -53,39 +54,40 @@ public class PreChatFormatEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@SuppressWarnings("checkstyle:MethodName")
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS_LIST;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatUser getUser() {
|
||||
return user;
|
||||
public ChatUser user() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatChannel getChannel() {
|
||||
return chatChannel;
|
||||
public ChatChannel channel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
public void setChannel(@NonNull ChatChannel chatChannel) {
|
||||
public void channel(@NonNull final ChatChannel chatChannel) {
|
||||
this.chatChannel = chatChannel;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getFormat() {
|
||||
return format;
|
||||
public String format() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public void setFormat(@Nullable String format) {
|
||||
public void format(@Nullable final String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getMessage() {
|
||||
return message;
|
||||
public String message() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(@NonNull String message) {
|
||||
public void message(@NonNull final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,17 +24,18 @@ public class PrivateMessageEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@SuppressWarnings("checkstyle:MethodName")
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@@ -56,7 +57,10 @@ public class PrivateMessageEvent extends Event implements Cancellable {
|
||||
@NonNull
|
||||
private final String message;
|
||||
|
||||
public PrivateMessageEvent(@NonNull ChatUser sender, @NonNull ChatUser target, @NonNull Component senderComponent, @NonNull Component targetComponent, @NonNull String message) {
|
||||
public PrivateMessageEvent(@NonNull final ChatUser sender, @NonNull final ChatUser target,
|
||||
@NonNull final Component senderComponent, @NonNull final Component targetComponent,
|
||||
@NonNull final String message) {
|
||||
|
||||
super(!Bukkit.isPrimaryThread());
|
||||
|
||||
this.sender = sender;
|
||||
@@ -67,28 +71,28 @@ public class PrivateMessageEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatUser getSender() {
|
||||
return sender;
|
||||
public ChatUser sender() {
|
||||
return this.sender;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatUser getTarget() {
|
||||
return target;
|
||||
public ChatUser target() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Component getSenderComponent() {
|
||||
return senderComponent;
|
||||
public Component senderComponent() {
|
||||
return this.senderComponent;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Component getTargetComponent() {
|
||||
return targetComponent;
|
||||
public Component targetComponent() {
|
||||
return this.targetComponent;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getMessage() {
|
||||
return message;
|
||||
public String message() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,35 +14,34 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitChatListener implements Listener {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public BukkitChatListener(@NonNull CarbonChat carbonChat) {
|
||||
public BukkitChatListener(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
// Chat messages
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerchat(@NonNull final AsyncPlayerChatEvent event) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer());
|
||||
ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (channel.shouldCancelChatEvent()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
for (final ChatChannel entry : carbonChat.getChannelManager().getRegistry().values()) {
|
||||
if (entry.getMessagePrefix() == null || entry.getMessagePrefix().isEmpty()) {
|
||||
for (final ChatChannel entry : this.carbonChat.getChannelManager().registry().values()) {
|
||||
if (entry.messagePrefix() == null || entry.messagePrefix().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event.getMessage().startsWith(entry.getMessagePrefix())) {
|
||||
if (event.getMessage().startsWith(entry.messagePrefix())) {
|
||||
if (entry.canPlayerUse(user)) {
|
||||
event.setMessage(event.getMessage().substring(entry.getMessagePrefix().length()));
|
||||
event.setMessage(event.getMessage().substring(entry.messagePrefix().length()));
|
||||
channel = entry;
|
||||
break;
|
||||
}
|
||||
@@ -60,30 +59,30 @@ public class BukkitChatListener implements Listener {
|
||||
if (selectedChannel.honorsRecipientList()) {
|
||||
recipients = new HashSet<>();
|
||||
|
||||
for (Player recipient : event.getRecipients()) {
|
||||
recipients.add(carbonChat.getUserService().wrap(recipient));
|
||||
for (final Player recipient : event.getRecipients()) {
|
||||
recipients.add(this.carbonChat.getUserService().wrap(recipient));
|
||||
}
|
||||
} else {
|
||||
recipients = (List<ChatUser>) selectedChannel.audiences();
|
||||
recipients = selectedChannel.audiences();
|
||||
}
|
||||
|
||||
event.getRecipients().clear();
|
||||
|
||||
if (event.isAsynchronous()) {
|
||||
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||
final Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||
|
||||
event.setFormat(CarbonChat.LEGACY.serialize(component)
|
||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||
final Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||
this.carbonChat.getAdventureManager().audiences().console().sendMessage(component);
|
||||
|
||||
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.");
|
||||
if (this.carbonChat.getConfig().getBoolean("show-tips")) {
|
||||
this.carbonChat.getLogger().info("Tip: Sync chat event! I cannot set the message format due to this. :(");
|
||||
this.carbonChat.getLogger().info("Tip: To 'solve' this, do a binary search and see which plugin is triggering");
|
||||
this.carbonChat.getLogger().info("Tip: sync chat events and causing this, and let that plugin author know.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,38 +12,38 @@ public class CapsHandler implements Listener {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CapsHandler(@NonNull CarbonChat carbonChat) {
|
||||
public CapsHandler(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onMessage(PreChatFormatEvent event) {
|
||||
if (!carbonChat.getModConfig().getBoolean("caps-protection.enabled")) {
|
||||
public void onMessage(final PreChatFormatEvent event) {
|
||||
if (!this.carbonChat.getModConfig().getBoolean("caps-protection.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getMessage().length() >= carbonChat.getModConfig().getInt("caps-protection.minimum-length"))) {
|
||||
if (!(event.message().length() >= this.carbonChat.getModConfig().getInt("caps-protection.minimum-length"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
int amountOfCaps = 0;
|
||||
|
||||
for (char letter : event.getMessage().toCharArray()) {
|
||||
for (final char letter : event.message().toCharArray()) {
|
||||
if (Character.isUpperCase(letter)) {
|
||||
amountOfCaps++;
|
||||
}
|
||||
}
|
||||
|
||||
double capsPercentage = (amountOfCaps * 100.0) / event.getMessage().length();
|
||||
final double capsPercentage = (amountOfCaps * 100.0) / event.message().length();
|
||||
|
||||
if (!(capsPercentage >= carbonChat.getModConfig().getDouble("caps-protection.percent-caps"))) {
|
||||
if (!(capsPercentage >= this.carbonChat.getModConfig().getDouble("caps-protection.percent-caps"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (carbonChat.getModConfig().getBoolean("block-message")) {
|
||||
if (this.carbonChat.getModConfig().getBoolean("block-message")) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
event.setMessage(event.getMessage().toLowerCase());
|
||||
event.message(event.message().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,23 +6,24 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class CustomPlaceholderHandler implements Listener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CustomPlaceholderHandler(CarbonChat carbonChat) {
|
||||
public CustomPlaceholderHandler(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPapiPlaceholder(PreChatFormatEvent event) {
|
||||
ConfigurationSection placeholders = carbonChat.getConfig().getConfigurationSection("placeholders");
|
||||
public void onPapiPlaceholder(final PreChatFormatEvent event) {
|
||||
final ConfigurationSection placeholders = this.carbonChat.getConfig().getConfigurationSection("placeholders");
|
||||
|
||||
for (String key : placeholders.getKeys(false)) {
|
||||
String value = placeholders.getString(key);
|
||||
for (final String key : placeholders.getKeys(false)) {
|
||||
final String value = placeholders.getString(key);
|
||||
|
||||
event.setFormat(event.getFormat().replace("<" + key + ">", value));
|
||||
event.format(event.format().replace("<" + key + ">", value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,70 +23,69 @@ public class FilterHandler implements Listener {
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@NonNull
|
||||
private final Map<String, List<Pattern>> patternReplacements = new HashMap<>();
|
||||
private final Map<String, List<@NonNull Pattern>> patternReplacements = new HashMap<>();
|
||||
|
||||
@NonNull
|
||||
private final List<Pattern> blockedWords = new ArrayList<>();
|
||||
private final List<@NonNull Pattern> blockedWords = new ArrayList<>();
|
||||
|
||||
public FilterHandler(@NonNull CarbonChat carbonChat) {
|
||||
public FilterHandler(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
reloadFilters();
|
||||
this.reloadFilters();
|
||||
}
|
||||
|
||||
public void reloadFilters() {
|
||||
patternReplacements.clear();
|
||||
blockedWords.clear();
|
||||
this.patternReplacements.clear();
|
||||
this.blockedWords.clear();
|
||||
|
||||
FileConfiguration config = carbonChat.getModConfig();
|
||||
ConfigurationSection filters = config.getConfigurationSection("filters.filters");
|
||||
final FileConfiguration config = this.carbonChat.getModConfig();
|
||||
final ConfigurationSection filters = config.getConfigurationSection("filters.filters");
|
||||
|
||||
if (filters != null) {
|
||||
for (String replacement : filters.getKeys(false)) {
|
||||
List<Pattern> patterns = new ArrayList<>();
|
||||
for (final String replacement : filters.getKeys(false)) {
|
||||
final List<Pattern> patterns = new ArrayList<>();
|
||||
|
||||
for (String word : filters.getStringList(replacement)) {
|
||||
if (carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
||||
for (final String word : filters.getStringList(replacement)) {
|
||||
if (this.carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
||||
patterns.add(Pattern.compile(word));
|
||||
} else {
|
||||
patterns.add(Pattern.compile(word, Pattern.CASE_INSENSITIVE));
|
||||
}
|
||||
}
|
||||
|
||||
patternReplacements.put(replacement, patterns);
|
||||
this.patternReplacements.put(replacement, patterns);
|
||||
}
|
||||
}
|
||||
|
||||
for (String replacement : config.getStringList("filters.blocked-words")) {
|
||||
if (carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
||||
blockedWords.add(Pattern.compile(replacement));
|
||||
for (final String replacement : config.getStringList("filters.blocked-words")) {
|
||||
if (this.carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
||||
this.blockedWords.add(Pattern.compile(replacement));
|
||||
} else {
|
||||
blockedWords.add(Pattern.compile(replacement, Pattern.CASE_INSENSITIVE));
|
||||
this.blockedWords.add(Pattern.compile(replacement, Pattern.CASE_INSENSITIVE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onFilter(PreChatFormatEvent event) {
|
||||
if (!carbonChat.getModConfig().getBoolean("filters.enabled")) {
|
||||
public void onFilter(final PreChatFormatEvent event) {
|
||||
if (!this.carbonChat.getModConfig().getBoolean("filters.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getUser().online()) {
|
||||
if (event.getUser().player().hasPermission("carbonchat.filter.exempt")) {
|
||||
if (event.user().online()) {
|
||||
if (event.user().player().hasPermission("carbonchat.filter.exempt")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!channelUsesFilter(event.getChannel())) {
|
||||
if (!this.channelUsesFilter(event.channel())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String message = event.getMessage();
|
||||
//Matcher matcher;
|
||||
String message = event.message();
|
||||
|
||||
for (Map.Entry<String, List<Pattern>> entry : patternReplacements.entrySet()) {
|
||||
for (Pattern pattern : entry.getValue()) {
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
for (final Map.Entry<String, List<Pattern>> entry : this.patternReplacements.entrySet()) {
|
||||
for (final Pattern pattern : entry.getValue()) {
|
||||
final Matcher matcher = pattern.matcher(message);
|
||||
|
||||
if (entry.getKey().equals("_")) {
|
||||
message = matcher.replaceAll("");
|
||||
@@ -96,18 +95,18 @@ public class FilterHandler implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message);
|
||||
event.message(message);
|
||||
|
||||
for (Pattern blockedWord : blockedWords) {
|
||||
if (blockedWord.matcher(event.getMessage()).find()) {
|
||||
for (final Pattern blockedWord : this.blockedWords) {
|
||||
if (blockedWord.matcher(event.message()).find()) {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean channelUsesFilter(@NonNull ChatChannel chatChannel) {
|
||||
Object filter = chatChannel.getContext("filter");
|
||||
private boolean channelUsesFilter(@NonNull final ChatChannel chatChannel) {
|
||||
final Object filter = chatChannel.context("filter");
|
||||
|
||||
return filter instanceof Boolean && ((Boolean) filter);
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ import org.bukkit.event.Listener;
|
||||
public class IgnoredPlayerHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPapiPlaceholder(ChatFormatEvent event) {
|
||||
if (event.getTarget() == null) {
|
||||
public void onPapiPlaceholder(final ChatFormatEvent event) {
|
||||
if (event.target() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getTarget().isIgnoringUser(event.getSender())) {
|
||||
if (event.target().ignoringUser(event.sender())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,30 +14,30 @@ import java.util.regex.Pattern;
|
||||
public class ItemLinkHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onItemLink(ChatComponentEvent event) {
|
||||
public void onItemLink(final ChatComponentEvent event) {
|
||||
// Handle item linking placeholders
|
||||
if (event.getSender().online()) {
|
||||
Player player = event.getSender().player();
|
||||
if (event.sender().online()) {
|
||||
final Player player = event.sender().player();
|
||||
|
||||
if (!player.hasPermission("carbonchat.itemlink")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Component itemComponent = CarbonUtils.createComponent(player);
|
||||
final Component itemComponent = CarbonUtils.createComponent(player);
|
||||
|
||||
if (itemComponent.equals(TextComponent.empty())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Pattern pattern : event.getChannel().getItemLinkPatterns()) {
|
||||
String patternContent = pattern.toString().replace("\\Q", "").replace("\\E", "");
|
||||
for (final Pattern pattern : event.channel().itemLinkPatterns()) {
|
||||
final String patternContent = pattern.toString().replace("\\Q", "").replace("\\E", "");
|
||||
|
||||
if (event.getOriginalMessage().contains(patternContent)) {
|
||||
TextComponent component = (TextComponent) event.getComponent().replaceFirstText(pattern, (input) -> {
|
||||
if (event.originalMessage().contains(patternContent)) {
|
||||
final TextComponent component = (TextComponent) event.component().replaceFirstText(pattern, input -> {
|
||||
return TextComponent.builder().append(itemComponent);
|
||||
});
|
||||
|
||||
event.setComponent(component);
|
||||
event.component(component);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ import org.bukkit.event.Listener;
|
||||
public class LegacyFormatHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onLegacyFormat(PreChatFormatEvent event) {
|
||||
Component component = CarbonChat.LEGACY.deserialize(event.getFormat());
|
||||
event.setFormat(MiniMessage.get().serialize(component));
|
||||
public void onLegacyFormat(final PreChatFormatEvent event) {
|
||||
final Component component = CarbonChat.LEGACY.deserialize(event.format());
|
||||
event.format(MiniMessage.get().serialize(component));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import org.bukkit.event.Listener;
|
||||
public class MuteHandler implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onMute(PreChatFormatEvent event) {
|
||||
if (event.getUser().isMuted()) {
|
||||
public void onMute(final PreChatFormatEvent event) {
|
||||
if (event.user().muted()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ import org.bukkit.event.Listener;
|
||||
public class OfflineNameHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onOfflineMessage(PreChatFormatEvent event) {
|
||||
public void onOfflineMessage(final PreChatFormatEvent event) {
|
||||
// If the player isn't online (cross server message), use their normal name
|
||||
if (!event.getUser().online()) {
|
||||
event.setFormat(event.getFormat().replace("%player_displayname%", "%player_name%"));
|
||||
if (!event.user().online()) {
|
||||
event.format(event.format().replace("%player_displayname%", "%player_name%"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,44 +14,44 @@ public class PingHandler implements Listener {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public PingHandler(@NonNull CarbonChat carbonChat) {
|
||||
public PingHandler(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPing(ChatComponentEvent event) {
|
||||
if (!carbonChat.getConfig().getBoolean("pings.enabled")) {
|
||||
public void onPing(final ChatComponentEvent event) {
|
||||
if (!this.carbonChat.getConfig().getBoolean("pings.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getTarget() == null) {
|
||||
if (event.target() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String targetName = event.getTarget().offlinePlayer().getName();
|
||||
String prefix = carbonChat.getConfig().getString("pings.prefix", "");
|
||||
boolean caseSensitive = carbonChat.getConfig().getBoolean("pings.case-sensitive", false);
|
||||
final String targetName = event.target().offlinePlayer().getName();
|
||||
final String prefix = this.carbonChat.getConfig().getString("pings.prefix", "");
|
||||
final boolean caseSensitive = this.carbonChat.getConfig().getBoolean("pings.case-sensitive", false);
|
||||
|
||||
if (targetName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (caseSensitive) {
|
||||
if (!event.getOriginalMessage().contains(prefix + targetName)) {
|
||||
if (!event.originalMessage().contains(prefix + targetName)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!event.getOriginalMessage().toLowerCase().contains((prefix + targetName).toLowerCase())) {
|
||||
if (!event.originalMessage().toLowerCase().contains((prefix + targetName).toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Key key = Key.of(carbonChat.getConfig().getString("pings.sound"));
|
||||
Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("pings.source"));
|
||||
float volume = (float) carbonChat.getConfig().getDouble("pings.volume");
|
||||
float pitch = (float) carbonChat.getConfig().getDouble("pings.pitch");
|
||||
final Key key = Key.of(this.carbonChat.getConfig().getString("pings.sound"));
|
||||
final Sound.Source source = Sound.Source.valueOf(this.carbonChat.getConfig().getString("pings.source"));
|
||||
final float volume = (float) this.carbonChat.getConfig().getDouble("pings.volume");
|
||||
final float pitch = (float) this.carbonChat.getConfig().getDouble("pings.pitch");
|
||||
|
||||
event.getTarget().playSound(Sound.of(key, source, volume, pitch));
|
||||
event.target().playSound(Sound.of(key, source, volume, pitch));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,8 +9,8 @@ import org.bukkit.event.Listener;
|
||||
public class PlaceholderHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPapiPlaceholder(PreChatFormatEvent event) {
|
||||
event.setFormat(PlaceholderAPI.setPlaceholders(event.getUser().offlinePlayer(), event.getFormat()));
|
||||
public void onPapiPlaceholder(final PreChatFormatEvent event) {
|
||||
event.format(PlaceholderAPI.setPlaceholders(event.user().offlinePlayer(), event.format()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,32 +14,32 @@ public class PlayerJoinListener implements Listener {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public PlayerJoinListener(@NonNull CarbonChat carbonChat) {
|
||||
public PlayerJoinListener(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer());
|
||||
|
||||
carbonChat.getUserService().validate(user);
|
||||
this.carbonChat.getUserService().validate(user);
|
||||
|
||||
if (user.nickname() != null) {
|
||||
user.nickname(user.nickname());
|
||||
}
|
||||
|
||||
String channel = carbonChat.getConfig().getString("channel-on-join");
|
||||
final String channel = this.carbonChat.getConfig().getString("channel-on-join");
|
||||
|
||||
if (channel == null || channel.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel.equals("DEFAULT")) {
|
||||
user.selectedChannel(carbonChat.getChannelManager().getDefaultChannel());
|
||||
user.selectedChannel(this.carbonChat.getChannelManager().defaultChannel());
|
||||
return;
|
||||
}
|
||||
|
||||
ChatChannel chatChannel = carbonChat.getChannelManager().getRegistry().get(channel);
|
||||
final ChatChannel chatChannel = this.carbonChat.getChannelManager().registry().channel(channel);
|
||||
|
||||
if (chatChannel != null) {
|
||||
user.selectedChannel(chatChannel);
|
||||
@@ -47,11 +47,11 @@ public class PlayerJoinListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
ChatUser user = carbonChat.getUserService().wrapIfLoaded(event.getPlayer());
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
final ChatUser user = this.carbonChat.getUserService().wrapIfLoaded(event.getPlayer());
|
||||
|
||||
if (user != null) {
|
||||
carbonChat.getUserService().invalidate(user);
|
||||
this.carbonChat.getUserService().invalidate(user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,19 +10,19 @@ import org.bukkit.event.Listener;
|
||||
public class RelationalPlaceholderHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPapiPlaceholder(ChatFormatEvent event) {
|
||||
if (event.getTarget() == null) {
|
||||
public void onPapiPlaceholder(final ChatFormatEvent event) {
|
||||
if (event.target() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getSender().online() || !event.getTarget().online()) {
|
||||
if (!event.sender().online() || !event.target().online()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player sender = event.getSender().player();
|
||||
Player target = event.getTarget().player();
|
||||
final Player sender = event.sender().player();
|
||||
final Player target = event.target().player();
|
||||
|
||||
event.setFormat(PlaceholderAPI.setRelationalPlaceholders(sender, target, event.getFormat()));
|
||||
event.format(PlaceholderAPI.setRelationalPlaceholders(sender, target, event.format()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,32 +13,32 @@ public class ShadowMuteHandler implements Listener {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ShadowMuteHandler(@NonNull CarbonChat carbonChat) {
|
||||
public ShadowMuteHandler(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onComponent(ChatComponentEvent event) {
|
||||
if (event.getSender().isShadowMuted()) {
|
||||
if (!event.getSender().equals(event.getTarget())) {
|
||||
public void onComponent(final ChatComponentEvent event) {
|
||||
if (event.sender().shadowMuted()) {
|
||||
if (!event.sender().equals(event.target())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(ChatFormatEvent event) {
|
||||
if (event.getTarget() != null) {
|
||||
public void on(final ChatFormatEvent event) {
|
||||
if (event.target() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getSender().isShadowMuted()) {
|
||||
if (!event.sender().shadowMuted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String prefix = carbonChat.getModConfig().getString("shadow-mute-prefix", "[SM] ");
|
||||
final String prefix = this.carbonChat.getModConfig().getString("shadow-mute-prefix", "[SM] ");
|
||||
|
||||
event.setFormat(prefix + event.getFormat());
|
||||
event.format(prefix + event.format());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,25 +10,25 @@ import org.bukkit.event.Listener;
|
||||
public class UserFormattingHandler implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onFormat(PreChatFormatEvent event) {
|
||||
if (!event.getUser().online()) {
|
||||
suppressFormatting(event);
|
||||
public void onFormat(final PreChatFormatEvent event) {
|
||||
if (!event.user().online()) {
|
||||
this.suppressFormatting(event);
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getUser().player();
|
||||
final Player player = event.user().player();
|
||||
|
||||
if (!player.hasPermission("carbonchat.formatting") &&
|
||||
!player.hasPermission("carbonchat.channels." + event.getChannel().getKey() + ".formatting")) {
|
||||
suppressFormatting(event);
|
||||
!player.hasPermission("carbonchat.channels." + event.channel().key() + ".formatting")) {
|
||||
this.suppressFormatting(event);
|
||||
} else {
|
||||
// Swap the &-style codes for minimessage-compatible strings
|
||||
event.setMessage(MiniMessage.get().serialize(CarbonChat.LEGACY.deserialize(event.getMessage())));
|
||||
event.message(MiniMessage.get().serialize(CarbonChat.LEGACY.deserialize(event.message())));
|
||||
}
|
||||
}
|
||||
|
||||
private void suppressFormatting(PreChatFormatEvent event) {
|
||||
event.setFormat(event.getFormat().replace("<message>", "<pre><message></pre>"));
|
||||
private void suppressFormatting(final PreChatFormatEvent event) {
|
||||
event.format(event.format().replace("<message>", "<pre><message></pre>"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,32 +14,32 @@ public class WhisperPingHandler implements Listener {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public WhisperPingHandler(@NonNull CarbonChat carbonChat) {
|
||||
public WhisperPingHandler(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPing(PrivateMessageEvent event) {
|
||||
if (event.getSender().uuid().equals(event.getTarget().uuid())) {
|
||||
public void onPing(final PrivateMessageEvent event) {
|
||||
if (event.sender().uuid().equals(event.target().uuid())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String senderName = event.getSender().offlinePlayer().getName();
|
||||
final String senderName = event.sender().offlinePlayer().getName();
|
||||
|
||||
if (senderName == null || !event.getMessage().contains(senderName)) {
|
||||
if (senderName == null || !event.message().contains(senderName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!carbonChat.getConfig().getBoolean("whisper.pings.enabled")) {
|
||||
if (!this.carbonChat.getConfig().getBoolean("whisper.pings.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Key key = Key.of(carbonChat.getConfig().getString("whisper.pings.sound"));
|
||||
Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("whisper.pings.source"));
|
||||
float volume = (float) carbonChat.getConfig().getDouble("whisper.pings.volume");
|
||||
float pitch = (float) carbonChat.getConfig().getDouble("whisper.pings.pitch");
|
||||
final Key key = Key.of(this.carbonChat.getConfig().getString("whisper.pings.sound"));
|
||||
final Sound.Source source = Sound.Source.valueOf(this.carbonChat.getConfig().getString("whisper.pings.source"));
|
||||
final float volume = (float) this.carbonChat.getConfig().getDouble("whisper.pings.volume");
|
||||
final float pitch = (float) this.carbonChat.getConfig().getDouble("whisper.pings.pitch");
|
||||
|
||||
event.getSender().playSound(Sound.of(key, source, volume, pitch));
|
||||
event.sender().playSound(Sound.of(key, source, volume, pitch));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,33 +19,34 @@ public class AdventureManager {
|
||||
@NonNull
|
||||
private final BukkitAudiences audiences;
|
||||
|
||||
public AdventureManager(@NonNull CarbonChat carbonChat) {
|
||||
public AdventureManager(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.audiences = BukkitAudiences.create(carbonChat);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Component processMessageWithPapi(@NonNull Player player, @Nullable String input, @NonNull String @NonNull ... placeholders) {
|
||||
public Component processMessageWithPapi(@NonNull final Player player, @Nullable final String input,
|
||||
@NonNull final String @NonNull ... placeholders) {
|
||||
if (input == null || input.trim().isEmpty()) {
|
||||
return TextComponent.empty();
|
||||
}
|
||||
|
||||
return processMessage(PlaceholderAPI.setPlaceholders(player, input), placeholders);
|
||||
return this.processMessage(PlaceholderAPI.setPlaceholders(player, input), placeholders);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Component processMessage(@Nullable String input, @NonNull String @NonNull ... placeholders) {
|
||||
public Component processMessage(@Nullable final String input, @NonNull final String @NonNull ... placeholders) {
|
||||
if (input == null || input.trim().isEmpty()) {
|
||||
return TextComponent.empty();
|
||||
}
|
||||
|
||||
switch (carbonChat.getLanguage().getString("formatting.type", "minimessage").toLowerCase()) {
|
||||
switch (this.carbonChat.getLanguage().getString("formatting.type", "minimessage").toLowerCase()) {
|
||||
case "minedown":
|
||||
return MineDown.parse(input, placeholders);
|
||||
case "mojang":
|
||||
case "mojangson":
|
||||
case "json":
|
||||
return processMojang(input, placeholders);
|
||||
return this.processMojang(input, placeholders);
|
||||
case "minimessage-markdown":
|
||||
return MiniMessage.markdown().parse(input, placeholders);
|
||||
case "minimessage":
|
||||
@@ -55,19 +56,19 @@ public class AdventureManager {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Component processMojang(@NonNull String input, @NonNull String @NonNull ... placeholders) {
|
||||
private Component processMojang(@NonNull String input, @NonNull final String @NonNull ... placeholders) {
|
||||
for (int i = 0; i < placeholders.length; i += 2) {
|
||||
String placeholder = placeholders[i];
|
||||
String replacement = placeholders[i + 1];
|
||||
final String placeholder = placeholders[i];
|
||||
final String replacement = placeholders[i + 1];
|
||||
|
||||
input = input.replace("<" + placeholder + ">", replacement);
|
||||
}
|
||||
|
||||
return getAudiences().gsonSerializer().deserialize(input);
|
||||
return this.audiences().gsonSerializer().deserialize(input);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public BukkitAudiences getAudiences() {
|
||||
return audiences;
|
||||
public BukkitAudiences audiences() {
|
||||
return this.audiences;
|
||||
}
|
||||
}
|
||||
@@ -26,87 +26,88 @@ public class ChannelManager {
|
||||
@MonotonicNonNull
|
||||
private String defaultChannelKey = null;
|
||||
|
||||
public ChannelManager(CarbonChat carbonChat) {
|
||||
public ChannelManager(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.registry = new ChannelRegistry(carbonChat);
|
||||
|
||||
reload();
|
||||
this.reload();
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel loadChannel(String key, @NonNull ConfigurationSection section) {
|
||||
ChatChannel channel = new CarbonChatChannel(key, carbonChat, section);
|
||||
public @Nullable ChatChannel loadChannel(@NonNull final String key, @NonNull final ConfigurationSection section) {
|
||||
final ChatChannel channel = new CarbonChatChannel(key, this.carbonChat, section);
|
||||
|
||||
String name = section.getString("name");
|
||||
final String name = section.getString("name");
|
||||
|
||||
if (name != null && name.length() > 16) {
|
||||
carbonChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
||||
carbonChat.getLogger().warning("Skipping channel, please check your settings!");
|
||||
this.carbonChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
||||
this.carbonChat.getLogger().warning("Skipping channel, please check your settings!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
public boolean registerChannel(@NonNull ChatChannel channel) {
|
||||
boolean success = getRegistry().register(channel.getKey(), channel);
|
||||
public boolean registerChannel(@NonNull final ChatChannel channel) {
|
||||
final boolean success = this.registry().register(channel.key(), channel);
|
||||
|
||||
if (success) {
|
||||
if (channel.isDefault() && defaultChannelKey == null) {
|
||||
carbonChat.getLogger().info("Default channel registered: " + channel.getName());
|
||||
defaultChannelKey = channel.getKey();
|
||||
if (channel.isDefault() && this.defaultChannelKey == null) {
|
||||
this.carbonChat.getLogger().info("Default channel registered: " + channel.name());
|
||||
this.defaultChannelKey = channel.key();
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(Collections.singletonList(channel), getRegistry()));
|
||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(Collections.singletonList(channel), this.registry()));
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public @NonNull Registry<ChatChannel> getRegistry() {
|
||||
return registry;
|
||||
public @NonNull Registry<ChatChannel> registry() {
|
||||
return this.registry;
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel getDefaultChannel() {
|
||||
if (defaultChannelKey != null) {
|
||||
return registry.get(defaultChannelKey);
|
||||
public @Nullable ChatChannel defaultChannel() {
|
||||
if (this.defaultChannelKey != null) {
|
||||
return this.registry.channel(this.defaultChannelKey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel getChannelOrDefault(@Nullable String key) {
|
||||
public @Nullable ChatChannel channelOrDefault(@Nullable final String key) {
|
||||
if (key == null) {
|
||||
return getDefaultChannel();
|
||||
return this.defaultChannel();
|
||||
}
|
||||
|
||||
ChatChannel channel = registry.get(key);
|
||||
final ChatChannel channel = this.registry.channel(key);
|
||||
|
||||
if (channel == null) {
|
||||
return getDefaultChannel();
|
||||
return this.defaultChannel();
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
registry.clearAll();
|
||||
this.registry.clearAll();
|
||||
|
||||
for (String key : carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
||||
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
||||
for (final String key : this.carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
||||
final ConfigurationSection section =
|
||||
this.carbonChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
||||
|
||||
ChatChannel channel = loadChannel(key, section);
|
||||
final ChatChannel channel = this.loadChannel(key, section);
|
||||
|
||||
if (channel != null) {
|
||||
if (registerChannel(channel)) {
|
||||
String prefix = channel.getMessagePrefix();
|
||||
if (this.registerChannel(channel)) {
|
||||
String prefix = channel.messagePrefix();
|
||||
|
||||
if (prefix != null && !prefix.trim().isEmpty()) {
|
||||
prefix = ("(" + prefix + ") ");
|
||||
prefix = "(" + prefix + ") ";
|
||||
} else {
|
||||
prefix = "";
|
||||
}
|
||||
|
||||
carbonChat.getLogger().info("Registering channel: " + prefix + channel.getName());
|
||||
this.carbonChat.getLogger().info("Registering channel: " + prefix + channel.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,32 +25,33 @@ public class CommandManager {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CommandManager(@NonNull CarbonChat carbonChat) {
|
||||
public CommandManager(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
reloadCommands();
|
||||
|
||||
this.reloadCommands();
|
||||
}
|
||||
|
||||
private void reloadCommands() {
|
||||
new ChannelCommand(carbonChat, getCommandSettings("channel"));
|
||||
new ChannelListCommand(carbonChat, getCommandSettings("channellist"));
|
||||
new ChatReloadCommand(carbonChat, getCommandSettings("chatreload"));
|
||||
new ClearChatCommand(carbonChat, getCommandSettings("clearchat"));
|
||||
new IgnoreCommand(carbonChat, getCommandSettings("ignore"));
|
||||
new MeCommand(carbonChat, getCommandSettings("me"));
|
||||
new MessageCommand(carbonChat, getCommandSettings("message"));
|
||||
new MuteCommand(carbonChat, getCommandSettings("mute"));
|
||||
new NicknameCommand(carbonChat, getCommandSettings("nickname"));
|
||||
new ReplyCommand(carbonChat, getCommandSettings("reply"));
|
||||
new SetColorCommand(carbonChat, getCommandSettings("setcolor"));
|
||||
new ShadowMuteCommand(carbonChat, getCommandSettings("shadowmute"));
|
||||
new SpyChannelCommand(carbonChat, getCommandSettings("spy"));
|
||||
new SudoChannelCommand(carbonChat, getCommandSettings("sudochannel"));
|
||||
new ToggleCommand(carbonChat, getCommandSettings("toggle"));
|
||||
new ChannelCommand(this.carbonChat, this.commandSettings("channel"));
|
||||
new ChannelListCommand(this.carbonChat, this.commandSettings("channellist"));
|
||||
new ChatReloadCommand(this.carbonChat, this.commandSettings("chatreload"));
|
||||
new ClearChatCommand(this.carbonChat, this.commandSettings("clearchat"));
|
||||
new IgnoreCommand(this.carbonChat, this.commandSettings("ignore"));
|
||||
new MeCommand(this.carbonChat, this.commandSettings("me"));
|
||||
new MessageCommand(this.carbonChat, this.commandSettings("message"));
|
||||
new MuteCommand(this.carbonChat, this.commandSettings("mute"));
|
||||
new NicknameCommand(this.carbonChat, this.commandSettings("nickname"));
|
||||
new ReplyCommand(this.carbonChat, this.commandSettings("reply"));
|
||||
new SetColorCommand(this.carbonChat, this.commandSettings("setcolor"));
|
||||
new ShadowMuteCommand(this.carbonChat, this.commandSettings("shadowmute"));
|
||||
new SpyChannelCommand(this.carbonChat, this.commandSettings("spy"));
|
||||
new SudoChannelCommand(this.carbonChat, this.commandSettings("sudochannel"));
|
||||
new ToggleCommand(this.carbonChat, this.commandSettings("toggle"));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private CommandSettings getCommandSettings(@NonNull String command) {
|
||||
ConfigurationSection section = carbonChat.getCommandsConfig().getConfigurationSection(command);
|
||||
private CommandSettings commandSettings(@NonNull final String command) {
|
||||
final ConfigurationSection section = this.carbonChat.getCommandsConfig().getConfigurationSection(command);
|
||||
|
||||
return new CommandSettings(section.getBoolean("enabled"), section.getString("name"),
|
||||
section.getStringList("aliases"));
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ContextManager {
|
||||
for (final Map.Entry<String, Function<MessageContext, Boolean>> handler : this.handlers.entrySet()) {
|
||||
final String key = handler.getKey();
|
||||
|
||||
final Object value = channel.getContext(key);
|
||||
final Object value = channel.context(key);
|
||||
|
||||
if (value == null) {
|
||||
continue;
|
||||
|
||||
@@ -26,11 +26,11 @@ public class MessageManager {
|
||||
@NonNull
|
||||
private final GsonComponentSerializer gsonSerializer;
|
||||
|
||||
public MessageManager(@NonNull CarbonChat carbonChat) {
|
||||
public MessageManager(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.gsonSerializer = carbonChat.getAdventureManager().getAudiences().gsonSerializer();
|
||||
this.gsonSerializer = this.carbonChat.getAdventureManager().audiences().gsonSerializer();
|
||||
|
||||
String messageSystem = carbonChat.getConfig().getString("message-system", "none");
|
||||
String messageSystem = this.carbonChat.getConfig().getString("message-system", "none");
|
||||
|
||||
if (messageSystem == null) {
|
||||
messageSystem = "none";
|
||||
@@ -38,19 +38,19 @@ public class MessageManager {
|
||||
|
||||
switch (messageSystem.toLowerCase()) {
|
||||
case "bungee":
|
||||
carbonChat.getLogger().info("Using Bungee Plugin Messaging for message forwarding!");
|
||||
messageService = new BungeeMessageService(carbonChat);
|
||||
this.carbonChat.getLogger().info("Using Bungee Plugin Messaging for message forwarding!");
|
||||
this.messageService = new BungeeMessageService(this.carbonChat);
|
||||
break;
|
||||
case "redis":
|
||||
carbonChat.getLogger().info("Using Redis for message forwarding!");
|
||||
messageService = new RedisMessageService(carbonChat);
|
||||
this.carbonChat.getLogger().info("Using Redis for message forwarding!");
|
||||
this.messageService = new RedisMessageService(this.carbonChat);
|
||||
break;
|
||||
case "none":
|
||||
messageService = new EmptyMessageService();
|
||||
this.messageService = new EmptyMessageService();
|
||||
break;
|
||||
default:
|
||||
carbonChat.getLogger().info("Invalid message service selected! Disabling syncing until next restart!");
|
||||
messageService = new EmptyMessageService();
|
||||
this.carbonChat.getLogger().info("Invalid message service selected! Disabling syncing until next restart!");
|
||||
this.messageService = new EmptyMessageService();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -58,106 +58,107 @@ public class MessageManager {
|
||||
}
|
||||
|
||||
private void registerDefaultListeners() {
|
||||
getMessageService().registerUserMessageListener("nickname", (user, byteArray) -> {
|
||||
String nickname = byteArray.readUTF();
|
||||
this.messageService().registerUserMessageListener("nickname", (user, byteArray) -> {
|
||||
final String nickname = byteArray.readUTF();
|
||||
|
||||
user.nickname(nickname, true);
|
||||
|
||||
if (user.online()) {
|
||||
String message = carbonChat.getLanguage().getString("nickname-set");
|
||||
final String message = this.carbonChat.getLanguage().getString("nickname-set");
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(user.player(),
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(user.player(),
|
||||
message, "nickname", nickname));
|
||||
}
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("nickname-reset", (user, byteArray) -> {
|
||||
this.messageService().registerUserMessageListener("nickname-reset", (user, byteArray) -> {
|
||||
user.nickname(null, true);
|
||||
|
||||
if (user.online()) {
|
||||
String message = carbonChat.getLanguage().getString("nickname-reset");
|
||||
final String message = this.carbonChat.getLanguage().getString("nickname-reset");
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(user.player(), message));
|
||||
user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(user.player(), message));
|
||||
}
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("selected-channel", (user, byteArray) -> {
|
||||
user.selectedChannel(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()), true);
|
||||
this.messageService().registerUserMessageListener("selected-channel", (user, byteArray) -> {
|
||||
user.selectedChannel(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF()), true);
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("spying-whispers", (user, byteArray) -> {
|
||||
user.setSpyingWhispers(byteArray.readBoolean(), true);
|
||||
this.messageService().registerUserMessageListener("spying-whispers", (user, byteArray) -> {
|
||||
user.spyingWhispers(byteArray.readBoolean(), true);
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("muted", (user, byteArray) -> {
|
||||
user.setMuted(byteArray.readBoolean(), true);
|
||||
this.messageService().registerUserMessageListener("muted", (user, byteArray) -> {
|
||||
user.muted(byteArray.readBoolean(), true);
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("shadow-muted", (user, byteArray) -> {
|
||||
user.setShadowMuted(byteArray.readBoolean(), true);
|
||||
this.messageService().registerUserMessageListener("shadow-muted", (user, byteArray) -> {
|
||||
user.shadowMuted(byteArray.readBoolean(), true);
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("reply-target", (user, byteArray) -> {
|
||||
user.setReplyTarget(new UUID(byteArray.readLong(), byteArray.readLong()), true);
|
||||
this.messageService().registerUserMessageListener("reply-target", (user, byteArray) -> {
|
||||
user.replyTarget(new UUID(byteArray.readLong(), byteArray.readLong()), true);
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("ignoring-user", (user, byteArray) -> {
|
||||
user.setIgnoringUser(new UUID(byteArray.readLong(), byteArray.readLong()), byteArray.readBoolean(), true);
|
||||
this.messageService().registerUserMessageListener("ignoring-user", (user, byteArray) -> {
|
||||
user.ignoringUser(new UUID(byteArray.readLong(), byteArray.readLong()), byteArray.readBoolean(), true);
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("ignoring-channel", (user, byteArray) -> {
|
||||
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
||||
this.messageService().registerUserMessageListener("ignoring-channel", (user, byteArray) -> {
|
||||
user.channelSettings(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF()))
|
||||
.ignoring(byteArray.readBoolean(), true);
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("spying-channel", (user, byteArray) -> {
|
||||
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
||||
this.messageService().registerUserMessageListener("spying-channel", (user, byteArray) -> {
|
||||
user.channelSettings(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF()))
|
||||
.spying(byteArray.readBoolean(), true);
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("channel-color", (user, byteArray) -> {
|
||||
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
||||
this.messageService().registerUserMessageListener("channel-color", (user, byteArray) -> {
|
||||
user.channelSettings(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF()))
|
||||
.color(TextColor.fromHexString(byteArray.readUTF()), true);
|
||||
});
|
||||
|
||||
getMessageService().registerUserMessageListener("channel-color-reset", (user, byteArray) -> {
|
||||
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
||||
this.messageService().registerUserMessageListener("channel-color-reset", (user, byteArray) -> {
|
||||
user.channelSettings(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF()))
|
||||
.color(null, true);
|
||||
});
|
||||
|
||||
getMessageService().registerUUIDMessageListener("channel-component", (uuid, byteArray) -> {
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF());
|
||||
ChatUser user = carbonChat.getUserService().wrap(uuid);
|
||||
this.messageService().registerUUIDMessageListener("channel-component", (uuid, byteArray) -> {
|
||||
final ChatChannel channel = this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF());
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(uuid);
|
||||
|
||||
if (channel != null) {
|
||||
Component component = gsonSerializer.deserialize(byteArray.readUTF());
|
||||
final Component component = this.gsonSerializer.deserialize(byteArray.readUTF());
|
||||
|
||||
channel.sendComponent(user, component);
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||
this.carbonChat.getAdventureManager().audiences().console().sendMessage(component);
|
||||
}
|
||||
});
|
||||
|
||||
getMessageService().registerUUIDMessageListener("whisper-component", (uuid, byteArray) -> {
|
||||
UUID recipient = new UUID(byteArray.readLong(), byteArray.readLong());
|
||||
this.messageService().registerUUIDMessageListener("whisper-component", (uuid, byteArray) -> {
|
||||
final UUID recipient = new UUID(byteArray.readLong(), byteArray.readLong());
|
||||
|
||||
ChatUser target = carbonChat.getUserService().wrap(recipient);
|
||||
String message = byteArray.readUTF();
|
||||
final ChatUser target = this.carbonChat.getUserService().wrap(recipient);
|
||||
final String message = byteArray.readUTF();
|
||||
|
||||
if (!target.isIgnoringUser(uuid)) {
|
||||
target.setReplyTarget(uuid);
|
||||
target.sendMessage(gsonSerializer.deserialize(message));
|
||||
if (!target.ignoringUser(uuid)) {
|
||||
target.replyTarget(uuid);
|
||||
target.sendMessage(this.gsonSerializer.deserialize(message));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MessageService getMessageService() {
|
||||
return messageService;
|
||||
public MessageService messageService() {
|
||||
return this.messageService;
|
||||
}
|
||||
|
||||
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
getMessageService().sendMessage(key, uuid, consumer);
|
||||
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid,
|
||||
@NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
this.messageService().sendMessage(key, uuid, consumer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class BungeeMessageService implements MessageService {
|
||||
public BungeeMessageService(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord");
|
||||
this.carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord");
|
||||
|
||||
api = BungeeChannelApi.of(carbonChat);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class BungeeMessageService implements MessageService {
|
||||
}
|
||||
|
||||
private void receiveMessage(@NonNull UUID uuid, @NonNull String key, @NonNull ByteArrayDataInput value) {
|
||||
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
||||
ChatUser user = this.carbonChat.getUserService().wrapIfLoaded(uuid);
|
||||
|
||||
if (user != null) {
|
||||
for (Map.Entry<String, BiConsumer<ChatUser, ByteArrayDataInput>> listener : userLoadedListeners.entrySet()) {
|
||||
|
||||
@@ -13,22 +13,22 @@ import java.util.function.Consumer;
|
||||
public class EmptyMessageService implements MessageService {
|
||||
|
||||
@Override
|
||||
public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
||||
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||
public void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterMessageListener(@NonNull String key) {
|
||||
public void unregisterMessageListener(@NonNull final String key) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,10 @@ public class RedisMessageService implements MessageService {
|
||||
public RedisMessageService(@NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String host = carbonChat.getConfig().getString("redis.host");
|
||||
String password = carbonChat.getConfig().getString("redis.password");
|
||||
int port = carbonChat.getConfig().getInt("redis.port");
|
||||
int database = carbonChat.getConfig().getInt("redis.database");
|
||||
String host = this.carbonChat.getConfig().getString("redis.host");
|
||||
String password = this.carbonChat.getConfig().getString("redis.password");
|
||||
int port = this.carbonChat.getConfig().getInt("redis.port");
|
||||
int database = this.carbonChat.getConfig().getInt("redis.database");
|
||||
|
||||
RedisURI.Builder builder = RedisURI.Builder.redis(host, port)
|
||||
.withDatabase(database);
|
||||
@@ -79,7 +79,7 @@ public class RedisMessageService implements MessageService {
|
||||
}
|
||||
|
||||
private void receiveMessage(@NonNull UUID uuid, @NonNull String key, @NonNull ByteArrayDataInput value) {
|
||||
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
||||
ChatUser user = this.carbonChat.getUserService().wrapIfLoaded(uuid);
|
||||
|
||||
if (user != null) {
|
||||
for (Map.Entry<String, BiConsumer<ChatUser, ByteArrayDataInput>> listener : userLoadedListeners.entrySet()) {
|
||||
|
||||
@@ -43,69 +43,69 @@ public interface ChatUser extends Audience {
|
||||
void clearSelectedChannel();
|
||||
|
||||
@NonNull
|
||||
UserChannelSettings getChannelSettings(@NonNull ChatChannel channel);
|
||||
UserChannelSettings channelSettings(@NonNull ChatChannel channel);
|
||||
|
||||
boolean isSpyingWhispers();
|
||||
boolean spyingwhispers();
|
||||
|
||||
default void setSpyingWhispers(boolean spyingWhispers) {
|
||||
this.setSpyingWhispers(spyingWhispers, false);
|
||||
default void spyingWhispers(boolean spyingWhispers) {
|
||||
this.spyingWhispers(spyingWhispers, false);
|
||||
}
|
||||
|
||||
void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote);
|
||||
void spyingWhispers(boolean spyingWhispers, boolean fromRemote);
|
||||
|
||||
boolean isMuted();
|
||||
boolean muted();
|
||||
|
||||
default void setMuted(boolean muted) {
|
||||
this.setMuted(muted, false);
|
||||
default void muted(boolean muted) {
|
||||
this.muted(muted, false);
|
||||
}
|
||||
|
||||
void setMuted(boolean muted, boolean fromRemote);
|
||||
void muted(boolean muted, boolean fromRemote);
|
||||
|
||||
boolean isShadowMuted();
|
||||
boolean shadowMuted();
|
||||
|
||||
default void setShadowMuted(boolean shadowMuted) {
|
||||
this.setShadowMuted(shadowMuted, false);
|
||||
default void shadowMuted(boolean shadowMuted) {
|
||||
this.shadowMuted(shadowMuted, false);
|
||||
}
|
||||
|
||||
void setShadowMuted(boolean shadowMuted, boolean fromRemote);
|
||||
void shadowMuted(boolean shadowMuted, boolean fromRemote);
|
||||
|
||||
@Nullable
|
||||
UUID getReplyTarget();
|
||||
UUID replyTarget();
|
||||
|
||||
default void setReplyTarget(@Nullable UUID target) {
|
||||
this.setReplyTarget(target, false);
|
||||
default void replyTarget(@Nullable UUID target) {
|
||||
this.replyTarget(target, false);
|
||||
}
|
||||
|
||||
default void setReplyTarget(@Nullable ChatUser user) {
|
||||
this.setReplyTarget(user.uuid(), false);
|
||||
default void replyTarget(@Nullable ChatUser user) {
|
||||
this.replyTarget(user.uuid(), false);
|
||||
}
|
||||
|
||||
void setReplyTarget(@Nullable UUID target, boolean fromRemote);
|
||||
void replyTarget(@Nullable UUID target, boolean fromRemote);
|
||||
|
||||
default void setReplyTarget(@Nullable ChatUser user, boolean fromRemote) {
|
||||
this.setReplyTarget(user.uuid(), fromRemote);
|
||||
default void replyTarget(@Nullable ChatUser user, boolean fromRemote) {
|
||||
this.replyTarget(user.uuid(), fromRemote);
|
||||
}
|
||||
|
||||
boolean isIgnoringUser(@NonNull UUID uuid);
|
||||
boolean ignoringUser(@NonNull UUID uuid);
|
||||
|
||||
void setIgnoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote);
|
||||
void ignoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote);
|
||||
|
||||
default void setIgnoringUser(@NonNull UUID uuid, boolean ignoring) {
|
||||
this.setIgnoringUser(uuid, ignoring, false);
|
||||
default void ignoringUser(@NonNull UUID uuid, boolean ignoring) {
|
||||
this.ignoringUser(uuid, ignoring, false);
|
||||
}
|
||||
|
||||
default boolean isIgnoringUser(@NonNull ChatUser user) {
|
||||
return this.isIgnoringUser(user.uuid());
|
||||
default boolean ignoringUser(@NonNull ChatUser user) {
|
||||
return this.ignoringUser(user.uuid());
|
||||
}
|
||||
|
||||
default void setIgnoringUser(@NonNull ChatUser user, boolean ignoring, boolean fromRemote) {
|
||||
this.setIgnoringUser(user.uuid(), ignoring, fromRemote);
|
||||
default void ignoringUser(@NonNull ChatUser user, boolean ignoring, boolean fromRemote) {
|
||||
this.ignoringUser(user.uuid(), ignoring, fromRemote);
|
||||
}
|
||||
|
||||
default void setIgnoringUser(@NonNull ChatUser user, boolean ignoring) {
|
||||
this.setIgnoringUser(user.uuid(), ignoring, false);
|
||||
default void ignoringUser(@NonNull ChatUser user, boolean ignoring) {
|
||||
this.ignoringUser(user.uuid(), ignoring, false);
|
||||
}
|
||||
|
||||
void sendMessage(@NonNull ChatUser sender, @NonNull String message);
|
||||
void sendMessage(@NonNull final ChatUser sender, @NonNull String message);
|
||||
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
@Override
|
||||
@NonNull
|
||||
public Iterable<@NonNull ? extends Audience> audiences() {
|
||||
return Collections.singleton(carbonChat.getAdventureManager().getAudiences().player(uuid));
|
||||
return Collections.singleton(carbonChat.getAdventureManager().audiences().player(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,7 +98,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
|
||||
if (online()) {
|
||||
if (newNickname != null) {
|
||||
Component component = carbonChat.getAdventureManager().processMessage(nickname);
|
||||
Component component = this.carbonChat.getAdventureManager().processMessage(nickname);
|
||||
newNickname = CarbonChat.LEGACY.serialize(component);
|
||||
}
|
||||
|
||||
@@ -111,10 +111,10 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
|
||||
if (!fromRemote) {
|
||||
if (nickname == null) {
|
||||
carbonChat.getMessageManager().sendMessage("nickname-reset", this.uuid(), (byteArray) -> {
|
||||
this.carbonChat.getMessageManager().sendMessage("nickname-reset", this.uuid(), (byteArray) -> {
|
||||
});
|
||||
} else {
|
||||
carbonChat.getMessageManager().sendMessage("nickname", this.uuid(), (byteArray) -> {
|
||||
this.carbonChat.getMessageManager().sendMessage("nickname", this.uuid(), (byteArray) -> {
|
||||
byteArray.writeUTF(this.nickname);
|
||||
});
|
||||
}
|
||||
@@ -124,45 +124,45 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatChannel selectedChannel() {
|
||||
return carbonChat.getChannelManager().getChannelOrDefault(selectedChannel);
|
||||
return this.carbonChat.getChannelManager().channelOrDefault(selectedChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectedChannel(@NonNull ChatChannel chatChannel, boolean fromRemote) {
|
||||
String failureMessage = chatChannel.getSwitchFailureMessage();
|
||||
String failureMessage = chatChannel.switchFailureMessage();
|
||||
|
||||
ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
|
||||
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
sendMessage(carbonChat.getAdventureManager().processMessage(event.getFailureMessage(),
|
||||
"channel", chatChannel.getName()));
|
||||
sendMessage(carbonChat.getAdventureManager().processMessage(event.failureMessage(),
|
||||
"channel", chatChannel.name()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.selectedChannel = chatChannel.getKey();
|
||||
this.selectedChannel = chatChannel.key();
|
||||
|
||||
if (!fromRemote) {
|
||||
carbonChat.getMessageManager().sendMessage("selected-channel", this.uuid(), (byteArray) -> {
|
||||
byteArray.writeUTF(chatChannel.getKey());
|
||||
this.carbonChat.getMessageManager().sendMessage("selected-channel", this.uuid(), (byteArray) -> {
|
||||
byteArray.writeUTF(chatChannel.key());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSelectedChannel() {
|
||||
selectedChannel(carbonChat.getChannelManager().getDefaultChannel());
|
||||
selectedChannel(carbonChat.getChannelManager().defaultChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIgnoringUser(@NonNull UUID uuid) {
|
||||
public boolean ignoringUser(@NonNull UUID uuid) {
|
||||
return ignoredUsers.contains(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIgnoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote) {
|
||||
public void ignoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote) {
|
||||
if (ignoring) {
|
||||
ignoredUsers.add(uuid);
|
||||
} else {
|
||||
@@ -170,7 +170,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
|
||||
if (!fromRemote) {
|
||||
carbonChat.getMessageManager().sendMessage("ignoring-user", this.uuid(), (byteArray) -> {
|
||||
this.carbonChat.getMessageManager().sendMessage("ignoring-user", this.uuid(), (byteArray) -> {
|
||||
byteArray.writeLong(uuid.getMostSignificantBits());
|
||||
byteArray.writeLong(uuid.getLeastSignificantBits());
|
||||
byteArray.writeBoolean(ignoring);
|
||||
@@ -184,49 +184,49 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMuted(boolean muted, boolean fromRemote) {
|
||||
public void muted(boolean muted, boolean fromRemote) {
|
||||
this.muted = muted;
|
||||
|
||||
if (!fromRemote) {
|
||||
carbonChat.getMessageManager().sendMessage("muted", this.uuid(), (byteArray) -> {
|
||||
this.carbonChat.getMessageManager().sendMessage("muted", this.uuid(), (byteArray) -> {
|
||||
byteArray.writeBoolean(muted);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMuted() {
|
||||
public boolean muted() {
|
||||
return muted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShadowMuted(boolean shadowMuted, boolean fromRemote) {
|
||||
public void shadowMuted(boolean shadowMuted, boolean fromRemote) {
|
||||
this.shadowMuted = shadowMuted;
|
||||
|
||||
if (!fromRemote) {
|
||||
carbonChat.getMessageManager().sendMessage("shadow-muted", this.uuid(), (byteArray) -> {
|
||||
this.carbonChat.getMessageManager().sendMessage("shadow-muted", this.uuid(), (byteArray) -> {
|
||||
byteArray.writeBoolean(shadowMuted);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShadowMuted() {
|
||||
public boolean shadowMuted() {
|
||||
return shadowMuted;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public UUID getReplyTarget() {
|
||||
public UUID replyTarget() {
|
||||
return replyTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReplyTarget(@Nullable UUID target, boolean fromRemote) {
|
||||
public void replyTarget(@Nullable UUID target, boolean fromRemote) {
|
||||
this.replyTarget = target;
|
||||
|
||||
if (!fromRemote) {
|
||||
carbonChat.getMessageManager().sendMessage("reply-target", this.uuid(), (byteArray) -> {
|
||||
this.carbonChat.getMessageManager().sendMessage("reply-target", this.uuid(), (byteArray) -> {
|
||||
byteArray.writeLong(target.getMostSignificantBits());
|
||||
byteArray.writeLong(target.getLeastSignificantBits());
|
||||
});
|
||||
@@ -235,9 +235,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public UserChannelSettings getChannelSettings(@NonNull ChatChannel channel) {
|
||||
return channelSettings.computeIfAbsent(channel.getKey(), (name) -> {
|
||||
return new SimpleUserChannelSettings(uuid, channel.getKey());
|
||||
public UserChannelSettings channelSettings(@NonNull ChatChannel channel) {
|
||||
return channelSettings.computeIfAbsent(channel.key(), (name) -> {
|
||||
return new SimpleUserChannelSettings(uuid, channel.key());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -247,29 +247,29 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote) {
|
||||
public void spyingWhispers(boolean spyingWhispers, boolean fromRemote) {
|
||||
this.spyingWhispers = spyingWhispers;
|
||||
|
||||
if (!fromRemote) {
|
||||
carbonChat.getMessageManager().sendMessage("spying-whispers", this.uuid(), (byteArray) -> {
|
||||
this.carbonChat.getMessageManager().sendMessage("spying-whispers", this.uuid(), (byteArray) -> {
|
||||
byteArray.writeBoolean(spyingWhispers);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpyingWhispers() {
|
||||
public boolean spyingwhispers() {
|
||||
return spyingWhispers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull ChatUser sender, @NonNull String message) {
|
||||
if (isIgnoringUser(sender) || sender.isIgnoringUser(this)) {
|
||||
if (ignoringUser(sender) || sender.ignoringUser(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String toPlayerFormat = carbonChat.getLanguage().getString("message-to-other");
|
||||
String fromPlayerFormat = carbonChat.getLanguage().getString("message-from-other");
|
||||
String toPlayerFormat = this.carbonChat.getLanguage().getString("message-to-other");
|
||||
String fromPlayerFormat = this.carbonChat.getLanguage().getString("message-from-other");
|
||||
|
||||
String senderName = sender.offlinePlayer().getName();
|
||||
String senderOfflineName = senderName;
|
||||
@@ -285,12 +285,12 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
targetName = this.player().getDisplayName();
|
||||
}
|
||||
|
||||
Component toPlayerComponent = carbonChat.getAdventureManager().processMessage(toPlayerFormat, "br", "\n",
|
||||
Component toPlayerComponent = this.carbonChat.getAdventureManager().processMessage(toPlayerFormat, "br", "\n",
|
||||
"message", message,
|
||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||
"target", targetName, "sender", senderName);
|
||||
|
||||
Component fromPlayerComponent = carbonChat.getAdventureManager().processMessage(fromPlayerFormat, "br", "\n",
|
||||
Component fromPlayerComponent = this.carbonChat.getAdventureManager().processMessage(fromPlayerFormat, "br", "\n",
|
||||
"message", message,
|
||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||
"target", targetName, "sender", senderName);
|
||||
@@ -307,20 +307,20 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
if (sender.online()) {
|
||||
sender.sendMessage(toPlayerComponent);
|
||||
|
||||
if (sender.isShadowMuted()) {
|
||||
if (sender.shadowMuted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.sendMessage(fromPlayerComponent);
|
||||
|
||||
sender.setReplyTarget(this);
|
||||
this.setReplyTarget(sender);
|
||||
sender.replyTarget(this);
|
||||
this.replyTarget(sender);
|
||||
|
||||
if (carbonChat.getConfig().getBoolean("pings.on-whisper")) {
|
||||
Key key = Key.of(carbonChat.getConfig().getString("pings.sound"));
|
||||
Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("pings.source"));
|
||||
float volume = (float) carbonChat.getConfig().getDouble("pings.volume");
|
||||
float pitch = (float) carbonChat.getConfig().getDouble("pings.pitch");
|
||||
float volume = (float) this.carbonChat.getConfig().getDouble("pings.volume");
|
||||
float pitch = (float) this.carbonChat.getConfig().getDouble("pings.pitch");
|
||||
|
||||
this.playSound(Sound.of(key, source, volume, pitch));
|
||||
}
|
||||
@@ -330,9 +330,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
final String senderNameFinal = senderName;
|
||||
|
||||
if (!carbonChat.isBungeeEnabled()) {
|
||||
String playerOfflineFormat = carbonChat.getLanguage().getString("other-player-offline");
|
||||
String playerOfflineFormat = this.carbonChat.getLanguage().getString("other-player-offline");
|
||||
|
||||
Component playerOfflineComponent = carbonChat.getAdventureManager().processMessage(playerOfflineFormat,
|
||||
Component playerOfflineComponent = this.carbonChat.getAdventureManager().processMessage(playerOfflineFormat,
|
||||
"br", "\n",
|
||||
"message", message,
|
||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||
@@ -345,9 +345,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
|
||||
BungeeChannelApi.of(carbonChat).getPlayerList("ALL").thenAccept(list -> {
|
||||
if (!list.contains(this.offlinePlayer().getName())) {
|
||||
String playerOfflineFormat = carbonChat.getLanguage().getString("other-player-offline");
|
||||
String playerOfflineFormat = this.carbonChat.getLanguage().getString("other-player-offline");
|
||||
|
||||
Component playerOfflineComponent = carbonChat.getAdventureManager().processMessage(playerOfflineFormat,
|
||||
Component playerOfflineComponent = this.carbonChat.getAdventureManager().processMessage(playerOfflineFormat,
|
||||
"br", "\n",
|
||||
"message", message,
|
||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||
@@ -360,18 +360,18 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
|
||||
sender.sendMessage(toPlayerComponent);
|
||||
|
||||
carbonChat.getMessageManager().sendMessage("whisper-component", sender.uuid(), (byteArray) -> {
|
||||
this.carbonChat.getMessageManager().sendMessage("whisper-component", sender.uuid(), (byteArray) -> {
|
||||
byteArray.writeLong(this.uuid().getMostSignificantBits());
|
||||
byteArray.writeLong(this.uuid().getLeastSignificantBits());
|
||||
byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(fromPlayerComponent));
|
||||
byteArray.writeUTF(carbonChat.getAdventureManager().audiences().gsonSerializer().serialize(fromPlayerComponent));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (!user.isSpyingWhispers()) {
|
||||
if (!user.spyingwhispers()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,108 +33,107 @@ public class JSONUserService implements UserService {
|
||||
@NonNull
|
||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
@NonNull
|
||||
private final Type userType = new TypeToken<CarbonChatUser>() {
|
||||
}.getType();
|
||||
private final Type userType = new TypeToken<CarbonChatUser>() {}.getType();
|
||||
@NonNull
|
||||
private final LoadingCache<@NonNull UUID, @NonNull CarbonChatUser> userCache = CacheBuilder.newBuilder()
|
||||
.removalListener(this::saveUser)
|
||||
.build(CacheLoader.from(this::loadUser));
|
||||
|
||||
public JSONUserService(@NonNull CarbonChat carbonChat) {
|
||||
public JSONUserService(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(carbonChat, userCache::cleanUp, 0L, 20 * 60 * 10);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(carbonChat, this.userCache::cleanUp, 0L, 20 * 60 * 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
userCache.invalidateAll();
|
||||
userCache.cleanUp();
|
||||
this.userCache.invalidateAll();
|
||||
this.userCache.cleanUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrap(@NonNull String name) {
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
public ChatUser wrap(@NonNull final String name) {
|
||||
final Player player = Bukkit.getPlayer(name);
|
||||
|
||||
if (player != null) {
|
||||
return wrap(player);
|
||||
return this.wrap(player);
|
||||
}
|
||||
|
||||
return wrap(Bukkit.getOfflinePlayer(name));
|
||||
return this.wrap(Bukkit.getOfflinePlayer(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrap(@NonNull OfflinePlayer player) {
|
||||
return wrap(player.getUniqueId());
|
||||
public ChatUser wrap(@NonNull final OfflinePlayer player) {
|
||||
return this.wrap(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrap(@NonNull UUID uuid) {
|
||||
public ChatUser wrap(@NonNull final UUID uuid) {
|
||||
try {
|
||||
return userCache.get(uuid);
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
return this.userCache.get(uuid);
|
||||
} catch (final ExecutionException exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrapIfLoaded(@NonNull UUID uuid) {
|
||||
return userCache.getIfPresent(uuid);
|
||||
public ChatUser wrapIfLoaded(@NonNull final UUID uuid) {
|
||||
return this.userCache.getIfPresent(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser refreshUser(@NonNull UUID uuid) {
|
||||
userCache.invalidate(uuid);
|
||||
public ChatUser refreshUser(@NonNull final UUID uuid) {
|
||||
this.userCache.invalidate(uuid);
|
||||
|
||||
return this.wrap(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(@NonNull ChatUser user) {
|
||||
userCache.invalidate(user.uuid());
|
||||
public void invalidate(@NonNull final ChatUser user) {
|
||||
this.userCache.invalidate(user.uuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(@NonNull ChatUser user) {
|
||||
userCache.put(user.uuid(), (CarbonChatUser) user);
|
||||
public void validate(@NonNull final ChatUser user) {
|
||||
this.userCache.put(user.uuid(), (CarbonChatUser) user);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private CarbonChatUser loadUser(@NonNull UUID uuid) {
|
||||
File userFile = new File(carbonChat.getDataFolder(), "users/" + uuid.toString() + ".json");
|
||||
ensureFileExists(userFile);
|
||||
private CarbonChatUser loadUser(@NonNull final UUID uuid) {
|
||||
final File userFile = new File(this.carbonChat.getDataFolder(), "users/" + uuid.toString() + ".json");
|
||||
this.ensureFileExists(userFile);
|
||||
|
||||
try (JsonReader reader = gson.newJsonReader(new FileReader(userFile))) {
|
||||
CarbonChatUser user = gson.fromJson(reader, userType);
|
||||
try (final JsonReader reader = this.gson.newJsonReader(new FileReader(userFile))) {
|
||||
final CarbonChatUser user = this.gson.fromJson(reader, this.userType);
|
||||
|
||||
if (user != null) {
|
||||
return user;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return new CarbonChatUser(uuid);
|
||||
}
|
||||
|
||||
private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
||||
File userFile = new File(carbonChat.getDataFolder(), "users/" + notification.getKey().toString() + ".json");
|
||||
ensureFileExists(userFile);
|
||||
private void saveUser(@NonNull final RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
||||
final File userFile = new File(this.carbonChat.getDataFolder(), "users/" + notification.getKey().toString() + ".json");
|
||||
this.ensureFileExists(userFile);
|
||||
|
||||
try (JsonWriter writer = gson.newJsonWriter(new FileWriter(userFile))) {
|
||||
gson.toJson(notification.getValue(), userType, writer);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
try (final JsonWriter writer = this.gson.newJsonWriter(new FileWriter(userFile))) {
|
||||
this.gson.toJson(notification.getValue(), this.userType, writer);
|
||||
} catch (final IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureFileExists(@NonNull File file) {
|
||||
private void ensureFileExists(@NonNull final File file) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
@@ -142,8 +141,8 @@ public class JSONUserService implements UserService {
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,146 +41,146 @@ public class MySQLUserService implements UserService {
|
||||
.removalListener(this::saveUser)
|
||||
.build(CacheLoader.from(this::loadUser));
|
||||
|
||||
public MySQLUserService(@NonNull CarbonChat carbonChat) {
|
||||
public MySQLUserService(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("storage");
|
||||
final ConfigurationSection section = this.carbonChat.getConfig().getConfigurationSection("storage");
|
||||
|
||||
if (section == null) {
|
||||
throw new IllegalStateException("Missing Database Credentials!");
|
||||
}
|
||||
|
||||
String username = section.getString("username", "username");
|
||||
String password = section.getString("password", "password");
|
||||
String dbname = section.getString("database", "0");
|
||||
String hostandport = section.getString("hostname", "hostname") + ":" + section.getString("port", "0");
|
||||
final String username = section.getString("username", "username");
|
||||
final String password = section.getString("password", "password");
|
||||
final String dbname = section.getString("database", "0");
|
||||
final String hostandport = section.getString("hostname", "hostname") + ":" + section.getString("port", "0");
|
||||
|
||||
database = new HikariPooledDatabase(BukkitDB.getRecommendedOptions(carbonChat, username, password, dbname, hostandport));
|
||||
this.database = new HikariPooledDatabase(BukkitDB.getRecommendedOptions(carbonChat, username, password, dbname, hostandport));
|
||||
|
||||
DB.setGlobalDatabase(database);
|
||||
DB.setGlobalDatabase(this.database);
|
||||
|
||||
try {
|
||||
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_users (uuid CHAR(36) PRIMARY KEY," +
|
||||
this.database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_users (uuid CHAR(36) PRIMARY KEY," +
|
||||
"channel VARCHAR(16), muted BOOLEAN, shadowmuted BOOLEAN, spyingwhispers BOOLEAN," +
|
||||
"nickname VARCHAR(512))");
|
||||
|
||||
// Ignore the exception, it's just saying the column already exists
|
||||
try {
|
||||
database.executeUpdate("ALTER TABLE sc_users ADD COLUMN spyingwhispers BOOLEAN DEFAULT false");
|
||||
database.executeUpdate("ALTER TABLE sc_users ADD COLUMN nickname VARCHAR(512) DEFAULT false");
|
||||
} catch (SQLSyntaxErrorException ignored) {
|
||||
this.database.executeUpdate("ALTER TABLE sc_users ADD COLUMN spyingwhispers BOOLEAN DEFAULT false");
|
||||
this.database.executeUpdate("ALTER TABLE sc_users ADD COLUMN nickname VARCHAR(512) DEFAULT false");
|
||||
} catch (final SQLSyntaxErrorException ignored) {
|
||||
}
|
||||
|
||||
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_channel_settings (uuid CHAR(36), channel CHAR(16), spying BOOLEAN, ignored BOOLEAN, color TINYTEXT, PRIMARY KEY (uuid, channel))");
|
||||
this.database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_channel_settings (uuid CHAR(36), channel CHAR(16), spying BOOLEAN, ignored BOOLEAN, color TINYTEXT, PRIMARY KEY (uuid, channel))");
|
||||
|
||||
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_ignored_users (uuid CHAR(36), user CHAR(36), PRIMARY KEY (uuid, user))");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
this.database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_ignored_users (uuid CHAR(36), user CHAR(36), PRIMARY KEY (uuid, user))");
|
||||
} catch (final SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
userCache.invalidateAll();
|
||||
userCache.cleanUp();
|
||||
database.close();
|
||||
this.userCache.invalidateAll();
|
||||
this.userCache.cleanUp();
|
||||
this.database.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrap(@NonNull String name) {
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
public ChatUser wrap(@NonNull final String name) {
|
||||
final Player player = Bukkit.getPlayer(name);
|
||||
|
||||
if (player != null) {
|
||||
return wrap(player);
|
||||
return this.wrap(player);
|
||||
}
|
||||
|
||||
return wrap(Bukkit.getOfflinePlayer(name));
|
||||
return this.wrap(Bukkit.getOfflinePlayer(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrap(@NonNull OfflinePlayer player) {
|
||||
return wrap(player.getUniqueId());
|
||||
public ChatUser wrap(@NonNull final OfflinePlayer player) {
|
||||
return this.wrap(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrap(@NonNull UUID uuid) {
|
||||
public ChatUser wrap(@NonNull final UUID uuid) {
|
||||
try {
|
||||
return userCache.get(uuid);
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
return this.userCache.get(uuid);
|
||||
} catch (final ExecutionException exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrapIfLoaded(@NonNull UUID uuid) {
|
||||
return userCache.getIfPresent(uuid);
|
||||
public ChatUser wrapIfLoaded(@NonNull final UUID uuid) {
|
||||
return this.userCache.getIfPresent(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser refreshUser(@NonNull UUID uuid) {
|
||||
userCache.invalidate(uuid);
|
||||
public ChatUser refreshUser(@NonNull final UUID uuid) {
|
||||
this.userCache.invalidate(uuid);
|
||||
|
||||
return this.wrap(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(@NonNull ChatUser user) {
|
||||
userCache.invalidate(user.uuid());
|
||||
public void invalidate(@NonNull final ChatUser user) {
|
||||
this.userCache.invalidate(user.uuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(@NonNull ChatUser user) {
|
||||
userCache.put(user.uuid(), (CarbonChatUser) user);
|
||||
public void validate(@NonNull final ChatUser user) {
|
||||
this.userCache.put(user.uuid(), (CarbonChatUser) user);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private CarbonChatUser loadUser(@NonNull UUID uuid) {
|
||||
CarbonChatUser user = new CarbonChatUser(uuid);
|
||||
private CarbonChatUser loadUser(@NonNull final UUID uuid) {
|
||||
final CarbonChatUser user = new CarbonChatUser(uuid);
|
||||
|
||||
try (DbStatement statement = database.query("SELECT * from sc_users WHERE uuid = ?;")) {
|
||||
try (final DbStatement statement = this.database.query("SELECT * from sc_users WHERE uuid = ?;")) {
|
||||
statement.execute(uuid.toString());
|
||||
|
||||
DbRow users = statement.getNextRow();
|
||||
final DbRow users = statement.getNextRow();
|
||||
|
||||
if (users == null) {
|
||||
return user;
|
||||
}
|
||||
|
||||
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());
|
||||
final List<DbRow> channelSettings = this.database.getResults("SELECT * from sc_channel_settings WHERE uuid = ?;", uuid.toString());
|
||||
final List<DbRow> ignoredUsers = this.database.getResults("SELECT * from sc_ignored_users WHERE uuid = ?;", uuid.toString());
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getChannelOrDefault(users.getString("channel"));
|
||||
final ChatChannel channel = this.carbonChat.getChannelManager().channelOrDefault(users.getString("channel"));
|
||||
|
||||
if (channel != null) {
|
||||
user.selectedChannel(channel, true);
|
||||
}
|
||||
|
||||
String nickname = users.getString("nickname");
|
||||
final String nickname = users.getString("nickname");
|
||||
|
||||
if (nickname != null) {
|
||||
user.nickname(nickname, true);
|
||||
}
|
||||
|
||||
user.setMuted(users.<Boolean>get("muted"), true);
|
||||
user.setShadowMuted(users.<Boolean>get("shadowmuted"), true);
|
||||
user.setSpyingWhispers(users.<Boolean>get("spyingwhispers"), true);
|
||||
user.muted(users.<Boolean>get("muted"), true);
|
||||
user.shadowMuted(users.<Boolean>get("shadowmuted"), true);
|
||||
user.spyingWhispers(users.<Boolean>get("spyingwhispers"), true);
|
||||
|
||||
for (DbRow channelSetting : channelSettings) {
|
||||
ChatChannel chatChannel = carbonChat.getChannelManager().getRegistry().get(channelSetting.getString("channel"));
|
||||
for (final DbRow channelSetting : channelSettings) {
|
||||
final ChatChannel chatChannel = this.carbonChat.getChannelManager().registry().channel(channelSetting.getString("channel"));
|
||||
|
||||
if (chatChannel != null) {
|
||||
UserChannelSettings settings = user.getChannelSettings(chatChannel);
|
||||
final UserChannelSettings settings = user.channelSettings(chatChannel);
|
||||
|
||||
settings.spying(channelSetting.<Boolean>get("spying"), true);
|
||||
settings.ignoring(channelSetting.<Boolean>get("ignored"), true);
|
||||
|
||||
String color = channelSetting.getString("color");
|
||||
final String color = channelSetting.getString("color");
|
||||
|
||||
if (color != null) {
|
||||
settings.color(TextColor.fromHexString(color), true);
|
||||
@@ -188,37 +188,37 @@ public class MySQLUserService implements UserService {
|
||||
}
|
||||
}
|
||||
|
||||
for (DbRow ignoredUser : ignoredUsers) {
|
||||
user.setIgnoringUser(UUID.fromString(ignoredUser.getString("user")), true, true);
|
||||
for (final DbRow ignoredUser : ignoredUsers) {
|
||||
user.ignoringUser(UUID.fromString(ignoredUser.getString("user")), true, true);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
||||
CarbonChatUser user = notification.getValue();
|
||||
private void saveUser(@NonNull final RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
||||
final CarbonChatUser user = notification.getValue();
|
||||
|
||||
database.createTransaction(stm -> {
|
||||
this.database.createTransaction(stm -> {
|
||||
// Save user general data
|
||||
String selectedName = null;
|
||||
|
||||
if (user.selectedChannel() != null) {
|
||||
selectedName = user.selectedChannel().getKey();
|
||||
selectedName = user.selectedChannel().key();
|
||||
}
|
||||
|
||||
carbonChat.getLogger().info("Saving user data!");
|
||||
this.carbonChat.getLogger().info("Saving user data!");
|
||||
stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted, spyingwhispers, nickname) VALUES (?, ?, ?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?, spyingwhispers = ?, nickname =?",
|
||||
user.uuid().toString(), selectedName, user.isMuted(), user.isShadowMuted(), user.isSpyingWhispers(), user.nickname(),
|
||||
selectedName, user.isMuted(), user.isShadowMuted(), user.isSpyingWhispers(), user.nickname());
|
||||
user.uuid().toString(), selectedName, user.muted(), user.shadowMuted(), user.spyingwhispers(), user.nickname(),
|
||||
selectedName, user.muted(), user.shadowMuted(), user.spyingwhispers(), user.nickname());
|
||||
|
||||
carbonChat.getLogger().info("Saving user channel settings!");
|
||||
this.carbonChat.getLogger().info("Saving user channel settings!");
|
||||
// Save user channel settings
|
||||
for (Map.Entry<String, ? extends UserChannelSettings> entry : user.getChannelSettings().entrySet()) {
|
||||
UserChannelSettings value = entry.getValue();
|
||||
for (final Map.Entry<String, ? extends UserChannelSettings> entry : user.getChannelSettings().entrySet()) {
|
||||
final UserChannelSettings value = entry.getValue();
|
||||
|
||||
String colorString = null;
|
||||
|
||||
@@ -232,12 +232,12 @@ public class MySQLUserService implements UserService {
|
||||
value.spying(), value.ignored(), colorString);
|
||||
}
|
||||
|
||||
carbonChat.getLogger().info("Saving user ignores!");
|
||||
this.carbonChat.getLogger().info("Saving user ignores!");
|
||||
// Save user ignore list (remove old entries then add new ones)
|
||||
// TODO: keep DB up to date with settings as settings are mutated
|
||||
stm.executeUpdateQuery("DELETE FROM sc_ignored_users WHERE uuid = ?", user.uuid().toString());
|
||||
|
||||
for (UUID entry : user.getIgnoredUsers()) {
|
||||
for (final UUID entry : user.getIgnoredUsers()) {
|
||||
stm.executeUpdateQuery("INSERT INTO sc_ignored_users (uuid, user) VALUES (?, ?)",
|
||||
user.uuid().toString(), entry.toString());
|
||||
}
|
||||
|
||||
@@ -24,19 +24,19 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
private String channel;
|
||||
|
||||
private SimpleUserChannelSettings() {
|
||||
carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
}
|
||||
|
||||
public SimpleUserChannelSettings(@NonNull UUID uuid, @NonNull String channel) {
|
||||
public SimpleUserChannelSettings(@NonNull final UUID uuid, @NonNull final String channel) {
|
||||
this.uuid = uuid;
|
||||
this.channel = channel;
|
||||
|
||||
carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private CarbonChatUser getUser() {
|
||||
return (CarbonChatUser) carbonChat.getUserService().wrap(uuid);
|
||||
private CarbonChatUser user() {
|
||||
return (CarbonChatUser) this.carbonChat.getUserService().wrap(this.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,12 +45,12 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spying(boolean spying, boolean fromRemote) {
|
||||
public void spying(final boolean spying, final boolean fromRemote) {
|
||||
this.spying = spying;
|
||||
|
||||
if (!fromRemote) {
|
||||
carbonChat.getMessageManager().sendMessage("spying-channel", uuid, (byteArray) -> {
|
||||
byteArray.writeUTF(channel);
|
||||
this.carbonChat.getMessageManager().sendMessage("spying-channel", this.uuid, byteArray -> {
|
||||
byteArray.writeUTF(this.channel);
|
||||
byteArray.writeBoolean(spying);
|
||||
});
|
||||
}
|
||||
@@ -58,16 +58,16 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
|
||||
@Override
|
||||
public boolean ignored() {
|
||||
return ignored;
|
||||
return this.ignored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoring(boolean ignored, boolean fromRemote) {
|
||||
public void ignoring(final boolean ignored, final boolean fromRemote) {
|
||||
this.ignored = ignored;
|
||||
|
||||
if (!fromRemote) {
|
||||
carbonChat.getMessageManager().sendMessage("ignoring-channel", uuid, (byteArray) -> {
|
||||
byteArray.writeUTF(channel);
|
||||
this.carbonChat.getMessageManager().sendMessage("ignoring-channel", this.uuid, byteArray -> {
|
||||
byteArray.writeUTF(this.channel);
|
||||
byteArray.writeBoolean(ignored);
|
||||
});
|
||||
}
|
||||
@@ -76,15 +76,15 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
@Override
|
||||
@Nullable
|
||||
public TextColor color() {
|
||||
if (color == null) {
|
||||
if (this.color == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return TextColor.fromHexString(color);
|
||||
return TextColor.fromHexString(this.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void color(@Nullable TextColor color, boolean fromRemote) {
|
||||
public void color(@Nullable final TextColor color, final boolean fromRemote) {
|
||||
if (color == null) {
|
||||
this.color = null;
|
||||
} else {
|
||||
@@ -92,7 +92,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
}
|
||||
|
||||
if (!fromRemote) {
|
||||
carbonChat.getMessageManager().sendMessage("channel-color", uuid, (byteArray) -> {
|
||||
this.carbonChat.getMessageManager().sendMessage("channel-color", this.uuid, byteArray -> {
|
||||
byteArray.writeUTF(color.asHexString());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CarbonPlaceholders(@NonNull CarbonChat carbonChat) {
|
||||
public CarbonPlaceholders(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@@ -43,48 +43,48 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
@Override
|
||||
@Nullable
|
||||
public String onPlaceholderRequest(@NonNull final Player player, @NonNull final String identifier) {
|
||||
String key = identifier.toLowerCase();
|
||||
final String key = identifier.toLowerCase();
|
||||
|
||||
if (key.startsWith("can_use_")) {
|
||||
String value = key.replace("can_use_", "");
|
||||
final String value = key.replace("can_use_", "");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||
final ChatChannel channel = this.carbonChat.getChannelManager().registry().channel(value);
|
||||
|
||||
if (channel == null) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
return String.valueOf(channel.canPlayerUse(user));
|
||||
} else if (key.startsWith("can_see_")) {
|
||||
String value = key.replace("can_see_", "");
|
||||
final String value = key.replace("can_see_", "");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||
final ChatChannel channel = this.carbonChat.getChannelManager().registry().channel(value);
|
||||
|
||||
if (channel == null) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
return String.valueOf(channel.canPlayerSee(user, true));
|
||||
} else if (key.startsWith("ignoring_channel_")) {
|
||||
String value = key.replace("ignoring_channel_", "");
|
||||
final String value = key.replace("ignoring_channel_", "");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||
final ChatChannel channel = this.carbonChat.getChannelManager().registry().channel(value);
|
||||
|
||||
if (channel == null) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
final ChatUser user = this.carbonChat.getUserService().wrap(player);
|
||||
|
||||
return String.valueOf(user.getChannelSettings(channel).ignored());
|
||||
return String.valueOf(user.channelSettings(channel).ignored());
|
||||
} else if (key.startsWith("selected_channel")) {
|
||||
ChatChannel channel = carbonChat.getUserService().wrap(player).selectedChannel();
|
||||
final ChatChannel channel = this.carbonChat.getUserService().wrap(player).selectedChannel();
|
||||
|
||||
return channel == null ? carbonChat.getChannelManager().getDefaultChannel().getName() : channel.getName();
|
||||
return channel == null ? this.carbonChat.getChannelManager().defaultChannel().name() : channel.name();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -51,10 +51,14 @@ public final class CarbonUtils {
|
||||
|
||||
private static final @NonNull String @NonNull [] colors;
|
||||
|
||||
static {
|
||||
List<String> colorList = new ArrayList<>();
|
||||
private CarbonUtils() {
|
||||
|
||||
for (NamedTextColor color : NamedTextColor.values()) {
|
||||
}
|
||||
|
||||
static {
|
||||
final List<String> colorList = new ArrayList<>();
|
||||
|
||||
for (final NamedTextColor color : NamedTextColor.values()) {
|
||||
colorList.add(color.toString());
|
||||
}
|
||||
|
||||
@@ -73,17 +77,17 @@ public final class CarbonUtils {
|
||||
return net.kyori.adventure.text.TextComponent.empty();
|
||||
}
|
||||
|
||||
Content content = Bukkit.getItemFactory().hoverContentOf(itemStack);
|
||||
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_ITEM, content);
|
||||
final Content content = Bukkit.getItemFactory().hoverContentOf(itemStack);
|
||||
final HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_ITEM, content);
|
||||
|
||||
ComponentBuilder component = new ComponentBuilder();
|
||||
final ComponentBuilder component = new ComponentBuilder();
|
||||
component.event(event); // Let this be inherited by all coming components.
|
||||
component.color(ChatColor.WHITE).append("[");
|
||||
|
||||
if (itemStack.getItemMeta().hasDisplayName()) {
|
||||
component.append(TextComponent.fromLegacyText(itemStack.getItemMeta().getDisplayName()));
|
||||
} else {
|
||||
String name = itemStack.getItemMeta().hasDisplayName()
|
||||
final String name = itemStack.getItemMeta().hasDisplayName()
|
||||
? itemStack.getItemMeta().getDisplayName()
|
||||
: "item.minecraft." + itemStack.getType().name().toLowerCase(); // As of 1.13, Material is 1:1 with MC's names
|
||||
component.append(new TranslatableComponent(name));
|
||||
@@ -95,12 +99,12 @@ public final class CarbonUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable String input) {
|
||||
public static TextColor parseColor(@Nullable final String input) {
|
||||
return parseColor(null, input);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable ChatUser user, @Nullable String input) {
|
||||
public static TextColor parseColor(@Nullable final ChatUser user, @Nullable String input) {
|
||||
if (input == null) {
|
||||
input = "white";
|
||||
}
|
||||
@@ -109,7 +113,7 @@ public final class CarbonUtils {
|
||||
input = PlaceholderAPI.setPlaceholders(user.player(), input);
|
||||
}
|
||||
|
||||
for (NamedTextColor namedColor : NamedTextColor.values()) {
|
||||
for (final NamedTextColor namedColor : NamedTextColor.values()) {
|
||||
if (namedColor.toString().equalsIgnoreCase(input)) {
|
||||
return namedColor;
|
||||
}
|
||||
@@ -126,48 +130,48 @@ public final class CarbonUtils {
|
||||
|
||||
@NonNull
|
||||
public static Argument onlineChatUserArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
return new CustomArgument<>(input -> {
|
||||
final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
Player player = Bukkit.getPlayer(input);
|
||||
final Player player = Bukkit.getPlayer(input);
|
||||
|
||||
if (player == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid player for input (" + input + ")");
|
||||
}
|
||||
|
||||
return carbonChat.getUserService().wrap(player);
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// ArrayList<String> players = new ArrayList<>();
|
||||
//
|
||||
// for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// players.add(player.getName());
|
||||
// }
|
||||
//
|
||||
// return players.toArray(new String[0]);
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// ArrayList<String> players = new ArrayList<>();
|
||||
//
|
||||
// for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// players.add(player.getName());
|
||||
// }
|
||||
//
|
||||
// return players.toArray(new String[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument chatUserArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
return new CustomArgument<>(input -> {
|
||||
final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
return carbonChat.getUserService().wrap(input);
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// ArrayList<String> players = new ArrayList<>();
|
||||
//
|
||||
// for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// players.add(player.getName());
|
||||
// }
|
||||
//
|
||||
// return players.toArray(new String[0]);
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// ArrayList<String> players = new ArrayList<>();
|
||||
//
|
||||
// for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// players.add(player.getName());
|
||||
// }
|
||||
//
|
||||
// return players.toArray(new String[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument textColorArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
TextColor color = parseColor(input);
|
||||
return new CustomArgument<>(input -> {
|
||||
final TextColor color = parseColor(input);
|
||||
|
||||
if (color == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid color for input (" + input + ")");
|
||||
@@ -179,26 +183,26 @@ public final class CarbonUtils {
|
||||
|
||||
@NonNull
|
||||
public static Argument channelArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
return new CustomArgument<>(input -> {
|
||||
final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(input);
|
||||
final ChatChannel channel = carbonChat.getChannelManager().registry().channel(input);
|
||||
|
||||
if (channel == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");
|
||||
}
|
||||
|
||||
return channel;
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
//
|
||||
// ArrayList<String> channels = new ArrayList<>();
|
||||
//
|
||||
// for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||
// channels.add(channel.getKey());
|
||||
// }
|
||||
//
|
||||
// return channels.toArray(new String[0]);
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
//
|
||||
// ArrayList<String> channels = new ArrayList<>();
|
||||
//
|
||||
// for (ChatChannel channel : this.carbonChat.getChannelManager().getRegistry().values()) {
|
||||
// channels.add(channel.getKey());
|
||||
// }
|
||||
//
|
||||
// return channels.toArray(new String[0]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import dev.jorel.commandapi.CommandAPI;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class CommandUtils {
|
||||
public final class CommandUtils {
|
||||
|
||||
private CommandUtils() {
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public interface Registry<@NonNull T> {
|
||||
* @return The entry associated with the key or {@code null} if unassociated
|
||||
*/
|
||||
@Nullable
|
||||
T get(@NonNull String key);
|
||||
T channel(@NonNull String key);
|
||||
|
||||
/**
|
||||
* Clears all registered entries from the registry
|
||||
|
||||
Reference in new issue
Block a user