gpt4 book ai didi

java - 在 Bukkit 中使用多个类作为命令?

转载 作者:行者123 更新时间:2023-11-30 07:02:54 25 4
gpt4 key购买 nike

最近我启动了一个 Bukkit 插件,但由于使用两个类(main 和 CommandExecutor)而遇到了麻烦。我已经尝试了所有方法,但是当我加载插件时,它抛出了一个错误,该错误位于帖子末尾。

主要(称为 ekits.java):

package me.mucapapipa.ekits;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class ekits extends JavaPlugin implements Listener {


@Override
public void onEnable() {
System.out.println("Main plugin enabled");
getCommand("pvp").setExecutor(new NormalPlayer(this));
getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onDisable() {
System.out.println("Main plugin disabled");
}


}

CommandExecutor(称为NormalPlayer):

package me.mucapapipa.ekits;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

public class NormalPlayer extends JavaPlugin implements CommandExecutor {

@SuppressWarnings("unused")
private ekits core;
public NormalPlayer(ekits core) {
this.core = core;
}

private String kit;

public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {

if (sender instanceof Player) {
Player player = (Player) sender;
if (cmd.getName().equalsIgnoreCase("pvp")) {
kit = "PvP";
player.getInventory().clear();
player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
/* We then set the armor */
player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
player.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));

player.sendMessage(ChatColor.GRAY + "~ " + ChatColor.AQUA + "Kit: " + kit);
}
else {
sender.sendMessage("The console should not play. It would be so OP.");
}
}

return true; }
}

插件.yml:

name: EKits
author: Mucapapipa
main: me.mucapapipa.ekits.ekits
version: 1.0
description: The server's main plugin.

commands:
pvp:
usage: /<command>
aliases: [kitpvp]
description: Uses the kit PvP.

错误:

[19:19:01 ERROR]: Error occurred while enabling EKits v1.0 (Is it up to date?) java.lang.IllegalArgumentException: Plugin already initialized! at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.plugin.java.JavaPlugin.(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-7019900] at me.mucapapipa.ekits.NormalPlayer.(NormalPlayer.java:16) ~[?:?] at me.mucapapipa.ekits.ekits.onEnable(ekits.java:16) ~[?:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:327) [craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:341) [craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:313) [craftbukkit.jar:git-Bukkit-7019900] at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:394) [craftbukkit.jar:git-Bukkit-7019900] at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:362) [craftbukkit.jar:git-Bukkit-7019900] at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:317) [craftbukkit.jar:git-Bukkit-7019900] at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:190) [craftbukkit.jar:git-Bukkit-7019900] at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:484) [craftbukkit.jar:git-Bukkit-7019900] at java.lang.Thread.run(Unknown Source) [?:1.8.0_101] Caused by: java.lang.IllegalStateException: Initial initialization at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.plugin.java.JavaPlugin.(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-7019900] at me.mucapapipa.ekits.ekits.(ekits.java:10) ~[?:?] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_101] at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_101] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_101] at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_101] at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_101] at org.bukkit.plugin.java.PluginClassLoader.(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:288) ~[craftbukkit.jar:git-Bukkit-7019900] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.(CraftServer.java:250) ~[craftbukkit.jar:git-Bukkit-7019900] at net.minecraft.server.v1_8_R1.PlayerList.(PlayerList.java:69) ~[craftbukkit.jar:git-Bukkit-7019900] at net.minecraft.server.v1_8_R1.DedicatedPlayerList.(SourceFile:14) ~[craftbukkit.jar:git-Bukkit-7019900] at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:133) ~[craftbukkit.jar:git-Bukkit-7019900] ... 2 more

最佳答案

公共(public)类NormalPlayer扩展JavaPlugin实现CommandExecutor

为什么你的命令执行器要扩展主插件类?这就是导致双重初始化的原因,删除该父类(super class)可能会修复代码。

关于java - 在 Bukkit 中使用多个类作为命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40579060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com