From 50f26145502d00b1d29bee404b6a049044e39bfb Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sun, 26 Sep 2021 22:44:42 +0900 Subject: [PATCH 01/80] version 4.1.0-SNAPSHOT --- api/pom.xml | 2 +- bundle/pom.xml | 20 ++++++++++---------- core/pom.xml | 4 ++-- features/autostore/pom.xml | 8 ++++---- features/category/pom.xml | 6 +++--- features/command/pom.xml | 6 +++--- features/craft/pom.xml | 8 ++++---- features/gui/pom.xml | 8 ++++---- features/notifier/pom.xml | 6 +++--- features/pom.xml | 2 +- features/stick/pom.xml | 6 +++--- migrator/pom.xml | 8 ++++---- pom.xml | 2 +- 13 files changed, 43 insertions(+), 43 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index c730d24f5e..e3383c071a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -7,7 +7,7 @@ net.okocraft.box parent - 4.0.0 + 4.1.0-SNAPSHOT api diff --git a/bundle/pom.xml b/bundle/pom.xml index 8dd6e9f74d..9343bfeae3 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -7,7 +7,7 @@ net.okocraft.box parent - 4.0.0 + 4.1.0-SNAPSHOT bundle @@ -16,55 +16,55 @@ net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT compile net.okocraft.box core - 4.0.0 + 4.1.0-SNAPSHOT compile net.okocraft.box.feature autostore - 4.0.0 + 4.1.0-SNAPSHOT compile net.okocraft.box.feature category - 4.0.0 + 4.1.0-SNAPSHOT compile net.okocraft.box.feature command - 4.0.0 + 4.1.0-SNAPSHOT compile net.okocraft.box.feature craft - 4.0.0 + 4.1.0-SNAPSHOT compile net.okocraft.box.feature gui - 4.0.0 + 4.1.0-SNAPSHOT compile net.okocraft.box.feature notifier - 4.0.0 + 4.1.0-SNAPSHOT compile net.okocraft.box.feature stick - 4.0.0 + 4.1.0-SNAPSHOT compile diff --git a/core/pom.xml b/core/pom.xml index 6a07299111..5b2b554154 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -7,7 +7,7 @@ net.okocraft.box parent - 4.0.0 + 4.1.0-SNAPSHOT core @@ -16,7 +16,7 @@ net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT provided diff --git a/features/autostore/pom.xml b/features/autostore/pom.xml index cd719643c1..71e2c3587a 100644 --- a/features/autostore/pom.xml +++ b/features/autostore/pom.xml @@ -7,24 +7,24 @@ net.okocraft.box features - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box.feature autostore - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT provided net.okocraft.box.feature gui - 4.0.0 + 4.1.0-SNAPSHOT provided diff --git a/features/category/pom.xml b/features/category/pom.xml index 265da403f5..32482f290f 100644 --- a/features/category/pom.xml +++ b/features/category/pom.xml @@ -7,18 +7,18 @@ net.okocraft.box features - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box.feature category - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT provided diff --git a/features/command/pom.xml b/features/command/pom.xml index e3f3a12e3f..311e303036 100644 --- a/features/command/pom.xml +++ b/features/command/pom.xml @@ -7,18 +7,18 @@ net.okocraft.box features - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box.feature command - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT compile diff --git a/features/craft/pom.xml b/features/craft/pom.xml index 72931261c7..56503aca30 100644 --- a/features/craft/pom.xml +++ b/features/craft/pom.xml @@ -7,24 +7,24 @@ net.okocraft.box features - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box.feature craft - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT provided net.okocraft.box.feature gui - 4.0.0 + 4.1.0-SNAPSHOT provided diff --git a/features/gui/pom.xml b/features/gui/pom.xml index 9432c85a39..2fa5c7a83e 100644 --- a/features/gui/pom.xml +++ b/features/gui/pom.xml @@ -7,24 +7,24 @@ features net.okocraft.box - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box.feature gui - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT provided net.okocraft.box.feature category - 4.0.0 + 4.1.0-SNAPSHOT provided diff --git a/features/notifier/pom.xml b/features/notifier/pom.xml index 4ec7108e89..995e112e94 100644 --- a/features/notifier/pom.xml +++ b/features/notifier/pom.xml @@ -7,18 +7,18 @@ net.okocraft.box features - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box.feature notifier - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT provided diff --git a/features/pom.xml b/features/pom.xml index 9c1d1f36ac..f3df7ec658 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -7,7 +7,7 @@ net.okocraft.box parent - 4.0.0 + 4.1.0-SNAPSHOT features diff --git a/features/stick/pom.xml b/features/stick/pom.xml index 487961faf7..b56312ced2 100644 --- a/features/stick/pom.xml +++ b/features/stick/pom.xml @@ -7,18 +7,18 @@ net.okocraft.box features - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box.feature stick - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT compile diff --git a/migrator/pom.xml b/migrator/pom.xml index 330266295c..0c59f787bb 100644 --- a/migrator/pom.xml +++ b/migrator/pom.xml @@ -7,24 +7,24 @@ net.okocraft.box parent - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box.migrator migrator - 4.0.0 + 4.1.0-SNAPSHOT net.okocraft.box api - 4.0.0 + 4.1.0-SNAPSHOT provided net.okocraft.box.feature autostore - 4.0.0 + 4.1.0-SNAPSHOT provided diff --git a/pom.xml b/pom.xml index 89689977d8..615232c3fa 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ net.okocraft.box parent - 4.0.0 + 4.1.0-SNAPSHOT pom Box From 619ed95e8ae54f2e9ab9ac5c053b79f32ff8fed2 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 27 Sep 2021 18:52:22 +0900 Subject: [PATCH 02/80] change(api): BoxPlayer should not implement BoxUser (closes #59) --- .../okocraft/box/api/player/BoxPlayer.java | 21 ++++++++++++++++--- .../box/core/listener/DebugListener.java | 4 ++-- .../box/core/player/BoxPlayerImpl.java | 5 ++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/net/okocraft/box/api/player/BoxPlayer.java b/api/src/main/java/net/okocraft/box/api/player/BoxPlayer.java index 2c22620649..83186402bf 100644 --- a/api/src/main/java/net/okocraft/box/api/player/BoxPlayer.java +++ b/api/src/main/java/net/okocraft/box/api/player/BoxPlayer.java @@ -2,14 +2,29 @@ import net.okocraft.box.api.model.stock.StockHolder; import net.okocraft.box.api.model.stock.UserStockHolder; -import net.okocraft.box.api.model.user.BoxUser; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.UUID; + /** - * An interface of the online {@link BoxUser}. + * An interface of the online user. */ -public interface BoxPlayer extends BoxUser { +public interface BoxPlayer { + + /** + * Gets the {@link UUID} of this user. + * + * @return the {@link UUID} of this user + */ + @NotNull UUID getUUID(); + + /** + * Gets the name of this user. + * + * @return the name of this user + */ + @NotNull String getName(); /** * Gets the {@link Player} instance. diff --git a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java index c4ea242d48..a619c687a8 100644 --- a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java +++ b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java @@ -75,7 +75,7 @@ private void handleEvent(@NotNull BoxEvent event) { if (event instanceof PlayerLoadEvent loadEvent) { printLog(loadEvent.getEventName() + "{" + "playerUuid=" + loadEvent.getBoxPlayer().getUUID() + ", " + - "playerName='" + loadEvent.getBoxPlayer().getPlayer().getName() + "'" + + "playerName='" + loadEvent.getBoxPlayer().getName() + "'" + "}" ); return; @@ -84,7 +84,7 @@ private void handleEvent(@NotNull BoxEvent event) { if (event instanceof PlayerUnloadEvent unloadEvent) { printLog(unloadEvent.getEventName() + "{" + "playerUuid=" + unloadEvent.getBoxPlayer().getUUID() + ", " + - "playerName='" + unloadEvent.getBoxPlayer().getPlayer().getName() + "'" + + "playerName='" + unloadEvent.getBoxPlayer().getName() + "'" + "}" ); return; diff --git a/core/src/main/java/net/okocraft/box/core/player/BoxPlayerImpl.java b/core/src/main/java/net/okocraft/box/core/player/BoxPlayerImpl.java index 3f62b367f9..83d63f120c 100644 --- a/core/src/main/java/net/okocraft/box/core/player/BoxPlayerImpl.java +++ b/core/src/main/java/net/okocraft/box/core/player/BoxPlayerImpl.java @@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; -import java.util.Optional; import java.util.UUID; public class BoxPlayerImpl implements BoxPlayer { @@ -53,7 +52,7 @@ public void setCurrentStockHolder(@NotNull StockHolder stockHolder) { } @Override - public @NotNull Optional getName() { - return Optional.of(player.getName()); + public @NotNull String getName() { + return player.getName(); } } From 2f59eb788e8d307d1f4e3b0ef5e66579bbe0d847 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Sep 2021 11:20:56 +0000 Subject: [PATCH 03/80] build(deps): bump maven-javadoc-plugin from 3.3.0 to 3.3.1 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.3.0...maven-javadoc-plugin-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index e3383c071a..276c985f69 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -32,7 +32,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.3.0 + 3.3.1 attach-docs From c85b809b669a477515b42ac5b78733127c173b18 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Sep 2021 11:30:28 +0000 Subject: [PATCH 04/80] build(deps): bump HikariCP from 3.4.5 to 5.0.0 Bumps [HikariCP](https://github.com/brettwooldridge/HikariCP) from 3.4.5 to 5.0.0. - [Release notes](https://github.com/brettwooldridge/HikariCP/releases) - [Changelog](https://github.com/brettwooldridge/HikariCP/blob/dev/CHANGES) - [Commits](https://github.com/brettwooldridge/HikariCP/compare/HikariCP-3.4.5...HikariCP-5.0.0) --- updated-dependencies: - dependency-name: com.zaxxer:HikariCP dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- migrator/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrator/pom.xml b/migrator/pom.xml index 0c59f787bb..4c4af0fb70 100644 --- a/migrator/pom.xml +++ b/migrator/pom.xml @@ -30,7 +30,7 @@ com.zaxxer HikariCP - 3.4.5 + 5.0.0 compile From 4a980187641e0a70d40e258a90922db11116bf09 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 29 Sep 2021 11:18:56 +0000 Subject: [PATCH 05/80] build(deps): bump actions/setup-java from 2.3.0 to 2.3.1 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.3.0 to 2.3.1. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v2.3.0...v2.3.1) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index a0dd41d69e..2b2cf9b815 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -7,7 +7,7 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - name: Set up JDK 16 - uses: actions/setup-java@v2.3.0 + uses: actions/setup-java@v2.3.1 with: distribution: 'temurin' java-version: '16' From be64d97d208ab9e03cf9c522eb02d00b707769e9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Oct 2021 21:22:55 +0000 Subject: [PATCH 06/80] build(deps): bump event4j from 2.0.0 to 2.1.0 Bumps [event4j](https://github.com/Siroshun09/Event4J) from 2.0.0 to 2.1.0. - [Release notes](https://github.com/Siroshun09/Event4J/releases) - [Commits](https://github.com/Siroshun09/Event4J/commits/2.1.0) --- updated-dependencies: - dependency-name: com.github.siroshun09.event4j:event4j dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index 276c985f69..343ab84dad 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -22,7 +22,7 @@ com.github.siroshun09.event4j event4j - 2.0.0 + 2.1.0 compile From ab083c61bc5535bb9adb6d4aeec1f876e5edcc0a Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 4 Oct 2021 06:32:08 +0900 Subject: [PATCH 07/80] feat(api): add TaskFactory --- .../box/api/taskfactory/TaskFactory.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 api/src/main/java/net/okocraft/box/api/taskfactory/TaskFactory.java diff --git a/api/src/main/java/net/okocraft/box/api/taskfactory/TaskFactory.java b/api/src/main/java/net/okocraft/box/api/taskfactory/TaskFactory.java new file mode 100644 index 0000000000..af65e81221 --- /dev/null +++ b/api/src/main/java/net/okocraft/box/api/taskfactory/TaskFactory.java @@ -0,0 +1,47 @@ +package net.okocraft.box.api.taskfactory; + +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * An interface to create {@link CompletableFuture}s. + */ +public interface TaskFactory { + + /** + * Creates a {@link CompletableFuture} to run the task on main thread. + * + * @param task the task to run + * @return the new {@link CompletableFuture} + */ + @NotNull CompletableFuture run(@NotNull Runnable task); + + /** + * Creates a {@link CompletableFuture} to supply values on main thread. + * + * @param supplier the supplier + * @param the value type + * @return the new {@link CompletableFuture} + */ + @NotNull CompletableFuture supply(@NotNull Supplier supplier); + + /** + * Creates a {@link CompletableFuture} to run the task asynchronously. + * + * @param task the task to run + * @return the new {@link CompletableFuture} + */ + @NotNull CompletableFuture runAsync(@NotNull Runnable task); + + /** + * Creates a {@link CompletableFuture} to supply values asynchronously. + * + * @param supplier the supplier + * @param the value type + * @return the new {@link CompletableFuture} + */ + @NotNull CompletableFuture supplyAsync(@NotNull Supplier supplier); + +} From 261fe655946b524edfd4103325efda2c2b9c705f Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 4 Oct 2021 06:32:32 +0900 Subject: [PATCH 08/80] feat(api): add BoxAPI#getTaskFactory --- api/src/main/java/net/okocraft/box/api/BoxAPI.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/src/main/java/net/okocraft/box/api/BoxAPI.java b/api/src/main/java/net/okocraft/box/api/BoxAPI.java index 7102185684..5ab8773561 100644 --- a/api/src/main/java/net/okocraft/box/api/BoxAPI.java +++ b/api/src/main/java/net/okocraft/box/api/BoxAPI.java @@ -10,6 +10,7 @@ import net.okocraft.box.api.model.manager.StockManager; import net.okocraft.box.api.model.manager.UserManager; import net.okocraft.box.api.player.BoxPlayerMap; +import net.okocraft.box.api.taskfactory.TaskFactory; import net.okocraft.box.api.util.ExecutorProvider; import org.bukkit.NamespacedKey; import org.bukkit.command.CommandSender; @@ -106,6 +107,13 @@ public interface BoxAPI { */ @NotNull CustomDataContainer getCustomDataContainer(); + /** + * Gets the {@link TaskFactory}. + * + * @return the {@link TaskFactory} + */ + @NotNull TaskFactory getTaskFactory(); + /** * Gets the {@link ExecutorProvider}. * From 4bc27e4a58aaf0ad4660d959f906c4b4cdc62e7f Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 4 Oct 2021 06:38:22 +0900 Subject: [PATCH 09/80] feat(core): implements TaskFactory --- .../java/net/okocraft/box/core/BoxPlugin.java | 8 +++ .../box/core/taskfactory/BoxTaskFactory.java | 66 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java diff --git a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java index ef77d58f73..1428e90326 100644 --- a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java +++ b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java @@ -18,6 +18,7 @@ import net.okocraft.box.api.model.manager.StockManager; import net.okocraft.box.api.model.manager.UserManager; import net.okocraft.box.api.player.BoxPlayerMap; +import net.okocraft.box.api.taskfactory.TaskFactory; import net.okocraft.box.api.util.ExecutorProvider; import net.okocraft.box.core.command.BoxAdminCommandImpl; import net.okocraft.box.core.command.BoxCommandImpl; @@ -35,6 +36,7 @@ import net.okocraft.box.core.storage.Storage; import net.okocraft.box.core.storage.implementations.yaml.YamlStorage; import net.okocraft.box.core.task.AutoSaveTask; +import net.okocraft.box.core.taskfactory.BoxTaskFactory; import net.okocraft.box.core.util.executor.BoxExecutorProvider; import net.okocraft.box.core.util.executor.InternalExecutors; import org.bukkit.Bukkit; @@ -70,6 +72,7 @@ public class BoxPlugin implements BoxAPI { private final DebugListener debugListener = new DebugListener(); private final EventBus eventBus = EventBus.newEventBus(); + private final BoxTaskFactory taskFactory = new BoxTaskFactory(); private final BoxExecutorProvider executorProvider = new BoxExecutorProvider(); private final BoxCommandImpl boxCommand = new BoxCommandImpl(); @@ -339,6 +342,11 @@ private void saveDefaultLanguages(@NotNull Path directory) throws IOException { return customDataContainer; } + @Override + public @NotNull TaskFactory getTaskFactory() { + return taskFactory; + } + @Override public @NotNull ExecutorProvider getExecutorProvider() { return executorProvider; diff --git a/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java b/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java new file mode 100644 index 0000000000..633aed1be0 --- /dev/null +++ b/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java @@ -0,0 +1,66 @@ +package net.okocraft.box.core.taskfactory; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import net.okocraft.box.api.BoxProvider; +import net.okocraft.box.api.taskfactory.TaskFactory; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; +import java.util.logging.Level; + +public class BoxTaskFactory implements TaskFactory { + + private final ExecutorService executor = Executors.newFixedThreadPool( + Math.min(Runtime.getRuntime().availableProcessors(), 4), + new ThreadFactoryBuilder() + .setDaemon(true) + .setNameFormat("box-worker-%d") + .setUncaughtExceptionHandler(this::reportUncaughtException) + .build() + ); + + @Override + public @NotNull CompletableFuture run(@NotNull Runnable task) { + return CompletableFuture.runAsync(task, getMainThread()); + } + + @Override + public @NotNull CompletableFuture supply(@NotNull Supplier supplier) { + return CompletableFuture.supplyAsync(supplier, getMainThread()); + } + + @Override + public @NotNull CompletableFuture runAsync(@NotNull Runnable task) { + return CompletableFuture.runAsync(task, executor); + } + + @Override + public @NotNull CompletableFuture supplyAsync(@NotNull Supplier supplier) { + return CompletableFuture.supplyAsync(supplier, executor); + } + + public void shutdown() throws InterruptedException { + executor.shutdown(); + + //noinspection ResultOfMethodCallIgnored + executor.awaitTermination(1, TimeUnit.MINUTES); + } + + private void reportUncaughtException(@NotNull Thread thread, @NotNull Throwable throwable) { + BoxProvider.get().getLogger().log( + Level.SEVERE, + "An exception occurred in the thread " + thread.getName(), + throwable + ); + } + + private @NotNull Executor getMainThread() { + return Bukkit.getScheduler().getMainThreadExecutor(BoxProvider.get().getPluginInstance()); + } +} From eb90072f23f7e5440fd863ec4e1837fb68874780 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 4 Oct 2021 06:50:11 +0900 Subject: [PATCH 10/80] refactor: change ExecutorProvider to TaskFactory --- .../box/core/command/BaseCommand.java | 8 ++--- .../feature/command/box/DepositCommand.java | 22 +++++-------- .../feature/command/box/WithdrawCommand.java | 8 ++--- .../box/feature/craft/util/ItemCrafter.java | 17 +++++----- .../okocraft/box/feature/gui/GuiFeature.java | 7 +--- .../feature/gui/api/buttons/CloseButton.java | 7 +--- .../box/feature/gui/api/util/MenuOpener.java | 9 ++--- .../internal/listener/InventoryListener.java | 27 +++++++-------- .../gui/internal/mode/StorageMode.java | 33 +++++++++---------- .../stick/command/CustomStickCommand.java | 7 +--- .../feature/stick/command/StickCommand.java | 6 +--- 11 files changed, 59 insertions(+), 92 deletions(-) diff --git a/core/src/main/java/net/okocraft/box/core/command/BaseCommand.java b/core/src/main/java/net/okocraft/box/core/command/BaseCommand.java index 8f90512794..cb7ec92e98 100644 --- a/core/src/main/java/net/okocraft/box/core/command/BaseCommand.java +++ b/core/src/main/java/net/okocraft/box/core/command/BaseCommand.java @@ -19,7 +19,6 @@ import java.util.Collections; import java.util.List; import java.util.Locale; -import java.util.concurrent.CompletableFuture; import java.util.logging.Level; import static net.kyori.adventure.text.Component.text; @@ -171,10 +170,9 @@ private void sendHelp(@NotNull CommandSender sender) { } private void runCommandAsync(@NotNull Command command, @NotNull CommandSender sender, @NotNull String[] args) { - CompletableFuture.runAsync( - () -> command.onCommand(sender, args), - BoxProvider.get().getExecutorProvider().getExecutor() - ).exceptionallyAsync(e -> reportError(sender, args, e)); + BoxProvider.get().getTaskFactory() + .runAsync(() -> command.onCommand(sender, args)) + .exceptionallyAsync(e -> reportError(sender, args, e)); } private @Nullable Void reportError(@NotNull CommandSender sender, @NotNull String[] args, @NotNull Throwable throwable) { diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/box/DepositCommand.java b/features/command/src/main/java/net/okocraft/box/feature/command/box/DepositCommand.java index 1a4679d351..0b81d2c79f 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/box/DepositCommand.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/box/DepositCommand.java @@ -21,7 +21,6 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -97,10 +96,9 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { private void depositItemInMainHand(@NotNull Player player, int amount) { var result = - CompletableFuture.supplyAsync( - () -> InventoryTransaction.depositItemInMainHand(player, amount), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + BoxProvider.get().getTaskFactory() + .supply(() -> InventoryTransaction.depositItemInMainHand(player, amount)) + .join(); if (result.getType().isModified()) { var item = result.getItem(); @@ -122,10 +120,9 @@ private void depositItemInMainHand(@NotNull Player player, int amount) { private void depositAll(@NotNull Player player) { var resultList = - CompletableFuture.supplyAsync( - () -> InventoryTransaction.depositItemsInInventory(player.getInventory()), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + BoxProvider.get().getTaskFactory() + .supply(() -> InventoryTransaction.depositItemsInInventory(player.getInventory())) + .join(); var stockHolder = BoxProvider.get().getBoxPlayerMap().get(player).getCurrentStockHolder(); @@ -138,10 +135,9 @@ private void depositAll(@NotNull Player player) { private void depositItem(@NotNull Player player, @NotNull BoxItem boxItem, int amount) { var resultList = - CompletableFuture.supplyAsync( - () -> InventoryTransaction.depositItem(player.getInventory(), boxItem, amount), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + BoxProvider.get().getTaskFactory() + .supply(() -> InventoryTransaction.depositItem(player.getInventory(), boxItem, amount)) + .join(); var stockHolder = BoxProvider.get().getBoxPlayerMap().get(player).getCurrentStockHolder(); diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/box/WithdrawCommand.java b/features/command/src/main/java/net/okocraft/box/feature/command/box/WithdrawCommand.java index cf73ca50df..ebdec4b028 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/box/WithdrawCommand.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/box/WithdrawCommand.java @@ -16,7 +16,6 @@ import java.util.List; import java.util.Locale; import java.util.Set; -import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; public class WithdrawCommand extends AbstractCommand { @@ -70,10 +69,9 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { } var result = - CompletableFuture.supplyAsync( - () -> InventoryTransaction.withdraw(player.getInventory(), boxItem, amount), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + BoxProvider.get().getTaskFactory() + .supply(() -> InventoryTransaction.withdraw(player.getInventory(), boxItem, amount)) + .join(); var resultType = result.getType(); diff --git a/features/craft/src/main/java/net/okocraft/box/feature/craft/util/ItemCrafter.java b/features/craft/src/main/java/net/okocraft/box/feature/craft/util/ItemCrafter.java index d7acf19881..d746cf57c0 100644 --- a/features/craft/src/main/java/net/okocraft/box/feature/craft/util/ItemCrafter.java +++ b/features/craft/src/main/java/net/okocraft/box/feature/craft/util/ItemCrafter.java @@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull; import java.util.HashMap; -import java.util.concurrent.CompletableFuture; public class ItemCrafter { @@ -52,13 +51,15 @@ public static boolean craft(@NotNull Player crafter, @NotNull SelectedRecipe rec int storeAmount = resultAmount; if (Distribution.toInventory(crafter)) { - var result = CompletableFuture.supplyAsync( - () -> InventoryTransaction.withdraw( - crafter.getInventory(), - recipe.result(), - resultAmount - ), BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + var result = + BoxProvider.get().getTaskFactory() + .supply(() -> + InventoryTransaction.withdraw( + crafter.getInventory(), + recipe.result(), + resultAmount + ) + ).join(); if (result.getType().isModified()) { storeAmount = resultAmount - result.getAmount(); diff --git a/features/gui/src/main/java/net/okocraft/box/feature/gui/GuiFeature.java b/features/gui/src/main/java/net/okocraft/box/feature/gui/GuiFeature.java index 3a45ee3472..fd070e5b23 100644 --- a/features/gui/src/main/java/net/okocraft/box/feature/gui/GuiFeature.java +++ b/features/gui/src/main/java/net/okocraft/box/feature/gui/GuiFeature.java @@ -16,8 +16,6 @@ import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; -import java.util.concurrent.CompletableFuture; - public class GuiFeature extends AbstractBoxFeature implements Reloadable { private final MenuOpenCommand command = new MenuOpenCommand(); @@ -53,10 +51,7 @@ public void disable() { if (Bukkit.isPrimaryThread()) { closeMenus(); } else { - CompletableFuture.runAsync( - this::closeMenus, - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + BoxProvider.get().getTaskFactory().run(this::closeMenus).join(); } HandlerList.unregisterAll(listener); diff --git a/features/gui/src/main/java/net/okocraft/box/feature/gui/api/buttons/CloseButton.java b/features/gui/src/main/java/net/okocraft/box/feature/gui/api/buttons/CloseButton.java index 73f27808cc..82c687f409 100644 --- a/features/gui/src/main/java/net/okocraft/box/feature/gui/api/buttons/CloseButton.java +++ b/features/gui/src/main/java/net/okocraft/box/feature/gui/api/buttons/CloseButton.java @@ -13,8 +13,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.concurrent.CompletableFuture; - public class CloseButton implements Button { @Override @@ -40,10 +38,7 @@ public int getSlot() { @Override public void onClick(@NotNull Player clicker, @NotNull ClickType clickType) { - CompletableFuture.runAsync( - clicker::closeInventory, BoxProvider.get().getExecutorProvider().getMainThread() - ); - + BoxProvider.get().getTaskFactory().run(clicker::closeInventory); clicker.playSound(clicker.getLocation(), Sound.BLOCK_CHEST_CLOSE, SoundCategory.MASTER, 100f, 1.5f); } } diff --git a/features/gui/src/main/java/net/okocraft/box/feature/gui/api/util/MenuOpener.java b/features/gui/src/main/java/net/okocraft/box/feature/gui/api/util/MenuOpener.java index 2b428bd411..0c69009050 100644 --- a/features/gui/src/main/java/net/okocraft/box/feature/gui/api/util/MenuOpener.java +++ b/features/gui/src/main/java/net/okocraft/box/feature/gui/api/util/MenuOpener.java @@ -7,8 +7,6 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import java.util.concurrent.CompletableFuture; - public final class MenuOpener { public static void open(@NotNull Menu menu, @NotNull Player viewer) { @@ -17,10 +15,9 @@ public static void open(@NotNull Menu menu, @NotNull Player viewer) { holder.initializeMenu(viewer); holder.applyContents(); - CompletableFuture.runAsync( - () -> viewer.openInventory(holder.getInventory()), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + BoxProvider.get().getTaskFactory() + .run(() -> viewer.openInventory(holder.getInventory())) + .join(); viewer.playSound(viewer.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 100f, 2.0f); } diff --git a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/listener/InventoryListener.java b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/listener/InventoryListener.java index 0a60a625a7..b534fe2bed 100644 --- a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/listener/InventoryListener.java +++ b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/listener/InventoryListener.java @@ -58,17 +58,17 @@ public void onClick(@NotNull InventoryClickEvent event) { this.lastClickTime.put(clicker.getUniqueId(), System.currentTimeMillis()); - var task = CompletableFuture.runAsync( - () -> processClick(holder, clicker, event.getSlot(), event.getClick()), - BoxProvider.get().getExecutorProvider().getExecutor() - ).exceptionallyAsync(throwable -> { - BoxProvider.get().getLogger().log( - Level.SEVERE, - "Could not complete click task (" + clicker.getName() + ")", - throwable - ); - return null; - }); + var task = + BoxProvider.get().getTaskFactory() + .runAsync(() -> processClick(holder, clicker, event.getSlot(), event.getClick())) + .exceptionallyAsync(throwable -> { + BoxProvider.get().getLogger().log( + Level.SEVERE, + "Could not complete click task (" + clicker.getName() + ")", + throwable + ); + return null; + }); clickTaskMap.put(clicker.getUniqueId(), task); } @@ -78,10 +78,7 @@ private void processClick(@NotNull BoxInventoryHolder holder, @NotNull Player cl holder.processClick(clicker, slot, type); if (holder.updateMenu(clicker)) { - CompletableFuture.runAsync( - () -> holder.updateInventory(clicker), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + BoxProvider.get().getTaskFactory().run(() -> holder.updateInventory(clicker)).join(); } } } diff --git a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/mode/StorageMode.java b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/mode/StorageMode.java index 669663d503..27ea953122 100644 --- a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/mode/StorageMode.java +++ b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/mode/StorageMode.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.concurrent.CompletableFuture; public class StorageMode implements BoxItemClickMode { @@ -94,14 +93,14 @@ private void processDeposit(@NotNull Context context) { int transactionAmount = PlayerSession.get(player).getCustomNumberHolder(TRANSACTION_AMOUNT_NAME).getAmount(); - var resultList = CompletableFuture.supplyAsync( - () -> InventoryTransaction.depositItem( - player.getInventory(), - context.item(), - transactionAmount - ), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + var resultList = + BoxProvider.get().getTaskFactory() + .supply(() -> InventoryTransaction.depositItem( + player.getInventory(), + context.item(), + transactionAmount + ) + ).join(); if (!resultList.getType().isModified()) { player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 100f, 1.5f); @@ -134,10 +133,10 @@ private void processWithdraw(@NotNull Context context) { var amount = Math.min(currentStock, transactionAmount); - var result = CompletableFuture.supplyAsync( - () -> InventoryTransaction.withdraw(player.getInventory(), context.item(), amount), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + var result = + BoxProvider.get().getTaskFactory() + .supply(() -> InventoryTransaction.withdraw(player.getInventory(), context.item(), amount)) + .join(); if (result.getType().isModified()) { stockHolder.decrease(result.getItem(), result.getAmount()); @@ -180,10 +179,10 @@ public void onClick(@NotNull Player clicker, @NotNull ClickType clickType) { return; } - var resultList = CompletableFuture.supplyAsync( - () -> InventoryTransaction.depositItemsInInventory(clicker.getInventory()), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + var resultList = + BoxProvider.get().getTaskFactory() + .supply(() -> InventoryTransaction.depositItemsInInventory(clicker.getInventory())) + .join(); if (!resultList.getType().isModified()) { clicker.playSound(clicker.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 100f, 1.5f); diff --git a/features/stick/src/main/java/net/okocraft/box/feature/stick/command/CustomStickCommand.java b/features/stick/src/main/java/net/okocraft/box/feature/stick/command/CustomStickCommand.java index 4396cf7598..b29d108ee9 100644 --- a/features/stick/src/main/java/net/okocraft/box/feature/stick/command/CustomStickCommand.java +++ b/features/stick/src/main/java/net/okocraft/box/feature/stick/command/CustomStickCommand.java @@ -10,8 +10,6 @@ import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; -import java.util.concurrent.CompletableFuture; - import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; import static net.kyori.adventure.text.format.NamedTextColor.AQUA; @@ -58,10 +56,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { return; } - CompletableFuture.runAsync( - () -> makeStick(player), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + BoxProvider.get().getTaskFactory().run(() -> makeStick(player)).join(); } private void makeStick(@NotNull Player player) { diff --git a/features/stick/src/main/java/net/okocraft/box/feature/stick/command/StickCommand.java b/features/stick/src/main/java/net/okocraft/box/feature/stick/command/StickCommand.java index 0807a2fd4f..162c14428d 100644 --- a/features/stick/src/main/java/net/okocraft/box/feature/stick/command/StickCommand.java +++ b/features/stick/src/main/java/net/okocraft/box/feature/stick/command/StickCommand.java @@ -10,7 +10,6 @@ import org.jetbrains.annotations.NotNull; import java.util.Set; -import java.util.concurrent.CompletableFuture; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; @@ -49,10 +48,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { return; } - CompletableFuture.runAsync( - () -> runCommand(player), - BoxProvider.get().getExecutorProvider().getMainThread() - ).join(); + BoxProvider.get().getTaskFactory().run(() -> runCommand(player)).join(); } private void runCommand(@NotNull Player player) { From 3de847b7f400d610bd478bf3d3f10124f6a0cf48 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 4 Oct 2021 06:50:47 +0900 Subject: [PATCH 11/80] fix(core): shutdown taskfactory --- core/src/main/java/net/okocraft/box/core/BoxPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java index 1428e90326..6a6f5c804b 100644 --- a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java +++ b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java @@ -224,7 +224,7 @@ public void disable() { getLogger().info("Shutting down executors..."); try { - executorProvider.shutdown(); + taskFactory.shutdown(); InternalExecutors.shutdownAll(); } catch (InterruptedException e) { getLogger().log(Level.SEVERE, "Could not shutdown executors", e); From 377797b64a2a389ab84f9e0860961e17d2f54ec8 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 4 Oct 2021 06:52:36 +0900 Subject: [PATCH 12/80] change(api): deprecate ExecutorProvider --- api/src/main/java/net/okocraft/box/api/BoxAPI.java | 3 +++ .../main/java/net/okocraft/box/api/util/ExecutorProvider.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/api/src/main/java/net/okocraft/box/api/BoxAPI.java b/api/src/main/java/net/okocraft/box/api/BoxAPI.java index 5ab8773561..060ec08848 100644 --- a/api/src/main/java/net/okocraft/box/api/BoxAPI.java +++ b/api/src/main/java/net/okocraft/box/api/BoxAPI.java @@ -16,6 +16,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; @@ -119,6 +120,8 @@ public interface BoxAPI { * * @return the {@link ExecutorProvider} */ + @Deprecated(forRemoval = true) + @ApiStatus.ScheduledForRemoval(inVersion = "4.2.0") @NotNull ExecutorProvider getExecutorProvider(); /** diff --git a/api/src/main/java/net/okocraft/box/api/util/ExecutorProvider.java b/api/src/main/java/net/okocraft/box/api/util/ExecutorProvider.java index 063ecd5d4a..7f81efe01e 100644 --- a/api/src/main/java/net/okocraft/box/api/util/ExecutorProvider.java +++ b/api/src/main/java/net/okocraft/box/api/util/ExecutorProvider.java @@ -1,5 +1,6 @@ package net.okocraft.box.api.util; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.util.concurrent.Executor; @@ -7,6 +8,8 @@ /** * An interface for providing {@link Executor}s. */ +@Deprecated(forRemoval = true) +@ApiStatus.ScheduledForRemoval(inVersion = "4.2.0") public interface ExecutorProvider { /** From e8a5b60251a08454b8e8c201a6466f161bff0dc1 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 4 Oct 2021 06:54:55 +0900 Subject: [PATCH 13/80] change(core): use TaskFactory's executor --- .../box/core/taskfactory/BoxTaskFactory.java | 6 +++- .../util/executor/BoxExecutorProvider.java | 36 ++----------------- 2 files changed, 8 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java b/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java index 633aed1be0..dbf1f5e7fd 100644 --- a/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java +++ b/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java @@ -60,7 +60,11 @@ private void reportUncaughtException(@NotNull Thread thread, @NotNull Throwable ); } - private @NotNull Executor getMainThread() { + public @NotNull Executor getExecutor() { + return executor; + } + + public @NotNull Executor getMainThread() { return Bukkit.getScheduler().getMainThreadExecutor(BoxProvider.get().getPluginInstance()); } } diff --git a/core/src/main/java/net/okocraft/box/core/util/executor/BoxExecutorProvider.java b/core/src/main/java/net/okocraft/box/core/util/executor/BoxExecutorProvider.java index 5eb496f15c..d27430fead 100644 --- a/core/src/main/java/net/okocraft/box/core/util/executor/BoxExecutorProvider.java +++ b/core/src/main/java/net/okocraft/box/core/util/executor/BoxExecutorProvider.java @@ -1,51 +1,21 @@ package net.okocraft.box.core.util.executor; -import com.google.common.util.concurrent.ThreadFactoryBuilder; import net.okocraft.box.api.BoxProvider; import net.okocraft.box.api.util.ExecutorProvider; -import org.bukkit.Bukkit; +import net.okocraft.box.core.taskfactory.BoxTaskFactory; import org.jetbrains.annotations.NotNull; import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; public class BoxExecutorProvider implements ExecutorProvider { - private final ExecutorService executor = Executors.newFixedThreadPool( - Math.min(Runtime.getRuntime().availableProcessors(), 4), - new ThreadFactoryBuilder() - .setDaemon(true) - .setNameFormat("box-worker-%d") - .setUncaughtExceptionHandler(this::reportUncaughtException) - .build() - ); - @Override public @NotNull Executor getExecutor() { - return executor; + return ((BoxTaskFactory) BoxProvider.get().getTaskFactory()).getExecutor(); } @Override public @NotNull Executor getMainThread() { - return Bukkit.getScheduler().getMainThreadExecutor(BoxProvider.get().getPluginInstance()); - } - - public void shutdown() throws InterruptedException { - executor.shutdown(); - - //noinspection ResultOfMethodCallIgnored - executor.awaitTermination(1, TimeUnit.MINUTES); - } - - - private void reportUncaughtException(@NotNull Thread thread, @NotNull Throwable throwable) { - BoxProvider.get().getLogger().log( - Level.SEVERE, - "An exception occurred in the thread " + thread.getName(), - throwable - ); + return ((BoxTaskFactory) BoxProvider.get().getTaskFactory()).getMainThread(); } } From 1642f86448fca4f8ebe203271189a7a5a30c2a58 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 4 Oct 2021 07:04:03 +0900 Subject: [PATCH 14/80] style: improve code formatting --- .../okocraft/box/feature/craft/util/ItemCrafter.java | 11 +++-------- .../box/feature/gui/internal/mode/StorageMode.java | 10 +++------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/features/craft/src/main/java/net/okocraft/box/feature/craft/util/ItemCrafter.java b/features/craft/src/main/java/net/okocraft/box/feature/craft/util/ItemCrafter.java index d746cf57c0..dfb746b737 100644 --- a/features/craft/src/main/java/net/okocraft/box/feature/craft/util/ItemCrafter.java +++ b/features/craft/src/main/java/net/okocraft/box/feature/craft/util/ItemCrafter.java @@ -52,14 +52,9 @@ public static boolean craft(@NotNull Player crafter, @NotNull SelectedRecipe rec if (Distribution.toInventory(crafter)) { var result = - BoxProvider.get().getTaskFactory() - .supply(() -> - InventoryTransaction.withdraw( - crafter.getInventory(), - recipe.result(), - resultAmount - ) - ).join(); + BoxProvider.get().getTaskFactory().supply( + () -> InventoryTransaction.withdraw(crafter.getInventory(), recipe.result(), resultAmount) + ).join(); if (result.getType().isModified()) { storeAmount = resultAmount - result.getAmount(); diff --git a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/mode/StorageMode.java b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/mode/StorageMode.java index 27ea953122..55a6844da8 100644 --- a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/mode/StorageMode.java +++ b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/mode/StorageMode.java @@ -94,13 +94,9 @@ private void processDeposit(@NotNull Context context) { PlayerSession.get(player).getCustomNumberHolder(TRANSACTION_AMOUNT_NAME).getAmount(); var resultList = - BoxProvider.get().getTaskFactory() - .supply(() -> InventoryTransaction.depositItem( - player.getInventory(), - context.item(), - transactionAmount - ) - ).join(); + BoxProvider.get().getTaskFactory().supply( + () -> InventoryTransaction.depositItem(player.getInventory(), context.item(), transactionAmount) + ).join(); if (!resultList.getType().isModified()) { player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 100f, 1.5f); From f9c885b8883f8b2eadba75d0c6eb6e7db8e50778 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Wed, 6 Oct 2021 22:13:27 +0900 Subject: [PATCH 15/80] change: add more null checks for api and its implementations --- .../net/okocraft/box/api/BoxProvider.java | 4 +++- .../box/api/command/AbstractCommand.java | 7 ++++--- .../box/api/command/SubCommandHoldable.java | 4 +++- .../box/api/event/feature/FeatureEvent.java | 6 ++++-- .../box/api/event/item/ItemImportEvent.java | 4 +++- .../box/api/event/player/PlayerEvent.java | 4 +++- .../player/PlayerStockHolderChangeEvent.java | 4 +++- .../box/api/event/stock/StockEvent.java | 4 +++- .../box/api/feature/AbstractBoxFeature.java | 4 +++- .../api/transaction/InventoryTransaction.java | 19 +++++++++++++++---- .../api/transaction/TransactionResult.java | 5 +++++ .../transaction/TransactionResultList.java | 5 +++++ .../box/core/command/BaseCommand.java | 7 +++++++ .../model/data/BoxCustomDataContainer.java | 8 ++++++++ .../core/model/manager/BoxItemManager.java | 17 +++++++++++++---- .../core/model/manager/BoxStockManager.java | 5 +++++ .../core/model/manager/BoxUserManager.java | 7 +++++++ .../core/model/stock/AbstractStockHolder.java | 2 ++ .../box/core/player/BoxPlayerMapImpl.java | 7 +++++++ .../box/core/taskfactory/BoxTaskFactory.java | 5 +++++ 20 files changed, 108 insertions(+), 20 deletions(-) diff --git a/api/src/main/java/net/okocraft/box/api/BoxProvider.java b/api/src/main/java/net/okocraft/box/api/BoxProvider.java index a1f73ab115..99f4fb1f3b 100644 --- a/api/src/main/java/net/okocraft/box/api/BoxProvider.java +++ b/api/src/main/java/net/okocraft/box/api/BoxProvider.java @@ -2,6 +2,8 @@ import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * A class to provide {@link BoxAPI}. */ @@ -31,7 +33,7 @@ public final class BoxProvider { */ public static void set(@NotNull BoxAPI api) { if (API == null) { - API = api; + API = Objects.requireNonNull(api); } else { throw new IllegalStateException("BoxAPI is already set."); } diff --git a/api/src/main/java/net/okocraft/box/api/command/AbstractCommand.java b/api/src/main/java/net/okocraft/box/api/command/AbstractCommand.java index 0c682477b6..511bcdec9d 100644 --- a/api/src/main/java/net/okocraft/box/api/command/AbstractCommand.java +++ b/api/src/main/java/net/okocraft/box/api/command/AbstractCommand.java @@ -6,6 +6,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Set; /** @@ -40,9 +41,9 @@ public AbstractCommand(@NotNull String name, @NotNull String permissionNode) { * @param aliases the set of aliases */ public AbstractCommand(@NotNull String name, @NotNull String permissionNode, @NotNull Set aliases) { - this.name = name; - this.permissionNode = permissionNode; - this.aliases = aliases; + this.name = Objects.requireNonNull(name); + this.permissionNode = Objects.requireNonNull(permissionNode); + this.aliases = Objects.requireNonNull(aliases); } public @NotNull String getName() { diff --git a/api/src/main/java/net/okocraft/box/api/command/SubCommandHoldable.java b/api/src/main/java/net/okocraft/box/api/command/SubCommandHoldable.java index ce7bc9c054..62d9f727a8 100644 --- a/api/src/main/java/net/okocraft/box/api/command/SubCommandHoldable.java +++ b/api/src/main/java/net/okocraft/box/api/command/SubCommandHoldable.java @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Optional; /** @@ -34,6 +35,7 @@ class SubCommandHolder { * @param subCommands the set of subcommands */ public SubCommandHolder(@NotNull Command... subCommands) { + Objects.requireNonNull(subCommands); this.subCommands = new ArrayList<>(Arrays.asList(subCommands)); } @@ -74,7 +76,7 @@ public void unregister(@NotNull Command subCommand) { * @return the search result */ public @NotNull Optional search(@NotNull String name) { - name = name.toLowerCase(Locale.ROOT); + name = Objects.requireNonNull(name).toLowerCase(Locale.ROOT); for (var subCommand : subCommands) { if (subCommand.getName().equals(name) || subCommand.getAliases().contains(name)) { diff --git a/api/src/main/java/net/okocraft/box/api/event/feature/FeatureEvent.java b/api/src/main/java/net/okocraft/box/api/event/feature/FeatureEvent.java index f0a6eb838e..340515ae77 100644 --- a/api/src/main/java/net/okocraft/box/api/event/feature/FeatureEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/feature/FeatureEvent.java @@ -4,6 +4,8 @@ import net.okocraft.box.api.feature.BoxFeature; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * A class that represents a {@link BoxFeature} related event. */ @@ -19,8 +21,8 @@ public class FeatureEvent extends BoxEvent { * @param type the type of this event */ public FeatureEvent(@NotNull BoxFeature feature, @NotNull Type type) { - this.feature = feature; - this.type = type; + this.feature = Objects.requireNonNull(feature); + this.type = Objects.requireNonNull(type); } /** diff --git a/api/src/main/java/net/okocraft/box/api/event/item/ItemImportEvent.java b/api/src/main/java/net/okocraft/box/api/event/item/ItemImportEvent.java index 560c7ad5d8..95081c07dc 100644 --- a/api/src/main/java/net/okocraft/box/api/event/item/ItemImportEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/item/ItemImportEvent.java @@ -3,6 +3,8 @@ import net.okocraft.box.api.model.item.BoxItem; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * A event called when the {@link BoxItem} is imported. *

@@ -20,7 +22,7 @@ public class ItemImportEvent extends ItemEvent { */ public ItemImportEvent(@NotNull BoxItem importedItem, @NotNull ItemType type) { super(importedItem); - this.type = type; + this.type = Objects.requireNonNull(type); } /** diff --git a/api/src/main/java/net/okocraft/box/api/event/player/PlayerEvent.java b/api/src/main/java/net/okocraft/box/api/event/player/PlayerEvent.java index f4377b08bf..2a14797a68 100644 --- a/api/src/main/java/net/okocraft/box/api/event/player/PlayerEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/player/PlayerEvent.java @@ -4,6 +4,8 @@ import net.okocraft.box.api.player.BoxPlayer; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * A class that represents a {@link BoxPlayer} related event. */ @@ -17,7 +19,7 @@ public class PlayerEvent extends BoxEvent { * @param boxPlayer the player of this event */ public PlayerEvent(@NotNull BoxPlayer boxPlayer) { - this.boxPlayer = boxPlayer; + this.boxPlayer = Objects.requireNonNull(boxPlayer); } /** diff --git a/api/src/main/java/net/okocraft/box/api/event/player/PlayerStockHolderChangeEvent.java b/api/src/main/java/net/okocraft/box/api/event/player/PlayerStockHolderChangeEvent.java index eec1f4df44..ad254c3377 100644 --- a/api/src/main/java/net/okocraft/box/api/event/player/PlayerStockHolderChangeEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/player/PlayerStockHolderChangeEvent.java @@ -4,6 +4,8 @@ import net.okocraft.box.api.player.BoxPlayer; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * A {@link PlayerEvent} called when the player changed the {@link StockHolder}. */ @@ -20,7 +22,7 @@ public class PlayerStockHolderChangeEvent extends PlayerEvent { public PlayerStockHolderChangeEvent(@NotNull BoxPlayer boxPlayer, @NotNull StockHolder previous) { super(boxPlayer); - this.previous = previous; + this.previous = Objects.requireNonNull(previous); } /** diff --git a/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java b/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java index 7859846f8a..ffc84fa4b7 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java @@ -5,6 +5,8 @@ import net.okocraft.box.api.model.stock.UserStockHolder; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * A class that represents a {@link StockHolder} related event. *

@@ -23,7 +25,7 @@ public class StockEvent extends BoxEvent { * @param stockHolder the stockholder of the event */ public StockEvent(@NotNull StockHolder stockHolder) { - this.stockHolder = stockHolder; + this.stockHolder = Objects.requireNonNull(stockHolder); } /** diff --git a/api/src/main/java/net/okocraft/box/api/feature/AbstractBoxFeature.java b/api/src/main/java/net/okocraft/box/api/feature/AbstractBoxFeature.java index 0542c6d739..04750ad2e9 100644 --- a/api/src/main/java/net/okocraft/box/api/feature/AbstractBoxFeature.java +++ b/api/src/main/java/net/okocraft/box/api/feature/AbstractBoxFeature.java @@ -3,6 +3,8 @@ import com.github.siroshun09.event4j.handlerlist.Key; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * An abstract implementation of {@link BoxFeature}. */ @@ -17,7 +19,7 @@ public abstract class AbstractBoxFeature implements BoxFeature { * @param name the feature name */ protected AbstractBoxFeature(@NotNull String name) { - this.name = name; + this.name = Objects.requireNonNull(name); this.listenerKey = Key.of(name); } diff --git a/api/src/main/java/net/okocraft/box/api/transaction/InventoryTransaction.java b/api/src/main/java/net/okocraft/box/api/transaction/InventoryTransaction.java index e15c6cb798..f0b55a7bee 100644 --- a/api/src/main/java/net/okocraft/box/api/transaction/InventoryTransaction.java +++ b/api/src/main/java/net/okocraft/box/api/transaction/InventoryTransaction.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.Objects; import static net.okocraft.box.api.transaction.TransactionResultType.DEPOSITED; import static net.okocraft.box.api.transaction.TransactionResultType.IS_AIR; @@ -29,6 +30,8 @@ public final class InventoryTransaction { * @return the {@link TransactionResult} */ public static @NotNull TransactionResult depositItemInMainHand(@NotNull Player player, int depositLimit) { + Objects.requireNonNull(player); + if (depositLimit < 1) { return TransactionResult.create(NOT_DEPOSITED); } @@ -65,6 +68,8 @@ public final class InventoryTransaction { * @return the {@link TransactionResultList} */ public static @NotNull TransactionResultList depositItemsInInventory(@NotNull Inventory inventory) { + Objects.requireNonNull(inventory); + var result = new ArrayList(); var contents = inventory.getStorageContents(); @@ -100,7 +105,10 @@ public final class InventoryTransaction { * @return the {@link TransactionResultList} */ public static @NotNull TransactionResultList depositItem(@NotNull Inventory inventory, - @NotNull BoxItem boxItem, int depositLimit) { + @NotNull BoxItem boxItem, int depositLimit) { + Objects.requireNonNull(inventory); + Objects.requireNonNull(boxItem); + if (depositLimit < 1) { return TransactionResultList.create(NOT_DEPOSITED); } @@ -153,12 +161,15 @@ public final class InventoryTransaction { * Withdraws items to an inventory. * * @param inventory the target inventory - * @param boxItem the item to withdraw - * @param amount the amount of item + * @param boxItem the item to withdraw + * @param amount the amount of item * @return the {@link TransactionResult} */ public static @NotNull TransactionResult withdraw(@NotNull Inventory inventory, - @NotNull BoxItem boxItem, int amount) { + @NotNull BoxItem boxItem, int amount) { + Objects.requireNonNull(inventory); + Objects.requireNonNull(boxItem); + var toStore = amount; var maxStackSize = boxItem.getOriginal().getMaxStackSize(); diff --git a/api/src/main/java/net/okocraft/box/api/transaction/TransactionResult.java b/api/src/main/java/net/okocraft/box/api/transaction/TransactionResult.java index 1487563e12..03d5bb175e 100644 --- a/api/src/main/java/net/okocraft/box/api/transaction/TransactionResult.java +++ b/api/src/main/java/net/okocraft/box/api/transaction/TransactionResult.java @@ -21,6 +21,8 @@ public class TransactionResult { */ @Contract(value = "_ -> new", pure = true) public static @NotNull TransactionResult create(@NotNull TransactionResultType type) { + Objects.requireNonNull(type); + if (!type.isModified()) { return new TransactionResult(type, null, 0); } else { @@ -40,6 +42,9 @@ public class TransactionResult { */ @Contract(value = "_, _, _ -> new", pure = true) public static @NotNull TransactionResult create(@NotNull TransactionResultType type, @NotNull BoxItem item, int amount) { + Objects.requireNonNull(type); + Objects.requireNonNull(item); + if (type.isModified()) { return new TransactionResult(type, item, amount); } else { diff --git a/api/src/main/java/net/okocraft/box/api/transaction/TransactionResultList.java b/api/src/main/java/net/okocraft/box/api/transaction/TransactionResultList.java index 193c17e278..47024dbab5 100644 --- a/api/src/main/java/net/okocraft/box/api/transaction/TransactionResultList.java +++ b/api/src/main/java/net/okocraft/box/api/transaction/TransactionResultList.java @@ -22,6 +22,8 @@ public class TransactionResultList { */ @Contract(value = "_ -> new", pure = true) public static @NotNull TransactionResultList create(@NotNull TransactionResultType type) { + Objects.requireNonNull(type); + if (!type.isModified()) { return new TransactionResultList(type, null); } else { @@ -41,6 +43,9 @@ public class TransactionResultList { @Contract(value = "_, _ -> new", pure = true) public static @NotNull TransactionResultList create(@NotNull TransactionResultType type, @NotNull List resultList) { + Objects.requireNonNull(type); + Objects.requireNonNull(resultList); + if (type.isModified()) { return new TransactionResultList(type, resultList); } else { diff --git a/core/src/main/java/net/okocraft/box/core/command/BaseCommand.java b/core/src/main/java/net/okocraft/box/core/command/BaseCommand.java index cb7ec92e98..c349dd1a2e 100644 --- a/core/src/main/java/net/okocraft/box/core/command/BaseCommand.java +++ b/core/src/main/java/net/okocraft/box/core/command/BaseCommand.java @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.logging.Level; import static net.kyori.adventure.text.Component.text; @@ -32,6 +33,9 @@ public abstract class BaseCommand implements Command, SubCommandHoldable, Comman @Override public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { + Objects.requireNonNull(sender); + Objects.requireNonNull(args); + if (!sender.hasPermission(getPermissionNode())) { sender.sendMessage(GeneralMessage.ERROR_NO_PERMISSION.apply(getPermissionNode())); return; @@ -73,6 +77,9 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { @Override public @NotNull List onTabComplete(@NotNull CommandSender sender, @NotNull String[] args) { + Objects.requireNonNull(sender); + Objects.requireNonNull(args); + if (args.length == 0 || !sender.hasPermission(getPermissionNode())) { return Collections.emptyList(); } diff --git a/core/src/main/java/net/okocraft/box/core/model/data/BoxCustomDataContainer.java b/core/src/main/java/net/okocraft/box/core/model/data/BoxCustomDataContainer.java index 22cd8cd6d3..31d3cd0056 100644 --- a/core/src/main/java/net/okocraft/box/core/model/data/BoxCustomDataContainer.java +++ b/core/src/main/java/net/okocraft/box/core/model/data/BoxCustomDataContainer.java @@ -6,6 +6,7 @@ import net.okocraft.box.core.util.executor.InternalExecutors; import org.jetbrains.annotations.NotNull; +import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; @@ -21,6 +22,9 @@ public BoxCustomDataContainer(@NotNull CustomDataStorage customDataStorage) { @Override public @NotNull CompletableFuture<@NotNull Configuration> get(@NotNull String namespace, @NotNull String key) { + Objects.requireNonNull(namespace); + Objects.requireNonNull(key); + return CompletableFuture.supplyAsync(() -> { try { return customDataStorage.load(namespace, key); @@ -32,6 +36,10 @@ public BoxCustomDataContainer(@NotNull CustomDataStorage customDataStorage) { @Override public @NotNull CompletableFuture set(@NotNull String namespace, @NotNull String key, @NotNull Configuration configuration) { + Objects.requireNonNull(namespace); + Objects.requireNonNull(key); + Objects.requireNonNull(configuration); + return CompletableFuture.runAsync(() -> { try { customDataStorage.save(namespace, key, configuration); diff --git a/core/src/main/java/net/okocraft/box/core/model/manager/BoxItemManager.java b/core/src/main/java/net/okocraft/box/core/model/manager/BoxItemManager.java index 19d1df8105..b871960947 100644 --- a/core/src/main/java/net/okocraft/box/core/model/manager/BoxItemManager.java +++ b/core/src/main/java/net/okocraft/box/core/model/manager/BoxItemManager.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -39,7 +40,7 @@ public BoxItemManager(@NotNull ItemStorage itemStorage) { @Override public @NotNull Optional getBoxItem(@NotNull ItemStack itemStack) { - var copied = itemStack.clone(); + var copied = Objects.requireNonNull(itemStack).clone(); copied.setAmount(1); @@ -48,7 +49,7 @@ public BoxItemManager(@NotNull ItemStorage itemStorage) { @Override public @NotNull Optional getBoxItem(@NotNull String name) { - name = name.toUpperCase(Locale.ROOT); + name = Objects.requireNonNull(name).toUpperCase(Locale.ROOT); for (var item : itemMap.values()) { if (item.getPlainName().equals(name)) { @@ -72,7 +73,7 @@ public BoxItemManager(@NotNull ItemStorage itemStorage) { @Override public boolean isRegistered(@NotNull ItemStack itemStack) { - var copied = itemStack.clone(); + var copied = Objects.requireNonNull(itemStack).clone(); copied.setAmount(1); @@ -81,6 +82,8 @@ public boolean isRegistered(@NotNull ItemStack itemStack) { @Override public boolean isUsed(@NotNull String name) { + Objects.requireNonNull(name); + var nameSet = itemNameCache; return nameSet.contains(name); } @@ -92,6 +95,8 @@ public boolean isCustomItem(@NotNull BoxItem item) { @Override public @NotNull CompletableFuture<@NotNull BoxCustomItem> registerCustomItem(@NotNull ItemStack original) { + Objects.requireNonNull(original); + return CompletableFuture.supplyAsync(() -> { var copied = original.clone(); @@ -119,7 +124,11 @@ public boolean isCustomItem(@NotNull BoxItem item) { } @Override - public @NotNull CompletableFuture<@NotNull BoxCustomItem> renameCustomItem(@NotNull BoxCustomItem item, @NotNull String newName) { + public @NotNull CompletableFuture<@NotNull BoxCustomItem> renameCustomItem(@NotNull BoxCustomItem item, + @NotNull String newName) { + Objects.requireNonNull(item); + Objects.requireNonNull(newName); + return CompletableFuture.supplyAsync(() -> { if (!isCustomItem(item)) { throw new IllegalStateException("Could not rename item because the item is created by box."); diff --git a/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java b/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java index e414366284..85925182b4 100644 --- a/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java +++ b/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java @@ -7,6 +7,7 @@ import net.okocraft.box.core.util.executor.InternalExecutors; import org.jetbrains.annotations.NotNull; +import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; @@ -22,6 +23,8 @@ public BoxStockManager(@NotNull StockStorage stockStorage) { @Override public @NotNull CompletableFuture<@NotNull UserStockHolder> loadUserStock(@NotNull BoxUser user) { + Objects.requireNonNull(user); + return CompletableFuture.supplyAsync(() -> { try { return stockStorage.loadUserStockHolder(user); @@ -33,6 +36,8 @@ public BoxStockManager(@NotNull StockStorage stockStorage) { @Override public @NotNull CompletableFuture saveUserStock(@NotNull UserStockHolder stockHolder) { + Objects.requireNonNull(stockHolder); + return CompletableFuture.runAsync(() -> { try { stockStorage.saveUserStockHolder(stockHolder); diff --git a/core/src/main/java/net/okocraft/box/core/model/manager/BoxUserManager.java b/core/src/main/java/net/okocraft/box/core/model/manager/BoxUserManager.java index db85486e7e..4394f4ca4a 100644 --- a/core/src/main/java/net/okocraft/box/core/model/manager/BoxUserManager.java +++ b/core/src/main/java/net/okocraft/box/core/model/manager/BoxUserManager.java @@ -6,6 +6,7 @@ import net.okocraft.box.core.util.executor.InternalExecutors; import org.jetbrains.annotations.NotNull; +import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -23,6 +24,8 @@ public BoxUserManager(@NotNull UserStorage userStorage) { @Override public @NotNull CompletableFuture<@NotNull BoxUser> loadUser(@NotNull UUID uuid) { + Objects.requireNonNull(uuid); + return CompletableFuture.supplyAsync(() -> { try { return userStorage.getUser(uuid); @@ -34,6 +37,8 @@ public BoxUserManager(@NotNull UserStorage userStorage) { @Override public @NotNull CompletableFuture saveUser(@NotNull BoxUser boxUser) { + Objects.requireNonNull(boxUser); + return CompletableFuture.runAsync(() -> { try { userStorage.saveBoxUser(boxUser); @@ -45,6 +50,8 @@ public BoxUserManager(@NotNull UserStorage userStorage) { @Override public @NotNull CompletableFuture> search(@NotNull String name) { + Objects.requireNonNull(name); + return CompletableFuture.supplyAsync(() -> { try { return userStorage.search(name); diff --git a/core/src/main/java/net/okocraft/box/core/model/stock/AbstractStockHolder.java b/core/src/main/java/net/okocraft/box/core/model/stock/AbstractStockHolder.java index 384f92282b..38a2c1f7ca 100644 --- a/core/src/main/java/net/okocraft/box/core/model/stock/AbstractStockHolder.java +++ b/core/src/main/java/net/okocraft/box/core/model/stock/AbstractStockHolder.java @@ -33,6 +33,7 @@ protected AbstractStockHolder(@NotNull Collection stockData) { @Override public int getAmount(@NotNull BoxItem item) { + Objects.requireNonNull(item); return Optional.ofNullable(stockData.get(item)).map(AtomicInteger::get).orElse(0); } @@ -126,6 +127,7 @@ public String toString() { } private @NotNull AtomicInteger getStock(@NotNull BoxItem item) { + Objects.requireNonNull(item); return stockData.computeIfAbsent(item, i -> new AtomicInteger(0)); } } diff --git a/core/src/main/java/net/okocraft/box/core/player/BoxPlayerMapImpl.java b/core/src/main/java/net/okocraft/box/core/player/BoxPlayerMapImpl.java index 60db0a3b35..7cf385aae9 100644 --- a/core/src/main/java/net/okocraft/box/core/player/BoxPlayerMapImpl.java +++ b/core/src/main/java/net/okocraft/box/core/player/BoxPlayerMapImpl.java @@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -33,11 +34,15 @@ public BoxPlayerMapImpl(@NotNull UserManager userManager, @NotNull StockManager @Override public @NotNull BoxPlayer get(@NotNull Player player) { + Objects.requireNonNull(player); + return Optional.ofNullable(playerMap.get(player)) .orElseThrow(() -> new IllegalStateException("player is not loaded (" + player.getName() + ")")); } public @NotNull CompletableFuture load(@NotNull Player player) { + Objects.requireNonNull(player); + return CompletableFuture.runAsync(() -> { var boxUser = new BoxUserImpl(player.getUniqueId(), player.getName()); @@ -54,6 +59,8 @@ public BoxPlayerMapImpl(@NotNull UserManager userManager, @NotNull StockManager } public @NotNull CompletableFuture unload(@NotNull Player player) { + Objects.requireNonNull(player); + var boxPlayer = playerMap.remove(player); if (boxPlayer != null) { diff --git a/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java b/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java index dbf1f5e7fd..c0f5061071 100644 --- a/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java +++ b/core/src/main/java/net/okocraft/box/core/taskfactory/BoxTaskFactory.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; +import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; @@ -27,21 +28,25 @@ public class BoxTaskFactory implements TaskFactory { @Override public @NotNull CompletableFuture run(@NotNull Runnable task) { + Objects.requireNonNull(task); return CompletableFuture.runAsync(task, getMainThread()); } @Override public @NotNull CompletableFuture supply(@NotNull Supplier supplier) { + Objects.requireNonNull(supplier); return CompletableFuture.supplyAsync(supplier, getMainThread()); } @Override public @NotNull CompletableFuture runAsync(@NotNull Runnable task) { + Objects.requireNonNull(task); return CompletableFuture.runAsync(task, executor); } @Override public @NotNull CompletableFuture supplyAsync(@NotNull Supplier supplier) { + Objects.requireNonNull(supplier); return CompletableFuture.supplyAsync(supplier, executor); } From 2412968de4521d1f2364e1f59dc98afcf3bab78e Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Wed, 6 Oct 2021 22:36:18 +0900 Subject: [PATCH 16/80] feat: send message when error occurred while processing click event async (closes #67) --- bundle/src/main/resources/ja_JP.yml | 1 + .../feature/gui/internal/lang/Displays.java | 9 ++++++++ .../internal/listener/InventoryListener.java | 23 ++++++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/bundle/src/main/resources/ja_JP.yml b/bundle/src/main/resources/ja_JP.yml index 158489f69d..2b44da6abc 100644 --- a/bundle/src/main/resources/ja_JP.yml +++ b/bundle/src/main/resources/ja_JP.yml @@ -235,6 +235,7 @@ box: recipe-not-found: "レシピがありません" gui: reloaded: "GUI 機能を再読み込みしました。" + error-occurred: "クリック処理中にエラーが発生しました。エラーメッセージ: {0}" command-help: command-line: "/box gui" description: "Box のメニューを開く" diff --git a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/lang/Displays.java b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/lang/Displays.java index 0a9ca06c99..40a85d55dd 100644 --- a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/lang/Displays.java +++ b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/lang/Displays.java @@ -1,6 +1,7 @@ package net.okocraft.box.feature.gui.internal.lang; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import net.okocraft.box.api.message.argument.SingleArgument; import net.okocraft.box.feature.category.model.Category; @@ -142,4 +143,12 @@ public final class Displays { public static final Component STORAGE_MODE_DEPOSIT_ALL_BUTTON_LORE_2 = translatable("box.gui.modes.storage-mode.deposit-all.lore-2", NO_DECORATION_GRAY); + + public static final SingleArgument ERROR_WHILE_CLICK_PROCESSING = + throwable -> + Component.translatable() + .key("box.gui.error-occurred") + .args(Component.text(throwable.getMessage(), NamedTextColor.WHITE)) + .color(NamedTextColor.RED) + .build(); } diff --git a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/listener/InventoryListener.java b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/listener/InventoryListener.java index b534fe2bed..9620c4916a 100644 --- a/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/listener/InventoryListener.java +++ b/features/gui/src/main/java/net/okocraft/box/feature/gui/internal/listener/InventoryListener.java @@ -2,6 +2,7 @@ import net.okocraft.box.api.BoxProvider; import net.okocraft.box.feature.gui.internal.holder.BoxInventoryHolder; +import net.okocraft.box.feature.gui.internal.lang.Displays; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -10,6 +11,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryClickEvent; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -61,14 +63,7 @@ public void onClick(@NotNull InventoryClickEvent event) { var task = BoxProvider.get().getTaskFactory() .runAsync(() -> processClick(holder, clicker, event.getSlot(), event.getClick())) - .exceptionallyAsync(throwable -> { - BoxProvider.get().getLogger().log( - Level.SEVERE, - "Could not complete click task (" + clicker.getName() + ")", - throwable - ); - return null; - }); + .exceptionallyAsync(e -> reportError(clicker, e)); clickTaskMap.put(clicker.getUniqueId(), task); } @@ -81,4 +76,16 @@ private void processClick(@NotNull BoxInventoryHolder holder, @NotNull Player cl BoxProvider.get().getTaskFactory().run(() -> holder.updateInventory(clicker)).join(); } } + + private @Nullable Void reportError(@NotNull Player player, @NotNull Throwable throwable) { + player.sendMessage(Displays.ERROR_WHILE_CLICK_PROCESSING.apply(throwable)); + + BoxProvider.get().getLogger().log( + Level.SEVERE, + "An error occurred while processing a click event (" + player.getName() + ")", + throwable + ); + + return null; + } } From 35edceb5d38fb19806ec646b7c0c2cb848260de9 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Mon, 4 Oct 2021 05:49:05 +0900 Subject: [PATCH 17/80] chore: show booleans --- bundle/src/main/resources/ja_JP.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/src/main/resources/ja_JP.yml b/bundle/src/main/resources/ja_JP.yml index 2b44da6abc..4d688e11af 100644 --- a/bundle/src/main/resources/ja_JP.yml +++ b/bundle/src/main/resources/ja_JP.yml @@ -25,7 +25,7 @@ box: all-toggled: "すべてのアイテムの自動収納設定を {0} にしました。" item-toggled: "アイテム {0} の自動収納設定を {1} にしました。" mode-not-found: "自動収納モードに {0} はありません。" - not-boolean: "{0} は有効な真偽値ではありません。" + not-boolean: "{0} は有効な真偽値ではありません。[on/off/true/false]" gui: mode: display-name: "自動収納設定" From e3c06a571030d75d9500bf939f158c4ee46aa6a0 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 15:58:48 +0900 Subject: [PATCH 18/80] chore: add en.yml --- bundle/src/main/resources/en.yml | 312 +++++++++++++++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 bundle/src/main/resources/en.yml diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml new file mode 100644 index 0000000000..51769622c9 --- /dev/null +++ b/bundle/src/main/resources/en.yml @@ -0,0 +1,312 @@ +box: + autostore: + error: + failed-to-load-settings: "Failed to load the auto-store settings. Please contact the administrator." + reloaded: "The auto-store feature has been reloaded." + mode: + all: "All items" + item: "Per item" + enabled: "Enabled" + disabled: "Disabled" + command: + help: + toggle: + command-line: "/box autostore [on/off]" + description: "Turn auto-store on/off" + all: + command-line: "/box autostore [all/item]" + description: "Change auto-store mode" + item: + command-line: "/box autostore item [on/off]" + description: "Change the auto-store setting for the item" + autostore-toggled: "Auto-store is now {0}." + mode-changed: "Auto-store mode is now {0}." + item: + all-toggled: "Set the auto-store setting for all items to {0}." + item-toggled: "Set the auto-store setting for item {0} to {1}." + mode-not-found: "Auto-store mode {0} is not found." + not-boolean: "{0} is not boolean. [on/off/true/false]" + gui: + mode: + display-name: "Auto-store setting" + lore: "Auto-store setting: " + setting-menu: + title: "Auto-store setting menu" + change-mode: + display-name: "Change auto-store mode" + all: "Click to change mode to 'all items'" + item: "Click to change mode to 'per item'" + toggle-button: "Click to set auto-store to {0}" + bulk-editing: + title: "Bulk change operation for per-item mode" + left-click: "Left click to set all items to {0}" + right-click: "Right click to set all items to {0}" + recent: "Recent bulk change operation: {0}" + category: + reloaded: "The category feature has been reloaded." + name: + armors: "Armors" + bows: "Bows" + candles: "Candles" + concretes: "Concretes" + custom-items: "Custom items" + decorations: "Decorations" + dirt: "Dirt" + dyes: "Dyes" + enchanted-books: "Enchanted books" + end: "End" + farms: "Farms" + flowers: "Flowers" + glasses: "Glasses" + horse: "Horse" + misc: "Misc" + mob-drops: "Mob drops" + mushrooms: "Mushrooms" + music-discs: "Music discs" + nether: "Nether" + oceans: "Oceans" + ores: "Ores" + potions: "Potions" + rails: "Rails" + redstones: "Redstones" + sand: "Sand" + shulker-boxes: "Shulker boxes" + spawn-eggs: "Spawn eggs" + stones: "Stones" + terracotta: "Terracotta" + tools: "Tools" + unavailable: "Unavailable" + uncategorized: "Uncategorized" + woods: "Woods" + wools: "Wools" + command: + box: + help: + command-line: "/box " + description: "Box base command" + deposit: + success: "Deposited {0}x{1} (Now {2})" + all-success: "Deposited {0} items in your inventory that can be deposited." + is-air: "You don't have no item in your main hand." + item-not-registered: "The item in your main hand is not registered in Box." + not-deposited: "The specified item was not found in your inventory." + not-found: "No items could be deposited in the inventory." + help: + main-hand: + command-line: "/box deposit [amount]" + description: "Deposit the item in your main hand" + all: + command-line: "/box deposit all" + description: "Deposit all items" + item: + command-line: "/box deposit [amount]" + description: "Deposit specified item" + give: + success: + sender: "Send {1}x{2} to player {0} (Now {3})." + target: "Receive {1}x{2} from player {0} (Now {3})." + no-stock: "There are no items {0} in stock." + self: "You can't send it to yourself." + target-no-permission: "Player {0} doesn't have the permission {1}." + target-is-in-disabled-world: "Player {0} is in world {1} where Box is not available." + help: + command-line: "/box give [amount]" + description: "Send items to other" + withdraw: + success: "Withdrew {0}x{1} (Now {2})." + stop: "Withdrawal ended because there is no more space in your inventory." + no-stock: "There are not items {0} in stock." + inventory-is-full: "There is not space in your inventory." + help: + command-line: "/box withdraw [amount]" + description: "Withdraw item" + iteminfo: + is-air: "You don't have no item in your main hand." + item-not-registered: "The item in your main hand is not registered in Box." + name: "Item Name: {0}" + stock: "Current stocks: {0}" + help: + command-line: "/box iteminfo [item]" + description: "Show information about the item you have or specify." + boxadmin: + help: + command-line: "/boxadmin " + description: "Box Admin command" + give: + success: + sender: "Gave {1}x{2} to player {0} (Now {3})." + target: "{0} give you {1}x{2} (Now {3})." + help: + command-line: "/boxadmin give " + description: "Increase stocks" + infinity: + enabled: "Enabled" + disabled: "Disabled" + toggle: "Infinite stock mode has been {0}." + toggle-sender: "{1} infinite stock mode for player {0}." + toggle-target: "Infinite stock mode has been {1} by {0}." + tip: "Infinite stock mode does not save deposited items." + help: + command-line: "/boxadmin infinity" + description: "Toggle infinite stock mode" + register: + is-air: "You don't have no item in your main hand." + already-registered: "{0} is already registered." + success: "{0} has been registered as name {1}." + failure: "Failed to register an item. Error message: {0}" + tip-rename: "Registered items can be renamed with /boxadmin rename ." + help: + command-line: "/boxadmin register" + description: "Register item in main hand to Box" + reload: + start: "Reloading Box..." + finish: "Reloading Box is complete." + help: + command-line: "/boxadmin reload" + description: "Reload Box" + rename: + is-not-custom-item: "The name of item {0} cannot be renamed." + already-used-name: "The item name {0} is already used." + success: "The item name has been renamed to {0}." + failure: "Failed to rename the item name. Error message: {0}" + help: + command-line: "/boxadmin rename " + description: "Change item name" + set: + success: + sender: "Player {0}'s item {1} has been set to {2}." + target: "Item {1} has been set to {2} by {0}." + help: + command-line: "/boxadmin set " + description: "Set stocks" + take: + success: + sender: "Took {1}x{2} from player {0} (Now {3})." + target: "{0} took {1}x{2} (Now {3})." + help: + command-line: "/boxadmin take " + description: "Decrease stocks" + version: + info: "Box {0}" + help: + command-line: "/boxadmin version" + description: "Show the current version of Box" + craft: + command: + recipe-not-found: "There is no recipe of item {0}." + recipe-reloaded: "Item recipes have been reloaded." + help: + command-line: "/box craft " + description: "Show the item recipe" + gui: + buttons: + display-name: "{0} crafts" + ingredients: "Ingredients" + shift-click-to-show-details: "Shift click to show details" + shift-click-to-show-recipes: "Shift click to show recipes" + current-stock: "Current stocks: {0}" + distribution: + display-name: "Destination" + inventory: "Inventory" + box: "Box" + current: "Destination of crafted items: {0}" + click-to-change: "Click to change to {0}" + change-unit: + display-name: "Change unit" + shift-click-to-reset-times: "Shift click to reset craft times" + change-times: + current: "Current craft times: {0}" + increase: + display-name: "Increase" + lore: "Click to increase craft times by {0}" + decrease: + display-name: "Decrease" + lore: "Click to decrease craft times by {0}" + set-to-unit: "Click to set craft times to {0}" + ingredient-change-mode: + bulk: "Bulk ingredient change" + each: "Partial ingredient change" + menus: + craft: "Crafting of {0}" + recipe-selector: "Recipes of {0}" + mode: + display-name: "Crafting mode" + click-to-show-recipes: "Click to show recipes" + recipe-not-found: "There is no recipe" + gui: + reloaded: "GUI feature has been reloaded." + error-occurred: "An error occurred while click processing. Error message: {0}" + command-help: + command-line: "/box gui" + description: "Open Box menu" + buttons: + back: "Back" + change-unit: + display-name: "Change unit" + shift-click-to-reset-amount: "Shift click to reset transaction amount" + change-transaction-amount: + current: "Current transaction amount: {0}" + decrease: + display-name: "Decrease" + lore: "Click to decrease transaction amount by {0}" + increase: + display-name: "Increase" + lore: "Click to increase transaction amount by {0}" + set-to-unit: "Click to set transaction amount to {0}" + close: "Close" + page-switch: + previous: "Previous page" + next: "Next page" + mode-change: "Change mode" + menus: + category-selector: "Category selector" + category-menu: "{0}" + modes: + storage-mode: + display-name: "Storage mode" + left-click-to-deposit: "Left click to deposit {0} items" + right-click-to-withdraw: "Right click to withdraw {0} items" + current-stock: "Current stocks: {0}" + deposit-all: + display-name: "Deposit all items" + lore-1: "Shift click to deposit" + lore-2: "all items in the inventory" + stick: + item: + display-name: "Box Stick" + lore-1: "Holding this in off hand will" + lore-2: "consume items from Box when use them." + lore-3: "Also, right click to open the menu" + command: + success: "You hold Box Stick in your off hand" + already-have: "You already have Box Stick in your off hand" + could-not-give-stick: "Could not hold Box Stick in your off hand because your inventory is full." + help: + command-line: "/box stick" + description: "Hold Box Stick in off hand" + customstick: + success: "The item in your hand can now be used as Box Stick." + already: "The item in your hand can already be used as Box Stick." + is-air: "You don't have no item in your main hand." + help: + command-line: "/boxadmin customstick" + description: "Make item in main hand a Box Stick" + error: + disabled-world: "Box cannot be used in world {0}." + failed-to-reload-feature: "Failed to reload {0}. Error message: {1}" + failed-to-execute-command: "Failed to execute command. Error message: {1}" + no-permission: "You don't have the permission: {0}" + player-data: + load-on-join: "Failed to load the stock data. Please contact the administrator." + save: "Failed to save the stock data. Please contact the administrator." + command: + only-player: "This command only execute by the player in game." + no-argument: "There is no argument." + not-enough-argument: "The arguments is not enough." + subcommand-not-found: "The specified subcommand was not found." + player-not-found: "The player {0} was not found." + item-not-found: "The item {0} was not found." + invalid-number: "{0} is not valid number." + mics: + config-reloaded: "config.yml has been reloaded." + languages-reloaded: "Language files have been reloaded." From 19bd9fdea9dcd98c831173f40fec08e839bd4d29 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 15:58:52 +0900 Subject: [PATCH 19/80] chore: improve some messages in ja_JP.yml --- bundle/src/main/resources/ja_JP.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bundle/src/main/resources/ja_JP.yml b/bundle/src/main/resources/ja_JP.yml index 4d688e11af..c06f149d2c 100644 --- a/bundle/src/main/resources/ja_JP.yml +++ b/bundle/src/main/resources/ja_JP.yml @@ -134,8 +134,8 @@ box: description: "Box の管理者用コマンド" give: success: - sender: "プレイヤー {0} にアイテム {1} を {2} 個付与しました (現在 {3} 個)。" - target: "{0} からアイテム {1} を {2} 個付与されました (現在 {3} 個)。" + sender: "プレイヤー {0} のアイテム {1} の在庫を {2} 個増やされました (現在 {3} 個)。" + target: "{0} にアイテム {1} の在庫を {2} 個増やされました (現在 {3} 個)。" help: command-line: "/boxadmin give <プレイヤー名> <アイテム名> <数量>" description: "在庫を増やす" @@ -174,15 +174,15 @@ box: description: "アイテムの名前を変更する" set: success: - sender: "プレイヤー {0} のアイテム {1} を {2} 個にセットしました。" - target: "{0} にアイテム {1} を {2} 個にセットされました。" + sender: "プレイヤー {0} のアイテム {1} の在庫を {2} 個にセットしました。" + target: "{0} にアイテム {1} の在庫を {2} 個にセットされました。" help: command-line: "/boxadmin set <プレイヤー名> <アイテム名> <数量>" description: "在庫をセットする" take: success: - sender: "プレイヤー {0} にアイテム {1} を {2} 個減らしました (現在 {3} 個)。" - target: "{0} にアイテム {1} を {2} 個減らされました (現在 {3} 個)。" + sender: "プレイヤー {0} のアイテム {1} の在庫を {2} 個減らしました (現在 {3} 個)。" + target: "{0} にアイテム {1} の在庫を {2} 個減らされました (現在 {3} 個)。" help: command-line: "/boxadmin take <プレイヤー名> <アイテム名> <数量>" description: "在庫を減らす" From 4b7fd7afa6cd738c6255e01c435ef26791afb76b Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 15:59:46 +0900 Subject: [PATCH 20/80] change(craft): distribution -> destination --- bundle/src/main/resources/en.yml | 2 +- bundle/src/main/resources/ja_JP.yml | 2 +- .../net/okocraft/box/feature/craft/lang/Displays.java | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index 51769622c9..66cd2c21c5 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -205,7 +205,7 @@ box: shift-click-to-show-details: "Shift click to show details" shift-click-to-show-recipes: "Shift click to show recipes" current-stock: "Current stocks: {0}" - distribution: + destination: display-name: "Destination" inventory: "Inventory" box: "Box" diff --git a/bundle/src/main/resources/ja_JP.yml b/bundle/src/main/resources/ja_JP.yml index c06f149d2c..e09dc1ee4b 100644 --- a/bundle/src/main/resources/ja_JP.yml +++ b/bundle/src/main/resources/ja_JP.yml @@ -205,7 +205,7 @@ box: shift-click-to-show-details: "シフトクリックで詳細を表示する" shift-click-to-show-recipes: "シフトクリックでレシピを表示する" current-stock: "現在の在庫: {0}" - distribution: + destination: display-name: "アイテムの収納先" inventory: "インベントリ" box: "Box" diff --git a/features/craft/src/main/java/net/okocraft/box/feature/craft/lang/Displays.java b/features/craft/src/main/java/net/okocraft/box/feature/craft/lang/Displays.java index 8d60460498..8eadbdd29c 100644 --- a/features/craft/src/main/java/net/okocraft/box/feature/craft/lang/Displays.java +++ b/features/craft/src/main/java/net/okocraft/box/feature/craft/lang/Displays.java @@ -60,18 +60,18 @@ public final class Displays { .build(); public static final Component DISTRIBUTION_BUTTON_DISPLAY_NAME = - translatable("box.craft.gui.buttons.distribution.display-name", NO_DECORATION_GOLD); + translatable("box.craft.gui.buttons.destination.display-name", NO_DECORATION_GOLD); public static final Component DISTRIBUTION_BUTTON_INVENTORY = - translatable("box.craft.gui.buttons.distribution.inventory", AQUA); + translatable("box.craft.gui.buttons.destination.inventory", AQUA); public static final Component DISTRIBUTION_BUTTON_BOX = - translatable("box.craft.gui.buttons.distribution.box", AQUA); + translatable("box.craft.gui.buttons.destination.box", AQUA); public static final SingleArgument DISTRIBUTION_CURRENT = current -> translatable() - .key("box.craft.gui.buttons.distribution.current") + .key("box.craft.gui.buttons.destination.current") .args(current ? DISTRIBUTION_BUTTON_INVENTORY : DISTRIBUTION_BUTTON_BOX) .style(NO_DECORATION_GRAY) .build(); @@ -79,7 +79,7 @@ public final class Displays { public static final SingleArgument DISTRIBUTION_CLICK_TO_CHANGE = current -> translatable() - .key("box.craft.gui.buttons.distribution.click-to-change") + .key("box.craft.gui.buttons.destination.click-to-change") .args(current ? DISTRIBUTION_BUTTON_BOX : DISTRIBUTION_BUTTON_INVENTORY) .style(NO_DECORATION_GRAY) .build(); From 60155cedd97f46048c1193f73981077df479eb16 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 16:09:02 +0900 Subject: [PATCH 21/80] feat(core): copy en.yml --- core/src/main/java/net/okocraft/box/core/BoxPlugin.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java index 6a6f5c804b..850d6b0813 100644 --- a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java +++ b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java @@ -293,6 +293,9 @@ public void accept(Supplier componentSupplier) { } private void saveDefaultLanguages(@NotNull Path directory) throws IOException { + var english = "en.yml"; + ResourceUtils.copyFromJar(jarFile, english, directory.resolve(english)); + var japanese = "ja_JP.yml"; ResourceUtils.copyFromJar(jarFile, japanese, directory.resolve(japanese)); } From 78271dc763af6352d597b73d9a45617fbe415c0e Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 16:09:19 +0900 Subject: [PATCH 22/80] change(core): change default locale to ENGLISH --- core/src/main/java/net/okocraft/box/core/BoxPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java index 850d6b0813..c49ed9eb9f 100644 --- a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java +++ b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java @@ -116,7 +116,7 @@ public boolean load() { getLogger().info("Loading languages..."); - translationDirectory.getRegistry().defaultLocale(Locale.JAPAN); + translationDirectory.getRegistry().defaultLocale(Locale.ENGLISH); try { translationDirectory.createDirectoryIfNotExists(this::saveDefaultLanguages); From 118155f5c4b0177df6aef55b3e5f0e087d64f0c3 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 16:21:49 +0900 Subject: [PATCH 23/80] build: update TranslationLoader to 1.1.1 --- core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index 5b2b554154..0a78b9cea9 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -22,7 +22,7 @@ com.github.siroshun09.translationloader translationloader - 1.1.0 + 1.1.1 compile From a81e2fa6478e2178f480a6f752e664d446f96e09 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 16:22:59 +0900 Subject: [PATCH 24/80] change(core): save default language files if not exists --- .../src/main/java/net/okocraft/box/core/BoxPlugin.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java index c49ed9eb9f..7b9f7b92e3 100644 --- a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java +++ b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java @@ -119,7 +119,8 @@ public boolean load() { translationDirectory.getRegistry().defaultLocale(Locale.ENGLISH); try { - translationDirectory.createDirectoryIfNotExists(this::saveDefaultLanguages); + translationDirectory.createDirectoryIfNotExists(); + saveDefaultLanguages(translationDirectory.getDirectory()); translationDirectory.load(); } catch (IOException e) { getLogger().log(Level.SEVERE, "Could not load languages", e); @@ -267,7 +268,8 @@ public void accept(Supplier componentSupplier) { } try { - translationDirectory.createDirectoryIfNotExists(this::saveDefaultLanguages); + translationDirectory.createDirectoryIfNotExists(); + saveDefaultLanguages(translationDirectory.getDirectory()); translationDirectory.load(); sender.sendMessage(MicsMessages.LANGUAGES_RELOADED); } catch (Throwable e) { @@ -294,10 +296,10 @@ public void accept(Supplier componentSupplier) { private void saveDefaultLanguages(@NotNull Path directory) throws IOException { var english = "en.yml"; - ResourceUtils.copyFromJar(jarFile, english, directory.resolve(english)); + ResourceUtils.copyFromJarIfNotExists(jarFile, english, directory.resolve(english)); var japanese = "ja_JP.yml"; - ResourceUtils.copyFromJar(jarFile, japanese, directory.resolve(japanese)); + ResourceUtils.copyFromJarIfNotExists(jarFile, japanese, directory.resolve(japanese)); } @Override From 64b6d4f536d27c1648a4472b9b29d95aecf70385 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 16:34:00 +0900 Subject: [PATCH 25/80] chore: add missing placeholder --- bundle/src/main/resources/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index 66cd2c21c5..d02109d4e8 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -29,7 +29,7 @@ box: gui: mode: display-name: "Auto-store setting" - lore: "Auto-store setting: " + lore: "Auto-store setting: {0}" setting-menu: title: "Auto-store setting menu" change-mode: From 230f006bf0abf5cbb6f577d0945f470abb07210b Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 16:37:51 +0900 Subject: [PATCH 26/80] chore: add periods --- bundle/src/main/resources/en.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index d02109d4e8..120ccefd1f 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -276,10 +276,10 @@ box: display-name: "Box Stick" lore-1: "Holding this in off hand will" lore-2: "consume items from Box when use them." - lore-3: "Also, right click to open the menu" + lore-3: "Also, right click to open the menu." command: - success: "You hold Box Stick in your off hand" - already-have: "You already have Box Stick in your off hand" + success: "You hold Box Stick in your off hand." + already-have: "You already have Box Stick in your off hand." could-not-give-stick: "Could not hold Box Stick in your off hand because your inventory is full." help: command-line: "/box stick" From 3f1aeb4d55aeaa18e6f32af246ff140970b17021 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 16:38:40 +0900 Subject: [PATCH 27/80] chore: improve box stick lore --- bundle/src/main/resources/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index 120ccefd1f..171df903a2 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -274,7 +274,7 @@ box: stick: item: display-name: "Box Stick" - lore-1: "Holding this in off hand will" + lore-1: "Holding this in off hand to" lore-2: "consume items from Box when use them." lore-3: "Also, right click to open the menu." command: From 3e1ea60fe8b06add52b95d51c5a58ac371611882 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 9 Oct 2021 17:12:28 +0900 Subject: [PATCH 28/80] fix: reset default locale when reloading --- core/src/main/java/net/okocraft/box/core/BoxPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java index 7b9f7b92e3..50006a4785 100644 --- a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java +++ b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java @@ -271,6 +271,7 @@ public void accept(Supplier componentSupplier) { translationDirectory.createDirectoryIfNotExists(); saveDefaultLanguages(translationDirectory.getDirectory()); translationDirectory.load(); + translationDirectory.getRegistry().defaultLocale(Locale.ENGLISH); sender.sendMessage(MicsMessages.LANGUAGES_RELOADED); } catch (Throwable e) { playerMessenger.accept(() -> ErrorMessages.ERROR_RELOAD_FAILURE.apply("languages", e)); From 7ba6b3d5c80b48071bf61cd9ecb21fd00f71f63f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Oct 2021 11:35:15 +0000 Subject: [PATCH 29/80] build(deps): bump configapi-yaml from 4.5.0-SNAPSHOT to 4.5.0 Bumps [configapi-yaml](https://github.com/Siroshun09/ConfigAPI) from 4.5.0-SNAPSHOT to 4.5.0. - [Release notes](https://github.com/Siroshun09/ConfigAPI/releases) - [Commits](https://github.com/Siroshun09/ConfigAPI/commits/4.5.0) --- updated-dependencies: - dependency-name: com.github.siroshun09.configapi:configapi-yaml dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index 343ab84dad..a24b10ab25 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -16,7 +16,7 @@ com.github.siroshun09.configapi configapi-yaml - 4.5.0-SNAPSHOT + 4.5.0 compile From c934a5e264f7b910d380cf04caede39969354d6e Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sun, 10 Oct 2021 07:06:17 +0900 Subject: [PATCH 30/80] chore: improve jp messages --- bundle/src/main/resources/ja_JP.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundle/src/main/resources/ja_JP.yml b/bundle/src/main/resources/ja_JP.yml index e09dc1ee4b..1ac733919f 100644 --- a/bundle/src/main/resources/ja_JP.yml +++ b/bundle/src/main/resources/ja_JP.yml @@ -134,7 +134,7 @@ box: description: "Box の管理者用コマンド" give: success: - sender: "プレイヤー {0} のアイテム {1} の在庫を {2} 個増やされました (現在 {3} 個)。" + sender: "プレイヤー {0} のアイテム {1} の在庫を {2} 個増やしました (現在 {3} 個)。" target: "{0} にアイテム {1} の在庫を {2} 個増やされました (現在 {3} 個)。" help: command-line: "/boxadmin give <プレイヤー名> <アイテム名> <数量>" @@ -147,14 +147,14 @@ box: toggle-target: "{0} に無限在庫モードを {1} にされました。" tip: "無限在庫モードでは収納されるアイテム情報が保存されません。" help: - command-line: "/boxadmin infinity" + command-line: "/boxadmin infinity [プレイヤー名]" description: "無限在庫モードにする" register: is-air: "手に何も持っていません。" already-registered: "アイテム {0} はすでに登録されています。" success: "アイテム {0} を名前 {1} として新しく登録しました。" failure: "アイテムの登録に失敗しました。エラーメッセージ: {0}" - tip-rename: "登録したアイテムは /boxadmin rename で改名できます。" + tip-rename: "登録したアイテムは /boxadmin rename で改名できます。" help: command-line: "/boxadmin register" description: "手に持っているアイテムを Box に登録する" From 88872f586dd180fc4cdb46e049f60da88c5bb43c Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sun, 10 Oct 2021 07:06:22 +0900 Subject: [PATCH 31/80] chore: improve translations --- bundle/src/main/resources/en.yml | 132 +++++++++++++++---------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index 171df903a2..1cb8c7dfa3 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -12,18 +12,18 @@ box: help: toggle: command-line: "/box autostore [on/off]" - description: "Turn auto-store on/off" + description: "Switches on/off auto-store" all: command-line: "/box autostore [all/item]" - description: "Change auto-store mode" + description: "Changes auto-store mode" item: command-line: "/box autostore item [on/off]" - description: "Change the auto-store setting for the item" + description: "Changes the auto-store setting of the item" autostore-toggled: "Auto-store is now {0}." mode-changed: "Auto-store mode is now {0}." item: - all-toggled: "Set the auto-store setting for all items to {0}." - item-toggled: "Set the auto-store setting for item {0} to {1}." + all-toggled: "Set the auto-store setting of all items to {0}." + item-toggled: "Set the auto-store setting of the item {0} to {1}." mode-not-found: "Auto-store mode {0} is not found." not-boolean: "{0} is not boolean. [on/off/true/false]" gui: @@ -39,8 +39,8 @@ box: toggle-button: "Click to set auto-store to {0}" bulk-editing: title: "Bulk change operation for per-item mode" - left-click: "Left click to set all items to {0}" - right-click: "Right click to set all items to {0}" + left-click: "Press LMB to set all items to {0}" + right-click: "Press RMB to set all items to {0}" recent: "Recent bulk change operation: {0}" category: reloaded: "The category feature has been reloaded." @@ -87,47 +87,47 @@ box: deposit: success: "Deposited {0}x{1} (Now {2})" all-success: "Deposited {0} items in your inventory that can be deposited." - is-air: "You don't have no item in your main hand." - item-not-registered: "The item in your main hand is not registered in Box." - not-deposited: "The specified item was not found in your inventory." - not-found: "No items could be deposited in the inventory." + is-air: "You have no item in your main hand." + item-not-registered: "The item in your main hand is not registered." + not-deposited: "The specified item is not present in your inventory." + not-found: "No items could be deposited in your inventory." help: main-hand: command-line: "/box deposit [amount]" - description: "Deposit the item in your main hand" + description: "Deposits the item in your main hand" all: command-line: "/box deposit all" - description: "Deposit all items" + description: "Deposits all items" item: command-line: "/box deposit [amount]" - description: "Deposit specified item" + description: "Deposits specified item" give: success: - sender: "Send {1}x{2} to player {0} (Now {3})." - target: "Receive {1}x{2} from player {0} (Now {3})." - no-stock: "There are no items {0} in stock." + sender: "Sent {1}x{2} to player {0} (Now {3})." + target: "Received {1}x{2} from player {0} (Now {3})." + no-stock: "Item {0} is out of stock." self: "You can't send it to yourself." target-no-permission: "Player {0} doesn't have the permission {1}." target-is-in-disabled-world: "Player {0} is in world {1} where Box is not available." help: command-line: "/box give [amount]" - description: "Send items to other" + description: "Sends items to others" withdraw: success: "Withdrew {0}x{1} (Now {2})." - stop: "Withdrawal ended because there is no more space in your inventory." - no-stock: "There are not items {0} in stock." - inventory-is-full: "There is not space in your inventory." + stop: "Withdrawal was cancelled because your inventory has no space." + no-stock: "Item {0} is out of stock." + inventory-is-full: "Your inventory is full." help: command-line: "/box withdraw [amount]" - description: "Withdraw item" + description: "Withdraws item" iteminfo: - is-air: "You don't have no item in your main hand." - item-not-registered: "The item in your main hand is not registered in Box." + is-air: "You have no item in your main hand." + item-not-registered: "The item in your main hand is not registered." name: "Item Name: {0}" stock: "Current stocks: {0}" help: command-line: "/box iteminfo [item]" - description: "Show information about the item you have or specify." + description: "Shows information about the item you have or specify." boxadmin: help: command-line: "/boxadmin " @@ -138,54 +138,54 @@ box: target: "{0} give you {1}x{2} (Now {3})." help: command-line: "/boxadmin give " - description: "Increase stocks" + description: "Increases stocks" infinity: enabled: "Enabled" disabled: "Disabled" toggle: "Infinite stock mode has been {0}." toggle-sender: "{1} infinite stock mode for player {0}." toggle-target: "Infinite stock mode has been {1} by {0}." - tip: "Infinite stock mode does not save deposited items." + tip: "Infinite stock mode does not save deposited items' data." help: - command-line: "/boxadmin infinity" - description: "Toggle infinite stock mode" + command-line: "/boxadmin infinity [player]" + description: "Toggles infinite stock mode" register: - is-air: "You don't have no item in your main hand." + is-air: "You have no item in your main hand." already-registered: "{0} is already registered." success: "{0} has been registered as name {1}." - failure: "Failed to register an item. Error message: {0}" - tip-rename: "Registered items can be renamed with /boxadmin rename ." + failure: "Failed to register the item. Error message: {0}" + tip-rename: "Registered items can be renamed with /boxadmin rename ." help: command-line: "/boxadmin register" - description: "Register item in main hand to Box" + description: "Registers item in main hand to Box" reload: start: "Reloading Box..." - finish: "Reloading Box is complete." + finish: "Box has been reloaded!" help: command-line: "/boxadmin reload" - description: "Reload Box" + description: "Reloads Box" rename: is-not-custom-item: "The name of item {0} cannot be renamed." already-used-name: "The item name {0} is already used." - success: "The item name has been renamed to {0}." + success: "The item has been renamed to {0}." failure: "Failed to rename the item name. Error message: {0}" help: command-line: "/boxadmin rename " - description: "Change item name" + description: "Changes item name" set: success: sender: "Player {0}'s item {1} has been set to {2}." target: "Item {1} has been set to {2} by {0}." help: command-line: "/boxadmin set " - description: "Set stocks" + description: "Sets stocks" take: success: sender: "Took {1}x{2} from player {0} (Now {3})." target: "{0} took {1}x{2} (Now {3})." help: command-line: "/boxadmin take " - description: "Decrease stocks" + description: "Decreases stocks" version: info: "Box {0}" help: @@ -197,13 +197,13 @@ box: recipe-reloaded: "Item recipes have been reloaded." help: command-line: "/box craft " - description: "Show the item recipe" + description: "Shows the item recipe" gui: buttons: display-name: "{0} crafts" ingredients: "Ingredients" - shift-click-to-show-details: "Shift click to show details" - shift-click-to-show-recipes: "Shift click to show recipes" + shift-click-to-show-details: "Shift + click to show details" + shift-click-to-show-recipes: "Shift + click to show recipes" current-stock: "Current stocks: {0}" destination: display-name: "Destination" @@ -213,7 +213,7 @@ box: click-to-change: "Click to change to {0}" change-unit: display-name: "Change unit" - shift-click-to-reset-times: "Shift click to reset craft times" + shift-click-to-reset-times: "Shift + click to reset craft times" change-times: current: "Current craft times: {0}" increase: @@ -227,31 +227,31 @@ box: bulk: "Bulk ingredient change" each: "Partial ingredient change" menus: - craft: "Crafting of {0}" + craft: "Craft of {0}" recipe-selector: "Recipes of {0}" mode: - display-name: "Crafting mode" + display-name: "Craft mode" click-to-show-recipes: "Click to show recipes" recipe-not-found: "There is no recipe" gui: reloaded: "GUI feature has been reloaded." - error-occurred: "An error occurred while click processing. Error message: {0}" + error-occurred: "An error occurred while click process. Error message: {0}" command-help: command-line: "/box gui" - description: "Open Box menu" + description: "Opens Box menu" buttons: back: "Back" change-unit: - display-name: "Change unit" - shift-click-to-reset-amount: "Shift click to reset transaction amount" + display-name: "Change the unit" + shift-click-to-reset-amount: "Shift + click to reset the transaction amount" change-transaction-amount: current: "Current transaction amount: {0}" decrease: display-name: "Decrease" - lore: "Click to decrease transaction amount by {0}" + lore: "Click to decrease the transaction amount by {0}" increase: display-name: "Increase" - lore: "Click to increase transaction amount by {0}" + lore: "Click to increase the transaction amount by {0}" set-to-unit: "Click to set transaction amount to {0}" close: "Close" page-switch: @@ -264,33 +264,33 @@ box: modes: storage-mode: display-name: "Storage mode" - left-click-to-deposit: "Left click to deposit {0} items" - right-click-to-withdraw: "Right click to withdraw {0} items" + left-click-to-deposit: "Press LMB to deposit {0} items" + right-click-to-withdraw: "Press RMB to withdraw {0} items" current-stock: "Current stocks: {0}" deposit-all: - display-name: "Deposit all items" - lore-1: "Shift click to deposit" + display-name: "Deposits all items" + lore-1: "Shift + click to deposit" lore-2: "all items in the inventory" stick: item: display-name: "Box Stick" lore-1: "Holding this in off hand to" lore-2: "consume items from Box when use them." - lore-3: "Also, right click to open the menu." + lore-3: "Also, press RMB to open the menu." command: - success: "You hold Box Stick in your off hand." + success: "Gave your off hand Box Stick." already-have: "You already have Box Stick in your off hand." - could-not-give-stick: "Could not hold Box Stick in your off hand because your inventory is full." + could-not-give-stick: "Could not give your off hand Box Stick because your inventory is full." help: command-line: "/box stick" - description: "Hold Box Stick in off hand" + description: "Gives your off hand Box Stick" customstick: success: "The item in your hand can now be used as Box Stick." already: "The item in your hand can already be used as Box Stick." - is-air: "You don't have no item in your main hand." + is-air: "You have no item in your main hand." help: command-line: "/boxadmin customstick" - description: "Make item in main hand a Box Stick" + description: "Makes item in main hand a Box Stick" error: disabled-world: "Box cannot be used in world {0}." failed-to-reload-feature: "Failed to reload {0}. Error message: {1}" @@ -300,13 +300,13 @@ box: load-on-join: "Failed to load the stock data. Please contact the administrator." save: "Failed to save the stock data. Please contact the administrator." command: - only-player: "This command only execute by the player in game." + only-player: "This command can only be executed by the player in game." no-argument: "There is no argument." not-enough-argument: "The arguments is not enough." - subcommand-not-found: "The specified subcommand was not found." - player-not-found: "The player {0} was not found." - item-not-found: "The item {0} was not found." - invalid-number: "{0} is not valid number." + subcommand-not-found: "Box could not recognize the specified subcommand." + player-not-found: "The player {0} could not be found." + item-not-found: "The item {0} could not be found." + invalid-number: "{0} is not a valid number." mics: config-reloaded: "config.yml has been reloaded." languages-reloaded: "Language files have been reloaded." From 2b1adc1c53d13143b925c1eb457d9a87ca7b25b2 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sun, 10 Oct 2021 14:54:38 +0900 Subject: [PATCH 32/80] feat: add more logging --- .../net/okocraft/box/bundle/BoxBootstrap.java | 29 +++++++++++++++---- .../java/net/okocraft/box/core/BoxPlugin.java | 24 +++++++-------- .../okocraft/box/core/storage/Storage.java | 2 ++ .../implementations/yaml/YamlStorage.java | 5 ++++ 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/bundle/src/main/java/net/okocraft/box/bundle/BoxBootstrap.java b/bundle/src/main/java/net/okocraft/box/bundle/BoxBootstrap.java index ed8ab6d9a9..d48a870307 100644 --- a/bundle/src/main/java/net/okocraft/box/bundle/BoxBootstrap.java +++ b/bundle/src/main/java/net/okocraft/box/bundle/BoxBootstrap.java @@ -4,6 +4,9 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; +import java.time.Duration; +import java.time.Instant; + public final class BoxBootstrap extends JavaPlugin { private BoxPlugin boxPlugin; @@ -16,7 +19,7 @@ public BoxBootstrap() { isPaper = true; } catch (NoSuchMethodException e) { getLogger().severe("Box only supports Paper or its fork."); - getLogger().severe("Please change your spigot server to Paper to use Box."); + getLogger().severe("Please change your Spigot server to Paper to use Box."); isPaper = false; return; } @@ -35,19 +38,30 @@ public void onLoad() { public void onEnable() { if (!isPaper) { getLogger().severe("Box only supports Paper or its fork."); - getLogger().severe("Please change your spigot server to Paper to use Box."); + getLogger().severe("Please change your Spigot server to Paper to use Box."); getLogger().severe(""); getLogger().severe("Disabling box..."); - getServer().getPluginManager().disablePlugin(this); + disablePlugin(); return; } - if (!isLoaded || !boxPlugin.enable()) { - getServer().getPluginManager().disablePlugin(this); + if (!isLoaded) { + disablePlugin(); // An exception occurred while loading Box. + return; + } + + var startTime = Instant.now(); + + if (!boxPlugin.enable()) { + disablePlugin(); + return; } Bundled.FEATURES.forEach(boxPlugin::register); + + var timeTaken = Duration.between(startTime, Instant.now()); + getLogger().info("Successfully enabled! (" + timeTaken.toMillis() + "ms)"); } @Override @@ -55,6 +69,11 @@ public void onDisable() { if (isPaper && isLoaded) { Bundled.FEATURES.forEach(boxPlugin::unregister); boxPlugin.disable(); + getLogger().info("Successfully disabled. Goodbye!"); } } + + private void disablePlugin() { + getServer().getPluginManager().disablePlugin(this); + } } diff --git a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java index 50006a4785..4422b73ffa 100644 --- a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java +++ b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java @@ -140,10 +140,12 @@ public boolean load() { public boolean enable() { storage = new YamlStorage(getPluginDirectory().resolve("data")); // TODO: SQLite, MySQL, or something else... + getLogger().info("Initializing " + storage.getName() + " storage..."); + try { storage.init(); } catch (Exception e) { - getLogger().log(Level.SEVERE, "Could not initialize a storage", e); + getLogger().log(Level.SEVERE, "Could not initialize" + storage.getName() + "storage", e); return false; } @@ -194,8 +196,6 @@ public boolean enable() { Bukkit.getPluginManager().registerEvents(boxCommand, plugin); Bukkit.getPluginManager().registerEvents(boxAdminCommand, plugin); - getLogger().info("Successfully enabled!"); - return true; } @@ -203,8 +203,10 @@ public void disable() { getLogger().info("Unregistering all listeners..."); HandlerList.unregisterAll(getPluginInstance()); - getLogger().info("Disabling features..."); - List.copyOf(features).forEach(this::unregister); + if (!features.isEmpty()) { + getLogger().info("Disabling features..."); + List.copyOf(features).forEach(this::unregister); + } stockHolderListener.unregister(); autoSaveTask.stop(); @@ -233,8 +235,6 @@ public void disable() { getLogger().info("Unloading translations..."); translationDirectory.unload(); - - getLogger().info("Successfully disabled!"); } @Override @@ -386,7 +386,7 @@ private void saveDefaultLanguages(@NotNull Path directory) throws IOException { @Override public void register(@NotNull BoxFeature boxFeature) { if (configuration.get(Settings.DISABLED_FEATURES).contains(boxFeature.getName())) { - getLogger().warning("Feature " + boxFeature.getName() + " is disabled by disabled-features in config.yml"); + getLogger().warning("The " + boxFeature.getName() + " feature is disabled in config.yml"); return; } @@ -395,7 +395,7 @@ public void register(@NotNull BoxFeature boxFeature) { } catch (Throwable throwable) { getLogger().log( Level.SEVERE, - "Could not enable the feature: " + boxFeature.getName(), + "Could not enable the " + boxFeature.getName() + " feature", throwable ); boxFeature.disable(); @@ -406,12 +406,12 @@ public void register(@NotNull BoxFeature boxFeature) { eventBus.callEvent(new FeatureEvent(boxFeature, FeatureEvent.Type.REGISTER)); - getLogger().info("Feature " + boxFeature.getName() + " has been enabled."); + getLogger().info("The " + boxFeature.getName() + " feature has been enabled."); } @Override public void unregister(@NotNull BoxFeature boxFeature) { - getLogger().info("Disabling feature " + boxFeature.getName() + "..."); + getLogger().info("Disabling the " + boxFeature.getName() + " feature..."); features.remove(boxFeature); try { @@ -419,7 +419,7 @@ public void unregister(@NotNull BoxFeature boxFeature) { } catch (Throwable throwable) { getLogger().log( Level.SEVERE, - "Could not disable the feature: " + boxFeature.getName(), + "Could not disable the " + boxFeature.getName() + " feature", throwable ); } diff --git a/core/src/main/java/net/okocraft/box/core/storage/Storage.java b/core/src/main/java/net/okocraft/box/core/storage/Storage.java index 78b0b4253c..017ce6986d 100644 --- a/core/src/main/java/net/okocraft/box/core/storage/Storage.java +++ b/core/src/main/java/net/okocraft/box/core/storage/Storage.java @@ -8,6 +8,8 @@ public interface Storage { + @NotNull String getName(); + void init() throws Exception; void close() throws Exception; diff --git a/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlStorage.java b/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlStorage.java index dd8cc6e8f6..0feea9e9e1 100644 --- a/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlStorage.java +++ b/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlStorage.java @@ -25,6 +25,11 @@ public YamlStorage(@NotNull Path rootDirectory) { this.customDataStorage = new YamlCustomDataStorage(rootDirectory); } + @Override + public @NotNull String getName() { + return "Yaml"; + } + @Override public void init() throws Exception { Files.createDirectories(rootDirectory); From bdef0431cec12c8c44ae3235a653c9a57285bcd1 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sun, 10 Oct 2021 15:08:09 +0900 Subject: [PATCH 33/80] improve(core): use try-with-resources --- .../implementations/yaml/YamlItemStorage.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlItemStorage.java b/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlItemStorage.java index e1195656c7..21543bb903 100644 --- a/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlItemStorage.java +++ b/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlItemStorage.java @@ -106,28 +106,28 @@ protected int getDefaultItemId(@NotNull String name) { @Override protected void saveVersionedItem(@NotNull String version, @NotNull BoxItem item) throws Exception { - var file = YamlConfiguration.create(itemDirectory.resolve(version + ".yml")); - - if (Files.exists(file.getPath())) { - file.load(); - } + try (var file = YamlConfiguration.create(itemDirectory.resolve(version + ".yml"))) { + if (Files.exists(file.getPath())) { + file.load(); + } - file.set(item.getInternalId() + ".name", item.getPlainName()); - file.setBytes(item.getInternalId() + ".data", item.getOriginal().serializeAsBytes()); + file.set(item.getInternalId() + ".name", item.getPlainName()); + file.setBytes(item.getInternalId() + ".data", item.getOriginal().serializeAsBytes()); - file.save(); + file.save(); + } } @Override protected void saveVersionedItems(@NotNull String version, @NotNull Collection items) throws Exception { - var file = YamlConfiguration.create(itemDirectory.resolve(version + ".yml")); + try (var file = YamlConfiguration.create(itemDirectory.resolve(version + ".yml"))) { + for (var item : items) { + file.set(item.getInternalId() + ".name", item.getPlainName()); + file.setBytes(item.getInternalId() + ".data", item.getOriginal().serializeAsBytes()); + } - for (var item : items) { - file.set(item.getInternalId() + ".name", item.getPlainName()); - file.setBytes(item.getInternalId() + ".data", item.getOriginal().serializeAsBytes()); + file.save(); } - - file.save(); } @Override From 2c1304ed4b4b6fdd43a3cbc49047ab57704ef765 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sun, 10 Oct 2021 15:11:02 +0900 Subject: [PATCH 34/80] change(api): isUsed -> isUsedName --- .../box/api/model/manager/ItemManager.java | 16 +++++++++++++++- .../box/core/model/manager/BoxItemManager.java | 2 +- .../feature/command/boxadmin/RenameCommand.java | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/net/okocraft/box/api/model/manager/ItemManager.java b/api/src/main/java/net/okocraft/box/api/model/manager/ItemManager.java index 23e21d4c70..9bf16e53b9 100644 --- a/api/src/main/java/net/okocraft/box/api/model/manager/ItemManager.java +++ b/api/src/main/java/net/okocraft/box/api/model/manager/ItemManager.java @@ -3,6 +3,7 @@ import net.okocraft.box.api.model.item.BoxCustomItem; import net.okocraft.box.api.model.item.BoxItem; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; @@ -54,7 +55,20 @@ public interface ItemManager { * @param name the name to check * @return {@code true} if used, {@code false} otherwise */ - boolean isUsed(@NotNull String name); + boolean isUsedName(@NotNull String name); + + /** + * Checks if the specified name has already been used. + * + * @param name the name to check + * @return {@code true} if used, {@code false} otherwise + * @deprecated use {@link #isUsedName(String)} + */ + @Deprecated(forRemoval = true) + @ApiStatus.ScheduledForRemoval(inVersion = "4.2.0") + default boolean isUsed(@NotNull String name) { + return isUsedName(name); + } /** * Checks if the specified item is a custom item created by box itself. diff --git a/core/src/main/java/net/okocraft/box/core/model/manager/BoxItemManager.java b/core/src/main/java/net/okocraft/box/core/model/manager/BoxItemManager.java index b871960947..9a6fbed82e 100644 --- a/core/src/main/java/net/okocraft/box/core/model/manager/BoxItemManager.java +++ b/core/src/main/java/net/okocraft/box/core/model/manager/BoxItemManager.java @@ -81,7 +81,7 @@ public boolean isRegistered(@NotNull ItemStack itemStack) { } @Override - public boolean isUsed(@NotNull String name) { + public boolean isUsedName(@NotNull String name) { Objects.requireNonNull(name); var nameSet = itemNameCache; diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/RenameCommand.java b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/RenameCommand.java index 16e8faf1ef..ce07465a4a 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/RenameCommand.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/RenameCommand.java @@ -47,7 +47,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { var newName = args[2].toUpperCase(Locale.ROOT); - if (itemManager.isUsed(newName)) { + if (itemManager.isUsedName(newName)) { sender.sendMessage(BoxAdminMessage.RENAME_ALREADY_USED_NAME.apply(newName)); return; } From 29e734ea60b0aa3a2a8383c2e8a9c8e8da001fc2 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sun, 10 Oct 2021 15:14:36 +0900 Subject: [PATCH 35/80] fix(core): add spaces --- core/src/main/java/net/okocraft/box/core/BoxPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java index 4422b73ffa..25e8a95bfc 100644 --- a/core/src/main/java/net/okocraft/box/core/BoxPlugin.java +++ b/core/src/main/java/net/okocraft/box/core/BoxPlugin.java @@ -145,7 +145,7 @@ public boolean enable() { try { storage.init(); } catch (Exception e) { - getLogger().log(Level.SEVERE, "Could not initialize" + storage.getName() + "storage", e); + getLogger().log(Level.SEVERE, "Could not initialize " + storage.getName() + " storage", e); return false; } From c4f3d0b885a9786fed7fd521b6c230c9d053d63a Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:05:52 +0900 Subject: [PATCH 36/80] improve(core): dequeue stockholder when player unloaded --- .../box/core/listener/StockHolderListener.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java b/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java index 22f8dbc300..14b1c08d4c 100644 --- a/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java +++ b/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java @@ -3,6 +3,7 @@ import com.github.siroshun09.event4j.handlerlist.Key; import net.okocraft.box.api.BoxProvider; import net.okocraft.box.api.event.general.AutoSaveStartEvent; +import net.okocraft.box.api.event.player.PlayerUnloadEvent; import net.okocraft.box.api.event.stock.StockDecreaseEvent; import net.okocraft.box.api.event.stock.StockEvent; import net.okocraft.box.api.event.stock.StockIncreaseEvent; @@ -27,9 +28,11 @@ public class StockHolderListener { public void register() { var eventBus = BoxProvider.get().getEventBus(); - eventBus.getHandlerList(StockSetEvent.class).subscribe(listenerKey, this::queueStockHolder); - eventBus.getHandlerList(StockIncreaseEvent.class).subscribe(listenerKey, this::queueStockHolder); - eventBus.getHandlerList(StockDecreaseEvent.class).subscribe(listenerKey, this::queueStockHolder); + eventBus.getHandlerList(StockSetEvent.class).subscribe(listenerKey, this::enqueueStockHolder); + eventBus.getHandlerList(StockIncreaseEvent.class).subscribe(listenerKey, this::enqueueStockHolder); + eventBus.getHandlerList(StockDecreaseEvent.class).subscribe(listenerKey, this::enqueueStockHolder); + + eventBus.getHandlerList(PlayerUnloadEvent.class).subscribe(listenerKey, this::dequeueStockHolder); eventBus.getHandlerList(AutoSaveStartEvent.class).subscribe(listenerKey, this::saveModifiedStockHolders); } @@ -38,7 +41,7 @@ public void unregister() { BoxProvider.get().getEventBus().unsubscribeAll(listenerKey); } - private void queueStockHolder(@NotNull StockEvent event) { + private void enqueueStockHolder(@NotNull StockEvent event) { if (event.isUserStockHolder()) { var userStockHolder = event.getUserStockHolder(); @@ -48,6 +51,10 @@ private void queueStockHolder(@NotNull StockEvent event) { } } + private void dequeueStockHolder(@NotNull PlayerUnloadEvent event) { + modifiedStockHolders.remove(event.getBoxPlayer().getUserStockHolder()); + } + private void saveModifiedStockHolders(@NotNull AutoSaveStartEvent task) { if (modifiedStockHolders.isEmpty()) { return; @@ -57,7 +64,7 @@ private void saveModifiedStockHolders(@NotNull AutoSaveStartEvent task) { modifiedStockHolders.clear(); - copied.stream().filter(UserStockHolder::isOnline).forEach(this::save); + copied.forEach(this::save); } private void save(@NotNull UserStockHolder userStockHolder) { From 84afb0c2aaf4afd389c031abed12ec07582d484d Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:07:05 +0900 Subject: [PATCH 37/80] change(api): deprecate UserStockHolder#isOnline --- .../java/net/okocraft/box/api/model/stock/UserStockHolder.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/src/main/java/net/okocraft/box/api/model/stock/UserStockHolder.java b/api/src/main/java/net/okocraft/box/api/model/stock/UserStockHolder.java index 5a4e8b4f3d..d66f239440 100644 --- a/api/src/main/java/net/okocraft/box/api/model/stock/UserStockHolder.java +++ b/api/src/main/java/net/okocraft/box/api/model/stock/UserStockHolder.java @@ -1,6 +1,7 @@ package net.okocraft.box.api.model.stock; import net.okocraft.box.api.model.user.BoxUser; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; /** @@ -22,5 +23,7 @@ public interface UserStockHolder extends StockHolder { * * @return whether the owner of this holder is online or not */ + @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "4.2.0") boolean isOnline(); } From 38b4acb01f6e693815cd8c285ab0f3fa5690c3a3 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:31:38 +0900 Subject: [PATCH 38/80] docs(api): fix the wrong link --- .../main/java/net/okocraft/box/api/event/stock/StockEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java b/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java index ffc84fa4b7..2f6a1785fe 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java @@ -54,7 +54,7 @@ public boolean isUserStockHolder() { * before calling this method. * * @return the {@link UserStockHolder} - * @throws IllegalStateException if the {@link StockEvent} of this event is not {@link UserStockHolder} + * @throws IllegalStateException if the {@link StockHolder} of this event is not {@link UserStockHolder} */ public @NotNull UserStockHolder getUserStockHolder() { if (stockHolder instanceof UserStockHolder userStockHolder) { From 1543f5be94b4c639214190516de09101f727a991 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 16:02:07 +0900 Subject: [PATCH 39/80] fix(api): add forRemoval = true --- .../java/net/okocraft/box/api/model/stock/UserStockHolder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/net/okocraft/box/api/model/stock/UserStockHolder.java b/api/src/main/java/net/okocraft/box/api/model/stock/UserStockHolder.java index d66f239440..c067a2d3fe 100644 --- a/api/src/main/java/net/okocraft/box/api/model/stock/UserStockHolder.java +++ b/api/src/main/java/net/okocraft/box/api/model/stock/UserStockHolder.java @@ -23,7 +23,7 @@ public interface UserStockHolder extends StockHolder { * * @return whether the owner of this holder is online or not */ - @Deprecated + @Deprecated(forRemoval = true) @ApiStatus.ScheduledForRemoval(inVersion = "4.2.0") boolean isOnline(); } From 92fa0f9508e1b2caeef23980a6bc08b9eb42aeb8 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:42:57 +0900 Subject: [PATCH 40/80] feat(api): creates StockHolderEvent --- .../event/stockholder/StockHolderEvent.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderEvent.java diff --git a/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderEvent.java b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderEvent.java new file mode 100644 index 0000000000..bb34eb0d95 --- /dev/null +++ b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderEvent.java @@ -0,0 +1,61 @@ +package net.okocraft.box.api.event.stockholder; + +import net.okocraft.box.api.event.BoxEvent; +import net.okocraft.box.api.model.stock.StockHolder; +import net.okocraft.box.api.model.stock.UserStockHolder; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +/** + * A class that represents a {@link StockHolder} related event. + */ +public class StockHolderEvent extends BoxEvent { + + private final StockHolder stockHolder; + + /** + * The constructor of {@link StockHolderEvent}. + * + * @param stockHolder the stockholder of the event + */ + public StockHolderEvent(@NotNull StockHolder stockHolder) { + this.stockHolder = Objects.requireNonNull(stockHolder); + } + + /** + * Gets the stockholder. + * + * @return the stockholder + */ + public @NotNull StockHolder getStockHolder() { + return stockHolder; + } + + /** + * Checks if the {@link StockHolder} of this event is a {@link UserStockHolder}. + * + * @return whether the {@link StockHolder} is a {@link UserStockHolder} or not + */ + public boolean isUserStockHolder() { + return stockHolder instanceof UserStockHolder; + } + + /** + * Gets the {@link StockHolder} as a {@link UserStockHolder}. + *

+ * You must check if the {@link StockHolder} of this event + * is {@link UserStockHolder} using {@link #isUserStockHolder()} + * before calling this method. + * + * @return the {@link UserStockHolder} + * @throws IllegalStateException if the {@link StockHolder} of this event is not {@link UserStockHolder} + */ + public @NotNull UserStockHolder getUserStockHolder() { + if (stockHolder instanceof UserStockHolder userStockHolder) { + return userStockHolder; + } else { + throw new IllegalStateException("The StockHolder of this event is not UserStockHolder."); + } + } +} From 518109e8361da0cecfbc5b49897e819ef4276d13 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:43:39 +0900 Subject: [PATCH 41/80] feat(api): add loading / saving stockholder event --- .../stockholder/StockHolderLoadEvent.java | 19 +++++++++++++++++++ .../stockholder/StockHolderSaveEvent.java | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderLoadEvent.java create mode 100644 api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java diff --git a/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderLoadEvent.java b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderLoadEvent.java new file mode 100644 index 0000000000..89056fdfa6 --- /dev/null +++ b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderLoadEvent.java @@ -0,0 +1,19 @@ +package net.okocraft.box.api.event.stockholder; + +import net.okocraft.box.api.model.stock.StockHolder; +import org.jetbrains.annotations.NotNull; + +/** + * A {@link StockHolderEvent} called when the stockholder is loaded. + */ +public class StockHolderLoadEvent extends StockHolderEvent { + + /** + * The constructor of {@link StockHolderLoadEvent}. + * + * @param stockHolder the loaded stockholder + */ + public StockHolderLoadEvent(@NotNull StockHolder stockHolder) { + super(stockHolder); + } +} diff --git a/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java new file mode 100644 index 0000000000..e91b028de0 --- /dev/null +++ b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java @@ -0,0 +1,19 @@ +package net.okocraft.box.api.event.stockholder; + +import net.okocraft.box.api.model.stock.StockHolder; +import org.jetbrains.annotations.NotNull; + +/** + * A {@link StockHolderEvent} called when the stockholder is saved. + */ +public class StockHolderSaveEvent extends StockHolderEvent { + + /** + * The constructor of {@link StockHolderSaveEvent}. + * + * @param stockHolder the saved stockholder + */ + public StockHolderSaveEvent(@NotNull StockHolder stockHolder) { + super(stockHolder); + } +} From cc176cd56b10f360c2097f0bb767b15fa6e4dc30 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:47:51 +0900 Subject: [PATCH 42/80] change(core): call StockHolderSaveEvent on BoxStockManager#saveUserStock --- .../net/okocraft/box/core/listener/StockHolderListener.java | 2 -- .../net/okocraft/box/core/model/manager/BoxStockManager.java | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java b/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java index 14b1c08d4c..93fbe29720 100644 --- a/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java +++ b/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java @@ -7,7 +7,6 @@ import net.okocraft.box.api.event.stock.StockDecreaseEvent; import net.okocraft.box.api.event.stock.StockEvent; import net.okocraft.box.api.event.stock.StockIncreaseEvent; -import net.okocraft.box.api.event.stock.StockSaveEvent; import net.okocraft.box.api.event.stock.StockSetEvent; import net.okocraft.box.api.model.stock.UserStockHolder; import net.okocraft.box.api.model.user.BoxUser; @@ -70,7 +69,6 @@ private void saveModifiedStockHolders(@NotNull AutoSaveStartEvent task) { private void save(@NotNull UserStockHolder userStockHolder) { try { BoxProvider.get().getStockManager().saveUserStock(userStockHolder).join(); - BoxProvider.get().getEventBus().callEvent(new StockSaveEvent(userStockHolder)); } catch (Exception e) { Optional.of(userStockHolder.getUser()) .map(BoxUser::getUUID) diff --git a/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java b/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java index 85925182b4..36a2f3ec29 100644 --- a/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java +++ b/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java @@ -1,5 +1,7 @@ package net.okocraft.box.core.model.manager; +import net.okocraft.box.api.BoxProvider; +import net.okocraft.box.api.event.stockholder.StockHolderSaveEvent; import net.okocraft.box.api.model.manager.StockManager; import net.okocraft.box.api.model.stock.UserStockHolder; import net.okocraft.box.api.model.user.BoxUser; @@ -41,6 +43,7 @@ public BoxStockManager(@NotNull StockStorage stockStorage) { return CompletableFuture.runAsync(() -> { try { stockStorage.saveUserStockHolder(stockHolder); + BoxProvider.get().getEventBus().callEvent(new StockHolderSaveEvent(stockHolder)); } catch (Exception e) { throw new RuntimeException("Could not save user stock holder (" + stockHolder.getUser().getUUID() + ")", e); } From 8f05a073a6e68616d4801356b548c0ce4087052d Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:48:13 +0900 Subject: [PATCH 43/80] change(core): change StockSaveEvent to StockHolderSaveEvent --- .../java/net/okocraft/box/core/listener/DebugListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java index a619c687a8..2577e32933 100644 --- a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java +++ b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java @@ -7,8 +7,8 @@ import net.okocraft.box.api.event.player.PlayerUnloadEvent; import net.okocraft.box.api.event.stock.StockDecreaseEvent; import net.okocraft.box.api.event.stock.StockIncreaseEvent; -import net.okocraft.box.api.event.stock.StockSaveEvent; import net.okocraft.box.api.event.stock.StockSetEvent; +import net.okocraft.box.api.event.stockholder.StockHolderSaveEvent; import org.jetbrains.annotations.NotNull; public class DebugListener { @@ -62,7 +62,7 @@ private void handleEvent(@NotNull BoxEvent event) { return; } - if (event instanceof StockSaveEvent saveEvent) { + if (event instanceof StockHolderSaveEvent saveEvent) { printLog( saveEvent.getEventName() + "{" + "stockholderName='" + saveEvent.getStockHolder().getName() + "', " + From 2d9fab89d091e6f51d61cedc6428db531e4da9fb Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:48:31 +0900 Subject: [PATCH 44/80] change(api): deprecates StockSaveEvent --- .../java/net/okocraft/box/api/event/stock/StockSaveEvent.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java b/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java index 0405cadaca..2c96d8b33c 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java @@ -1,11 +1,14 @@ package net.okocraft.box.api.event.stock; import net.okocraft.box.api.model.stock.StockHolder; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; /** * A {@link StockEvent} called when the stockholder has been saved. */ +@Deprecated(forRemoval = true) +@ApiStatus.ScheduledForRemoval(inVersion = "4.2.0") public class StockSaveEvent extends StockEvent{ /** From 20c24eae1a7591cfca69fb72eef10aa9b8420908 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:50:30 +0900 Subject: [PATCH 45/80] feat(api): implements toString() --- .../box/api/event/stockholder/StockHolderLoadEvent.java | 7 +++++++ .../box/api/event/stockholder/StockHolderSaveEvent.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderLoadEvent.java b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderLoadEvent.java index 89056fdfa6..db354b18fe 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderLoadEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderLoadEvent.java @@ -16,4 +16,11 @@ public class StockHolderLoadEvent extends StockHolderEvent { public StockHolderLoadEvent(@NotNull StockHolder stockHolder) { super(stockHolder); } + + @Override + public String toString() { + return "StockHolderLoadEvent{" + + "stockholder=" + getStockHolder() + + "}"; + } } diff --git a/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java index e91b028de0..d137ba2136 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java @@ -16,4 +16,11 @@ public class StockHolderSaveEvent extends StockHolderEvent { public StockHolderSaveEvent(@NotNull StockHolder stockHolder) { super(stockHolder); } + + @Override + public String toString() { + return "StockHolderSaveEvent{" + + "stockholder=" + getStockHolder() + + "}"; + } } From f2283cbc70c59f754f1dbd11895d4ab1ea9ae6c0 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:55:43 +0900 Subject: [PATCH 46/80] docs(api): add @.deprecated --- .../java/net/okocraft/box/api/event/stock/StockSaveEvent.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java b/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java index 2c96d8b33c..28f2f644ff 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java @@ -6,6 +6,8 @@ /** * A {@link StockEvent} called when the stockholder has been saved. + * + * @deprecated use {@link net.okocraft.box.api.event.stockholder.StockHolderSaveEvent}. This event is no longer called. */ @Deprecated(forRemoval = true) @ApiStatus.ScheduledForRemoval(inVersion = "4.2.0") From a795752564a55327e9f1451a74fba52d9e2026e5 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 15:58:50 +0900 Subject: [PATCH 47/80] change(api): make StockEvent extend StockHolderEvent --- .../box/api/event/stock/StockEvent.java | 55 ++----------------- 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java b/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java index 2f6a1785fe..ab20bbb286 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java @@ -1,23 +1,16 @@ package net.okocraft.box.api.event.stock; -import net.okocraft.box.api.event.BoxEvent; +import net.okocraft.box.api.event.stockholder.StockHolderEvent; import net.okocraft.box.api.model.stock.StockHolder; -import net.okocraft.box.api.model.stock.UserStockHolder; import org.jetbrains.annotations.NotNull; -import java.util.Objects; - /** - * A class that represents a {@link StockHolder} related event. - *

- * This event is triggered when a {@link StockHolder} is modified. + * A {@link StockHolderEvent} called when the stock of the {@link StockHolder} is modified. *

- * Therefore, you need to be very careful not to call methods - * that cause changes to a {@link StockHolder} in the event, as this may result in an infinite loop. + * You need to be very careful not to call methods that cause changes to a {@link StockHolder} in the event, + * as this may result in an infinite loop. */ -public class StockEvent extends BoxEvent { - - private final StockHolder stockHolder; +public class StockEvent extends StockHolderEvent { /** * The constructor of {@link StockEvent}. @@ -25,42 +18,6 @@ public class StockEvent extends BoxEvent { * @param stockHolder the stockholder of the event */ public StockEvent(@NotNull StockHolder stockHolder) { - this.stockHolder = Objects.requireNonNull(stockHolder); - } - - /** - * Gets the stockholder. - * - * @return the stockholder - */ - public @NotNull StockHolder getStockHolder() { - return stockHolder; - } - - /** - * Checks if the {@link StockHolder} of this event is a {@link UserStockHolder}. - * - * @return whether the {@link StockHolder} is a {@link UserStockHolder} or not - */ - public boolean isUserStockHolder() { - return stockHolder instanceof UserStockHolder; - } - - /** - * Gets the {@link StockHolder} as a {@link UserStockHolder}. - *

- * You must check if the {@link StockHolder} of this event - * is {@link UserStockHolder} using {@link #isUserStockHolder()} - * before calling this method. - * - * @return the {@link UserStockHolder} - * @throws IllegalStateException if the {@link StockHolder} of this event is not {@link UserStockHolder} - */ - public @NotNull UserStockHolder getUserStockHolder() { - if (stockHolder instanceof UserStockHolder userStockHolder) { - return userStockHolder; - } else { - throw new IllegalStateException("The StockHolder of this event is not UserStockHolder."); - } + super(stockHolder); } } From 7ac088e62eec138b4dcc4bff0f877688621c6c50 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 16:00:48 +0900 Subject: [PATCH 48/80] feat(core): call StockHolderLoadEvent --- .../okocraft/box/core/model/manager/BoxStockManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java b/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java index 36a2f3ec29..fdec8d6c5f 100644 --- a/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java +++ b/core/src/main/java/net/okocraft/box/core/model/manager/BoxStockManager.java @@ -1,6 +1,7 @@ package net.okocraft.box.core.model.manager; import net.okocraft.box.api.BoxProvider; +import net.okocraft.box.api.event.stockholder.StockHolderLoadEvent; import net.okocraft.box.api.event.stockholder.StockHolderSaveEvent; import net.okocraft.box.api.model.manager.StockManager; import net.okocraft.box.api.model.stock.UserStockHolder; @@ -28,11 +29,15 @@ public BoxStockManager(@NotNull StockStorage stockStorage) { Objects.requireNonNull(user); return CompletableFuture.supplyAsync(() -> { + UserStockHolder stockHolder; try { - return stockStorage.loadUserStockHolder(user); + stockHolder = stockStorage.loadUserStockHolder(user); } catch (Exception e) { throw new RuntimeException("Could not load user stock holder (" + user.getUUID() + ")", e); } + + BoxProvider.get().getEventBus().callEvent(new StockHolderLoadEvent(stockHolder)); + return stockHolder; }, executor); } From 4035de8cfa74fbc32674d5ba3e391b647f2355b9 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 16:29:13 +0900 Subject: [PATCH 49/80] todo(api): move StockEvent classes to api.event.stockholder in version 5.0.0 [ci skip] --- .../main/java/net/okocraft/box/api/event/stock/StockEvent.java | 1 + 1 file changed, 1 insertion(+) diff --git a/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java b/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java index ab20bbb286..1b62eab897 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stock/StockEvent.java @@ -10,6 +10,7 @@ * You need to be very careful not to call methods that cause changes to a {@link StockHolder} in the event, * as this may result in an infinite loop. */ +// TODO: move StockEvent classes to api.event.stockholder in version 5.0.0 public class StockEvent extends StockHolderEvent { /** From 32c1c4b8675e88e818a4982edcb4df6331356cd0 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Tue, 12 Oct 2021 16:54:09 +0900 Subject: [PATCH 50/80] change(api): call StockSaveEvent for compatibility --- .../java/net/okocraft/box/api/event/stock/StockSaveEvent.java | 2 +- .../box/api/event/stockholder/StockHolderSaveEvent.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java b/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java index 28f2f644ff..87442bd888 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stock/StockSaveEvent.java @@ -7,7 +7,7 @@ /** * A {@link StockEvent} called when the stockholder has been saved. * - * @deprecated use {@link net.okocraft.box.api.event.stockholder.StockHolderSaveEvent}. This event is no longer called. + * @deprecated use {@link net.okocraft.box.api.event.stockholder.StockHolderSaveEvent} */ @Deprecated(forRemoval = true) @ApiStatus.ScheduledForRemoval(inVersion = "4.2.0") diff --git a/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java index d137ba2136..3959bce0e9 100644 --- a/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java +++ b/api/src/main/java/net/okocraft/box/api/event/stockholder/StockHolderSaveEvent.java @@ -1,5 +1,7 @@ package net.okocraft.box.api.event.stockholder; +import net.okocraft.box.api.BoxProvider; +import net.okocraft.box.api.event.stock.StockSaveEvent; import net.okocraft.box.api.model.stock.StockHolder; import org.jetbrains.annotations.NotNull; @@ -15,6 +17,7 @@ public class StockHolderSaveEvent extends StockHolderEvent { */ public StockHolderSaveEvent(@NotNull StockHolder stockHolder) { super(stockHolder); + BoxProvider.get().getEventBus().callEvent(new StockSaveEvent(stockHolder)); // for compatibility } @Override From 8830727106d967cb078147bd8445a96b1483e94d Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Wed, 13 Oct 2021 01:05:54 +0900 Subject: [PATCH 51/80] feat(core): add debug log of loading the stockholder --- .../net/okocraft/box/core/listener/DebugListener.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java index 2577e32933..900f29a96b 100644 --- a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java +++ b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java @@ -8,6 +8,7 @@ import net.okocraft.box.api.event.stock.StockDecreaseEvent; import net.okocraft.box.api.event.stock.StockIncreaseEvent; import net.okocraft.box.api.event.stock.StockSetEvent; +import net.okocraft.box.api.event.stockholder.StockHolderLoadEvent; import net.okocraft.box.api.event.stockholder.StockHolderSaveEvent; import org.jetbrains.annotations.NotNull; @@ -62,6 +63,16 @@ private void handleEvent(@NotNull BoxEvent event) { return; } + if (event instanceof StockHolderLoadEvent loadEvent) { + printLog( + loadEvent.getEventName() + "{" + + "stockholderName='" + loadEvent.getStockHolder().getName() + "', " + + "stockholderClass=" + loadEvent.getStockHolder().getClass().getSimpleName() + + "}" + ); + return; + } + if (event instanceof StockHolderSaveEvent saveEvent) { printLog( saveEvent.getEventName() + "{" + From e3166351990f48989c808e03a8e00de797448224 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Wed, 13 Oct 2021 01:15:34 +0900 Subject: [PATCH 52/80] improve(core): conditional branches --- .../box/core/listener/DebugListener.java | 111 +++++++----------- 1 file changed, 45 insertions(+), 66 deletions(-) diff --git a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java index 900f29a96b..2af7ddebf4 100644 --- a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java +++ b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java @@ -3,13 +3,11 @@ import com.github.siroshun09.event4j.handlerlist.Key; import net.okocraft.box.api.BoxProvider; import net.okocraft.box.api.event.BoxEvent; -import net.okocraft.box.api.event.player.PlayerLoadEvent; -import net.okocraft.box.api.event.player.PlayerUnloadEvent; +import net.okocraft.box.api.event.player.PlayerEvent; import net.okocraft.box.api.event.stock.StockDecreaseEvent; import net.okocraft.box.api.event.stock.StockIncreaseEvent; import net.okocraft.box.api.event.stock.StockSetEvent; -import net.okocraft.box.api.event.stockholder.StockHolderLoadEvent; -import net.okocraft.box.api.event.stockholder.StockHolderSaveEvent; +import net.okocraft.box.api.event.stockholder.StockHolderEvent; import org.jetbrains.annotations.NotNull; public class DebugListener { @@ -25,77 +23,58 @@ public void unregister() { } private void handleEvent(@NotNull BoxEvent event) { - if (event instanceof StockIncreaseEvent increaseEvent) { - printLog( - increaseEvent.getEventName() + "{" + - "stockholderName='" + increaseEvent.getStockHolder().getName() + "', " + - "stockholderClass=" + increaseEvent.getStockHolder().getClass().getSimpleName() + ", " + - "boxItem=" + increaseEvent.getItem() + ", " + - "increments=" + increaseEvent.getIncrements() + ", " + - "current=" + increaseEvent.getAmount() + - "}" - ); - return; - } + if (event instanceof StockHolderEvent stockHolderEvent) { + if (event instanceof StockIncreaseEvent increaseEvent) { + printLog( + increaseEvent.getEventName() + "{" + + "stockholderName='" + increaseEvent.getStockHolder().getName() + "', " + + "stockholderClass=" + increaseEvent.getStockHolder().getClass().getSimpleName() + ", " + + "boxItem=" + increaseEvent.getItem() + ", " + + "increments=" + increaseEvent.getIncrements() + ", " + + "current=" + increaseEvent.getAmount() + + "}" + ); + return; + } - if (event instanceof StockDecreaseEvent decreaseEvent) { - printLog( - decreaseEvent.getEventName() + "{" + - "stockholderName='" + decreaseEvent.getStockHolder().getName() + "', " + - "stockholderClass=" + decreaseEvent.getStockHolder().getClass().getSimpleName() + ", " + - "boxItem=" + decreaseEvent.getItem() + ", " + - "decrements=" + decreaseEvent.getDecrements() + ", " + - "current=" + decreaseEvent.getAmount() + - "}" - ); - return; - } - - if (event instanceof StockSetEvent setEvent) { - printLog( - setEvent.getEventName() + "{" + - "stockholderName='" + setEvent.getStockHolder().getName() + "', " + - "stockholderClass=" + setEvent.getStockHolder().getClass().getSimpleName() + ", " + - "boxItem=" + setEvent.getItem() + ", " + - "current=" + setEvent.getAmount() + - "}" - ); - return; - } + if (event instanceof StockDecreaseEvent decreaseEvent) { + printLog( + decreaseEvent.getEventName() + "{" + + "stockholderName='" + decreaseEvent.getStockHolder().getName() + "', " + + "stockholderClass=" + decreaseEvent.getStockHolder().getClass().getSimpleName() + ", " + + "boxItem=" + decreaseEvent.getItem() + ", " + + "decrements=" + decreaseEvent.getDecrements() + ", " + + "current=" + decreaseEvent.getAmount() + + "}" + ); + return; + } - if (event instanceof StockHolderLoadEvent loadEvent) { - printLog( - loadEvent.getEventName() + "{" + - "stockholderName='" + loadEvent.getStockHolder().getName() + "', " + - "stockholderClass=" + loadEvent.getStockHolder().getClass().getSimpleName() + - "}" - ); - return; - } + if (event instanceof StockSetEvent setEvent) { + printLog( + setEvent.getEventName() + "{" + + "stockholderName='" + setEvent.getStockHolder().getName() + "', " + + "stockholderClass=" + setEvent.getStockHolder().getClass().getSimpleName() + ", " + + "boxItem=" + setEvent.getItem() + ", " + + "current=" + setEvent.getAmount() + + "}" + ); + return; + } - if (event instanceof StockHolderSaveEvent saveEvent) { printLog( - saveEvent.getEventName() + "{" + - "stockholderName='" + saveEvent.getStockHolder().getName() + "', " + - "stockholderClass=" + saveEvent.getStockHolder().getClass().getSimpleName() + + stockHolderEvent.getEventName() + "{" + + "stockholderName='" + stockHolderEvent.getStockHolder().getName() + "', " + + "stockholderClass=" + stockHolderEvent.getStockHolder().getClass().getSimpleName() + "}" ); return; } - if (event instanceof PlayerLoadEvent loadEvent) { - printLog(loadEvent.getEventName() + "{" + - "playerUuid=" + loadEvent.getBoxPlayer().getUUID() + ", " + - "playerName='" + loadEvent.getBoxPlayer().getName() + "'" + - "}" - ); - return; - } - - if (event instanceof PlayerUnloadEvent unloadEvent) { - printLog(unloadEvent.getEventName() + "{" + - "playerUuid=" + unloadEvent.getBoxPlayer().getUUID() + ", " + - "playerName='" + unloadEvent.getBoxPlayer().getName() + "'" + + if (event instanceof PlayerEvent playerEvent) { + printLog(playerEvent.getEventName() + "{" + + "playerUuid=" + playerEvent.getBoxPlayer().getUUID() + ", " + + "playerName='" + playerEvent.getBoxPlayer().getName() + "'" + "}" ); return; From 59a2d76212914e5b59cdef365b0f40ce89b13528 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Wed, 13 Oct 2021 01:15:49 +0900 Subject: [PATCH 53/80] feat(core): add debug log for PlayerStockHolderChangeEvent --- .../okocraft/box/core/listener/DebugListener.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java index 2af7ddebf4..eacca9cd96 100644 --- a/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java +++ b/core/src/main/java/net/okocraft/box/core/listener/DebugListener.java @@ -4,6 +4,7 @@ import net.okocraft.box.api.BoxProvider; import net.okocraft.box.api.event.BoxEvent; import net.okocraft.box.api.event.player.PlayerEvent; +import net.okocraft.box.api.event.player.PlayerStockHolderChangeEvent; import net.okocraft.box.api.event.stock.StockDecreaseEvent; import net.okocraft.box.api.event.stock.StockIncreaseEvent; import net.okocraft.box.api.event.stock.StockSetEvent; @@ -72,6 +73,19 @@ private void handleEvent(@NotNull BoxEvent event) { } if (event instanceof PlayerEvent playerEvent) { + if (event instanceof PlayerStockHolderChangeEvent changeEvent) { + printLog(changeEvent.getEventName() + "{" + + "playerUuid=" + changeEvent.getBoxPlayer().getUUID() + ", " + + "playerName='" + changeEvent.getBoxPlayer().getName() + "', " + + "previousStockHolderName='" + changeEvent.getPreviousStockHolder().getName() + "', " + + "previousStockHolderClass='" + changeEvent.getPreviousStockHolder().getClass().getSimpleName() + "'," + + "currentStockHolderName='" + changeEvent.getBoxPlayer().getName() + "', " + + "currentStockHolderClass='" + changeEvent.getBoxPlayer().getClass().getSimpleName() + "'" + + "}" + ); + return; + } + printLog(playerEvent.getEventName() + "{" + "playerUuid=" + playerEvent.getBoxPlayer().getUUID() + ", " + "playerName='" + playerEvent.getBoxPlayer().getName() + "'" + From 606428ea770d9a3cfc79974a224c69c2e759c94f Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Wed, 13 Oct 2021 01:20:00 +0900 Subject: [PATCH 54/80] feat(core): dequeue stockholder when it is saved by the other operation --- .../okocraft/box/core/listener/StockHolderListener.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java b/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java index 93fbe29720..feb4f42cf5 100644 --- a/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java +++ b/core/src/main/java/net/okocraft/box/core/listener/StockHolderListener.java @@ -8,6 +8,7 @@ import net.okocraft.box.api.event.stock.StockEvent; import net.okocraft.box.api.event.stock.StockIncreaseEvent; import net.okocraft.box.api.event.stock.StockSetEvent; +import net.okocraft.box.api.event.stockholder.StockHolderSaveEvent; import net.okocraft.box.api.model.stock.UserStockHolder; import net.okocraft.box.api.model.user.BoxUser; import net.okocraft.box.core.message.ErrorMessages; @@ -31,6 +32,7 @@ public void register() { eventBus.getHandlerList(StockIncreaseEvent.class).subscribe(listenerKey, this::enqueueStockHolder); eventBus.getHandlerList(StockDecreaseEvent.class).subscribe(listenerKey, this::enqueueStockHolder); + eventBus.getHandlerList(StockHolderSaveEvent.class).subscribe(listenerKey, this::dequeueStockHolder); eventBus.getHandlerList(PlayerUnloadEvent.class).subscribe(listenerKey, this::dequeueStockHolder); eventBus.getHandlerList(AutoSaveStartEvent.class).subscribe(listenerKey, this::saveModifiedStockHolders); @@ -50,6 +52,12 @@ private void enqueueStockHolder(@NotNull StockEvent event) { } } + private void dequeueStockHolder(@NotNull StockHolderSaveEvent event) { + if (!modifiedStockHolders.isEmpty() && event.isUserStockHolder()) { + modifiedStockHolders.remove(event.getUserStockHolder()); + } + } + private void dequeueStockHolder(@NotNull PlayerUnloadEvent event) { modifiedStockHolders.remove(event.getBoxPlayer().getUserStockHolder()); } From 8bb45276f974c339d57ad50bd802f61dea8ca89f Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Wed, 13 Oct 2021 01:25:04 +0900 Subject: [PATCH 55/80] fix(command): save the UserStockHolder when the user is offline if the user logs in before the auto-save, the changes will not be applied --- .../box/feature/command/boxadmin/StockModifyCommands.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/StockModifyCommands.java b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/StockModifyCommands.java index f508121768..5cb0d4ebae 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/StockModifyCommands.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/StockModifyCommands.java @@ -192,6 +192,10 @@ private void processCommand(@NotNull CommandSender sender, @NotNull UserStockHol int current = modifyStock(target, item.get(), amount); + if (targetPlayer == null) { + BoxProvider.get().getStockManager().saveUserStock(target).join(); + } + sendMessage(sender, targetPlayer, target.getName(), item.get(), amount, current); } From 09eb2092d6566cca6270d1da948a4877b2c86591 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Wed, 13 Oct 2021 14:13:11 +0900 Subject: [PATCH 56/80] fix(bundle): escape single quotes in en.yml --- bundle/src/main/resources/en.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index 1cb8c7dfa3..a1f410ad00 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -34,8 +34,8 @@ box: title: "Auto-store setting menu" change-mode: display-name: "Change auto-store mode" - all: "Click to change mode to 'all items'" - item: "Click to change mode to 'per item'" + all: "Click to change mode to ''all items''" + item: "Click to change mode to ''per item''" toggle-button: "Click to set auto-store to {0}" bulk-editing: title: "Bulk change operation for per-item mode" @@ -106,8 +106,8 @@ box: sender: "Sent {1}x{2} to player {0} (Now {3})." target: "Received {1}x{2} from player {0} (Now {3})." no-stock: "Item {0} is out of stock." - self: "You can't send it to yourself." - target-no-permission: "Player {0} doesn't have the permission {1}." + self: "You can''t send it to yourself." + target-no-permission: "Player {0} doesn''t have the permission {1}." target-is-in-disabled-world: "Player {0} is in world {1} where Box is not available." help: command-line: "/box give [amount]" @@ -145,7 +145,7 @@ box: toggle: "Infinite stock mode has been {0}." toggle-sender: "{1} infinite stock mode for player {0}." toggle-target: "Infinite stock mode has been {1} by {0}." - tip: "Infinite stock mode does not save deposited items' data." + tip: "Infinite stock mode does not save deposited items'' data." help: command-line: "/boxadmin infinity [player]" description: "Toggles infinite stock mode" @@ -174,7 +174,7 @@ box: description: "Changes item name" set: success: - sender: "Player {0}'s item {1} has been set to {2}." + sender: "Player {0}''s item {1} has been set to {2}." target: "Item {1} has been set to {2} by {0}." help: command-line: "/boxadmin set " @@ -295,7 +295,7 @@ box: disabled-world: "Box cannot be used in world {0}." failed-to-reload-feature: "Failed to reload {0}. Error message: {1}" failed-to-execute-command: "Failed to execute command. Error message: {1}" - no-permission: "You don't have the permission: {0}" + no-permission: "You don''t have the permission: {0}" player-data: load-on-join: "Failed to load the stock data. Please contact the administrator." save: "Failed to save the stock data. Please contact the administrator." From 8e59966024b7e5299a69f655c395dbadb58a3c75 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Thu, 14 Oct 2021 17:21:03 +0900 Subject: [PATCH 57/80] fix(stick): ignore POWDER_SNOW because it cannot be replenished --- .../okocraft/box/feature/stick/listener/StickListener.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/features/stick/src/main/java/net/okocraft/box/feature/stick/listener/StickListener.java b/features/stick/src/main/java/net/okocraft/box/feature/stick/listener/StickListener.java index eba0a95d80..0297197bc6 100644 --- a/features/stick/src/main/java/net/okocraft/box/feature/stick/listener/StickListener.java +++ b/features/stick/src/main/java/net/okocraft/box/feature/stick/listener/StickListener.java @@ -60,6 +60,11 @@ public void onInteract(@NotNull PlayerInteractEvent event) { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockPlace(@NotNull BlockPlaceEvent event) { + // ignore POWDER_SNOW because it cannot be replenished + if (event.getBlockPlaced().getType() == Material.POWDER_SNOW) { + return; + } + var player = event.getPlayer(); if (!checkPlayerCondition(player, "box.stick.block")) { From f8b4f9c4e458ce288ec7ad6dd143f01b67fa5d79 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Thu, 14 Oct 2021 17:46:10 +0900 Subject: [PATCH 58/80] improve(autostore): check early if autostore is enabled --- .../box/feature/autostore/listener/ItemListener.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/autostore/src/main/java/net/okocraft/box/feature/autostore/listener/ItemListener.java b/features/autostore/src/main/java/net/okocraft/box/feature/autostore/listener/ItemListener.java index c0e443a1dd..0cb3c6c0f5 100644 --- a/features/autostore/src/main/java/net/okocraft/box/feature/autostore/listener/ItemListener.java +++ b/features/autostore/src/main/java/net/okocraft/box/feature/autostore/listener/ItemListener.java @@ -50,7 +50,9 @@ private boolean processEvent(@NotNull Player player, @NotNull ItemStack item) { return false; } - if (!player.hasPermission("box.autostore")) { + var setting = AutoStoreSettingContainer.INSTANCE.get(player); + + if (!setting.isEnabled() || !player.hasPermission("box.autostore")) { return false; } @@ -60,9 +62,7 @@ private boolean processEvent(@NotNull Player player, @NotNull ItemStack item) { return false; } - var setting = AutoStoreSettingContainer.INSTANCE.get(player); - - if (setting.isEnabled() && setting.shouldAutoStore(boxItem.get())) { + if (setting.shouldAutoStore(boxItem.get())) { BoxProvider.get() .getBoxPlayerMap() .get(player) From 66b8004d641741758d5a81f7c159d642a2645168 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Thu, 14 Oct 2021 17:50:46 +0900 Subject: [PATCH 59/80] refactor(command): add UserStockHolderOperator and use it --- .../command/boxadmin/StockModifyCommands.java | 76 +++------------- .../command/util/UserStockHolderOperator.java | 91 +++++++++++++++++++ 2 files changed, 105 insertions(+), 62 deletions(-) create mode 100644 features/command/src/main/java/net/okocraft/box/feature/command/util/UserStockHolderOperator.java diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/StockModifyCommands.java b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/StockModifyCommands.java index 5cb0d4ebae..2b51dc5414 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/StockModifyCommands.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/StockModifyCommands.java @@ -7,10 +7,9 @@ import net.okocraft.box.api.message.GeneralMessage; import net.okocraft.box.api.model.item.BoxItem; import net.okocraft.box.api.model.stock.StockHolder; -import net.okocraft.box.api.model.stock.UserStockHolder; -import net.okocraft.box.api.model.user.BoxUser; import net.okocraft.box.feature.command.message.BoxAdminMessage; import net.okocraft.box.feature.command.util.TabCompleter; +import net.okocraft.box.feature.command.util.UserStockHolderOperator; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -20,7 +19,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import java.util.UUID; public class StockModifyCommands { @@ -120,60 +118,6 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { return; } - try { - var uuid = UUID.fromString(args[1]); - processUUID(sender, uuid, args); - } catch (IllegalArgumentException ignored) { - processPlayerName(sender, args); - } - } - - private void processUUID(@NotNull CommandSender sender, @NotNull UUID uuid, - @NotNull String[] args) { - var player = Bukkit.getPlayer(uuid); - - if (player != null) { - var boxPlayer = BoxProvider.get().getBoxPlayerMap().get(player); - processCommand(sender, boxPlayer.getUserStockHolder(), player, args); - return; - } - - var boxUser = BoxProvider.get().getUserManager().loadUser(uuid).join(); - var userStockHolder = BoxProvider.get().getStockManager().loadUserStock(boxUser).join(); - processCommand(sender, userStockHolder, null, args); - } - - private void processPlayerName(@NotNull CommandSender sender, @NotNull String[] args) { - var player = Bukkit.getPlayer(args[1]); - - if (player != null) { - processPlayer(sender, player, args); - return; - } - - var boxUser = BoxProvider.get().getUserManager().search(args[1]).join(); - - if (boxUser.isPresent()) { - processBoxUser(sender, boxUser.get(), args); - } else { - sender.sendMessage(GeneralMessage.ERROR_COMMAND_PLAYER_NOT_FOUND.apply(args[1])); - } - } - - private void processPlayer(@NotNull CommandSender sender, @NotNull Player target, - @NotNull String[] args) { - var boxPlayer = BoxProvider.get().getBoxPlayerMap().get(target); - processCommand(sender, boxPlayer.getUserStockHolder(), target, args); - } - - private void processBoxUser(@NotNull CommandSender sender, @NotNull BoxUser target, - @NotNull String[] args) { - var userStockHolder = BoxProvider.get().getStockManager().loadUserStock(target).join(); - processCommand(sender, userStockHolder, null, args); - } - - private void processCommand(@NotNull CommandSender sender, @NotNull UserStockHolder target, - @Nullable Player targetPlayer, @NotNull String[] args) { var item = BoxProvider.get().getItemManager().getBoxItem(args[2]); if (item.isEmpty()) { @@ -190,13 +134,21 @@ private void processCommand(@NotNull CommandSender sender, @NotNull UserStockHol return; } - int current = modifyStock(target, item.get(), amount); + UserStockHolderOperator.create(args[1]) + .supportOffline(true) + .stockHolderOperator(target -> { + int current = modifyStock(target, item.get(), amount); - if (targetPlayer == null) { - BoxProvider.get().getStockManager().saveUserStock(target).join(); - } + var targetPlayer = Bukkit.getPlayer(target.getUUID()); + + if (targetPlayer == null) { + BoxProvider.get().getStockManager().saveUserStock(target).join(); + } - sendMessage(sender, targetPlayer, target.getName(), item.get(), amount, current); + sendMessage(sender, targetPlayer, target.getName(), item.get(), amount, current); + }) + .onNotFound(name -> sender.sendMessage(GeneralMessage.ERROR_COMMAND_PLAYER_NOT_FOUND.apply(name))) + .run(); } abstract int modifyStock(@NotNull StockHolder stockHolder, @NotNull BoxItem item, int amount); diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/util/UserStockHolderOperator.java b/features/command/src/main/java/net/okocraft/box/feature/command/util/UserStockHolderOperator.java new file mode 100644 index 0000000000..772b3899d3 --- /dev/null +++ b/features/command/src/main/java/net/okocraft/box/feature/command/util/UserStockHolderOperator.java @@ -0,0 +1,91 @@ +package net.okocraft.box.feature.command.util; + +import net.okocraft.box.api.BoxProvider; +import net.okocraft.box.api.model.stock.UserStockHolder; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; +import java.util.function.Consumer; + +public class UserStockHolderOperator { + + private final String argument; + private boolean supportOffline = false; + private Consumer stockHolderConsumer; + private Consumer argumentConsumer; + + private UserStockHolderOperator(@NotNull String argument) { + this.argument = argument; + } + + @Contract(value = "_ -> new", pure = true) + public static @NotNull UserStockHolderOperator create(@NotNull String argument) { + return new UserStockHolderOperator(argument); + } + + @Contract(value = "_ -> this") + public @NotNull UserStockHolderOperator supportOffline(boolean bool) { + supportOffline = bool; + return this; + } + + @Contract(value = "_ -> this") + public @NotNull UserStockHolderOperator stockHolderOperator(@NotNull Consumer stockHolderConsumer) { + this.stockHolderConsumer = stockHolderConsumer; + return this; + } + + @Contract(value = "_ -> this") + public @NotNull UserStockHolderOperator onNotFound(@NotNull Consumer argumentConsumer) { + this.argumentConsumer = argumentConsumer; + return this; + } + + public void run() { + if (stockHolderConsumer == null) { + return; + } + + var target = getUserStockHolder(); + + if (target != null) { + stockHolderConsumer.accept(target); + } else { + argumentConsumer.accept(argument); + } + } + + private @Nullable UserStockHolder getUserStockHolder() { + UUID uuid = null; + + try { + uuid = UUID.fromString(argument); + } catch (IllegalArgumentException ignored) { + } + + var player = uuid != null ? Bukkit.getPlayer(uuid) : Bukkit.getPlayer(argument); + + if (player != null) { + return BoxProvider.get().getBoxPlayerMap().get(player).getUserStockHolder(); + } + + if (supportOffline) { + return getOfflineUserStockHolder(uuid); + } else { + return null; + } + } + + private @Nullable UserStockHolder getOfflineUserStockHolder(@Nullable UUID uuid) { + var boxUser = uuid != null ? + BoxProvider.get().getUserManager().loadUser(uuid).join() : + BoxProvider.get().getUserManager().search(argument).join().orElse(null); + + var stockManager = BoxProvider.get().getStockManager(); + + return boxUser != null ? stockManager.loadUserStock(boxUser).join() : null; + } +} From 9418ad8687ecb55ca03fa5068f760bfbc5d19e5e Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Wed, 13 Oct 2021 13:51:25 +0900 Subject: [PATCH 60/80] feat(command): implements /boxadmin reset --- bundle/src/main/resources/en.yml | 13 ++ bundle/src/main/resources/ja_JP.yml | 13 ++ .../box/feature/command/CommandFeature.java | 3 +- .../command/boxadmin/ResetCommand.java | 118 ++++++++++++++++++ .../command/message/BoxAdminMessage.java | 51 ++++++++ 5 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/ResetCommand.java diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index a1f410ad00..e53e26c43b 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -172,6 +172,19 @@ box: help: command-line: "/boxadmin rename " description: "Changes item name" + reset: + success: + sender: "All stocks of player {0} has been reset." + target: "All stocks has been reset by {0}." + cancel: "Cancelled reset operation." + confirmation: + info: "Reset all stocks of player {0}." + warning: "This operation cannot be undone." + confirm-command: "To confirm, run {0}." + cancel-command: "To cancel, run {0}." + help: + command-line: "/boxadmin reset " + description: "Resets all stocks" set: success: sender: "Player {0}''s item {1} has been set to {2}." diff --git a/bundle/src/main/resources/ja_JP.yml b/bundle/src/main/resources/ja_JP.yml index 1ac733919f..b8e2ba21fd 100644 --- a/bundle/src/main/resources/ja_JP.yml +++ b/bundle/src/main/resources/ja_JP.yml @@ -172,6 +172,19 @@ box: help: command-line: "/boxadmin rename <現在の名前> <新しい名前>" description: "アイテムの名前を変更する" + reset: + success: + sender: "プレイヤー {0} の在庫をすべてリセットしました。" + target: "{0} によって在庫がすべてリセットされました。" + cancel: "リセット操作をキャンセルしました。" + confirmation: + info: "プレイヤー {0} の在庫をすべて 0 にします。" + warning: "この操作は元に戻すことができません。" + confirm-command: "問題なければ {0} を実行してください。" + cancel-command: "キャンセルする場合は {0} を実行します。" + help: + command-line: "/boxadmin reset <プレイヤー名>" + description: "在庫をすべてリセットする" set: success: sender: "プレイヤー {0} のアイテム {1} の在庫を {2} 個にセットしました。" diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/CommandFeature.java b/features/command/src/main/java/net/okocraft/box/feature/command/CommandFeature.java index 2351598195..f2b5f33ae7 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/CommandFeature.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/CommandFeature.java @@ -11,6 +11,7 @@ import net.okocraft.box.feature.command.boxadmin.RegisterCommand; import net.okocraft.box.feature.command.boxadmin.ReloadCommand; import net.okocraft.box.feature.command.boxadmin.RenameCommand; +import net.okocraft.box.feature.command.boxadmin.ResetCommand; import net.okocraft.box.feature.command.boxadmin.StockModifyCommands; import net.okocraft.box.feature.command.boxadmin.VersionCommand; @@ -25,7 +26,7 @@ public class CommandFeature extends AbstractBoxFeature { public final List boxAdminSubCommands = List.of(StockModifyCommands.give(), StockModifyCommands.set(), StockModifyCommands.take(), new InfinityCommand(), new RegisterCommand(), new RenameCommand(), - new ReloadCommand(), new VersionCommand()); + new ReloadCommand(), new ResetCommand(), new VersionCommand()); public CommandFeature() { super("command"); diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/ResetCommand.java b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/ResetCommand.java new file mode 100644 index 0000000000..6b132886ae --- /dev/null +++ b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/ResetCommand.java @@ -0,0 +1,118 @@ +package net.okocraft.box.feature.command.boxadmin; + +import net.kyori.adventure.text.Component; +import net.okocraft.box.api.BoxProvider; +import net.okocraft.box.api.command.AbstractCommand; +import net.okocraft.box.api.message.GeneralMessage; +import net.okocraft.box.api.model.stock.UserStockHolder; +import net.okocraft.box.feature.command.message.BoxAdminMessage; +import net.okocraft.box.feature.command.util.TabCompleter; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +public class ResetCommand extends AbstractCommand { + + private static final String CONFIRM = "confirm"; + private static final String CANCEL = "cancel"; + + private final Map confirmationMap = new HashMap<>(); + + public ResetCommand() { + super("reset", "box.admin.command.reset"); + } + + @Override + public @NotNull Component getHelp() { + return BoxAdminMessage.RESET_HELP; + } + + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { + if (args.length < 2) { + sender.sendMessage(GeneralMessage.ERROR_COMMAND_NOT_ENOUGH_ARGUMENT); + sender.sendMessage(getHelp()); + return; + } + + if (CONFIRM.equalsIgnoreCase(args[1]) && confirmationMap.containsKey(sender)) { + var target = confirmationMap.remove(sender); + + for (var stockedItem : target.getStockedItems()) { + target.setAmount(stockedItem, 0); + } + + sender.sendMessage(BoxAdminMessage.RESET_SUCCESS_SENDER.apply(target)); + + var targetPlayer = Bukkit.getPlayer(target.getUUID()); + + if (targetPlayer != null && !sender.getName().equals(targetPlayer.getName())) { + targetPlayer.sendMessage(BoxAdminMessage.RESET_SUCCESS_TARGET.apply(sender)); + } else { + BoxProvider.get().getStockManager().saveUserStock(target).join(); + } + + return; + } + + if (CANCEL.equalsIgnoreCase(args[1]) && confirmationMap.remove(sender) != null) { + sender.sendMessage(BoxAdminMessage.RESET_CANCEL); + return; + } + + var targetPlayer = Bukkit.getPlayer(args[1]); + UserStockHolder targetStockHolder; + + if (targetPlayer != null) { + targetStockHolder = BoxProvider.get().getBoxPlayerMap().get(targetPlayer).getUserStockHolder(); + } else { + targetStockHolder = + BoxProvider.get().getUserManager().search(args[1]).join() + .map(BoxProvider.get().getStockManager()::loadUserStock) + .map(CompletableFuture::join) + .orElse(null); + } + + if (targetStockHolder != null) { + confirmationMap.put(sender, targetStockHolder); + sender.sendMessage(BoxAdminMessage.RESET_CONFIRMATION.apply(targetStockHolder)); + } else { + sender.sendMessage(GeneralMessage.ERROR_COMMAND_PLAYER_NOT_FOUND.apply(args[1])); + } + } + + @Override + public @NotNull List onTabComplete(@NotNull CommandSender sender, @NotNull String[] args) { + if (args.length != 2) { + return Collections.emptyList(); + } + + if (confirmationMap.containsKey(sender)) { + var secondArgument = args[1].toLowerCase(Locale.ROOT); + + if (secondArgument.isEmpty() || + (secondArgument.length() == 1 && secondArgument.charAt(0) == 'c')) { + return List.of(CONFIRM, CANCEL); + } + + if (secondArgument.length() < 7 && secondArgument.startsWith("ca")) { + return List.of(CANCEL); + } + + if (secondArgument.length() < 8 && secondArgument.startsWith("co")) { + return List.of(CONFIRM); + } + + return Collections.emptyList(); + } else { + return TabCompleter.players(args[1]); + } + } +} diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/message/BoxAdminMessage.java b/features/command/src/main/java/net/okocraft/box/feature/command/message/BoxAdminMessage.java index fdf82af4f0..87c6d6fabd 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/message/BoxAdminMessage.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/message/BoxAdminMessage.java @@ -8,10 +8,12 @@ import net.okocraft.box.api.message.argument.TripleArgument; import net.okocraft.box.api.model.item.BoxCustomItem; import net.okocraft.box.api.model.item.BoxItem; +import net.okocraft.box.api.model.stock.UserStockHolder; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import static net.kyori.adventure.text.Component.newline; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; import static net.kyori.adventure.text.format.NamedTextColor.AQUA; @@ -249,6 +251,55 @@ public final class BoxAdminMessage { .append(text(" - ", DARK_GRAY)) .append(translatable("box.command.boxadmin.infinity.help.description", GRAY)); + public static final SingleArgument RESET_SUCCESS_SENDER = + target -> translatable() + .key("box.command.boxadmin.reset.success.sender") + .args(text(target.getName(), AQUA)) + .color(GRAY) + .build(); + + public static final SingleArgument RESET_SUCCESS_TARGET = + sender -> translatable() + .key("box.command.boxadmin.reset.success.target") + .args(text(sender.getName(), AQUA)) + .color(GRAY) + .build(); + + public static final Component RESET_CANCEL = + translatable("box.command.boxadmin.reset.cancel", GRAY); + + public static final SingleArgument RESET_CONFIRMATION = + target -> text() + .append( + translatable() + .key("box.command.boxadmin.reset.confirmation.info") + .args(text(target.getName(), AQUA)) + .color(GRAY) + .build() + ).append(newline()) + .append(translatable("box.command.boxadmin.reset.confirmation.warning", GRAY)) + .append(newline()) + .append( + translatable() + .key("box.command.boxadmin.reset.confirmation.confirm-command") + .args(text("/boxadmin reset confirm", AQUA)) + .color(GRAY) + .build() + ).append(newline()) + .append( + translatable() + .key("box.command.boxadmin.reset.confirmation.cancel-command") + .args(text("/boxadmin reset cancel", AQUA)) + .color(GRAY) + .build() + ) + .build(); + + public static final Component RESET_HELP = + translatable("box.command.boxadmin.reset.help.command-line", AQUA) + .append(text(" - ", DARK_GRAY)) + .append(translatable("box.command.boxadmin.reset.help.description", GRAY)); + private BoxAdminMessage() { throw new UnsupportedOperationException(); } From d5a4d020372533d55c57fa92511194d1c3259b16 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Thu, 14 Oct 2021 17:54:54 +0900 Subject: [PATCH 61/80] refactor(command): use UserStockHolderOperator --- .../command/boxadmin/ResetCommand.java | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/ResetCommand.java b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/ResetCommand.java index 6b132886ae..22caebbc73 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/ResetCommand.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/ResetCommand.java @@ -7,6 +7,7 @@ import net.okocraft.box.api.model.stock.UserStockHolder; import net.okocraft.box.feature.command.message.BoxAdminMessage; import net.okocraft.box.feature.command.util.TabCompleter; +import net.okocraft.box.feature.command.util.UserStockHolderOperator; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -16,7 +17,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.concurrent.CompletableFuture; public class ResetCommand extends AbstractCommand { @@ -67,25 +67,14 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { return; } - var targetPlayer = Bukkit.getPlayer(args[1]); - UserStockHolder targetStockHolder; - - if (targetPlayer != null) { - targetStockHolder = BoxProvider.get().getBoxPlayerMap().get(targetPlayer).getUserStockHolder(); - } else { - targetStockHolder = - BoxProvider.get().getUserManager().search(args[1]).join() - .map(BoxProvider.get().getStockManager()::loadUserStock) - .map(CompletableFuture::join) - .orElse(null); - } - - if (targetStockHolder != null) { - confirmationMap.put(sender, targetStockHolder); - sender.sendMessage(BoxAdminMessage.RESET_CONFIRMATION.apply(targetStockHolder)); - } else { - sender.sendMessage(GeneralMessage.ERROR_COMMAND_PLAYER_NOT_FOUND.apply(args[1])); - } + UserStockHolderOperator.create(args[1]) + .supportOffline(true) + .stockHolderOperator(targetStockHolder -> { + confirmationMap.put(sender, targetStockHolder); + sender.sendMessage(BoxAdminMessage.RESET_CONFIRMATION.apply(targetStockHolder)); + }) + .onNotFound(name -> sender.sendMessage(GeneralMessage.ERROR_COMMAND_PLAYER_NOT_FOUND.apply(name))) + .run(); } @Override From 47795698ee62de73d2488413aaade43410a44784 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 12:21:39 +0900 Subject: [PATCH 62/80] build: all project generate Javadocs --- pom.xml | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/pom.xml b/pom.xml index 615232c3fa..f3966dc7e0 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,17 @@ ${project.charset} + + + staging + file://${user.dir}/staging/maven + + + staging-snapshot + file://${user.dir}/staging/maven-snapshot + + + paper-repo @@ -101,6 +112,92 @@ maven-jar-plugin 3.2.0 + + maven-source-plugin + 3.2.1 + + + attach-sources + prepare-package + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.1 + + + attach-docs + prepare-package + + jar + + + true + + + + aggregate-docs + prepare-package + + aggregate + + + + net/okocraft/box/api/** + net/okocraft/box/feature/autostore/model/** + net/okocraft/box/feature/category/CategoryHolder.java + net/okocraft/box/feature/category/model/Category.java + net/okocraft/box/feature/gui/api/** + + + + + + ${java.version} + ${project.charset} + ${project.charset} + ${project.charset} + true + en_US + true + protected + true + + Copyright ©2020-2021 OKOCRAFT.

]]> + + + https://papermc.io/javadocs/paper/1.17/ + https://jd.adventure.kyori.net/api/4.9.2/ + https://javadoc.io/doc/org.jetbrains/annotations/22.0.0/ + https://siroshun09.github.io/ConfigAPI/ + https://siroshun09.github.io/Event4J/ + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.1 + + + aggregate + false + + aggregate + + + + + + From 435fbe7e1d8ecfcace2c269c5b87eda9878caedd Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 12:22:00 +0900 Subject: [PATCH 63/80] ci: skip javadoc generation --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2b2cf9b815..8bd4a3f964 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -15,7 +15,7 @@ jobs: - name: Build with Maven run: | mvn clean - mvn -B package --file pom.xml + mvn -B package --file pom.xml -D maven.javadoc.skip=true - name: Move the artifact run: | mkdir staging From c659e5fd4a156c70ab1925c2ff2e08f082b29c23 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 12:22:16 +0900 Subject: [PATCH 64/80] chore: ignore staging directory --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index b7de36ebec..232fcad141 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,7 @@ buildNumber.properties # Box Wiki ./wiki + +# Box Staging Directory + +staging From 3098dec72fbaf913b04feb976eda8b10666ff8cd Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 12:22:27 +0900 Subject: [PATCH 65/80] chore: update README.md --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index 8802d71deb..e5efd27a21 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,48 @@ Box には以下のような特徴があります。 * `languages/ja_JP.yml` が生成されます。起動後、何も設定しなくても使い始めることができます。 + +## API + +### Javadocs + +- [Latest Release](https://okocraft.github.io/Box/release) +- [Snapshot](https://okocraft.github.io/Box/snapshot) + +### Usage + +#### 1. Add a repository + +```xml + + okocraft-box-repo + https://okocraft.github.io/Box/maven/ + +``` + +```gradle +repositories { + maven { + url 'https://okocraft.github.io/Box/maven/' + } +} +``` + +For snapshot version, use https://okocraft.github.io/Box/maven-snapshot/ + +#### 2. Add to dependencies + +```xml + + net.okocraft.box + api + 4.1.0-SNAPSHOT + provided + +``` + +```gradle +dependencies { + compileOnly 'net.okocraft.box:api:4.1.0-SNAPSHOT' +} +``` From 334c63f6eca17c3428f0c75c75748e75bb6f68e4 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 12:23:12 +0900 Subject: [PATCH 66/80] ci: add deployment.yml --- .github/workflows/deployment.yml | 43 +++++++++++++++++++++++++++ assets/gh-pages.html | 34 ++++++++++++++++++++++ assets/gh-pages.md | 50 ++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 .github/workflows/deployment.yml create mode 100644 assets/gh-pages.html create mode 100644 assets/gh-pages.md diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml new file mode 100644 index 0000000000..a0638237e5 --- /dev/null +++ b/.github/workflows/deployment.yml @@ -0,0 +1,43 @@ +name: Maven Deployment +on: + push: + branches: + - "v4/master" + - "v4/develop" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.4 + - name: Set up JDK 16 + uses: actions/setup-java@v2.3.1 + with: + distribution: 'temurin' + java-version: '16' + cache: 'maven' + - name: Deploy to staging directory + run: | + mvn clean + mvn -B deploy --file pom.xml + - name: Move Javadoc pages to staging directory (release) + if: ${{ github.ref == 'refs/heads/v4/master' }} + run: | + rm -rf staging/release + mv target/site/apidocs staging/release + - name: Move Javadoc pages to staging directory (snapshot) + if: ${{ github.ref == 'refs/heads/v4/develop' }} + run: | + rm -rf staging/snapshot + mv target/site/apidocs staging/snapshot + - name: Create top and not-found pages + run: | + cp -f assets/gh-pages.html staging/index.html + cp -f assets/gh-pages.html staging/404.html + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3.8.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./staging + keep_files: true + allow_empty_commit: true diff --git a/assets/gh-pages.html b/assets/gh-pages.html new file mode 100644 index 0000000000..64020c4957 --- /dev/null +++ b/assets/gh-pages.html @@ -0,0 +1,34 @@ +

Box GitHub Pages

+

Javadocs

+ +

Maven Repository

+

For release

+

Maven

+
<repository>
+    <id>okocraft-box-repo</id>
+    <url>https://okocraft.github.io/Box/maven/</url>
+</repository>
+
+

Gradle

+
repositories {
+    maven {
+        url 'https://okocraft.github.io/Box/maven/'
+    }
+}
+

For snapshot

+

Maven

+
<repository>
+    <id>okocraft-box-snapshot-repo</id>
+    <url>https://okocraft.github.io/Box/maven-snapshot/</url>
+</repository>
+
+

Gradle

+
repositories {
+    maven {
+        url 'https://okocraft.github.io/Box/maven-snapshot/'
+    }
+}
+
diff --git a/assets/gh-pages.md b/assets/gh-pages.md new file mode 100644 index 0000000000..40e6ef84e8 --- /dev/null +++ b/assets/gh-pages.md @@ -0,0 +1,50 @@ +# Box GitHub Pages + +## Javadocs + +- [Latest Release](https://okocraft.github.io/Box/release) +- [Snapshot](https://okocraft.github.io/Box/snapshot) + +## Maven Repository + +### For release + +#### Maven + +```xml + + okocraft-box-repo + https://okocraft.github.io/Box/maven/ + +``` + +#### Gradle + +``` +repositories { + maven { + url 'https://okocraft.github.io/Box/maven/' + } +} +``` + +### For snapshot + +#### Maven + +```xml + + okocraft-box-snapshot-repo + https://okocraft.github.io/Box/maven-snapshot/ + +``` + +#### Gradle + +``` +repositories { + maven { + url 'https://okocraft.github.io/Box/maven-snapshot/' + } +} +``` From feaa33ddf854c14f68568b40a3f5a3a46c07ae7e Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 12:34:38 +0900 Subject: [PATCH 67/80] build(api): remove plugin setting --- api/pom.xml | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index a24b10ab25..d63b116fe1 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -26,41 +26,4 @@ compile
- - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.3.1 - - - attach-docs - prepare-package - - jar - - - - - ${java.version} - ${project.charset} - ${project.charset} - ${project.charset} - true - en_US - true - protected - true - - https://papermc.io/javadocs/paper/1.17/ - https://jd.adventure.kyori.net/api/4.8.1/ - https://javadoc.io/doc/org.jetbrains/annotations/22.0.0/ - https://siroshun09.github.io/ConfigAPI/ - https://siroshun09.github.io/Event4J/ - - - - - From 5880d607e7a475cfea8ef5119af06f6184b47950 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 18:39:34 +0900 Subject: [PATCH 68/80] feat(api): add UserManager#saveUserIfNotExists --- .../box/api/model/manager/UserManager.java | 8 ++++++++ .../box/core/model/manager/BoxUserManager.java | 13 +++++++++++++ .../implementations/yaml/YamlUserStorage.java | 14 ++++++++++++-- .../box/core/storage/model/user/UserStorage.java | 2 ++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/okocraft/box/api/model/manager/UserManager.java b/api/src/main/java/net/okocraft/box/api/model/manager/UserManager.java index 49eceec7dd..ad31483230 100644 --- a/api/src/main/java/net/okocraft/box/api/model/manager/UserManager.java +++ b/api/src/main/java/net/okocraft/box/api/model/manager/UserManager.java @@ -28,6 +28,14 @@ public interface UserManager { */ @NotNull CompletableFuture saveUser(@NotNull BoxUser boxUser); + /** + * Saves the {@link BoxUser} if it doesn't exist. + * + * @param boxUser the user to save + * @return the {@link CompletableFuture} to save the {@link BoxUser} + */ + @NotNull CompletableFuture saveUserIfNotExists(@NotNull BoxUser boxUser); + /** * Searches for {@link BoxUser} with the specified name. * diff --git a/core/src/main/java/net/okocraft/box/core/model/manager/BoxUserManager.java b/core/src/main/java/net/okocraft/box/core/model/manager/BoxUserManager.java index 4394f4ca4a..d4a41bbb23 100644 --- a/core/src/main/java/net/okocraft/box/core/model/manager/BoxUserManager.java +++ b/core/src/main/java/net/okocraft/box/core/model/manager/BoxUserManager.java @@ -48,6 +48,19 @@ public BoxUserManager(@NotNull UserStorage userStorage) { }, executor); } + @Override + public @NotNull CompletableFuture saveUserIfNotExists(@NotNull BoxUser boxUser) { + Objects.requireNonNull(boxUser); + + return CompletableFuture.runAsync(() -> { + try { + userStorage.saveBoxUserIfNotExists(boxUser); + } catch (Exception e) { + throw new RuntimeException("Could not save the box user (" + boxUser.getUUID() + ")", e); + } + }, executor); + } + @Override public @NotNull CompletableFuture> search(@NotNull String name) { Objects.requireNonNull(name); diff --git a/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlUserStorage.java b/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlUserStorage.java index 0dc7a916d1..445210fba7 100644 --- a/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlUserStorage.java +++ b/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlUserStorage.java @@ -35,8 +35,18 @@ public void close() { @Override public void saveBoxUser(@NotNull BoxUser user) throws Exception { - userData.set(user.getUUID().toString(), user.getName().orElse("")); - userData.save(); + if (user.getName().isPresent()) { + userData.set(user.getUUID().toString(), user.getName().get()); + userData.save(); + } + } + + @Override + public void saveBoxUserIfNotExists(@NotNull BoxUser user) throws Exception { + if (user.getName().isPresent() && userData.get(user.getUUID().toString()) == null) { + userData.set(user.getUUID().toString(), user.getName().get()); + userData.save(); + } } @Override diff --git a/core/src/main/java/net/okocraft/box/core/storage/model/user/UserStorage.java b/core/src/main/java/net/okocraft/box/core/storage/model/user/UserStorage.java index 5a6d1c8c80..ae7f20f4b5 100644 --- a/core/src/main/java/net/okocraft/box/core/storage/model/user/UserStorage.java +++ b/core/src/main/java/net/okocraft/box/core/storage/model/user/UserStorage.java @@ -16,5 +16,7 @@ public interface UserStorage { void saveBoxUser(@NotNull BoxUser user) throws Exception; + void saveBoxUserIfNotExists(@NotNull BoxUser user) throws Exception; + @NotNull Optional search(@NotNull String name) throws Exception; } From 7a6b611099c87a070da52511374f3b15163d3345 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 18:41:34 +0900 Subject: [PATCH 69/80] fix(migrator): save a boxuser if it doesn't exist --- .../okocraft/box/migrator/table/PlayerTable.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/migrator/src/main/java/net/okocraft/box/migrator/table/PlayerTable.java b/migrator/src/main/java/net/okocraft/box/migrator/table/PlayerTable.java index ba69fe0af5..e1e7d0d105 100644 --- a/migrator/src/main/java/net/okocraft/box/migrator/table/PlayerTable.java +++ b/migrator/src/main/java/net/okocraft/box/migrator/table/PlayerTable.java @@ -1,7 +1,9 @@ package net.okocraft.box.migrator.table; +import net.okocraft.box.api.BoxProvider; import net.okocraft.box.api.model.user.BoxUser; import net.okocraft.box.migrator.database.Database; +import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -31,7 +33,16 @@ public PlayerTable(@NotNull Database database) { var uuid = UUID.fromString(rs.getString("uuid")); var name = rs.getString("name"); - userIdMap.put(new MigratedBoxUser(uuid, name), id); + var user = new MigratedBoxUser(uuid, name); + + if (Bukkit.getPlayer(uuid) == null) { + try { + BoxProvider.get().getUserManager().saveUserIfNotExists(user).join(); + } catch (Exception ignored) { + } + } + + userIdMap.put(user, id); } }); From a895e4e0862654afb192c95be72d3041aa20601d Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 18:43:17 +0900 Subject: [PATCH 70/80] fix(migrator): catch IAE if the uuid is invalid --- .../net/okocraft/box/migrator/table/PlayerTable.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/migrator/src/main/java/net/okocraft/box/migrator/table/PlayerTable.java b/migrator/src/main/java/net/okocraft/box/migrator/table/PlayerTable.java index e1e7d0d105..4d325b3789 100644 --- a/migrator/src/main/java/net/okocraft/box/migrator/table/PlayerTable.java +++ b/migrator/src/main/java/net/okocraft/box/migrator/table/PlayerTable.java @@ -30,7 +30,17 @@ public PlayerTable(@NotNull Database database) { database.execute("SELECT id, uuid, name FROM box_players", rs -> { while (rs.next()) { var id = rs.getInt("id"); - var uuid = UUID.fromString(rs.getString("uuid")); + + var strUuid = rs.getString("uuid"); + UUID uuid; + + try { + uuid = UUID.fromString(strUuid); + } catch (IllegalArgumentException e) { + BoxProvider.get().getLogger().warning("Could not parse a string to uuid: " + strUuid); + continue; + } + var name = rs.getString("name"); var user = new MigratedBoxUser(uuid, name); From eb116951a28e7e1d4dd3533ba37690c833db43b3 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 18:46:13 +0900 Subject: [PATCH 71/80] feat(api): add BoxPlayerMap#isLoaded --- .../java/net/okocraft/box/api/player/BoxPlayerMap.java | 8 ++++++++ .../net/okocraft/box/core/player/BoxPlayerMapImpl.java | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/api/src/main/java/net/okocraft/box/api/player/BoxPlayerMap.java b/api/src/main/java/net/okocraft/box/api/player/BoxPlayerMap.java index 72869b3090..95680dcdc7 100644 --- a/api/src/main/java/net/okocraft/box/api/player/BoxPlayerMap.java +++ b/api/src/main/java/net/okocraft/box/api/player/BoxPlayerMap.java @@ -8,6 +8,14 @@ */ public interface BoxPlayerMap { + /** + * Checks if the {@link BoxPlayer} of specified player is loaded. + * + * @param player the {@link Player} to check + * @return {@code true} if loaded, {@code false} otherwise + */ + boolean isLoaded(@NotNull Player player); + /** * Gets the {@link BoxPlayer}. * diff --git a/core/src/main/java/net/okocraft/box/core/player/BoxPlayerMapImpl.java b/core/src/main/java/net/okocraft/box/core/player/BoxPlayerMapImpl.java index 7cf385aae9..2e2b577d61 100644 --- a/core/src/main/java/net/okocraft/box/core/player/BoxPlayerMapImpl.java +++ b/core/src/main/java/net/okocraft/box/core/player/BoxPlayerMapImpl.java @@ -32,6 +32,11 @@ public BoxPlayerMapImpl(@NotNull UserManager userManager, @NotNull StockManager this.stockManager = stockManager; } + @Override + public boolean isLoaded(@NotNull Player player) { + return playerMap.containsKey(player); + } + @Override public @NotNull BoxPlayer get(@NotNull Player player) { Objects.requireNonNull(player); From e384cb7555ce1f65c646bfdd6ae85c6df7db0629 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 19:11:35 +0900 Subject: [PATCH 72/80] change: checks if the player is loaded --- .../feature/autostore/listener/ItemListener.java | 13 +++++++------ .../command/util/UserStockHolderOperator.java | 5 +++-- .../notifier/listener/StockHolderListener.java | 12 +++++++----- .../box/feature/stick/listener/StickListener.java | 8 +++++++- .../okocraft/box/migrator/table/MasterTable.java | 6 ++++-- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/features/autostore/src/main/java/net/okocraft/box/feature/autostore/listener/ItemListener.java b/features/autostore/src/main/java/net/okocraft/box/feature/autostore/listener/ItemListener.java index 0cb3c6c0f5..ed1141e4b5 100644 --- a/features/autostore/src/main/java/net/okocraft/box/feature/autostore/listener/ItemListener.java +++ b/features/autostore/src/main/java/net/okocraft/box/feature/autostore/listener/ItemListener.java @@ -50,6 +50,12 @@ private boolean processEvent(@NotNull Player player, @NotNull ItemStack item) { return false; } + var playerMap = BoxProvider.get().getBoxPlayerMap(); + + if (!playerMap.isLoaded(player)) { + return false; + } + var setting = AutoStoreSettingContainer.INSTANCE.get(player); if (!setting.isEnabled() || !player.hasPermission("box.autostore")) { @@ -63,12 +69,7 @@ private boolean processEvent(@NotNull Player player, @NotNull ItemStack item) { } if (setting.shouldAutoStore(boxItem.get())) { - BoxProvider.get() - .getBoxPlayerMap() - .get(player) - .getCurrentStockHolder() - .increase(boxItem.get(), item.getAmount()); - + playerMap.get(player).getCurrentStockHolder().increase(boxItem.get(), item.getAmount()); player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.2f, (float) Math.random() + 1.0f); return true; } else { diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/util/UserStockHolderOperator.java b/features/command/src/main/java/net/okocraft/box/feature/command/util/UserStockHolderOperator.java index 772b3899d3..8a457a36ce 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/util/UserStockHolderOperator.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/util/UserStockHolderOperator.java @@ -67,9 +67,10 @@ public void run() { } var player = uuid != null ? Bukkit.getPlayer(uuid) : Bukkit.getPlayer(argument); + var playerMap = BoxProvider.get().getBoxPlayerMap(); - if (player != null) { - return BoxProvider.get().getBoxPlayerMap().get(player).getUserStockHolder(); + if (player != null && playerMap.isLoaded(player)) { + return playerMap.get(player).getUserStockHolder(); } if (supportOffline) { diff --git a/features/notifier/src/main/java/net/okocraft/box/feature/notifier/listener/StockHolderListener.java b/features/notifier/src/main/java/net/okocraft/box/feature/notifier/listener/StockHolderListener.java index b01a27d3df..e5632e2b9c 100644 --- a/features/notifier/src/main/java/net/okocraft/box/feature/notifier/listener/StockHolderListener.java +++ b/features/notifier/src/main/java/net/okocraft/box/feature/notifier/listener/StockHolderListener.java @@ -31,13 +31,15 @@ public class StockHolderListener { private Key listenerKey; public void register(@NotNull Key listenerKey) { - for (var player : Bukkit.getOnlinePlayers()) { - var boxPlayer = BoxProvider.get().getBoxPlayerMap().get(player); + var playerMap = BoxProvider.get().getBoxPlayerMap(); - var stockHolder = boxPlayer.getCurrentStockHolder(); + for (var player : Bukkit.getOnlinePlayers()) { + if (playerMap.isLoaded(player)) { + var stockHolder = playerMap.get(player).getCurrentStockHolder(); - if (!(stockHolder instanceof UserStockHolder)) { - addToMap(stockHolder.getUUID(), player.getUniqueId()); + if (!(stockHolder instanceof UserStockHolder)) { + addToMap(stockHolder.getUUID(), player.getUniqueId()); + } } } diff --git a/features/stick/src/main/java/net/okocraft/box/feature/stick/listener/StickListener.java b/features/stick/src/main/java/net/okocraft/box/feature/stick/listener/StickListener.java index 0297197bc6..d60f324474 100644 --- a/features/stick/src/main/java/net/okocraft/box/feature/stick/listener/StickListener.java +++ b/features/stick/src/main/java/net/okocraft/box/feature/stick/listener/StickListener.java @@ -181,7 +181,13 @@ private boolean tryConsumingStock(@NotNull Player player, @NotNull ItemStack ite return false; } - var stockHolder = BoxProvider.get().getBoxPlayerMap().get(player).getCurrentStockHolder(); + var playerMap = BoxProvider.get().getBoxPlayerMap(); + + if (!playerMap.isLoaded(player)) { + return false; + } + + var stockHolder = playerMap.get(player).getCurrentStockHolder(); if (0 < stockHolder.getAmount(boxItem.get())) { stockHolder.decrease(boxItem.get()); diff --git a/migrator/src/main/java/net/okocraft/box/migrator/table/MasterTable.java b/migrator/src/main/java/net/okocraft/box/migrator/table/MasterTable.java index ed3d2673d4..9cce1d355f 100644 --- a/migrator/src/main/java/net/okocraft/box/migrator/table/MasterTable.java +++ b/migrator/src/main/java/net/okocraft/box/migrator/table/MasterTable.java @@ -38,8 +38,10 @@ public void migrate(@NotNull BoxUser user, int id) { UserStockHolder stockHolder; AutoStoreSetting autoStoreSetting; - if (player != null) { - stockHolder = BoxProvider.get().getBoxPlayerMap().get(player).getUserStockHolder(); + var playerMap = BoxProvider.get().getBoxPlayerMap(); + + if (player != null && playerMap.isLoaded(player)) { + stockHolder = playerMap.get(player).getUserStockHolder(); autoStoreSetting = AutoStoreSettingContainer.INSTANCE.get(player); } else { stockHolder = BoxProvider.get().getStockManager().loadUserStock(user).join(); From 3e00cc59f0100516241cc7b7f0c6d81acc6c6826 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 19:12:19 +0900 Subject: [PATCH 73/80] feat(api): add GeneralMessage#ERROR_PLAYER_NOT_LOADED and GeneralMessage#ERROR_TARGET_PLAYER_NOT_LOADED --- .../box/api/message/GeneralMessage.java | 18 ++++++++++++++++++ bundle/src/main/resources/en.yml | 3 +++ bundle/src/main/resources/ja_JP.yml | 3 +++ 3 files changed, 24 insertions(+) diff --git a/api/src/main/java/net/okocraft/box/api/message/GeneralMessage.java b/api/src/main/java/net/okocraft/box/api/message/GeneralMessage.java index cb41a555cb..83ec649d2a 100644 --- a/api/src/main/java/net/okocraft/box/api/message/GeneralMessage.java +++ b/api/src/main/java/net/okocraft/box/api/message/GeneralMessage.java @@ -3,6 +3,7 @@ import net.kyori.adventure.text.Component; import net.okocraft.box.api.message.argument.SingleArgument; import org.bukkit.World; +import org.bukkit.entity.Player; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; @@ -80,4 +81,21 @@ public final class GeneralMessage { .args(text(world.getName(), AQUA)) .color(RED) .build(); + + /** + * A message sent when the player is not loaded. + */ + public static final Component ERROR_PLAYER_NOT_LOADED = + translatable("box.error.player-data.not-loaded.self", RED); + + /** + * A message sent when the targeted player is not loaded. + */ + public static final SingleArgument ERROR_TARGET_PLAYER_NOT_LOADED = + target -> + translatable() + .key("box.error.player-data.not-loaded.other") + .args(text(target.getName(), AQUA)) + .color(RED) + .build(); } diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index a1f410ad00..ce5f0d2a82 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -299,6 +299,9 @@ box: player-data: load-on-join: "Failed to load the stock data. Please contact the administrator." save: "Failed to save the stock data. Please contact the administrator." + not-loaded: + self: "Your player data is not loaded. Please contact the administrator." + other: "Player {0}''s data is not loaded. Please contact the administrator." command: only-player: "This command can only be executed by the player in game." no-argument: "There is no argument." diff --git a/bundle/src/main/resources/ja_JP.yml b/bundle/src/main/resources/ja_JP.yml index 1ac733919f..56360e8995 100644 --- a/bundle/src/main/resources/ja_JP.yml +++ b/bundle/src/main/resources/ja_JP.yml @@ -299,6 +299,9 @@ box: player-data: load-on-join: "Box の在庫データの読み込みに失敗しました。管理者にお問い合わせください。" save: "Box の在庫データの保存に失敗しました。管理者にお問い合わせください。" + not-loaded: + self: "あなたのプレイヤーデータが読み込まれていません。管理者にお問い合わせください。" + other: "プレイヤー {0} のデータが読み込まれていません。管理者にお問い合わせください。" command: only-player: "ゲーム内のプレイヤーのみ実行できます。" no-argument: "引数がありません。" From eda28b68657723337e6fc49849477e327a429f4c Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 19:13:40 +0900 Subject: [PATCH 74/80] change(command): prevents execution when the player data hasn't been loaded --- .../box/core/command/BoxCommandImpl.java | 16 +++++++++++ .../box/feature/command/box/GiveCommand.java | 17 +++++++----- .../command/boxadmin/InfinityCommand.java | 27 +++++++++++++------ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/net/okocraft/box/core/command/BoxCommandImpl.java b/core/src/main/java/net/okocraft/box/core/command/BoxCommandImpl.java index 0f0712e5ff..c442882e31 100644 --- a/core/src/main/java/net/okocraft/box/core/command/BoxCommandImpl.java +++ b/core/src/main/java/net/okocraft/box/core/command/BoxCommandImpl.java @@ -1,7 +1,11 @@ package net.okocraft.box.core.command; import net.kyori.adventure.text.Component; +import net.okocraft.box.api.BoxProvider; import net.okocraft.box.api.command.base.BoxCommand; +import net.okocraft.box.api.message.GeneralMessage; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; @@ -37,4 +41,16 @@ public class BoxCommandImpl extends BaseCommand implements BoxCommand { .append(translatable("box.command.box.help.description", GRAY)) .build(); } + + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { + if (sender instanceof Player player) { + if (!BoxProvider.get().getBoxPlayerMap().isLoaded(player)) { + sender.sendMessage(GeneralMessage.ERROR_PLAYER_NOT_LOADED); + return; + } + } + + super.onCommand(sender, args); + } } diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/box/GiveCommand.java b/features/command/src/main/java/net/okocraft/box/feature/command/box/GiveCommand.java index 4a2a31e988..c263f4d349 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/box/GiveCommand.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/box/GiveCommand.java @@ -89,13 +89,18 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { amount = 1; } - var currentSender = stockHolder.decrease(boxItem, amount); - var currentTarget = - BoxProvider.get().getBoxPlayerMap().get(target) - .getCurrentStockHolder().increase(boxItem, amount); + var playerMap = BoxProvider.get().getBoxPlayerMap(); - player.sendMessage(BoxMessage.GIVE_SUCCESS_SENDER.apply(target.getName(), boxItem, amount, currentSender)); - target.sendMessage(BoxMessage.GIVE_SUCCESS_TARGET.apply(player.getName(), boxItem, amount, currentTarget)); + if (!playerMap.isLoaded(target)) { + sender.sendMessage(GeneralMessage.ERROR_TARGET_PLAYER_NOT_LOADED.apply(target)); + return; + } + + var senderCurrent = stockHolder.decrease(boxItem, amount); + var targetCurrent = playerMap.get(target).getCurrentStockHolder().increase(boxItem, amount); + + player.sendMessage(BoxMessage.GIVE_SUCCESS_SENDER.apply(target.getName(), boxItem, amount, senderCurrent)); + target.sendMessage(BoxMessage.GIVE_SUCCESS_TARGET.apply(player.getName(), boxItem, amount, targetCurrent)); } @Override diff --git a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/InfinityCommand.java b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/InfinityCommand.java index 5b15173f42..6e936f4c73 100644 --- a/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/InfinityCommand.java +++ b/features/command/src/main/java/net/okocraft/box/feature/command/boxadmin/InfinityCommand.java @@ -7,7 +7,6 @@ import net.okocraft.box.api.model.item.BoxItem; import net.okocraft.box.api.model.stock.StockData; import net.okocraft.box.api.model.stock.StockHolder; -import net.okocraft.box.api.player.BoxPlayer; import net.okocraft.box.feature.command.message.BoxAdminMessage; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -28,27 +27,41 @@ public InfinityCommand() { @Override public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { - BoxPlayer boxPlayer; + Player target; + boolean self; if (1 < args.length) { - var target = Bukkit.getPlayer(args[1]); + target = Bukkit.getPlayer(args[1]); if (target == null) { sender.sendMessage(GeneralMessage.ERROR_COMMAND_PLAYER_NOT_FOUND.apply(args[1])); return; - } else { - boxPlayer = BoxProvider.get().getBoxPlayerMap().get(target); } + + self = false; } else { if (sender instanceof Player player) { - boxPlayer = BoxProvider.get().getBoxPlayerMap().get(player); + target = player; } else { sender.sendMessage(GeneralMessage.ERROR_COMMAND_NOT_ENOUGH_ARGUMENT); sender.sendMessage(getHelp()); return; } + + self = true; + } + + var playerMap = BoxProvider.get().getBoxPlayerMap(); + + if (!playerMap.isLoaded(target)) { + sender.sendMessage(self ? + GeneralMessage.ERROR_PLAYER_NOT_LOADED : + GeneralMessage.ERROR_TARGET_PLAYER_NOT_LOADED.apply(target) + ); } + var boxPlayer = playerMap.get(target); + boolean enabled; if (boxPlayer.getCurrentStockHolder() instanceof InfinityStockHolder) { @@ -59,8 +72,6 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String[] args) { enabled = true; } - var target = boxPlayer.getPlayer(); - if (sender instanceof Player player && player.getUniqueId().equals(target.getUniqueId())) { sender.sendMessage(BoxAdminMessage.INFINITY_MODE_TOGGLE.apply(enabled)); } else { From 578e90b7e1a6f1cd8e50d8a704dc7c5217ddb763 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 20:11:49 +0900 Subject: [PATCH 75/80] chore(bundle): fix 'stock' --- bundle/src/main/resources/en.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index e53e26c43b..dd2530f0fe 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -174,17 +174,17 @@ box: description: "Changes item name" reset: success: - sender: "All stocks of player {0} has been reset." - target: "All stocks has been reset by {0}." + sender: "Stock of all {0}''s items has been reset." + target: "Stock of all items has been reset for {0}." cancel: "Cancelled reset operation." confirmation: - info: "Reset all stocks of player {0}." + info: "Reset stock of all {0}''s items." warning: "This operation cannot be undone." confirm-command: "To confirm, run {0}." cancel-command: "To cancel, run {0}." help: command-line: "/boxadmin reset " - description: "Resets all stocks" + description: "Resets all stock" set: success: sender: "Player {0}''s item {1} has been set to {2}." From 77e3ce60ea52123ea3c6d53dda5ae3c36423be02 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 20:43:13 +0900 Subject: [PATCH 76/80] chore(bundle): stocks -> stock --- bundle/src/main/resources/en.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bundle/src/main/resources/en.yml b/bundle/src/main/resources/en.yml index 21d72fca74..4170bf7804 100644 --- a/bundle/src/main/resources/en.yml +++ b/bundle/src/main/resources/en.yml @@ -124,7 +124,7 @@ box: is-air: "You have no item in your main hand." item-not-registered: "The item in your main hand is not registered." name: "Item Name: {0}" - stock: "Current stocks: {0}" + stock: "Current stock: {0}" help: command-line: "/box iteminfo [item]" description: "Shows information about the item you have or specify." @@ -138,7 +138,7 @@ box: target: "{0} give you {1}x{2} (Now {3})." help: command-line: "/boxadmin give " - description: "Increases stocks" + description: "Increases stock" infinity: enabled: "Enabled" disabled: "Disabled" @@ -191,14 +191,14 @@ box: target: "Item {1} has been set to {2} by {0}." help: command-line: "/boxadmin set " - description: "Sets stocks" + description: "Sets stock" take: success: sender: "Took {1}x{2} from player {0} (Now {3})." target: "{0} took {1}x{2} (Now {3})." help: command-line: "/boxadmin take " - description: "Decreases stocks" + description: "Decreases stock" version: info: "Box {0}" help: @@ -217,7 +217,7 @@ box: ingredients: "Ingredients" shift-click-to-show-details: "Shift + click to show details" shift-click-to-show-recipes: "Shift + click to show recipes" - current-stock: "Current stocks: {0}" + current-stock: "Current stock: {0}" destination: display-name: "Destination" inventory: "Inventory" @@ -279,7 +279,7 @@ box: display-name: "Storage mode" left-click-to-deposit: "Press LMB to deposit {0} items" right-click-to-withdraw: "Press RMB to withdraw {0} items" - current-stock: "Current stocks: {0}" + current-stock: "Current stock: {0}" deposit-all: display-name: "Deposits all items" lore-1: "Shift + click to deposit" From 4984b60a49b6493ee51a02efa6126f4dbb93fef6 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 20:43:38 +0900 Subject: [PATCH 77/80] docs(api): stocks -> stock --- .../java/net/okocraft/box/api/model/stock/StockHolder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/okocraft/box/api/model/stock/StockHolder.java b/api/src/main/java/net/okocraft/box/api/model/stock/StockHolder.java index 2ae79b9891..530cc5a0fb 100644 --- a/api/src/main/java/net/okocraft/box/api/model/stock/StockHolder.java +++ b/api/src/main/java/net/okocraft/box/api/model/stock/StockHolder.java @@ -8,7 +8,7 @@ import java.util.UUID; /** - * An interface that holds stocks. + * An interface that holds stock. *

* The implementation of this interface must be thread-safe. */ @@ -86,7 +86,7 @@ public interface StockHolder { @NotNull @Unmodifiable Collection getStockedItems(); /** - * Gets the current stocks as a {@link StockData} collection. + * Gets the current stock as a {@link StockData} collection. * * @return the collection of {@link StockData} */ From 785e6e23cae8c8f3a1550efb07a417e72fbe971a Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Fri, 15 Oct 2021 20:47:14 +0900 Subject: [PATCH 78/80] fix(core): stocks -> stock --- .../yaml/YamlStockStorage.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlStockStorage.java b/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlStockStorage.java index 01c75e2a1f..d99a9abf13 100644 --- a/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlStockStorage.java +++ b/core/src/main/java/net/okocraft/box/core/storage/implementations/yaml/YamlStockStorage.java @@ -9,8 +9,10 @@ import net.okocraft.box.core.storage.model.stock.StockStorage; import org.jetbrains.annotations.NotNull; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; class YamlStockStorage implements StockStorage { @@ -18,11 +20,29 @@ class YamlStockStorage implements StockStorage { private final Path stockDirectory; YamlStockStorage(@NotNull Path rootDirectory) { - this.stockDirectory = rootDirectory.resolve("stocks"); + this.stockDirectory = rootDirectory.resolve("stock"); } @Override public void init() throws Exception { + if (Files.exists(stockDirectory)) { + return; + } + + var parent = stockDirectory.getParent(); + + if (parent != null) { + var oldStockDirectory = parent.resolve("stocks"); + + if (Files.exists(oldStockDirectory)) { + try { + Files.move(oldStockDirectory, stockDirectory, StandardCopyOption.REPLACE_EXISTING); + return; + } catch (IOException ignored) { + } + } + } + Files.createDirectories(stockDirectory); } From 4f64cd42e353cdc86036f20a7939a0b5bf65b959 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Oct 2021 04:33:49 +0000 Subject: [PATCH 79/80] build(deps): bump actions/checkout from 2.3.4 to 2.3.5 Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.3.5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2.3.4...v2.3.5) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/deployment.yml | 2 +- .github/workflows/maven.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index a0638237e5..e5074ca863 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -9,7 +9,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@v2.3.5 - name: Set up JDK 16 uses: actions/setup-java@v2.3.1 with: diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8bd4a3f964..47b560177a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -5,7 +5,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@v2.3.5 - name: Set up JDK 16 uses: actions/setup-java@v2.3.1 with: From 724cda329a01544b9acd95607d23348142707303 Mon Sep 17 00:00:00 2001 From: Siroshun09 Date: Sat, 16 Oct 2021 14:36:43 +0900 Subject: [PATCH 80/80] build(api): update event4j to 2.1.1 --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index d63b116fe1..2750007829 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -22,7 +22,7 @@ com.github.siroshun09.event4j event4j - 2.1.0 + 2.1.1 compile