add trapped command
This commit is contained in:
parent
8fd8560723
commit
e04370955e
@ -1,3 +1,13 @@
|
||||
Flan 1.4.0
|
||||
======================
|
||||
- Add FLIGHT permission. Prevents non creative flight in claims
|
||||
- Add CANSTAY permission. Makes players unable to enter your claim
|
||||
- Remove the mobspawn config.
|
||||
- Add support for wildcard worlds in globalDefaultPerms. Use "*" instead of <dimension key>
|
||||
MOBSPAWN added to globalDefaultPerms with value false
|
||||
FLIGHT added to globalDefaultPerms with value true
|
||||
- Add /flan trapped command. Using it teleports you out of a claim you don't own after 5 seconds
|
||||
|
||||
Flan 1.3.3
|
||||
======================
|
||||
- Some blocks permission changed from PROJECTILES to OPENCONTAINER on direct interaction
|
||||
|
@ -54,6 +54,7 @@ public class CommandClaim {
|
||||
.then(CommandManager.literal("reload").requires(src -> CommandPermission.perm(src, CommandPermission.cmdReload, true)).executes(CommandClaim::reloadConfig))
|
||||
.then(CommandManager.literal("addClaim").requires(src -> CommandPermission.perm(src, CommandPermission.claimCreate)).then(CommandManager.argument("from", BlockPosArgumentType.blockPos()).then(CommandManager.argument("to", BlockPosArgumentType.blockPos()).executes(CommandClaim::addClaim))))
|
||||
.then(CommandManager.literal("menu").requires(src -> CommandPermission.perm(src, CommandPermission.cmdMenu)).executes(CommandClaim::openMenu))
|
||||
.then(CommandManager.literal("trapped").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTrapped)).executes(CommandClaim::trapped))
|
||||
.then(CommandManager.literal("personalGroups").requires(src -> CommandPermission.perm(src, CommandPermission.cmdPGroup)).executes(CommandClaim::openPersonalGroups))
|
||||
.then(CommandManager.literal("claimInfo").requires(src -> CommandPermission.perm(src, CommandPermission.cmdInfo)).executes(CommandClaim::claimInfo))
|
||||
.then(CommandManager.literal("transferClaim").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTransfer)).then(CommandManager.argument("player", GameProfileArgumentType.gameProfile()).executes(CommandClaim::transferClaim)))
|
||||
@ -190,6 +191,18 @@ public class CommandClaim {
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int trapped(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (data.setTrappedRescue()) {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.trappedRescue, Formatting.GOLD), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
} else {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.trappedFail, Formatting.RED), false);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int openPersonalGroups(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
PersonalGroupScreenHandler.openGroupMenu(player);
|
||||
|
@ -116,6 +116,10 @@ public class LangConfig {
|
||||
public String buySuccess = "Bought %1$s claimblocks for %2$s";
|
||||
public String gunpowderMissing = "Missing gunpowder currency mod";
|
||||
|
||||
public String trappedRescue = "Rescuing. Don't move for 5 seconds";
|
||||
public String trappedFail = "Rescue not necessary or already rescuing";
|
||||
public String trappedMove = "You moved. Aborting rescue";
|
||||
|
||||
public LangConfig(MinecraftServer server) {
|
||||
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
|
||||
//server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||
|
@ -8,6 +8,7 @@ import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import com.flemmli97.flan.claim.ObjectToPermissionMap;
|
||||
import com.flemmli97.flan.mixin.IPersistentProjectileVars;
|
||||
import com.flemmli97.flan.player.IOwnedItem;
|
||||
import com.flemmli97.flan.player.TeleportUtils;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
@ -39,13 +40,11 @@ import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
@ -287,7 +286,7 @@ public class EntityInteractEvents {
|
||||
|
||||
public static void updateClaim(ServerPlayerEntity player, Claim currentClaim, Consumer<Claim> cons) {
|
||||
Vec3d pos = player.getPos();
|
||||
BlockPos rounded = roundedBlockPos(pos.add(0, player.getEyeHeight(player.getPose()), 0));
|
||||
BlockPos rounded = TeleportUtils.roundedBlockPos(pos.add(0, player.getEyeHeight(player.getPose()), 0));
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
if (currentClaim != null) {
|
||||
if (!currentClaim.insideClaim(rounded)) {
|
||||
@ -296,10 +295,10 @@ public class EntityInteractEvents {
|
||||
if (!player.isSpectator()) {
|
||||
BlockPos.Mutable bPos = rounded.mutableCopy();
|
||||
if (!currentClaim.canInteract(player, PermissionRegistry.CANSTAY, bPos, true)) {
|
||||
Vec3d tp = getTeleportPos(player, pos, storage, currentClaim.getDimensions(), bPos);
|
||||
Vec3d tp = TeleportUtils.getTeleportPos(player, pos, storage, currentClaim.getDimensions(), bPos, (claim, nPos) -> claim.canInteract(player, PermissionRegistry.CANSTAY, nPos, false));
|
||||
player.teleport(tp.getX(), tp.getY(), tp.getZ());
|
||||
}
|
||||
if (player.abilities.flying && !currentClaim.canInteract(player, PermissionRegistry.FLIGHT, rounded, true)) {
|
||||
if (player.abilities.flying && !player.isCreative() && !currentClaim.canInteract(player, PermissionRegistry.FLIGHT, rounded, true)) {
|
||||
player.abilities.flying = false;
|
||||
player.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.abilities));
|
||||
}
|
||||
@ -310,58 +309,4 @@ public class EntityInteractEvents {
|
||||
cons.accept(claim);
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockPos roundedBlockPos(Vec3d pos) {
|
||||
return new BlockPos(Math.round(pos.getX()), MathHelper.floor(pos.getY()), Math.round(pos.getZ()));
|
||||
}
|
||||
|
||||
private static Vec3d getTeleportPos(ServerPlayerEntity player, Vec3d playerPos, ClaimStorage storage, int[] dim, BlockPos.Mutable bPos) {
|
||||
Pair<Direction, Vec3d> pos = nearestOutside(dim, playerPos);
|
||||
bPos.set(pos.getRight().getX(), pos.getRight().getY(), pos.getRight().getZ());
|
||||
Claim claim = storage.getClaimAt(bPos);
|
||||
if (claim == null || claim.canInteract(player, PermissionRegistry.CANSTAY, bPos, false))
|
||||
return pos.getRight();
|
||||
int[] newDim = claim.getDimensions();
|
||||
switch (pos.getLeft()) {
|
||||
case NORTH:
|
||||
dim[2] = newDim[2];
|
||||
break;
|
||||
case SOUTH:
|
||||
dim[3] = newDim[3];
|
||||
break;
|
||||
case EAST:
|
||||
dim[1] = newDim[1];
|
||||
break;
|
||||
default:
|
||||
dim[0] = newDim[0];
|
||||
break;
|
||||
}
|
||||
return getTeleportPos(player, playerPos, storage, dim, bPos);
|
||||
}
|
||||
|
||||
|
||||
private static Pair<Direction, Vec3d> nearestOutside(int[] dim, Vec3d from) {
|
||||
double northDist = Math.abs(from.getZ() - dim[2]);
|
||||
double southDist = Math.abs(dim[3] - from.getZ());
|
||||
double westDist = Math.abs(from.getX() - dim[0]);
|
||||
double eastDist = Math.abs(dim[1] - from.getX());
|
||||
if (northDist > southDist) {
|
||||
if (eastDist > westDist) {
|
||||
if (southDist > westDist)
|
||||
return new Pair<>(Direction.WEST, new Vec3d(dim[0] - 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.SOUTH, new Vec3d(from.getX(), from.getY(), dim[3] + 1.5));
|
||||
}
|
||||
if (southDist > eastDist)
|
||||
return new Pair<>(Direction.EAST, new Vec3d(dim[1] + 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.SOUTH, new Vec3d(from.getX(), from.getY(), dim[3] + 1.5));
|
||||
}
|
||||
if (eastDist > westDist) {
|
||||
if (northDist > westDist)
|
||||
return new Pair<>(Direction.WEST, new Vec3d(dim[0] - 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.NORTH, new Vec3d(from.getX(), from.getY(), dim[2] - 1.5));
|
||||
}
|
||||
if (northDist > eastDist)
|
||||
return new Pair<>(Direction.EAST, new Vec3d(dim[1] + 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.NORTH, new Vec3d(from.getX(), from.getY(), dim[2] - 1.5));
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.flemmli97.flan.event;
|
||||
import com.flemmli97.flan.api.PermissionRegistry;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
|
@ -14,6 +14,7 @@ public class CommandPermission {
|
||||
public static final String claimCreate = "flan.claim.create";
|
||||
|
||||
public static final String cmdMenu = "flan.command.menu";
|
||||
public static final String cmdTrapped = "flan.command.trapped";
|
||||
public static final String cmdPGroup = "flan.command.personal";
|
||||
public static final String cmdInfo = "flan.command.info";
|
||||
public static final String cmdTransfer = "flan.command.transfer";
|
||||
|
@ -20,6 +20,7 @@ import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@ -37,7 +38,8 @@ public class PlayerClaimData {
|
||||
|
||||
private int claimBlocks, additionalClaimBlocks, confirmTick, actionCooldown;
|
||||
|
||||
private int lastBlockTick;
|
||||
private int lastBlockTick, trappedTick = -1;
|
||||
private Vec3d trappedPos;
|
||||
private EnumEditMode mode = EnumEditMode.DEFAULT;
|
||||
private Claim editingClaim;
|
||||
private ClaimDisplay displayEditing;
|
||||
@ -201,6 +203,16 @@ public class PlayerClaimData {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setTrappedRescue() {
|
||||
Claim claim = ((IPlayerClaimImpl) this.player).getCurrentClaim();
|
||||
if (this.trappedTick < 0 && claim != null && !this.player.getUuid().equals(claim.getOwner())) {
|
||||
this.trappedTick = 101;
|
||||
this.trappedPos = this.player.getPos();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
boolean tool = this.player.getMainHandStack().getItem() == ConfigHandler.config.claimingItem
|
||||
|| this.player.getOffHandStack().getItem() == ConfigHandler.config.claimingItem;
|
||||
@ -237,6 +249,19 @@ public class PlayerClaimData {
|
||||
this.getClaimBlocks(), this.getAdditionalClaims(), this.usedClaimBlocks()), Formatting.GOLD), false);
|
||||
}
|
||||
this.actionCooldown--;
|
||||
if (--this.trappedTick >= 0) {
|
||||
if (this.trappedTick == 0) {
|
||||
Vec3d tp = TeleportUtils.getTeleportPos(this.player, this.player.getPos(), ClaimStorage.get(this.player.getServerWorld()),
|
||||
((IPlayerClaimImpl) this.player).getCurrentClaim().getDimensions(),
|
||||
TeleportUtils.roundedBlockPos(this.player.getPos()).mutableCopy(), (claim, nPos) -> false);
|
||||
this.player.teleport(tp.getX(), tp.getY(), tp.getZ());
|
||||
}
|
||||
if (this.player.getPos().squaredDistanceTo(this.trappedPos) > 0.15) {
|
||||
this.trappedTick = -1;
|
||||
this.trappedPos = null;
|
||||
this.player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.trappedMove), Formatting.RED), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clone(PlayerClaimData data) {
|
||||
|
68
src/main/java/com/flemmli97/flan/player/TeleportUtils.java
Normal file
68
src/main/java/com/flemmli97/flan/player/TeleportUtils.java
Normal file
@ -0,0 +1,68 @@
|
||||
package com.flemmli97.flan.player;
|
||||
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class TeleportUtils {
|
||||
|
||||
public static BlockPos roundedBlockPos(Vec3d pos) {
|
||||
return new BlockPos(Math.round(pos.getX()), MathHelper.floor(pos.getY()), Math.round(pos.getZ()));
|
||||
}
|
||||
|
||||
public static Vec3d getTeleportPos(ServerPlayerEntity player, Vec3d playerPos, ClaimStorage storage, int[] dim, BlockPos.Mutable bPos, BiFunction<Claim, BlockPos, Boolean> check) {
|
||||
Pair<Direction, Vec3d> pos = nearestOutside(dim, playerPos);
|
||||
bPos.set(pos.getRight().getX(), pos.getRight().getY(), pos.getRight().getZ());
|
||||
Claim claim = storage.getClaimAt(bPos);
|
||||
if (claim == null || check.apply(claim, bPos))
|
||||
return pos.getRight();
|
||||
int[] newDim = claim.getDimensions();
|
||||
switch (pos.getLeft()) {
|
||||
case NORTH:
|
||||
dim[2] = newDim[2];
|
||||
break;
|
||||
case SOUTH:
|
||||
dim[3] = newDim[3];
|
||||
break;
|
||||
case EAST:
|
||||
dim[1] = newDim[1];
|
||||
break;
|
||||
default:
|
||||
dim[0] = newDim[0];
|
||||
break;
|
||||
}
|
||||
return getTeleportPos(player, playerPos, storage, dim, bPos, check);
|
||||
}
|
||||
|
||||
private static Pair<Direction, Vec3d> nearestOutside(int[] dim, Vec3d from) {
|
||||
double northDist = Math.abs(from.getZ() - dim[2]);
|
||||
double southDist = Math.abs(dim[3] - from.getZ());
|
||||
double westDist = Math.abs(from.getX() - dim[0]);
|
||||
double eastDist = Math.abs(dim[1] - from.getX());
|
||||
if (northDist > southDist) {
|
||||
if (eastDist > westDist) {
|
||||
if (southDist > westDist)
|
||||
return new Pair<>(Direction.WEST, new Vec3d(dim[0] - 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.SOUTH, new Vec3d(from.getX(), from.getY(), dim[3] + 1.5));
|
||||
}
|
||||
if (southDist > eastDist)
|
||||
return new Pair<>(Direction.EAST, new Vec3d(dim[1] + 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.SOUTH, new Vec3d(from.getX(), from.getY(), dim[3] + 1.5));
|
||||
}
|
||||
if (eastDist > westDist) {
|
||||
if (northDist > westDist)
|
||||
return new Pair<>(Direction.WEST, new Vec3d(dim[0] - 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.NORTH, new Vec3d(from.getX(), from.getY(), dim[2] - 1.5));
|
||||
}
|
||||
if (northDist > eastDist)
|
||||
return new Pair<>(Direction.EAST, new Vec3d(dim[1] + 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.NORTH, new Vec3d(from.getX(), from.getY(), dim[2] - 1.5));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user