add sethome and teleport command (for claims)
This commit is contained in:
parent
c205f5e133
commit
341aa9ebce
@ -1,7 +1,11 @@
|
||||
Flan 1.4.3
|
||||
Flan 1.5.0
|
||||
======================
|
||||
- Fix some items checking for wrong position and thus are able to interact in claims
|
||||
- Fix enderpearl phasing through blocks
|
||||
- Add claim homes set via /flan setHome in a claim to the players position.
|
||||
The claim permission to allow others do that too is EDITCLAIM
|
||||
- Add /flan teleport to tp to a claims home.
|
||||
Default global value is ALLFALSE so disabled.
|
||||
|
||||
Flan 1.4.2
|
||||
======================
|
||||
|
@ -68,6 +68,7 @@ public class PermissionRegistry {
|
||||
public static ClaimPermission PICKUP = register(new ClaimPermission("PICKUP", () -> new ItemStack(Items.BRICK), true, "Allow the pickup of items"));
|
||||
public static ClaimPermission FLIGHT = register(new ClaimPermission("FLIGHT", () -> new ItemStack(Items.FEATHER), true, "Allow non creative flight"));
|
||||
public static ClaimPermission CANSTAY = register(new ClaimPermission("CANSTAY", () -> new ItemStack(Items.PAPER), true, "Allow player to enter your claim"));
|
||||
public static ClaimPermission TELEPORT = register(new ClaimPermission("TELEPORT", () -> new ItemStack(Items.END_PORTAL_FRAME), false, "Allow player to teleport to your claim home position"));
|
||||
|
||||
public static ClaimPermission HURTPLAYER = global(new ClaimPermission("HURTPLAYER", () -> new ItemStack(Items.DIAMOND_SWORD), "Permission to hurt other players"));
|
||||
public static ClaimPermission EXPLOSIONS = global(new ClaimPermission("EXPLOSIONS", () -> new ItemStack(Items.TNT), "Toggle explosions in claim"));
|
||||
|
@ -19,6 +19,8 @@ import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -38,6 +40,7 @@ public class Claim implements IPermissionContainer {
|
||||
|
||||
private UUID claimID;
|
||||
private String claimName = "";
|
||||
private BlockPos homePos;
|
||||
private final Map<ClaimPermission, Boolean> globalPerm = new HashMap<>();
|
||||
private final Map<String, Map<ClaimPermission, Boolean>> permissions = new HashMap<>();
|
||||
|
||||
@ -80,6 +83,7 @@ public class Claim implements IPermissionContainer {
|
||||
this.minY = Math.max(0, minY);
|
||||
this.owner = creator;
|
||||
this.world = world;
|
||||
this.homePos = this.getInitCenterPos();
|
||||
this.setDirty(true);
|
||||
PermissionRegistry.getPerms().stream().filter(perm -> perm.defaultVal).forEach(perm -> this.globalPerm.put(perm, true));
|
||||
if (setDefaultGroups)
|
||||
@ -92,6 +96,12 @@ public class Claim implements IPermissionContainer {
|
||||
return claim;
|
||||
}
|
||||
|
||||
private BlockPos getInitCenterPos() {
|
||||
BlockPos center = new BlockPos(this.minX + (this.maxX - this.minX) * 0.5, 0, this.minZ + (this.maxZ - this.minZ) * 0.5);
|
||||
int y = this.world.getChunk(center.getX() >> 4, center.getZ() >> 4, ChunkStatus.HEIGHTMAPS).sampleHeightmap(Heightmap.Type.MOTION_BLOCKING, center.getX() & 15, center.getZ() & 15);
|
||||
return new BlockPos(center.getX(), y + 1, center.getZ());
|
||||
}
|
||||
|
||||
public void setClaimID(UUID uuid) {
|
||||
this.claimID = uuid;
|
||||
this.setDirty(true);
|
||||
@ -443,6 +453,18 @@ public class Claim implements IPermissionContainer {
|
||||
return l;
|
||||
}
|
||||
|
||||
public boolean setHomePos(BlockPos homePos) {
|
||||
if (this.insideClaim(homePos)) {
|
||||
this.homePos = homePos;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public BlockPos getHomePos() {
|
||||
return this.homePos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only marks non sub claims
|
||||
*/
|
||||
@ -467,6 +489,12 @@ public class Claim implements IPermissionContainer {
|
||||
this.minZ = pos.get(2).getAsInt();
|
||||
this.maxZ = pos.get(3).getAsInt();
|
||||
this.minY = pos.get(4).getAsInt();
|
||||
JsonArray home = ConfigHandler.arryFromJson(obj, "Home");
|
||||
if (home.size() != 3)
|
||||
this.homePos = this.getInitCenterPos();
|
||||
else {
|
||||
this.homePos = new BlockPos(home.get(0).getAsInt(), home.get(1).getAsInt(), home.get(2).getAsInt());
|
||||
}
|
||||
if (ConfigHandler.fromJson(obj, "AdminClaim", false))
|
||||
this.owner = null;
|
||||
else
|
||||
@ -526,6 +554,11 @@ public class Claim implements IPermissionContainer {
|
||||
pos.add(this.maxZ);
|
||||
pos.add(this.minY);
|
||||
obj.add("PosxXzZY", pos);
|
||||
JsonArray home = new JsonArray();
|
||||
home.add(this.homePos.getX());
|
||||
home.add(this.homePos.getY());
|
||||
home.add(this.homePos.getZ());
|
||||
obj.add("Home", home);
|
||||
if (this.parent != null)
|
||||
obj.addProperty("Parent", this.parent.toString());
|
||||
if (!this.globalPerm.isEmpty()) {
|
||||
|
@ -9,6 +9,7 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
@ -46,6 +47,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandClaim {
|
||||
|
||||
@ -54,6 +56,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("setHome").requires(src -> CommandPermission.perm(src, CommandPermission.cmdHome)).executes(CommandClaim::setClaimHome))
|
||||
.then(CommandManager.literal("trapped").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTrapped)).executes(CommandClaim::trapped))
|
||||
.then(CommandManager.literal("name").requires(src -> CommandPermission.perm(src, CommandPermission.cmdName)).then(CommandManager.argument("name", StringArgumentType.string()).executes(CommandClaim::nameClaim)))
|
||||
.then(CommandManager.literal("unlockDrops").executes(CommandClaim::unlockDrops)
|
||||
@ -101,6 +104,11 @@ public class CommandClaim {
|
||||
}
|
||||
return CommandSource.suggestMatching(list, build);
|
||||
}).executes(CommandClaim::removePlayer))))))
|
||||
.then(CommandManager.literal("teleport").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTeleport))
|
||||
.then(CommandManager.literal("self").then(CommandManager.argument("claim", StringArgumentType.word()).suggests((ctx, b) -> CommandClaim.claimSuggestions(ctx, b, ctx.getSource().getPlayer().getUuid()))
|
||||
.executes(CommandClaim::teleport)))
|
||||
.then(CommandManager.literal("other").then(CommandManager.argument("player", GameProfileArgumentType.gameProfile()).then(CommandManager.argument("claim", StringArgumentType.word()).suggests((ctx, b) -> CommandClaim.claimSuggestions(ctx, b, CommandClaim.singleProfile(ctx, "player").getId()))
|
||||
.executes(src -> CommandClaim.teleport(src, CommandClaim.singleProfile(src, "player").getId()))))))
|
||||
.then(CommandManager.literal("permission").requires(src -> CommandPermission.perm(src, CommandPermission.cmdPermission))
|
||||
.then(CommandManager.literal("personal").then(CommandManager.argument("group", StringArgumentType.string()).suggests(CommandClaim::personalGroupSuggestion)
|
||||
.then(CommandManager.argument("permission", StringArgumentType.word()).suggests((ctx, b) -> permSuggestions(ctx, b, true))
|
||||
@ -744,4 +752,54 @@ public class CommandClaim {
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.editPersonalGroup, group, perm, setPerm), Formatting.GOLD), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static int setClaimHome(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
Claim claim = PermHelper.checkReturn(player, PermissionRegistry.EDITCLAIM, PermHelper.genericNoPermMessage(player));
|
||||
if (claim == null)
|
||||
return 0;
|
||||
claim.setHomePos(player.getBlockPos());
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.setHome, player.getBlockPos()), Formatting.GOLD), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static int teleport(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
return teleport(context, context.getSource().getPlayer().getUuid());
|
||||
}
|
||||
|
||||
public static int teleport(CommandContext<ServerCommandSource> context, UUID owner) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
String name = StringArgumentType.getString(context, "claim");
|
||||
return ClaimStorage.get(player.getServerWorld()).allClaimsFromPlayer(owner)
|
||||
.stream().filter(claim -> {
|
||||
if (claim.getClaimName().isEmpty())
|
||||
return claim.getClaimID().toString().equals(name);
|
||||
return claim.getClaimName().equals(name);
|
||||
}).findFirst().map(claim -> {
|
||||
BlockPos pos = claim.getHomePos();
|
||||
if (claim.canInteract(player, PermissionRegistry.TELEPORT, pos, false)) {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (data.setTeleportTo(pos)) {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.teleportHome, Formatting.GOLD), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.teleportHomeFail, Formatting.RED), false);
|
||||
} else
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
return 0;
|
||||
}).orElse(0);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Suggestions> claimSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder build, UUID owner) {
|
||||
return CommandSource.suggestMatching(ClaimStorage.get(context.getSource().getWorld()).allClaimsFromPlayer(owner)
|
||||
.stream().map(claim -> claim.getClaimName().isEmpty() ? claim.getClaimID().toString() : claim.getClaimName()).collect(Collectors.toList()), build);
|
||||
}
|
||||
|
||||
public static GameProfile singleProfile(CommandContext<ServerCommandSource> context, String arg) throws CommandSyntaxException {
|
||||
Collection<GameProfile> profs = GameProfileArgumentType.getProfileArgument(context, arg);
|
||||
if (profs.size() != 1) {
|
||||
throw new SimpleCommandExceptionType(() -> ConfigHandler.lang.onlyOnePlayer).create();
|
||||
}
|
||||
return profs.stream().findFirst().get();
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ public class Config {
|
||||
private final Map<String, Map<ClaimPermission, GlobalType>> globalDefaultPerms = createHashMap(map -> map.put("*", createHashMap(perms -> {
|
||||
perms.put(PermissionRegistry.FLIGHT, GlobalType.ALLTRUE);
|
||||
perms.put(PermissionRegistry.MOBSPAWN, GlobalType.ALLFALSE);
|
||||
perms.put(PermissionRegistry.TELEPORT, GlobalType.ALLFALSE);
|
||||
})));
|
||||
|
||||
public Config(MinecraftServer server) {
|
||||
|
@ -26,6 +26,8 @@ public class LangCommands {
|
||||
map.put("buyBlocks", new String[]{"buyBlocks <amount>", "Buys <amount> claimblocks. Needs gunpowder currency installed."});
|
||||
map.put("trapped", new String[]{"trapped", "If in a claim not owned by the player attempts to teleport the player out of it after 5 seconds."});
|
||||
map.put("unlockDrops", new String[]{"unlockDrops <players>", "Unlocks dropped items from death so other players can pick them up too. Or all of the given players (needs OP)"});
|
||||
map.put("setHome", new String[]{"setHome", "Standing in a claim with sufficient permission sets that claims home to the players position"});
|
||||
map.put("teleport", new String[]{"teleport self | (other <player>) (<claim name> | <claim uuid>)", "Teleport to the given claims home position"});
|
||||
|
||||
map.put("reload", new String[]{"reload", "Reloads the config ingame."});
|
||||
map.put("adminMode", new String[]{"adminMode", "Switches to admin mode ignoring all claims."});
|
||||
|
@ -124,7 +124,7 @@ public class LangConfig {
|
||||
|
||||
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 String trappedMove = "You moved. Aborting teleport";
|
||||
|
||||
public String unlockDropsCmd = "Your deathitems are protected. Use %s to unlock them for other players";
|
||||
public String unlockDrops = "Your deathitems are now unlocked for %s ticks";
|
||||
@ -134,6 +134,10 @@ public class LangConfig {
|
||||
public String claimNameUsed = "The owner of the claim already has another claim with the same name";
|
||||
public String claimNameUsedSub = "One of the subclaim of this claim already has this name";
|
||||
|
||||
public String setHome = "Claim home set to [x=%s,y=%s,z=%s]";
|
||||
public String teleportHome = "Teleporting to claim home. Don't move for 5 seconds";
|
||||
public String teleportHomeFail = "Teleport already happening";
|
||||
|
||||
public LangCommands cmdLang = new LangCommands();
|
||||
|
||||
public LangConfig(MinecraftServer server) {
|
||||
|
@ -148,7 +148,7 @@ public class EntityInteractEvents {
|
||||
pers.setShotFromCrossbow(false);
|
||||
((IPersistentProjectileVars) pers).resetPiercingStatus();
|
||||
}
|
||||
if(proj instanceof EnderPearlEntity)
|
||||
if (proj instanceof EnderPearlEntity)
|
||||
proj.remove();
|
||||
//TODO: find a way to properly update chorus fruit break on hit
|
||||
//player.getServer().send(new ServerTask(player.getServer().getTicks()+2, ()->player.world.updateListeners(pos, state, state, 2)));
|
||||
|
@ -41,6 +41,9 @@ public class CommandPermission {
|
||||
public static final String cmdUnlockAll = "flan.command.unlock.all";
|
||||
public static final String cmdName = "flan.command.name";
|
||||
|
||||
public static final String cmdHome = "flan.command.home";
|
||||
public static final String cmdTeleport = "flan.command.teleport";
|
||||
|
||||
public static boolean perm(CommandSource src, String perm) {
|
||||
return perm(src, perm, false);
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ public class PlayerClaimData {
|
||||
|
||||
private int lastBlockTick, trappedTick = -1, deathPickupTick;
|
||||
private Vec3d trappedPos;
|
||||
private BlockPos tpPos;
|
||||
private EnumEditMode mode = EnumEditMode.DEFAULT;
|
||||
private Claim editingClaim;
|
||||
private ClaimDisplay displayEditing;
|
||||
@ -214,6 +215,16 @@ public class PlayerClaimData {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean setTeleportTo(BlockPos tp) {
|
||||
if (this.trappedTick < 0) {
|
||||
this.trappedTick = 101;
|
||||
this.trappedPos = this.player.getPos();
|
||||
this.tpPos = tp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void tick(Claim currentClaim, Consumer<Claim> cons) {
|
||||
EntityInteractEvents.updateClaim(this.player, currentClaim, cons);
|
||||
boolean tool = this.player.getMainHandStack().getItem() == ConfigHandler.config.claimingItem
|
||||
@ -253,10 +264,15 @@ public class PlayerClaimData {
|
||||
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.tpPos != null) {
|
||||
this.player.teleport(this.tpPos.getX(), this.tpPos.getY(), this.tpPos.getZ());
|
||||
this.tpPos = null;
|
||||
} else {
|
||||
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());
|
||||
}
|
||||
} else if (this.player.getPos().squaredDistanceTo(this.trappedPos) > 0.15) {
|
||||
this.trappedTick = -1;
|
||||
this.trappedPos = null;
|
||||
|
@ -2,8 +2,6 @@ package io.github.flemmli97.flan.claim.fabric;
|
||||
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.fabric.PermissionCheckEvent;
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.github.flemmli97.flan.forgeevent;
|
||||
|
||||
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
|
@ -8,7 +8,7 @@ minecraft_version=1.16.5
|
||||
yarn_mappings=1.16.5+build.9
|
||||
loader_version=0.11.3
|
||||
# Mod Properties
|
||||
mod_version=1.4.3
|
||||
mod_version=1.5.0
|
||||
maven_group=io.github.flemmli97
|
||||
archives_base_name=flan
|
||||
# Dependencies
|
||||
|
Loading…
x
Reference in New Issue
Block a user