Smiting plugin fire at blocks over 100 blocks away

Discussion in 'Plugin Development' started by Teddinator, May 4, 2014.

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

    Teddinator

    So basically my plugin is supposed to smite objects that aren't over blocks away, and aren't null. But for some reason, it is smiting at blocks over 100 blocks away, when they aren't null. Any help?

    Here is my code:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @Override
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    4. Player player = (Player) sender;
    5. if (sender instanceof Player) {
    6. if (player.hasPermission("target.smite") && label.equalsIgnoreCase("smiteblock")) {
    7. Block targetBlock = player.getTargetBlock(null, 100);
    8. Location playerLocation = player.getLocation();
    9. if (targetBlock.getLocation().distance(playerLocation) < 100 && targetBlock.getLocation().getBlock() != null) {
    10. targetBlock.getWorld().strikeLightning(targetBlock.getLocation());
    11. player.sendMessage(ChatColor.GOLD + "Excellent smite " + ChatColor.ITALIC + player.getName());
    12. return true;
    13. }
    14. if (targetBlock.getLocation().distance(playerLocation) > 100 && targetBlock.getLocation().getBlock() != null
    15. || targetBlock.getLocation().distance(playerLocation) > 100 && targetBlock.getLocation().getBlock() == null
    16. || targetBlock.getLocation().distance(playerLocation) < 100 && targetBlock.getLocation().getBlock() == null) {
    17. player.sendMessage(ChatColor.RED + "Are striking within a 100 block radius? Try again...");
    18. return true;
    19. }
    20. }
    21. }
    22. return false;
    23. }
     
  2. Offline

    hugokk

    Didn't test it, but this might work:
    Code:java
    1. if (targetBlock != null && targetBlock.getLocation().distance(playerLocation) < 100) {
    2. targetBlock.getWorld().strikeLightning(targetBlock.getLocation());
    3. player.sendMessage(ChatColor.GOLD + "Excellent smite " + ChatColor.ITALIC + player.getName());
    4. return true;
    5. }
    6. else
    7. {
    8. player.sendMessage(ChatColor.RED + "Are striking within a 100 block radius? Try again...");
    9. return true;
    10. }
     
  3. Offline

    Teddinator

    Thanks, but I just figured it out. It was actually quite similar method to yours. Thread closed. :)
     
Thread Status:
Not open for further replies.

Share This Page