Simple code doesn't work

Discussion in 'Plugin Development' started by lolcoder, May 6, 2011.

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


    This should break an area of 10x10 blocks, but it does work only sometime. I can't get the drops and sometimes the client crash (without errors on the server).

    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.inventory.ItemStack;
    public class tpBlockListener extends BlockListener {
        public static tp plugin;
        public tpBlockListener(tp instance) {
            plugin = instance;
        public void onBlockBreak(BlockBreakEvent event){
            Block block = event.getBlock();
            Player player = event.getPlayer();
            if(player.getName().endsWith("arrior")) {
                World w = player.getWorld();
                Block b;
                for(int i = 0; i < 10; i++) {
                    for(int j = 0; j < 10; j++) {
                        b = w.getBlockAt(block.getX() + i, block.getY(), block.getZ() + j);
                        if(b.getX() != block.getX()) {
                            int t = b.getTypeId();
                            w.dropItem(b.getLocation(), new ItemStack(t));


    And In the main file I have:

        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if (commandLabel.equalsIgnoreCase("tppos")) {
                Location loc = player.getLocation();
                player.sendMessage("You are located at:" + loc.getX() + "," + loc.getY() + "," + loc.getZ());
                return true;
            return false;
    But it doesn't do nothing, it just display that the command doesn't exist.

    Sorry for my bad english.
  2. Offline


    You're trying to drop air. Dropping air causes client crashes.
  3. Offline



    You have to register the command in plugin.yml

        usage: /<command>
        description: 'Show your coordinates'
    @nisovin Where is he dropping air? He is saving the blocks material in a new ItemStack, and dropping it at the original location after setting the block there to air.. No Problems :)
  4. Offline


    @Deathly But what if it was air in the first place? Then he'll be dropping an item stack of air.
  5. Offline


    @nisovin But if it was already air, then the event wouldnt get called.. ok it depends on the priority he registered it as..

    @lolcoder Add an additional check to prevent dropping air :)
  6. Offline


    @Deathly He's manually removing and dropping all blocks near the block broken. Any of those blocks could be air, and he's not checking for that. Thus, he's dropping air.
  7. Offline


    Ah right.. yeah.. well just add the check :D
  8. Offline


    Now it works, but... when i get the drop, for example sand, the number of sand in my inventory is still 1.
  9. Offline


    Because you drop itemstacks that have 0 amount.
  10. Offline


    @Acrobot: Thank you, now it works.
Thread Status:
Not open for further replies.

Share This Page