/
FakeBlock.java
40 lines (33 loc) · 1.32 KB
/
FakeBlock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package net.aufdemrand.denizen.utilities.blocks;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import org.bukkit.Bukkit;
/**
* Creates a temporary fake block and shows it to a dPlayer.
*
*/
public class FakeBlock {
public FakeBlock(final dPlayer player, final dLocation location,
final dMaterial material, final Duration duration) {
// Send the block to the player
player.getPlayerEntity().sendBlockChange(
location,
material.getMaterial(),
material.getMaterialData().getData());
if (duration.getTicks() > 0)
{
// Schedule removal of the block (and show the original block again)
Bukkit.getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(),
new Runnable() {
@Override
public void run() {
if (player.isValid() && player.isOnline())
player.getPlayerEntity().sendBlockChange(
location,
location.getBlock().getType(),
location.getBlock().getData());
}
}, duration.getTicks());
}
}
}