Fix disallowedBlocks

This commit is contained in:
Jesse Boyd 2019-04-11 14:05:29 +10:00
parent f726c9afc4
commit 24590199c8
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
6 changed files with 45 additions and 24 deletions

View File

@ -272,7 +272,7 @@ public class SnipeData {
* @param voxelId the voxelId to set * @param voxelId the voxelId to set
*/ */
public final void setVoxelId(final int voxelId) { public final void setVoxelId(final int voxelId) {
if (WorldEdit.getInstance().getConfiguration().disallowedBlocks.contains(BlockTypes.getFromStateId(voxelId).getId())) { if (WorldEdit.getInstance().getConfiguration().checkDisallowedBlocks(BlockTypes.getFromStateId(voxelId).getDefaultState())) {
if (owner != null) { if (owner != null) {
Player plr = owner.getPlayer(); Player plr = owner.getPlayer();
if (plr != null) { if (plr != null) {

View File

@ -55,7 +55,7 @@ public class VoxelVoxelCommand extends VoxelCommand {
Material blockType = block.getType(); Material blockType = block.getType();
BlockType weType = BukkitAdapter.adapt(blockType); BlockType weType = BukkitAdapter.adapt(blockType);
if(!player.hasPermission("voxelsniper.ignorelimitations") && WorldEdit.getInstance().getConfiguration().disallowedBlocks.contains(weType.getId())) { if(!player.hasPermission("voxelsniper.ignorelimitations") && WorldEdit.getInstance().getConfiguration().checkDisallowedBlocks(weType.getDefaultState())) {
player.sendMessage("You are not allowed to use " + blockType.name() + ". (WorldEdit config.yml)"); player.sendMessage("You are not allowed to use " + blockType.name() + ". (WorldEdit config.yml)");
return true; return true;
} }
@ -68,7 +68,7 @@ public class VoxelVoxelCommand extends VoxelCommand {
} else { } else {
BlockType weType = BlockTypes.parse(args[0]); BlockType weType = BlockTypes.parse(args[0]);
if(weType != null) { if(weType != null) {
if(!player.hasPermission("voxelsniper.ignorelimitations") && WorldEdit.getInstance().getConfiguration().disallowedBlocks.contains(weType.getId())) { if(!player.hasPermission("voxelsniper.ignorelimitations") && WorldEdit.getInstance().getConfiguration().checkDisallowedBlocks(weType.getDefaultState())) {
player.sendMessage("You are not allowed to use " + weType + "."); player.sendMessage("You are not allowed to use " + weType + ".");
return true; return true;
} else { } else {

View File

@ -20,7 +20,11 @@
package com.sk89q.worldedit; package com.sk89q.worldedit;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.sk89q.worldedit.extent.NullExtent;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.BlockMaskBuilder;
import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
@ -40,6 +44,7 @@ public abstract class LocalConfiguration {
public boolean profile = false; public boolean profile = false;
public boolean traceUnflushedSessions = false; public boolean traceUnflushedSessions = false;
public Set<String> disallowedBlocks = new HashSet<>(); public Set<String> disallowedBlocks = new HashSet<>();
protected BlockMask disallowedBlocksMask;
public int defaultChangeLimit = -1; public int defaultChangeLimit = -1;
public int maxChangeLimit = -1; public int maxChangeLimit = -1;
public int defaultMaxPolygonalPoints = -1; public int defaultMaxPolygonalPoints = -1;
@ -149,6 +154,17 @@ public abstract class LocalConfiguration {
*/ */
public abstract void load(); public abstract void load();
public boolean checkDisallowedBlocks(BlockStateHolder holder) {
if (disallowedBlocksMask == null) {
BlockMaskBuilder builder = new BlockMaskBuilder();
for (String blockRegex : disallowedBlocks) {
builder.addRegex(blockRegex);
}
disallowedBlocksMask = builder.build(new NullExtent());
}
return disallowedBlocksMask.test(holder.toImmutableState());
}
/** /**
* Get the working directory to work from. * Get the working directory to work from.
* *

View File

@ -50,6 +50,7 @@ import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
@ -257,21 +258,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
// Check if the item is allowed // Check if the item is allowed
BlockType blockType = state.getBlockType(); BlockType blockType = state.getBlockType();
if (context.isRestricted()) { if (nbt != null) return validate(context, state.toBaseBlock(nbt));
Actor actor = context.requireActor();
if (actor != null) {
if (!actor.hasPermission("worldedit.anyblock") && worldEdit.getConfiguration().disallowedBlocks.contains(blockType.getId())) {
throw new DisallowedUsageException("You are not allowed to use '" + input + "'");
}
if (nbt != null) {
if (!actor.hasPermission("worldedit.anyblock")) {
throw new DisallowedUsageException("You are not allowed to nbt'");
}
}
}
}
if (nbt != null) return state.toBaseBlock(nbt);
if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN) { if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN) {
// Allow special sign text syntax // Allow special sign text syntax
@ -280,7 +267,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
text[1] = blockAndExtraData.length > 2 ? blockAndExtraData[2] : ""; text[1] = blockAndExtraData.length > 2 ? blockAndExtraData[2] : "";
text[2] = blockAndExtraData.length > 3 ? blockAndExtraData[3] : ""; text[2] = blockAndExtraData.length > 3 ? blockAndExtraData[3] : "";
text[3] = blockAndExtraData.length > 4 ? blockAndExtraData[4] : ""; text[3] = blockAndExtraData.length > 4 ? blockAndExtraData[4] : "";
return new SignBlock(state, text); return validate(context, new SignBlock(state, text));
} else if (blockType == BlockTypes.SPAWNER) { } else if (blockType == BlockTypes.SPAWNER) {
// Allow setting mob spawn type // Allow setting mob spawn type
if (blockAndExtraData.length > 1) { if (blockAndExtraData.length > 1) {
@ -299,21 +286,37 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
.filter(s -> s.startsWith(finalMobName)) .filter(s -> s.startsWith(finalMobName))
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
return new MobSpawnerBlock(state, mobName); return validate(context, new MobSpawnerBlock(state, mobName));
} else { } else {
return new MobSpawnerBlock(state, MobType.PIG.getName()); return validate(context, new MobSpawnerBlock(state, MobType.PIG.getName()));
} }
} else if (blockType == BlockTypes.PLAYER_HEAD || blockType == BlockTypes.PLAYER_WALL_HEAD) { } else if (blockType == BlockTypes.PLAYER_HEAD || blockType == BlockTypes.PLAYER_WALL_HEAD) {
// allow setting type/player/rotation // allow setting type/player/rotation
if (blockAndExtraData.length <= 1) { if (blockAndExtraData.length <= 1) {
return new SkullBlock(state); return validate(context, new SkullBlock(state));
} }
String type = blockAndExtraData[1]; String type = blockAndExtraData[1];
return new SkullBlock(state, type.replace(" ", "_")); // valid MC usernames return validate(context, new SkullBlock(state, type.replace(" ", "_"))); // valid MC usernames
} else { } else {
return state.toBaseBlock(); return validate(context, state.toBaseBlock());
} }
} }
private <T extends BlockStateHolder> T validate(ParserContext context, T holder) {
if (context.isRestricted()) {
Actor actor = context.requireActor();
if (!actor.hasPermission("worldedit.anyblock") && worldEdit.getConfiguration().checkDisallowedBlocks(holder)) {
throw new DisallowedUsageException("You are not allowed to use '" + holder + "'");
}
CompoundTag nbt = holder.getNbtData();
if (nbt != null) {
if (!actor.hasPermission("worldedit.anyblock")) {
throw new DisallowedUsageException("You are not allowed to nbt'");
}
}
}
return holder;
}
} }

View File

@ -80,6 +80,7 @@ public class PropertiesConfiguration extends LocalConfiguration {
profile = getBool("profile", profile); profile = getBool("profile", profile);
traceUnflushedSessions = getBool("trace-unflushed-sessions", traceUnflushedSessions); traceUnflushedSessions = getBool("trace-unflushed-sessions", traceUnflushedSessions);
disallowedBlocks = getStringSet("disallowed-blocks", getDefaultDisallowedBlocks()); disallowedBlocks = getStringSet("disallowed-blocks", getDefaultDisallowedBlocks());
disallowedBlocksMask = null;
allowedDataCycleBlocks = allowedDataCycleBlocks =
new HashSet<>(getStringSet("limits.allowed-data-cycle-blocks", null)); new HashSet<>(getStringSet("limits.allowed-data-cycle-blocks", null));
defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit); defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit);

View File

@ -79,6 +79,7 @@ public class YAMLConfiguration extends LocalConfiguration {
butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius)); butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius));
disallowedBlocks = new HashSet<>(config.getStringList("limits.disallowed-blocks", Lists.newArrayList(getDefaultDisallowedBlocks()))); disallowedBlocks = new HashSet<>(config.getStringList("limits.disallowed-blocks", Lists.newArrayList(getDefaultDisallowedBlocks())));
disallowedBlocksMask = null;
allowedDataCycleBlocks = new HashSet<>(config.getStringList("limits.allowed-data-cycle-blocks", null)); allowedDataCycleBlocks = new HashSet<>(config.getStringList("limits.allowed-data-cycle-blocks", null));
registerHelp = config.getBoolean("register-help", true); registerHelp = config.getBoolean("register-help", true);