好友
阅读权限20
听众
最后登录1970-1-1
|
有一个名为CommandExample.java的Java源文件,内容如下:
[JavaScript] 纯文本查看 复制代码 package com.yourname.yourplugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CommandExample implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (args.length < 1) {
player.sendMessage("Usage: /example <command>");
return false;
}
String commandToExecute = args[0];
String result = runProgram(commandToExecute);
player.sendMessage("The result of the program is: " + result);
return true;
}
sender.sendMessage("This command can only be run by a player.");
return false;
}
// 执行指定命令并返回结果
private String runProgram(String command) {
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line).append("\n");
}
return result.toString();
} catch (IOException e) {
return "Error executing the command: " + e.getMessage();
}
}
}
使用这个命令
javac -d . CommandExample.java
提示这个错误
CommandExample.java:3: 错误: 程序包org.bukkit.command不存在
import org.bukkit.command.Command;
^
CommandExample.java:4: 错误: 程序包org.bukkit.command不存在
import org.bukkit.command.CommandExecutor;
^
CommandExample.java:5: 错误: 程序包org.bukkit.command不存在
import org.bukkit.command.CommandSender;
^
CommandExample.java:6: 错误: 程序包org.bukkit.entity不存在
import org.bukkit.entity.Player;
^
CommandExample.java:12: 错误: 找不到符号
public class CommandExample implements CommandExecutor {
^
符号: 类 CommandExecutor
CommandExample.java:15: 错误: 找不到符号
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
^
符号: 类 CommandSender
位置: 类 CommandExample
CommandExample.java:15: 错误: 找不到符号
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
^
符号: 类 Command
位置: 类 CommandExample
CommandExample.java:14: 错误: 方法不会覆盖或实现超类型的方法
@Override
^
CommandExample.java:16: 错误: 找不到符号
if (sender instanceof Player) {
^
符号: 类 Player
位置: 类 CommandExample
CommandExample.java:17: 错误: 找不到符号
Player player = (Player) sender;
^
符号: 类 Player
位置: 类 CommandExample
CommandExample.java:17: 错误: 找不到符号
Player player = (Player) sender;
^
符号: 类 Player
位置: 类 CommandExample
11 个错误 问:这些org.bukkit开头的程序包如何安装 |
免费评分
-
查看全部评分
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|