if (args.length > 3){
Commands.showCommandHelpAndUsage(sender, "cex_cannon", alias);
return true;
}
EntityType toSpawn = null;
int explosionStrength = CommandsEX.getConf().getInt("CannonExplosionStrength");
Player target = null;
String type = null;
String entity = null;
if (args.length == 1 || args.length == 2){
if (sender instanceof Player){
target = (Player) sender;
if (args[0].contains(":")){
String[] data = args[0].split(":");
entity = data[0];
if (data.length == 2){ type = data[1]; }
} else {
entity = args[0];
}
List<EntityType> matches = ClosestMatches.spawnableEntity(entity);
if (matches.size() > 0){
toSpawn = matches.get(0);
} else {
LogHelper.showInfo("cannonInvalid", sender, ChatColor.RED);
return true;
}
} else {
Commands.showCommandHelpAndUsage(sender, "cex_cannon", alias);
return true;
}
}
if (args.length == 2){
if (args[1].matches(CommandsEX.intRegex)){
explosionStrength = Integer.valueOf(args[1]);
if (explosionStrength > explosionStrengthLimit){
LogHelper.showInfo("cannonLimit", sender, ChatColor.RED);
explosionStrength = explosionStrengthLimit;
}
} else {
LogHelper.showInfo("cannonInteger", sender, ChatColor.RED);
return true;
}
}
if (args.length == 3){
target = Bukkit.getPlayer(args[0]);
if (target == null){
LogHelper.showInfo("invalidPlayer", sender, ChatColor.RED);
return true;
}
if (args[1].contains(":")){
String[] data = args[1].split(":");
entity = data[0];
if (data.length == 2){ type = data[1]; }
} else {
entity = args[1];
}
if (ClosestMatches.spawnableEntity(entity).size() > 0){
List<EntityType> matches = ClosestMatches.spawnableEntity(entity);
toSpawn = matches.get(0);
} else {
LogHelper.showInfo("cannonInvalid", sender, ChatColor.RED);
return true;
}
if (args[2].matches(CommandsEX.intRegex)){
explosionStrength = Integer.valueOf(args[2]);
if (explosionStrength > explosionStrengthLimit){
LogHelper.showInfo("cannonLimit", sender, ChatColor.RED);
explosionStrength = explosionStrengthLimit;
}
} else {
LogHelper.showInfo("cannonInteger", sender, ChatColor.RED);
return true;
}
}
DyeColor dye = null;
try {
for (DyeColor d : DyeColor.values()){
String lower = d.name().toLowerCase();
if (lower.equalsIgnoreCase(type)){
dye = d;
}
}
} catch (Exception e){
}
if (type != null){
if (type.equalsIgnoreCase("fire")){
} else if (type.equalsIgnoreCase("charged") || type.equalsIgnoreCase("powered") && toSpawn == EntityType.CREEPER){
type = "charged";
} else if (type.equalsIgnoreCase("baby") || type.equalsIgnoreCase("child") && (toSpawn == EntityType.PIG || toSpawn == EntityType.COW
|| toSpawn == EntityType.CHICKEN || toSpawn == EntityType.SHEEP || toSpawn == EntityType.OCELOT || toSpawn == EntityType.WOLF)){
type = "baby";
} else if (type.equalsIgnoreCase("tamed") && (toSpawn == EntityType.WOLF || toSpawn == EntityType.OCELOT)){
} else if (type.equalsIgnoreCase("angry") && (toSpawn == EntityType.WOLF || toSpawn == EntityType.PIG_ZOMBIE)){
} else if (toSpawn == EntityType.ENDERMAN && ClosestMatches.material(type).size() > 0){
} else if (toSpawn == EntityType.VILLAGER && ClosestMatches.villagerProfessions(type).size() > 0){
} else if (toSpawn == EntityType.DROPPED_ITEM && ClosestMatches.material(type).size() > 0){
type = "item:" + type;
} else if (toSpawn == EntityType.SHEEP && dye != null){
// Correct, nothing to do here
} else {
LogHelper.showInfo("cannonInvalidType", sender, ChatColor.RED);
return true;
}
}
final Entity entity1;
if (toSpawn == EntityType.DROPPED_ITEM){
entity1 = target.getWorld().dropItem(target.getEyeLocation(), new ItemStack(ClosestMatches.material(type.split(":")[1].replaceFirst(":", "")).get(0)));
} else {
entity1 = target.getWorld().spawn(target.getEyeLocation(), toSpawn.getEntityClass());
}
if (toSpawn == EntityType.OCELOT){
final Ocelot ocelot = (Ocelot) entity1;
Random random = new Random();