Skip to content

Instantly share code, notes, and snippets.

@brcdev
Created April 22, 2017 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brcdev/b1b508902d969c36627508f1e9c1d606 to your computer and use it in GitHub Desktop.
Save brcdev/b1b508902d969c36627508f1e9c1d606 to your computer and use it in GitHub Desktop.
package net.brcdev.shopgui.provider.spawner;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
public abstract class SpawnerProvider {
/**
* Gets the spawner item stack
*
* @param entityId Name of the entity
* @param customName Spawner's display name
* @return spawner item stack
*/
public abstract ItemStack getSpawnerItem(String entityId, String customName);
/**
* Gets the entity ID (one of {@link EntityType})
*
* @param itemStack Spawner item stack
* @return entity ID
*/
public abstract String getSpawnerEntityId(ItemStack itemStack);
/**
* Gets a neatly formatted entity name
*
* @param itemStack Spawner item stack
* @return entity name
*/
public abstract String getSpawnerEntityName(ItemStack itemStack);
/**
* Converts the entity name to numeric ID
*
* @param entityId Name of the entity
* @return numeric ID of an entity
*/
@SuppressWarnings("deprecation")
protected short getNumericEntityId(String entityId) {
short entity = 0;
try {
entity = EntityType.fromName(entityId).getTypeId();
} catch(NullPointerException ex) {
}
return entity;
}
/**
* Converts the numeric entity ID to entity name
*
* @param entityId numeric ID of an entity
* @return name of an entity
*/
@SuppressWarnings("deprecation")
protected String getStringEntityId(short entityId) {
String entity = "";
try {
entity = EntityType.fromId(entityId).getName();
} catch(NullPointerException ex) {
}
return entity;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment