-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCraftControllableMobAI.java
More file actions
91 lines (75 loc) · 2.83 KB
/
CraftControllableMobAI.java
File metadata and controls
91 lines (75 loc) · 2.83 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 de.ntcomputer.minecraft.controllablemobs.implementation;
import de.ntcomputer.minecraft.controllablemobs.api.ControllableMobAI;
import de.ntcomputer.minecraft.controllablemobs.api.ai.AIPart;
import de.ntcomputer.minecraft.controllablemobs.api.ai.AIType;
import de.ntcomputer.minecraft.controllablemobs.api.ai.behaviors.AIBehavior;
import de.ntcomputer.minecraft.controllablemobs.implementation.ai.AIDispatcher;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
public class CraftControllableMobAI<E extends LivingEntity> implements ControllableMobAI<E> {
private AIDispatcher<E> dispatcher;
CraftControllableMobAI(final CraftControllableMob<E> mob) {
this.dispatcher = new AIDispatcher<E>(mob);
}
void dispose() {
this.dispatcher.dispose();
this.dispatcher = null;
}
@Override
public <B extends AIBehavior<? super E>> AIPart<E,B> addBehavior(B behavior) throws IllegalArgumentException {
if(behavior==null) throw new IllegalArgumentException("the AIBehavior must not be null");
return this.dispatcher.add(behavior);
}
@Override
public AIPart<E,?>[] addBehaviors(AIBehavior<? super E>... behaviors) throws IllegalArgumentException {
if(behaviors==null) throw new IllegalArgumentException("the AIBehavior-Array must not be null");
for(int i=0; i<behaviors.length; i++) {
if(behaviors[i]==null) throw new IllegalArgumentException("the AIBehavior["+i+"] must not be null");
}
@SuppressWarnings("unchecked")
AIPart<E,?>[] parts = new AIPart[behaviors.length];
for(int i=0; i<behaviors.length; i++) {
parts[i] = this.dispatcher.add(behaviors[i]);
}
return parts;
}
@Override
public void remove(AIType... typesToRemove) {
this.dispatcher.remove(typesToRemove, true);
}
@Override
public void removeExcept(AIType... typesToKeep) {
this.dispatcher.remove(typesToKeep, false);
}
@Override
public void clear() {
this.dispatcher.clear();
}
@Override
public void reset() {
this.dispatcher.reset();
}
@SuppressWarnings("unchecked")
@Override
public AIPart<E,?>[] getParts() {
ArrayList<AIPart<E,?>> parts = new ArrayList<AIPart<E,?>>();
this.dispatcher.get(parts,null);
return parts.toArray(new AIPart[parts.size()]);
}
@Override
public boolean hasBehavior(AIType type) {
return this.dispatcher.contains(type);
}
@SuppressWarnings("unchecked")
@Override
public AIPart<E, ?>[] getPartsOf(AIType... types) {
ArrayList<AIPart<E,?>> parts = new ArrayList<AIPart<E,?>>();
this.dispatcher.get(parts,types);
return parts.toArray(new AIPart[parts.size()]);
}
@Override
public boolean hasBehavior(AIType... types) throws IllegalArgumentException {
if(types==null || types.length==0) throw new IllegalArgumentException("types must not be null or empty");
return this.dispatcher.contains(types);
}
}