Literally none of my code works

Discussion in 'Plugin Development' started by XgXXSnipz, Dec 20, 2014.

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

    XgXXSnipz

    Nothing works, it used to but now nothing works

    Code:
        public void onEnable(){
           
            Bukkit.getServer().getPluginManager().registerEvents(new Gui(), this);
    
        }
       
        @EventHandler
        public void onJoin(PlayerJoinEvent e){
           
            Player p = e.getPlayer();
           
           
           
            ItemStack hubitems = new ItemStack(Material.STICK, 1);
               ItemMeta hubmeta = hubitems.getItemMeta();
               ArrayList<String> hub = new ArrayList<String>();
               hubmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD + "Hide Players");
               hub.add(ChatColor.RED +  "[Click to hide]");
               hubmeta.setLore(hub);
               hubitems.setItemMeta(hubmeta);
    
              
              
              
               ItemStack donateitems = new ItemStack(Material.EMERALD, 1);
               ItemMeta donatemeta = donateitems.getItemMeta();
               ArrayList<String> emerald = new ArrayList<String>();
               donatemeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD + "Donate");
               emerald.add(ChatColor.RED +  "Donate!");
               donatemeta.setLore(emerald);
               donateitems.setItemMeta(donatemeta);
              
               ItemStack bungeeitems = new ItemStack(Material.COMPASS, 1);
               ItemMeta bungeemeta = bungeeitems.getItemMeta();
               ArrayList<String> compass = new ArrayList<String>();
               bungeemeta.setDisplayName(ChatColor.AQUA.toString() + ChatColor.BOLD + "Server Selector");
               compass.add(ChatColor.RED +  "Go somewhere!!");
               bungeemeta.setLore(compass);
               bungeeitems.setItemMeta(bungeemeta);
              
              
              
              
              
               //Add these later
           
            ItemStack book;
           
           
            book = new ItemStack(Material.WRITTEN_BOOK);
            BookMeta bm = (BookMeta) book.getItemMeta();
            bm.addPage("1", "2");
            bm.setPage(1, (ChatColor.BLACK.toString() + ChatColor.BOLD + "Welcome to ReflectiveMC! Here you will find a lot of fun things!! Like "
                    + ChatColor.RED.toString() + ChatColor.BOLD + "* SurvivalGames, Factions, KitPVP and Bowbash!"));
            bm.setPage(2, (ChatColor.GREEN.toString() + ChatColor.BOLD + "Staff: " + ChatColor.RED.toString() + ChatColor.BOLD +
                    "- Owner napoleancrafter , - 2nd Owner InvalidGaming, - Admin traydenpoke,  - Admin GodCookiez, - Admin Alex,  - Head-Developer bwfcwalshy, - Developer nverdier, - Developer CreeperSwagg34"));
            bm.setAuthor(ChatColor.GREEN.toString() + ChatColor.ITALIC + "ReflectiveMC");
            bm.setDisplayName(ChatColor.GOLD.toString() + ChatColor.BOLD + "Welcome!" + ChatColor.GREEN +" (Click)");
            book.setItemMeta(bm);
           
           
           
             p.setAllowFlight(true);
             p.setFlying(false);
            
            
             p.getInventory().addItem(new ItemStack(bungeeitems));
             p.getInventory().addItem(new ItemStack(hubitems));
             p.getInventory().addItem(new ItemStack(book));
             p.getInventory().addItem(new ItemStack(donateitems));
            
              
        }
       
         @SuppressWarnings("deprecation")
        @EventHandler
         public void onPlayerFly(PlayerToggleFlightEvent e) {
                 Player p = e.getPlayer();
                 if (p.getGameMode() != GameMode.CREATIVE) {
                         e.setCancelled(true);
                         p.setAllowFlight(false);
                         p.setFlying(false);
                         p.setVelocity(p.getLocation().getDirection().multiply(2.0D).setY(2.1D).setZ(3.0D));
                         p.playEffect(p.getLocation(), Effect.SMOKE, 15);
                 }
         }
    
         @EventHandler
         public void move(PlayerMoveEvent e) {
                 Player p = e.getPlayer();
                 if (e.getPlayer().getGameMode() != GameMode.CREATIVE) {
                         if (p.getLocation().getBlock().getRelative(BlockFace.DOWN)
                                         .getType() != Material.AIR) {
                                 p.setAllowFlight(true);
                         }
                 }
         }
        
        
         @EventHandler
         public void onPlayerInteract(PlayerInteractEvent e) {
            
            
             ItemStack hubitems = new ItemStack(Material.STICK, 1);
                ItemMeta hubmeta = hubitems.getItemMeta();
                ArrayList<String> hub = new ArrayList<String>();
                hubmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD + "Hide Players");
                hub.add(ChatColor.RED +  "[Click to hide]");
                hubmeta.setLore(hub);
                hubitems.setItemMeta(hubmeta);
               
               
                ItemStack hideplayers = new ItemStack(Material.BLAZE_ROD, 1);
                   ItemMeta hideplayersmeta = hideplayers.getItemMeta();
                   ArrayList<String> hide = new ArrayList<String>();
                   hubmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD + "Show Players");
                   hub.add(ChatColor.RED +  "[Click to show]");
                   hubmeta.setLore(hide);
                   hubitems.setItemMeta(hideplayersmeta);
                  
                  
                  
         if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
             if (e.getItem().getType() == Material.STICK) {
                 Player player = e.getPlayer();
                 for (Player other : getServer().getOnlinePlayers()) {
                     player.hidePlayer(other);
                     player.playSound(player.getLocation(), Sound.ANVIL_LAND, 10, 1);
                     player.getInventory().remove(hubitems);
                     player.getInventory().addItem(hideplayers);
                     player.sendMessage(ChatColor.GREEN + "Players have been hidden!");
                     return;
                 }
                 return;
             }
             if (e.getItem().getType() == Material.BLAZE_ROD) {
                 Player player = e.getPlayer();
                 for (Player other : getServer().getOnlinePlayers()) {
                     player.showPlayer(other);
                     player.playSound(player.getLocation(), Sound.ANVIL_BREAK, 10, 1);
                     player.getInventory().remove(hideplayers);
                     player.getInventory().addItem(hubitems);
                     player.sendMessage(ChatColor.GREEN + "Players have been shown!");
                     return;
                 }
                
                 return;
             }
            
             if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                 if (e.getItem().getType() == Material.EMERALD) {
                     Player player = e.getPlayer();
                         player.sendMessage(ChatColor.GREEN + "http://reflectivemc.com/");
                         return;
                     }
                
                 if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                     if (e.getItem().getType() == Material.COMPASS) {
                         Player player = e.getPlayer();
                         player.openInventory(Gui.GUI);
                             return;
                         }
                     return;
                 }
             }
         }
         }
    GUI:
    Code:
    private static ItemStack spawn;
       
        public static Inventory GUI = Bukkit.createInventory(null, 18, "Test GUI");
       
        static
        {
           
            spawn = item1(ChatColor.RED + "Spawn");
           
            GUI.setItem(4, spawn);
           
        }
       
       
       
        private static ItemStack item1(String name){
            ItemStack i = new ItemStack(new ItemStack(Material.ANVIL, 1));
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(name);
            im.setLore(Arrays.asList("§aGo to the server spawn!"));
            i.setItemMeta(im);
            return i;
        }
       
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e) {
            if (!e.getInventory().getName().equalsIgnoreCase(GUI.getName())) return;
            if (e.getCurrentItem().getItemMeta() == null) return;
            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Spawn")){
                e.setCancelled(true);
                e.getWhoClicked().teleport(e.getWhoClicked().getWorld().getSpawnLocation());
                e.getWhoClicked().closeInventory();
            }
        }
    please help
     
  2. Offline

    Skionz

    Debug.
     
  3. Offline

    teej107

    It's probably from your misuse of static. (not really)
     
  4. Offline

    XgXXSnipz

  5. Offline

    es359

    Be more specific. What doesn't work? Are there any errors? Post them here.
     
  6. Offline

    teej107

    1st step: Turn on your computer.
     
  7. Offline

    XgXXSnipz

    @teej107 LOL, seriously though @es359 literally NO errors, just nothing happens, my hide players dont work, my GUI wont work, it all did work then it just stopped
     
  8. Offline

    teej107

    @XgXXSnipz
    2nd step: install Java

    EDIT: Now would be the time to post any errors in the console to save your self from more steps.
     
  9. Offline

    Skionz

     
    Jaaakee224 likes this.
  10. Offline

    Rocoty

    It's really quite simple: You did not register events for your main class.
     
  11. Offline

    mine-care

    Also why thaT much of static??
     
  12. Offline

    xTrollxDudex

    I think he did
     
  13. Offline

    Rocoty

    @xTrollxDudex In that case he left out that part of the code. According to the code snippets above, only events for the Gui class are registered.
     
  14. Offline

    XgXXSnipz

    @Rocoty Fixed it

    Works now... lock please
     
Thread Status:
Not open for further replies.

Share This Page