get armor stand in radius...

Discussion in 'Plugin Development' started by kemalcik, Feb 27, 2022.

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

    kemalcik

    Hello. In my code, when I put a custom head on the ground, an armor stand is formed inside the glass. When I break that glass, I want the armor stand destroyed.

    Code:
        @SuppressWarnings("unlikely-arg-type")
        @EventHandler
        public void onBreakLB(BlockBreakEvent e) {
            Block b = (Block) e.getBlock();
            Player p = (Player) e.getPlayer();
            Material bt = b.getType();
           
            if(bt.equals(new ItemStack(Material.STAINED_GLASS, 1, (short)15))) {
               
            }
           
        }
    
     
  2. Offline

    Strahan

    That'll never work. The warning you are suppressing is trying to tell you it won't work. You're checking if a Material equals an ItemStack. What you need to do is check if bt == Material.STAINED_GLASS. Then you can check if it's black or not. Example:
    Code:
    @EventHandler
    public void onBreakLB(BlockBreakEvent e) {
      Block b = e.getBlock();
      Player p = e.getPlayer();
      Material bt = b.getType();
    
      if (bt != Material.STAINED_GLASS) return;
      if (b.getData() != DyeColor.BLACK.getData()) return;
    
      p.sendMessage("You broke black stained glass!");
    }
    Notice I removed the pointless casting on b and p. If a method returns the same type as your declaration, casting is superfluous. getData will bitch about being deprecated, but in 1.8 I do not believe there is an alternative. So in this case, suppressing a warning would be fine (deprecation). But normally, it's best to try to resolve what it's bitching about.
     
    kemalcik likes this.
  3. Offline

    kemalcik

    Thanks Close.
     
Thread Status:
Not open for further replies.

Share This Page