Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ private boolean checkBrackets(Optional<String> brackets) {
public final MethodResult sendFormattedMessage(@NotNull IArguments arguments) throws LuaException {
return withChatOperation(ignored -> {
String message = arguments.getString(0);
int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get();
int range = arguments.optInt(4, -1);
ResourceKey<Level> dimension = getLevel().dimension();
MutableComponent component = Component.Serializer.fromJson(message);
if (component == null) {
Expand All @@ -236,6 +234,19 @@ public final MethodResult sendFormattedMessage(@NotNull IArguments arguments) th
return MethodResult.of(null, "illegal prefix");
}
preparedMessage.append(component);

int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get();
int range = arguments.optInt(4, -1);
if (
APConfig.PERIPHERALS_CONFIG.chatBoxBroadcast.get()
&& APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get()
&& maxRange == -1
&& range == -1
) {
ServerLifecycleHooks.getCurrentServer().getPlayerList().broadcastSystemMessage(preparedMessage, false);
return MethodResult.of(true);
}

for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) {
if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) {
continue;
Expand All @@ -252,8 +263,6 @@ public final MethodResult sendFormattedMessage(@NotNull IArguments arguments) th
public final MethodResult sendMessage(@NotNull IArguments arguments) throws LuaException {
return withChatOperation(ignored -> {
String message = arguments.getString(0);
int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get();
int range = arguments.optInt(4, -1);
ResourceKey<Level> dimension = getLevel().dimension();
if (checkBrackets(arguments.optString(2))) {
return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)");
Expand All @@ -268,6 +277,19 @@ public final MethodResult sendMessage(@NotNull IArguments arguments) throws LuaE
return MethodResult.of(null, "illegal prefix");
}
preparedMessage.append(message);

int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get();
int range = arguments.optInt(4, -1);
if (
APConfig.PERIPHERALS_CONFIG.chatBoxBroadcast.get()
&& APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get()
&& maxRange == -1
&& range == -1
) {
ServerLifecycleHooks.getCurrentServer().getPlayerList().broadcastSystemMessage(preparedMessage, false);
return MethodResult.of(true);
}

for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) {
if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class PeripheralsConfig implements IAPConfig {
public final ForgeConfigSpec.ConfigValue<String> defaultChatBoxPrefix;
public final ForgeConfigSpec.IntValue chatBoxMaxRange;
public final ForgeConfigSpec.BooleanValue chatBoxMultiDimensional;
public final ForgeConfigSpec.BooleanValue chatBoxBroadcast;
public final ForgeConfigSpec.BooleanValue chatBoxPreventRunCommand;
public final ForgeConfigSpec.BooleanValue chatBoxWrapCommand;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> chatBoxBannedCommands;
Expand Down Expand Up @@ -147,6 +148,7 @@ public PeripheralsConfig() {
defaultChatBoxPrefix = builder.comment("Defines default chatbox prefix").define("defaultChatBoxPrefix", "AP");
chatBoxMaxRange = builder.comment("Defines the maximal range of the chat box in blocks. -1 for infinite. If the range is not -1, players in other dimensions won't able to receive messages").defineInRange("chatBoxMaxRange", -1, -1, 30000000);
chatBoxMultiDimensional = builder.comment("If true, the chat box is able to send messages to other dimensions than its own").define("chatBoxMultiDimensional", true);
chatBoxBroadcast = builder.comment("If true, chat box will 'broadcast' the messages instead of sending one individually to each player. This option does not affect anything directly, and relies on other mods to utilise this behavior (for example, mods that bridge minecraft chat to other platforms can intercept broadcasted messages and relay them, unlike individually sent ones). This option will only go in effect if `chatBoxMaxRange` is set to `-1` and `chatBoxMultiDimensional` is also set to `true`.").define("chatBoxBroadcast", true);
chatBoxPreventRunCommand = builder.comment("If true, the chat box cannot use 'run_command' action").define("chatBoxPreventRunCommand", false);
chatBoxWrapCommand = builder.comment("If true, the chat box will wrap and execute 'run_command' or 'suggest_command' action with zero permission, in order to prevent operators accidently run dangerous commands.").define("chatBoxWrapCommand", true);
chatBoxBannedCommands = builder.comment("These commands below will not be able to send by 'run_command' or 'suggest_command' action. It will match as prefix if starts with '/', other wise use regex pattern").defineList("chatBoxBannedCommands", chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0);
Expand Down