diff --git a/build.gradle b/build.gradle index 701576d8..fdac7054 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ import org.apache.tools.ant.filters.ReplaceTokens plugins { id 'io.github.goooler.shadow' version '8.1.7' id 'org.cadixdev.licenser' version '0.6.1' apply false + id 'fabric-loom' version "$fabric_loom_version" apply false id 'org.ajoberstar.grgit' version '5.2.2' id 'checkstyle' id 'maven-publish' @@ -70,10 +71,6 @@ allprojects { repositories { mavenLocal() mavenCentral() - maven { - url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' - mavenContent { snapshotsOnly() } - } maven { url 'https://repo.william278.net/releases/' } maven { url 'https://maven.fabricmc.net/' } maven { url 'https://libraries.minecraft.net/' } @@ -87,6 +84,7 @@ allprojects { maven { url 'https://repo.alessiodp.com/releases/' } maven { url 'https://repo.essentialsx.net/releases/' } maven { url 'https://repo.mikeprimm.com/' } + maven { url 'https://maven.impactdev.net/repository/development' } maven { url 'https://jitpack.io' } } @@ -121,6 +119,11 @@ allprojects { } subprojects { + if (['fabric'].contains(project.name)) { + apply plugin: 'fabric-loom' + compileJava.options.release.set 21 + } + version rootProject.version archivesBaseName = "${rootProject.name}-${project.name.capitalize()}" @@ -133,10 +136,6 @@ subprojects { archiveClassifier.set('') } - if (['fabric'].contains(project.name)) { - compileJava.options.release.set 21 - } - // API publishing if (['common', 'bukkit', 'fabric', 'sponge'].contains(project.name)) { java { @@ -183,8 +182,8 @@ subprojects { mavenJavaFabric(MavenPublication) { groupId = 'net.william278.huskhomes' artifactId = 'huskhomes-fabric' - version = "$rootProject.version" - artifact shadowJar + version = "$rootProject.version+${fabric_minecraft_version}" + artifact remapJar artifact sourcesJar artifact javadocJar } @@ -214,16 +213,20 @@ logger.lifecycle("Building HuskHomes ${version} by William278") @SuppressWarnings('GrMethodMayBeStatic') def versionMetadata() { + // Require grgit if (grgit == null) { - return '-' + System.getenv("GITHUB_RUN_NUMBER") ? 'build.' + System.getenv("GITHUB_RUN_NUMBER") : 'unknown' + return '-unknown' } - // Get if there is a tag for this commit + // If unclean, return the last commit hash with -indev + if (!grgit.status().clean) { + return '-' + grgit.head().abbreviatedId + '-indev' + } + + // Otherwise if this matches a tag, return nothing def tag = grgit.tag.list().find { it.commit.id == grgit.head().id } if (tag != null) { return '' } - - // Otherwise, get the last commit hash and if it's a clean head - return '-' + grgit.head().abbreviatedId + (grgit.status().clean ? '' : '-indev') + return '-' + grgit.head().abbreviatedId } \ No newline at end of file diff --git a/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java b/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java index 206eb95c..c2b10f52 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java +++ b/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java @@ -38,6 +38,8 @@ import java.util.Objects; * and process teleports * *

Retrieve an instance of the API class via {@link #getInstance()}. + * + * @since 3.0 */ @SuppressWarnings("unused") public class HuskHomesAPI extends BaseHuskHomesAPI { @@ -72,10 +74,10 @@ public class HuskHomesAPI extends BaseHuskHomesAPI { } /** - * Returns an {@link OnlineUser} instance for the given bukkit {@link Player}. + * Returns an {@link OnlineUser} instance for the given Bukkit {@link Player}. * - * @param player the bukkit player to get the {@link User} instance for - * @return the {@link OnlineUser} instance for the given bukkit {@link Player} + * @param player the Bukkit player to get the {@link User} instance for + * @return the {@link OnlineUser} instance for the given Bukkit {@link Player} * @since 3.0 */ @NotNull @@ -84,10 +86,10 @@ public class HuskHomesAPI extends BaseHuskHomesAPI { } /** - * Returns the bukkit {@link Player} being represented by the given {@link OnlineUser}. + * Returns the Bukkit {@link Player} being represented by the given {@link OnlineUser}. * - * @param user {@link OnlineUser} to get the bukkit player from - * @return the bukkit {@link Player} being represented by the given {@link OnlineUser} + * @param user {@link OnlineUser} to get the Bukkit player from + * @return the Bukkit {@link Player} being represented by the given {@link OnlineUser} * @since 3.0 */ @NotNull @@ -96,10 +98,10 @@ public class HuskHomesAPI extends BaseHuskHomesAPI { } /** - * Returns the bukkit {@link Location} being represented by the given {@link Position}. + * Returns the Bukkit {@link Location} being represented by the given {@link Position}. * - * @param position the {@link Position} to get the bukkit location from - * @return the bukkit {@link Location} being represented by the given {@link Position} + * @param position the {@link Position} to get the Bukkit location from + * @return the Bukkit {@link Location} being represented by the given {@link Position} * @since 3.0 */ @Nullable @@ -108,10 +110,10 @@ public class HuskHomesAPI extends BaseHuskHomesAPI { } /** - * Returns a {@link Location} instance for the given bukkit {@link Location} on the server. + * Returns a {@link Location} instance for the given Bukkit {@link Location} on the server. * - * @param location the bukkit location to get the {@link Location} instance for - * @return the {@link Location} instance for the given bukkit {@link Location} + * @param location the Bukkit location to get the {@link Location} instance for + * @return the {@link Location} instance for the given Bukkit {@link Location} * @since 3.0 */ @Nullable @@ -120,11 +122,11 @@ public class HuskHomesAPI extends BaseHuskHomesAPI { } /** - * Returns a {@link Position} instance for the given bukkit {@link Location} on the server. + * Returns a {@link Position} instance for the given Bukkit {@link Location} on the server. * - * @param location the bukkit location to get the {@link Position} instance for + * @param location the Bukkit location to get the {@link Position} instance for * @param server the {@link Server} the position is on - * @return the {@link Position} instance for the given bukkit {@link Location} on the given {@link Server} + * @return the {@link Position} instance for the given Bukkit {@link Location} on the given {@link Server} * @see Position#getServer() to get the server the position is on * @since 4.0 */ @@ -134,9 +136,9 @@ public class HuskHomesAPI extends BaseHuskHomesAPI { } /** - * Returns a {@link Position} instance for the given bukkit {@link Location} on the server. + * Returns a {@link Position} instance for the given Bukkit {@link Location} on the server. * - * @param location the bukkit location to get the {@link Position} instance for + * @param location the Bukkit location to get the {@link Position} instance for * @return the {@link Position} instance for the given {@link Location} on the server * @since 4.0 */ @@ -145,15 +147,4 @@ public class HuskHomesAPI extends BaseHuskHomesAPI { return Position.at(Objects.requireNonNull(adaptLocation(location)), getServer()); } - /** - * Get the name of this server. - * - * @return the server name - * @since 4.0 - */ - @NotNull - public String getServer() { - return plugin.getServerName(); - } - } diff --git a/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java b/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java index 8e082034..843016b6 100644 --- a/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java +++ b/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java @@ -71,6 +71,17 @@ public class BaseHuskHomesAPI { this.plugin = plugin; } + /** + * Get the name of this server. + * + * @return the server name + * @since 4.6.4 + */ + @NotNull + public String getServer() { + return plugin.getServerName(); + } + /** * Returns saved {@link SavedUser} for the given player's account {@link UUID}, if they exist. * diff --git a/fabric/build.gradle b/fabric/build.gradle index 68876a95..d9441c19 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -15,22 +15,11 @@ dependencies { mappings "net.fabricmc:yarn:${fabric_yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" - // Fabric API modules - Set fabricApiModules = [ - 'fabric-api-base', - 'fabric-lifecycle-events-v1', - 'fabric-entity-events-v1', - 'fabric-command-api-v2', - 'fabric-networking-api-v1', - 'fabric-dimensions-v1', - ] - fabricApiModules.forEach { - modCompileOnly(fabricApi.module(it, fabric_api_version)) - } modImplementation include("net.kyori:adventure-platform-fabric:${adventure_platform_fabric_version}") modImplementation include("me.lucko:fabric-permissions-api:${fabric_permissions_api_version}") modImplementation include("eu.pb4:placeholder-api:${fabric_placeholder_api_version}") - modImplementation("net.impactdev.impactor.api:economy:${fabric_impactor_api_version}") + modImplementation include("net.impactdev.impactor.api:economy:${fabric_impactor_api_version}") + modCompileOnly "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}" implementation include("redis.clients:jedis:$jedis_version") implementation include("org.apache.commons:commons-pool2:$commons_pool_version") diff --git a/fabric/src/main/java/net/william278/huskhomes/FabricHuskHomes.java b/fabric/src/main/java/net/william278/huskhomes/FabricHuskHomes.java index 279f75f5..5a0e648b 100644 --- a/fabric/src/main/java/net/william278/huskhomes/FabricHuskHomes.java +++ b/fabric/src/main/java/net/william278/huskhomes/FabricHuskHomes.java @@ -34,6 +34,8 @@ import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.platform.fabric.FabricServerAudiences; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Identifier; @@ -41,6 +43,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.TeleportTarget; import net.william278.desertwell.util.Version; +import net.william278.huskhomes.api.FabricHuskHomesAPI; import net.william278.huskhomes.command.Command; import net.william278.huskhomes.command.FabricCommand; import net.william278.huskhomes.config.Locales; @@ -192,6 +195,9 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes // Register events initialize("events", (plugin) -> this.eventListener = new FabricEventListener(this)); + // Initialize the API + initialize("API", (plugin) -> FabricHuskHomesAPI.register(this)); + this.checkForUpdates(); } @@ -250,7 +256,10 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes public void setWorldSpawn(@NotNull Position position) { final ServerWorld world = Adapter.adapt(position, minecraftServer); if (world != null) { - world.setSpawnPos(BlockPos.ofFloored(Adapter.adapt(position).position), position.getYaw()); + world.setSpawnPos( + BlockPos.ofFloored(position.getX(), position.getY(), position.getZ()), + position.getYaw() + ); } } @@ -403,25 +412,28 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes } @NotNull - public static TeleportTarget adapt(@NotNull Location location) { + public static TeleportTarget adapt(@NotNull Location location, @NotNull MinecraftServer server) { return new TeleportTarget( + adapt(location.getWorld(), server), new Vec3d(location.getX(), location.getY(), location.getZ()), Vec3d.ZERO, location.getYaw(), - location.getPitch() + location.getPitch(), + entity -> entity.refreshPositionAndAngles( + location.getX(), location.getY(), location.getZ(), + location.getYaw(), location.getPitch() + ) ); } @Nullable public static ServerWorld adapt(@NotNull World world, @NotNull MinecraftServer server) { - return server.getWorld(server.getWorldRegistryKeys().stream() - .filter(key -> key.getValue().equals(Identifier.tryParse(world.getName()))) - .findFirst().orElse(null)); + return server.getWorld(RegistryKey.of(RegistryKeys.WORLD, Identifier.tryParse(world.getName()))); } @Nullable - public static ServerWorld adapt(@NotNull Location location, @NotNull MinecraftServer server) { - return adapt(location.getWorld(), server); + public static ServerWorld adapt(@NotNull Position position, @NotNull MinecraftServer server) { + return adapt(position.getWorld(), server); } @NotNull diff --git a/fabric/src/main/java/net/william278/huskhomes/api/FabricHuskHomesAPI.java b/fabric/src/main/java/net/william278/huskhomes/api/FabricHuskHomesAPI.java new file mode 100644 index 00000000..48886435 --- /dev/null +++ b/fabric/src/main/java/net/william278/huskhomes/api/FabricHuskHomesAPI.java @@ -0,0 +1,173 @@ +/* + * This file is part of HuskHomes, licensed under the Apache License 2.0. + * + * Copyright (c) William278 + * Copyright (c) contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.william278.huskhomes.api; + +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.TeleportTarget; +import net.william278.huskhomes.FabricHuskHomes; +import net.william278.huskhomes.config.Server; +import net.william278.huskhomes.position.Location; +import net.william278.huskhomes.position.Position; +import net.william278.huskhomes.position.World; +import net.william278.huskhomes.user.FabricUser; +import net.william278.huskhomes.user.OnlineUser; +import net.william278.huskhomes.user.User; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * The HuskHomes API implementation for the Fabric platform, providing methods to access ServerPlayerEntity data, + * homes, warps and process teleports + * + *

Retrieve an instance of the API class via {@link #getInstance()}. + * + * @since 4.7 + */ +@SuppressWarnings("unused") +public class FabricHuskHomesAPI extends BaseHuskHomesAPI { + + /** + * (Internal use only) - Constructor, instantiating the API. + */ + @ApiStatus.Internal + private FabricHuskHomesAPI(@NotNull FabricHuskHomes plugin) { + super(plugin); + } + + /** + * Get an instance of the HuskHomes API. + * + * @return instance of the HuskHomes API + * @throws NotRegisteredException if the API has not yet been registered. + */ + @NotNull + public static FabricHuskHomesAPI getInstance() throws NotRegisteredException { + return (FabricHuskHomesAPI) BaseHuskHomesAPI.getInstance(); + } + + /** + * (Internal use only) - Register the API for this platform. + * + * @param plugin the plugin instance + */ + @ApiStatus.Internal + public static void register(@NotNull FabricHuskHomes plugin) { + instance = new FabricHuskHomesAPI(plugin); + } + + /** + * Returns an {@link OnlineUser} instance for the given Fabric {@link ServerPlayerEntity}. + * + * @param player the Fabric ServerPlayerEntity to get the {@link User} instance for + * @return the {@link OnlineUser} instance for the given Fabric {@link ServerPlayerEntity} + * @since 4.7 + */ + @NotNull + public OnlineUser adaptUser(@NotNull ServerPlayerEntity player) { + return FabricUser.adapt(player, (FabricHuskHomes) plugin); + } + + /** + * Returns the Fabric {@link ServerPlayerEntity} being represented by the given {@link OnlineUser}. + * + * @param user {@link OnlineUser} to get the Fabric ServerPlayerEntity from + * @return the Fabric {@link ServerPlayerEntity} being represented by the given {@link OnlineUser} + * @since 4.7 + */ + @NotNull + public ServerPlayerEntity getServerPlayerEntity(@NotNull OnlineUser user) { + return ((FabricUser) user).getPlayer(); + } + + /** + * Returns the Fabric {@link Location} being represented by the given {@link Position}. + * + * @param position the {@link Position} to get the Fabric location from + * @return the fabric {@link ServerWorld} being represented by the given {@link Position} + * @since 4.7 + */ + @Nullable + public ServerWorld getServerWorld(@NotNull World position) { + return FabricHuskHomes.Adapter.adapt(position, ((FabricHuskHomes) plugin).getMinecraftServer()); + } + + /** + * Returns the Fabric {@link TeleportTarget} being represented by the given {@link Location}. + * + * @param location the {@link Location} to get the {@link TeleportTarget} from + * @return the {@link TeleportTarget} being represented by the given {@link Location} + * @since 4.7 + */ + @Nullable + public TeleportTarget getTeleportTarget(@NotNull Location location) { + return FabricHuskHomes.Adapter.adapt(location, ((FabricHuskHomes) plugin).getMinecraftServer()); + } + + /** + * Returns a {@link Location} instance for the given Fabric {@link Location} on the server. + * + * @return the {@link Location} instance for the given Fabric {@link Location} + * @since 4.7 + */ + @Nullable + public Location adaptLocation(@NotNull Vec3d pos, @NotNull net.minecraft.world.World world, + float yaw, float pitch) { + return FabricHuskHomes.Adapter.adapt(pos, world, yaw, pitch); + } + + /** + * Returns a {@link Position} instance for the given Fabric {@link Location} on the server. + * + * @param pos the {@link Vec3d} position to get the {@link Position} instance for + * @param world the world the position is on + * @param yaw the yaw of the position + * @param pitch the pitch of the position + * @param server the {@link Server} the position is on + * @return the {@link Position} instance for the given Fabric {@link Location} on the given {@link Server} + * @see Position#getServer() to get the server the position is on + * @since 4.7 + */ + @NotNull + public Position adaptPosition(@NotNull Vec3d pos, @NotNull net.minecraft.world.World world, + float yaw, float pitch, @NotNull String server) { + return FabricHuskHomes.Adapter.adapt(pos, world, yaw, pitch, server); + } + + /** + * Returns a {@link Position} instance for the given Fabric {@link Location} on the server. + * + * @param pos the {@link Vec3d} position to get the {@link Position} instance for + * @param world the world the position is on + * @param yaw the yaw of the position + * @param pitch the pitch of the position + * @return the {@link Position} instance for the given Fabric {@link Location} on the given {@link Server} + * @see Position#getServer() to get the server the position is on + * @since 4.7 + */ + @NotNull + public Position adaptPosition(@NotNull Vec3d pos, @NotNull net.minecraft.world.World world, + float yaw, float pitch) { + return FabricHuskHomes.Adapter.adapt(pos, world, yaw, pitch, getServer()); + } + +} diff --git a/fabric/src/main/java/net/william278/huskhomes/hook/FabricPlaceholderAPIHook.java b/fabric/src/main/java/net/william278/huskhomes/hook/FabricPlaceholderAPIHook.java index 488b8862..015019c6 100644 --- a/fabric/src/main/java/net/william278/huskhomes/hook/FabricPlaceholderAPIHook.java +++ b/fabric/src/main/java/net/william278/huskhomes/hook/FabricPlaceholderAPIHook.java @@ -39,7 +39,7 @@ public class FabricPlaceholderAPIHook extends Hook { @SuppressWarnings("SameParameterValue") @NotNull private Identifier createIdentifier(@NotNull String name) { - return new Identifier("huskhomes", name); + return Identifier.of("huskhomes", name); } @Override diff --git a/fabric/src/main/java/net/william278/huskhomes/user/FabricUser.java b/fabric/src/main/java/net/william278/huskhomes/user/FabricUser.java index 7eeafdfb..a35c324e 100644 --- a/fabric/src/main/java/net/william278/huskhomes/user/FabricUser.java +++ b/fabric/src/main/java/net/william278/huskhomes/user/FabricUser.java @@ -20,7 +20,6 @@ package net.william278.huskhomes.user; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.fabricmc.fabric.api.dimension.v1.FabricDimensions; import net.kyori.adventure.audience.Audience; import net.minecraft.entity.Entity; import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; @@ -145,7 +144,7 @@ public class FabricUser extends OnlineUser { if (world == null) { throw new TeleportationException(TeleportationException.Type.WORLD_NOT_FOUND, plugin); } - FabricDimensions.teleport(player, world, FabricHuskHomes.Adapter.adapt(location)); + player.teleportTo(FabricHuskHomes.Adapter.adapt(location, server)); } @Override @@ -178,4 +177,9 @@ public class FabricUser extends OnlineUser { plugin.runSyncDelayed(() -> player.setInvulnerable(false), this, invulnerabilityTimeInTicks); } + @NotNull + public ServerPlayerEntity getPlayer() { + return player; + } + } diff --git a/gradle.properties b/gradle.properties index 3ee3caa2..a5b78c8e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,12 +18,12 @@ postgresql_driver_version=42.7.3 commons_pool_version=2.12.0 # Fabric settings -fabric_loom_version=1.6-SNAPSHOT -fabric_minecraft_version=1.20.6 +fabric_loom_version=1.7-SNAPSHOT +fabric_minecraft_version=1.21 fabric_loader_version=0.15.11 -fabric_yarn_mappings=1.20.6+build.3 -fabric_api_version=0.99.0+1.20.6 +fabric_yarn_mappings=1.21+build.2 +fabric_api_version=0.100.3+1.21 fabric_permissions_api_version=0.3.1 -adventure_platform_fabric_version=5.13.0 -fabric_impactor_api_version=5.2.4 -fabric_placeholder_api_version=2.4.0-pre.1+1.20.5 +adventure_platform_fabric_version=5.14.0 +fabric_impactor_api_version=5.2.4-SNAPSHOT +fabric_placeholder_api_version=2.4.0+1.21 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d64cd491..e6441136 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23a..a4413138 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME