Cannot resolve method "getName()'

Discussion in 'Plugin Development' started by WetriZ, Dec 8, 2019.

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

    WetriZ

    Hey guys,
    I am making GUI plugin for our server. I have a problem with my code. Could somebody check my code and tell me what is wrong with method 'getName()'? Thanks.

    My code:

    Code:
    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);
        }
    
        private void teleportujVeSvete(Player p, int x, int y, int z){
            p.teleport(new Location(p.getWorld(), x, y, z));
        }
    
        private void otevriGUI(Player p){
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_GREEN + "Server Selector");
    
            ItemStack survival = new ItemStack(Material.DIAMOND_SWORD);
            ItemMeta survivalMeta = survival.getItemMeta();
    
            ItemStack lobby = new ItemStack(Material.CRAFTING_TABLE);
            ItemMeta lobbyMeta = lobby.getItemMeta();
    
            ItemStack bedwars = new ItemStack(Material.RED_BED);
            ItemMeta bedwarsMeta = bedwars.getItemMeta();
    
            survivalMeta.setDisplayName(ChatColor.RED + "Survival");
            survival.setItemMeta(survivalMeta);
    
            lobbyMeta.setDisplayName(ChatColor.GREEN + "Lobby");
            lobby.setItemMeta(lobbyMeta);
    
            bedwarsMeta.setDisplayName(ChatColor.YELLOW + "Bed Wars");
            bedwars.setItemMeta(bedwarsMeta);
    
            inv.setItem(3, survival);
            inv.setItem(4,lobby);
            inv.setItem(5, bedwars);
    
            p.openInventory(inv);
        }
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event){
            if(ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Server Selector")) {
                    return;
            }
            Player p = (Player) event.getWhoClicked();
            event.setCancelled(true);
    
            if(event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR || event.getCurrentItem().hasItemMeta()){
                p.closeInventory();
                return;
            }
        }
        @EventHandler
        public void onJoin(PlayerJoinEvent event){
            event.getPlayer().getInventory().addItem(new ItemStack(Material.COMPASS));
        }
    
    
    
        @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.COMPASS)
                otevriGUI(event.getPlayer());
        }
    }
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    WetriZ

Thread Status:
Not open for further replies.

Share This Page