|
| 1 | +// $Id$ |
| 2 | +/* |
| 3 | + * WorldGuard |
| 4 | + * Copyright (C) 2010 sk89q <http://www.sk89q.com> |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +package com.sk89q.worldguard.bukkit; |
| 21 | + |
| 22 | + |
| 23 | +import static com.sk89q.worldguard.bukkit.BukkitUtil.isBlockLava; |
| 24 | +import static com.sk89q.worldguard.bukkit.BukkitUtil.setBlockToLava; |
| 25 | +import org.bukkit.World; |
| 26 | + |
| 27 | +public class SpongeUtilLava { |
| 28 | + |
| 29 | +// I made this separate from SpongeUtil.java to keep it more distinct from the water draining function |
| 30 | + |
| 31 | + /** |
| 32 | + * Remove lava around a sponge. |
| 33 | + * |
| 34 | + * @param plugin |
| 35 | + * @param world |
| 36 | + * @param ox |
| 37 | + * @param oy |
| 38 | + * @param oz |
| 39 | + */ |
| 40 | + public static void clearSpongeLava(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) { |
| 41 | + ConfigurationManager cfg = plugin.getGlobalStateManager(); |
| 42 | + WorldConfiguration wcfg = cfg.get(world); |
| 43 | + |
| 44 | + for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) { |
| 45 | + for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) { |
| 46 | + for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) { |
| 47 | + if (isBlockLava(world, ox + cx, oy + cy, oz + cz)) { |
| 48 | + world.getBlockAt(ox + cx, oy + cy, oz + cz).setTypeId(0); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | +/** |
| 56 | + * Add lava around a sponge. |
| 57 | + * |
| 58 | + * @param plugin |
| 59 | + * @param world |
| 60 | + * @param ox |
| 61 | + * @param oy |
| 62 | + * @param oz |
| 63 | + */ |
| 64 | +public static void addSpongeLava(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) { |
| 65 | + ConfigurationManager cfg = plugin.getGlobalStateManager(); |
| 66 | + WorldConfiguration wcfg = cfg.get(world); |
| 67 | + |
| 68 | + // The negative x edge |
| 69 | + int cx = ox - wcfg.spongeRadius - 1; |
| 70 | + for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) { |
| 71 | + for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) { |
| 72 | + if (isBlockLava(world, cx, cy, cz)) { |
| 73 | + setBlockToLava(world, cx + 1, cy, cz); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + // The positive x edge |
| 79 | + cx = ox + wcfg.spongeRadius + 1; |
| 80 | + for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) { |
| 81 | + for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) { |
| 82 | + if (isBlockLava(world, cx, cy, cz)) { |
| 83 | + setBlockToLava(world, cx - 1, cy, cz); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + // The negative y edge |
| 89 | + int cy = oy - wcfg.spongeRadius - 1; |
| 90 | + for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) { |
| 91 | + for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) { |
| 92 | + if (isBlockLava(world, cx, cy, cz)) { |
| 93 | + setBlockToLava(world, cx, cy + 1, cz); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + // The positive y edge |
| 99 | + cy = oy + wcfg.spongeRadius + 1; |
| 100 | + for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) { |
| 101 | + for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) { |
| 102 | + if (isBlockLava(world, cx, cy, cz)) { |
| 103 | + setBlockToLava(world, cx, cy - 1, cz); |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + // The negative z edge |
| 109 | + int cz = oz - wcfg.spongeRadius - 1; |
| 110 | + for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) { |
| 111 | + for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) { |
| 112 | + if (isBlockLava(world, cx, cy, cz)) { |
| 113 | + setBlockToLava(world, cx, cy, cz + 1); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + // The positive z edge |
| 119 | + cz = oz + wcfg.spongeRadius + 1; |
| 120 | + for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) { |
| 121 | + for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) { |
| 122 | + if (isBlockLava(world, cx, cy, cz)) { |
| 123 | + setBlockToLava(world, cx, cy, cz - 1); |
| 124 | + } |
| 125 | + } |
| 126 | + } |
| 127 | +} |
| 128 | +} |
| 129 | + |
0 commit comments