Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions api/src/main/java/net/okocraft/box/api/BoxAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.okocraft.box.api.event.caller.EventCallerProvider;
import net.okocraft.box.api.feature.BoxFeature;
import net.okocraft.box.api.feature.FeatureProvider;
import net.okocraft.box.api.message.MessageProvider;
import net.okocraft.box.api.model.customdata.CustomDataManager;
import net.okocraft.box.api.model.manager.ItemManager;
import net.okocraft.box.api.model.manager.StockManager;
Expand Down Expand Up @@ -54,13 +53,6 @@ static boolean isLoaded() {
*/
@NotNull Path getPluginDirectory();

/**
* Gets the {@link MessageProvider}.
*
* @return the {@link MessageProvider}
*/
@NotNull MessageProvider getMessageProvider();

/**
* Gets the {@link UserManager}.
*
Expand Down
6 changes: 2 additions & 4 deletions api/src/main/java/net/okocraft/box/api/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.okocraft.box.api.command;

import com.github.siroshun09.messages.minimessage.source.MiniMessageSource;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
Expand Down Expand Up @@ -38,10 +37,9 @@ public interface Command {
/**
* Gets the helps.
*
* @param msgSrc a {@link MiniMessageSource}
* @return the helps
*/
@NotNull Component getHelp(@NotNull MiniMessageSource msgSrc);
@NotNull ComponentLike getHelp();

/**
* Executes the command.
Expand Down
38 changes: 18 additions & 20 deletions api/src/main/java/net/okocraft/box/api/message/ErrorMessages.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package net.okocraft.box.api.message;

import com.github.siroshun09.messages.minimessage.arg.Arg1;
import com.github.siroshun09.messages.minimessage.base.MiniMessageBase;
import dev.siroshun.mcmsgdef.MessageKey;
import net.kyori.adventure.text.ComponentLike;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static com.github.siroshun09.messages.minimessage.arg.Arg1.arg1;
import static com.github.siroshun09.messages.minimessage.base.MiniMessageBase.messageKey;
import static net.okocraft.box.api.message.Placeholders.ARG;
import static net.okocraft.box.api.message.Placeholders.ITEM_NAME;
import static net.okocraft.box.api.message.Placeholders.PERMISSION;
Expand All @@ -20,54 +18,54 @@ public final class ErrorMessages {
/**
* A message sent when the player does not have the permission.
*/
public static final Arg1<String> NO_PERMISSION = arg1(getKeyFromCore("NO_PERMISSION"), PERMISSION);
public static final MessageKey.Arg1<String> NO_PERMISSION = getKeyFromCore("NO_PERMISSION").with(PERMISSION);

/**
* A message sent when the player cannot use Box.
*/
public static final MiniMessageBase CANNOT_USE_BOX = messageKey(getKeyFromCore("CANNOT_USE_BOX"));
public static final MessageKey CANNOT_USE_BOX = getKeyFromCore("CANNOT_USE_BOX");

/**
* A message sent when the command executed by the non-player.
*/
public static final MiniMessageBase COMMAND_ONLY_PLAYER = messageKey(getKeyFromCore("ONLY_PLAYER"));
public static final MessageKey COMMAND_ONLY_PLAYER = getKeyFromCore("ONLY_PLAYER");

/**
* A message sent when the specified argument is not number.
*/
public static final Arg1<String> INVALID_NUMBER = arg1(getKeyFromCore("INVALID_NUMBER"), ARG);
public static final MessageKey.Arg1<String> INVALID_NUMBER = getKeyFromCore("INVALID_NUMBER").with(ARG);

/**
* A message sent when the specified item is not found.
*/
public static final Arg1<String> ITEM_NOT_FOUND = arg1(getKeyFromCore("ITEM_NOT_FOUND"), ITEM_NAME);
public static final MessageKey.Arg1<String> ITEM_NOT_FOUND = getKeyFromCore("ITEM_NOT_FOUND").with(ITEM_NAME);

/**
* A message sent when the specified player is not found.
*/
public static final Arg1<String> PLAYER_NOT_FOUND = arg1(getKeyFromCore("PLAYER_NOT_FOUND"), PLAYER_NAME);
public static final MessageKey.Arg1<String> PLAYER_NOT_FOUND = getKeyFromCore("PLAYER_NOT_FOUND").with(PLAYER_NAME);

/**
* A message sent when the specified subcommand is not found.
*/
public static final MiniMessageBase SUB_COMMAND_NOT_FOUND = messageKey(getKeyFromCore("SUB_COMMAND_NOT_FOUND"));
public static final MessageKey SUB_COMMAND_NOT_FOUND = getKeyFromCore("SUB_COMMAND_NOT_FOUND");

/**
* A message sent when arguments are not enough.
*/
public static final MiniMessageBase NOT_ENOUGH_ARGUMENT = messageKey(getKeyFromCore("NOT_ENOUGH_ARGUMENT"));
public static final MessageKey NOT_ENOUGH_ARGUMENT = getKeyFromCore("NOT_ENOUGH_ARGUMENT");

private static final MiniMessageBase NOT_LOADED_SELF = messageKey(getKeyFromCore("NOT_LOADED_SELF"));
private static final Arg1<String> NOT_LOADED_OTHER = arg1(getKeyFromCore("NOT_LOADED_OTHER"), PLAYER_NAME);
private static final MiniMessageBase LOADING_SELF = messageKey(getKeyFromCore("LOADING_SELF"));
private static final Arg1<String> LOADING_OTHER = arg1(getKeyFromCore("LOADING_OTHER"), PLAYER_NAME);
private static final MessageKey NOT_LOADED_SELF = getKeyFromCore("NOT_LOADED_SELF");
private static final MessageKey.Arg1<String> NOT_LOADED_OTHER = getKeyFromCore("NOT_LOADED_OTHER").with(PLAYER_NAME);
private static final MessageKey LOADING_SELF = getKeyFromCore("LOADING_SELF");
private static final MessageKey.Arg1<String> LOADING_OTHER = getKeyFromCore("LOADING_OTHER").with(PLAYER_NAME);

private static @NotNull String getKeyFromCore(@NotNull String fieldName) {
private static @NotNull MessageKey getKeyFromCore(@NotNull String fieldName) {
try {
var clazz = Class.forName("net.okocraft.box.core.message.CoreMessages");
var field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
return (String) field.get(null);
return MessageKey.key((String) field.get(null));
} catch (NoSuchFieldException | ClassNotFoundException | IllegalAccessException e) {
throw new RuntimeException(e);
}
Expand All @@ -79,7 +77,7 @@ public final class ErrorMessages {
* @param playerName a player name or {@code null} if self
* @return a message sent when the player data is not loaded
*/
public static @NotNull MiniMessageBase playerDataIsNotLoaded(@Nullable String playerName) {
public static @NotNull ComponentLike playerDataIsNotLoaded(@Nullable String playerName) {
return playerName == null ? NOT_LOADED_SELF : NOT_LOADED_OTHER.apply(playerName);
}

Expand All @@ -89,7 +87,7 @@ public final class ErrorMessages {
* @param playerName a player name or {@code null} if self
* @return a message sent when the player data is currently loading
*/
public static @NotNull MiniMessageBase playerDataIsLoading(@Nullable String playerName) {
public static @NotNull ComponentLike playerDataIsLoading(@Nullable String playerName) {
return playerName == null ? LOADING_SELF : LOADING_OTHER.apply(playerName);
}

Expand Down

This file was deleted.

25 changes: 10 additions & 15 deletions api/src/main/java/net/okocraft/box/api/message/Placeholders.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package net.okocraft.box.api.message;

import com.github.siroshun09.messages.minimessage.base.Placeholder;
import net.kyori.adventure.text.Component;
import dev.siroshun.mcmsgdef.Placeholder;
import net.kyori.adventure.text.minimessage.translation.Argument;
import net.okocraft.box.api.model.item.BoxItem;
import org.jetbrains.annotations.NotNull;

/**
* A collection of common {@link Placeholder}s.
Expand All @@ -13,46 +12,42 @@ public final class Placeholders {
/**
* A {@link Placeholder} of {@code <permission>}.
*/
public static final Placeholder<String> PERMISSION = Placeholder.component("permission", Component::text);
public static final Placeholder<String> PERMISSION = node -> Argument.string("permission", node);

/**
* A {@link Placeholder} of {@code <player_name>}.
*/
public static final Placeholder<String> PLAYER_NAME = Placeholder.component("player_name", Component::text);
public static final Placeholder<String> PLAYER_NAME = name -> Argument.string("player_name", name);

/**
* A {@link Placeholder} of {@code <item>}.
*/
public static final Placeholder<BoxItem> ITEM = Placeholder.component("item", Placeholders::render);
public static final Placeholder<BoxItem> ITEM = item -> Argument.component("item", item.getDisplayName().color(null).hoverEvent(item.getOriginal()));

/**
* A {@link Placeholder} of {@code <item_name>}.
*/
public static final Placeholder<String> ITEM_NAME = Placeholder.component("item_name", Component::text);
public static final Placeholder<String> ITEM_NAME = itemName -> Argument.string("item_name", itemName);

/**
* A {@link Placeholder} of {@code <amount>}.
*/
public static final Placeholder<Integer> AMOUNT = Placeholder.component("amount", Component::text);
public static final Placeholder<Integer> AMOUNT = amount -> Argument.numeric("amount", amount);

/**
* A {@link Placeholder} of {@code <current>}.
*/
public static final Placeholder<Integer> CURRENT = Placeholder.component("current", Component::text);
public static final Placeholder<Integer> CURRENT = current -> Argument.numeric("current", current);

/**
* A {@link Placeholder} of {@code <error>}.
*/
public static final Placeholder<Throwable> ERROR = Placeholder.component("error", e -> Component.text(e.getMessage()));
public static final Placeholder<Throwable> ERROR = e -> Argument.string("error", e.getMessage());

/**
* A {@link Placeholder} of {@code <arg>}.
*/
public static final Placeholder<String> ARG = Placeholder.component("arg", Component::text);

private static @NotNull Component render(@NotNull BoxItem item) {
return item.getDisplayName().color(null).hoverEvent(item.getOriginal());
}
public static final Placeholder<String> ARG = arg -> Argument.string("arg", arg);

private Placeholders() {
throw new UnsupportedOperationException();
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jcommon {
exclude("org.yaml", "snakeyaml")
}
api(libs.event4j)
api(libs.messages)
api(libs.mcmsgdef)
compileOnlyApi(libs.paper)
implementation(libs.configapi.serialization.record)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.okocraft.box.bootstrap;

import com.github.siroshun09.messages.api.directory.DirectorySource;
import com.github.siroshun09.messages.api.util.Loader;
import dev.siroshun.event4j.api.caller.EventCaller;
import dev.siroshun.event4j.api.listener.ListenerSubscriber;
import dev.siroshun.event4j.api.priority.Priority;
import dev.siroshun.event4j.tree.TreeEventService;
import dev.siroshun.mcmsgdef.directory.DirectorySource;
import dev.siroshun.mcmsgdef.file.Loader;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import net.kyori.adventure.key.Key;
import net.okocraft.box.api.event.BoxEvent;
Expand Down
2 changes: 1 addition & 1 deletion bundle/src/main/java/net/okocraft/box/bundle/Builtin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.okocraft.box.bundle;

import com.github.siroshun09.messages.api.util.PropertiesFile;
import dev.siroshun.mcmsgdef.file.PropertiesFile;
import net.okocraft.box.bootstrap.BoxBootstrapContext;
import net.okocraft.box.feature.autostore.AutoStoreFeature;
import net.okocraft.box.feature.bemode.BEModeFeature;
Expand Down
24 changes: 8 additions & 16 deletions core/src/main/java/net/okocraft/box/core/BoxCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.okocraft.box.api.feature.FeatureContext;
import net.okocraft.box.api.feature.FeatureProvider;
import net.okocraft.box.api.feature.Reloadable;
import net.okocraft.box.api.message.MessageProvider;
import net.okocraft.box.api.model.manager.ItemManager;
import net.okocraft.box.api.model.manager.StockManager;
import net.okocraft.box.api.model.manager.UserManager;
Expand Down Expand Up @@ -107,7 +106,7 @@ public boolean enable(@NotNull Storage storage) {

this.customDataManager = new BoxCustomDataManager(storage.getCustomDataStorage());

this.playerMap = new BoxPlayerMapImpl(this.userManager, this.stockManager, this.eventCallers, this.context.scheduler(), this.context.messageProvider());
this.playerMap = new BoxPlayerMapImpl(this.userManager, this.stockManager, this.eventCallers, this.context.scheduler());
this.playerMap.loadAll();

Bukkit.getPluginManager().registerEvents(new PlayerConnectionListener(this.playerMap), this.context.plugin());
Expand All @@ -116,8 +115,8 @@ public boolean enable(@NotNull Storage storage) {

BoxLogger.logger().info("Registering commands...");

this.boxCommand = new BoxCommandImpl(this.context.messageProvider(), this.context.scheduler(), this.playerMap, this::canUseBox);
this.boxAdminCommand = new BoxAdminCommandImpl(this.context.messageProvider(), this.context.scheduler());
this.boxCommand = new BoxCommandImpl(this.context.scheduler(), this.playerMap, this::canUseBox);
this.boxAdminCommand = new BoxAdminCommandImpl(this.context.scheduler());

this.context.commandRegisterer().register(this.boxCommand).register(this.boxAdminCommand);

Expand All @@ -138,7 +137,6 @@ public void disable() {

@Override
public void reload(@NotNull CommandSender sender) {
var source = this.context.messageProvider().findSource(sender);
var playerMessenger = new Consumer<Supplier<Component>>() {
@Override
public void accept(Supplier<Component> componentSupplier) {
Expand All @@ -154,19 +152,19 @@ public void accept(Supplier<Component> componentSupplier) {

try {
this.context.config().reload();
CoreMessages.CONFIG_RELOADED_MSG.apply(Config.FILENAME).source(source).send(sender);
sender.sendMessage(CoreMessages.CONFIG_RELOADED_MSG.apply(Config.FILENAME));
} catch (Throwable e) {
playerMessenger.accept(() -> CoreMessages.CONFIG_RELOAD_FAILURE.apply(Config.FILENAME, e).source(source).message());
playerMessenger.accept(() -> CoreMessages.CONFIG_RELOAD_FAILURE.apply(Config.FILENAME, e));
BoxLogger.logger().error("Could not reload {}", Config.FILENAME, e);
}

this.toggleDebugListener(this.context.config().coreSetting().debug());

try {
this.context.messageProvider().load();
CoreMessages.MESSAGE_RELOADED_MSG.source(source).send(sender);
sender.sendMessage(CoreMessages.MESSAGE_RELOADED_MSG);
} catch (Throwable e) {
playerMessenger.accept(() -> CoreMessages.MESSAGES_RELOAD_FAILURE.apply(e).source(source).message());
playerMessenger.accept(() -> CoreMessages.MESSAGES_RELOAD_FAILURE.apply(e));
BoxLogger.logger().error("Could not reload messages", e);
}

Expand All @@ -178,7 +176,7 @@ public void accept(Supplier<Component> componentSupplier) {
reloadable.reload(featureReloadContext);
this.eventCallers.sync().call(new FeatureEvent(feature, FeatureEvent.Type.RELOAD));
} catch (Throwable e) {
playerMessenger.accept(() -> CoreMessages.FEATURE_RELOAD_FAILURE.apply(feature, e).source(source).message());
playerMessenger.accept(() -> CoreMessages.FEATURE_RELOAD_FAILURE.apply(feature, e));
BoxLogger.logger().error("Could not reload {}", feature.getName(), e);
}
}
Expand All @@ -194,12 +192,6 @@ public void accept(Supplier<Component> componentSupplier) {
return this.context.dataDirectory();
}

@Override
public @NotNull MessageProvider getMessageProvider() {
return this.context.messageProvider();
}


@Override
public @NotNull EventCallerProvider getEventCallers() {
return this.eventCallers;
Expand Down
Loading