From b366a0723b8f2196dcadf5d7fa8d7d141d3aa510 Mon Sep 17 00:00:00 2001
From: rafal <63915083+rchomczyk@users.noreply.github.com>
Date: Tue, 19 Nov 2024 02:09:15 +0100
Subject: [PATCH] Add more specific uses cases to test plugin
---
.idea/gradle.xml | 1 -
.../src/dev/shiza/honey/ExampleListener.java | 34 +++++++++------
.../src/dev/shiza/honey/ExamplePlugin.java | 42 ++++++++++++++++++-
settings.gradle.kts | 2 +-
4 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index bb8d63b..4a3641f 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -23,7 +23,6 @@
-
diff --git a/honey-test-plugin/src/dev/shiza/honey/ExampleListener.java b/honey-test-plugin/src/dev/shiza/honey/ExampleListener.java
index 38a0ace..689454a 100644
--- a/honey-test-plugin/src/dev/shiza/honey/ExampleListener.java
+++ b/honey-test-plugin/src/dev/shiza/honey/ExampleListener.java
@@ -11,34 +11,44 @@
final class ExampleListener implements Listener {
- private final AdventureMessageFormatter formatter;
+ private final AdventureMessageFormatter defaultMessageFormatter;
+ private final AdventureMessageFormatter reflectMessageFormatter;
- ExampleListener(final AdventureMessageFormatter formatter) {
- this.formatter = formatter;
+ ExampleListener(
+ final AdventureMessageFormatter defaultMessageFormatter,
+ final AdventureMessageFormatter reflectMessageFormatter) {
+ this.defaultMessageFormatter = defaultMessageFormatter;
+ this.reflectMessageFormatter = reflectMessageFormatter;
}
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent event) {
+ // 1) Using the default message formatter
AdventureMessageDispatcher.createTitle()
.viewer(event.getPlayer())
.times(2, 4, 2)
- .title(it -> it.template(formatter, "Hello {{number}}!"))
+ .title(it -> it.template(defaultMessageFormatter, "Hello {{number}}!"))
.subtitle(
it ->
- it.template(formatter, "It is a pleasure to see you there {{number}} {{player}}")
+ it.template(
+ defaultMessageFormatter,
+ "It is a pleasure to see you there {{number}} {{player}}")
.placeholders(
- environment -> environment.replace("player", event.getPlayer().getName())))
- .placeholders(environment -> environment.replace("number", 15))
+ mapping -> mapping.replace("player", event.getPlayer().getName())))
+ .placeholders(mapping -> mapping.replace("number", 15))
.dispatch();
+ // 2) Using the reflective message formatter
+ AdventureMessageDispatcher.createActionBar()
+ .viewer(event.getPlayer())
+ .template(reflectMessageFormatter, "Hello {{player.getName}}, {{player.getUniqueId}}!")
+ .placeholders(mapping -> mapping.replace("player", event.getPlayer()))
+ .dispatch();
+
+ // 3) Using dispatcher without any message formatter
AdventureMessageDispatcher.createChat()
.viewer(Bukkit.getServer())
.template(Component.text("Somebody joined to the server!").color(NamedTextColor.RED))
.dispatch();
-
- AdventureMessageDispatcher.createActionBar()
- .viewer(event.getPlayer())
- .template(formatter, "Honey is great, isn't it?")
- .dispatch();
}
}
diff --git a/honey-test-plugin/src/dev/shiza/honey/ExamplePlugin.java b/honey-test-plugin/src/dev/shiza/honey/ExamplePlugin.java
index 4ae36f8..6d2d2db 100644
--- a/honey-test-plugin/src/dev/shiza/honey/ExamplePlugin.java
+++ b/honey-test-plugin/src/dev/shiza/honey/ExamplePlugin.java
@@ -1,14 +1,52 @@
package dev.shiza.honey;
+import dev.shiza.honey.adventure.message.compiler.AdventureMessageCompilerFactory;
import dev.shiza.honey.adventure.message.formatter.AdventureMessageFormatter;
import dev.shiza.honey.adventure.message.formatter.AdventureMessageFormatterFactory;
+import dev.shiza.honey.adventure.placeholder.sanitizer.AdventurePlaceholderSanitizerFactory;
+import dev.shiza.honey.conversion.ImplicitConversion;
+import dev.shiza.honey.message.compiler.MessageCompiler;
+import dev.shiza.honey.placeholder.PlaceholderContext;
+import dev.shiza.honey.placeholder.evaluator.PlaceholderEvaluator;
+import dev.shiza.honey.placeholder.evaluator.reflection.ReflectivePlaceholderEvaluatorFactory;
+import dev.shiza.honey.placeholder.processor.PlaceholderProcessor;
+import dev.shiza.honey.placeholder.processor.PlaceholderProcessorFactory;
+import dev.shiza.honey.placeholder.resolver.PlaceholderResolver;
+import dev.shiza.honey.placeholder.resolver.PlaceholderResolverFactory;
+import dev.shiza.honey.placeholder.sanitizer.PlaceholderSanitizer;
+import dev.shiza.honey.processor.ProcessorRegistry;
+import dev.shiza.honey.processor.ProcessorRegistryFactory;
+import net.kyori.adventure.text.Component;
import org.bukkit.plugin.java.JavaPlugin;
public final class ExamplePlugin extends JavaPlugin {
@Override
public void onEnable() {
- final AdventureMessageFormatter messageFormatter = AdventureMessageFormatterFactory.create();
- getServer().getPluginManager().registerEvents(new ExampleListener(messageFormatter), this);
+ final AdventureMessageFormatter defaultMessageFormatter = AdventureMessageFormatterFactory.create();
+ final AdventureMessageFormatter reflectMessageFormatter = createReflectMessageFormatter();
+ getServer().getPluginManager().registerEvents(new ExampleListener(defaultMessageFormatter, reflectMessageFormatter), this);
+ }
+
+ private AdventureMessageFormatter createReflectMessageFormatter() {
+ final MessageCompiler messageCompiler = AdventureMessageCompilerFactory.create();
+ final ImplicitConversion implicitConversion = ImplicitConversion.create();
+ final PlaceholderContext placeholderContext = PlaceholderContext.create();
+ final PlaceholderResolver placeholderResolver = PlaceholderResolverFactory.create();
+ final PlaceholderSanitizer placeholderSanitizer =
+ AdventurePlaceholderSanitizerFactory.createReflective();
+ final PlaceholderEvaluator placeholderEvaluator =
+ ReflectivePlaceholderEvaluatorFactory.create();
+ final PlaceholderProcessor placeholderProcessor =
+ PlaceholderProcessorFactory.create(
+ placeholderEvaluator, placeholderSanitizer, implicitConversion);
+ final ProcessorRegistry processorRegistry = ProcessorRegistryFactory.create();
+ return AdventureMessageFormatterFactory.create(
+ messageCompiler,
+ placeholderContext,
+ placeholderResolver,
+ placeholderProcessor,
+ placeholderSanitizer,
+ processorRegistry);
}
}
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 678653f..6818302 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -3,4 +3,4 @@ include(":honey-common")
include(":honey-kt-extension")
// Uncomment in case if you would like to run test plugin
-include(":honey-test-plugin")
\ No newline at end of file
+// include(":honey-test-plugin")
\ No newline at end of file