Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mcmonkey4eva/Denizen
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 11, 2015
2 parents 2f35758 + ba8947e commit 91d8711
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ public void onEnable() {
// register core dEntity properties
propertyParser.registerProperty(EntityAge.class, dEntity.class);
propertyParser.registerProperty(EntityAI.class, dEntity.class);
propertyParser.registerProperty(EntityAnger.class, dEntity.class);
propertyParser.registerProperty(EntityAngry.class, dEntity.class);
propertyParser.registerProperty(EntityArmorPose.class, dEntity.class);
propertyParser.registerProperty(EntityChestCarrier.class, dEntity.class);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,28 @@ else if (split.length > 1) {
}
}

// <--[mechanism]
// @object dPlayer
// @name is_whitelisted
// @input Element(Boolean)
// @description
// Changes whether the player is whitelisted or not.
// -->
if (mechanism.matches("is_whitelisted") && mechanism.requireBoolean()) {
getPlayerEntity().setWhitelisted(mechanism.getValue().asBoolean());
}

// <--[mechanism]
// @object dPlayer
// @name is_op
// @input Element(Boolean)
// @description
// Changes whether the player is a server operator or not.
// -->
if (mechanism.matches("is_op") && mechanism.requireBoolean()) {
getPlayerEntity().setOp(mechanism.getValue().asBoolean());
}

// Iterate through this object's properties' mechanisms
for (Property property : PropertyParser.getProperties(this)) {
property.adjust(mechanism);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,26 @@ public String getAttribute(Attribute attribute) {
// @description
// Returns the element with all color encoding stripped.
// -->
if (attribute.startsWith("strip_color"))
if (attribute.startsWith("strip_color")) {
return new Element(ChatColor.stripColor(element.asString())).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <el@element.parse_color>
// @returns Element
// @group string manipulation
// @description
// Returns the element with all color codes parsed.
// Optionally, specify a character to prefix the color ids. Defaults to '&' if not specified.
// -->
if (attribute.startsWith("parse_color")) {
char prefix = '&';
if (attribute.hasContext(1)) {
prefix = attribute.getContext(1).charAt(0);
}
return new Element(ChatColor.translateAlternateColorCodes(prefix, element.asString()))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <el@element.to_itemscript_hash>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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.EntityType;
import org.bukkit.entity.PigZombie;

public class EntityAnger implements Property {

public static boolean describes(dObject entity) {
return entity instanceof dEntity && ((dEntity) entity).getBukkitEntityType() == EntityType.PIG_ZOMBIE;
}

public static EntityAnger getFrom(dObject entity) {
if (!describes(entity)) return null;

else return new EntityAnger((dEntity) entity);
}

///////////////////
// Instance Fields and Methods
/////////////

private EntityAnger(dEntity entity) {
this.entity = entity;
}

dEntity entity;

/////////
// Property Methods
///////

@Override
public String getPropertyString() {
return String.valueOf(((PigZombie) entity.getBukkitEntity()).getAnger());
}

@Override
public String getPropertyId() {
return "anger";
}

///////////
// dObject Attributes
////////

@Override
public String getAttribute(Attribute attribute) {

if (attribute == null) return "null";

// <--[tag]
// @attribute <e@entity.anger>
// @returns Element(Integer)
// @mechanism dEntity.anger
// @group properties
// @description
// Returns the anger level of a PigZombie.
// -->
if (attribute.startsWith("anger")) {
if (entity.getBukkitEntityType() == EntityType.PIG_ZOMBIE) {
return new Element(((PigZombie) entity.getBukkitEntity()).getAnger())
.getAttribute(attribute.fulfill(1));
}
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object dEntity
// @name anger
// @input Element(Boolean)
// @description
// Changes the anger level of a PigZombie.
// @tags
// <e@entity.anger>
// -->

if (mechanism.matches("anger") && mechanism.requireInteger()) {
if (entity.getBukkitEntityType() == EntityType.PIG_ZOMBIE) {
((PigZombie) entity.getBukkitEntity()).setAnger(mechanism.getValue().asInt());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Wolf;

public class EntityAngry implements Property {

public static boolean describes(dObject entity) {
return entity instanceof dEntity && ((dEntity) entity).getBukkitEntityType() == EntityType.WOLF;
return entity instanceof dEntity && (((dEntity) entity).getBukkitEntityType() == EntityType.WOLF
|| ((dEntity) entity).getBukkitEntityType() == EntityType.PIG_ZOMBIE);
}

public static EntityAngry getFrom(dObject entity) {
Expand All @@ -37,10 +39,23 @@ private EntityAngry(dEntity entity) {

@Override
public String getPropertyString() {
if (!((Wolf) entity.getBukkitEntity()).isAngry())
return null;
else
return "true";
if (entity.getBukkitEntityType() == EntityType.WOLF) {
if (!((Wolf) entity.getLivingEntity()).isAngry()) {
return null;
}
else {
return "true";
}
}
else if (entity.getBukkitEntityType() == EntityType.PIG_ZOMBIE) {
if (!((PigZombie) entity.getLivingEntity()).isAngry()) {
return null;
}
else {
return "true";
}
}
return null;
}

@Override
Expand All @@ -65,9 +80,16 @@ public String getAttribute(Attribute attribute) {
// @description
// If the entity is a wolf, returns whether the wolf is angry.
// -->
if (attribute.startsWith("angry"))
return new Element(((Wolf) entity.getBukkitEntity()).isAngry())
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("angry")) {
if (entity.getBukkitEntityType() == EntityType.WOLF) {
return new Element(((Wolf) entity.getBukkitEntity()).isAngry())
.getAttribute(attribute.fulfill(1));
}
else if (entity.getBukkitEntityType() == EntityType.PIG_ZOMBIE) {
return new Element(((PigZombie) entity.getBukkitEntity()).isAngry())
.getAttribute(attribute.fulfill(1));
}
}

return null;
}
Expand All @@ -80,13 +102,18 @@ public void adjust(Mechanism mechanism) {
// @name angry
// @input Element(Boolean)
// @description
// Changes the anger state of a wolf.
// Changes the anger state of a Wolf or PigZombie.
// @tags
// <e@entity.angry>
// -->

if (mechanism.matches("angry") && mechanism.requireBoolean()) {
((Wolf) entity.getBukkitEntity()).setAngry(mechanism.getValue().asBoolean());
if (entity.getBukkitEntityType() == EntityType.WOLF) {
((Wolf) entity.getBukkitEntity()).setAngry(mechanism.getValue().asBoolean());
}
else if (entity.getBukkitEntityType() == EntityType.PIG_ZOMBIE) {
((PigZombie) entity.getBukkitEntity()).setAngry(mechanism.getValue().asBoolean());
}
}
}
}

0 comments on commit 91d8711

Please sign in to comment.