add a blacklist for blockentity and entity tags.

This commit is contained in:
Flemmli97 2021-06-10 19:09:59 +02:00
parent 964a87d98c
commit d8216079a3
6 changed files with 47 additions and 19 deletions

View File

@ -196,6 +196,7 @@ public class Claim implements IPermissionContainer {
return this.removed;
}
@Override
public boolean canInteract(ServerPlayerEntity player, ClaimPermission perm, BlockPos pos, boolean message) {
ActionResult res = ClaimPermissionEvent.CHECK.invoker().check(player, perm, pos);
if (res != ActionResult.PASS)

View File

@ -114,7 +114,7 @@ public class CommandClaim {
.suggests((ctx, b) -> CommandSource.suggestMatching(new String[]{"default", "true", "false"}, b)).executes(CommandClaim::editGroupPerm))))));
builder.then(CommandManager.literal("help").executes(ctx -> CommandHelp.helpMessage(ctx, 0, builder.getArguments()))
.then(CommandManager.argument("page", IntegerArgumentType.integer()).executes(ctx -> CommandHelp.helpMessage(ctx, builder.getArguments())))
.then(CommandManager.literal("cmd").then(CommandManager.argument("command", StringArgumentType.word()).suggests((ctx, sb) -> CommandSource.suggestMatching(CommandHelp.registeredCommands(ctx, builder.getArguments()), sb)).executes(ctx -> CommandHelp.helpCmd(ctx)))));
.then(CommandManager.literal("cmd").then(CommandManager.argument("command", StringArgumentType.word()).suggests((ctx, sb) -> CommandSource.suggestMatching(CommandHelp.registeredCommands(ctx, builder.getArguments()), sb)).executes(CommandHelp::helpCmd))));
dispatcher.register(builder);
}

View File

@ -1,5 +1,6 @@
package io.github.flemmli97.flan.config;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.github.flemmli97.flan.Flan;
@ -35,6 +36,12 @@ public class Config {
public int defaultClaimDepth = 10;
public boolean lenientBlockEntityCheck;
public List<String> ignoredBlocks = new ArrayList<>();
public List<String> blockEntityTagIgnore = Lists.newArrayList(
"IsDeathChest" //vanilla death chest
);
public List<String> entityTagIgnore = Lists.newArrayList(
"graves.marker" //vanilla tweaks
);
public String[] blacklistedWorlds = new String[0];
public boolean worldWhitelist;
@ -70,12 +77,10 @@ public class Config {
}));
});
private final Map<String, Map<ClaimPermission, GlobalType>> globalDefaultPerms = createHashMap(map -> {
map.put("*", createHashMap(perms -> {
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);
}));
});
})));
public Config(MinecraftServer server) {
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
@ -104,8 +109,12 @@ public class Config {
this.defaultClaimDepth = ConfigHandler.fromJson(obj, "defaultClaimDepth", this.defaultClaimDepth);
this.lenientBlockEntityCheck = ConfigHandler.fromJson(obj, "lenientBlockEntityCheck", this.lenientBlockEntityCheck);
this.ignoredBlocks.clear();
JsonArray blockCheck = ConfigHandler.arryFromJson(obj, "ignoredBlocks");
blockCheck.forEach(e -> this.ignoredBlocks.add(e.getAsString()));
ConfigHandler.arryFromJson(obj, "ignoredBlocks").forEach(e -> this.ignoredBlocks.add(e.getAsString()));
this.blockEntityTagIgnore.clear();
ConfigHandler.arryFromJson(obj, "blockEntityTagIgnore").forEach(e -> this.blockEntityTagIgnore.add(e.getAsString()));
this.entityTagIgnore.clear();
ConfigHandler.arryFromJson(obj, "entityTagIgnore").forEach(e -> this.entityTagIgnore.add(e.getAsString()));
JsonArray arr = ConfigHandler.arryFromJson(obj, "blacklistedWorlds");
this.blacklistedWorlds = new String[arr.size()];
for (int i = 0; i < arr.size(); i++)
@ -173,6 +182,13 @@ public class Config {
this.ignoredBlocks.forEach(blocks::add);
obj.add("ignoredBlocks", blocks);
obj.addProperty("lenientBlockEntityCheck", this.lenientBlockEntityCheck);
JsonArray blocksEntities = new JsonArray();
this.blockEntityTagIgnore.forEach(blocksEntities::add);
obj.add("blockEntityTagIgnore", blocksEntities);
JsonArray entities = new JsonArray();
this.entityTagIgnore.forEach(entities::add);
obj.add("entityTagIgnore", entities);
JsonArray arr = new JsonArray();
for (String blacklistedWorld : this.blacklistedWorlds)
arr.add(blacklistedWorld);
@ -220,9 +236,9 @@ public class Config {
if (allMap != null) {
world.getServer().getWorlds().forEach(w -> {
Map<ClaimPermission, GlobalType> wMap = ConfigHandler.config.globalDefaultPerms.getOrDefault(w.getRegistryKey().getValue().toString(), new HashMap<>());
allMap.entrySet().forEach(e -> {
if (!wMap.containsKey(e.getKey()))
wMap.put(e.getKey(), e.getValue());
allMap.forEach((key, value) -> {
if (!wMap.containsKey(key))
wMap.put(key, value);
});
ConfigHandler.config.globalDefaultPerms.put(w.getRegistryKey().getValue().toString(), wMap);
});

View File

@ -22,6 +22,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
@ -43,7 +44,7 @@ public class BlockInteractEvents {
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null) {
Identifier id = Registry.BLOCK.getId(state.getBlock());
if (ConfigHandler.config.ignoredBlocks.contains(id.toString()))
if (alwaysAllowBlock(id, world.getBlockEntity(pos)))
return true;
if (!claim.canInteract(player, PermissionRegistry.BREAK, pos, true)) {
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
@ -75,7 +76,8 @@ public class BlockInteractEvents {
if (!cancelBlockInteract) {
BlockState state = world.getBlockState(hitResult.getBlockPos());
Identifier id = Registry.BLOCK.getId(state.getBlock());
if (ConfigHandler.config.ignoredBlocks.contains(id.toString()))
BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
if (alwaysAllowBlock(id, blockEntity))
return ActionResult.PASS;
ClaimPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
if (perm == PermissionRegistry.PROJECTILES)
@ -97,7 +99,6 @@ public class BlockInteractEvents {
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
return ActionResult.FAIL;
}
BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
if (blockEntity != null) {
if (blockEntity instanceof LecternBlockEntity) {
if (claim.canInteract(player, PermissionRegistry.LECTERNTAKE, hitResult.getBlockPos(), false))
@ -118,6 +119,12 @@ public class BlockInteractEvents {
return ActionResult.PASS;
}
public static boolean alwaysAllowBlock(Identifier id, BlockEntity blockEntity) {
return ConfigHandler.config.ignoredBlocks.contains(id.toString())
|| (blockEntity != null
&& ConfigHandler.config.blockEntityTagIgnore.stream().anyMatch(blockEntity.toTag(new CompoundTag())::contains));
}
public static boolean cancelEntityBlockCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (world.isClient)
return false;

View File

@ -60,7 +60,7 @@ public class EntityInteractEvents {
}
public static ActionResult useAtEntity(PlayerEntity player, World world, Hand hand, Entity entity, /* Nullable */ EntityHitResult hitResult) {
if (player.world.isClient || player.isSpectator())
if (player.world.isClient || player.isSpectator() || canInteract(entity))
return ActionResult.PASS;
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
BlockPos pos = entity.getBlockPos();
@ -75,7 +75,7 @@ public class EntityInteractEvents {
}
public static ActionResult useEntity(PlayerEntity p, World world, Hand hand, Entity entity) {
if (p.world.isClient || p.isSpectator())
if (p.world.isClient || p.isSpectator() || canInteract(entity))
return ActionResult.PASS;
ServerPlayerEntity player = (ServerPlayerEntity) p;
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
@ -103,6 +103,10 @@ public class EntityInteractEvents {
return ActionResult.PASS;
}
public static boolean canInteract(Entity entity) {
return entity.getScoreboardTags().stream().anyMatch(ConfigHandler.config.entityTagIgnore::contains);
}
public static boolean projectileHit(ProjectileEntity proj, HitResult res) {
if (proj.world.isClient)
return false;
@ -182,7 +186,7 @@ public class EntityInteractEvents {
}
public static ActionResult attackSimple(PlayerEntity p, Entity entity, boolean message) {
if (p.world.isClient || p.isSpectator())
if (p.world.isClient || p.isSpectator() || canInteract(entity))
return ActionResult.PASS;
if (entity instanceof Monster)
return ActionResult.PASS;

View File

@ -257,7 +257,7 @@ public class PlayerClaimData {
} else 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);
this.player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.trappedMove, Formatting.RED), false);
}
}
this.deathPickupTick--;