@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)); } } }
/** * 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; }
@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); } } } }
@Override public boolean resetChanges(HungerGame game) { EquatableWeakReference<HungerGame> eMap = new EquatableWeakReference<HungerGame>(game); if (!changedBlocks.containsKey(new EquatableWeakReference<HungerGame>(game))) return true; for (Location l : changedBlocks.get(eMap).keySet()) { BlockState state = changedBlocks.get(eMap).get(l); l.getBlock().setTypeId(state.getTypeId()); l.getBlock().setData(state.getRawData()); } int chests = 0; for (Location l : changedInvs.get(eMap).keySet()) { BlockState state = l.getBlock().getState(); if (!(state instanceof InventoryHolder)) throw new IllegalStateException( "Error when resetting a game: inventory saved for non-InventoryHolder"); ((InventoryHolder) state).getInventory().setContents(changedInvs.get(eMap).get(l)); chests++; } Logging.debug("Reset " + chests + " chests"); changedBlocks.get(eMap).clear(); return true; }
/** * Get the block's raw data. * * @return The block's raw data. */ public byte getRawData() { return blockState.getRawData(); }