Skip to content

Commit

Permalink
dLocation lockable attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mergu committed Jan 3, 2018
1 parent 991dee4 commit d819280
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -859,7 +859,9 @@ public void onEnable() {
propertyParser.registerProperty(ItemFirework.class, dItem.class);
propertyParser.registerProperty(ItemFlags.class, dItem.class);
propertyParser.registerProperty(ItemInventory.class, dItem.class);
propertyParser.registerProperty(ItemLock.class, dItem.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_10_R1)) {
propertyParser.registerProperty(ItemLock.class, dItem.class);
}
propertyParser.registerProperty(ItemLore.class, dItem.class);
propertyParser.registerProperty(ItemMap.class, dItem.class);
propertyParser.registerProperty(ItemNBT.class, dItem.class);
Expand Down
60 changes: 60 additions & 0 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -724,6 +724,46 @@ else if (type == Material.TRAP_DOOR
}
}

// <--[tag]
// @attribute <l@location.lock>
// @mechanism dLocation.lock
// @returns Element
// @description
// Returns the password to a locked container.
// -->
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_10_R1)
&& attribute.startsWith("lock") && getBlock().getState() instanceof Lockable) {
Lockable lock = (Lockable) getBlock().getState();
return new Element(lock.isLocked() ? lock.getLock() : null)
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <l@location.is_locked>
// @mechanism dLocation.lock
// @returns Element(Boolean)
// @description
// Returns whether the container is locked.
// -->
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_10_R1)
&& attribute.startsWith("is_locked") && getBlock().getState() instanceof Lockable) {
return new Element(((Lockable) getBlock().getState()).isLocked())
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <l@location.is_lockable>
// @mechanism dLocation.lock
// @returns Element(Boolean)
// @description
// Returns whether the container is lockable.
// -->
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_10_R1)
&& attribute.startsWith("is_lockable")) {
return new Element(getBlock().getState() instanceof Lockable)
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <l@location.drops>
// @returns dList(dItem)
Expand Down Expand Up @@ -2146,6 +2186,26 @@ && getBlock().getState() instanceof CreatureSpawner) {
spawner.update();
}

// <--[mechanism]
// @object dLocation
// @name lock
// @input Element
// @description
// Sets the container's lock password.
// Locked containers can only be opened while holding an item with the name of the lock.
// Leave blank to remove a container's lock.
// @tags
// <l@location.lock>
// <l@location.is_locked>
// <l@location.is_lockable>
// -->
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_10_R1)
&& mechanism.matches("lock") && getBlock().getState() instanceof Lockable) {
BlockState state = getBlock().getState();
((Lockable) state).setLock(mechanism.hasValue() ? mechanism.getValue().asString() : null);
state.update();
}

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

0 comments on commit d819280

Please sign in to comment.