问题描述
我正在尝试为Minecraft进行bukkit编程,但是由于某些原因,我陷入了事件.这是我的代码:
I'm trying to get into bukkit programming for minecraft, but for some reason I'm stuck with events. Here's my code:
主类文件:
package com.plugin1;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile;
//import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import net.md_5.bungee.api.ChatColor;
public class Plugin extends JavaPlugin {
public int songStage;
public static Plugin plugin;
public void OnEnable () {
PluginDescriptionFile pluginDesc = getDescription();
Logger logger = getLogger();
plugin = this;
registerEvents(this, new BlockBreak());
logger.info(pluginDesc.getName() + " is enabled! (V. " + pluginDesc.getVersion() + ")");
}
public void OnDisable () {
PluginDescriptionFile pluginDesc = getDescription();
Logger logger = Logger.getLogger("Plugin");
plugin = null;
logger.info(pluginDesc.getName() + " is disabled! (V. " + pluginDesc.getVersion() + ")");
}
public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
for (Listener listener : listeners) {
Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
}
}
public static Plugin getPlugin() {
return plugin;
}
}
事件类文件:
package com.plugin1;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
public class BlockBreak implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void OnBlockBreak (BlockBreakEvent e) {
Player p = e.getPlayer();
p.sendMessage("Block broken.");
}
}
基本上,这不会返回任何错误.我已经通过控制台了,什么都没有.当我打破障碍时,实际上什么也没发生!
Basically, this returns no errors. I've gone through console and there's nothing. When I break a block, literally nothing happens!
我已经尝试了一些方法:我已经尝试过了,尝试了多个视频教程,并在Minecraft论坛上尝试了文本教程,但还是一无所获.我还联系了一位为bukkit插件编码的服务器所有者,但他无法解决此问题...
I've tried a few of things: I've gone through it, tried multiple video tutorials and tried a text tutorial on the minecraft forums but still nothing. I also contacted a server owner who codes bukkit plugins, but he couldn't fix this...
如果有人可以帮助我,请告诉我!!!
If there's anyone who can help me with this, PLEASE LET ME KNOW!!!!
提前谢谢!
推荐答案
我认为您没有以正确的方式注册侦听器...
I think you aren't registering the Listeners in the right way...
尝试此代码并告诉我是否可行...我真的很想为您提供帮助
Try this code and tell me if it works... I'm really wanting to help you
首先,不要使用插件"作为主类的名称,而应使用主".
First of all don't use "Plugin" as the name for your Main Class... Use "Main" instead.
启用:
public class Main extends JavaPlugin {
public void onEnable() {
Bukkit.getPluginManger().registerEvents(new Join(this),this);
}
}
监听器:
public class Join implements Listener {
private Main plugin;
public Join(Main plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent ev) {
ev.setJoinMessage("Just another test");
}
}
希望它能起作用...
Hope it works...
这篇关于Minecraft Bukkit活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!