Need Help Destroying Blocks(Location Stuff)

Discussion in 'Plugin Development' started by jacz24, Dec 22, 2014.

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

    jacz24

    Hello, I am having some trouble I am having trouble destroying the blocks after they have been placed. What I am trying to do is every time the command is issued it deletes the previous instance but i'm not too sure how to find the previous instance. My theory's are that if I put the destroy code at the top before it gets the new coordinates it will work but I can't get b1 and b2. The other way I was thinking was making something that forces it to run when spawnchest command was issued again. That's why I am turning to you guys. Is this possible. Any help would be appreciated. I am going to sleep now so I will reply first thing in the morning.
    Code:
    if (commandLabel.equalsIgnoreCase("spawnchest"))
    
        {
          if ((sender instanceof Player))
          {
            Player player = ((Player)sender).getPlayer();
            if ((player.isOp()) || (player.hasPermission("treasure.spawnchest")))
            {
               
           
          
              int x = random.nextInt(maxX * 2 + 1) - maxX;
              int y = random.nextInt(maxY - 6) + 7;
              int z = random.nextInt(maxZ * 2 + 1) - maxZ;
              if (args.length > 0)
              {
                if (args[0] != null) {
                  x = Integer.parseInt(args[0]);
                }
                if (args[1] != null) {
                  y = Integer.parseInt(args[1]);
                }
                if (args[2] != null) {
                  z = Integer.parseInt(args[2]);
                }
              }
             
             
              Location loc = new Location(getServer().getWorld(world), x, y, z);
              World w = loc.getWorld();
              Block b1 = w.getBlockAt(loc);
             
              b1.setTypeId(54);
              loc.setY(loc.getY() - 1.0D);
              Block b2 = w.getBlockAt(loc);
             
              b2.setTypeId(block);
              Chest chest = (Chest)b1.getState();
             
              //chest.getBlock().setType(Material.AIR);
              updateLast10(ChatColor.RED + "x: " + ChatColor.AQUA + x + ChatColor.RED + " y: " + ChatColor.AQUA + y + ChatColor.RED + " z: " + ChatColor.AQUA + z);
              for (int i = 0; i < 10; i++) {
                if (random.nextInt(2) == 1)
                {
                  int itemArrayNum = random.nextInt(items.size());
                  ItemStack choice = new ItemStack(((Integer)items.get(itemArrayNum)).intValue(), random.nextInt(((Integer)stacks.get(itemArrayNum)).intValue()) + 1);
                  chest.getInventory().setItem(i, choice);
                }
              }
                     
              Bukkit.getServer().getScheduler().cancelTask(this.taskID);
             
              getServer().broadcastMessage(ChatColor.AQUA + "A MysteryChest has spawned! " + ChatColor.RED + "x: " + ChatColor.BLUE + x + ChatColor.RED + " y: " + ChatColor.BLUE + y + ChatColor.RED + " z: " + ChatColor.BLUE + z);
             
                  this.taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
                      {
                          @Override
                          public void run() {
                              Firework firework = (Firework) b1.getWorld().spawn(loc, Firework.class);
                            FireworkMeta meta = firework.getFireworkMeta();
                            FireworkEffect effect = FireworkEffect.builder()
                                    .flicker(true)
                                    .withColor(Color.MAROON)
                                    .withFade(Color.BLUE)
                                    .with(Type.STAR)
                                    .trail(true)
                                    .build();
                            meta.addEffect(effect);
                            meta.setPower(3);
                            firework.setFireworkMeta(meta);
                           
                          }
                      }, 0, 30);
                  b1.breakNaturally();//Breaks the Chest
                  b2.breakNaturally();//Breaks the Glowstone under the chest
                  }
           
            else
            {
              player.sendMessage("You don't have permission for that!");
            }
    Bump I really need help getting this work. Still haven't found a problem.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 28, 2016
Thread Status:
Not open for further replies.

Share This Page