Solved cannot access org.bukkit.Material

Discussion in 'Plugin Development' started by LegendPro, Oct 7, 2021.

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

    LegendPro

    I use intellij IDEA to write my code and use maven to compile it into a .jar file but when i compile this comes "cannot access org.bukkit.Material"
    i use paper 1.17
    the log from maven is :


    [INFO]
    [INFO] -----------------------< com.legendpro:OpBlocks >-----------------------
    [INFO] Building OpBlocks 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ OpBlocks ---
    [INFO] Deleting G:\programming\OpBlocks\target
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ OpBlocks ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO]
    [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ OpBlocks ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 6 source files to G:\programming\OpBlocks\target\classes
    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR :
    [INFO] -------------------------------------------------------------
    [ERROR] /G:/programming/OpBlocks/src/main/java/com/legendpro/opblocks/moreoredrops/IRON/irondrops.java:[3,18] cannot access org.bukkit.Material
    bad class file: C:\Users\legendpro\.m2\repository\io\papermc\paper\paper-api\1.17.1-R0.1-SNAPSHOT\paper-api-1.17.1-R0.1-SNAPSHOT.jar(org/bukkit/Material.class)
    class file has wrong version 60.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    [INFO] 1 error
    [INFO] -------------------------------------------------------------

    This is my main code

    Code:
    package com.legendpro.opblocks;
    
    import com.legendpro.opblocks.moreoredrops.COPPER.copperdrops;
    import com.legendpro.opblocks.moreoredrops.DIAMOND.diamondrops;
    import com.legendpro.opblocks.moreoredrops.GOLD.golddrops;
    import com.legendpro.opblocks.moreoredrops.IRON.irondrops;
    import com.legendpro.opblocks.moreoredrops.NETHERITE.netheritedrops;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public final class OpBlocks extends JavaPlugin {
    
        @Override
        public void onEnable() {
            // Plugin startup logic
            getServer().getPluginManager().registerEvents(new netheritedrops(), this);
            getServer().getPluginManager().registerEvents(new golddrops(), this);
            getServer().getPluginManager().registerEvents(new diamondrops(), this);
            getServer().getPluginManager().registerEvents(new copperdrops(), this);
            getServer().getPluginManager().registerEvents(new irondrops(), this);
            System.out.println("OpBlocks PLUGIN IS RUNNING");
        }
    
        @Override
        public void onDisable() {
            // Plugin shutdown logic
            System.out.println("OpBlocks PLUGIN IS SHUTTING DOWN");
        }
    }
    This is one of my listener classes:
    Code:
    package com.legendpro.opblocks.moreoredrops.IRON;
    
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    
    public class irondrops implements Listener {
        @EventHandler
        public void onPlayerBreakIronOre(BlockBreakEvent e) {
            Block ironoreBroken = e.getBlock();
    
    
            if (ironoreBroken.getType() == Material.IRON_ORE) {
                e.setCancelled(true);
                ironoreBroken.setType(Material.AIR);
                ItemStack ironingot = new ItemStack(Material.IRON_INGOT, 5);
                ironoreBroken.getWorld().dropItemNaturally(ironoreBroken.getLocation(), ironingot);
            }
        }
    }
    
     
    Last edited: Oct 7, 2021
  2. Offline

    KarimAKL

    @LegendPro
    The error tells you that it was a class file version mismatch.

    Class file version 60.0 means Java 16, and class file version 52.0 means Java 8.
    Note: You can get the version by subtracting by 44.

    You can set the Java version in the pom.xml file.
     
  3. Offline

    LegendPro

    Last edited: Oct 8, 2021
Thread Status:
Not open for further replies.

Share This Page