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
9e968d4
commit 01f71dc
Showing
4 changed files
with
113 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
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
92 changes: 92 additions & 0 deletions
92
.../src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityShulkerPeek.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,92 @@ | ||
package com.denizenscript.denizen.objects.properties.entity; | ||
|
||
import com.denizenscript.denizen.nms.NMSHandler; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
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.tags.Attribute; | ||
import org.bukkit.entity.Shulker; | ||
|
||
public class EntityShulkerPeek implements Property { | ||
|
||
public static boolean describes(ObjectTag entity) { | ||
return entity instanceof EntityTag && | ||
((EntityTag) entity).getBukkitEntity() instanceof Shulker; | ||
} | ||
|
||
public static EntityShulkerPeek getFrom(ObjectTag entity) { | ||
if (!describes(entity)) { | ||
return null; | ||
} | ||
else { | ||
return new EntityShulkerPeek((EntityTag) entity); | ||
} | ||
} | ||
|
||
public static final String[] handledTags = new String[] { | ||
"shulker_peek" | ||
}; | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"shulker_peek" | ||
}; | ||
|
||
private EntityShulkerPeek(EntityTag ent) { | ||
entity = ent; | ||
} | ||
|
||
EntityTag entity; | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return String.valueOf(NMSHandler.getEntityHelper().getShulkerPeek(entity.getBukkitEntity())); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "shulker_peek"; | ||
} | ||
|
||
@Override | ||
public ObjectTag getObjectAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) { | ||
return null; | ||
} | ||
|
||
// <--[tag] | ||
// @attribute <EntityTag.shulker_peek> | ||
// @returns ElementTag(Number) | ||
// @mechanism EntityTag.shulker_peek | ||
// @group properties | ||
// @description | ||
// Returns the peek value of a shulker box (where 0 is fully closed, 100 is fully open). | ||
// --> | ||
if (attribute.startsWith("shulker_peek")) { | ||
return new ElementTag(NMSHandler.getEntityHelper().getShulkerPeek(entity.getBukkitEntity())) | ||
.getObjectAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object EntityTag | ||
// @name shulker_peek | ||
// @input ElementTag(Number) | ||
// @description | ||
// Sets the peek value of a shulker box (where 0 is fully closed, 100 is fully open). | ||
// @tags | ||
// <EntityTag.shulker_peek> | ||
// --> | ||
if (mechanism.matches("shulker_peek") && mechanism.requireInteger()) { | ||
NMSHandler.getEntityHelper().setShulkerPeek(entity.getBukkitEntity(), mechanism.getValue().asInt()); | ||
} | ||
} | ||
} | ||
|
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