InstantiationException和Abnormal Plugin Type:是什么?



我目前正在尝试修复一些代码,但我似乎找不到问题:

构建路径包括Vault和Bukkit 1.7.9。

它声称错误来自一个实例异常,但据我所知,我还没有包括任何实例。如果有人有这个错误,请帮助修复。这是一个异常的插件类型…

下面是我的代码:

package me.REDANDBLUEWHO.Combat;
import java.util.Arrays;
import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
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.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class Combat extends JavaPlugin implements Listener {
    public static Economy econ = null;
    public static EconomyResponse r;
    Logger logger = Logger.getLogger("Minecraft");
    public Inventory CombatShopInv;
    public ItemStack H, C, L, B;

    public Combat(Plugin plugin) {
        CombatShopInv = Bukkit.getServer().createInventory(null, 36, ChatColor.DARK_AQUA + "CombatShop");
        ItemStack DH = new ItemStack (Material.DIAMOND_HELMET);
        ItemMeta MH = DH.getItemMeta();
        MH.setLore(Arrays.asList(ChatColor.DARK_AQUA + "8000 Credits"));
        MH.setDisplayName(ChatColor.GRAY + "Buy: " + ChatColor.DARK_AQUA + "Diamond Helmet");
        DH.setItemMeta(MH);
        H = DH;
        ItemStack DC = new ItemStack (Material.DIAMOND_CHESTPLATE);
        ItemMeta MC = DC.getItemMeta();
        MC.setLore(Arrays.asList(ChatColor.DARK_AQUA + "12800 Credits"));
        MC.setDisplayName(ChatColor.GRAY + "Buy: " + ChatColor.DARK_AQUA + "Diamond Chestplate");
        DC.setItemMeta(MC);
        C = DC;
        ItemStack DL = new ItemStack (Material.DIAMOND_LEGGINGS);
        ItemMeta ML = DL.getItemMeta();
        ML.setLore(Arrays.asList(ChatColor.DARK_AQUA + "11200 Credits"));
        ML.setDisplayName(ChatColor.GRAY + "Buy: " + ChatColor.DARK_AQUA + "Diamond Leggings");
        DL.setItemMeta(ML);
        L = DL;
        ItemStack DB = new ItemStack (Material.DIAMOND_BOOTS);
        ItemMeta MB = DB.getItemMeta();
        MB.setDisplayName(ChatColor.GRAY + "Buy: " + ChatColor.DARK_AQUA + "Diamond Boots");
        MB.setLore(Arrays.asList(ChatColor.DARK_AQUA + "6400"));
        DB.setItemMeta(MB);
        B = DB;
        CombatShopInv.setItem(0, H);
        CombatShopInv.setItem(1, C);
        CombatShopInv.setItem(2, L);
        CombatShopInv.setItem(3, B);

    }
    public void onEnable() {
        new Combat(this);
        Bukkit.getServer().getLogger().info("Combat Shop Enabled!");
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
         if (!setupEconomy() ) {
                this.logger.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
         }
    }
    public void onDisable() {
        Bukkit.getServer().getLogger().info("Combat Shop Disabled!");
    }
    private boolean setupEconomy() {
        if (getServer().getPluginManager().getPlugin("Vault") == null) {
            return false;
        }
        RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) {
            return false;
        }
        econ = rsp.getProvider();
        return econ != null;
    }
    public boolean onCommand(CommandSender sender, Command cmd,
            String commandLabel, String[] args) {
        Player player = (Player) sender;
        if (cmd.getName().equalsIgnoreCase("CombatShop")) {
            player.openInventory(CombatShopInv);
            player.sendMessage(ChatColor.DARK_AQUA + "[Global-Kits] "
                    + ChatColor.GRAY + "Opening the" + ChatColor.DARK_AQUA
                    + " Global Kits " + ChatColor.GRAY
                    + "InGame credits store!");
        }
        return true;
    }
    @EventHandler
    public void onInventoryClick(InventoryClickEvent e) {
        Player p = (Player) e.getWhoClicked();
            if (!e.getInventory().equals(CombatShopInv)) {
                if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Diamond Helmet")) {
                    r = econ.withdrawPlayer(p.getName(), 8000.00);
                    p.closeInventory();
                    p.getEquipment().setHelmet(new ItemStack (Material.DIAMOND_HELMET));
                if(r.transactionSuccess()) {
                    p.sendMessage("You successfully bought a Diamond Helmet");
                } else {
                    e.isCancelled();
                    p.sendMessage(ChatColor.RED + "You do not have enough credits to buy this item!");
                    p.closeInventory();
                }
            }           
        }
    }
}

下面是错误日志:

[13:58:21 ERROR]: Could not load 'pluginsCombatShop.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: Abnormal plugin type
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
a:56) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
ava:127) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
java:328) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
.java:251) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugins(CraftServer.ja
va:357) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.reload(CraftServer.java:79
9) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.Bukkit.reload(Bukkit.java:288) [craftbukkit.jar:git-Bukkit
-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
23) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
0) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServe
r.java:703) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchServerCommand(Craf
tServer.java:690) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.aB(DedicatedServer.java:
296) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2
61) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5
58) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
:469) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
Caused by: java.lang.InstantiationException: me.REDANDBLUEWHO.Combat.Combat
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_51]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
a:52) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
        ... 15 more

我认为这种行为来自onEnable()方法中的new Combat(this);行。为什么你不创建一个方法,例如称为createCombatShopInv,你把你的代码?然后调用onEnable()

中的方法

另外,我发现:

  1. 在Java中,方法名和变量名都是小写开头的(除非它是常量)
  2. 不需要使用"Bukkit",你有一个插件实例,可以使用getServer()
  3. Bukkit已经有一个记录器,(你也使用它),只需使用getLogger()

相关内容

  • 没有找到相关文章

最新更新