游戏:我的世界
软件:bukkit crakkit
制作方法:插件
流程:
原有的SamplePlugin提供了/pos命令,现在我加了列出所有物料的命令/listit
1 仿照/pos增加/list命令处理
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) { if (!(sender instanceof Player)) { return false; } Player player = (Player) sender; if (split.length == 0) { String things = ""; for(Material c: Material.values()){ things += c.toString(); things += "\r\n"; } player.sendMessage("Material lists:\r\n" + things); return true; } else if (split.length == 3) { try { double x = Double.parseDouble(split[0]); double y = Double.parseDouble(split[1]); double z = Double.parseDouble(split[2]); player.teleport(new Location(player.getWorld(), x, y, z)); } catch (NumberFormatException ex) { player.sendMessage("Given location is invalid"); } return true; } else { return false; } }
2 在plugin.yml中增加对命令行的定义说明。
name: SamplePlugin main: com.dinnerbone.bukkit.sample.SamplePlugin version: ${version} commands: pos: description: Displays your position or teleports you to another. usage: "Usage: '/pos' to get current position, or '/pos x y z' to teleport to x,y,z" debug: description: Toggles your debugging status for this plugin. usage: /debug listit: description: Displays all materials. usage: "Usage: '/listit' to get current all materials, or '/pos x y z' to teleport to x,y,z"
其中2的架构很像我现在做的命令行解析程序。
问题解决
myeclipse处理pom.xml文件有问题,是maven的下载或life cycle处理问题,我重新定义了pom.xml
待处理:
1 SamplePlugin来自git, 位置FIXME