PlayerFishEvent get block

Discussion in 'Spigot Plugin Help' started by Newpredator, Jun 27, 2018.

  1. Is it possible to get the block that I hooked with the fishing rod?
     
  2. PlayerFishEvent.getCaught() returns the caught entity (which is a dropped block). Get the data from that and create a Material with that data I guess.
     
  3. yeah but I mean blocks in the ground, State.IN_GROUND
     
  4. Like a placed block?
     
  5. Yeah so Im doing a grappling hook plugin and I want to ban some blocks for this hook
     
  6. Oh wait you want to get the block that the hook is touching! I understood you the wrong way. Let me look into that.
     
    • Useful Useful x 1
  7. Ok I´ll try, thx for the info bro
     
    • Friendly Friendly x 1
  8. Just another easy question

    Code (Text):
        @SuppressWarnings("unlikely-arg-type")
        @EventHandler
        public void FishOnTheGround(ProjectileHitEvent e) {
            if(e.getEntityType().equals(EntityType.FISHING_HOOK)) {
                ((Player) e.getEntity().getShooter()).sendMessage("a");
                 this.blockedItemsString = Survival.getPlugin().getConfig().getStringList("Hook-Blocked-Blocks").toUpperCase();
                  for (String current : blockedItemsString) {
                        try {
                            blockedItems.add(Material.getMaterial(current.trim()));
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                  }
                if(!e.getHitBlock().getType().equals(blockedItems)) {
                    ((Player) e.getEntity().getShooter()).sendMessage("C");
                    return;
                }
                ((Player) e.getEntity().getShooter()).sendMessage("d");
                e.getEntity().remove();
            }
        }
        }
     
    Code (Text):
        private List<String> blockedItemsString;
        private List<Material> blockedItems = new ArrayList<Material>();
    Code (Text):
    Hook-Blocked-Blocks:
      - ender_stone
      - cobblestone
    It dont work for me. Is it wrong?
     
  9. Do you receive any errors?
     
    • Friendly Friendly x 1
  10. You use
    Code (Java):
    Material.equals(List<Material>)
    You should use
    Code (Text):
    List<Material>.contains(Material)
     
    • Useful Useful x 1
  11. Also in the Material.getMaterial(x) method, x should be .toUpperCase.
     
    • Useful Useful x 1
  12. Code (Text):

    @EventHandler
            public void FishOnTheGround(ProjectileHitEvent e) {
                if(e.getEntityType().equals(EntityType.FISHING_HOOK)) {
                     this.blockedItemsString = Survival.getPlugin().getConfig().getStringList("Hook-Blocked-Blocks");
                      for (String current : blockedItemsString) {
                            try {
                                blockedItems.add(Material.getMaterial(current.trim().toUpperCase()));
                            } catch (Exception ex) {
                                ex.printStackTrace();
                            }
                      }
                    if(!blockedItems.contains(e.getHitBlock().getType())) {
                        return;
                    }
                    e.getEntity().remove();
                }
            }
     
    Working... Thx to all
     
    #13 Newpredator, Jun 28, 2018
    Last edited: Jun 28, 2018
    • Winner Winner x 1