@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);
 }
  @Override
  public void run() {
    if (master.contchunks.isEmpty()) return;

    World world = master.team.getMatch().getWorld();
    Location loc = new Location(world, 0, 0, 0);
    Set<BlockData> goals = master.searching;
    for (int i = 0; i < 15; i++) // 15 chunks per run
    {
      Vector vec = master.entitychunks.poll();
      if (vec == null) {
        this.cancel();
        return;
      }
      BlockState[] containers =
          world
              .getChunkAt(vec.getBlockX(), vec.getBlockZ())
              .getTileEntities(); // actually chunk-coords

      for (BlockState state : containers) {
        if (state instanceof InventoryHolder) {
          Inventory inv = ((InventoryHolder) state).getInventory();
          if (state instanceof Chest) inv = ((Chest) state).getBlockInventory();
          checkInventory(inv, goals, state.getLocation(loc));
        }
        // TODO: spawners
      }
    }
  }
  /** BlockFadeEvent */
  public static BlockFadeEvent callBlockFadeEvent(Block block, int type) {
    BlockState state = block.getState();
    state.setTypeId(type);

    BlockFadeEvent event = new BlockFadeEvent(block, state);
    Bukkit.getPluginManager().callEvent(event);
    return event;
  }
  /** Drop the corresponding items on the ground. */
  @Override
  public void drop() {
    Location loc = blockState.getBlock().getLocation();
    World w = loc.getWorld();

    Collection<ItemStack> drop = blockState.getBlock().getDrops();
    for (ItemStack s : drop) w.dropItemNaturally(loc, s);
  }
Beispiel #5
0
 /**
  * Checks if the object corresponds to provided parameters
  *
  * @param block Block to compare to
  * @return <b>true</b> if the conditions are met, <b>false</b> otherwise
  */
 public boolean equals(BlockState block) {
   if (ItemsWithMetadata.checkAgainst(block.getTypeId())) {
     return block.getType().equals(this.block.getType())
         && block.getData().getData() == this.block.getData().getData();
   } else {
     return block.getType().equals(this.block.getType());
   }
 }
Beispiel #6
0
 /*
  * Установка блока с проверкой на приват
  */
 public boolean placeBlock(Block block, Player p, Material newType, byte newData, boolean phys) {
   BlockState state = block.getState();
   block.setTypeIdAndData(newType.getId(), newData, phys);
   BlockPlaceEvent event =
       new BlockPlaceEvent(state.getBlock(), state, block, p.getItemInHand(), p, true);
   plg.getServer().getPluginManager().callEvent(event);
   if (event.isCancelled()) state.update(true);
   return event.isCancelled();
 }
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onBlockForm(final BlockFormEvent event) {
   final Block b = event.getBlock();
   if (isLogging(b.getWorld(), Logging.SNOWFORM)) {
     final BlockState n = event.getNewState();
     final int type = n.getTypeId();
     if (type == 78 || type == 79) consumer.queueBlockReplace("SnowForm", b.getState(), n);
   }
 }
 private static BlockFace getAttachedFace(Block lever) {
   BlockState state = lever.getState();
   MaterialData md = state.getData();
   if (md instanceof Attachable) {
     BlockFace face = ((Attachable) md).getAttachedFace();
     return face.getOppositeFace();
   } else {
     return null;
   }
 }
  public void a(World world, int i, int j, int k, Random random) {
    if (random.nextInt(25) == 0) {
      byte b0 = 4;
      int l = 5;

      int i1;
      int j1;
      int k1;

      for (i1 = i - b0; i1 <= i + b0; ++i1) {
        for (j1 = k - b0; j1 <= k + b0; ++j1) {
          for (k1 = j - 1; k1 <= j + 1; ++k1) {
            if (world.getTypeId(i1, k1, j1) == this.id) {
              --l;
              if (l <= 0) {
                return;
              }
            }
          }
        }
      }

      i1 = i + random.nextInt(3) - 1;
      j1 = j + random.nextInt(2) - random.nextInt(2);
      k1 = k + random.nextInt(3) - 1;

      for (int l1 = 0; l1 < 4; ++l1) {
        if (world.isEmpty(i1, j1, k1) && this.f(world, i1, j1, k1)) {
          i = i1;
          j = j1;
          k = k1;
        }

        i1 = i + random.nextInt(3) - 1;
        j1 = j + random.nextInt(2) - random.nextInt(2);
        k1 = k + random.nextInt(3) - 1;
      }

      if (world.isEmpty(i1, j1, k1) && this.f(world, i1, j1, k1)) {
        // lightstone start
        org.bukkit.World bworld = world.getWorld();
        org.bukkit.block.BlockState blockState = bworld.getBlockAt(i1, j1, k1).getState();
        blockState.setTypeId(this.id);

        BlockSpreadEvent event =
            new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(i, j, k), blockState);
        world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
          blockState.update(true);
        }
        // lightstone end
      }
    }
  }
  @Override
  public void run() {
    BlockState tmp_state = block.getState();

    block.setType(type); // set the block to tnt

    List<BlockState> list = cEx.getBlockList();
    list.add(block.getState()); // record it

    tmp_state.update(true); // set it back to what it was
  }
Beispiel #11
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);
  }
Beispiel #12
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);
   }
 }
  /** Detect when pistons affect water or sensor components. PISTONS MAH BOI! */
  @EventHandler
  public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    if (event.isCancelled()) return;

    // Get the block just at the end of the piston chain (that will be replaced when the chain is
    // pushed)
    Block endblock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1);
    BlockState b = endblock.getState();
    plugin.debugprint("Block at end of piston chain " + b.getType());
    if (plugin.isBlockStateAnUpdater(b)) {
      plugin.executeSensorsAroundBlock(b, true, event);
    }
  }
Beispiel #14
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);
   }
 }
  @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);
    }
  }
 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);
                 }
               }
             }
           }
         }
       }
     }
   }
 }
  /**
   * Process the Hylian Luck ability.
   *
   * @param blockState The {@link BlockState} to check ability activation for
   * @return true if the ability was successful, false otherwise
   */
  public boolean processHylianLuck(BlockState blockState) {
    if (!SkillUtils.activationSuccessful(
        SecondaryAbility.HYLIAN_LUCK, getPlayer(), getSkillLevel(), activationChance)) {
      return false;
    }

    List<HylianTreasure> treasures;

    switch (blockState.getType()) {
      case DEAD_BUSH:
      case LONG_GRASS:
      case SAPLING:
        treasures = TreasureConfig.getInstance().hylianFromBushes;
        break;

      case RED_ROSE:
      case YELLOW_FLOWER:
        if (mcMMO.getPlaceStore().isTrue(blockState)) {
          mcMMO.getPlaceStore().setFalse(blockState);
          return false;
        }

        treasures = TreasureConfig.getInstance().hylianFromFlowers;
        break;

      case FLOWER_POT:
        treasures = TreasureConfig.getInstance().hylianFromPots;
        break;

      default:
        return false;
    }

    Player player = getPlayer();

    if (treasures.isEmpty()
        || !EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) {
      return false;
    }

    blockState.setType(Material.AIR);

    Misc.dropItem(
        blockState.getLocation(),
        treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
    player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
    return true;
  }
 public static boolean isPlotWorld(final BlockState b) {
   if (b == null) {
     return false;
   } else {
     return AthionPlots.AthionMaps.containsKey(b.getWorld().getName().toLowerCase());
   }
 }
  /** Block place methods */
  public static BlockPlaceEvent callBlockPlaceEvent(
      World world,
      EntityPlayerMP who,
      BlockState replacedBlockState,
      int clickedX,
      int clickedY,
      int clickedZ) {
    BukkitWorld craftWorld =
        (BukkitWorld)
            Bukkit.getServer().getWorld(((WorldServer) world).getWorldInfo().getWorldName());
    BukkitServer craftServer = (BukkitServer) Bukkit.getServer();

    Player player = (who == null) ? null : (Player) BukkitEntity.getEntity(craftServer, who);

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    Block placedBlock = replacedBlockState.getBlock();

    boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());

    BlockPlaceEvent event =
        new BlockPlaceEvent(
            placedBlock,
            replacedBlockState,
            blockClicked,
            player.getItemInHand(),
            player,
            canBuild);
    craftServer.getPluginManager().callEvent(event);

    return event;
  }
Beispiel #20
0
  /**
   * Check if a given block should allow for the activation of abilities
   *
   * @param blockState The {@link BlockState} of the block to check
   * @return true if the block should allow ability activation, false otherwise
   */
  public static boolean canActivateAbilities(BlockState blockState) {
    switch (blockState.getType()) {
      case BED_BLOCK:
      case BREWING_STAND:
      case BOOKSHELF:
      case BURNING_FURNACE:
      case CAKE_BLOCK:
      case CHEST:
      case DISPENSER:
      case ENCHANTMENT_TABLE:
      case ENDER_CHEST:
      case FENCE_GATE:
      case FURNACE:
      case IRON_DOOR_BLOCK:
      case JUKEBOX:
      case LEVER:
      case NOTE_BLOCK:
      case STONE_BUTTON:
      case WOOD_BUTTON:
      case TRAP_DOOR:
      case WALL_SIGN:
      case WOODEN_DOOR:
      case WORKBENCH:
      case BEACON:
      case ANVIL:
      case DROPPER:
      case HOPPER:
      case TRAPPED_CHEST:
        return false;

      default:
        return true;
    }
  }
  public void createMobSpawner(Vector pos, EntityType entityType) {
    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(Material.MOB_SPAWNER);
      state.update(true);

      state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
      if (state instanceof CreatureSpawner) {
        ((CreatureSpawner) state).setSpawnedType(entityType);
      }
    }
  }
Beispiel #22
0
  /**
   * Check if a block is affected by this ability.
   *
   * @param blockState the block to check
   * @return true if the block is affected by this ability, false otherwise
   */
  public boolean blockCheck(BlockState blockState) {
    switch (this) {
      case BERSERK:
        return (BlockUtils.affectedByGigaDrillBreaker(blockState)
            || blockState.getType() == Material.SNOW);

      case BLOCK_CRACKER:
        return BlockUtils.affectedByBlockCracker(blockState);

      case GIGA_DRILL_BREAKER:
        return BlockUtils.affectedByGigaDrillBreaker(blockState);

      case GREEN_TERRA:
        return BlockUtils.canMakeMossy(blockState);

      case LEAF_BLOWER:
        return BlockUtils.isLeaves(blockState);

      case SUPER_BREAKER:
        return BlockUtils.affectedBySuperBreaker(blockState);

      case TREE_FELLER:
        return BlockUtils.isLog(blockState);

      default:
        return false;
    }
  }
  public boolean canGreenThumbBlock(BlockState blockState) {
    Player player = getPlayer();

    return player.getItemInHand().getType() == Material.SEEDS
        && BlockUtils.canMakeMossy(blockState)
        && Permissions.greenThumbBlock(player, blockState.getType());
  }
Beispiel #24
0
  private Block getBlock(final Material material, final TreeSpecies type) {
    // TODO correct this once new trees are implemented correctly
    BlockState state = Mockito.mock(BlockState.class);
    if (material == Material.LOG_2) {
      Mockito.when(state.getData())
          .thenReturn(new MaterialData(material, (byte) (type.getData() - 4)));
    } else {
      Mockito.when(state.getData()).thenReturn(new Tree(type));
    }

    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getType()).thenReturn(material);
    Mockito.when(block.getState()).thenReturn(state);
    Mockito.when(block.getWorld()).thenReturn(null);

    return block;
  }
Beispiel #25
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);
  }
  private int HolderStateToInventory(PrisonPearl pp, Inventory inv[]) {
    if (pp == null || inv == null) {
      return HolderStateToInventory_BADPARAM;
    }
    BlockState inherentViolence = pp.getHolderBlockState();
    //		if (Bukkit.getPluginManager().isPluginEnabled("EnderExpansion")){
    //			if (pp.getLocation().getBlock().getType() == Material.ENDER_CHEST){
    //				inv[0] = Enderplugin.getchestInventory(pp.getLocation());
    //				return HolderStateToInventory_SUCCESS;
    //			}
    //		}
    if (inherentViolence == null) {
      return HolderStateToInventory_NULLSTATE;
    }
    Material mat = inherentViolence.getType();

    switch (mat) {
      case FURNACE:
        inv[0] = ((Furnace) inherentViolence).getInventory();
        break;
      case DISPENSER:
        inv[0] = ((Dispenser) inherentViolence).getInventory();
        break;
      case BREWING_STAND:
        inv[0] = ((BrewingStand) inherentViolence).getInventory();
        break;
      case CHEST:
      case TRAPPED_CHEST:
        Chest c = ((Chest) inherentViolence);
        DoubleChestInventory dblInv = null;
        try {
          dblInv = (DoubleChestInventory) c.getInventory();
          inv[0] = dblInv.getLeftSide();
          inv[1] = dblInv.getRightSide();
        } catch (Exception e) {
          inv[0] = c.getInventory();
        }
        break;
      default:
        return HolderStateToInventory_BADCONTAINER;
    }
    if (inv[0] == null && inv[1] == null) {
      return HolderStateToInventory_NULLINV;
    }
    return HolderStateToInventory_SUCCESS;
  }
Beispiel #27
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);
    }
  }
 /**
  * Get the face a blockState is dependent on.
  *
  * @param blockState The blockState.
  * @return The face the blockState i s attached by.
  */
 public static BlockFace getAttachingFace(BlockState blockState) {
   if (blockState.getData() instanceof Attachable)
     return ((Attachable) blockState.getData()).getAttachedFace();
   if (blockState instanceof Rails)
     switch (blockState.getRawData()) {
       case 5:
         return BlockFace.WEST;
       case 4:
         return BlockFace.EAST;
       case 3:
         return BlockFace.NORTH;
       case 2:
         return BlockFace.SOUTH;
       default:
         return BlockFace.DOWN;
     }
   if (DEPENDENT_DOWN_BLOCKS.contains(blockState.getTypeId())) return BlockFace.DOWN;
   return BlockFace.SELF;
 }
  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;
  }
 @Override
 public void run() {
   if (active) {
     if (!fInit) {
       fInit = true;
     }
     int lRadius = fRadius;
     int lDy = 0;
     switch (mode) {
       case Down:
         lDy = -1;
         break;
       case Up:
         lDy = 1;
         break;
     }
     Logger.getLogger("LandSlip").info("strength " + new Integer(fStrength));
     for (int dx = -lRadius; dx <= lRadius; dx++) {
       for (int dz = -lRadius; dz <= lRadius; dz++) {
         Block lBlock = world.getHighestBlockAt(x + dx, z + dz);
         lBlock = lBlock.getLocation().add(0, -1, 0).getBlock();
         BlockState lState = lBlock.getState();
         Location lTo = lBlock.getLocation().add(0, lDy, 0);
         plugin.setTypeAndData(lTo, lState.getType(), lState.getRawData(), true);
         // if (mode == Mode.Down) {
         plugin.setTypeAndData(lBlock.getLocation(), Material.AIR, (byte) 0, false);
         // }
       }
     }
     fRadius++;
     if (fRadius > radius) {
       fRadius = 0;
       fStrength++;
       if (fStrength >= strength) {
         Logger.getLogger("LandSlip").info("stopped");
         plugin.getServer().getScheduler().cancelTask(taskId);
       }
     }
   }
 }