我刚刚开始学习如何开发Minecraft服务器插件,但每当我尝试将我的插件加载到服务器上进行测试时,它就会抛出错误:找不到主类'me.light.bukkit.Main'
我的主要类代码:
package me.light.bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@Override
//when plugin is enabled
public void onEnable() {
new PlayerListener(this);
}
@Override
//when plugin is disabled (ie saving stuff)
public void onDisable() {
}
}
我的PlayerListener类代码:
package me.light.bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.plugin.Plugin;
public class PlayerListener implements Listener{
public PlayerListener(Main plugin) {
plugin.getServer().getPluginManager().registerEvents(this, (Plugin) plugin);
}
@EventHandler
public void blank(PlayerEggThrowEvent event) {
Player player = event.getPlayer();
player.sendMessage(ChatColor.RED + "DO NOT THROW EGGS");
player.kickPlayer("You were throwing eggs!");
}
}
最后我的plugin.yml
name: Illumination
main: me.light.bukkit.Main
version: 1.0
author: kb
description: First Plugin
commands:
此处还有服务器给我的错误
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128M; sup
port was removed in 8.0
Loading libraries, please wait...
[19:41:24 INFO]: Starting minecraft server version 1.8
[19:41:24 INFO]: Loading properties
[19:41:25 INFO]: Default game type: SURVIVAL
[19:41:25 INFO]: Generating keypair
[19:41:25 INFO]: Starting Minecraft server on *:25565
[19:41:25 INFO]: This server is running CraftBukkit version git-Bukkit- ee6d0fa (
MC: 1.8) (Implementing API version 1.8-R0.1-SNAPSHOT)
[19:41:25 ERROR]: Could not load 'plugins\illumination.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: Cannot find main class `me.light.bukki
t.Main'
at org.bukkit.plugin.java.PluginClassLoader.<init> (PluginClassLoader.jav
a:42) ~[craftbukkit.jar:git-Bukkit-ee6d0fa]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
ava:129) ~[craftbukkit.jar:git-Bukkit-ee6d0fa]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
java:328) ~[craftbukkit.jar:git-Bukkit-ee6d0fa]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
.java:251) [craftbukkit.jar:git-Bukkit-ee6d0fa]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.ja
va:288) [craftbukkit.jar:git-Bukkit-ee6d0fa]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.<init> (CraftServer.java:25
0) [craftbukkit.jar:git-Bukkit-ee6d0fa]
at net.minecraft.server.v1_8_R1.PlayerList.<init> (PlayerList.java:69) [c
raftbukkit.jar:git-Bukkit-ee6d0fa]
at net.minecraft.server.v1_8_R1.DedicatedPlayerList.<init> (SourceFile:14
) [craftbukkit.jar:git-Bukkit-ee6d0fa]
at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.jav
a:133) [craftbukkit.jar:git-Bukkit-ee6d0fa]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
:484) [craftbukkit.jar:git-Bukkit-ee6d0fa]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
Caused by: java.lang.ClassNotFoundException: me.light.bukkit.Main
at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_25]
at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_25]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_
25]
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_25]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
java:77) ~[craftbukkit.jar:git-Bukkit-ee6d0fa]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
java:62) ~[craftbukkit.jar:git-Bukkit-ee6d0fa]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_25]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_25]
at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_25]
at org.bukkit.plugin.java.PluginClassLoader.<init> (PluginClassLoader.jav
a:40) ~[craftbukkit.jar:git-Bukkit-ee6d0fa]
... 10 more
[19:41:25 INFO]: Preparing level "world"
[19:41:25 INFO]: Preparing start region for level 0 (Seed: -6785130429683314732)
[19:41:26 INFO]: Preparing start region for level 1 (Seed: -6785130429683314732)
[19:41:26 INFO]: Preparing start region for level 2 (Seed: -6785130429683314732)
[19:41:26 INFO]: Server permissions file permissions.yml is empty, ignoring it
[19:41:26 INFO]: Done (1.351s)! For help, type "help" or "?"
我试图多次修复但无济于事。我尝试在plugin.yml中重命名一些东西,在我的插件中移动我的plugin.yml,并更改我的类的名称,但没有任何工作。任何帮助将不胜感激。
答案 0 :(得分:0)
首先......这是一个奇怪的插件。 其次,我不确定这样做是否合适(我真的不是这样,所以不要责怪):
public PlayerListener(Main plugin) {
plugin.getServer().getPluginManager().registerEvents(this, (Plugin) plugin);
}
通常你应该这样做:
public void onEnable() {
bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
}
并删除:
new PlayerListener(this);
答案 1 :(得分:0)
注意:您应该重构您的插件并将 Main 重命名为其他内容。 (例如插件的名称)
package me.light.bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
private PlayerListener playerListener;
@Override
//when plugin is enabled
public void onEnable() {
playerListener = new PlayerListener(this);
getServer().getPluginManager().registerEvents(playerListener, this);
}
@Override
//when plugin is disabled (ie saving stuff)
public void onDisable() {}
}
<强>监听强>
package me.light.bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.plugin.Plugin;
public class PlayerListener implements Listener{
private Main plugin;
public PlayerListener(Main plugin) {
this.plugin = plugin;
}
@EventHandler
public void blank(PlayerEggThrowEvent event) {
Player player = event.getPlayer();
player.sendMessage(ChatColor.RED + "DO NOT THROW EGGS");
player.kickPlayer("You were throwing eggs!");
}
}