Skip to content

Commit c917ced

Browse files
committed
renamed methods, deprecated old methods
1 parent 5696e49 commit c917ced

1 file changed

Lines changed: 142 additions & 15 deletions

File tree

src/java/de/ntcomputer/minecraft/controllablemobs/api/ControllableMobs.java

Lines changed: 142 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ private ControllableMobs() {
5757
*
5858
* @param entity to check for a {@link ControllableMob} instance
5959
* @return whether the entity has been assigned ({@link ControllableMob} instance is available)
60+
* @deprecated use {@link #isUnderControl(LivingEntity)} instead
6061
*/
62+
@Deprecated
6163
public static boolean isAssigned(LivingEntity entity) {
62-
return entities.containsKey(entity);
64+
return isUnderControl(entity);
6365
}
6466

6567
/**
@@ -68,11 +70,11 @@ public static boolean isAssigned(LivingEntity entity) {
6870
* @param entity which is already under control
6971
* @return the {@link ControllableMob} you can use to control the entity
7072
* @throws IllegalStateException when the entity has not been assigned yet
73+
* @deprecated use {@link #getControl(LivingEntity)} instead
7174
*/
72-
@SuppressWarnings("unchecked")
75+
@Deprecated
7376
public static <E extends LivingEntity> ControllableMob<E> get(E entity) throws IllegalStateException {
74-
if(!entities.containsKey(entity)) throw new IllegalStateException("entity "+entity.toString()+" is not assigned yet");
75-
return (ControllableMob<E>) entities.get(entity);
77+
return getControl(entity);
7678
}
7779

7880
/**
@@ -82,11 +84,11 @@ public static <E extends LivingEntity> ControllableMob<E> get(E entity) throws I
8284
* @param entity which you want to control
8385
* @return the {@link ControllableMob} you can use to control the entity
8486
* @throws InvalidEntityException when the entity is null or can't be controlled
87+
* @deprecated use {@link #getOrPutUnderControl(LivingEntity)} instead
8588
*/
86-
@SuppressWarnings("unchecked")
89+
@Deprecated
8790
public static <E extends LivingEntity> ControllableMob<E> getOrAssign(E entity) throws InvalidEntityException {
88-
if(entities.containsKey(entity)) return (ControllableMob<E>) entities.get(entity);
89-
else return assign(entity);
91+
return getOrPutUnderControl(entity);
9092
}
9193

9294
/**
@@ -98,11 +100,11 @@ public static <E extends LivingEntity> ControllableMob<E> getOrAssign(E entity)
98100
* @param clearAI a boolean indicating whether default behaviors should be removed (true) or not (false).
99101
* @return the {@link ControllableMob} you can use to control the entity
100102
* @throws InvalidEntityException when the entity is null or can't be controlled
103+
* @deprecated use {@link #getOrPutUnderControl(LivingEntity, boolean)} instead
101104
*/
102-
@SuppressWarnings("unchecked")
105+
@Deprecated
103106
public static <E extends LivingEntity> ControllableMob<E> getOrAssign(E entity, boolean clearAI) throws InvalidEntityException {
104-
if(entities.containsKey(entity)) return (ControllableMob<E>) entities.get(entity);
105-
else return assign(entity, clearAI);
107+
return getOrPutUnderControl(entity, clearAI);
106108
}
107109

108110
/**
@@ -113,9 +115,11 @@ public static <E extends LivingEntity> ControllableMob<E> getOrAssign(E entity,
113115
* @return the {@link ControllableMob} you can use to control the entity
114116
* @throws InvalidEntityException when the entity is null or can't be controlled
115117
* @throws IllegalStateException when the entity is already being controlled
118+
* @deprecated use {@link #putUnderControl(LivingEntity)} instead
116119
*/
120+
@Deprecated
117121
public static <E extends LivingEntity> ControllableMob<E> assign(E entity) throws IllegalStateException, InvalidEntityException {
118-
return assign(entity, false);
122+
return putUnderControl(entity);
119123
}
120124

121125
/**
@@ -127,8 +131,129 @@ public static <E extends LivingEntity> ControllableMob<E> assign(E entity) throw
127131
* @return the {@link ControllableMob} you can use to control the entity
128132
* @throws InvalidEntityException when the entity is null or can't be controlled
129133
* @throws IllegalStateException when the entity is already being controlled
134+
* @deprecated use {@link #putUnderControl(LivingEntity, boolean)} instead
130135
*/
136+
@Deprecated
131137
public static <E extends LivingEntity> ControllableMob<E> assign(E entity, boolean clearAI) throws IllegalStateException, InvalidEntityException {
138+
return putUnderControl(entity, clearAI);
139+
}
140+
141+
/**
142+
* Releases the entity from control and restores default behaviors.
143+
* All actions will be stopped immediately, all custom AI behaviors will be removed and default attributes and behaviors will be restored. Frees memory.
144+
* After having this method called, nothing will show that the entity was once controlled.
145+
*
146+
* @see ControllableMobs#unassign(ControllableMob, boolean)
147+
* @param controllableMob the controller which should be unassigned
148+
* @throws IllegalStateException when the controllableMob is already unassigned
149+
* @deprecated use {@link #releaseControl(ControllableMob)} instead
150+
*/
151+
@Deprecated
152+
public static void unassign(ControllableMob<?> controllableMob) throws IllegalStateException {
153+
releaseControl(controllableMob);
154+
}
155+
156+
/**
157+
* Releases the entity from control and restores default behaviors.
158+
* All actions will be stopped immediately, all custom AI behaviors will be removed and default behaviors (and attributes, if specified) will be restored. Frees memory.
159+
* After having this method called, nothing will show that the entity was once controlled.
160+
*
161+
* @param controllableMob the controller which should be unassigned
162+
* @param resetAttributes whether to also reset attributes (movement speed, attack damage, etc.) to their default values. Removes custom modifiers. Default ist true.
163+
* @throws IllegalStateException when the controllableMob is already unassigned
164+
* @deprecated use {@link #releaseControl(ControllableMob, boolean)} instead
165+
*/
166+
@Deprecated
167+
public static void unassign(ControllableMob<?> controllableMob, boolean resetAttributes) throws IllegalStateException {
168+
releaseControl(controllableMob, resetAttributes);
169+
}
170+
171+
172+
173+
174+
175+
/**
176+
* Retrieves whether the specified entity has already been assigned.
177+
*
178+
* @param entity to check for a {@link ControllableMob} instance
179+
* @return whether the entity has been put under control ({@link ControllableMob} instance is available)
180+
*/
181+
public static boolean isUnderControl(LivingEntity entity) {
182+
return entities.containsKey(entity);
183+
}
184+
185+
186+
/**
187+
* Retrieves a {@link ControllableMob} instance for an entity that had been put under control previously.
188+
*
189+
* @param entity which is already under control
190+
* @return the {@link ControllableMob} you can use to control the entity
191+
* @throws IllegalStateException when the entity has not been put under control yet
192+
*/
193+
@SuppressWarnings("unchecked")
194+
public static <E extends LivingEntity> ControllableMob<E> getControl(E entity) throws IllegalStateException {
195+
if(!entities.containsKey(entity)) throw new IllegalStateException("entity "+entity.toString()+" is not put under control yet");
196+
return (ControllableMob<E>) entities.get(entity);
197+
}
198+
199+
200+
/**
201+
* Simply retrieves a {@link ControllableMob} instance if the passed entity has been put under control, or puts it under control.
202+
* Combines {@link ControllableMobs#getControl(LivingEntity)} and {@link ControllableMobs#putUnderControl(LivingEntity)}.
203+
*
204+
* @param entity which you want to control
205+
* @return the {@link ControllableMob} you can use to control the entity
206+
* @throws InvalidEntityException when the entity is null or can't be controlled
207+
*/
208+
@SuppressWarnings("unchecked")
209+
public static <E extends LivingEntity> ControllableMob<E> getOrPutUnderControl(E entity) throws InvalidEntityException {
210+
if(entities.containsKey(entity)) return (ControllableMob<E>) entities.get(entity);
211+
else return putUnderControl(entity);
212+
}
213+
214+
215+
/**
216+
* Simply retrieves a {@link ControllableMob} instance if the passed entity has been put under control, or puts it under control.
217+
* Combines {@link ControllableMobs#getControl(LivingEntity)} and {@link ControllableMobs#putUnderControl(LivingEntity, boolean)}
218+
* Clearing the AI is only being performed when clearAI is true and the entity is being assigned for the first time.
219+
*
220+
* @param entity which you want to control
221+
* @param clearAI a boolean indicating whether default behaviors should be removed (true) or not (false).
222+
* @return the {@link ControllableMob} you can use to control the entity
223+
* @throws InvalidEntityException when the entity is null or can't be controlled
224+
*/
225+
@SuppressWarnings("unchecked")
226+
public static <E extends LivingEntity> ControllableMob<E> getOrPutUnderControl(E entity, boolean clearAI) throws InvalidEntityException {
227+
if(entities.containsKey(entity)) return (ControllableMob<E>) entities.get(entity);
228+
else return putUnderControl(entity, clearAI);
229+
}
230+
231+
232+
/**
233+
* Simply puts the entity under your control.
234+
* Will not change any default behaviors, the entity will continue to act normally.
235+
*
236+
* @param entity an instance of a subclass of LivingEntity - the entity you want to control
237+
* @return the {@link ControllableMob} you can use to control the entity
238+
* @throws InvalidEntityException when the entity is null or can't be controlled
239+
* @throws IllegalStateException when the entity is already being controlled
240+
*/
241+
public static <E extends LivingEntity> ControllableMob<E> putUnderControl(E entity) throws IllegalStateException, InvalidEntityException {
242+
return putUnderControl(entity, false);
243+
}
244+
245+
246+
/**
247+
* Simply puts the entity under your control, optionally clearing its AI.
248+
* If you decide to clear its AI, the entity will stop moving and attacking and stand still until you order it to execute any actions.
249+
*
250+
* @param entity an instance of a subclass of LivingEntity - the entity you want to control
251+
* @param clearAI a boolean indicating whether default behaviors should be removed (true) or not (false)
252+
* @return the {@link ControllableMob} you can use to control the entity
253+
* @throws InvalidEntityException when the entity is null or can't be controlled
254+
* @throws IllegalStateException when the entity is already being controlled
255+
*/
256+
public static <E extends LivingEntity> ControllableMob<E> putUnderControl(E entity, boolean clearAI) throws IllegalStateException, InvalidEntityException {
132257
if(entity==null) throw new InvalidEntityException("entity must not be null",entity);
133258
EntityLiving notchEntity = ((CraftLivingEntity) entity).getHandle();
134259
if(!(notchEntity instanceof EntityInsentient)) throw new InvalidEntityException("the entity "+entity.toString()+" can't be controlled",entity);
@@ -141,6 +266,7 @@ public static <E extends LivingEntity> ControllableMob<E> assign(E entity, boole
141266
return controllableMob;
142267
}
143268

269+
144270
/**
145271
* Releases the entity from control and restores default behaviors.
146272
* All actions will be stopped immediately, all custom AI behaviors will be removed and default attributes and behaviors will be restored. Frees memory.
@@ -150,10 +276,11 @@ public static <E extends LivingEntity> ControllableMob<E> assign(E entity, boole
150276
* @param controllableMob the controller which should be unassigned
151277
* @throws IllegalStateException when the controllableMob is already unassigned
152278
*/
153-
public static void unassign(ControllableMob<?> controllableMob) throws IllegalStateException {
154-
unassign(controllableMob, true);
279+
public static void releaseControl(ControllableMob<?> controllableMob) throws IllegalStateException {
280+
releaseControl(controllableMob, true);
155281
}
156282

283+
157284
/**
158285
* Releases the entity from control and restores default behaviors.
159286
* All actions will be stopped immediately, all custom AI behaviors will be removed and default behaviors (and attributes, if specified) will be restored. Frees memory.
@@ -163,8 +290,8 @@ public static void unassign(ControllableMob<?> controllableMob) throws IllegalSt
163290
* @param resetAttributes whether to also reset attributes (movement speed, attack damage, etc.) to their default values. Removes custom modifiers. Default ist true.
164291
* @throws IllegalStateException when the controllableMob is already unassigned
165292
*/
166-
public static void unassign(ControllableMob<?> controllableMob, boolean resetAttributes) throws IllegalStateException {
167-
if(!entities.containsKey(controllableMob.getEntity())) throw new IllegalStateException("entity "+controllableMob.toString()+" is already unassigned");
293+
public static void releaseControl(ControllableMob<?> controllableMob, boolean resetAttributes) throws IllegalStateException {
294+
if(!entities.containsKey(controllableMob.getEntity())) throw new IllegalStateException("entity "+controllableMob.toString()+" is already released from control");
168295
entities.remove(controllableMob.getEntity());
169296
((CraftControllableMob<?>) controllableMob).unassign(resetAttributes);
170297
}

0 commit comments

Comments
 (0)