-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Open
MC-Samuel
wants to merge
4
commits into
DenizenScript:dev
Choose a base branch
from
MC-Samuel:sign_back
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Multi-Sided Sign Support #2796
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 31 additions & 89 deletions
120
plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemSignContents.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| ItemTag item; | ||
|
|
||
| @Override | ||
| public ObjectTag getObjectAttribute(Attribute attribute) { | ||
|
|
||
| if (attribute == null) { | ||
| return null; | ||
| public void setPropertyValue(ListTag value, Mechanism mechanism) { | ||
| BlockStateMeta bsm = ((BlockStateMeta) getItemMeta()); | ||
| 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); | ||
| } | ||
|
|
||
| @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); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
isnt this missing return statement?