Bukkit 插件不工作?
Bukkit plugin not working?
所以我最近尝试为我的世界制作一个 bukkit 插件。
我的想法是,这只是一个测试插件,看看我是否能做到,显然我做不到。这是我想出的代码
package me.glowhoo.BlockChanger; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class BlockChanger extends JavaPlugin
{
@Override public void onEnable() {
Bukkit.getLogger().info(this.getDescription().getName() +
" has been enabled");
}
@Override public void onDisable() {
Bukkit.getLogger().info(this.getDescription().getName() + " has been disabled");
}
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
/*command: /tpa Glowhoo
* args.length = 1
* args[0] = Glowhoo
* command.getName() = tpa
*/
if (cmd.getName().equalsIgnoreCase("message")){
if(sender instanceof Player)
{
/*ComandSender sender-who sent the command
* Command cmd- the command that was executed
* String commandLabel-the command alias that was used
* String[] args-array of additional arguments
*/
sender.sendMessage(ChatColor.RED +"Hello player!");
}else
{
sender.sendMessage(ChatColor.AQUA +"Hello console!");
}
}
return false;
}
}
所以这个问题是,每当我加载服务器时,它都会显示 "BlockChanger has been enabled",但是当我尝试键入它具有的唯一命令(消息)或 /message 时,没有任何反应它说这是一个无法识别的命令,输入 /help 获取信息。问题并没有就此结束,每当我实际尝试让插件运行时,90% 的时间我都会遇到 plugin.yml 错误,我不完全理解,但是如果你们中的任何人知道任何关于这个问题,请回复
我的 plugin.yml 文件在这里(注意:这个 plugin.yml 副本实际上有效,但命令本身无效。):
name: BlockChanger
version: 1.0
main: me.glowhoo.BlockChanger.BlockChanger
description:
commands:
message:
description: -no desc-
usage: /message
您的plugin.yml
不正确。您需要在commands
下缩进message
来定义一个节点。目前 commands
是一个没有意义的键值。将相关部分改为:
commands:
message:
usage: /message
这是未来的某个时间,但是如果你再次使用它,当你有一个命令时,你需要return true,否则它会告诉你这是一个错误的命令,甚至如果您的 .yml/.yaml 文件设置正确。因此,您需要执行以下操作才能在调用时注册您的命令:
package me.glowhoo.BlockChanger; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class BlockChanger extends JavaPlugin
{
@Override public void onEnable() {
Bukkit.getLogger().info(this.getDescription().getName() +
" has been enabled");
}
@Override public void onDisable() {
Bukkit.getLogger().info(this.getDescription().getName() + " has been disabled");
}
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
/*command: /tpa Glowhoo
* args.length = 1
* args[0] = Glowhoo
* command.getName() = tpa
*/
if (cmd.getName().equalsIgnoreCase("message")){
if(sender instanceof Player)
{
/*ComandSender sender-who sent the command
* Command cmd- the command that was executed
* String commandLabel-the command alias that was used
* String[] args-array of additional arguments
*/
sender.sendMessage(ChatColor.RED +"Hello player!");
}else
{
sender.sendMessage(ChatColor.AQUA +"Hello console!");
}
return true;
}
return false;
}
}
您需要在 onEnable 方法中将此 class 注册为命令执行器。
所以我最近尝试为我的世界制作一个 bukkit 插件。 我的想法是,这只是一个测试插件,看看我是否能做到,显然我做不到。这是我想出的代码
package me.glowhoo.BlockChanger; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class BlockChanger extends JavaPlugin
{
@Override public void onEnable() {
Bukkit.getLogger().info(this.getDescription().getName() +
" has been enabled");
}
@Override public void onDisable() {
Bukkit.getLogger().info(this.getDescription().getName() + " has been disabled");
}
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
/*command: /tpa Glowhoo
* args.length = 1
* args[0] = Glowhoo
* command.getName() = tpa
*/
if (cmd.getName().equalsIgnoreCase("message")){
if(sender instanceof Player)
{
/*ComandSender sender-who sent the command
* Command cmd- the command that was executed
* String commandLabel-the command alias that was used
* String[] args-array of additional arguments
*/
sender.sendMessage(ChatColor.RED +"Hello player!");
}else
{
sender.sendMessage(ChatColor.AQUA +"Hello console!");
}
}
return false;
}
}
所以这个问题是,每当我加载服务器时,它都会显示 "BlockChanger has been enabled",但是当我尝试键入它具有的唯一命令(消息)或 /message 时,没有任何反应它说这是一个无法识别的命令,输入 /help 获取信息。问题并没有就此结束,每当我实际尝试让插件运行时,90% 的时间我都会遇到 plugin.yml 错误,我不完全理解,但是如果你们中的任何人知道任何关于这个问题,请回复
我的 plugin.yml 文件在这里(注意:这个 plugin.yml 副本实际上有效,但命令本身无效。):
name: BlockChanger
version: 1.0
main: me.glowhoo.BlockChanger.BlockChanger
description:
commands:
message:
description: -no desc-
usage: /message
您的plugin.yml
不正确。您需要在commands
下缩进message
来定义一个节点。目前 commands
是一个没有意义的键值。将相关部分改为:
commands:
message:
usage: /message
这是未来的某个时间,但是如果你再次使用它,当你有一个命令时,你需要return true,否则它会告诉你这是一个错误的命令,甚至如果您的 .yml/.yaml 文件设置正确。因此,您需要执行以下操作才能在调用时注册您的命令:
package me.glowhoo.BlockChanger; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class BlockChanger extends JavaPlugin
{
@Override public void onEnable() {
Bukkit.getLogger().info(this.getDescription().getName() +
" has been enabled");
}
@Override public void onDisable() {
Bukkit.getLogger().info(this.getDescription().getName() + " has been disabled");
}
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
/*command: /tpa Glowhoo
* args.length = 1
* args[0] = Glowhoo
* command.getName() = tpa
*/
if (cmd.getName().equalsIgnoreCase("message")){
if(sender instanceof Player)
{
/*ComandSender sender-who sent the command
* Command cmd- the command that was executed
* String commandLabel-the command alias that was used
* String[] args-array of additional arguments
*/
sender.sendMessage(ChatColor.RED +"Hello player!");
}else
{
sender.sendMessage(ChatColor.AQUA +"Hello console!");
}
return true;
}
return false;
}
}
您需要在 onEnable 方法中将此 class 注册为命令执行器。