Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make rabbit handling less like Bukkit Entity classes
- Loading branch information
Showing
3 changed files
with
84 additions
and
92 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
76 changes: 0 additions & 76 deletions
76
src/main/java/net/aufdemrand/denizen/utilities/entity/Rabbit.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
src/main/java/net/aufdemrand/denizen/utilities/entity/RabbitType.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,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; | ||
} | ||
} |