Skip to content

Commit

Permalink
Add dLocation custom_name tag/mec
Browse files Browse the repository at this point in the history
  • Loading branch information
MusicScore committed Jan 17, 2019
1 parent 6a76ea1 commit c13627f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -2158,6 +2158,20 @@ else if (this.getWorld() == toLocation.getWorld()) {
}
}

// <--[tag]
// @attribute <l@location.custom_name>
// @returns Element
// @mechanism custom_name
// @description
// Returns the custom name of this block.
// Only works for nameable blocks, such as chests and dispensers.
// -->
if (attribute.startsWith("custom_name")) {
if (getBlock().getState() instanceof Nameable) {
return new Element(((Nameable) getBlock().getState()).getCustomName()).getAttribute(attribute.fulfill(1));
}
}

// Iterate through this object's properties' attributes
for (Property property : PropertyParser.getProperties(this)) {
String returned = property.getAttribute(attribute);
Expand Down Expand Up @@ -2419,6 +2433,28 @@ else if (getBlock().getType() == Material.FLOWER_POT) {
}
}

// <--[mechanism]
// @object dLocation
// @name custom_name
// @input Element
// @description
// Sets the custom name of the block.
// Use no value to reset the block's name.
// @tags
// <l@location.custom_name>
// -->
if (mechanism.matches("custom_name")) {
if (getBlock().getState() instanceof Nameable) {
String title = mechanism.getValue().asString();
if (!mechanism.hasValue()) {
title = null;
}
BlockState state = getBlock().getState();
((Nameable) state).setCustomName(title);
state.update(true);
}
}

// <--[mechanism]
// @object dLocation
// @name furnace_burn_time
Expand Down

0 comments on commit c13627f

Please sign in to comment.