Set a block after it's broken?

Discussion in 'Plugin Development' started by DinoZauruZ, Feb 22, 2015.

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

    DinoZauruZ

    Here I am... Again!
    Sorry for all theese threads! I just tried to fix this bug and it just wont get fixed!
    I want to set a block after it's broken
    Code:
    Code:
    @EventHandler
        public void onBlockBreak(BlockBreakEvent e) {
           
            final Player p = e.getPlayer();
            Block b = e.getBlock();
           
            int blockbroken = config.getInt(p.getName());
           
            if(blockbroken == 199) {
                p.sendMessage("§b§o200 Blocks broken! Not bad!");
                b.getLocation().getBlock().setType(Material.CHEST);
                final Block chest = b.getLocation().getBlock();
                chests.add(chest);
                config.set(p.getName(), 0);
                saveConfig();
                server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        chest.setType(Material.AIR);
                        p.sendMessage("§cYour crate was removed! Hope you had the time to get its contents...");
                        chests.remove(chest);
                    }
                }, 20*20);
            } else {
                config.set(p.getName(), config.getInt(p.getName()) + 1);
                saveConfig();   
            }
        }
    It's something of a crate this is not whole code, if you want whole code just ask me.
     
  2. Offline

    bobthefish

    Im slightly confused, is there an error? is it just not working? what exactly is your question?
     
  3. Offline

    DinoZauruZ

    Sorry @bobthefish I was up late yesterday and that thread wasen't such clear.
    I want to set the block after it's removed by a player.
    So after the blockbreakevent is triggered and the player has broken 200 blocks then I want to set the block at the broken blocks location to a chest, then later I have an interact event that checks if the arraylist "chests" contains the chest and then it cancels the event and opens a gui with some stuff in.

    Hope that's more clearer. Oh! The error is the block is not being set to a chest, which is a huge problem in this code since that's the whole point of it :p To be even more clearer, I want to set the broken block to chest or atleast the block at the broken blocks location to a chest.
     
  4. Offline

    MajorSkillage

    You need to save the blocks broken data as a hashmap into a yml but you should store it using a section. If you want to rollback amounts of blocks just get the data from the yml and at the location set the block back to what it was.
     
  5. Offline

    DinoZauruZ

    @MajorSkillage is that neccesary to just set the type of the block?

    EDIT:
    I want to set the block at the broken blocks location to type chest. Is it neccesary to store them in a hashmap?
     
  6. Offline

    MajorSkillage

    HashMap<Location, Block> you tell me.
     
  7. Offline

    bobthefish

    Does the method run at all? or does it break at a certain line (are there any stacktraces you can give us?)
     
  8. Offline

    RenditionsRule

    I think one of the problems is, you saveConfig at the bottom of it, but you never reloadConfig it, which is necessary to dump old values and swap them for the updated config.
     
  9. Offline

    DinoZauruZ

    The method runs, but the setType doesn't work :/
    @bobthefish
    Could it have something to do with plugin version and server version?
    Server 1.7.10, plugin 1.7.10
    Craftbukkit Bukkit
     
Thread Status:
Not open for further replies.

Share This Page