Skip to content

Commit

Permalink
Sponges now destroy kelp and seagrass, similar to vanilla behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Nov 17, 2018
1 parent 9169653 commit 83b375b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TimeLockFlag create(Session session) {
private Long initialTime;
private boolean initialRelative;

private static Pattern timePattern = Pattern.compile("(\\+|-)?\\d+");
private static Pattern timePattern = Pattern.compile("([+\\-])?\\d+");

public TimeLockFlag(Session session) {
super(session, Flags.TIME_LOCK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldguard.bukkit.listener;
package com.sk89q.worldguard.util;

import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.config.WorldConfiguration;
Expand All @@ -31,6 +32,12 @@ public final class SpongeUtil {
private SpongeUtil() {
}

private static boolean isReplacable(BlockType blockType) {
return blockType == BlockTypes.WATER || blockType == BlockTypes.SEAGRASS
|| blockType == BlockTypes.TALL_SEAGRASS || blockType == BlockTypes.KELP_PLANT
|| blockType == BlockTypes.KELP;
}

/**
* Remove water around a sponge.
*
Expand All @@ -46,7 +53,7 @@ public static void clearSpongeWater(World world, int ox, int oy, int oz) {
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
BlockVector3 vector = BlockVector3.at(ox + cx, oy + cy, oz + cz);
if (world.getBlock(vector).getBlockType() == BlockTypes.WATER) {
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
world.setBlock(vector, BlockTypes.AIR.getDefaultState());
} catch (WorldEditException e) {
Expand Down Expand Up @@ -90,7 +97,7 @@ public static void addSpongeWater(World world, int ox, int oy, int oz) {
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (world.getBlock(vector).getBlockType() == BlockTypes.WATER) {
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx + 1, cy, cz);
} catch (WorldEditException e) {
Expand All @@ -105,7 +112,7 @@ public static void addSpongeWater(World world, int ox, int oy, int oz) {
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (world.getBlock(vector).getBlockType() == BlockTypes.WATER) {
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx - 1, cy, cz);
} catch (WorldEditException e) {
Expand All @@ -120,7 +127,7 @@ public static void addSpongeWater(World world, int ox, int oy, int oz) {
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (world.getBlock(vector).getBlockType() == BlockTypes.WATER) {
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx, cy + 1, cz);
} catch (WorldEditException e) {
Expand All @@ -135,7 +142,7 @@ public static void addSpongeWater(World world, int ox, int oy, int oz) {
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (world.getBlock(vector).getBlockType() == BlockTypes.WATER) {
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx, cy - 1, cz);
} catch (WorldEditException e) {
Expand All @@ -150,7 +157,7 @@ public static void addSpongeWater(World world, int ox, int oy, int oz) {
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (world.getBlock(vector).getBlockType() == BlockTypes.WATER) {
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx, cy, cz + 1);
} catch (WorldEditException e) {
Expand All @@ -165,7 +172,7 @@ public static void addSpongeWater(World world, int ox, int oy, int oz) {
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (world.getBlock(vector).getBlockType() == BlockTypes.WATER) {
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx, cy, cz - 1);
} catch (WorldEditException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.sk89q.worldguard.protection.association.RegionAssociable;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.util.SpongeUtil;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
Expand Down

0 comments on commit 83b375b

Please sign in to comment.