Skip to content

Commit f1bc327

Browse files
committed
Add simple API to add multiple dynamic replacements
1 parent ddc2de0 commit f1bc327

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55

66
allprojects {
77
group 'dev.peri.yetanothermessageslibrary'
8-
version '6.7.0-SNAPSHOT'
8+
version '6.8.0-SNAPSHOT'
99

1010
apply plugin: 'java-library'
1111
apply plugin: 'maven-publish'

core/src/main/java/dev/peri/yetanothermessageslibrary/message/MessageDispatcher.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@
55
import dev.peri.yetanothermessageslibrary.util.TriFunction;
66
import dev.peri.yetanothermessageslibrary.viewer.Viewer;
77
import dev.peri.yetanothermessageslibrary.viewer.ViewerService;
8-
import org.jetbrains.annotations.Contract;
9-
import org.jetbrains.annotations.NotNull;
10-
import org.jetbrains.annotations.Nullable;
11-
12-
import java.util.*;
8+
import java.util.ArrayList;
9+
import java.util.Collection;
10+
import java.util.Collections;
11+
import java.util.HashSet;
12+
import java.util.List;
13+
import java.util.Locale;
14+
import java.util.Map;
15+
import java.util.Objects;
16+
import java.util.Set;
17+
import java.util.WeakHashMap;
1318
import java.util.function.Consumer;
1419
import java.util.function.Function;
1520
import java.util.function.Predicate;
1621
import java.util.function.Supplier;
22+
import org.jetbrains.annotations.Contract;
23+
import org.jetbrains.annotations.NotNull;
24+
import org.jetbrains.annotations.Nullable;
1725

1826
@SuppressWarnings("unchecked")
1927
public class MessageDispatcher<R, D extends MessageDispatcher<R, ?>> {
@@ -160,6 +168,15 @@ public <T extends R> D with(
160168
return this.with(requiredType, replacementSupplier, null);
161169
}
162170

171+
@Contract("_, _ -> this")
172+
public <T extends R> D with(
173+
@NotNull Class<T> requiredType,
174+
@NotNull Collection<Function<@NotNull T, ? extends @NotNull Replaceable>> replacementSuppliers
175+
) {
176+
replacementSuppliers.forEach(replacementSupplier -> this.with(requiredType, replacementSupplier));
177+
return (D) this;
178+
}
179+
163180
@Contract(" -> this")
164181
public D send() {
165182
this.receivers.forEach(this::sendTo);

0 commit comments

Comments
 (0)