Ejemplo n.º 1
0
 public static Snitch getSnitchUnderCursor(Player player) {
   SnitchManager manager = JukeAlert.getInstance().getSnitchManager();
   List<Block> lastTwo = player.getLastTwoTargetBlocks(null, 64);
   for (Block block : lastTwo) {
     Material mat = block.getType();
     if (mat != Material.JUKEBOX) {
       continue;
     }
     Snitch found = manager.getSnitch(block.getWorld(), block.getLocation());
     if (found != null) {
       return found;
     }
   }
   return null;
 }
Ejemplo n.º 2
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent event) {

    if (event.getAction() == Action.PHYSICAL) {
      return;
    }

    int mode = 0;
    Player player = event.getPlayer();
    Stick stick = null;

    stick = plugin.getStick(player);

    mode = stick.getMode();

    if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
      if (player.getGameMode() == GameMode.CREATIVE && stick.isEnabled()) {
        event.setCancelled(true);
      }
      return;
    }

    if (event.getAction() == Action.RIGHT_CLICK_BLOCK
        && stick.isThrowBuild()
        && player.getItemInHand().getType() != stick.getTool()) {
      return;
    }

    if (!stick.doRightClickModes()
        && (event.getAction() == Action.RIGHT_CLICK_AIR
            || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
      mode = Stick.REMOVE_MODE;
    }

    if (plugin.canUse(player, stick, mode)) {

      event.setCancelled(true);

      List<Block> targetBlocks =
          player.getLastTwoTargetBlocks(stick.getIgnore(), stick.getDistance());

      // sanity check
      if (targetBlocks.size() != 2) {
        plugin.log(Level.WARNING, "Did not get two blocks to work with");
        return;
      }

      Block targetedBlock = null;
      Block placedAgainstBlock = null;

      Item item = stick.getItem();

      if (!item.isBlock()) {
        item = MaterialUtils.getPlaceableMaterial(item);
        if (!item.isBlock()) {
          if (!stick.isThrowBuild()) {
            MessageUtils.send(player, ChatColor.RED, "Invalid item usage.");
          } else {
            event.setCancelled(false);
          }
          return;
        }
      }

      BlockEvent actionEvent = null;

      if (mode == Stick.REPLACE_MODE || mode == Stick.REMOVE_MODE) {
        targetedBlock = targetBlocks.get(1);
        placedAgainstBlock = targetBlocks.get(0);
      } else if (mode == Stick.BUILD_MODE) {
        targetedBlock = targetBlocks.get(0);
        placedAgainstBlock = targetBlocks.get(1);
      }

      if (targetedBlock.getLocation().getBlockY() == 0 && stick.doProtectBottom()) {
        plugin.log(Level.WARNING, "Player " + player.getDisplayName() + " hit rock bottom!");
        return;
      }

      if (LocationUtil.isSameLocation(player, targetedBlock)) {
        if (stick.isDebug()) {
          MessageUtils.send(player, "** boink **");
        }

        return;
      }

      BlockState after = targetedBlock.getState();
      after.setType(mode == Stick.REMOVE_MODE ? Material.AIR : item.getMaterial());

      MaterialData data = null;
      if (mode == Stick.REMOVE_MODE) {
        data = Material.AIR.getNewData((byte) 0);
      } else if (MaterialUtils.isSameMaterial(item.getMaterial(), Material.LADDER)) {
        BlockFace face = LocationUtil.getFace(player, targetedBlock);
        if (stick.isDebug()) {
          MessageUtils.send(player, "clicked " + face + " face! (" + player.getEyeLocation() + ")");
        }

        Ladder ladder = new Ladder();
        ladder.setFacingDirection(face);
        data = ladder;

      } else {
        data = item.getData();
      }

      if (data != null) after.setData(data);

      BlockState before = targetedBlock.getState();
      if (mode == Stick.REMOVE_MODE) {
        stick.setDoItemSwitch(true);
        actionEvent = new BlockBreakEvent(targetedBlock, player);
      } else if (MaterialUtils.isSameMaterial(item.getMaterial(), Material.FIRE)) {
        actionEvent = new BlockIgniteEvent(targetedBlock, IgniteCause.FLINT_AND_STEEL, player);
      } else {
        actionEvent =
            new BlockPlaceEvent(
                after.getBlock(),
                before,
                placedAgainstBlock,
                new ItemStack(stick.getTool()),
                player,
                true);
      }

      plugin.getServer().getPluginManager().callEvent(actionEvent);

      if (!((Cancellable) actionEvent).isCancelled()) {
        plugin.takeAction(before, after, player);
      }
    }
  }
Ejemplo n.º 3
0
 @Override
 public List<Block> getLastTwoTargetBlocks(HashSet<Byte> transparent, int maxDistance) {
   return caller.getLastTwoTargetBlocks(transparent, maxDistance);
 }
Ejemplo n.º 4
0
 private BlockFace getClickedFace(Player player) {
   List<Block> blocks = player.getLastTwoTargetBlocks((Set<Material>) null, 30);
   return blocks.get(0).getFace(blocks.get(1));
 }