public void run() {
   for (String s : lifewalkers.toArray(strArr)) {
     Player player = Bukkit.getServer().getPlayer(s);
     if (player != null) {
       if (isExpired(player)) {
         turnOff(player);
         continue;
       }
       Block feet = player.getLocation().getBlock();
       Block ground = feet.getRelative(BlockFace.DOWN);
       if (feet.getType() == Material.AIR
           && (ground.getType() == Material.DIRT || ground.getType() == Material.GRASS)) {
         if (ground.getType() == Material.DIRT) {
           ground.setType(Material.GRASS);
         }
         int rand = random.nextInt(100);
         if (rand < redFlowerChance) {
           feet.setType(Material.RED_ROSE);
           addUse(player);
           chargeUseCost(player);
         } else {
           rand -= redFlowerChance;
           if (rand < yellowFlowerChance) {
             feet.setType(Material.YELLOW_FLOWER);
             addUse(player);
             chargeUseCost(player);
           } else {
             rand -= yellowFlowerChance;
             if (rand < saplingChance) {
               feet.setType(Material.SAPLING);
               addUse(player);
               chargeUseCost(player);
             } else {
               rand -= saplingChance;
               if (rand < tallgrassChance) {
                 BlockState state = feet.getState();
                 state.setType(Material.LONG_GRASS);
                 state.setData(new LongGrass(GrassSpecies.NORMAL));
                 state.update(true);
                 addUse(player);
                 chargeUseCost(player);
               } else {
                 rand -= tallgrassChance;
                 if (rand < fernChance) {
                   BlockState state = feet.getState();
                   state.setType(Material.LONG_GRASS);
                   state.setData(new LongGrass(GrassSpecies.FERN_LIKE));
                   state.update(true);
                   addUse(player);
                   chargeUseCost(player);
                 }
               }
             }
           }
         }
       }
     }
   }
 }
  @HawkEvent(dataType = {DataType.LAVA_FLOW, DataType.WATER_FLOW})
  public void onBlockFromTo(BlockFromToEvent event) {
    List<Integer> fluidBlocks =
        Arrays.asList(
            0, 27, 28, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 69, 70, 75, 76, 78, 93, 94);

    Location loc = event.getToBlock().getLocation();
    BlockState from = event.getBlock().getState();
    BlockState to = event.getToBlock().getState();
    MaterialData data = from.getData();

    // Lava
    if (from.getTypeId() == 10 || from.getTypeId() == 11) {

      // Flowing into a normal block
      if (fluidBlocks.contains(to.getTypeId())) {
        data.setData((byte) (from.getRawData() + 1));
        from.setData(data);
      }

      // Flowing into water
      else if (to.getTypeId() == 8 || to.getTypeId() == 9) {
        from.setTypeId(event.getFace() == BlockFace.DOWN ? 10 : 4);
        data.setData((byte) 0);
        from.setData(data);
      }
      DataManager.addEntry(new BlockChangeEntry("Environment", DataType.LAVA_FLOW, loc, to, from));

    }

    // Water
    else if (from.getTypeId() == 8 || from.getTypeId() == 9) {

      // Normal block
      if (fluidBlocks.contains(to.getTypeId())) {
        data.setData((byte) (from.getRawData() + 1));
        from.setData(data);
        DataManager.addEntry(
            new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, to, from));
      }

      // If we are flowing over lava, cobble or obsidian will form
      BlockState lower = event.getToBlock().getRelative(BlockFace.DOWN).getState();
      if (lower.getTypeId() == 10 || lower.getTypeId() == 11) {
        from.setTypeId(lower.getData().getData() == 0 ? 49 : 4);
        loc.setY(loc.getY() - 1);
        DataManager.addEntry(
            new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, lower, from));
      }
    }
  }
 @Override
 public void setType(int x, int y, int z, Material type, MaterialData data) {
   BlockState block = world.getBlockAt(x, y, z).getState();
   block.setType(type);
   block.setData(data);
   block.update(true);
 }
Exemple #4
0
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.LOW)
  public void onBlockFade(BlockFadeEvent event) {
    Map map = Rixor.getRotation().getSlot().getMap();
    BlockState newState = event.getBlock().getState();
    newState.setData(new MaterialData(Material.AIR, (byte) 0));

    BlockChangeEvent change =
        new BlockChangeEvent(event, map, null, event.getBlock().getState(), newState);
    Rixor.callEvent(change);
  }
Exemple #5
0
 @SuppressWarnings("deprecation")
 @EventHandler(priority = EventPriority.LOW)
 public void onBlockPistonRetract(BlockPistonRetractEvent event) {
   Map map = Rixor.getRotation().getSlot().getMap();
   if (event.isSticky()) {
     BlockState state =
         event.getBlock().getWorld().getBlockAt(event.getRetractLocation()).getState();
     BlockState newState = state;
     newState.setData(new MaterialData(Material.AIR, (byte) 0));
     BlockChangeEvent change = new BlockChangeEvent(event, map, null, state, newState);
     Rixor.callEvent(change);
   }
 }
Exemple #6
0
 @SuppressWarnings("deprecation")
 @EventHandler(priority = EventPriority.LOW)
 public void onBlockPistonExtend(BlockPistonExtendEvent event) {
   Map map = Rixor.getRotation().getSlot().getMap();
   for (Block block : event.getBlocks()) {
     BlockState newState = block.getRelative(event.getDirection()).getState();
     newState.setData(new MaterialData(block.getType(), block.getData()));
     BlockChangeEvent change =
         new BlockChangeEvent(
             event, map, null, block.getRelative(event.getDirection()).getState(), newState);
     Rixor.callEvent(change);
   }
 }
  @Override
  public void placeBlock(
      GlowPlayer player,
      GlowBlockState state,
      BlockFace face,
      ItemStack holding,
      Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);

    MaterialData data = state.getData();
    if (data instanceof Chest) {
      Chest chest = (Chest) data;
      GlowBlock chestBlock = state.getBlock();

      BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);

      Collection<BlockFace> attachedChests = searchChests(chestBlock);
      if (attachedChests.isEmpty()) {
        chest.setFacingDirection(normalFacing);
        state.setData(chest);
        return;
      } else if (attachedChests.size() > 1) {
        GlowServer.logger.warning("Chest placed near two other chests!");
        return;
      }

      BlockFace otherPart = attachedChests.iterator().next();

      GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
      BlockState otherPartState = otherPartBlock.getState();
      MaterialData otherPartData = otherPartState.getData();

      if (otherPartData instanceof Chest) {
        Chest otherChest = (Chest) otherPartData;
        BlockFace facing =
            getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);

        chest.setFacingDirection(facing);
        state.setData(chest);

        otherChest.setFacingDirection(facing);
        otherPartState.setData(otherChest);
        otherPartState.update();
      } else {
        warnMaterialData(Chest.class, otherPartData);
      }
    } else {
      warnMaterialData(Chest.class, data);
    }
  }
Exemple #8
0
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.LOW)
  public void onBucketEmpty(PlayerBucketEmptyEvent event) {
    Player player = event.getPlayer();
    Client client = Client.getClient(player);
    Block block = event.getBlockClicked().getRelative(event.getBlockFace());
    Map map = Rixor.getRotation().getSlot().getMap();

    BlockState newState = block.getState();
    Material update = Material.LAVA;
    if (event.getBucket() == Material.WATER_BUCKET) update = Material.WATER;
    newState.setData(new MaterialData(update, (byte) 0));

    BlockState oldState = block.getState();
    BlockChangeEvent change = new BlockChangeEvent(event, map, client, oldState, newState);
    Rixor.callEvent(change);
  }
Exemple #9
0
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
  public void onEntityExplodeNormal(EntityExplodeEvent event) {
    Map map = Rixor.getRotation().getSlot().getMap();

    Client client = null;
    if (event.getEntity() instanceof TNTPrimed) {
      TNTPrimed tnt = (TNTPrimed) event.getEntity();
      if (tnt.getSource() instanceof Player) client = Client.getClient((Player) tnt.getSource());
    }

    for (Block block : event.blockList()) {
      BlockState newState = block.getState();
      newState.setData(new MaterialData(Material.AIR, (byte) 0));
      BlockChangeEvent change =
          new BlockChangeEvent(event, map, client, block.getState(), newState);
      Rixor.callEvent(change);
    }
  }
  public boolean createRandomItemsContainer(
      Vector pos,
      Random random,
      RandomItemsContent content,
      DirectionalContainer container,
      int maxStacks) {
    Vector vec = translate(pos);
    if (boundingBox.isVectorInside(vec)) {
      BlockState state =
          world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
      delegate.backupBlockState(state.getBlock());

      state.setType(container.getItemType());
      state.setData(container);
      state.update(true);

      return content.fillContainer(random, container, state, maxStacks);
    }
    return false;
  }
Exemple #11
0
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.LOW)
  public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    Client client = Client.getClient(player);

    if (client.isObserver() || !Rixor.getRotation().getSlot().getMatch().isCurrentlyRunning()) {
      event.setCancelled(true);
      return;
    }

    if (!client.isObserver()) {
      Map map = Rixor.getRotation().getSlot().getMap();

      BlockState newState = event.getBlock().getState();
      newState.setData(new MaterialData(Material.AIR, (byte) 0));

      BlockChangeEvent change =
          new BlockChangeEvent(event, map, client, event.getBlock().getState(), newState);
      Rixor.callEvent(change);
    }
  }
Exemple #12
0
 /** Changes block to its state before change. */
 public void applyRollback() {
   BlockState state = this.blockLocation.getBlock().getState();
   state.setType(this.oldMaterial);
   state.setData(this.oldMaterialData);
   state.update(true, false); // Do not apply physics on rollbacks.
 }
  @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);
      }
    }
  }