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
Showing
3 changed files
with
102 additions
and
1 deletion.
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
100 changes: 100 additions & 0 deletions
100
...in/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityMaxFuseTicks.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,100 @@ | ||
package net.aufdemrand.denizen.objects.properties.entity; | ||
|
||
import net.aufdemrand.denizen.objects.dEntity; | ||
import net.aufdemrand.denizencore.objects.Element; | ||
import net.aufdemrand.denizencore.objects.Mechanism; | ||
import net.aufdemrand.denizencore.objects.dObject; | ||
import net.aufdemrand.denizencore.objects.properties.Property; | ||
import net.aufdemrand.denizencore.tags.Attribute; | ||
import org.bukkit.entity.Creeper; | ||
import org.bukkit.entity.EntityType; | ||
|
||
public class EntityMaxFuseTicks implements Property { | ||
|
||
public static boolean describes(dObject object) { | ||
return object instanceof dEntity && ((dEntity) object).getBukkitEntityType() == EntityType.CREEPER; | ||
} | ||
|
||
public static EntityMaxFuseTicks getFrom(dObject object) { | ||
if (!describes(object)) { | ||
return null; | ||
} | ||
else { | ||
return new EntityMaxFuseTicks((dEntity) object); | ||
} | ||
} | ||
|
||
public static final String[] handledTags = new String[]{ | ||
"max_fuse_ticks" | ||
}; | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"max_fuse_ticks" | ||
}; | ||
|
||
|
||
/////////////////// | ||
// Instance Fields and Methods | ||
///////////// | ||
|
||
private EntityMaxFuseTicks(dEntity entity) { | ||
this.entity = entity; | ||
} | ||
|
||
dEntity entity; | ||
|
||
///////// | ||
// Property Methods | ||
/////// | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return entity.getBukkitEntity() instanceof Creeper ? ((Creeper) entity.getBukkitEntity()).getMaxFuseTicks() + "" : null; | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "max_fuse_ticks"; | ||
} | ||
|
||
@Override | ||
public String getAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) { | ||
return null; | ||
} | ||
|
||
// <--[tag] | ||
// @attribute <e@entity.max_fuse_ticks> | ||
// @returns Element(Integer) | ||
// @mechanism dEntity.max_fuse_ticks | ||
// @group properties | ||
// @description | ||
// Returns the number of fuse ticks a creeper will default to when not triggered. | ||
// --> | ||
if (attribute.startsWith("max_fuse_ticks") && entity.getBukkitEntity() instanceof Creeper) { | ||
return new Element(((Creeper) entity.getBukkitEntity()).getMaxFuseTicks()) | ||
.getAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object dEntity | ||
// @name max_fuse_ticks | ||
// @input Element(Integer) | ||
// @description | ||
// Sets the number of fuse ticks a creeper will default to when not triggered | ||
// @tags | ||
// <e@entity.max_fuse_ticks> | ||
// --> | ||
if (mechanism.matches("max_fuse_ticks") && entity.getBukkitEntity() instanceof Creeper && mechanism.requireInteger()) { | ||
((Creeper) entity.getBukkitEntity()).setMaxFuseTicks(mechanism.getValue().asInt()); | ||
} | ||
|
||
} | ||
} |