Bukkit/CraftBukkit — pull request #1145 by Zarius (2013-04-24 17:27:51+00:00)
Title: [C] Set data earlier for BlockPiston when extending. Fixes BUKKIT-3523

##### The Issue:
In Bukkit 1.3.1 the world.setRawData(...) functions were removed from BlockPiston.l (now BlockPiston.k in 1.5.1). This appears to have caused piston extend/retract events to fire twice. Further testing confirmed this as the issue does not appear in 1.2.5 but does appear in 1.4.6.

In Bukkit 1.5.1 world.setData(...) was added back but only for the PistonRetractEvent. This further supports the above hypothesis that this is the issue as in 1.5.1 the PistonRetractEvent only fires once whereas the PistonExtendEvent still fires twice.

Data was still being correctly set after the second event fired, this fix retains the correct data (see testing below) and only fires the event once.

For reference see the lines removing the setData in 1.3.1 here:
https://github.com/Bukkit/CraftBukkit/commit/ea5109cc39f0a864d27b9677e54bc84697d1325b#L21L82
https://github.com/Bukkit/CraftBukkit/commit/ea5109cc39f0a864d27b9677e54bc84697d1325b#L21L97

And line adding it back for PistonRetractEvent in 1.5.1 here:
https://github.com/Bukkit/CraftBukkit/commit/d3d98a166f05f8fadfcd11adc0318c548da8a25b#L27R89

##### Justification for this PR:
PistonExtendEvent should not fire twice for one extension.

##### PR Breakdown:
Adds line ```world.setData(i, j, k, i1 | 8, 2);```

New line matches missing line from pre 1.3.1 and matches the re-added line for PistonRetractEvent in 1.5.1.

I understand ```world.setData(i, j, k, l, i1)``` parameters to be ```(x, y, z, dataValue, i1)``` but not sure what i1 is or does. I copied the value from the PistonRetractEvent setData call - please confirm if this is correct (as per testing below it all seemed to work ok).

##### Testing Results and Materials:
Tested basic piston functions and ensured data still matched correctly when extended and retracted (4 & 12 in my case) with both standard Bukkit 1.5.1 and this PR change.

Not sure how to write a unit test that would cover this particular issue.

##### Relevant PR(s):
I'm not aware of an alternate PR(s) for this issue.

##### JIRA Ticket:
BUKKIT-3523 - https://bukkit.atlassian.net/browse/BUKKIT-3523