What's Wrong?

Discussion in 'Programming' started by nick_2002, Jun 23, 2016.

  1. I was making this plugin and something when wrong.
    found the mistake :3


    Code (Text):
    package com.script07;

    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    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.permissions.Permission;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin implements Listener{
       
        public static final Logger log = Logger.getLogger("Minecraft");
        public static main plugin;
       
        @Override
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
            PluginDescriptionFile pdf = getDescription();
            log.info(pdf.getName() + " > has been enabled.");
            onPermission();
        }
        @Override
        public void onDisable(){
            PluginDescriptionFile pdf = getDescription();
            log.info(pdf.getName() + " > has been disabled.");
        }
       
        public Permission gamemode = new Permission("gamemode.use");
       
        public void onPermission(){
            PluginManager pm = getServer().getPluginManager();
            pm.addPermission(gamemode);
        }
        private void onGUI(Player p){
            if (p.hasPermission("gamemode.use")){
            // GUI
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_GRAY + "GameMode Selector");
            // Creative
            ItemStack creative = new ItemStack(Material.IRON_INGOT);
            ItemMeta creativemeta = creative.getItemMeta();
            creativemeta.setDisplayName(ChatColor.RED + "Creative");
            creative.setItemMeta(creativemeta);
            inv.setItem(2, creative);
            // Survival
            ItemStack survival = new ItemStack(Material.GOLD_INGOT);
            ItemMeta smeta = survival.getItemMeta();
            smeta.setDisplayName(ChatColor.RED + "Survival");
            survival.setItemMeta(smeta);
            inv.setItem(4, survival);
            // Adventure
            ItemStack adventure = new ItemStack(Material.DIAMOND);
            ItemMeta ameta = adventure.getItemMeta();
            ameta.setDisplayName(ChatColor.RED + "Adventure");
            adventure.setItemMeta(ameta);
            inv.setItem(6, adventure);
           
            p.openInventory(inv);
            }
        }
        @EventHandler
        public void onGUI(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.DIAMOND)
                onGUI(event.getPlayer());
        }
        @EventHandler
        public void onEvent(PlayerJoinEvent event){
            event.getPlayer().getInventory().addItem(new ItemStack(Material.DIAMOND));
        }
        @EventHandler
        public void onClick(InventoryClickEvent event){
            if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Abilities"))
                return;
            Player p = (Player) event.getWhoClicked();
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR || !event.getCurrentItem().hasItemMeta()){
                p.closeInventory();
                return;
            }
            switch (event.getCurrentItem().getType()){
                case IRON_INGOT:
                    p.closeInventory();
                    p.setGameMode(GameMode.CREATIVE);
                    p.sendMessage(ChatColor.BLUE + "GameMode > " + ChatColor.GRAY + "You have changed your gamemode to creative.");
                    break;
                case GOLD_INGOT:
                    p.closeInventory();
                    p.setGameMode(GameMode.SURVIVAL);
                    p.sendMessage(ChatColor.BLUE + "GameMode > " + ChatColor.GRAY + "You have changed your gamemode to survival.");
                    break;
                case DIAMOND:
                    p.closeInventory();
                    p.setGameMode(GameMode.ADVENTURE);
                    p.sendMessage(ChatColor.BLUE + "GameMode > " + ChatColor.GRAY + "You have changed your gamemode to adventure.");
                    break;
                default:
                    break;
            }
        }
    }
     
  2. Great, very fucking detailed. That was sarcasm. What is not happening?
     
  3. xD
     
  4. he fixed it lol read
     
  5. And next time, make the title a little more detailed. It would help other members that may have the same problem.
     
  6. He changed it after I posted my message. lol learn to read timestamps