Jackhammer kit, crashing server (time out)

Discussion in 'Plugin Development' started by CMG, Jun 1, 2013.

  1. Offline

    CMG

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I have made many kits replicating the mcpvp's ones and my own for a Hunger Games plugin. There has only been maybe 1 or 2 ones that i have had trouble with and this is one of them. Basically when a player breaks a block with a stone axe and has the jackhammer kit ability it should break all blocks above it like mcpvp's jackhammer. But instead it crashes my server anyway to fix this or can you give me some better code?:
    Code:
    package me.CMG.HungerGames.Listeners;
     
    import me.CMG.HungerGames.Main.HungerGames;
    import me.CMG.HungerGames.Main.HungerGames.Kit;
    import me.CMG.HungerGames.Main.Methods;
     
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
     
    public class JackhammerAbility implements Listener
    {
        HungerGames plugin;
     
        public final Methods m = new Methods();
     
        public JackhammerAbility(HungerGames plugin) {
            this.plugin = plugin;
        }
     
        int specType = Material.STONE_AXE.getId();
     
        @EventHandler
        public void onBreakBlock(BlockBreakEvent e)
        {
            Player p = (Player) e.getPlayer();
            Kit k = HungerGames.players.get(p.getName());
            int type = p.getItemInHand().getTypeId();
     
            if(type == specType)
            {
                if(k == Kit.Jackhammer)
                {
                    if(e.getBlock().getType() != null)
                    {
                        Block b = e.getBlock().getRelative(BlockFace.UP);
     
                        while(b.getType() != null)
                        {
                            b.setType(Material.AIR);
                            b = b.getRelative(BlockFace.UP);
                        }
                    }
                    else
                    {
     
                    }
                }
                else
                {
     
                }
            }
            else
            {
     
            }
        }
    }
  2. Offline

    GodzOfMadness

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @CMG instead of b.getType() != null do while(!b.getType().equals(Material.AIR))
  3. Offline

    CMG

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Thanks :D, that works but how would i make it so it does each block one by one like an animation? so a little pause inbetween? EDIT what about gaps though? so if it goes Block Air Block?

    This post has been edited 1 time. It was last edited by CMG Jun 1, 2013.
  4. Offline

    CMG

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Anyone?
  5. Offline

    GodzOfMadness

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @CMG Just make something like create a custom event and then loop through all the blocks. When it reaches a certain amount then just stop, store the rest and then schedule a delayed task for how ever long and then call the event again and again until it finishes.
  6. Offline

    GodzOfMadness

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @CMG Don't bump after 5 minutes of no one answering you..
  7. Offline

    CMG

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Yeah sorry.
  8. Offline

    CMG

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Ok, but how would i loop through all the blocks that's what i don't know how to do.
  9. Offline

    GodzOfMadness

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @CMG Create an arraylist that stores their locations like ArrayList<Location> list = new ArrayList<Location>()
    then add the location of each block it finds. Then you could make another list and then go through each one of them and when the size of that list is large enough stop the loop and then build the blocks and start the delayed task to start again with the rest of the blocks.
  10. Offline

    CMG

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Ill try that
  11. Offline

    CMG

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Nope had a go but still didn't understand.
  12. Offline

    GodzOfMadness

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @CMG create a list that holds all the blocks you find. Create another list for the certain amount of blocks you want regened. Then loop through the list that holds all the blocks. make a while loop like
    while(tempList.size() < amount){
    tempList.add(all.get(0));
    all.remove(0);
    }
    then keep going until the amount is done
    then go and regen those blocks in that list like
    for(Location loc : tempList){
    loc.getBlock().setType(Material.AIR);
    }
    then schedule the delayed task
    when the delay is over call the custom event again with the list that holds all the blocks and it will repeat until it is over
  13. Offline

    CMG

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Something like this:
    Code:
    package me.CMG.HungerGames.Listeners;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import me.CMG.HungerGames.Main.HungerGames;
    import me.CMG.HungerGames.Main.HungerGames.Kit;
    import me.CMG.HungerGames.Main.Methods;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
     
    public class JackhammerAbility implements Listener
    {
        HungerGames plugin;
     
        public final Methods m = new Methods();
     
        public JackhammerAbility(HungerGames plugin) {
            this.plugin = plugin;
        }
     
        int specType = Material.STONE_AXE.getId();
     
        int maxRemoveHeight = 128;
     
        List<Location> tempList = new ArrayList<Location>();
     
        @EventHandler
        public void onBreakBlock(BlockBreakEvent e)
        {
            Player p = (Player) e.getPlayer();
            Kit k = HungerGames.players.get(p.getName());
            int type = p.getItemInHand().getTypeId();
     
            if(type == specType)
            {
                if(k == Kit.Jackhammer)
                {
                    Block b = e.getBlock().getRelative(BlockFace.UP);
                    while(tempList.size() < maxRemoveHeight)
                    {
                        tempList.add(b.getLocation());
                        b = b.getRelative(BlockFace.UP);
                    }
                    if(tempList.size() == maxRemoveHeight)
                    {
                        for(int i = 0; i < maxRemoveHeight; i++)
                        {
                            final int no = i;
                            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
                            {
                                public void run()
                                {
                                 
                                    if(no == maxRemoveHeight)
                                    {
                                     
                                    }
                                }
     
                            }, i * 20);
                        }
                    }
                }
                else
                {
     
                }
            }
            else
            {
     
            }
        }
    }
    Then?....

    This post has been edited 1 time. It was last edited by CMG Jun 1, 2013.

Share This Page