コード例 #1
0
  @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));
      }
    }
  }
コード例 #2
0
 @Override
 public void toggleLeverOrButton(Block block) {
   if (block.getType() == Material.STONE_BUTTON || block.getType() == Material.WOOD_BUTTON) {
     BlockState state = block.getState();
     Button button = (Button) state.getData();
     button.setPowered(true);
     state.update();
   } else if (block.getType() == Material.LEVER) {
     BlockState state = block.getState();
     Lever lever = (Lever) state.getData();
     lever.setPowered(!lever.isPowered());
     state.update();
   }
 }
コード例 #3
0
ファイル: WoodCuttingTest.java プロジェクト: cryxli/ExpCraft
  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;
  }
コード例 #4
0
ファイル: BlocksData.java プロジェクト: kajar9/Plugin
 /**
  * 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());
   }
 }
コード例 #5
0
 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;
   }
 }
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
  @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);
    }
  }
コード例 #8
0
  private boolean handleBlockState(BlockState blockState, boolean greenTerra) {
    byte greenThumbStage = getGreenThumbStage();

    switch (blockState.getType()) {
      case CROPS:
        Crops crops = (Crops) blockState.getData();

        if (greenTerra) {
          crops.setState(CropState.MEDIUM);
        } else {
          switch (greenThumbStage) {
            case 4:
              crops.setState(CropState.SMALL);
              break;
            case 3:
              crops.setState(CropState.VERY_SMALL);
              break;
            case 2:
              crops.setState(CropState.GERMINATED);
              break;
            default:
              crops.setState(CropState.SEEDED);
              break;
          }
        }

        return true;

      case CARROT:
      case POTATO:
        if (greenTerra) {
          blockState.setRawData(CropState.MEDIUM.getData());
        } else {
          blockState.setRawData(greenThumbStage);
        }

        return true;

      case NETHER_WARTS:
        NetherWarts warts = (NetherWarts) blockState.getData();

        if (greenTerra || greenThumbStage > 2) {
          warts.setState(NetherWartsState.STAGE_TWO);
        } else if (greenThumbStage == 2) {
          warts.setState(NetherWartsState.STAGE_ONE);
        } else {
          warts.setState(NetherWartsState.SEEDED);
        }

        return true;

      case COCOA:
        CocoaPlant plant = (CocoaPlant) blockState.getData();

        if (greenTerra || getGreenThumbStage() > 1) {
          plant.setSize(CocoaPlantSize.MEDIUM);
        } else {
          plant.setSize(CocoaPlantSize.SMALL);
        }

        return true;

      default:
        return false;
    }
  }
コード例 #9
0
ファイル: LoggingUtil.java プロジェクト: Cube-Nation/LogBlock
  public static void smartLogBlockBreak(Consumer consumer, String playerName, Block origin) {

    WorldConfig wcfg = getWorldConfig(origin.getWorld());
    if (wcfg == null) return;

    Block checkBlock = origin.getRelative(BlockFace.UP);
    if (BukkitUtils.getRelativeTopBreakabls().contains(checkBlock.getType())) {
      if (wcfg.isLogging(Logging.SIGNTEXT) && checkBlock.getType() == Material.SIGN_POST) {
        consumer.queueSignBreak(playerName, (Sign) checkBlock.getState());
      } else if (checkBlock.getType() == Material.IRON_DOOR
          || checkBlock.getType() == Material.WOOD_DOOR) {
        Block doorBlock = checkBlock;
        // If the doorBlock is the top half a door the player simply punched a door
        // this will be handled later.
        if (doorBlock.getData() != 8 && doorBlock.getData() != 9) {
          doorBlock = doorBlock.getRelative(BlockFace.UP);
          // Fall back check just in case the top half wasn't a door
          if (doorBlock.getType() == Material.IRON_DOOR
              || doorBlock.getType() == Material.WOOD_DOOR) {
            consumer.queueBlockBreak(playerName, doorBlock.getState());
          }
          consumer.queueBlockBreak(playerName, checkBlock.getState());
        }
      } else {
        consumer.queueBlockBreak(playerName, checkBlock.getState());
      }
    }

    List<Location> relativeBreakables =
        BukkitUtils.getBlocksNearby(origin, BukkitUtils.getRelativeBreakables());
    if (relativeBreakables.size() != 0) {
      for (Location location : relativeBreakables) {
        final Material blockType = location.getBlock().getType();
        final BlockState blockState = location.getBlock().getState();
        final MaterialData data = blockState.getData();
        switch (blockType) {
          case REDSTONE_TORCH_ON:
          case REDSTONE_TORCH_OFF:
            if (blockState
                .getBlock()
                .getRelative(((RedstoneTorch) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case TORCH:
            if (blockState
                .getBlock()
                .getRelative(((Torch) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case COCOA:
            if (blockState
                .getBlock()
                .getRelative(((CocoaPlant) data).getAttachedFace().getOppositeFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case LADDER:
            if (blockState
                .getBlock()
                .getRelative(((Ladder) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case LEVER:
            if (blockState
                .getBlock()
                .getRelative(((Lever) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case TRIPWIRE_HOOK:
            if (blockState
                .getBlock()
                .getRelative(((TripwireHook) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case WOOD_BUTTON:
          case STONE_BUTTON:
            if (blockState
                .getBlock()
                .getRelative(((Button) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case WALL_SIGN:
            if (blockState
                .getBlock()
                .getRelative(((org.bukkit.material.Sign) data).getAttachedFace())
                .equals(origin)) {
              if (wcfg.isLogging(Logging.SIGNTEXT)) {
                consumer.queueSignBreak(playerName, (Sign) blockState);
              } else {
                consumer.queueBlockBreak(playerName, blockState);
              }
            }
            break;
          case TRAP_DOOR:
            if (blockState
                .getBlock()
                .getRelative(((TrapDoor) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          default:
            consumer.queueBlockBreak(playerName, blockState);
            break;
        }
      }
    }

    // Special door check
    if (origin.getType() == Material.IRON_DOOR || origin.getType() == Material.WOOD_DOOR) {
      Block doorBlock = origin;

      // Up or down?
      if (origin.getData() != 8 && origin.getData() != 9) {
        doorBlock = doorBlock.getRelative(BlockFace.UP);
      } else {
        doorBlock = doorBlock.getRelative(BlockFace.DOWN);
      }

      if (doorBlock.getType() == Material.IRON_DOOR || doorBlock.getType() == Material.WOOD_DOOR) {
        consumer.queueBlockBreak(playerName, doorBlock.getState());
      }
    }

    // Do this down here so that the block is added after blocks sitting on it
    consumer.queueBlockBreak(playerName, origin.getState());
  }
コード例 #10
0
ファイル: LoggingUtil.java プロジェクト: andune/LogBlock
  public static void smartLogBlockBreak(Consumer consumer, String playerName, Block origin) {

    WorldConfig wcfg = getWorldConfig(origin.getWorld());
    if (wcfg == null) return;

    Block checkBlock = origin.getRelative(BlockFace.UP);
    if (BukkitUtils.getRelativeTopBreakabls().contains(checkBlock.getTypeId())) {
      if (wcfg.isLogging(Logging.SIGNTEXT) && checkBlock.getType() == Material.SIGN_POST) {
        consumer.queueSignBreak(playerName, (Sign) checkBlock.getState());
      } else {
        consumer.queueBlockBreak(playerName, checkBlock.getState());
      }
    }

    List<Location> relativeBreakables =
        BukkitUtils.getBlocksNearby(origin, BukkitUtils.getRelativeBreakables());
    if (relativeBreakables.size() != 0) {
      for (Location location : relativeBreakables) {
        final Material blockType = location.getBlock().getType();
        final BlockState blockState = location.getBlock().getState();
        final MaterialData data = blockState.getData();
        switch (blockType) {
          case REDSTONE_TORCH_ON:
          case REDSTONE_TORCH_OFF:
            if (blockState
                .getBlock()
                .getRelative(((RedstoneTorch) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case TORCH:
            if (blockState
                .getBlock()
                .getRelative(((Torch) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case COCOA:
            if (blockState
                .getBlock()
                .getRelative(((CocoaPlant) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case LADDER:
            if (blockState
                .getBlock()
                .getRelative(((Ladder) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case LEVER:
            if (blockState
                .getBlock()
                .getRelative(((Lever) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case TRIPWIRE_HOOK:
            if (blockState
                .getBlock()
                .getRelative(((TripwireHook) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case WOOD_BUTTON:
          case STONE_BUTTON:
            if (blockState
                .getBlock()
                .getRelative(((Button) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case WALL_SIGN:
            if (blockState
                .getBlock()
                .getRelative(((org.bukkit.material.Sign) data).getAttachedFace())
                .equals(origin)) {
              if (wcfg.isLogging(Logging.SIGNTEXT)) {
                consumer.queueSignBreak(playerName, (Sign) blockState);
              } else {
                consumer.queueBlockBreak(playerName, blockState);
              }
            }
            break;
          case TRAP_DOOR:
            if (blockState
                .getBlock()
                .getRelative(((TrapDoor) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          default:
            consumer.queueBlockBreak(playerName, blockState);
            break;
        }
      }
    }
    // Do this down here so that the block is added after blocks sitting on it
    consumer.queueBlockBreak(playerName, origin.getState());
  }