only yeet out of subclaim if main claim allows it close #107

This commit is contained in:
Flemmli97 2021-12-19 21:09:47 +01:00
parent 40350ca1c3
commit 485a2be455
2 changed files with 12 additions and 2 deletions

View File

@ -327,7 +327,8 @@ public class EntityInteractEvents {
if (!player.isSpectator()) {
BlockPos.MutableBlockPos bPos = rounded.mutable();
if (!currentClaim.canInteract(player, PermissionRegistry.CANSTAY, bPos, true)) {
Vec3 tp = TeleportUtils.getTeleportPos(player, pos, storage, currentClaim.getDimensions(), bPos, (claim, nPos) -> claim.canInteract(player, PermissionRegistry.CANSTAY, nPos, false));
Claim sub = currentClaim.getSubClaim(bPos);
Vec3 tp = TeleportUtils.getTeleportPos(player, pos, storage, sub != null ? sub.getDimensions() : currentClaim.getDimensions(), true, bPos, (claim, nPos) -> claim.canInteract(player, PermissionRegistry.CANSTAY, nPos, false));
player.teleportToWithTicket(tp.x(), tp.y(), tp.z());
}
if (player.getAbilities().flying && !player.isCreative() && !currentClaim.canInteract(player, PermissionRegistry.FLIGHT, rounded, true)) {

View File

@ -19,9 +19,18 @@ public class TeleportUtils {
}
public static Vec3 getTeleportPos(ServerPlayer player, Vec3 playerPos, ClaimStorage storage, int[] dim, BlockPos.MutableBlockPos bPos, BiFunction<Claim, BlockPos, Boolean> check) {
return getTeleportPos(player, playerPos, storage, dim, false, bPos, check);
}
public static Vec3 getTeleportPos(ServerPlayer player, Vec3 playerPos, ClaimStorage storage, int[] dim, boolean checkSub, BlockPos.MutableBlockPos bPos, BiFunction<Claim, BlockPos, Boolean> check) {
Tuple<Direction, Vec3> pos = nearestOutside(dim, playerPos);
bPos.set(pos.getB().x(), pos.getB().y(), pos.getB().z());
Claim claim = storage.getClaimAt(bPos);
if (checkSub) {
Claim sub = claim != null ? claim.getSubClaim(bPos) : null;
if (sub != null)
claim = sub;
}
if (claim == null || check.apply(claim, bPos)) {
Vec3 ret = pos.getB();
BlockPos rounded = roundedBlockPos(ret);
@ -47,7 +56,7 @@ public class TeleportUtils {
dim[0] = newDim[0];
break;
}
return getTeleportPos(player, playerPos, storage, dim, bPos, check);
return getTeleportPos(player, playerPos, storage, dim, checkSub, bPos, check);
}
private static Tuple<Direction, Vec3> nearestOutside(int[] dim, Vec3 from) {