Skip to content

Commit fc83763

Browse files
authored
feat: add permission to allow default nbt (#3053)
* feat: add permission to allow default nbt - closes #3044 * Existing nbt permission should allow default nbt
1 parent 0e30588 commit fc83763

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ public Object toRaw() {
6464
}
6565

6666
public abstract int getTypeCode();
67+
68+
@Override
69+
public boolean equals(Object o) {
70+
if (this == o) {
71+
return true;
72+
} else if (!this.getClass().equals(o.getClass())) {
73+
return false;
74+
}
75+
return linTag.equals(((Tag<?, ?>) o).linTag);
76+
}
6777
//FAWE end
6878

6979
}

worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,20 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa
538538
//FAWE end
539539
}
540540

541-
if (DeprecationUtil.isSign(blockType)) {
541+
//FAWE start - only handle if extra data is actually supplied or if the user has permission for nbt
542+
boolean allowWorkingDefault = context.requireActor().hasPermission("worldedit.anyblock.nbt") && nbt != null;
543+
if (DeprecationUtil.isSign(blockType) && (blockAndExtraData.length > 1 || allowWorkingDefault)) {
544+
//FAWE end
542545
// Allow special sign text syntax
543546
String[] text = new String[4];
544547
text[0] = blockAndExtraData.length > 1 ? blockAndExtraData[1] : "";
545548
text[1] = blockAndExtraData.length > 2 ? blockAndExtraData[2] : "";
546549
text[2] = blockAndExtraData.length > 3 ? blockAndExtraData[3] : "";
547550
text[3] = blockAndExtraData.length > 4 ? blockAndExtraData[4] : "";
548551
return validate(context, new SignBlock(state, text));
549-
} else if (blockType == BlockTypes.SPAWNER && (blockAndExtraData.length > 1 || nbt != null)) {
552+
//FAWE start - only handle if extra data is actually supplied or if the user has permission for nbt
553+
} else if (blockType == BlockTypes.SPAWNER && (blockAndExtraData.length > 1 || allowWorkingDefault)) {
554+
//FAWE end
550555
// Allow setting mob spawn type
551556
String mobName;
552557
if (blockAndExtraData.length > 1) {
@@ -563,7 +568,9 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa
563568
mobName = EntityTypes.PIG.id();
564569
}
565570
return validate(context, new MobSpawnerBlock(state, mobName));
566-
} else if ((blockType == BlockTypes.PLAYER_HEAD || blockType == BlockTypes.PLAYER_WALL_HEAD) && (blockAndExtraData.length > 1 || nbt != null)) {
571+
//FAWE start - only handle if extra data is actually supplied or if the user has permission for nbt
572+
} else if ((blockType == BlockTypes.PLAYER_HEAD || blockType == BlockTypes.PLAYER_WALL_HEAD) && (blockAndExtraData.length > 1 || allowWorkingDefault)) {
573+
//FAWE end
567574
// allow setting type/player/rotation
568575
if (blockAndExtraData.length == 1) {
569576
return validate(context, new SkullBlock(state));
@@ -600,7 +607,17 @@ private <T extends BlockStateHolder> T validate(ParserContext context, T holder)
600607
}
601608
CompoundTag nbt = holder.getNbtData();
602609
if (nbt != null) {
603-
if (!actor.hasPermission("worldedit.anyblock.nbt")) {
610+
if (actor.hasPermission("worldedit.anyblock.nbt")) {
611+
return holder;
612+
}
613+
if (nbt.equals(holder.getBlockType().getDefaultState().getNbtData())) {
614+
if (!actor.hasPermission("worldedit.anyblock.default-nbt")) {
615+
throw new DisallowedUsageException(Caption.of(
616+
"fawe.error.nbt.forbidden",
617+
TextComponent.of("worldedit.anyblock.default-nbt")
618+
));
619+
}
620+
} else {
604621
throw new DisallowedUsageException(Caption.of(
605622
"fawe.error.nbt.forbidden",
606623
TextComponent.of("worldedit.anyblock.nbt")

0 commit comments

Comments
 (0)