-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extensive support for using dispatchers in configuration
- Loading branch information
Showing
30 changed files
with
778 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ plugins { | |
|
||
repositories { | ||
mavenCentral() | ||
maven("https://storehouse.okaeri.eu/repository/maven-public/") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...mon/src/dev/shiza/honey/adventure/message/dispatcher/AdventureBatchMessageDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package dev.shiza.honey.adventure.message.dispatcher; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.spotify.futures.CompletableFutures; | ||
import dev.shiza.honey.message.dispatcher.BatchMessageDispatcher; | ||
import dev.shiza.honey.message.dispatcher.MessagePolyDispatcher; | ||
import dev.shiza.honey.message.dispatcher.MessageRenderer; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.UnaryOperator; | ||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.text.Component; | ||
|
||
public final class AdventureBatchMessageDispatcher | ||
implements BatchMessageDispatcher<Audience, Component> { | ||
|
||
private final List<MessagePolyDispatcher<Audience, Component>> dispatchers; | ||
|
||
public AdventureBatchMessageDispatcher( | ||
final List<MessagePolyDispatcher<Audience, Component>> dispatchers) { | ||
this.dispatchers = ImmutableList.copyOf(dispatchers); | ||
} | ||
|
||
public AdventureBatchMessageDispatcher() { | ||
this(ImmutableList.of()); | ||
} | ||
|
||
@Override | ||
public BatchMessageDispatcher<Audience, Component> add( | ||
final MessagePolyDispatcher<Audience, Component> dispatcher) { | ||
return new AdventureBatchMessageDispatcher( | ||
ImmutableList.<MessagePolyDispatcher<Audience, Component>>builder() | ||
.addAll(dispatchers) | ||
.add(dispatcher) | ||
.build()); | ||
} | ||
|
||
@SafeVarargs | ||
@Override | ||
public final BatchMessageDispatcher<Audience, Component> addAll( | ||
final MessagePolyDispatcher<Audience, Component>... dispatchers) { | ||
return new AdventureBatchMessageDispatcher( | ||
ImmutableList.<MessagePolyDispatcher<Audience, Component>>builder() | ||
.addAll(this.dispatchers) | ||
.addAll(Arrays.asList(dispatchers)) | ||
.build()); | ||
} | ||
|
||
@Override | ||
public MessagePolyDispatcher<Audience, Component> viewer(final Audience audience) { | ||
return new AdventureBatchMessageDispatcher( | ||
dispatchers.stream() | ||
.map(dispatcher -> dispatcher.viewer(audience)) | ||
.collect(ImmutableList.toImmutableList())); | ||
} | ||
|
||
@Override | ||
public MessagePolyDispatcher<Audience, Component> placeholders( | ||
final UnaryOperator<MessageRenderer<Component>> consumer) { | ||
return new AdventureBatchMessageDispatcher( | ||
dispatchers.stream() | ||
.map(dispatcher -> dispatcher.placeholders(consumer)) | ||
.collect(ImmutableList.toImmutableList())); | ||
} | ||
|
||
@Override | ||
public void dispatch() { | ||
dispatchers.forEach(MessagePolyDispatcher::dispatch); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> dispatchAsync() { | ||
return dispatchers.stream() | ||
.map(MessagePolyDispatcher::dispatchAsync) | ||
.collect(CompletableFutures.joinList()) | ||
.thenAccept(__ -> {}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
honey-common/src/dev/shiza/honey/message/dispatcher/BatchMessageDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.shiza.honey.message.dispatcher; | ||
|
||
public interface BatchMessageDispatcher<VIEWER, RESULT> | ||
extends MessagePolyDispatcher<VIEWER, RESULT> { | ||
|
||
BatchMessageDispatcher<VIEWER, RESULT> add( | ||
final MessagePolyDispatcher<VIEWER, RESULT> dispatcher); | ||
|
||
BatchMessageDispatcher<VIEWER, RESULT> addAll( | ||
final MessagePolyDispatcher<VIEWER, RESULT>... dispatchers); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
honey-common/src/dev/shiza/honey/message/dispatcher/MessagePolyDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.shiza.honey.message.dispatcher; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.UnaryOperator; | ||
|
||
public interface MessagePolyDispatcher<VIEWER, RESULT> { | ||
|
||
MessagePolyDispatcher<VIEWER, RESULT> viewer(final VIEWER viewer); | ||
|
||
MessagePolyDispatcher<VIEWER, RESULT> placeholders( | ||
final UnaryOperator<MessageRenderer<RESULT>> consumer); | ||
|
||
void dispatch(); | ||
|
||
CompletableFuture<Void> dispatchAsync(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
plugins { | ||
`honey-java` | ||
`honey-publish` | ||
`honey-repositories` | ||
} | ||
|
||
dependencies { | ||
compileOnly(project(":honey-common")) | ||
compileOnly(libs.bundles.adventure) | ||
} | ||
|
||
honeyPublish { | ||
artifactId = "honey-configs-common" | ||
} |
48 changes: 48 additions & 0 deletions
48
...mon/src/dev/shiza/honey/adventure/message/dispatcher/AdventureBatchMessageConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package dev.shiza.honey.adventure.message.dispatcher; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import dev.shiza.honey.message.dispatcher.BatchMessageConfigurer; | ||
import dev.shiza.honey.message.dispatcher.BatchMessageDispatcher; | ||
import dev.shiza.honey.message.dispatcher.MessagePolyConfigurer; | ||
import dev.shiza.honey.message.dispatcher.MessagePolyDispatcher; | ||
import dev.shiza.honey.message.formatter.MessageFormatter; | ||
import java.util.List; | ||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.text.Component; | ||
|
||
public final class AdventureBatchMessageConfigurer | ||
implements BatchMessageConfigurer<Audience, Component> { | ||
|
||
private final List<MessagePolyConfigurer<Audience, Component>> configurers; | ||
|
||
AdventureBatchMessageConfigurer(final List<MessagePolyConfigurer<Audience, Component>> configurers) { | ||
this.configurers = ImmutableList.copyOf(configurers); | ||
} | ||
|
||
AdventureBatchMessageConfigurer() { | ||
this(ImmutableList.of()); | ||
} | ||
|
||
@Override | ||
public AdventureBatchMessageConfigurer add(final MessagePolyConfigurer<Audience, Component> configurer) { | ||
return new AdventureBatchMessageConfigurer( | ||
ImmutableList.<MessagePolyConfigurer<Audience, Component>>builder() | ||
.addAll(configurers) | ||
.add(configurer) | ||
.build()); | ||
} | ||
|
||
@Override | ||
public BatchMessageDispatcher<Audience, Component> dispatcher( | ||
final MessageFormatter<Component> formatter) { | ||
return new AdventureBatchMessageDispatcher() | ||
.addAll( | ||
configurers.stream() | ||
.map(configurer -> configurer.dispatcher(formatter)) | ||
.toArray(MessagePolyDispatcher[]::new)); | ||
} | ||
|
||
List<MessagePolyConfigurer<Audience, Component>> configurers() { | ||
return configurers; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...s-common/src/dev/shiza/honey/adventure/message/dispatcher/AdventureMessageConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package dev.shiza.honey.adventure.message.dispatcher; | ||
|
||
import dev.shiza.honey.message.dispatcher.MessageBaseDispatcher; | ||
import dev.shiza.honey.message.dispatcher.MessageConfigurationException; | ||
import dev.shiza.honey.message.dispatcher.MessageConfigurer; | ||
import dev.shiza.honey.message.dispatcher.MessageDispatcher; | ||
import dev.shiza.honey.message.formatter.MessageFormatter; | ||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.text.Component; | ||
|
||
public final class AdventureMessageConfigurer | ||
implements MessageConfigurer<Audience, String, Component> { | ||
|
||
private final AdventureMessageDelivery delivery; | ||
private final String template; | ||
|
||
AdventureMessageConfigurer(final AdventureMessageDelivery delivery, final String template) { | ||
this.delivery = delivery; | ||
this.template = template; | ||
} | ||
|
||
AdventureMessageConfigurer(final AdventureMessageDelivery delivery) { | ||
this(delivery, null); | ||
} | ||
|
||
@Override | ||
public MessageConfigurer<Audience, String, Component> delivery( | ||
final AdventureMessageDelivery delivery) { | ||
return new AdventureMessageConfigurer(delivery, template); | ||
} | ||
|
||
@Override | ||
public AdventureMessageConfigurer template(final String template) { | ||
return new AdventureMessageConfigurer(delivery, template); | ||
} | ||
|
||
@Override | ||
public MessageDispatcher<Audience, Component> dispatcher( | ||
final MessageFormatter<Component> formatter) { | ||
if (template == null) { | ||
throw new MessageConfigurationException( | ||
"Could not get a message dispatcher without a template."); | ||
} | ||
|
||
return new MessageBaseDispatcher<>(Audience.empty(), delivery.deliver()) | ||
.template(formatter, template); | ||
} | ||
|
||
AdventureMessageDelivery delivery() { | ||
return delivery; | ||
} | ||
|
||
String template() { | ||
return template; | ||
} | ||
} |
Oops, something went wrong.