use of org.bukkit.block.data.Waterlogged in project Prism-Bukkit by prism.
the class PrismPlayerEvents method onPlayerBucketFill.
/**
* PlayerBucketFillEvent.
*
* @param event PlayerBucketFillEvent
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerBucketFill(final PlayerBucketFillEvent event) {
final Player player = event.getPlayer();
if (!Prism.getIgnore().event("bucket-fill", player)) {
return;
}
final Block spot = event.getBlock();
String liquidType = "milk";
if (spot.getType() == Material.WATER) {
liquidType = "water";
} else if (spot.getBlockData() instanceof Waterlogged && ((Waterlogged) spot.getBlockData()).isWaterlogged()) {
liquidType = "water";
} else if (spot.getType() == Material.LAVA) {
liquidType = "lava";
}
final Handler pa = ActionFactory.createPlayer("bucket-fill", player, liquidType);
// Override the location with the area taken
pa.setX(spot.getX());
pa.setY(spot.getY());
pa.setZ(spot.getZ());
RecordingQueue.addToQueue(pa);
}
use of org.bukkit.block.data.Waterlogged in project Prism-Bukkit by prism.
the class Utilities method checkForWaterlogged.
private static ArrayList<BlockStateChangeImpl> checkForWaterlogged(final Location loc, int radius) {
final ArrayList<BlockStateChangeImpl> blockStateChanges = new ArrayList<>();
if (loc != null && radius > 0) {
final int x1 = loc.getBlockX();
final int y1 = loc.getBlockY();
final int z1 = loc.getBlockZ();
final World world = loc.getWorld();
for (int x = x1 - radius; x <= x1 + radius; x++) {
for (int y = y1 - radius; y <= y1 + radius; y++) {
for (int z = z1 - radius; z <= z1 + radius; z++) {
Location testLocation = new Location(world, x, y, z);
final Block b = testLocation.getBlock();
if (b.getType().equals(Material.AIR)) {
continue;
}
BlockData data = testLocation.getBlock().getBlockData();
if (data instanceof Waterlogged) {
final BlockState originalBlock = testLocation.getBlock().getState();
BlockData modified = testLocation.getBlock().getBlockData();
((Waterlogged) modified).setWaterlogged(false);
testLocation.getBlock().setBlockData(modified);
final BlockState newBlock = testLocation.getBlock().getState();
blockStateChanges.add(new BlockStateChangeImpl(originalBlock, newBlock));
}
}
}
}
}
return blockStateChanges;
}
use of org.bukkit.block.data.Waterlogged in project Prism-Bukkit by prism.
the class PrismPlayerEvents method onPlayerBucketEmpty.
/**
* PlayerBucketEmptyEvent.
*
* @param event PlayerBucketEmptyEvent
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event) {
final Player player = event.getPlayer();
String cause;
Material newMat;
Block spot = event.getBlockClicked().getRelative(event.getBlockFace());
switch(event.getBucket()) {
case LAVA_BUCKET:
cause = "lava-bucket";
newMat = Material.LAVA;
break;
case TROPICAL_FISH_BUCKET:
case SALMON_BUCKET:
case PUFFERFISH_BUCKET:
case WATER_BUCKET:
default:
cause = "water-bucket";
newMat = Material.WATER;
break;
}
if (!Prism.getIgnore().event(cause, player)) {
return;
}
BlockData oldData = spot.getBlockData();
BlockData newData = Bukkit.createBlockData(newMat);
BlockData clickedData = event.getBlockClicked().getBlockData();
// TODO If "Lavalogged" blocks become a thing, please revisit.
if (clickedData instanceof Waterlogged && event.getBucket() != Material.LAVA) {
Waterlogged wl = (Waterlogged) clickedData;
if (!wl.isWaterlogged()) {
spot = event.getBlockClicked();
newMat = spot.getType();
oldData = wl;
newData = wl.clone();
((Waterlogged) newData).setWaterlogged(true);
cause = "water-bucket";
}
}
RecordingQueue.addToQueue(ActionFactory.createBlockChange(cause, spot.getLocation(), spot.getType(), oldData, newMat, newData, player));
if (plugin.getConfig().getBoolean("prism.alerts.uses.lava") && event.getBucket() == Material.LAVA_BUCKET && !player.hasPermission("prism.alerts.use.lavabucket.ignore") && !player.hasPermission("prism.alerts.ignore")) {
plugin.useMonitor.alertOnItemUse(player, "poured lava", "prism.alerts.use.lavabucket");
}
}
Aggregations