Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.*;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
import org.bukkit.event.entity.CreatureSpawnEvent;
Expand Down Expand Up @@ -104,15 +105,36 @@ public String getPlayerListName(Player player) {
public String[] getSignLines(Sign sign) {
String[] output = new String[4];
int i = 0;
for (Component component : sign.lines()) {
List<Component> list = NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) ? sign.getSide(Side.FRONT).lines() : sign.lines();
for (Component component : list) {
output[i++] = PaperModule.stringifyComponent(component);
}
return output;
}

@Override
public String[] getBackSignLines(Sign sign) {
String[] output = new String[4];
int i = 0;
for (Component component : sign.getSide(Side.BACK).lines()) {
output[i++] = PaperModule.stringifyComponent(component);
}
return output;
}

@Override
public void setSignLine(Sign sign, int line, String text) {
sign.line(line, PaperModule.parseFormattedText(text == null ? "" : text, ChatColor.BLACK));
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) {
sign.getSide(Side.FRONT).line(line, PaperModule.parseFormattedText(text == null ? "" : text, ChatColor.BLACK));
}
else {
sign.line(line, PaperModule.parseFormattedText(text == null ? "" : text, ChatColor.BLACK));
}
}

@Override
public void setBackSignLine(Sign sign, int line, String text) {
sign.getSide(Side.BACK).line(line, PaperModule.parseFormattedText(text == null ? "" : text, ChatColor.BLACK));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 new ListTag(Arrays.asList(PaperAPITools.instance.getBackSignLines(sign)), true);
}
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!");
Copy link
Contributor

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?

}
for (int i = 0; i < input.size(); i++) {
PaperAPITools.instance.setBackSignLine(sign, i, input.get(i));
}
sign.update();
});
}

// <--[mechanism]
Expand Down Expand Up @@ -4574,6 +4619,35 @@ 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, "");
}
CoreUtilities.fixNewLinesToListSeparation(value);
if (value.size() > 4) {
mechanism.echoError("Sign can only hold four lines!");
}
for (int i = 0; i < value.size(); i++) {
PaperAPITools.instance.setSignLine(sign, i, value.get(i));
}
sign.update();
});
}

public static final ObjectTagProcessor<LocationTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down Expand Up @@ -4769,33 +4843,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
PropertyParser.registerProperty(ItemSignIsWaxed.class, ItemTag.class); // Special case handling in ItemComponentsPatch
}
registerItemProperty(ItemSkullskin.class, "profile");
Expand Down
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);
}
}
Loading