Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5f6611
commit 288d39b
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
84 changes: 84 additions & 0 deletions
84
...in/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHinge.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.denizenscript.denizen.objects.properties.material; | ||
|
||
import com.denizenscript.denizen.objects.MaterialTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
import org.bukkit.block.data.type.Door; | ||
|
||
public class MaterialHinge implements Property { | ||
|
||
public static boolean describes(ObjectTag material) { | ||
return material instanceof MaterialTag | ||
&& ((MaterialTag) material).hasModernData() | ||
&& ((MaterialTag) material).getModernData().data instanceof Door; | ||
} | ||
|
||
public static MaterialHinge getFrom(ObjectTag _material) { | ||
if (!describes(_material)) { | ||
return null; | ||
} | ||
else { | ||
return new MaterialHinge((MaterialTag) _material); | ||
} | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"hinge" | ||
}; | ||
|
||
private MaterialHinge(MaterialTag _material) { | ||
material = _material; | ||
} | ||
|
||
MaterialTag material; | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <MaterialTag.hinge> | ||
// @returns ElementTag | ||
// @mechanism MaterialTag.hinge | ||
// @group properties | ||
// @description | ||
// Returns a door's hinge side. | ||
// Output is LEFT or RIGHT. | ||
// --> | ||
PropertyParser.<MaterialHinge>registerTag("hinge", (attribute, material) -> { | ||
return new ElementTag(material.getDoor().getHinge().name()); | ||
}); | ||
} | ||
|
||
public Door getDoor() { | ||
return (Door) material.getModernData().data; | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return getDoor().getHinge().name(); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "hinge"; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object MaterialTag | ||
// @name hinge | ||
// @input ElementTag | ||
// @description | ||
// Sets a door's hinge side to LEFT or RIGHT. | ||
// @tags | ||
// <MaterialTag.hinge> | ||
// --> | ||
if (mechanism.matches("hinge") && mechanism.requireEnum(false, Door.Hinge.values())) { | ||
getDoor().setHinge(Door.Hinge.valueOf(mechanism.getValue().asString().toUpperCase())); | ||
} | ||
} | ||
} |
This file contains 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