use of org.bukkit.event.Event in project Denizen-For-Bukkit by DenizenScript.
the class ModifyBlockCommand method handleLocation.
void handleLocation(LocationTag location, int index, List<MaterialTag> materialList, boolean doPhysics, ItemTag natural, int radius, int height, int depth, List<Float> percents, Player source, ScriptEntry entry) {
MaterialTag material;
if (percents == null) {
material = materialList.get(index % materialList.size());
} else {
material = null;
for (int i = 0; i < materialList.size(); i++) {
float perc = percents.get(i) / 100f;
if (CoreUtilities.getRandom().nextDouble() <= perc) {
material = materialList.get(i);
break;
}
}
if (material == null) {
return;
}
}
World world = location.getWorld();
location.setX(location.getBlockX());
location.setY(location.getBlockY());
location.setZ(location.getBlockZ());
if (source != null) {
Event event;
if (material.getMaterial() == Material.AIR) {
event = new BlockBreakEvent(location.getBlock(), source);
} else {
Block block = location.getBlock();
BlockState state = NMSHandler.getBlockHelper().generateBlockState(block, material.getMaterial());
state.setBlockData(material.getModernData());
event = new BlockPlaceEvent(block, state, block, new ItemTag(material, 1).getItemStack(), source, true, EquipmentSlot.HAND);
}
Bukkit.getPluginManager().callEvent(event);
if (((Cancellable) event).isCancelled()) {
if (entry.dbCallShouldDebug()) {
Debug.echoDebug(entry, "Source event cancelled, not changing block.");
}
return;
}
}
setBlock(location, material, doPhysics, natural);
if (radius != 0) {
for (int x = 0; x < 2 * radius + 1; x++) {
for (int z = 0; z < 2 * radius + 1; z++) {
setBlock(new Location(world, location.getX() + x - radius, location.getY(), location.getZ() + z - radius), material, doPhysics, natural);
}
}
}
if (height != 0) {
for (int x = 0; x < 2 * radius + 1; x++) {
for (int z = 0; z < 2 * radius + 1; z++) {
for (int y = 1; y < height + 1; y++) {
setBlock(new Location(world, location.getX() + x - radius, location.getY() + y, location.getZ() + z - radius), material, doPhysics, natural);
}
}
}
}
if (depth != 0) {
for (int x = 0; x < 2 * radius + 1; x++) {
for (int z = 0; z < 2 * radius + 1; z++) {
for (int y = 1; y < depth + 1; y++) {
setBlock(new Location(world, location.getX() + x - radius, location.getY() - y, location.getZ() + z - radius), material, doPhysics, natural);
}
}
}
}
}
Aggregations