-
-
Notifications
You must be signed in to change notification settings - Fork 449
Expand file tree
/
Copy pathCatData.java
More file actions
97 lines (80 loc) · 2.5 KB
/
Copy pathCatData.java
File metadata and controls
97 lines (80 loc) · 2.5 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
92
93
94
95
96
97
package ch.njol.skript.entity;
import ch.njol.skript.classes.registry.RegistryClassInfo;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.registrations.Classes;
import ch.njol.util.coll.CollectionUtils;
import com.google.common.collect.Iterators;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.entity.Cat;
import org.bukkit.entity.Cat.Type;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class CatData extends EntityData<Cat> {
private static final Type[] TYPES;
static {
var catTypeClassInfo = new RegistryClassInfo<>(Cat.Type.class, RegistryKey.CAT_VARIANT, "cattype", "cat types");
Classes.registerClass(catTypeClassInfo
.user("cat ?(type|race)s?")
.name("Cat Type")
.description("Represents the race/type of a cat entity.",
"NOTE: Minecraft namespaces are supported, ex: 'minecraft:british_shorthair'.")
.since("2.4")
.requiredPlugins("Minecraft 1.14 or newer")
.documentationId("CatType"));
EntityData.register(CatData.class, "cat", Cat.class, "cat");
TYPES = Iterators.toArray(catTypeClassInfo.getSupplier().get(), Type.class);
}
private @Nullable Type type = null;
@Override
protected boolean init(Literal<?>[] exprs, int matchedCodeName, int matchedPattern, ParseResult parseResult) {
if (exprs.length > 0 && exprs[0] != null) {
//noinspection unchecked
type = ((Literal<Type>) exprs[0]).getSingle();
}
return true;
}
@Override
protected boolean init(@Nullable Class<? extends Cat> entityClass, @Nullable Cat cat) {
if (cat != null)
type = cat.getCatType();
return true;
}
@Override
public void set(Cat cat) {
Type type = this.type;
if (type == null)
type = CollectionUtils.getRandom(TYPES);
assert type != null;
cat.setCatType(type);
}
@Override
protected boolean match(Cat cat) {
return dataMatch(type, cat.getCatType());
}
@Override
public Class<? extends Cat> getType() {
return Cat.class;
}
@Override
public @NotNull EntityData<?> getSuperType() {
return new CatData();
}
@Override
protected int hashCode_i() {
return Objects.hashCode(type);
}
@Override
protected boolean equals_i(EntityData<?> entityData) {
if (!(entityData instanceof CatData other))
return false;
return type == other.type;
}
@Override
public boolean isSupertypeOf(EntityData<?> entityData) {
if (!(entityData instanceof CatData other))
return false;
return dataMatch(type, other.type);
}
}