Skip to content
Open
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 @@ -26,7 +26,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class Settings extends Config {

Expand Down Expand Up @@ -519,9 +518,7 @@ public static final class Chat {
@Comment({"The click event actions that should be removed from user input in e.g. plot flags like 'greeting'.",
"Actions like 'RUN_COMMAND' may be used maliciously as players could trick staff into clicking on messages",
"triggering destructive commands."})
public static List<String> CLICK_EVENT_ACTIONS_TO_REMOVE = Arrays.stream(ClickEvent.Action.values())
.map(Enum::name)
.collect(Collectors.toList());
public static List<String> CLICK_EVENT_ACTIONS_TO_REMOVE = new ArrayList<>(ClickEvent.Action.NAMES.keys());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.plotsquared.core.configuration.caption.ComponentTransform.nested;
import static com.plotsquared.core.configuration.caption.ComponentTransform.stripClicks;

public class CaptionUtility {

Expand All @@ -51,10 +52,11 @@ public class CaptionUtility {
);

private static final ComponentTransform CLICK_STRIP_TRANSFORM = nested(
stripClicks(
new ClickStripTransform(
Settings.Chat.CLICK_EVENT_ACTIONS_TO_REMOVE.stream()
.map(ClickEvent.Action::valueOf)
.toArray(ClickEvent.Action[]::new)
.map(ClickEvent.Action.NAMES::value)
.filter(Objects::nonNull)
.collect(Collectors.toUnmodifiableSet())
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import net.kyori.adventure.text.event.ClickEvent;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.EnumSet;
import java.util.Set;

final class ClickStripTransform implements ComponentTransform {

private final Set<ClickEvent.@NonNull Action> actionsToStrip;
private final Set<ClickEvent.Action<?>> actionsToStrip;

public ClickStripTransform(final Set<ClickEvent.@NonNull Action> actionsToStrip) {
this.actionsToStrip = EnumSet.copyOf(actionsToStrip);
public ClickStripTransform(final Set<? extends ClickEvent.Action<?>> actionsToStrip) {
this.actionsToStrip = Set.copyOf(actionsToStrip);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ static ComponentTransform nested(ComponentTransform transform) {
* @return a new transform that removes click events from a component.
* @since 6.0.10
*/
static ComponentTransform stripClicks(ClickEvent.Action... actionsToRemove) {
@SafeVarargs
static ComponentTransform stripClicks(ClickEvent.Action<?>... actionsToRemove) {
return new ClickStripTransform(Set.of(actionsToRemove));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.EnumSet;
import java.util.Set;


class ClickStripTransformTest {
Expand All @@ -36,7 +36,7 @@ class ClickStripTransformTest {
@DisplayName("Remove click event of specific action correctly")
void removeClickEvent() {
var commonAction = ClickEvent.Action.OPEN_FILE;
var transform = new ClickStripTransform(EnumSet.of(commonAction));
var transform = new ClickStripTransform(Set.of(commonAction));
var component = Component.text("Hello").clickEvent(ClickEvent.openFile("World"));
var transformedComponent = transform.transform(component);
Assertions.assertNull(transformedComponent.clickEvent());
Expand All @@ -46,7 +46,7 @@ void removeClickEvent() {
@DisplayName("Don't remove click events of other action types")
void ignoreClickEvent() {
var actionToRemove = ClickEvent.Action.SUGGEST_COMMAND;
var transform = new ClickStripTransform(EnumSet.of(actionToRemove));
var transform = new ClickStripTransform(Set.of(actionToRemove));
var originalClickEvent = ClickEvent.changePage(1337);
var component = Component.text("Hello")
.clickEvent(originalClickEvent);
Expand All @@ -58,7 +58,7 @@ void ignoreClickEvent() {
@DisplayName("Remove nested click events correctly")
void removeNestedClickEvent() {
// nested transform is required to apply on children
var transform = new NestedComponentTransform(new ClickStripTransform(EnumSet.allOf(ClickEvent.Action.class)));
var transform = new NestedComponentTransform(new ClickStripTransform(new java.util.HashSet<>(ClickEvent.Action.NAMES.values())));
var inner = Component
// some arbitrary values that should remain
.text("World")
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ checkerqual = "4.1.0"
gson = "2.10"
guava = "31.1-jre"
snakeyaml = "2.0"
adventure = "4.26.1"
adventure = "5.1.1"
adventure-bukkit = "4.4.1"
log4j = "2.19.0"

Expand Down
Loading