forked from bootswithdefer/LogBlock
-
Notifications
You must be signed in to change notification settings - Fork 112
/
CreatureInteractLogging.java
64 lines (57 loc) · 2.63 KB
/
CreatureInteractLogging.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
package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.util.BukkitUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.TurtleEgg;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityInteractEvent;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
public class CreatureInteractLogging extends LoggingListener {
public CreatureInteractLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityInteract(EntityInteractEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getEntity().getWorld());
// Mobs only
if (event.getEntity() instanceof Player) {
return;
}
if (wcfg != null) {
final Block clicked = event.getBlock();
final Material type = clicked.getType();
final Location loc = clicked.getLocation();
if (type == Material.FARMLAND) {
if (wcfg.isLogging(Logging.CREATURECROPTRAMPLE)) {
// 3 = Dirt ID
consumer.queueBlock(new Actor("CreatureTrample"), loc, type.createBlockData(), Material.DIRT.createBlockData());
// Log the crop on top as being broken
Block trampledCrop = clicked.getRelative(BlockFace.UP);
if (BukkitUtils.getCropBlocks().contains(trampledCrop.getType())) {
consumer.queueBlockBreak(new Actor("CreatureTrample"), trampledCrop.getState());
}
}
} else if (type == Material.TURTLE_EGG) {
if (wcfg.isLogging(Logging.CREATURECROPTRAMPLE)) {
TurtleEgg turtleEggData = (TurtleEgg) clicked.getBlockData();
int eggs = turtleEggData.getEggs();
if (eggs > 1) {
TurtleEgg turtleEggData2 = (TurtleEgg) turtleEggData.clone();
turtleEggData2.setEggs(eggs - 1);
consumer.queueBlock(new Actor("CreatureTrample"), loc, turtleEggData, turtleEggData2);
} else {
consumer.queueBlock(new Actor("CreatureTrample"), loc, turtleEggData, Material.AIR.createBlockData());
}
}
}
}
}
}