MCPcopy Create free account
hub / github.com/boxbeam/RedLib / ProtectionPolicy

Class ProtectionPolicy

src/redempt/redlib/protection/ProtectionPolicy.java:26–460  ·  view source on GitHub ↗

Represents a set of rules in the form of ProtectionTypes protecting a set of blocks, which can have bypasses @author Redempt

Source from the content-addressed store, hash-verified

24 * @author Redempt
25 */
26public class ProtectionPolicy implements Listener {
27
28 protected static Set<ProtectionPolicy> globalPolicies = new HashSet<>();
29 protected static RegionMap<ProtectionPolicy> regionMap = new RegionMap<>();
30
31 static {
32 ProtectionRegistrations.registerProtections();
33 }
34
35 /**
36 * Registers a custom event to be protected using a specific ProtectionType
37 *
38 * @param clazz The event class of an event which implements {@link Cancellable}
39 * @param type The ProtectionType to protect against this event
40 * @param getPlayer A function to get the player associated with the event - can return null
41 * @param getBlocks A vararg of functions to get blocks associated with the event
42 * @param <T> The event type
43 */
44 public static <T extends Event & Cancellable> void registerProtection(Class<T> clazz, ProtectionType type, Function<T, Player> getPlayer, Function<T, Block>... getBlocks) {
45 ProtectionListener.protect(clazz, type, getPlayer, getBlocks);
46 }
47
48 /**
49 * Registers a custom event that cannot be cancelled using {@link Cancellable#setCancelled(boolean)} using a specific ProtectionType
50 *
51 * @param clazz The event class
52 * @param type The ProtectionType to protect against this event
53 * @param getPlayer A function to get the player associated with the event - can return null
54 * @param cancel A consumer to cancel the event
55 * @param getBlocks A vararg of functions to get the blocks associated with this event
56 * @param <T> The event type
57 */
58 public static <T extends Event> void registerProtectionNonCancellable(Class<T> clazz, ProtectionType type, Function<T, Player> getPlayer, Consumer<T> cancel, Function<T, Block>... getBlocks) {
59 ProtectionListener.protectNonCancellable(clazz, type, getPlayer, cancel, getBlocks);
60 }
61
62 /**
63 * Registers a custom event that modifies multiple blocks to be protected using a specific ProtectionType
64 *
65 * @param clazz The event class
66 * @param type The ProtectionType to protect against this event
67 * @param getPlayer A function to get the player associated with the event - can return null
68 * @param cancel A function to cancel the modification of a specific block in the event
69 * @param getBlocks A vararg of functions to get the blocks associated with the event
70 * @param <T> The event type
71 */
72 public static <T extends Event> void registerProtectionMultiBlock(Class<T> clazz, ProtectionType type, Function<T, Player> getPlayer, BiConsumer<T, Block> cancel, Function<T, List<Block>> getBlocks) {
73 ProtectionListener.protectMultiBlock(clazz, type, getPlayer, cancel, getBlocks);
74 }
75
76 /**
77 * Registers a custom event to be protected using a specific ProtectionType, where there is a block acting and blocks being acted upon
78 *
79 * @param clazz The event class
80 * @param type The ProtectionType to protect against this event
81 * @param getPlayer A function to get the player associated with the event - can be null
82 * @param getActingBlock A function to get the block acting upon the other blocks, i.e. a piston pushing blocks or a water source spawning new water blocks
83 * @param getSubjectBlocks A function to get the list of blocks being acted upon, i.e. the blocks being pushed by a piston or the water block being spawned

Callers

nothing calls this directly

Calls 6

registerProtectionsMethod · 0.95
getInstanceMethod · 0.95
disableMethod · 0.95
unregisterMethod · 0.80
equalsMethod · 0.45
getPluginMethod · 0.45

Tested by

no test coverage detected