Error initialising Plugin

Discussion in 'Plugin Development' started by Samthelord1, Jan 1, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Samthelord1

    01.01 14:41:08 [Server] INFO ... 2 more
    01.01 14:41:08 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:133) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedPlayerList.<init>(SourceFile:14) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerList.<init>(PlayerList.java:68) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.<init>(CraftServer.java:326) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.java:364) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_51]
    01.01 14:41:08 [Server] INFO at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_51]
    01.01 14:41:08 [Server] INFO at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_51]
    01.01 14:41:08 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_51]
    01.01 14:41:08 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_51]
    01.01 14:41:08 [Server] INFO at me.samthelord1.tokens.Main.<init>(Main.java:21) ~[?:?]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO Caused by: java.lang.IllegalStateException: Initial initialization
    01.01 14:41:08 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:436) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:189) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:282) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:326) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:352) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:389) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:455) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at me.samthelord1.tokens.Main.onEnable(Main.java:31) ~[?:?]
    01.01 14:41:08 [Server] INFO at me.samthelord1.tokens.Menu.<init>(Menu.java:34) ~[?:?]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 14:41:08 [Server] INFO java.lang.IllegalArgumentException: Plugin already initialized!
    01.01 14:41:08 [Server] ERROR Error occurred while enabling Tokens v1.0.0 (Is it up to date?)

    Error when enabling (reads bottom to top)


    01.01 14:41:08 [Server] INFO at me.samthelord1.tokens.Main.<init>(Main.java:21) ~[?:?
    01.01 14:41:08 [Server] INFO at me.samthelord1.tokens.Main.onEnable(Main.java:31) ~[?:?]
    01.01 14:41:08 [Server] INFO at me.samthelord1.tokens.Menu.<init>(Menu.java:34) ~[?:?]

    Three things in my classes;
    Line 21 in Main.java:
    public class Main extends JavaPlugin implements Listener {

    Line 31 in Main.java:
    public void onEnable() {

    Line 34 in Menu.java:
    public Menu(Plugin p) {
     
  2. @Samthelord1 You may have exported the plugin twice? If the plugin has been initialized twice, then there must be some other instance of it somewhere. Try removing all of your plugins and only running the Tokens plugin on its own.
     
  3. Offline

    Samthelord1

    @DJSkepter no instances of it anywhere, loading it on its own
    01.01 15:53:05 [Server] INFO ... 15 more
    01.01 15:53:05 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:837) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.java:364) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_51]
    01.01 15:53:05 [Server] INFO at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_51]
    01.01 15:53:05 [Server] INFO at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_51]
    01.01 15:53:05 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_51]
    01.01 15:53:05 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_51]
    01.01 15:53:05 [Server] INFO at me.samthelord1.tokens.Main.<init>(Main.java:21) ~[?:?]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO Caused by: java.lang.IllegalStateException: Initial initialization
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:818) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:957) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:740) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.Bukkit.reload(Bukkit.java:303) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:839) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:389) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:455) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at me.samthelord1.tokens.Main.onEnable(Main.java:31) ~[?:?]
    01.01 15:53:05 [Server] INFO at me.samthelord1.tokens.Menu.<init>(Menu.java:34) ~[?:?]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 15:53:05 [Server] INFO java.lang.IllegalArgumentException: Plugin already initialized!
    01.01 15:53:05 [Server] ERROR Error occurred while enabling Tokens v1.0.0 (Is it up to date?)
    01.01 15:53:05 [Server] INFO Enabling Tokens v1.0.0

    I think my error is somewhere in the opening of the inventory, as i can do /tokens balance and it will give me the tokens, but /tokens shop which opens the inventory does not open.. Here are snippets of the code:

    public Menu(Plugin p) {
    inv = Bukkit.getServer().createInventory(null, 9, "Token Shop");
    getServer().getPluginManager().registerEvents(this, p);

    public void show(Player p) {
    p.openInventory(inv);
    }
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getLabel().equalsIgnoreCase("tokens")) {
    if(args[0].equalsIgnoreCase("shop")) {
    menu.show(p);
     
  4. Offline

    teej107

  5. Offline

    Samthelord1

    Main.java Class:

    Code:
    /*
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */
    package me.samthelord1.tokens;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    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.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class Main extends JavaPlugin implements Listener {
      
        private Menu menu;
       
       
        FileConfiguration config = getConfig();
       
      
          @Override
       public void onEnable() {
          
          
      
       getConfig().options().copyDefaults(true);
           saveConfig();
       }
       
       
        public int getTokens(Player p) {
         return getConfig().getInt("tokens." + p.getName());
        }
       
        @EventHandler
        public void onInt(PlayerInteractEvent e) {
            if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
            menu.show(e.getPlayer());
        }
        }
       
        @EventHandler
       public void onJoin(PlayerJoinEvent e) {
           if(config.contains("tokens." + e.getPlayer().getName())) {
               return;
           }
           if(!config.contains("tokens." + e.getPlayer().getName())) {
               config.set("tokens." + e.getPlayer().getName(), 5);
              e.getPlayer().sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Welcome to " + config.getString("servername"));
               e.getPlayer().sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "You have no tokens!");
           }
       }
       @Override
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
       if(cmd.getLabel().equalsIgnoreCase("tokens")) {
    
          
          
           if(!(sender instanceof Player)) {
              sender.sendMessage("You must be a player to perform this command!");
          }
          if(sender instanceof Player) {
            
              if(args.length == 0) {
                  sender.sendMessage(ChatColor.GOLD + "========[TokenShop]========");
                  sender.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "</tokens balance> - Displays how many tokens you have.");
                  sender.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "</tokens shop> - Opens the token shop.");
              }
                  if(args.length >= 2) {
                  sender.sendMessage(ChatColor.GOLD + "========[TokenShop]========");
                  sender.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "</tokens balance> - Displays how many tokens you have.");
                  sender.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "</tokens shop> - Opens the token shop.");
                 
             
              }
              if(args.length == 1) {
                 
              Player p = (Player) sender;
              if(args[0].equalsIgnoreCase("balance")) {
                p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "you have " + config.getInt("tokens." + p.getName()) + "."); 
              }
              if(args[0].equalsIgnoreCase("shop")) {
                  menu.show(p);
                
              }
                 
             
          }
          }
       }
       return true;
       }
      
      
      
      
      
      
      
      
    
    }
           
           
       
    
    
    Menu.java class

    Code:
    /*
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */
    package me.samthelord1.tokens;
    
    import java.util.Arrays;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    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.java.JavaPlugin;
    
    /**
    *
    * @author Sam
    */
    public class Menu extends JavaPlugin implements Listener{
        private Inventory inv;
        private ItemStack sgapple, lbow, lsword, lshovel, laxe, hopper, beacon, creepegg, lpickaxe;
          static Integer myValue;
         private Main main;
    
    
    public Menu(Plugin p) {
        inv = Bukkit.getServer().createInventory(null, 9, "Token Shop");
    getServer().getPluginManager().registerEvents(this, p);
        ItemStack sgapple = new ItemStack(Material.GOLDEN_APPLE);
    ItemMeta sgam = sgapple.getItemMeta();
    sgam.setDisplayName(ChatColor.RED + "Super Golden Apple");
    sgam.setLore(Arrays.asList(ChatColor.YELLOW + "Price: " + getConfig().getInt("sgappleprice")));
    sgapple.setItemMeta(sgam);
    
    
    ItemStack lbow = new ItemStack(Material.BOW);
    ItemMeta lbw = lbow.getItemMeta();
    lbw.setDisplayName(ChatColor.AQUA + "Legendary Bow");
    lbw.setLore(Arrays.asList(ChatColor.YELLOW + "Price: " + getConfig().getInt("lbowprice")));
    lbow.setItemMeta(lbw);
    lbow.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 6);
    lbow.addEnchantment(Enchantment.ARROW_FIRE, 2);
    lbow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
    
    ItemStack lsword = new ItemStack(Material.DIAMOND_SWORD);
    ItemMeta lswo = lsword.getItemMeta();
    lswo.setDisplayName(ChatColor.AQUA + "Legendary Sword");
    lswo.setLore(Arrays.asList(ChatColor.YELLOW + "Price: " + getConfig().getInt("lswordprice")));
    lsword.setItemMeta(lswo);
    lsword.addUnsafeEnchantment(Enchantment.DURABILITY, 4);
    lsword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 6);
    lsword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
    
    ItemStack lpickaxe = new ItemStack(Material.DIAMOND_PICKAXE);
    ItemMeta lpick = lpickaxe.getItemMeta();
    lpick.setDisplayName(ChatColor.AQUA + "Legendary Pickaxe");
    lpick.setLore(Arrays.asList(ChatColor.YELLOW + "Price: " + getConfig().getInt("lpickaxeprice")));
    lpickaxe.setItemMeta(lpick);
    lpickaxe.addUnsafeEnchantment(Enchantment.LUCK, 4);
    lpickaxe.addUnsafeEnchantment(Enchantment.DURABILITY, 4);
    lpickaxe.addUnsafeEnchantment(Enchantment.DIG_SPEED, 6);
    
    ItemStack lshovel = new ItemStack(Material.DIAMOND_SPADE);
    ItemMeta lshov = lshovel.getItemMeta();
    lshov.setDisplayName(ChatColor.AQUA + "Legendary Shovel");
    lshov.setLore(Arrays.asList(ChatColor.YELLOW + "Price: " + getConfig().getInt("lshovelprice")));
    lshovel.setItemMeta(lshov);
    lshovel.addUnsafeEnchantment(Enchantment.DIG_SPEED, 6);
    lshovel.addUnsafeEnchantment(Enchantment.DURABILITY, 4);
    lshovel.addUnsafeEnchantment(Enchantment.LUCK, 4);
    
    ItemStack laxe = new ItemStack(Material.DIAMOND_AXE);
    ItemMeta lax = laxe.getItemMeta();
    lax.setDisplayName(ChatColor.AQUA + "Legendary Axe");
    lax.setLore(Arrays.asList(ChatColor.YELLOW + "Price: " + getConfig().getInt("laxeprice")));
    laxe.setItemMeta(lax);
    laxe.addUnsafeEnchantment(Enchantment.DURABILITY, 4);
    laxe.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 6);
    
    ItemStack beacon = new ItemStack(Material.BEACON);
    ItemMeta beac = beacon.getItemMeta();
    beac.setDisplayName(ChatColor.GOLD + "Beacon");
    beac.setLore(Arrays.asList(ChatColor.YELLOW + "Price: " + getConfig().getInt("beaconprice")));
    
    ItemStack hopper = new ItemStack(Material.HOPPER);
    ItemMeta hop = hopper.getItemMeta();
    hop.setDisplayName(ChatColor.BLACK + "Hopper");
    hop.setLore(Arrays.asList(ChatColor.YELLOW + "Price: " + getConfig().getInt("hopperprice")));
    
    ItemStack creeperegg = new ItemStack(Material.MONSTER_EGG);
    ItemMeta creep = creeperegg.getItemMeta();
    creep.setDisplayName(ChatColor.GREEN + "Creeper Egg");
    creep.setLore(Arrays.asList(ChatColor.YELLOW + "Price: " + getConfig().getInt("creepereggprice")));
    
    inv.setItem(0, sgapple);
    inv.setItem(1, lbow);
    inv.setItem(2, laxe);
    inv.setItem(3, lsword);
    inv.setItem(4, lshovel);
    inv.setItem(5, lpickaxe);
    inv.setItem(6, creeperegg);
    inv.setItem(7, hopper);
    inv.setItem(8, beacon);
    
    }
    
    
    public void show(Player p) {
        p.openInventory(inv);
    }
    
    
    @EventHandler
    public void onInvClick(InventoryClickEvent e) {
        if(!(e.getInventory().equals(inv))) return;
        if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Super Golden Apple")) {
           Player p = (Player)e.getWhoClicked();
          
           if(!(main.getTokens(p) < getConfig().getInt("gappleprice"))) {
           ItemStack gapple = new ItemStack(Material.GOLDEN_APPLE,1,(short)1);
            p.getInventory().addItem(gapple);
           
            getConfig().set("tokens." + p.getName(), main.getTokens(p) - getConfig().getInt("gappleprice"));
        p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Super Golden Apple bought for" + getConfig().getInt("gappleprice" + "."));
           }
           else {
               p.sendMessage(ChatColor.RED + "You do not have enough tokens!");
        }
        }
            if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Legendary Sword")) {
           Player p = (Player)e.getWhoClicked();
         if(!(main.getTokens(p) < getConfig().getInt("lswordprice"))) {
          ItemStack legsword = new ItemStack(Material.DIAMOND_SWORD);
          ItemMeta legswords = legsword.getItemMeta();
          legswords.setDisplayName(ChatColor.AQUA + "Legendary Sword");
          legsword.setItemMeta(legswords);
         legsword.addUnsafeEnchantment(Enchantment.DURABILITY, 4);
    legsword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 6);
    legsword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
             p.getInventory().addItem(legsword);
             getConfig().set("tokens." + p.getName(), main.getTokens(p) - getConfig().getInt("lswordprice"));
         p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Legendary Sword bought for" + getConfig().getInt("lswordprice" + "."));
         }           
         else {
             p.sendMessage(ChatColor.RED + "You do not have enough tokens!");
       
    }
    }
            if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Legendary Axe")) {
               Player p = (Player)e.getWhoClicked();
             
               if(!(main.getTokens(p) < getConfig().getInt("laxeprice"))) {
                  ItemStack legaxe = new ItemStack(Material.DIAMOND_AXE);
                  ItemMeta legaxes = legaxe.getItemMeta();
                  legaxes.setDisplayName(ChatColor.AQUA + "Legendary Axe");
                  legaxe.setItemMeta(legaxes);
                  legaxe.addUnsafeEnchantment(Enchantment.DURABILITY, 4);
                  legaxe.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 6);
                  p.getInventory().addItem(legaxe);
             getConfig().set("tokens." + p.getName(), main.getTokens(p) - getConfig().getInt("laxeprice"));
    p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Legendary Axe bought for" + getConfig().getInt("laxeprice" + "."));
            
               }
               else {
                   p.sendMessage(ChatColor.RED + "You do not have enough tokens!");
               }
            }
            if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Legendary Shovel")) {
               Player p = (Player)e.getWhoClicked();
              
               if(!(main.getTokens(p) < getConfig().getInt("lshovelprice"))) {
                   ItemStack legshovel = new ItemStack(Material.DIAMOND_SPADE);
                   ItemMeta legshovels = legshovel.getItemMeta();
                   legshovels.setDisplayName(ChatColor.AQUA + "Legendary Shovel");
                   legshovel.setItemMeta(legshovels);
                   legshovel.addUnsafeEnchantment(Enchantment.DIG_SPEED, 6);
    legshovel.addUnsafeEnchantment(Enchantment.DURABILITY, 4);
    legshovel.addUnsafeEnchantment(Enchantment.LUCK, 4);
        p.getInventory().addItem(legshovel);
        getConfig().set("tokens." + p.getName(), main.getTokens(p) - getConfig().getInt("lshovelprice"));
          p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Legendary Shovel bought for" + getConfig().getInt("lshovelprice" + "."));        
              
               }
               else {
                   p.sendMessage(ChatColor.RED + "You do not have enough tokens!");
               }
            }
            if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Legendary Bow")) {
                Player p = (Player)e.getWhoClicked();
       
                if(!(main.getTokens(p) < getConfig().getInt("lbowprice"))) {
                    ItemStack legbow = new ItemStack(Material.BOW);
                    ItemMeta legbows = legbow.getItemMeta();
                    legbows.setDisplayName(ChatColor.AQUA + "Legendary Bow");
                    legbow.setItemMeta(legbows);
                    legbow.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 6);
    legbow.addEnchantment(Enchantment.ARROW_FIRE, 2);
    legbow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
    getConfig().set("tokens." + p.getName(), main.getTokens(p) - getConfig().getInt("lbowprice"));
                p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Legendary Bow bought for" + getConfig().getInt("lbowprice" + "."));
                }
                else {
                   p.sendMessage(ChatColor.RED + "You do not have enough tokens!");
               }
            }
            if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Legendary Pickaxe")) {
               Player p = (Player)e.getWhoClicked();
            
               if(!(main.getTokens(p) < getConfig().getInt("lpickaxeprice"))) {
                   ItemStack legpick = new ItemStack(Material.DIAMOND_PICKAXE);
                   ItemMeta legpicks = legpick.getItemMeta();
                   legpicks.setDisplayName(ChatColor.AQUA + "Legendary Pickaxe");
                   legpick.setItemMeta(legpicks);
                   legpick.addUnsafeEnchantment(Enchantment.LUCK, 4);
                   legpick.addUnsafeEnchantment(Enchantment.DURABILITY, 4);
                   legpick.addUnsafeEnchantment(Enchantment.DIG_SPEED, 6);
               getConfig().set("tokens." + p.getName(), main.getTokens(p) - getConfig().getInt("lpickaxeprice"));
               p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Legendary Pickaxe bought for" + getConfig().getInt("lpickaxeprice" + "."));
               }
               else {
                   p.sendMessage(ChatColor.RED + "You do not have enough tokens!");
               }
            }
            if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Hopper")) {
               Player p = (Player)e.getWhoClicked();
             
               if(!(main.getTokens(p) < getConfig().getInt("hopperprice"))) {
                   p.getInventory().addItem(new ItemStack(Material.HOPPER));
                   getConfig().set("tokens." + p.getName(), main.getTokens(p) - getConfig().getInt("hopperprice"));
            p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Hopper bought for" + getConfig().getInt("hopperprice" + "."));
               }
               else {
                   p.sendMessage(ChatColor.RED + "You do not have enough tokens!");
               }
            }
            if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Beacon")) {
                Player p = (Player)e.getWhoClicked();
             
                if(!(main.getTokens(p) < getConfig().getInt("beaconprice"))) {
                    p.getInventory().addItem(new ItemStack(Material.BEACON));
                getConfig().set("tokens." + p.getName(), main.getTokens(p) - getConfig().getInt("beaconprice"));
            p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Beacon bought for" + getConfig().getInt("beaconprice" + "."));
                }
                else {
                    p.sendMessage(ChatColor.RED + "You do not have enough tokens!");
                }
               
            }
            if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Creeper Egg")) {
           Player p = (Player)e.getWhoClicked();
          
           if(!(main.getTokens(p) < getConfig().getInt("creepereggprice"))) {
               ItemStack creeperegg = new ItemStack(Material.MONSTER_EGG, 1, (short)50);
               p.getInventory().addItem(creeperegg);
                getConfig().set("tokens." + p.getName(), main.getTokens(p) - getConfig().getInt("creepereggprice"));
           p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "Creeper Egg bought for" + getConfig().getInt("creepereggprice" + "."));
           }
           else {
              
               p.sendMessage(ChatColor.RED + "You do not have enough tokens!");
           }
            }
    }
    
    
    }
    
    
    
     
  6. Offline

    teej107

    @Samthelord1 You can only have one JavaPlugin extended class. You should never instantiate them yourself.
     
  7. Offline

    Samthelord1

    @teej107 thanks ive just created an object of main in menu and used main.getConfig()
    testing now..
     
  8. Offline

    teej107

    @Samthelord1 No.....
     
  9. Offline

    Samthelord1

  10. Offline

    teej107

    @Samthelord1 Don't instantiate a JavaPlugin extended class.
     
  11. Offline

    Samthelord1

    @teej107 ok I get you, but how would i instead instance my config in another class?
     
  12. Offline

    teej107

  13. Offline

    Samthelord1

    @teej107 I dont understand why you're linking this? Please can you offer some insight as to how i get the config?
     
  14. Offline

    teej107

  15. Offline

    Samthelord1

    @teej107 I found that this would work;

    public Menu(Main instance){

    plugin = instance;
    }


    public Menu(Plugin p) {

    but, if i am using public Menu twice, is that wrong?
     
  16. Offline

    teej107

  17. Offline

    Samthelord1

    @teej107 yeah i fixed it, now getting a nullpointer when im running the command :/
     
  18. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page