Add support for Minecraft 1.21.11 (#913)

This commit is contained in:
Nicholis authored and GitHub committed 2025-12-20 21:21:41 +02:00
1 parent 50a32dca7d
commit 305dc35011
13 files changed
+157 -23

No files matched your search

@@ -46,6 +46,7 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.WorldProperties;
import net.william278.desertwell.util.Version;
import net.william278.huskhomes.api.FabricHuskHomesAPI;
import net.william278.huskhomes.command.Command;
@@ -196,10 +197,19 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes
public void setWorldSpawn(@NotNull Position position) {
final ServerWorld world = Adapter.adapt(position, minecraftServer);
if (world != null) {
world.setSpawnPos(
//#if MC>=12111
world.setSpawnPoint(WorldProperties.SpawnPoint.create(
world.getRegistryKey(),
BlockPos.ofFloored(position.getX(), position.getY(), position.getZ()),
position.getYaw()
);
position.getYaw(),
0
));
//#else
//$$ world.setSpawnPos(
//$$ BlockPos.ofFloored(position.getX(), position.getY(), position.getZ()),
//$$ position.getYaw()
//$$ );
//#endif
}
}
@@ -25,6 +25,10 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
import me.lucko.fabric.api.permissions.v0.PermissionCheckEvent;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.util.TriState;
//#if MC>=12111
import net.minecraft.command.permission.Permission;
import net.minecraft.command.permission.PermissionLevel;
//#endif
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.william278.huskhomes.FabricHuskHomes;
@@ -50,8 +54,16 @@ public class FabricCommand {
public void register(@NotNull CommandDispatcher<ServerCommandSource> dispatcher) {
// Register brigadier command
final int permissionLevel = command.isOperatorCommand() ? 3 : 0;
final Predicate<ServerCommandSource> predicate = Permissions
.require(command.getPermission(), command.isOperatorCommand() ? 3 : 0);
.require(
command.getPermission(),
//#if MC>=1.21.11
PermissionLevel.fromLevel(permissionLevel)
//#else
//$$ permissionLevel
//#endif
);
final LiteralArgumentBuilder<ServerCommandSource> builder = literal(command.getName())
.requires(predicate).executes(getBrigadierExecutor());
plugin.getPermissions().put(command.getPermission(), command.isOperatorCommand());
@@ -66,7 +78,7 @@ public class FabricCommand {
permissions.forEach((permission, isOp) -> plugin.getPermissions().put(permission, isOp));
PermissionCheckEvent.EVENT.register((player, node) -> {
if (permissions.containsKey(node) && permissions.get(node) &&
(!(player instanceof ServerCommandSource source) || source.hasPermissionLevel(3))) {
(!(player instanceof ServerCommandSource source) || hasPermissionLevel(source, 3))) {
return TriState.TRUE;
}
return TriState.DEFAULT;
@@ -84,6 +96,14 @@ public class FabricCommand {
});
}
private boolean hasPermissionLevel(ServerCommandSource source, int level) {
//#if MC>=12111
return source.getPermissions().hasPermission(new Permission.Level(PermissionLevel.fromLevel(level)));
//#else
//$$ return source.hasPermissionLevel(level);
//#endif
}
private com.mojang.brigadier.Command<ServerCommandSource> getBrigadierExecutor() {
return (context) -> {
command.onExecuted(
@@ -24,6 +24,10 @@ import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.util.TriState;
import net.kyori.adventure.audience.Audience;
//#if MC>=12111
import net.minecraft.command.permission.Permission;
import net.minecraft.command.permission.PermissionLevel;
//#endif
import net.minecraft.entity.Entity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.MinecraftServer;
@@ -47,7 +51,11 @@ public class FabricUser extends OnlineUser {
private final ServerPlayerEntity player;
private FabricUser(@NotNull ServerPlayerEntity player, @NotNull FabricHuskHomes plugin) {
super(player.getUuid(), player.getGameProfile().getName(), plugin);
//#if MC>=12111
super(player.getUuid(), player.getGameProfile().name(), plugin);
//#else
//$$ super(player.getUuid(), player.getGameProfile().getName(), plugin);
//#endif
this.player = player;
}
@@ -60,7 +68,11 @@ public class FabricUser extends OnlineUser {
@Override
public Position getPosition() {
return FabricHuskHomes.Adapter.adapt(
player.getPos(),
//#if MC>=12111
player.getEntityPos(),
//#else
//$$ player.getPos(),
//#endif
getServerWorld(player),
player.getYaw(), player.getPitch(),
plugin.getServerName()
@@ -69,10 +81,12 @@ public class FabricUser extends OnlineUser {
@NotNull
private ServerWorld getServerWorld(ServerPlayerEntity player) {
//#if MC <=12104
//#if MC <=12105
//$$ return player.getServerWorld();
//#elseif MC >=12111
return player.getEntityWorld();
//#else
return player.getWorld();
//$$ return player.getWorld();
//#endif
}
@@ -82,10 +96,14 @@ public class FabricUser extends OnlineUser {
//$$ final BlockPos spawn = player.getSpawnPointPosition();
//$$ final float angle = player.getSpawnAngle();
//$$ final RegistryKey<net.minecraft.world.World> world = player.getSpawnPointDimension();
//#elseif MC>=12111
final BlockPos spawn = player.getRespawn() == null ? null : player.getRespawn().respawnData().getPos();
final float angle = player.getRespawn() == null ? 0 : player.getRespawn().respawnData().yaw();
final RegistryKey<net.minecraft.world.World> world = player.getRespawn() == null ? null : player.getRespawn().respawnData().getDimension();
//#else
final BlockPos spawn = player.getRespawn() == null ? null : player.getRespawn().pos();
final float angle = player.getRespawn() == null ? 0 : player.getRespawn().angle();
final RegistryKey<net.minecraft.world.World> world = player.getRespawn() == null ? null : player.getRespawn().dimension();
//$$ final BlockPos spawn = player.getRespawn() == null ? null : player.getRespawn().pos();
//$$ final float angle = player.getRespawn() == null ? 0 : player.getRespawn().angle();
//$$ final RegistryKey<net.minecraft.world.World> world = player.getRespawn() == null ? null : player.getRespawn().dimension();
//#endif
if (spawn == null || world == null) {
return Optional.empty();
@@ -115,7 +133,12 @@ public class FabricUser extends OnlineUser {
@Override
public boolean hasPermission(@NotNull String node) {
boolean op = Boolean.TRUE.equals(((FabricHuskHomes) plugin).getPermissions().getOrDefault(node, true));
return Permissions.check(player, node, !op || player.hasPermissionLevel(3));
//#if MC>=12111
boolean hasPermission = player.getPermissions().hasPermission(new Permission.Level(PermissionLevel.fromLevel(3)));
//#else
//$$ boolean hasPermission = player.hasPermissionLevel(3);
//#endif
return Permissions.check(player, node, !op || hasPermission);
}
@Override
@@ -157,7 +180,12 @@ public class FabricUser extends OnlineUser {
@Override
public void teleportLocally(@NotNull Location location, boolean async) throws TeleportationException {
final MinecraftServer server = player.getServer();
//#if MC>=12111
final MinecraftServer server = player.getEntityWorld().getServer();
//#else
//$$ final MinecraftServer server = player.getServer();
//#endif
if (server == null) {
throw new TeleportationException(TeleportationException.Type.ILLEGAL_TARGET_COORDINATES, plugin);
}