Skip to content

Commit

Permalink
feat: add permission to allow default nbt
Browse files Browse the repository at this point in the history
 - closes #3044
  • Loading branch information
dordsor21 committed Dec 31, 2024
1 parent 7160792 commit dba5fea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
10 changes: 10 additions & 0 deletions worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public Object toRaw() {
}

public abstract int getTypeCode();

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (!this.getClass().equals(o.getClass())) {
return false;
}
return linTag.equals(((Tag<?, ?>) o).linTag);
}
//FAWE end

}
Original file line number Diff line number Diff line change
Expand Up @@ -538,15 +538,20 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa
//FAWE end
}

if (DeprecationUtil.isSign(blockType)) {
//FAWE start - only handle if extra data is actually supplied or if the user has permission for nbt
boolean allowWorkingDefault = context.requireActor().hasPermission("worldedit.anyblock.nbt") && nbt != null;
if (DeprecationUtil.isSign(blockType) && (blockAndExtraData.length > 1 || allowWorkingDefault)) {
//FAWE end
// Allow special sign text syntax
String[] text = new String[4];
text[0] = blockAndExtraData.length > 1 ? blockAndExtraData[1] : "";
text[1] = blockAndExtraData.length > 2 ? blockAndExtraData[2] : "";
text[2] = blockAndExtraData.length > 3 ? blockAndExtraData[3] : "";
text[3] = blockAndExtraData.length > 4 ? blockAndExtraData[4] : "";
return validate(context, new SignBlock(state, text));
} else if (blockType == BlockTypes.SPAWNER && (blockAndExtraData.length > 1 || nbt != null)) {
//FAWE start - only handle if extra data is actually supplied or if the user has permission for nbt
} else if (blockType == BlockTypes.SPAWNER && (blockAndExtraData.length > 1 || allowWorkingDefault)) {
//FAWE end
// Allow setting mob spawn type
String mobName;
if (blockAndExtraData.length > 1) {
Expand All @@ -563,7 +568,9 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa
mobName = EntityTypes.PIG.id();
}
return validate(context, new MobSpawnerBlock(state, mobName));
} else if ((blockType == BlockTypes.PLAYER_HEAD || blockType == BlockTypes.PLAYER_WALL_HEAD) && (blockAndExtraData.length > 1 || nbt != null)) {
//FAWE start - only handle if extra data is actually supplied or if the user has permission for nbt
} else if ((blockType == BlockTypes.PLAYER_HEAD || blockType == BlockTypes.PLAYER_WALL_HEAD) && (blockAndExtraData.length > 1 || allowWorkingDefault)) {
//FAWE end
// allow setting type/player/rotation
if (blockAndExtraData.length == 1) {
return validate(context, new SkullBlock(state));
Expand Down Expand Up @@ -600,7 +607,14 @@ private <T extends BlockStateHolder> T validate(ParserContext context, T holder)
}
CompoundTag nbt = holder.getNbtData();
if (nbt != null) {
if (!actor.hasPermission("worldedit.anyblock.nbt")) {
if (nbt.equals(holder.getBlockType().getDefaultState().getNbtData())) {
if (!actor.hasPermission("worldedit.anyblock.default-nbt")) {
throw new DisallowedUsageException(Caption.of(
"fawe.error.nbt.forbidden",
TextComponent.of("worldedit.anyblock.default-nbt")
));
}
} else if (!actor.hasPermission("worldedit.anyblock.nbt")) {
throw new DisallowedUsageException(Caption.of(
"fawe.error.nbt.forbidden",
TextComponent.of("worldedit.anyblock.nbt")
Expand Down

0 comments on commit dba5fea

Please sign in to comment.