lock death items
This commit is contained in:
parent
5e30049ce7
commit
03dfd44380
@ -55,6 +55,7 @@ public class CommandClaim {
|
|||||||
.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("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("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("trapped").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTrapped)).executes(CommandClaim::trapped))
|
||||||
|
.then(CommandManager.literal("unlockDrops").executes(CommandClaim::unlockDrops))
|
||||||
.then(CommandManager.literal("personalGroups").requires(src -> CommandPermission.perm(src, CommandPermission.cmdPGroup)).executes(CommandClaim::openPersonalGroups))
|
.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("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)))
|
.then(CommandManager.literal("transferClaim").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTransfer)).then(CommandManager.argument("player", GameProfileArgumentType.gameProfile()).executes(CommandClaim::transferClaim)))
|
||||||
@ -203,6 +204,14 @@ public class CommandClaim {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int unlockDrops(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||||
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||||
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
|
data.unlockDeathItems();
|
||||||
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.unlockDrops, ConfigHandler.config.dropTicks), Formatting.GOLD), false);
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
private static int openPersonalGroups(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
private static int openPersonalGroups(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||||
PersonalGroupScreenHandler.openGroupMenu(player);
|
PersonalGroupScreenHandler.openGroupMenu(player);
|
||||||
|
@ -48,6 +48,9 @@ public class Config {
|
|||||||
public int sellPrice = -1;
|
public int sellPrice = -1;
|
||||||
public int buyPrice = -1;
|
public int buyPrice = -1;
|
||||||
|
|
||||||
|
public boolean lockDrops = true;
|
||||||
|
public int dropTicks = 2400;
|
||||||
|
|
||||||
public boolean log;
|
public boolean log;
|
||||||
|
|
||||||
public Map<String, Map<ClaimPermission, Boolean>> defaultGroups = createHashMap(map -> {
|
public Map<String, Map<ClaimPermission, Boolean>> defaultGroups = createHashMap(map -> {
|
||||||
@ -150,6 +153,8 @@ public class Config {
|
|||||||
this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel);
|
this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel);
|
||||||
this.sellPrice = ConfigHandler.fromJson(obj, "sellPrice", this.sellPrice);
|
this.sellPrice = ConfigHandler.fromJson(obj, "sellPrice", this.sellPrice);
|
||||||
this.buyPrice = ConfigHandler.fromJson(obj, "buyPrice", this.buyPrice);
|
this.buyPrice = ConfigHandler.fromJson(obj, "buyPrice", this.buyPrice);
|
||||||
|
this.lockDrops = ConfigHandler.fromJson(obj, "lockDrops", this.lockDrops);
|
||||||
|
this.dropTicks = ConfigHandler.fromJson(obj, "dropTicks", this.dropTicks);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -194,6 +199,8 @@ public class Config {
|
|||||||
obj.addProperty("enableLogs", this.log);
|
obj.addProperty("enableLogs", this.log);
|
||||||
obj.addProperty("sellPrice", this.sellPrice);
|
obj.addProperty("sellPrice", this.sellPrice);
|
||||||
obj.addProperty("buyPrice", this.buyPrice);
|
obj.addProperty("buyPrice", this.buyPrice);
|
||||||
|
obj.addProperty("lockDrops", this.lockDrops);
|
||||||
|
obj.addProperty("dropTicks", this.dropTicks);
|
||||||
try {
|
try {
|
||||||
FileWriter writer = new FileWriter(this.config);
|
FileWriter writer = new FileWriter(this.config);
|
||||||
ConfigHandler.GSON.toJson(obj, writer);
|
ConfigHandler.GSON.toJson(obj, writer);
|
||||||
|
@ -120,6 +120,9 @@ public class LangConfig {
|
|||||||
public String trappedFail = "Rescue not necessary or already rescuing";
|
public String trappedFail = "Rescue not necessary or already rescuing";
|
||||||
public String trappedMove = "You moved. Aborting rescue";
|
public String trappedMove = "You moved. Aborting rescue";
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
public LangConfig(MinecraftServer server) {
|
public LangConfig(MinecraftServer server) {
|
||||||
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
|
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
|
||||||
//server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
//server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||||
|
@ -6,8 +6,10 @@ import io.github.flemmli97.flan.claim.Claim;
|
|||||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||||
import io.github.flemmli97.flan.claim.IPermissionContainer;
|
import io.github.flemmli97.flan.claim.IPermissionContainer;
|
||||||
import io.github.flemmli97.flan.claim.ObjectToPermissionMap;
|
import io.github.flemmli97.flan.claim.ObjectToPermissionMap;
|
||||||
|
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||||
import io.github.flemmli97.flan.mixin.IPersistentProjectileVars;
|
import io.github.flemmli97.flan.mixin.IPersistentProjectileVars;
|
||||||
import io.github.flemmli97.flan.player.IOwnedItem;
|
import io.github.flemmli97.flan.player.IOwnedItem;
|
||||||
|
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||||
import io.github.flemmli97.flan.player.TeleportUtils;
|
import io.github.flemmli97.flan.player.TeleportUtils;
|
||||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
@ -211,14 +213,22 @@ public class EntityInteractEvents {
|
|||||||
|
|
||||||
public static boolean canCollideWith(PlayerEntity player, Entity entity) {
|
public static boolean canCollideWith(PlayerEntity player, Entity entity) {
|
||||||
if (player instanceof ServerPlayerEntity) {
|
if (player instanceof ServerPlayerEntity) {
|
||||||
|
ServerPlayerEntity sPlayer = (ServerPlayerEntity) player;
|
||||||
if (entity instanceof ItemEntity) {
|
if (entity instanceof ItemEntity) {
|
||||||
if (player.getUuid().equals(((IOwnedItem) entity).getPlayerOrigin()))
|
IOwnedItem ownedItem = (IOwnedItem) entity;
|
||||||
|
if (ownedItem.getDeathPlayer() != null && ConfigHandler.config.lockDrops) {
|
||||||
|
ServerPlayerEntity other = sPlayer.getServer().getPlayerManager().getPlayer(ownedItem.getDeathPlayer());
|
||||||
|
if (other == null)
|
||||||
|
return false;
|
||||||
|
return PlayerClaimData.get(other).deathItemsUnlocked();
|
||||||
|
}
|
||||||
|
if (sPlayer.getUuid().equals(ownedItem.getPlayerOrigin()))
|
||||||
return true;
|
return true;
|
||||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) player.world);
|
ClaimStorage storage = ClaimStorage.get(sPlayer.getServerWorld());
|
||||||
BlockPos pos = player.getBlockPos();
|
BlockPos pos = sPlayer.getBlockPos();
|
||||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||||
if (claim != null)
|
if (claim != null)
|
||||||
return claim.canInteract((ServerPlayerEntity) player, PermissionRegistry.PICKUP, pos, false);
|
return claim.canInteract(sPlayer, PermissionRegistry.PICKUP, pos, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -284,6 +294,10 @@ public class EntityInteractEvents {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void updateDroppedItem(PlayerEntity player, ItemEntity entity) {
|
||||||
|
((IOwnedItem) entity).setOriginPlayer((player));
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateClaim(ServerPlayerEntity player, Claim currentClaim, Consumer<Claim> cons) {
|
public static void updateClaim(ServerPlayerEntity player, Claim currentClaim, Consumer<Claim> cons) {
|
||||||
Vec3d pos = player.getPos();
|
Vec3d pos = player.getPos();
|
||||||
BlockPos rounded = TeleportUtils.roundedBlockPos(pos.add(0, player.getEyeHeight(player.getPose()), 0));
|
BlockPos rounded = TeleportUtils.roundedBlockPos(pos.add(0, player.getEyeHeight(player.getPose()), 0));
|
||||||
|
@ -17,6 +17,8 @@ public class ItemEntityMixin implements IOwnedItem {
|
|||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private UUID playerOrigin;
|
private UUID playerOrigin;
|
||||||
|
@Unique
|
||||||
|
private UUID deathPlayerOrigin;
|
||||||
|
|
||||||
@Inject(method = "readCustomDataFromTag", at = @At("RETURN"))
|
@Inject(method = "readCustomDataFromTag", at = @At("RETURN"))
|
||||||
private void readData(CompoundTag tag, CallbackInfo info) {
|
private void readData(CompoundTag tag, CallbackInfo info) {
|
||||||
@ -30,10 +32,19 @@ public class ItemEntityMixin implements IOwnedItem {
|
|||||||
tag.putUuid("Flan:PlayerOrigin", this.playerOrigin);
|
tag.putUuid("Flan:PlayerOrigin", this.playerOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setOriginPlayer(PlayerEntity player) {
|
public void setOriginPlayer(PlayerEntity player) {
|
||||||
this.playerOrigin = player.getUuid();
|
this.playerOrigin = player.getUuid();
|
||||||
|
if (player.isDead())
|
||||||
|
this.deathPlayerOrigin = this.playerOrigin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getDeathPlayer() {
|
||||||
|
return this.deathPlayerOrigin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public UUID getPlayerOrigin() {
|
public UUID getPlayerOrigin() {
|
||||||
return this.playerOrigin;
|
return this.playerOrigin;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package io.github.flemmli97.flan.mixin;
|
package io.github.flemmli97.flan.mixin;
|
||||||
|
|
||||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||||
import io.github.flemmli97.flan.player.IOwnedItem;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.ItemEntity;
|
import net.minecraft.entity.ItemEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
@ -26,7 +25,7 @@ public abstract class PlayerMixin {
|
|||||||
|
|
||||||
@ModifyVariable(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;setPickupDelay(I)V"))
|
@ModifyVariable(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;setPickupDelay(I)V"))
|
||||||
private ItemEntity ownerDrop(ItemEntity entity) {
|
private ItemEntity ownerDrop(ItemEntity entity) {
|
||||||
((IOwnedItem) entity).setOriginPlayer(((PlayerEntity) (Object) this));
|
EntityInteractEvents.updateDroppedItem((PlayerEntity) (Object) this, entity);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ public interface IOwnedItem {
|
|||||||
|
|
||||||
void setOriginPlayer(PlayerEntity player);
|
void setOriginPlayer(PlayerEntity player);
|
||||||
|
|
||||||
|
UUID getDeathPlayer();
|
||||||
|
|
||||||
UUID getPlayerOrigin();
|
UUID getPlayerOrigin();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import io.github.flemmli97.flan.claim.ParticleIndicators;
|
|||||||
import io.github.flemmli97.flan.claim.PermHelper;
|
import io.github.flemmli97.flan.claim.PermHelper;
|
||||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
@ -38,7 +37,7 @@ public class PlayerClaimData {
|
|||||||
|
|
||||||
private int claimBlocks, additionalClaimBlocks, confirmTick, actionCooldown;
|
private int claimBlocks, additionalClaimBlocks, confirmTick, actionCooldown;
|
||||||
|
|
||||||
private int lastBlockTick, trappedTick = -1;
|
private int lastBlockTick, trappedTick = -1, deathPickupTick;
|
||||||
private Vec3d trappedPos;
|
private Vec3d trappedPos;
|
||||||
private EnumEditMode mode = EnumEditMode.DEFAULT;
|
private EnumEditMode mode = EnumEditMode.DEFAULT;
|
||||||
private Claim editingClaim;
|
private Claim editingClaim;
|
||||||
@ -62,7 +61,7 @@ public class PlayerClaimData {
|
|||||||
this.claimBlocks = ConfigHandler.config.startingBlocks;
|
this.claimBlocks = ConfigHandler.config.startingBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerClaimData get(PlayerEntity player) {
|
public static PlayerClaimData get(ServerPlayerEntity player) {
|
||||||
return ((IPlayerClaimImpl) player).get();
|
return ((IPlayerClaimImpl) player).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,11 +260,22 @@ public class PlayerClaimData {
|
|||||||
this.player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.trappedMove), Formatting.RED), false);
|
this.player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.trappedMove), Formatting.RED), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.deathPickupTick--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unlockDeathItems() {
|
||||||
|
this.deathPickupTick = 1200;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deathItemsUnlocked() {
|
||||||
|
return this.deathPickupTick > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clone(PlayerClaimData data) {
|
public void clone(PlayerClaimData data) {
|
||||||
this.claimBlocks = data.claimBlocks;
|
this.claimBlocks = data.claimBlocks;
|
||||||
this.additionalClaimBlocks = data.additionalClaimBlocks;
|
this.additionalClaimBlocks = data.additionalClaimBlocks;
|
||||||
|
if (ConfigHandler.config.lockDrops)
|
||||||
|
this.player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.unlockDropsCmd, "/flan unlockDrops"), Formatting.GOLD), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(MinecraftServer server) {
|
public void save(MinecraftServer server) {
|
||||||
@ -380,7 +390,7 @@ public class PlayerClaimData {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(f));
|
BufferedReader reader = new BufferedReader(new FileReader(f));
|
||||||
PlayerEntity player = server.getPlayerManager().getPlayer(UUID.fromString(f.getName()));
|
ServerPlayerEntity player = server.getPlayerManager().getPlayer(UUID.fromString(f.getName()));
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PlayerClaimData data = PlayerClaimData.get(player);
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
reader.readLine();
|
reader.readLine();
|
||||||
|
Loading…
Reference in New Issue
Block a user