Solved Plugin Malfuction

Discussion in 'Plugin Development' started by Geekhellmc, Nov 19, 2015.

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

    Geekhellmc

    Hi there, here is the problem: My plugin seems to run properly on the server and when I type /plugins, it shows the Plugin in green so it means everything is working but what I don't get it is that none of what I've coded seems to work in game.

    Plugin: It's a Menu Plugin that opens a menu when I click a skull_item that should appear when I join the server and that I'm at the Hub world.

    What doesn't work in the plugin: Like if the plugin didn't exist at all!

    Code
    Code:
    public class Main extends JavaPlugin{
    
        // Groups of Inventory
        public static Inventory ProfileInv = Bukkit.createInventory(null,45, ChatColor.BLUE + "My Profile");
        public static Inventory AchievementsInv = Bukkit.createInventory(null, 45, ChatColor.GOLD + "Achievements");
        public static Inventory PreferencesInv = Bukkit.createInventory(null, 45, ChatColor.RED + "Player Settings");
    
        //Inventory Blocks
        public void onPlayerInteract(PlayerInteractEvent event){
            Player player = event.getPlayer();
            if(player.getItemInHand() != null){
                ItemStack item = player.getItemInHand();
                if(item.getType() == Material.SKULL_ITEM){
                    event.setCancelled(true);
                    player.openInventory(ProfileInv);
                }
            }
        }
    
    
        @SuppressWarnings("deprecation")
        public void onPlayerJoin(Player p, InventoryClickEvent event){
            if(p.getWorld().getName().equals("Hub")){
                //Profile Settings
                ItemStack Skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
                SkullMeta SkullM = (SkullMeta) Skull.getItemMeta();
                SkullM.setOwner(p.getName());
                SkullM.setDisplayName(ChatColor.GREEN + "Profile Settings");
                ArrayList<String> SkullL = new ArrayList<String>();
                SkullL.add(ChatColor.GRAY + "View and configure your settings.");
                SkullM.setLore(SkullL);
                Skull.setItemMeta(SkullM);
    
                p.getInventory().setItem(9,Skull);
                p.updateInventory();
    
                Player player = (Player) event.getWhoClicked();
                ItemStack clicked = event.getCurrentItem();
                if(clicked.getType().equals(Skull)){
                    event.setCancelled(true);
                    player.closeInventory();
                    player.openInventory(PreferencesInv);
                }
            }
        }
    
        //Inventory Events
        public void onInventoryClick(InventoryClickEvent event){
            //Inventory Contents
            ItemStack WorkBench = new ItemStack(Material.WORKBENCH, 1);
            ItemMeta WorkBenchM = WorkBench.getItemMeta();
            WorkBenchM.setDisplayName(ChatColor.BLUE + "Achievements");
            ArrayList<String> WorkBenchL = new ArrayList<String>();
            WorkBenchL.add(ChatColor.GRAY + "View your achievements");
            WorkBenchM.setLore(WorkBenchL);
            WorkBench.setItemMeta(WorkBenchM);
    
            ItemStack Redstone = new ItemStack(Material.REDSTONE, 1);
            ItemMeta RedstoneM = Redstone.getItemMeta();
            RedstoneM.setDisplayName(ChatColor.GOLD + "Preferences");
            ArrayList<String> RedstoneL = new ArrayList<String>();
            RedstoneL.add(ChatColor.GRAY + "Set your preferences");
            RedstoneM.setLore(RedstoneL);
            Redstone.setItemMeta(RedstoneM);
    
            ItemStack BlazeRod = new ItemStack(Material.BLAZE_ROD, 1);
            ItemMeta BlazeRodM = BlazeRod.getItemMeta();
            BlazeRodM.setDisplayName(ChatColor.DARK_PURPLE + "Charmed");
            ArrayList<String> BlazeRodL = new ArrayList<String>();
            BlazeRodL.add(ChatColor.GRAY + "View your witchery achievements!");
            BlazeRodM.setLore(BlazeRodL);
            BlazeRod.setItemMeta(BlazeRodM);
    
            ItemStack DHelmet = new ItemStack(Material.DIAMOND_HELMET, 1);
            ItemMeta DHelmetM = DHelmet.getItemMeta();
            DHelmetM.setDisplayName(ChatColor.GREEN + "Put invisibility coat!");
            ArrayList<String> DHelmetL = new ArrayList<String>();
            DHelmetL.add(ChatColor.GRAY + "Hide yourself!");
            DHelmetM.setLore(DHelmetL);
            DHelmet.setItemMeta(DHelmetM);
    
            ItemStack IHelmet = new ItemStack(Material.IRON_HELMET, 1);
            ItemMeta IHelmetM = IHelmet.getItemMeta();
            IHelmetM.setDisplayName(ChatColor.RED + "Remove invisibility coat!");
            ArrayList<String> IHelmetL = new ArrayList<String>();
            IHelmetL.add(ChatColor.GRAY + "Show yourself!!");
            IHelmetM.setLore(IHelmetL);
            IHelmet.setItemMeta(IHelmetM);
    
            ItemStack DLegs = new ItemStack(Material.DIAMOND_BOOTS, 1);
            ItemMeta DLegsM = DLegs.getItemMeta();
            DLegsM.setDisplayName(ChatColor.GREEN + "Sonic Boots addition!");
            ArrayList<String> DLegsL = new ArrayList<String>();
            DLegsL.add(ChatColor.GRAY + "Run faster then Sonic!");
            DLegsM.setLore(DLegsL);
            DLegs.setItemMeta(DLegsM);
    
            ItemStack ILegs = new ItemStack(Material.IRON_BOOTS, 1);
            ItemMeta ILegsM = ILegs.getItemMeta();
            ILegsM.setDisplayName(ChatColor.RED + "Sonic Boots loss!");
            ArrayList<String> ILegsL = new ArrayList<String>();
            ILegsL.add(ChatColor.GRAY + "Run slower then a turtle!");
            ILegsM.setLore(ILegsL);
            ILegs.setItemMeta(ILegsM);
            //Set the items
            ProfileInv.setItem(21, WorkBench);
            ProfileInv.setItem(34, Redstone);
            AchievementsInv.setItem(21, BlazeRod);
            PreferencesInv.setItem(20, DHelmet);
            PreferencesInv.setItem(22, DLegs);
    
            // Items Configuration
            Player player = (Player) event.getWhoClicked();
            ItemStack clicked = event.getCurrentItem();
            Inventory inventory = event.getInventory();
            if(inventory.getName().equals(ProfileInv.getName())){
                if(clicked.getType().equals(Redstone)){
                    event.setCancelled(true);
                    player.closeInventory();
                    player.openInventory(PreferencesInv);
                    if(clicked.getType().equals(DHelmet)){
                        event.setCancelled(true);
                        PreferencesInv.remove(DHelmet);
                        PreferencesInv.setItem(20, IHelmet);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 0, 0));
                    }
                    if(clicked.getType().equals(IHelmet)){
                        event.setCancelled(true);
                        PreferencesInv.remove(IHelmet);
                        PreferencesInv.setItem(20, DHelmet);
                        player.removePotionEffect(PotionEffectType.INVISIBILITY);
    
                    }
                    if(clicked.getType().equals(DLegs)){
                        event.setCancelled(true);
                        PreferencesInv.remove(DLegs);
                        PreferencesInv.setItem(22, ILegs);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 0, 2));           
                    }
                    if(clicked.getType().equals(ILegs)){
                        event.setCancelled(true);
                        PreferencesInv.remove(ILegs);
                        PreferencesInv.setItem(22, DLegs);
                        player.removePotionEffect(PotionEffectType.SPEED);           
                    }
                }
                if(clicked.getType().equals(WorkBench)){
                    event.setCancelled(true);
                    player.closeInventory();
                    player.openInventory(AchievementsInv);
                    if(clicked.getType().equals(BlazeRod)){
                        event.setCancelled(true);
                        player.sendMessage(ChatColor.YELLOW + "[ " + ChatColor.LIGHT_PURPLE + "Magica" + ChatColor.YELLOW + " ] " + ChatColor.BLUE + "The game is still under developement!");
                    }
                }
            }
        }
    }
    

    PLEASE do not tell me to go download a MenuGui plugin! I want to make my own!
     
  2. Offline

    Lordloss

    Your class has to implement Listener to work as an EventListener, and youre mising the @EventHandler over your methods. Also they need to be registered as such. Please google how to setup an EventListener correctly.
     
  3. Offline

    RoboticPlayer

  4. Offline

    Geekhellmc

    Wow that worked, thanks!
     
Thread Status:
Not open for further replies.

Share This Page