Solved help, plugin break bedrock

Discussion in 'Plugin Development' started by tg95, Dec 13, 2014.

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

    tg95

    hello, I am trying to create a plugin that with an object of the bedrock, so that is giving some errors and I am not to solve, can you help me?

    my code:
    Code:
    package me.tg95.bed;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public final class Main extends JavaPlugin implements Listener {
       
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("bedrockbreaker")){
                Player player = (Player) sender;
                PlayerInventory inventory = player.getInventory();
    
                ItemStack bedrockbreaker = new ItemStack(Material.DIAMOND_HOE,1);
    
                ItemMeta im = bedrockbreaker.getItemMeta();
    
                im.setDisplayName(ChatColor.DARK_AQUA + "Breaker");
                bedrockbreaker.setItemMeta(im);
                inventory.addItem(bedrockbreaker);
                return true;
            }
    
            return false;
        }
        @EventHandler(priority=EventPriority.HIGH)
        public void onPlayerUse (org.bukkit.event.player.PlayerInteractEvent evnt) {
            Block block = evnt.getClickedBlock();
            ItemStack item = evnt.getItem();
            Player player = evnt.getPlayer();
            World world = block.getWorld();
            ItemMeta itemmeta = item.getItemMeta();
                if (block.getType() == Material.BEDROCK && item.getType() ==
                        Material.DIAMOND_HOE && itemmeta.getDisplayName() == ChatColor.DARK_AQUA + "Breaker") {
    
                    BlockBreakEvent breakEvent = new BlockBreakEvent(block, player);
                    getServer().getPluginManager().callEvent(breakEvent);
                    ItemStack drop = new ItemStack(block.getType());
                    drop.setAmount(1);
                    drop.setType(Material.BEDROCK);
                    block.setType(Material.AIR);
    
                    world.dropItemNaturally(block.getLocation(), drop);
                    player.sendMessage("Bedrock Broken!");
                }
        }
    }
    sorry for my bad english.
    Thanks all for help.
     
  2. Offline

    JordyPwner

    the rror would be nice if you posted it
     
  3. Offline

    Gingerbreadman

    @tg95 hmm your class seems to be final?
    final classes cant extend, try removing final
     
  4. Offline

    tg95

    hi thanks.
    error:
    Code:
    [12:26:02] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to BreackBedRock v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:165) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:988) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.a(SourceFile:43) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.handle(SourceFile:9) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
        at me.tg95.bed.Main.onPlayerUse(Main.java:47) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_20]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_20]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_20]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_20]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        ... 15 more
    [12:26:16] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to BreackBedRock v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:165) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:988) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.a(SourceFile:43) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.handle(SourceFile:9) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
        at me.tg95.bed.Main.onPlayerUse(Main.java:47) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_20]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_20]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_20]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_20]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[NSPGaming.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        ... 15 more
    
    @Gingerbreadman
    hi, thanks but not resolved.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  5. Offline

    Tehmaker

    Code:
    Caused by: java.lang.NullPointerException    
    at me.tg95.bed.Main.onPlayerUse(Main.java:47) ~[?:?]
    
    Your 47th line is:
    Code:
    World world = block.getWorld();
    
    The world that is being returned is null from what I can gather. try adding an ifstatement to check if it is null, and send a message to the player to confirm this.
     
  6. Offline

    tg95

    @Tehmaker hi, sorry for my quest, but, where put this?
    Thanks for attention.
     
  7. Offline

    Tehmaker

    @tg95
    You would check right under the declaration of the variable.
     
Thread Status:
Not open for further replies.

Share This Page