Fixed getBytes() exception

Only objects that are in objectList are added to the Quadtree. Prevents
later errors where the quadtree objects would not be found in
objectList. After all such objects should not even be around, but well
...
This commit is contained in:
CharonInferar
2014-10-05 18:48:34 +02:00
parent 8520db18e2
commit e863548182
2 changed files with 57 additions and 0 deletions
@@ -21,6 +21,9 @@
******************************************************************************/
package resources.objects.creature;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -1431,6 +1434,9 @@ public class CreatureObject extends TangibleObject implements IPersistent {
public void sendBaselines(Client destination) {
if (destination != null && destination.getSession() != null) {
//objectFieldDiagnosis();
destination.getSession().write(getBaseline(3).getBaseline());
destination.getSession().write(getBaseline(6).getBaseline());
if (destination == getClient()) {
@@ -1451,6 +1457,45 @@ public class CreatureObject extends TangibleObject implements IPersistent {
}
}
// Utility method to check which fields are null
public void objectFieldDiagnosis(){
System.out.println("Object being diagnosed: " + this.getTemplate() + " Id: " + this.getObjectID());
ArrayList<Method> list = new ArrayList<Method>();
Method[] methods = this.getClass().getDeclaredMethods();
for (Method method : methods)
if (isGetter(method)){
try {
Object valueObject = method.invoke(this, (Object[]) null);
if (valueObject==null){
System.err.println("method " + method.getName() + " delivers null object");
}
} catch (IllegalAccessException e) {
System.err.println("IllegalAccessException during reflection");
e.printStackTrace();
} catch (IllegalArgumentException e) {
System.err.println("IllegalArgumentException during reflection");
e.printStackTrace();
} catch (InvocationTargetException e) {
System.err.println("InvocationTargetException during reflection");
e.printStackTrace();
}
}
}
public static boolean isGetter(Method method) {
if (Modifier.isPublic(method.getModifiers()) &&
method.getParameterTypes().length == 0) {
if (method.getName().matches("^get[A-Z].*") &&
!method.getReturnType().equals(void.class))
return true;
if (method.getName().matches("^is[A-Z].*") &&
method.getReturnType().equals(boolean.class))
return true;
}
return false;
}
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
switch (viewType) {
case 1: