Skip to content

Commit

Permalink
feature: update to modern MiniMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
broccoli committed Nov 17, 2022
1 parent 0a96a54 commit e4e6931
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 104 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dependencies {
api("com.google.inject", "guice", Versions.GUICE)

api("net.kyori", "adventure-api", Versions.ADVENTURE)
api("net.kyori", "adventure-text-minimessage", Versions.MINI_MESSAGE) {
api("net.kyori", "adventure-text-minimessage", Versions.ADVENTURE) {
isTransitive = true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package broccolai.tags.api.events.event;

import broccolai.tags.api.events.Event;
import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.TagsUser;
import net.kyori.event.Cancellable;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand All @@ -10,9 +10,9 @@
public final class TagChangeEvent extends Cancellable.Impl implements Event {

private final @NonNull TagsUser user;
private final @NonNull Tag tag;
private final @NonNull ConstructedTag tag;

public TagChangeEvent(final @NonNull TagsUser user, final @NonNull Tag tag) {
public TagChangeEvent(final @NonNull TagsUser user, final @NonNull ConstructedTag tag) {
this.user = user;
this.tag = tag;
}
Expand All @@ -23,7 +23,7 @@ public TagChangeEvent(final @NonNull TagsUser user, final @NonNull Tag tag) {
}

@Pure
public @NonNull Tag tag() {
public @NonNull ConstructedTag tag() {
return this.tag;
}

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

public final class Tag implements Permissible {
public final class ConstructedTag implements Permissible {

private final int id;
private final String name;
private final boolean secret;
private final @NonNull Component component;
private final @NonNull String reason;

public Tag(
public ConstructedTag(
final int id,
final @NonNull String name,
final boolean secret,
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/broccolai/tags/api/model/user/TagsUser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package broccolai.tags.api.model.user;

import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.impl.ConsoleTagsUser;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -14,7 +14,7 @@ public interface TagsUser {

@NonNull UUID uuid();

void setCurrent(@Nullable Tag tag);
void setCurrent(@Nullable ConstructedTag tag);

@NonNull Optional<Integer> current();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package broccolai.tags.api.model.user.impl;

import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.TagsUser;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -20,7 +20,7 @@ public final class ConsoleTagsUser implements TagsUser {
}

@Override
public void setCurrent(final @Nullable Tag tag) {
public void setCurrent(final @Nullable ConstructedTag tag) {
this.currentTag = tag != null ? tag.id() : null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package broccolai.tags.api.model.user.impl;

import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.TagsUser;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -27,7 +27,7 @@ public PlayerTagsUser(
}

@Override
public void setCurrent(final @Nullable Tag tag) {
public void setCurrent(final @Nullable ConstructedTag tag) {
this.current = tag != null ? tag.id() : null;
}

Expand Down
20 changes: 10 additions & 10 deletions api/src/main/java/broccolai/tags/api/service/MessageService.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package broccolai.tags.api.service;

import broccolai.tags.api.model.Service;
import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.TagsUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.Template;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Collection;

public interface MessageService extends Service {

Template prefix();
TagResolver prefix();

Component commandSelect(@NonNull Tag tag);
Component commandSelect(@NonNull ConstructedTag tag);

Component commandList(@NonNull Collection<Tag> tags);
Component commandList(@NonNull Collection<ConstructedTag> tags);

Component commandInfo(@NonNull Tag tag);
Component commandInfo(@NonNull ConstructedTag tag);

Component commandAdminGive(@NonNull Tag tag, @NonNull TagsUser target);
Component commandAdminGive(@NonNull ConstructedTag tag, @NonNull TagsUser target);

Component commandAdminRemove(@NonNull Tag tag, @NonNull TagsUser target);
Component commandAdminRemove(@NonNull ConstructedTag tag, @NonNull TagsUser target);

Component commandAdminList(@NonNull Collection<Tag> tags);
Component commandAdminList(@NonNull Collection<ConstructedTag> tags);

Component commandAdminSet(@NonNull Tag tag, @NonNull TagsUser target);
Component commandAdminSet(@NonNull ConstructedTag tag, @NonNull TagsUser target);

Component commandErrorUserNotFound(@NonNull String input);

Expand Down
14 changes: 7 additions & 7 deletions api/src/main/java/broccolai/tags/api/service/TagsService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package broccolai.tags.api.service;

import broccolai.tags.api.model.Service;
import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.TagsUser;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -11,7 +11,7 @@

public interface TagsService extends Service {

@NotNull Tag defaultTag();
@NotNull ConstructedTag defaultTag();

void create(
int id,
Expand All @@ -21,14 +21,14 @@ void create(
@NonNull String reason
);

@Nullable Tag load(int id);
@Nullable ConstructedTag load(int id);

@Nullable Tag load(@NonNull String name);
@Nullable ConstructedTag load(@NonNull String name);

@NonNull Tag load(@NonNull TagsUser user);
@NonNull ConstructedTag load(@NonNull TagsUser user);

@NonNull Collection<@NonNull Tag> allTags();
@NonNull Collection<@NonNull ConstructedTag> allTags();

@NonNull Collection<@NonNull Tag> allTags(@NonNull TagsUser user);
@NonNull Collection<@NonNull ConstructedTag> allTags(@NonNull TagsUser user);

}
3 changes: 1 addition & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ object Versions {
const val FLYWAY = "9.8.1"
const val CONFIGURATE = "4.1.2"
const val CORN = "2.2.0"
const val ADVENTURE = "4.5.0"
const val ADVENTURE = "4.11.0"
const val ADVENTURE_PLATFORM = "4.1.2"
const val MINI_MESSAGE = "4.1.0-SNAPSHOT"
const val EVENT = "4.0.0-SNAPSHOT"
const val COFFEE = "1.0.0-SNAPSHOT"
const val CLOUD = "1.7.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package broccolai.tags.bukkit.integrations;

import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.service.TagsService;
import broccolai.tags.api.service.UserService;
import com.google.inject.Inject;
Expand All @@ -25,7 +25,7 @@ public BasicIntegration(final @NonNull UserService userService, final @NonNull T
@EventHandler
public void onChat(final @NonNull AsyncChatEvent event) {
event.renderer(((source, name, message, viewer) -> {
Tag tag = this.tagsService.load(this.userService.get(source.getUniqueId()));
ConstructedTag tag = this.tagsService.load(this.userService.get(source.getUniqueId()));
return message.replaceText(builder -> builder.matchLiteral("%tag%").replacement(tag.component()));
}));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package broccolai.tags.bukkit.integrations;

import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.TagsUser;
import broccolai.tags.api.service.TagsService;
import broccolai.tags.api.service.UserService;
Expand Down Expand Up @@ -49,7 +49,7 @@ public String onRequest(final @NonNull OfflinePlayer player, final @NonNull Stri
TagsUser user = this.userService.get(player.getUniqueId());

if (identifier.equalsIgnoreCase("current")) {
Tag tag = this.tagsService.load(user);
ConstructedTag tag = this.tagsService.load(user);
return LEGACY.serialize(tag.component());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package broccolai.tags.core.commands;

import broccolai.tags.api.events.event.TagChangeEvent;
import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.TagsUser;
import broccolai.tags.api.service.EventService;
import broccolai.tags.api.service.MessageService;
Expand Down Expand Up @@ -83,7 +83,7 @@ public void register(
private void handleGive(final @NonNull CommandContext<CommandUser> context) {
CommandUser sender = context.getSender();
TagsUser target = context.get("target");
Tag tag = context.get("tag");
ConstructedTag tag = context.get("tag");

this.permissionService.grant(target, tag);
sender.sendMessage(this.messageService.commandAdminGive(tag, target));
Expand All @@ -92,15 +92,15 @@ private void handleGive(final @NonNull CommandContext<CommandUser> context) {
private void handleRemove(final @NonNull CommandContext<CommandUser> context) {
CommandUser sender = context.getSender();
TagsUser target = context.get("target");
Tag tag = context.get("tag");
ConstructedTag tag = context.get("tag");

this.permissionService.remove(target, tag);
sender.sendMessage(this.messageService.commandAdminRemove(tag, target));
}

private void handleList(final @NonNull CommandContext<CommandUser> context) {
CommandUser sender = context.getSender();
Collection<Tag> tags = context.<TagsUser>getOptional("target")
Collection<ConstructedTag> tags = context.<TagsUser>getOptional("target")
.map(this.tagsService::allTags)
.orElse(this.tagsService.allTags());

Expand All @@ -110,7 +110,7 @@ private void handleList(final @NonNull CommandContext<CommandUser> context) {
private void handleSet(final @NonNull CommandContext<CommandUser> context) {
CommandUser sender = context.getSender();
TagsUser target = context.get("target");
Tag tag = context.get("tag");
ConstructedTag tag = context.get("tag");

TagChangeEvent event = new TagChangeEvent(target, tag);
this.eventService.post(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package broccolai.tags.core.commands;

import broccolai.tags.api.events.event.TagChangeEvent;
import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.TagsUser;
import broccolai.tags.api.service.EventService;
import broccolai.tags.api.service.MessageService;
Expand Down Expand Up @@ -71,7 +71,7 @@ public void register(
private void handleSelect(final @NonNull CommandContext<CommandUser> context) {
CommandUser sender = context.getSender();
TagsUser user = this.userService.get(sender.uuid());
Tag tag = context.get("tag");
ConstructedTag tag = context.get("tag");

TagChangeEvent event = new TagChangeEvent(user, tag);
this.eventService.post(event);
Expand All @@ -84,14 +84,14 @@ private void handleSelect(final @NonNull CommandContext<CommandUser> context) {
private void handleList(final @NonNull CommandContext<CommandUser> context) {
CommandUser sender = context.getSender();
TagsUser user = this.userService.get(sender.uuid());
Collection<Tag> tags = this.tagsService.allTags(user);
Collection<ConstructedTag> tags = this.tagsService.allTags(user);

sender.sendMessage(this.messageService.commandList(tags));
}

private void handlePreview(final @NonNull CommandContext<CommandUser> context) {
CommandUser sender = context.getSender();
Tag tag = context.get("tag");
ConstructedTag tag = context.get("tag");

sender.sendMessage(this.messageService.commandInfo(tag));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package broccolai.tags.core.commands.arguments;

import broccolai.corn.core.Lists;
import broccolai.tags.api.model.tag.Tag;
import broccolai.tags.api.model.tag.ConstructedTag;
import broccolai.tags.api.model.user.TagsUser;
import broccolai.tags.api.service.PermissionService;
import broccolai.tags.api.service.TagsService;
Expand All @@ -22,7 +22,7 @@
import java.util.List;
import java.util.Queue;

public class TagArgument extends CommandArgument<@NonNull CommandUser, @NonNull Tag> {
public class TagArgument extends CommandArgument<@NonNull CommandUser, @NonNull ConstructedTag> {

@AssistedInject
public TagArgument(
Expand All @@ -32,10 +32,10 @@ public TagArgument(
final @Assisted("name") @NonNull String name,
final @Assisted("mode") @NonNull TagParserMode mode
) {
super(true, name, new TagParser(permissionService, tagsService, userService, mode), Tag.class);
super(true, name, new TagParser(permissionService, tagsService, userService, mode), ConstructedTag.class);
}

public static final class TagParser implements ArgumentParser<@NonNull CommandUser, Tag> {
public static final class TagParser implements ArgumentParser<@NonNull CommandUser, ConstructedTag> {

private final @NonNull PermissionService permissionService;
private final @NonNull TagsService tagsService;
Expand All @@ -55,7 +55,7 @@ public TagParser(
}

@Override
public @NonNull ArgumentParseResult<Tag> parse(
public @NonNull ArgumentParseResult<ConstructedTag> parse(
final @NonNull CommandContext<@NonNull CommandUser> commandContext,
final @NonNull Queue<String> inputQueue
) {
Expand All @@ -65,7 +65,7 @@ public TagParser(
return ArgumentParseResult.failure(new NoInputProvidedException(TagParser.class, commandContext));
}

Tag tag = this.tagsService.load(input);
ConstructedTag tag = this.tagsService.load(input);

if (tag == null) {
return ArgumentParseResult.failure(new TagArgumentException(input));
Expand Down Expand Up @@ -104,7 +104,7 @@ public TagParser(
final @NonNull String input
) {
if (this.mode == TagParserMode.ANY || this.mode == TagParserMode.NON_SECRET) {
Collection<Tag> tags = new ArrayList<>(this.tagsService.allTags());
Collection<ConstructedTag> tags = new ArrayList<>(this.tagsService.allTags());

if (this.mode == TagParserMode.NON_SECRET) {
CommandUser self = commandContext.getSender();
Expand All @@ -113,7 +113,7 @@ public TagParser(
tags.removeIf(tag -> !(this.permissionService.has(user, tag) || tag.secret()));
}

return Lists.map(this.tagsService.allTags(), Tag::name);
return Lists.map(this.tagsService.allTags(), ConstructedTag::name);
}

final TagsUser target;
Expand All @@ -125,7 +125,7 @@ public TagParser(
target = commandContext.get("target");
}

return Lists.map(this.tagsService.allTags(target), Tag::name);
return Lists.map(this.tagsService.allTags(target), ConstructedTag::name);
}

}
Expand Down
Loading

0 comments on commit e4e6931

Please sign in to comment.