-
Notifications
You must be signed in to change notification settings - Fork 17
/
LWCMCPCSupport.java
81 lines (66 loc) · 2.25 KB
/
LWCMCPCSupport.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
package com.griefcraft.listeners;
import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class LWCMCPCSupport implements Listener {
/**
* The shared multiplayer block id used by transport pipes
*/
public static final int TRANSPORT_PIPE_ID = 166;
/**
* The LWC object
*/
private LWC lwc;
public LWCMCPCSupport(LWC lwc) {
this.lwc = lwc;
}
/**
* Check if MCPC is installed to the server (which Tekkit uses)
*
* @return
*/
public boolean mcpcInstalled() {
// quickest and easiest check
if (Bukkit.getBukkitVersion().contains("MCPC")) {
return true;
}
// attempt to detect Forge, tekkit definitely contains forge, most other MCPC mods are going to have it ?
try {
Class.forName("forge.MinecraftForge");
return true;
} catch (Exception e) { } // ignore failure
return false; // no mcpc
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
// if we matched the block to our own blacklist
boolean blockIsBlacklisted = false;
// transport pipes
if (lwc.getConfiguration().getBoolean("optional.blockTransportPipes", true)) {
if (block.getTypeId() == TRANSPORT_PIPE_ID) {
blockIsBlacklisted = true;
}
}
if (blockIsBlacklisted) {
// it's blacklisted, check for a protected chest
Block chest = lwc.findAdjacentBlockOnAllSides(block, Material.CHEST);
if (chest != null) {
Protection protection = lwc.findProtection(chest);
if (protection != null) {
if (!lwc.canAccessProtection(player, protection)) {
// they can't access the protection ..
event.setCancelled(true);
}
}
}
}
}
}