-
Notifications
You must be signed in to change notification settings - Fork 17
/
LWCMCPCSupport.java
67 lines (54 loc) · 1.84 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
package com.griefcraft.listeners;
import com.griefcraft.lwc.LWC;
import com.griefcraft.model.LWCPlayer;
import com.griefcraft.scripting.JavaModule;
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class LWCMCPCSupport extends JavaModule {
/**
* The shared multiplayer block id used by transport pipes
*/
public static final int TRANSPORT_PIPE_ID = 166;
/**
* The LWC object
*/
private LWC lwc;
/**
* A set of blacklisted players that are blocked from destroying any blocks protected by LWC. Mainly useful for MCPC
* where mods can remove blocks and try to break the block by sending an event first (e.g turtle)
*/
private final Set<String> blacklistedPlayers = new HashSet<String>();
public LWCMCPCSupport(LWC lwc) {
this.lwc = lwc;
loadAndProcessConfig();
}
/**
* Load and process the configuration
*/
public void loadAndProcessConfig() {
blacklistedPlayers.clear();
for (String player : lwc.getConfiguration().getStringList("optional.blacklistedPlayers", new ArrayList<String>())) {
blacklistedPlayers.add(player.toLowerCase());
}
}
/**
* Called when a protection is destroyed
*
* @param event
*/
public void onDestroyProtection(LWCProtectionDestroyEvent event) {
if (event.isCancelled()) {
return;
}
Player bPlayer = event.getPlayer();
LWCPlayer player = lwc.wrapPlayer(bPlayer);
String lowerPlayerName = player.getName().toLowerCase();
if (blacklistedPlayers.contains(lowerPlayerName)) {
event.setCancelled(true);
player.sendLocale("protection.accessdenied");
}
}
}