mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-09-29 23:27:28 +02:00
Added redstone support to sponges, removed classic water.
This commit is contained in:
parent
2f6b51e811
commit
5cf38cc885
@ -26,9 +26,9 @@ protection:
|
||||
item-durability: on
|
||||
|
||||
simulation:
|
||||
classic-water: off
|
||||
sponge:
|
||||
enable: on
|
||||
redstone: off
|
||||
radius: 3
|
||||
|
||||
physics:
|
||||
|
@ -123,7 +123,9 @@ public void onBlockFlow(BlockFromToEvent event) {
|
||||
for (int cx = -plugin.spongeRadius; cx <= plugin.spongeRadius; cx++) {
|
||||
for (int cy = -plugin.spongeRadius; cy <= plugin.spongeRadius; cy++) {
|
||||
for (int cz = -plugin.spongeRadius; cz <= plugin.spongeRadius; cz++) {
|
||||
if (world.getBlockTypeIdAt(ox + cx, oy + cy, oz + cz) == 19) {
|
||||
Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
|
||||
if (sponge.getTypeId() == 19
|
||||
&& (!plugin.redstoneSponges || !sponge.isBlockIndirectlyPowered())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -132,14 +134,16 @@ public void onBlockFlow(BlockFromToEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.classicWater && isWater) {
|
||||
int blockBelow = world.getBlockTypeIdAt(blockFrom.getX(), blockFrom.getY() - 1, blockFrom.getZ());
|
||||
/*if (plugin.classicWater && isWater) {
|
||||
int blockBelow = blockFrom.getRelative(0, -1, 0).getTypeId();
|
||||
if (blockBelow != 0 && blockBelow != 8 && blockBelow != 9) {
|
||||
world.getBlockAt(blockFrom.getX(), blockFrom.getY(), blockFrom.getZ()).setTypeId(9);
|
||||
event.setCancelled(true);
|
||||
blockFrom.setTypeId(9);
|
||||
if (blockTo.getTypeId() == 0) {
|
||||
blockTo.setTypeId(9);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (plugin.preventWaterDamage.size() > 0 && isWater) {
|
||||
int targetId = world.getBlockTypeIdAt(
|
||||
@ -343,21 +347,15 @@ public void onBlockPlace(BlockPlaceEvent event) {
|
||||
}
|
||||
|
||||
if (plugin.simulateSponge && blockPlaced.getTypeId() == 19) {
|
||||
if (plugin.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int ox = blockPlaced.getX();
|
||||
int oy = blockPlaced.getY();
|
||||
int oz = blockPlaced.getZ();
|
||||
|
||||
for (int cx = -plugin.spongeRadius; cx <= plugin.spongeRadius; cx++) {
|
||||
for (int cy = -plugin.spongeRadius; cy <= plugin.spongeRadius; cy++) {
|
||||
for (int cz = -plugin.spongeRadius; cz <= plugin.spongeRadius; cz++) {
|
||||
int id = world.getBlockTypeIdAt(ox + cx, oy + cy, oz + cz);
|
||||
if (id == 8 || id == 9) {
|
||||
world.getBlockAt(ox + cx, oy + cy, oz + cz)
|
||||
.setTypeId(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
clearSpongeWater(world, ox, oy, oz);
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,4 +391,61 @@ public void onBlockRightClick(BlockRightClickEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when redstone changes
|
||||
* From: the source of the redstone change
|
||||
* To: The redstone dust that changed
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@Override
|
||||
public void onBlockRedstoneChange(BlockFromToEvent event) {
|
||||
World world = event.getBlock().getWorld();
|
||||
Block blockTo = event.getToBlock();
|
||||
|
||||
if (plugin.simulateSponge && plugin.redstoneSponges) {
|
||||
int ox = blockTo.getX();
|
||||
int oy = blockTo.getY();
|
||||
int oz = blockTo.getZ();
|
||||
|
||||
for (int cx = -1; cx <= 1; cx++) {
|
||||
for (int cy = -1; cy <= 1; cy++) {
|
||||
for (int cz = -1; cz <= 1; cz++) {
|
||||
Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
|
||||
if (sponge.getTypeId() == 19
|
||||
&& sponge.isBlockIndirectlyPowered()) {
|
||||
clearSpongeWater(world, ox + cx, oy + cy, oz + cz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove water around a sponge.
|
||||
*
|
||||
* @param world
|
||||
* @param ox
|
||||
* @param oy
|
||||
* @param oz
|
||||
*/
|
||||
private void clearSpongeWater(World world, int ox, int oy, int oz) {
|
||||
for (int cx = -plugin.spongeRadius; cx <= plugin.spongeRadius; cx++) {
|
||||
for (int cy = -plugin.spongeRadius; cy <= plugin.spongeRadius; cy++) {
|
||||
for (int cz = -plugin.spongeRadius; cz <= plugin.spongeRadius; cz++) {
|
||||
Block block = world.getBlockAt(ox + cx, oy + cy, oz + cz);
|
||||
int id = block.getTypeId();
|
||||
if (id == 8 || id == 9) {
|
||||
world.getBlockAt(ox + cx, oy + cy, oz + cz)
|
||||
.setTypeId(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ public class WorldGuardPlugin extends JavaPlugin {
|
||||
boolean classicWater;
|
||||
boolean simulateSponge;
|
||||
int spongeRadius;
|
||||
boolean redstoneSponges;
|
||||
|
||||
boolean noPhysicsGravel;
|
||||
boolean noPhysicsSand;
|
||||
@ -181,6 +182,7 @@ private void registerEvents() {
|
||||
registerEvent(Event.Type.BLOCK_INTERACT, blockListener, Priority.High);
|
||||
registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.High);
|
||||
registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener, Priority.High);
|
||||
registerEvent(Event.Type.REDSTONE_CHANGE, blockListener, Priority.High);
|
||||
|
||||
registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.High);
|
||||
registerEvent(Event.Type.ENTITY_DAMAGEDBY_PROJECTILE, entityListener, Priority.High);
|
||||
@ -262,6 +264,7 @@ public void loadConfiguration() {
|
||||
classicWater = config.getBoolean("simulation.classic-water", false);
|
||||
simulateSponge = config.getBoolean("simulation.sponge.enable", true);
|
||||
spongeRadius = Math.max(1, config.getInt("simulation.sponge.radius", 3)) - 1;
|
||||
redstoneSponges = config.getBoolean("simulation.sponge.redstone", false);
|
||||
|
||||
noPhysicsGravel = config.getBoolean("physics.no-physics-gravel", false);
|
||||
noPhysicsSand = config.getBoolean("physics.no-physics-sand", false);
|
||||
|
Loading…
Reference in New Issue
Block a user