Skip to content

Commit 89588b0

Browse files
authored
Merge pull request #1 from Garsooon/Sponge-Lava-Draining
Sponge Lava Draining
2 parents e43ac5f + f5550f9 commit 89588b0

File tree

5 files changed

+176
-8
lines changed

5 files changed

+176
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<modelVersion>4.0.0</modelVersion>
88
<groupId>com.sk89q</groupId>
99
<artifactId>worldguard</artifactId>
10-
<version>5.2.4</version>
10+
<version>5.2.5</version>
1111
<name>WorldGuard</name>
1212
<description>WorldGuard protects your Minecraft servers</description>
1313

src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static void setBlockToWater(World world, int ox, int oy, int oz) {
132132

133133
/**
134134
* Checks if the given block is water
135-
*
135+
*
136136
* @param world
137137
* @param ox
138138
* @param oy
@@ -149,6 +149,42 @@ public static boolean isBlockWater(World world, int ox, int oy, int oz) {
149149
}
150150
}
151151

152+
/**
153+
* Sets the given block to fluid lava.
154+
* Used by addSpongeLava()
155+
*
156+
* @param world
157+
* @param ox
158+
* @param oy
159+
* @param oz
160+
*/
161+
public static void setBlockToLava(World world, int ox, int oy, int oz) {
162+
Block block = world.getBlockAt(ox, oy, oz);
163+
int id = block.getTypeId();
164+
if (id == 0) {
165+
block.setTypeId(10);
166+
}
167+
}
168+
169+
/**
170+
* Checks if the given block is lava
171+
*
172+
* @param world
173+
* @param ox
174+
* @param oy
175+
* @param oz
176+
* @return
177+
*/
178+
public static boolean isBlockLava(World world, int ox, int oy, int oz) {
179+
Block block = world.getBlockAt(ox, oy, oz);
180+
int id = block.getTypeId();
181+
if (id == 10 || id == 11) {
182+
return true;
183+
} else {
184+
return false;
185+
}
186+
}
187+
152188
/**
153189
* Find a position for the player to stand that is not inside a block.
154190
* Blocks above the player will be iteratively tested until there is

src/main/java/com/sk89q/worldguard/bukkit/SpongeUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import static com.sk89q.worldguard.bukkit.BukkitUtil.isBlockWater;
2323
import static com.sk89q.worldguard.bukkit.BukkitUtil.setBlockToWater;
24-
2524
import org.bukkit.World;
2625

2726
public class SpongeUtil {
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+

src/main/java/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
224224
return;
225225
}
226226

227-
if (wcfg.simulateSponge && isWater) {
227+
if (wcfg.simulateSponge && (isWater || isLava)) {
228228
int ox = blockTo.getX();
229229
int oy = blockTo.getY();
230230
int oz = blockTo.getZ();
@@ -544,6 +544,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
544544
int oz = blockPlaced.getZ();
545545

546546
SpongeUtil.clearSpongeWater(plugin, world, ox, oy, oz);
547+
SpongeUtilLava.clearSpongeLava(plugin, world, ox, oy, oz);
547548
}
548549
}
549550

@@ -568,12 +569,15 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
568569
for (int cy = -1; cy <= 1; cy++) {
569570
for (int cz = -1; cz <= 1; cz++) {
570571
Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
571-
if (sponge.getTypeId() == 19
572-
&& sponge.isBlockIndirectlyPowered()) {
572+
if (sponge.getTypeId() != 19)
573+
continue;
574+
575+
if (sponge.isBlockIndirectlyPowered()) {
573576
SpongeUtil.clearSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
574-
} else if (sponge.getTypeId() == 19
575-
&& !sponge.isBlockIndirectlyPowered()) {
577+
SpongeUtilLava.clearSpongeLava(plugin, world, ox + cx, oy + cy, oz + cz);
578+
} else {
576579
SpongeUtil.addSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
580+
SpongeUtilLava.addSpongeLava(plugin, world, ox + cx, oy + cy, oz + cz);
577581
}
578582
}
579583
}

0 commit comments

Comments
 (0)