-
-
Notifications
You must be signed in to change notification settings - Fork 115
Multi-Sided Sign Support #2796
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
base: dev
Are you sure you want to change the base?
Multi-Sided Sign Support #2796
Changes from 3 commits
cf3b3ba
ab8f8d7
0f2a237
f0b904b
d7f7b5a
052f456
9cf0e07
d46b6a8
4c8310e
055ac88
fa34e12
2184381
8a1f43d
c703bd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1249,14 +1249,14 @@ public static void register() { | |
| // @group world | ||
| // @description | ||
| // Returns a list of lines on a sign. | ||
| // For MC 1.20+, this returns the contents on the front of the sign. | ||
| // To get the contents of the back, see <@link tag LocationTag.sign_contents_back>. | ||
| // --> | ||
| tagProcessor.registerTag(ListTag.class, "sign_contents", (attribute, object) -> { | ||
| if (object.getBlockStateForTag(attribute) instanceof Sign) { | ||
| return new ListTag(Arrays.asList(PaperAPITools.instance.getSignLines(((Sign) object.getBlockStateForTag(attribute))))); | ||
| } | ||
| else { | ||
| return null; | ||
| if (object.getBlockStateForTag(attribute) instanceof Sign sign) { | ||
| return new ListTag(Arrays.asList(PaperAPITools.instance.getSignLines(sign))); | ||
| } | ||
| return null; | ||
| }); | ||
|
|
||
| // <--[tag] | ||
|
|
@@ -4507,6 +4507,51 @@ else if (material.hasModernData() && material.getModernData() instanceof org.buk | |
| } | ||
| return new ElementTag(chiseledBookshelf.getSlot(input.toVector()) + 1); | ||
| }); | ||
|
|
||
| // <--[tag] | ||
| // @attribute <LocationTag.sign_contents_back> | ||
| // @returns ListTag | ||
| // @mechanism LocationTag.sign_contents_back | ||
| // @group world | ||
| // @description | ||
| // Returns the contents on the back of a sign block. | ||
| // For the contents on the front, see <@link tag LocationTag.sign_contents>. | ||
| // Map keys are 'front' and 'back'. | ||
| // --> | ||
| tagProcessor.registerTag(ListTag.class, "sign_contents_back", (attribute, object) -> { | ||
| if (object.getBlockStateForTag(attribute) instanceof Sign sign) { | ||
| return PaperAPITools.instance.getBackSignLines(sign); | ||
| } | ||
| return null; | ||
| }); | ||
|
|
||
| // <--[mechanism] | ||
| // @object LocationTag | ||
| // @name sign_contents_back | ||
| // @input ListTag | ||
| // @description | ||
| // Sets the contents on the back of a sign block. | ||
| // To set the contents of the front, see <@link mechanism LocationTag.sign_contents>. | ||
| // @tags | ||
| // <LocationTag.sign_contents_back> | ||
| // --> | ||
| tagProcessor.registerMechanism("sign_contents_back", false, ListTag.class, (object, mechanism, input) -> { | ||
| if (!(object.getBlockState() instanceof Sign sign)) { | ||
| mechanism.echoError("Mechanism 'LocationTag.sign_contents_back' is only valid for Sign blocks."); | ||
| return; | ||
| } | ||
| for (int i = 0; i < 4; i++) { | ||
| PaperAPITools.instance.setBackSignLine(sign, i, ""); | ||
| } | ||
| CoreUtilities.fixNewLinesToListSeparation(input); | ||
| if (input.size() > 4) { | ||
| mechanism.echoError("Sign can only hold four lines!"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isnt this missing return statement?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An |
||
| } | ||
| for (int i = 0; i < input.size(); i++) { | ||
| PaperAPITools.instance.setBackSignLine(sign, i, input.get(i)); | ||
| } | ||
| sign.update(); | ||
| }); | ||
| } | ||
|
|
||
| // <--[mechanism] | ||
|
|
@@ -4574,6 +4619,38 @@ else if (mechanism.requireObject(EntityTag.class)) { | |
| mechanism.echoError("The 'LocationTag.page' mechanism can only be called on a lectern block."); | ||
| } | ||
| }); | ||
|
|
||
| // <--[mechanism] | ||
| // @object LocationTag | ||
| // @name sign_contents | ||
| // @input ListTag | ||
| // @description | ||
| // Sets the contents of a sign block. | ||
| // For MC 1.20+, this sets the contents on the front of the sign. | ||
| // To set the contents of the back, see <@link mechanism LocationTag.sign_contents_back>. | ||
| // @tags | ||
| // <LocationTag.sign_contents> | ||
| // --> | ||
| tagProcessor.registerMechanism("sign_contents", false, ListTag.class, (object, mechanism, value) -> { | ||
| if (!(object.getBlockState() instanceof Sign sign)) { | ||
| mechanism.echoError("Mechanism 'LocationTag.sign_contents' is only valid for Sign blocks."); | ||
| return; | ||
| } | ||
| for (int i = 0; i < 4; i++) { | ||
| PaperAPITools.instance.setSignLine(sign, i, ""); | ||
| } | ||
| ListTag list = mechanism.valueAsType(ListTag.class); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this required? |
||
| CoreUtilities.fixNewLinesToListSeparation(list); | ||
| if (list.size() > 4) { | ||
| mechanism.echoError("Sign can only hold four lines!"); | ||
| } | ||
| else { | ||
| for (int i = 0; i < list.size(); i++) { | ||
| PaperAPITools.instance.setSignLine(sign, i, list.get(i)); | ||
| } | ||
| } | ||
| sign.update(); | ||
| }); | ||
| } | ||
|
|
||
| public static final ObjectTagProcessor<LocationTag> tagProcessor = new ObjectTagProcessor<>(); | ||
|
|
@@ -4769,33 +4846,6 @@ public void adjust(Mechanism mechanism) { | |
| state.update(); | ||
| } | ||
|
|
||
| // <--[mechanism] | ||
| // @object LocationTag | ||
| // @name sign_contents | ||
| // @input ListTag | ||
| // @description | ||
| // Sets the contents of a sign block. | ||
| // @tags | ||
| // <LocationTag.sign_contents> | ||
| // --> | ||
| if (mechanism.matches("sign_contents") && getBlockState() instanceof Sign) { | ||
| Sign state = (Sign) getBlockState(); | ||
| for (int i = 0; i < 4; i++) { | ||
| PaperAPITools.instance.setSignLine(state, i, ""); | ||
| } | ||
| ListTag list = mechanism.valueAsType(ListTag.class); | ||
| CoreUtilities.fixNewLinesToListSeparation(list); | ||
| if (list.size() > 4) { | ||
| mechanism.echoError("Sign can only hold four lines!"); | ||
| } | ||
| else { | ||
| for (int i = 0; i < list.size(); i++) { | ||
| PaperAPITools.instance.setSignLine(state, i, list.get(i)); | ||
| } | ||
| } | ||
| state.update(); | ||
| } | ||
|
|
||
| // <--[mechanism] | ||
| // @object LocationTag | ||
| // @name skull_skin | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,6 +260,7 @@ public static void registerMainProperties() { | |
| PropertyParser.registerProperty(ItemScript.class, ItemTag.class); | ||
| PropertyParser.registerProperty(ItemSignContents.class, ItemTag.class); // Special case handling in ItemComponentsPatch | ||
| if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { | ||
| PropertyParser.registerProperty(ItemSignContentsBack.class, ItemTag.class); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also has special case handling in ItemComponentsPatch |
||
| PropertyParser.registerProperty(ItemSignIsWaxed.class, ItemTag.class); // Special case handling in ItemComponentsPatch | ||
| } | ||
| registerItemProperty(ItemSkullskin.class, "profile"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,121 +1,63 @@ | ||
| package com.denizenscript.denizen.objects.properties.item; | ||
|
|
||
| import com.denizenscript.denizen.utilities.PaperAPITools; | ||
| import com.denizenscript.denizencore.utilities.debugging.Debug; | ||
| import com.denizenscript.denizen.objects.ItemTag; | ||
| import com.denizenscript.denizencore.objects.Mechanism; | ||
| import com.denizenscript.denizencore.objects.core.ListTag; | ||
| import com.denizenscript.denizencore.objects.ObjectTag; | ||
| import com.denizenscript.denizencore.objects.properties.Property; | ||
| import com.denizenscript.denizencore.tags.Attribute; | ||
| import com.denizenscript.denizencore.utilities.CoreUtilities; | ||
| import org.bukkit.block.Sign; | ||
| import org.bukkit.inventory.meta.BlockStateMeta; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public class ItemSignContents implements Property { | ||
| public class ItemSignContents extends ItemProperty<ListTag> { | ||
|
|
||
| public static boolean describes(ObjectTag item) { | ||
| return item instanceof ItemTag | ||
| && ((ItemTag) item).getItemMeta() instanceof BlockStateMeta | ||
| && ((BlockStateMeta) ((ItemTag) item).getItemMeta()).getBlockState() instanceof Sign; | ||
| } | ||
|
|
||
| public static ItemSignContents getFrom(ObjectTag _item) { | ||
| if (!describes(_item)) { | ||
| return null; | ||
| } | ||
| else { | ||
| return new ItemSignContents((ItemTag) _item); | ||
| } | ||
| } | ||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name sign_contents | ||
| // @input ListTag | ||
| // @description | ||
| // Controls the contents of a sign item. | ||
| // For MC 1.20+, this is the contents on the front of the sign. | ||
| // For the back of the sign, see <@link property ItemTag.sign_contents_back>. | ||
| // --> | ||
|
|
||
| public static final String[] handledTags = new String[] { | ||
| "sign_contents" | ||
| }; | ||
|
|
||
| public static final String[] handledMechs = new String[] { | ||
| "sign_contents" | ||
| }; | ||
|
|
||
| public ListTag getSignContents() { | ||
| return new ListTag(Arrays.asList(PaperAPITools.instance.getSignLines((Sign) ((BlockStateMeta) item.getItemMeta()).getBlockState())), true); | ||
| public static boolean describes(ItemTag item) { | ||
| return item.getItemMeta() instanceof BlockStateMeta blockStateMeta | ||
| && blockStateMeta.getBlockState() instanceof Sign; | ||
| } | ||
|
|
||
| public ItemSignContents(ItemTag _item) { | ||
| item = _item; | ||
| @Override | ||
| public ListTag getPropertyValue() { | ||
| return new ListTag(Arrays.asList(PaperAPITools.instance.getSignLines((Sign) ((BlockStateMeta) getItemMeta()).getBlockState())), true); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason these methods return a |
||
| } | ||
|
|
||
| ItemTag item; | ||
|
|
||
| @Override | ||
| public ObjectTag getObjectAttribute(Attribute attribute) { | ||
|
|
||
| if (attribute == null) { | ||
| return null; | ||
| public void setPropertyValue(ListTag value, Mechanism mechanism) { | ||
| BlockStateMeta bsm = ((BlockStateMeta) getItemMeta()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can use the |
||
| Sign sign = (Sign) bsm.getBlockState(); | ||
| for (int i = 0; i < 4; i++) { | ||
| PaperAPITools.instance.setSignLine(sign, i, ""); | ||
| } | ||
|
|
||
| // <--[tag] | ||
| // @attribute <ItemTag.sign_contents> | ||
| // @returns ListTag | ||
| // @mechanism ItemTag.sign_contents | ||
| // @group properties | ||
| // @description | ||
| // Returns a list of lines on a sign item. | ||
| // --> | ||
| if (attribute.startsWith("sign_contents")) { | ||
| return getSignContents().getObjectAttribute(attribute.fulfill(1)); | ||
| CoreUtilities.fixNewLinesToListSeparation(value); | ||
| if (value.size() > 4) { | ||
| mechanism.echoError("Sign can only hold four lines!"); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyString() { | ||
| for (String line : getSignContents()) { | ||
| if (line.length() > 0) { | ||
| return getSignContents().identify(); | ||
| else { | ||
| for (int i = 0; i < value.size(); i++) { | ||
| PaperAPITools.instance.setSignLine(sign, i, value.get(i)); | ||
| } | ||
| } | ||
| return null; | ||
| bsm.setBlockState(sign); | ||
| getItemStack().setItemMeta(bsm); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just |
||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "sign_contents"; | ||
| } | ||
|
|
||
| @Override | ||
| public void adjust(Mechanism mechanism) { | ||
|
|
||
| // <--[mechanism] | ||
| // @object ItemTag | ||
| // @name sign_contents | ||
| // @input ListTag | ||
| // @description | ||
| // Sets the contents of a sign item. | ||
| // @tags | ||
| // <ItemTag.sign_contents> | ||
| // --> | ||
| if (mechanism.matches("sign_contents")) { | ||
| BlockStateMeta bsm = ((BlockStateMeta) item.getItemMeta()); | ||
| Sign sign = (Sign) bsm.getBlockState(); | ||
| for (int i = 0; i < 4; i++) { | ||
| PaperAPITools.instance.setSignLine(sign, i, ""); | ||
| } | ||
| ListTag list = mechanism.valueAsType(ListTag.class); | ||
| CoreUtilities.fixNewLinesToListSeparation(list); | ||
| if (list.size() > 4) { | ||
| Debug.echoError("Sign can only hold four lines!"); | ||
| } | ||
| else { | ||
| for (int i = 0; i < list.size(); i++) { | ||
| PaperAPITools.instance.setSignLine(sign, i, list.get(i)); | ||
| } | ||
| } | ||
| bsm.setBlockState(sign); | ||
| item.setItemMeta(bsm); | ||
| } | ||
| public static void register() { | ||
| autoRegister("sign_contents", ItemSignContents.class, ListTag.class, false); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this probably could be ternary in the for-each statement, since the body is the same