use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.
the class MagicController method spawnMob.
@Nullable
@Override
public Entity spawnMob(String key, Location location) {
EntityData mobType = mobs.get(key);
if (mobType != null) {
return mobType.spawn(this, location);
}
EntityType entityType = com.elmakers.mine.bukkit.entity.EntityData.parseEntityType(key);
if (entityType == null) {
return null;
}
return location.getWorld().spawnEntity(location, entityType);
}
use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.
the class CycleEntityAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity entity = context.getTargetEntity();
EntityType entityType = entity.getType();
Mage mage = context.getMage();
switch(entityType) {
case PAINTING:
context.registerModified(entity);
Painting painting = (Painting) entity;
Art[] artValues = Art.values();
Art oldArt = painting.getArt();
Art newArt = oldArt;
int ordinal = (oldArt.ordinal() + 1);
for (int i = 0; i < artValues.length; i++) {
newArt = artValues[ordinal++ % artValues.length];
painting.setArt(newArt);
newArt = painting.getArt();
if (oldArt != newArt) {
break;
}
}
if (oldArt == newArt) {
return SpellResult.FAIL;
}
mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
break;
case ITEM_FRAME:
ItemFrame itemFrame = (ItemFrame) entity;
ItemStack frameItem = itemFrame.getItem();
if (frameItem == null || frameItem.getType() != Material.MAP) {
return SpellResult.NO_TARGET;
}
short data = frameItem.getDurability();
data++;
MapView mapView = DeprecatedUtils.getMap(data);
if (mapView == null) {
data = 0;
mapView = DeprecatedUtils.getMap(data);
if (mapView == null) {
return SpellResult.NO_TARGET;
}
}
context.registerModified(entity);
frameItem.setDurability(data);
itemFrame.setItem(frameItem);
break;
case HORSE:
context.registerModified(entity);
Horse horse = (Horse) entity;
Horse.Color color = horse.getColor();
Horse.Color[] colorValues = Horse.Color.values();
color = colorValues[(color.ordinal() + 1) % colorValues.length];
Horse.Style horseStyle = horse.getStyle();
Horse.Style[] styleValues = Horse.Style.values();
horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];
horse.setStyle(horseStyle);
horse.setColor(color);
break;
case OCELOT:
context.registerModified(entity);
Ocelot ocelot = (Ocelot) entity;
Ocelot.Type catType = ocelot.getCatType();
Ocelot.Type[] typeValues = Ocelot.Type.values();
catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
ocelot.setCatType(catType);
break;
case VILLAGER:
context.registerModified(entity);
Villager villager = (Villager) entity;
Villager.Profession profession = villager.getProfession();
Villager.Profession[] professionValues = Villager.Profession.values();
int villagerOrdinal = (profession.ordinal() + 1) % professionValues.length;
// Special-cases for zombie-reserved professions
if (villagerOrdinal == 0 || villagerOrdinal == 7) {
villagerOrdinal = 1;
}
profession = professionValues[villagerOrdinal];
villager.setProfession(profession);
break;
case WOLF:
context.registerModified(entity);
Wolf wolf = (Wolf) entity;
DyeColor wolfColor = wolf.getCollarColor();
DyeColor[] wolfColorValues = DyeColor.values();
wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
wolf.setCollarColor(wolfColor);
break;
case SHEEP:
context.registerModified(entity);
Sheep sheep = (Sheep) entity;
DyeColor dyeColor = sheep.getColor();
DyeColor[] dyeColorValues = DyeColor.values();
dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
sheep.setColor(dyeColor);
break;
default:
return SpellResult.NO_TARGET;
}
;
return SpellResult.CAST;
}
use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.
the class HitboxUtils method configureHeadSizes.
public static void configureHeadSizes(ConfigurationSection config) {
headSizes.clear();
Collection<String> keys = config.getKeys(false);
for (String key : keys) {
try {
double size = config.getDouble(key);
EntityType entityType = EntityType.valueOf(key.toUpperCase());
if (size > 0) {
headSizes.put(entityType, size);
}
} catch (Exception ex) {
org.bukkit.Bukkit.getLogger().log(Level.WARNING, "Invalid entity type in head size definition: " + key, ex);
}
}
}
use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.
the class HitboxUtils method configureHitboxes.
public static void configureHitboxes(ConfigurationSection config) {
hitboxes.clear();
Collection<String> keys = config.getKeys(false);
for (String key : keys) {
try {
Vector bounds = ConfigurationUtils.getVector(config, key);
String upperKey = key.toUpperCase();
double halfX = bounds.getX() / 2;
double halfZ = bounds.getZ() / 2;
BoundingBox bb = new BoundingBox(-halfX, halfX, 0, bounds.getY(), -halfZ, halfZ).scaleFromBase(hitboxScale, hitboxScaleY);
if (upperKey.equals("DEFAULT")) {
defaultHitbox = bb;
continue;
}
EntityType entityType = EntityType.valueOf(upperKey);
hitboxes.put(entityType, bb);
} catch (Exception ex) {
org.bukkit.Bukkit.getLogger().log(Level.WARNING, "Invalid entity type in hitbox definition: " + key, ex);
}
}
}
use of org.bukkit.entity.EntityType in project TokenManager by RealizedMC.
the class ItemUtil method loadFromString.
public static ItemStack loadFromString(final String line) {
if (line == null || line.isEmpty()) {
throw new IllegalArgumentException("Line is empty or null!");
}
final String[] args = line.split(" +");
final String[] materialData = args[0].split(":");
final Material material = Material.matchMaterial(materialData[0]);
if (material == null) {
throw new IllegalArgumentException("'" + args[0] + "' is not a valid material.");
}
ItemStack result = new ItemStack(material, 1);
if (materialData.length > 1) {
// Handle potions and spawn eggs switching to NBT in 1.9+
if (!ItemUtil.isPre1_9()) {
if (material.name().contains("POTION")) {
final String[] values = materialData[1].split("-");
final PotionType type;
if ((type = EnumUtil.getByName(values[0], PotionType.class)) == null) {
throw new IllegalArgumentException("'" + values[0] + "' is not a valid PotionType. Available: " + EnumUtil.getNames(PotionType.class));
}
result = new Potions(type, Arrays.asList(values)).toItemStack();
} else if (material == Material.MONSTER_EGG) {
final EntityType type;
if ((type = EnumUtil.getByName(materialData[1], EntityType.class)) == null) {
throw new IllegalArgumentException("'" + materialData[0] + "' is not a valid EntityType. Available: " + EnumUtil.getNames(EntityType.class));
}
result = new SpawnEggs(type).toItemStack();
}
}
final OptionalLong value;
if ((value = NumberUtil.parseLong(materialData[1])).isPresent()) {
result.setDurability((short) value.getAsLong());
}
}
if (args.length < 2) {
return result;
}
result.setAmount(Integer.parseInt(args[1]));
if (args.length > 2) {
for (int i = 2; i < args.length; i++) {
final String argument = args[i];
final String[] pair = argument.split(":", 2);
if (pair.length < 2) {
continue;
}
applyMeta(result, pair[0], pair[1]);
}
}
return result;
}
Aggregations