forked from bootswithdefer/LogBlock
-
Notifications
You must be signed in to change notification settings - Fork 112
/
BlockSpreadLogging.java
101 lines (91 loc) · 4.63 KB
/
BlockSpreadLogging.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.PointedDripstone;
import org.bukkit.block.data.type.PointedDripstone.Thickness;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockSpreadEvent;
import static de.diddiz.LogBlock.config.Config.isLogging;
public class BlockSpreadLogging extends LoggingListener {
public BlockSpreadLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockSpread(BlockSpreadEvent event) {
String name;
World world = event.getNewState().getWorld();
Material type = event.getNewState().getType();
if (type == Material.GRASS) {
if (!isLogging(world, Logging.GRASSGROWTH)) {
return;
}
name = "GrassGrowth";
} else if (type == Material.MYCELIUM) {
if (!isLogging(world, Logging.MYCELIUMSPREAD)) {
return;
}
name = "MyceliumSpread";
} else if (type == Material.VINE || type == Material.CAVE_VINES || type == Material.CAVE_VINES_PLANT || type == Material.WEEPING_VINES || type == Material.WEEPING_VINES_PLANT || type == Material.TWISTING_VINES || type == Material.TWISTING_VINES_PLANT) {
if (!isLogging(world, Logging.VINEGROWTH)) {
return;
}
name = "VineGrowth";
} else if (type == Material.RED_MUSHROOM || type == Material.BROWN_MUSHROOM) {
if (!isLogging(world, Logging.MUSHROOMSPREAD)) {
return;
}
name = "MushroomSpread";
} else if (type == Material.BAMBOO || type == Material.BAMBOO_SAPLING) {
if (!isLogging(world, Logging.BAMBOOGROWTH)) {
return;
}
name = "BambooGrowth";
if (type == Material.BAMBOO_SAPLING) {
// bamboo sapling gets replaced by bamboo
consumer.queueBlockReplace(new Actor(name), event.getSource().getState(), Material.BAMBOO.createBlockData());
}
} else if (type == Material.POINTED_DRIPSTONE) {
if (!isLogging(world, Logging.DRIPSTONEGROWTH)) {
return;
}
name = "DripstoneGrowth";
PointedDripstone pointed = (PointedDripstone) event.getNewState().getBlockData();
if (pointed.getThickness() != Thickness.TIP_MERGE) {
BlockFace direction = pointed.getVerticalDirection();
Block previousPart = event.getBlock().getRelative(direction.getOppositeFace());
if (previousPart.getType() == Material.POINTED_DRIPSTONE) {
PointedDripstone newBelow = (PointedDripstone) previousPart.getBlockData();
newBelow.setThickness(Thickness.FRUSTUM);
consumer.queueBlockReplace(new Actor(name), previousPart.getState(), newBelow);
previousPart = previousPart.getRelative(direction.getOppositeFace());
if (previousPart.getType() == Material.POINTED_DRIPSTONE) {
Block evenMorePrevious = previousPart.getRelative(direction.getOppositeFace());
newBelow = (PointedDripstone) previousPart.getBlockData();
newBelow.setThickness(evenMorePrevious.getType() == Material.POINTED_DRIPSTONE ? Thickness.MIDDLE : Thickness.BASE);
consumer.queueBlockReplace(new Actor(name), previousPart.getState(), newBelow);
}
}
} else {
// special case because the old state is already changed (for one half)
PointedDripstone oldState = (PointedDripstone) event.getNewState().getBlockData();
oldState.setThickness(Thickness.TIP);
consumer.queueBlockReplace(new Actor(name), oldState, event.getNewState());
return;
}
} else if (type == Material.SCULK || type == Material.SCULK_VEIN || type == Material.SCULK_CATALYST || type == Material.SCULK_SENSOR || type == Material.SCULK_SHRIEKER) {
if (!isLogging(world, Logging.SCULKSPREAD)) {
return;
}
name = "SculkSpread";
} else {
return;
}
consumer.queueBlockReplace(new Actor(name), event.getBlock().getState(), event.getNewState());
}
}