Gui menu help|cant spawn with item

Discussion in 'Plugin Development' started by Paco the miner, Mar 12, 2014.

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

    Paco the miner

    this is my code and nothing is wrong in it from what i can tell and theres no error in my plugin.yml someone please help
    Code:
    package me.wrinkledog;
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    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.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public class Main extends JavaPlugin implements Listener {
       
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
           
        }
     
        public void teleportInWorld(Player player, int x, int y, int z) {
            player.teleport(new Location(player.getWorld(), x,y,z));
            }
     
      private void openGUI(Player player) {
          Inventory inv = Bukkit.createInventory(null, 9, ChatColor.BLUE + "Surprise Maker");
         
     
          ItemStack survival = new ItemStack (Material.DRAGON_EGG);
          ItemMeta  survivalMeta = survival.getItemMeta();
          ItemStack create = new ItemStack (Material.BEDROCK);
          ItemMeta  createMeta = survival.getItemMeta();
         
          survivalMeta.setDisplayName(ChatColor.BLACK + "A Surprise coming soon");
          survival.setItemMeta(survivalMeta);
         
          createMeta.setDisplayName(ChatColor.DARK_PURPLE + "Another Surprise coming soon");
          create.setItemMeta(createMeta);
         
          inv.setItem(3, survival);
          inv.setItem(5, create);
         
          player.openInventory(inv);
      }
      @EventHandler
      public void onInventoryClick(InventoryClickEvent event) {
          if(ChatColor.stripColor(event.getInventory().getName())
                  .equalsIgnoreCase("Surprise Maker"))
              return;
          Player player = (Player) event.getWhoClicked();
          event.setCancelled(true);
         
          if(event.getCurrentItem()==null
                  || event.getCurrentItem().getType()==Material.AIR
                  ||event.getCurrentItem().hasItemMeta()) {
              player.closeInventory();
              return;
          }
         
          switch(event.getCurrentItem().getType()) {
          case DRAGON_EGG:
              player.closeInventory();
              player.sendMessage(ChatColor.DARK_BLUE + "You can't go there yet" + player.getName());
              break;
          case BEDROCK:
              player.closeInventory();
              player.sendMessage(ChatColor.DARK_BLUE + "You can't go there yet" + player.getName());
              break;
          default:
              player.closeInventory();
              break;
          }
      }
     
      @EventHandler
      public void onPlayerJoin(PlayerJoinEvent event) {
        event.getPlayer().getInventory()
        .addItem(new ItemStack(Material.APPLE));
       
      }
     
     
      @EventHandler
      public void onPlayerInteract(PlayerInteractEvent event) {
          Action a = event.getAction();
          ItemStack is = event.getItem();
         
          if(a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
              return;
         
          if(is.getType()==Material.APPLE)
              openGUI(event.getPlayer());
             
      }
    }
     
  2. Offline

    Paco the miner

  3. Offline

    nlthijs48

    Paco the miner Do you have an error in the console if you try it or does nothing happen?
     
  4. Offline

    Paco the miner

    nlthijs48 No it runs fine and registers as a plugin and i followed a video perfectly
     
  5. Offline

    nlthijs48

    Paco the miner You have the following line:
    Code:java
    1. if(ChatColor.stripColor(event.getInventory().getName())
    2. .equalsIgnoreCase("Surprise Maker"))
    3. return;

    That would stop the handling of the event if the name of the inventory is "Surprise Maker", I think you wan't it to run if it is "Surprise Maker" and not run it if it is not named like that. Change the code to this to invert your statement and then it should do more:
    Code:java
    1. if(!(ChatColor.stripColor(event.getInventory().getName())
    2. .equalsIgnoreCase("Surprise Maker")))
    3. return;
     
  6. Offline

    Paco the miner

Thread Status:
Not open for further replies.

Share This Page