ignore block config. for things like gravestones. fixes #37 but also #36

This commit is contained in:
Flemmli97 2021-03-08 21:43:46 +01:00
parent d82cec790e
commit a8c8d7508b
2 changed files with 19 additions and 2 deletions

View File

@ -18,6 +18,8 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Config {
@ -30,6 +32,7 @@ public class Config {
public int minClaimsize = 100;
public int defaultClaimDepth = 10;
public boolean lenientBlockEntityCheck;
public List<String> ignoredBlocks = new ArrayList<>();
public String[] blacklistedWorlds = new String[0];
public boolean worldWhitelist;
@ -72,6 +75,9 @@ public class Config {
this.minClaimsize = ConfigHandler.fromJson(obj, "minClaimsize", this.minClaimsize);
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()));
JsonArray arr = ConfigHandler.arryFromJson(obj, "blacklistedWorlds");
this.blacklistedWorlds = new String[arr.size()];
for (int i = 0; i < arr.size(); i++)
@ -114,10 +120,13 @@ public class Config {
obj.addProperty("ticksForNextBlock", this.ticksForNextBlock);
obj.addProperty("minClaimsize", this.minClaimsize);
obj.addProperty("defaultClaimDepth", this.defaultClaimDepth);
JsonArray blocks = new JsonArray();
this.ignoredBlocks.forEach(blocks::add);
obj.add("ignoredBlocks", blocks);
obj.addProperty("lenientBlockEntityCheck", this.lenientBlockEntityCheck);
JsonArray arr = new JsonArray();
for (int i = 0; i < this.blacklistedWorlds.length; i++)
arr.add(this.blacklistedWorlds[i]);
for (String blacklistedWorld : this.blacklistedWorlds)
arr.add(blacklistedWorld);
obj.add("blacklistedWorlds", arr);
obj.addProperty("worldWhitelist", this.worldWhitelist);
obj.addProperty("allowMobSpawnToggle", this.allowMobSpawnToggle);

View File

@ -27,8 +27,10 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
public class BlockInteractEvents {
@ -40,6 +42,9 @@ public class BlockInteractEvents {
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null) {
Identifier id = Registry.BLOCK.getId(state.getBlock());
if (ConfigHandler.config.ignoredBlocks.contains(id.toString()))
return true;
if (!claim.canInteract(player, PermissionRegistry.BREAK, pos, true)) {
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
return false;
@ -69,6 +74,9 @@ public class BlockInteractEvents {
boolean cancelBlockInteract = player.shouldCancelInteraction() && emptyHand;
if (!cancelBlockInteract) {
BlockState state = world.getBlockState(hitResult.getBlockPos());
Identifier id = Registry.BLOCK.getId(state.getBlock());
if (ConfigHandler.config.ignoredBlocks.contains(id.toString()))
return ActionResult.PASS;
ClaimPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
//Pressureplate handled elsewhere
if (perm != null && perm != PermissionRegistry.PRESSUREPLATE) {