Regenerating blocks after you mine them

Discussion in 'Plugin Development' started by MiBB3L, Mar 31, 2020.

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

    MiBB3L

    I want to regenerate a block after it getting mined by a player with a delay of 4 seconds!
    But it don´t place the block back.
    Code:
    public class BlockRegen implements Listener{
      
      
       private final long CMD_DELAY = 4 * 20;
       private Main plugin;
       public BlockRegen() {
       }
    
    
       @EventHandler
       public void onBreak(BlockBreakEvent event) {
         Block block = event.getBlock();
         Material blockname = event.getBlock().getType();
        
        
         Location location = block.getLocation();
         if(location.getWorld().getName().equals("FarmweltRaum")) {
        
         Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
           @Override
           public void run() {
              location.getBlock().setType(blockname);
           }
         }, CMD_DELAY);
         }
        
        
       }
     
  2. Online

    timtower Administrator Administrator Moderator

    @MiBB3L Print blockname, is it the old name or is it AIR?
     
  3. Offline

    MiBB3L

    Code:
    Could not pass event BlockBreakEvent to MiBB3L_Plugin v1.0
    org.bukkit.event.EventException
       at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
       at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
       at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.PlayerInteractManager.breakBlock(PlayerInteractManager.java:286) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.PlayerInteractManager.a(PlayerInteractManager.java:121) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:623) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:40) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:10) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_241]
       at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_241]
       at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
       at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
       at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
       at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.validate(CraftScheduler.java:397) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
       at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:123) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
       at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:119) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
       at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.scheduleSyncDelayedTask(CraftScheduler.java:102) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
       at de.mibbel.tutorial.listeners.BlockRegen.onBreak(BlockRegen.java:31) ~[?:?]
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_241]
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_241]
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_241]
       at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_241]
       at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
       ... 17 more
    
    I broke a grass-block and it said "GRASS"
    But this error appears in the console.
     
  4. Online

    timtower Administrator Administrator Moderator

  5. Offline

    MiBB3L

    Now i did it like that. Did you meant that?
    Code:
    public class BlockRegen implements Listener{
      
      
       private final long CMD_DELAY = 4 * 20;
       private Main plugin;
       public BlockRegen(Main plugin) {
         this.plugin = plugin;
       }
    
    
       @EventHandler
       public void onBreak(BlockBreakEvent event) {
         Block block = event.getBlock();
         Material blockname = event.getBlock().getType();
        
        
         Location location = block.getLocation();
         if(location.getWorld().getName().equals("FarmweltRaum")) {
           System.out.println(blockname);
        
         Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
           @Override
           public void run() {
             System.out.println(blockname);
              location.getBlock().setType(blockname);
           }
         }, CMD_DELAY);
         }
        
        
       }


    But how do i register that Event in my Main
    Bukkit.getPluginManager().registerEvents((Listener)new BlockRegen(), (Plugin)this);
    this doesn´t work
     
    Last edited by a moderator: Mar 31, 2020
  6. Online

    timtower Administrator Administrator Moderator

    @MiBB3L 1. No need for the constant bold.
    2. That should work.
    And just new BlockRegen(this)
    Don't cast.
     
  7. Offline

    MiBB3L

    Oh okay sorry for the bold.
    I did new BlockRegen(this)
    but there is the same error.
    Is there everything right with my scheduler?
     
  8. Online

    timtower Administrator Administrator Moderator

    @MiBB3L Please post the error again then
     
  9. Offline

    MiBB3L

    Could not pass event BlockBreakEvent to MiBB3L_Plugin v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerInteractManager.breakBlock(PlayerInteractManager.java:286) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerInteractManager.a(PlayerInteractManager.java:121) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:623) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:40) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:10) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_241]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_241]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
    at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.validate(CraftScheduler.java:397) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:123) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:119) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.scheduleSyncDelayedTask(CraftScheduler.java:102) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at de.mibbel.tutorial.listeners.BlockRegen.onBreak(BlockRegen.java:32) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_241]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_241]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    ... 17 more
     
  10. Online

    timtower Administrator Administrator Moderator

    @MiBB3L Please post your onEnable
     
  11. Offline

    MiBB3L

    public class Main extends JavaPlugin {
    private static Main plugin;

    public void onEnable() {
    plugin = this;
    new BlockRegen(this);
    }
     
  12. Online

    timtower Administrator Administrator Moderator

    @MiBB3L And you sure that everything exported? Because with that code you should not get that error.
     
  13. Offline

    MiBB3L

    public void onEnable() {
    plugin = this;
    (new Broadcaster(this)).startBroadcast();
    (new Mine(this)).startMine();
    new BlockRegen(this);
    getCommand("discord").setExecutor((CommandExecutor)new DiscordCommand());
    getCommand("kits").setExecutor((CommandExecutor)new KitSpielerCommand());
    getCommand("hilfe").setExecutor((CommandExecutor)new HilfeCommand());
    getCommand("arena").setExecutor((CommandExecutor)new ArenaCommand());
    getCommand("team").setExecutor((CommandExecutor)new TeamCommand());
    getCommand("discordRaenge").setExecutor((CommandExecutor)new DiscordRaengeCommand() );
    getCommand("teamspeak").setExecutor((CommandExecutor)new TeamspeakCommand());
    getCommand("ts").setExecutor((CommandExecutor)new TeamspeakCommand());
    getCommand("help").setExecutor((CommandExecutor)new HelpCommand());
    getCommand("?").setExecutor((CommandExecutor)new HelpCommand());
    getCommand("about").setExecutor((CommandExecutor)new HelpCommand());
    getCommand("support").setExecutor((CommandExecutor)new HelpCommand());
    getCommand("farmwelt").setExecutor((CommandExecutor)new FarmweltCommand());
    getCommand("event").setExecutor((CommandExecutor)new EventCommand());
    getCommand("pvparena").setExecutor((CommandExecutor)new PvPCommand());
    getCommand("snake").setExecutor((CommandExecutor)new SnakeCommand());
    getCommand("spawn").setExecutor((CommandExecutor)new SpawnCommand());
    getCommand("erze").setExecutor((CommandExecutor)new ErzeCommand());
    getCommand("gamble").setExecutor((CommandExecutor)new CasinoCommand());
    getCommand("trash").setExecutor((CommandExecutor)new TrashCommand());
    getCommand("muell").setExecutor((CommandExecutor)new TrashCommand());




    // getCommand("setspawn").setExecutor((CommandExecutor)new SetspawnCommand());
    getCommand("spawn").setExecutor((CommandExecutor)new SpawnCommand());

    PluginManager pluginManager = Bukkit.getPluginManager();
    pluginManager.registerEvents((Listener)new DeathListener(), (Plugin)this);
    pluginManager.registerEvents((Listener)new KillListener(), (Plugin)this);
    Bukkit.getPluginManager().registerEvents((Listener)new InventoryClickListener(), (Plugin)this);


    }

    public static Main getPlugin() {
    return plugin;
    }

    }
    That is my full Main Class but there works everything right except the BlockRegen
     
  14. Online

    timtower Administrator Administrator Moderator

    @MiBB3L Why is everything casted? Did you decompile this?
     
  15. Offline

    CraftCreeper6

    @MiBB3L
    You never register the events for BlockRegen, so how that error is even appearing is beyond me.
     
  16. Offline

    MiBB3L

    Guys can you send me an exmaple how to make it? I´m new in this programming stuff :oops:
     
  17. Offline

    CraftCreeper6

    @MiBB3L
    You need to register the events of BlockRegen.
    Exactly like that except replace KillListener with BlockRegen.
     
  18. Offline

    MiBB3L

    @CraftCreeper6 When i do it like you said it tells me this:
    The constructor BlockRegen() is undefined
     
  19. Offline

    CraftCreeper6

    @MiBB3L
    Because the constructor in your BlockRegen class also includes a reference to your main, so add a reference to your main within the constructor.
     
Thread Status:
Not open for further replies.

Share This Page