use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class MagicMobCommandExecutor method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!api.hasPermission(sender, "Magic.commands.mmob")) {
sendNoPermission(sender);
return true;
}
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: mmob [spawn|list] <type> [count]");
return true;
}
if (args[0].equalsIgnoreCase("list")) {
onListMobs(sender);
return true;
}
if (args[0].equalsIgnoreCase("clear")) {
onClearMobs(sender, args);
return true;
}
if (!args[0].equalsIgnoreCase("spawn") || args.length < 2) {
return false;
}
if (!(sender instanceof Player) && !(sender instanceof BlockCommandSender) && args.length < 6) {
sender.sendMessage(ChatColor.RED + "Usage: mmob spawn <type> <x> <y> <z> <world> [count]");
return true;
}
Location targetLocation = null;
World targetWorld = null;
Player player = (sender instanceof Player) ? (Player) sender : null;
BlockCommandSender commandBlock = (sender instanceof BlockCommandSender) ? (BlockCommandSender) sender : null;
if (args.length >= 6) {
targetWorld = Bukkit.getWorld(args[5]);
if (targetWorld == null) {
sender.sendMessage(ChatColor.RED + "Invalid world: " + ChatColor.GRAY + args[5]);
return true;
}
} else if (player != null) {
targetWorld = player.getWorld();
} else if (commandBlock != null) {
Block block = commandBlock.getBlock();
targetWorld = block.getWorld();
targetLocation = block.getLocation();
}
if (args.length >= 5) {
try {
double currentX = 0;
double currentY = 0;
double currentZ = 0;
if (player != null) {
Location currentLocation = player.getLocation();
currentX = currentLocation.getX();
currentY = currentLocation.getY();
currentZ = currentLocation.getZ();
} else if (commandBlock != null) {
Block blockLocation = commandBlock.getBlock();
currentX = blockLocation.getX();
currentY = blockLocation.getY();
currentZ = blockLocation.getZ();
}
targetLocation = new Location(targetWorld, ConfigurationUtils.overrideDouble(args[2], currentX), ConfigurationUtils.overrideDouble(args[3], currentY), ConfigurationUtils.overrideDouble(args[4], currentZ));
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Usage: mmob spawn <type> <x> <y> <z> <world> [count]");
return true;
}
} else if (player != null) {
Location location = player.getEyeLocation();
BlockIterator iterator = new BlockIterator(location.getWorld(), location.toVector(), location.getDirection(), 0, 64);
Block block = location.getBlock();
while (block.getType() == Material.AIR && iterator.hasNext()) {
block = iterator.next();
}
block = block.getRelative(BlockFace.UP);
targetLocation = block.getLocation();
}
if (targetLocation == null || targetLocation.getWorld() == null) {
sender.sendMessage(ChatColor.RED + "Usage: mmob spawn <type> <x> <y> <z> <world> [count]");
return true;
}
String mobKey = args[1];
int count = 1;
String countString = null;
if (args.length == 7) {
countString = args[6];
} else if (args.length == 3) {
countString = args[2];
}
if (countString != null) {
try {
count = Integer.parseInt(countString);
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Invalid count: " + countString);
return true;
}
}
if (count <= 0)
return true;
MageController controller = api.getController();
Entity spawned = null;
for (int i = 0; i < count; i++) {
spawned = controller.spawnMob(mobKey, targetLocation);
}
if (spawned == null) {
sender.sendMessage(ChatColor.RED + "Unknown mob type " + mobKey);
return true;
}
String name = spawned.getName();
if (name == null) {
name = mobKey;
}
sender.sendMessage(ChatColor.AQUA + "Spawned mob: " + ChatColor.LIGHT_PURPLE + name);
return true;
}
Aggregations