我是Bukkit API的新手,不久前我学习了java。我正在制作一个小游戏插件。
虽然Eclipse没有给我任何错误,但它似乎来自我的主类。 Minecraft确实启动了,但是控制台记录了插件无法启动的情况,当我执行命令时它会被重复。
这是我的主要课程
package me.jobisingh;
import java.util.HashSet;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditOperation;
import com.sk89q.worldedit.bukkit.WorldEditAPI;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.WorldGuardCommands;
import com.sk89q.worldguard.bukkit.listener.WorldGuardBlockListener;
import com.sk89q.worldguard.bukkit.listener.WorldGuardCommandBookListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
// Color Code Here §
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;
import me.jobisingh.handlers.Game;
public class MainClass extends JavaPlugin {
@Override
public void onEnable() {
new ListenerClass(this);
new Game();
}
@Override
public void onDisable() {
}
private WorldGuardPlugin getWorldGuard() {
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
// WorldGuard may not be loaded
if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
return null; // Maybe you want throw an exception instead
}
return (WorldGuardPlugin) plugin;
}
public WorldEditPlugin getWorldEdit() {
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if(p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
else return null;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("setteam1spawn") && sender instanceof Player) {
Player player = (Player) sender;
Block getBlock = player.getTargetBlock((HashSet<Byte>)null, 100);
int x = getBlock.getX();
int y = getBlock.getY();
int z = getBlock.getZ();
player.sendMessage("Team 1 Spawn Set At " + x + " " + y + " " + z);
return true;
}
return false;
}
public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("lobbyCreate") && sender instanceof Player) {
Player player = (Player) sender;
Selection selection = getWorldEdit().getSelection(player);
Location LocA = selection.getMaximumPoint();
Location LocB = selection.getMinimumPoint();
World world = player.getWorld();
CuboidSelection lobby = new CuboidSelection(world, LocA, LocB);
return true;
}
return false;
}
public Location lobbyLocation;
public boolean onCommand2(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("lobbySetSpawn") && sender instanceof Player) {
Player player = (Player) sender;
Location lobbyLocation = player.getLocation();
return true;
}
return false;
}
}
这是我得到的错误
Error occurred while enabling MiniGame v1.0 (Is it up to date?)
java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at me.jobisingh.MainClass.<init>(MainClass.java:36) ~[?:?]
at me.jobisingh.ListenerClass.<init>(ListenerClass.java:16) ~[?:?]
at me.jobisingh.MainClass.onEnable(MainClass.java:40) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:356) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:316) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:524) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
Caused by: java.lang.IllegalStateException: Initial initialization
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at me.jobisingh.MainClass.<init>(MainClass.java:36) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_51]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_51]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_51]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_51]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_51]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:291) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
... 2 more
答案 0 :(得分:0)
启用MiniGame v1.0时出错(是否为最新版本?) java.lang.IllegalArgumentException:插件已初始化!
你的插件因为已经加载而无法加载,我认为创建重复的注册监听器或插件的任何其他部分存在问题。
答案 1 :(得分:0)
所以我检查了你说的链接,问题非常接近链接中的问题。为了解决这个问题,我刚从侦听器类中删除了MainClass导入,然后以不同的方式导入了MainClass。