Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add permission to allow default nbt #3053

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,17 @@ private <T extends BlockStateHolder> T validate(ParserContext context, T holder)
}
CompoundTag nbt = holder.getNbtData();
if (nbt != null) {
if (!actor.hasPermission("worldedit.anyblock.nbt")) {
if (actor.hasPermission("worldedit.anyblock.nbt")) {
return holder;
}
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 {
throw new DisallowedUsageException(Caption.of(
"fawe.error.nbt.forbidden",
TextComponent.of("worldedit.anyblock.nbt")
Expand Down
Loading