mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
Progress on CarbonChat-Common
This commit is contained in:
1 parent
508ad88e26
commit
64295c84ea
60 files changed
+889
-556
No files matched your search
+59
@@ -0,0 +1,59 @@
|
||||
package net.draycia.carbon.common.adventure;
|
||||
|
||||
import de.themoep.minedown.adventure.MineDown;
|
||||
import net.draycia.carbon.api.adventure.MessageProcessor;
|
||||
import net.kyori.adventure.platform.AudienceProvider;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class AdventureManager implements MessageProcessor {
|
||||
|
||||
@NonNull
|
||||
private final AudienceProvider provider;
|
||||
|
||||
@NonNull
|
||||
private final FormatType formatType;
|
||||
|
||||
public AdventureManager(@NonNull final AudienceProvider provider, @NonNull final FormatType formatType) {
|
||||
this.provider = provider;
|
||||
this.formatType = formatType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component processMessage(@Nullable final String input, @NonNull final String @NonNull ... placeholders) {
|
||||
if (input == null || input.trim().isEmpty()) {
|
||||
return TextComponent.empty();
|
||||
}
|
||||
|
||||
switch (this.formatType) {
|
||||
case MINEDOWN:
|
||||
return MineDown.parse(input, placeholders);
|
||||
case MOJANG:
|
||||
return this.processMojang(input, placeholders);
|
||||
case MINIMESSAGE_MARKDOWN:
|
||||
return MiniMessage.markdown().parse(input, placeholders);
|
||||
case MINIMESSAGE:
|
||||
default:
|
||||
return MiniMessage.get().parse(input, placeholders);
|
||||
}
|
||||
}
|
||||
|
||||
private @NonNull Component processMojang(@NonNull String input, @NonNull final String @NonNull ... placeholders) {
|
||||
for (int i = 0; i < placeholders.length; i += 2) {
|
||||
final String placeholder = placeholders[i];
|
||||
final String replacement = placeholders[i + 1];
|
||||
|
||||
input = input.replace("<" + placeholder + ">", replacement);
|
||||
}
|
||||
|
||||
return this.audiences().gsonSerializer().deserialize(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull AudienceProvider audiences() {
|
||||
return this.provider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.draycia.carbon.common.adventure;
|
||||
|
||||
public enum FormatType {
|
||||
MOJANG,
|
||||
MINIMESSAGE_MARKDOWN,
|
||||
MINIMESSAGE,
|
||||
MINEDOWN
|
||||
}
|
||||
Reference in new issue
Block a user