mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
fabric: Only build 1.20.1
This commit is contained in:
85 files changed
+15
-5585
No files matched your search
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* 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.user;
|
||||
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.william278.huskhomes.FabricHuskHomes;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.teleport.TeleportationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FabricUser extends OnlineUser {
|
||||
|
||||
private final FabricHuskHomes plugin;
|
||||
private final ServerPlayerEntity player;
|
||||
|
||||
private FabricUser(@NotNull ServerPlayerEntity player, @NotNull FabricHuskHomes plugin) {
|
||||
super(player.getUuid(), player.getEntityName());
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FabricUser adapt(@NotNull ServerPlayerEntity player, @NotNull FabricHuskHomes plugin) {
|
||||
return new FabricUser(player, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return Position.at(
|
||||
player.getX(), player.getY(), player.getZ(),
|
||||
player.getYaw(), player.getPitch(),
|
||||
World.from(
|
||||
player.getWorld().getRegistryKey().getValue().asString(),
|
||||
UUID.nameUUIDFromBytes(player.getWorld().getRegistryKey().getValue().asString().getBytes())
|
||||
),
|
||||
plugin.getServerName()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Position> getBedSpawnPosition() {
|
||||
final BlockPos spawn = player.getSpawnPointPosition();
|
||||
if (spawn == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(Position.at(
|
||||
spawn.getX(), spawn.getY(), spawn.getZ(),
|
||||
player.getSpawnAngle(), 0,
|
||||
World.from(
|
||||
player.getSpawnPointDimension().getValue().asString(),
|
||||
UUID.nameUUIDFromBytes(player.getSpawnPointDimension().getValue().asString().getBytes())
|
||||
),
|
||||
plugin.getServerName()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHealth() {
|
||||
return player.getHealth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull String node) {
|
||||
final boolean requiresOp = Boolean.TRUE.equals(plugin.getPermissions().getOrDefault(node, true));
|
||||
return Permissions.check(player, node, !requiresOp || player.hasPermissionLevel(3));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<String, Boolean> getPermissions() {
|
||||
return plugin.getPermissions().entrySet().stream()
|
||||
.filter(entry -> Permissions.check(player, entry.getKey(), entry.getValue()))
|
||||
.collect(HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), HashMap::putAll);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected List<Integer> getNumericalPermissions(@NotNull String nodePrefix) {
|
||||
final List<Integer> permissions = new ArrayList<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
if (hasPermission(nodePrefix + i)) {
|
||||
permissions.add(i);
|
||||
}
|
||||
}
|
||||
return permissions.stream().sorted(Collections.reverseOrder()).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Audience getAudience() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(@NotNull String soundEffect) throws IllegalArgumentException {
|
||||
// Do nothing - todo: Fix sounds when adventure-platform-fabric is updated.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportLocally(@NotNull Location location, boolean async) throws TeleportationException {
|
||||
final MinecraftServer server = player.getServer();
|
||||
assert server != null : "Server is null";
|
||||
final Identifier worldId = Identifier.tryParse(location.getWorld().getName());
|
||||
player.teleport(
|
||||
server.getWorld(server.getWorldRegistryKeys().stream()
|
||||
.filter(key -> key.getValue().equals(worldId)).findFirst().orElseThrow(
|
||||
() -> new TeleportationException(TeleportationException.Type.WORLD_NOT_FOUND, plugin))
|
||||
),
|
||||
location.getX(), location.getY(), location.getZ(),
|
||||
location.getYaw(), location.getPitch()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginMessage(@NotNull String channel, byte[] message) {
|
||||
final PacketByteBuf buf = PacketByteBufs.create();
|
||||
buf.writeBytes(message);
|
||||
final CustomPayloadS2CPacket packet = new CustomPayloadS2CPacket(parseIdentifier(channel), buf);
|
||||
player.networkHandler.sendPacket(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMoving() {
|
||||
return player.isTouchingWater() || player.isFallFlying() || player.isSprinting() || player.isSneaking();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Identifier parseIdentifier(@NotNull String channel) {
|
||||
if (channel.equals("BungeeCord")) {
|
||||
return new Identifier("bungeecord", "main");
|
||||
}
|
||||
return Optional.ofNullable(Identifier.tryParse(channel))
|
||||
.orElseThrow(() -> new IllegalArgumentException("Invalid channel name: " + channel));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user