Skip to content

Commit

Permalink
Make rabbit handling less like Bukkit Entity classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Dec 28, 2014
1 parent 556d719 commit d978848
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 92 deletions.
Expand Up @@ -3,14 +3,10 @@
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.entity.Rabbit;
import net.aufdemrand.denizen.utilities.entity.RabbitType;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.DyeColor;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.*;

public class EntityColor implements Property {

Expand Down Expand Up @@ -60,7 +56,7 @@ else if (type == EntityType.OCELOT)
return ((Ocelot) colored.getBukkitEntity()).getCatType().name();

else if (type == EntityType.RABBIT)
return Rabbit.getRabbitType((org.bukkit.entity.Rabbit) colored.getBukkitEntity()).name();
return RabbitType.getRabbitType((Rabbit) colored.getBukkitEntity()).name();

else // Should never happen
return null;
Expand Down Expand Up @@ -105,10 +101,8 @@ public String getPropertyId() {
// @name Rabbit Types
// @group Properties
// @description
// Currently, there are no official names for rabbit types in Bukkit, so
// Denizen includes its own user-friendly list of names. However, once Bukkit
// has an official list, Denizen will most likely switch to that list.
// Therefore, please be aware that these names could possibly change in the future.
// Denizen includes its own user-friendly list of rabbit type names, instead
// of relying on Bukkit names which did not exist at the time of writing.
//
// Types currently available:
// BROWN, WHITE, BLACK, WHITE_SPLOTCHED, GOLD, SALT, KILLER.
Expand All @@ -133,7 +127,7 @@ public String getAttribute(Attribute attribute) {
// Currently, only Horse, Wolf, Ocelot, Sheep, and Rabbit type entities can have a color.
// For horses, the output is COLOR|STYLE|VARIANT, see <@link language horse types>.
// For ocelots, the types are BLACK_CAT, RED_CAT, SIAMESE_CAT, or WILD_OCELOT.
// For rabbits types, see <@link language rabbit types>.
// For rabbit types, see <@link language rabbit types>.
// -->
if (attribute.startsWith("color"))
return new Element(getColor().toLowerCase())
Expand All @@ -151,10 +145,10 @@ public void adjust(Mechanism mechanism) {
// @input Element
// @description
// Changes the entity's color.
// Currently, only Horse, Wolf, Ocelot, and Sheep type entities can have a color.
// Currently, only Horse, Wolf, Ocelot, Sheep, and Rabbit type entities can have a color.
// For horses, the input is COLOR|STYLE|VARIANT, see <@link language horse types>
// For ocelots, the types are BLACK_CAT, RED_CAT, SIAMESE_CAT, or WILD_OCELOT.
// For rabbits types, see <@link language rabbit types>.
// For rabbit types, see <@link language rabbit types>.
// @tags
// <e@entity.color>
// <e@entity.is_colorable>
Expand Down Expand Up @@ -193,8 +187,8 @@ else if (type == EntityType.OCELOT

else if (type == EntityType.RABBIT
&& mechanism.getValue().matchesEnum(Rabbit.Type.values()))
Rabbit.setRabbitType((org.bukkit.entity.Rabbit) colored.getBukkitEntity(),
Rabbit.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
RabbitType.setRabbitType((Rabbit) colored.getBukkitEntity(),
RabbitType.valueOf(mechanism.getValue().asString().toUpperCase()));

}
}
Expand Down
76 changes: 0 additions & 76 deletions src/main/java/net/aufdemrand/denizen/utilities/entity/Rabbit.java

This file was deleted.

@@ -0,0 +1,74 @@
package net.aufdemrand.denizen.utilities.entity;

import net.minecraft.server.v1_8_R1.EntityRabbit;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftRabbit;
import org.bukkit.entity.Rabbit;

public enum RabbitType {
BROWN(0,0),
WHITE(1,1),
BLACK(2,2),
WHITE_SPLOTCHED(3,3),
GOLD(4,4),
SALT(5,5),
KILLER(6,99);

public static RabbitType getRabbitType(Rabbit rabbit) {
return RabbitType.getType(getEntityRabbit(rabbit).cl());
}

public static void setRabbitType(Rabbit rabbit, RabbitType type) {
getEntityRabbit(rabbit).r(type.getId());
}

private static EntityRabbit getEntityRabbit(Rabbit rabbit) {
return (EntityRabbit) ((CraftRabbit) rabbit).getHandle();
}

private static final RabbitType[] types = new RabbitType[values().length];
private final int internalId;
private final int id;

static {
for (RabbitType type : values()) {
types[type.getInternalId()] = type;
}
}

private RabbitType(int internalId, int id) {
this.internalId = internalId;
this.id = id;
}

/**
* Gets the ID of this rabbit type.
*
* @return Type ID.
*/
public int getId() {
return id;
}

/**
* Gets the internal ID of this rabbit type.
*
* @return Internal Type ID.
*/
private int getInternalId() {
return internalId;
}

/**
* Gets a rabbit type by its ID.
*
* @param id ID of the rabbit type to get.
* @return Resulting type, or null if not found.
*/
public static RabbitType getType(int id) {
for (RabbitType type : types) {
if (id == type.getId())
return type;
}
return null;
}
}

0 comments on commit d978848

Please sign in to comment.