diff --git a/gradle.properties b/gradle.properties index 4d70fea4..ce8233a3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,4 +11,4 @@ fabric-api=0.92.0+1.20.1 # Is the project currently in a snapshot state? snapshot = false -release-candidate = 1 +release-candidate = 2 diff --git a/gradle/libs.versions.yml b/gradle/libs.versions.yml index a6bef649..456df50b 100644 --- a/gradle/libs.versions.yml +++ b/gradle/libs.versions.yml @@ -39,6 +39,11 @@ versions: # Utility gson: 2.10.1 + # Adventure + adventure: 4.16.0 + adventure-fabric: 5.9.0 # 1.20.1 + examination: 1.3.0 + dependencies: # build-logic @@ -186,6 +191,44 @@ dependencies: name: cloud-processors-common version: { ref: cloud-new } + # Adventure + adventure: + group: net.kyori + name: adventure-api + version: { ref: adventure } + adventureKey: + group: net.kyori + name: adventure-key + version: { ref: adventure } + adventureNBT: + group: net.kyori + name: adventure-key + version: { ref: adventure } + adventureSerializerPlain: + group: net.kyori + name: adventure-text-serializer-plain + version: { ref: adventure } + adventureSerializerLegacy: + group: net.kyori + name: adventure-text-serializer-legacy + version: { ref: adventure } + adventureSerializerGson: + group: net.kyori + name: adventure-text-serializer-gson + version: { ref: adventure } + adventureMinimessage: + group: net.kyori + name: adventure-text-minimessage + version: { ref: adventure } + adventureLoggerSlf4j: + group: net.kyori + name: adventure-text-logger-slf4j + version: { ref: adventure } + adventureFabric: + group: net.kyori + name: adventure-platform-fabric + version: { ref: adventure-fabric } + # Utilities gson: group: com.google.code.gson diff --git a/launchers/fabric/build.gradle.kts b/launchers/fabric/build.gradle.kts index b4b088d6..b0645b07 100644 --- a/launchers/fabric/build.gradle.kts +++ b/launchers/fabric/build.gradle.kts @@ -55,7 +55,8 @@ dependencies { libs.cloudFabric, libs.cloudMinecraftExtras, libs.cloudConfirmations, - libs.cloudProcessorsCommon + libs.cloudProcessorsCommon, + libs.adventureFabric ).forEach { include(it) } modCompileOnly("eu.pb4:placeholder-api:2.1.3+1.20.1") diff --git a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/AdventureClickCallbackProvider.java b/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/AdventureClickCallbackProvider.java deleted file mode 100644 index 84da0db1..00000000 --- a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/AdventureClickCallbackProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of Impactor, licensed under the MIT License (MIT). - * - * Copyright (c) 2018-2022 NickImpact - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package net.impactdev.impactor.minecraft.utility.adventure; - -import com.google.auto.service.AutoService; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.event.ClickCallback; -import net.kyori.adventure.text.event.ClickEvent; -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings("UnstableApiUsage") -@AutoService(ClickCallback.Provider.class) -public final class AdventureClickCallbackProvider implements ClickCallback.Provider { - - @Override - public @NotNull ClickEvent create(@NotNull ClickCallback callback, ClickCallback.@NotNull Options options) { - return ClickEvent.runCommand(ClickCallbackRegistry.INSTANCE.register(callback, options)); - } - -} diff --git a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/AdventureComponentLoggerProvider.java b/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/AdventureComponentLoggerProvider.java deleted file mode 100644 index beb0dc39..00000000 --- a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/AdventureComponentLoggerProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of Impactor, licensed under the MIT License (MIT). - * - * Copyright (c) 2018-2022 NickImpact - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package net.impactdev.impactor.minecraft.utility.adventure; - -import com.google.auto.service.AutoService; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; -import net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider; -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import net.kyori.adventure.translation.GlobalTranslator; -import org.jetbrains.annotations.NotNull; -import org.slf4j.LoggerFactory; - -import java.util.Locale; - -@SuppressWarnings("UnstableApiUsage") -@AutoService(ComponentLoggerProvider.class) -public final class AdventureComponentLoggerProvider implements ComponentLoggerProvider { - - @Override - public @NotNull ComponentLogger logger(@NotNull LoggerHelper helper, @NotNull String name) { - return helper.delegating(LoggerFactory.getLogger(name), this::serialize); - } - - private String serialize(final Component message) { - final Component rendered = GlobalTranslator.render(message, Locale.getDefault()); - return PlainTextComponentSerializer.plainText().serialize(rendered); - } - -} diff --git a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/ClickCallbackCommand.java b/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/ClickCallbackCommand.java deleted file mode 100644 index 5e17719c..00000000 --- a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/ClickCallbackCommand.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * This file is part of Impactor, licensed under the MIT License (MIT). - * - * Copyright (c) 2018-2022 NickImpact - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package net.impactdev.impactor.minecraft.utility.adventure; - -import net.impactdev.impactor.api.commands.CommandSource; -import net.impactdev.impactor.api.utility.Context; -import net.impactdev.impactor.core.translations.internal.ImpactorTranslations; -import net.kyori.adventure.text.event.ClickCallback; -import org.incendo.cloud.annotations.Argument; -import org.incendo.cloud.annotations.Command; -import org.incendo.cloud.annotations.processing.CommandContainer; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.time.Instant; -import java.util.UUID; - -@CommandContainer -public final class ClickCallbackCommand { - - public static final String COMMAND_ID = "impactor-callback"; - - @Command(COMMAND_ID + " [id]") - public void execute(final @NotNull CommandSource source, final @Argument("id") UUID uuid) { - @Nullable - final ClickCallbackRegistry.CallbackRegistration registration = ClickCallbackRegistry.INSTANCE - .query(uuid) - .orElse(null); - - if(registration == null) { - ImpactorTranslations.INVALID_CLICK_CALLBACK.send(source, Context.empty()); - return; - } - - boolean expired = false; - boolean allow = true; - - // Check use count - final int allowed = registration.options().uses(); - if(allowed != ClickCallback.UNLIMITED_USES) { - final int useCount = registration.useCount().incrementAndGet(); - if(useCount >= allowed) { - expired = true; - allow = !(useCount > allowed); - } - } - - // Check duration expiry - final Instant now = Instant.now(); - if(now.isAfter(registration.expiration())) { - expired = true; - allow = false; - } - - if(expired) { - ClickCallbackRegistry.INSTANCE.invalidate(uuid); - } - - if(allow) { - registration.callback().accept(source); - } else { - ImpactorTranslations.INVALID_CLICK_CALLBACK.send(source, Context.empty()); - } - } - -} diff --git a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/ClickCallbackRegistry.java b/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/ClickCallbackRegistry.java deleted file mode 100644 index ac4565ea..00000000 --- a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/utility/adventure/ClickCallbackRegistry.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is part of Impactor, licensed under the MIT License (MIT). - * - * Copyright (c) 2018-2022 NickImpact - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package net.impactdev.impactor.minecraft.utility.adventure; - - -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.RemovalListener; -import net.impactdev.impactor.core.plugin.BaseImpactorPlugin; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.event.ClickCallback; - -import java.time.Instant; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -public final class ClickCallbackRegistry { - - public static final ClickCallbackRegistry INSTANCE = new ClickCallbackRegistry(); - - private final Cache registrations = Caffeine.newBuilder() - .expireAfterWrite(24, TimeUnit.HOURS) - .maximumSize(1024) - .removalListener((RemovalListener) (key, value, cause) -> BaseImpactorPlugin.instance() - .logger() - .debug("Removing callback " + key + " from cache with reason: " + cause.name()) - ) - .build(); - - record CallbackRegistration(ClickCallback.Options options, ClickCallback callback, Instant expiration, AtomicInteger useCount) {} - - private ClickCallbackRegistry() {} - - public String register(final ClickCallback callback, final ClickCallback.Options options) { - final UUID id = UUID.randomUUID(); - final CallbackRegistration registration = new CallbackRegistration( - options, - callback, - Instant.now().plus(options.lifetime()), - new AtomicInteger() - ); - - this.registrations.put(id, registration); - - return "/" + ClickCallbackCommand.COMMAND_ID + " " + id; - } - - Optional query(UUID uuid) { - return Optional.ofNullable(this.registrations.getIfPresent(uuid)); - } - - void invalidate(UUID uuid) { - this.registrations.invalidate(uuid); - } -}