-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathGroupDefinition.java
More file actions
91 lines (75 loc) · 3.36 KB
/
GroupDefinition.java
File metadata and controls
91 lines (75 loc) · 3.36 KB
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
package com.froobworld.farmcontrol.group;
import com.froobworld.farmcontrol.controller.entity.SnapshotEntity;
import com.froobworld.farmcontrol.utils.EntityNameUtils;
import com.froobworld.farmcontrol.utils.EntityTypeUtils;
import org.bukkit.configuration.ConfigurationSection;
import java.util.function.Predicate;
public class GroupDefinition {
private final Predicate<SnapshotEntity> typePredicate;
private final Predicate<SnapshotEntity> excludeTypePredicate;
private final Predicate<SnapshotEntity> namePredicate;
private final int size;
private final double distance;
private final double distanceSquared;
private final boolean sameChunk;
private final boolean ignoreVerticalDistance;
private final boolean pure;
public GroupDefinition(Predicate<SnapshotEntity> typePredicate, Predicate<SnapshotEntity> excludeTypePredicate, Predicate<SnapshotEntity> namePredicate, int size, double distance, boolean sameChunk, boolean ignoreVerticalDistance, boolean pure) {
this.typePredicate = typePredicate;
this.excludeTypePredicate = excludeTypePredicate;
this.namePredicate = namePredicate;
this.size = size;
this.distance = distance;
this.distanceSquared = distance * distance;
this.sameChunk = sameChunk;
this.ignoreVerticalDistance = ignoreVerticalDistance;
this.pure = pure;
}
public Predicate<SnapshotEntity> getTypePredicate() {
return typePredicate;
}
public Predicate<SnapshotEntity> getExcludeTypePredicate() {
return excludeTypePredicate;
}
public Predicate<SnapshotEntity> getNamePredicate() {
return namePredicate;
}
public int getSize() {
return size;
}
public boolean isSameChunk() {
return sameChunk;
}
public double getDistance() {
return distance;
}
public double getDistanceSquared() {
return distanceSquared;
}
public boolean ignoreVerticalDistance() {
return ignoreVerticalDistance;
}
public boolean isPure() {
return pure;
}
public static GroupDefinition fromConfigurationSection(ConfigurationSection section) {
Predicate<SnapshotEntity> typePredicate = section.getStringList("types").stream()
.map(EntityTypeUtils::fromString)
.reduce(Predicate::or)
.orElse(snapshotEntity -> true);
Predicate<SnapshotEntity> excludeTypePredicate = section.getStringList("exclude-types").stream()
.map(EntityTypeUtils::fromString)
.reduce(Predicate::or)
.orElse(snapshotEntity -> false);
Predicate<SnapshotEntity> namePredicate = section.getStringList("names").stream()
.map(EntityNameUtils::fromString)
.reduce(Predicate::or)
.orElse(snapshotEntity -> true);
int size = section.getInt("count");
boolean sameChunk = section.isString("distance") && "same-chunk".equalsIgnoreCase(section.getString("distance"));
double distance = sameChunk ? 0 : section.getDouble("distance");
boolean ignoreVerticalDistance = section.getBoolean("ignore-vertical-distance");
boolean pure = section.getBoolean("pure");
return new GroupDefinition(typePredicate, excludeTypePredicate, namePredicate, size, distance, sameChunk, ignoreVerticalDistance, pure);
}
}