Merge pull request #100 from Shadowrs/development

Special case: add universal getter for hash() for debug classes
This commit is contained in:
Jeroen Ketelaar
2018-10-21 15:27:58 -05:00
committed by GitHub
6 changed files with 35 additions and 10 deletions
@@ -1,6 +1,8 @@
package org.rev317.min.api.wrappers;
import org.parabot.core.Context;
import org.parabot.core.reflect.RefClass;
import org.parabot.core.reflect.RefMethod;
import org.rev317.min.accessors.SceneObjectTile;
import org.rev317.min.api.interfaces.Locatable;
import org.rev317.min.api.methods.Calculations;
@@ -35,6 +37,27 @@ public class SceneObject implements Locatable {
return accessor.getHash();
}
/**
* Resolves the hash depending on the API's inner SceneObjectTile getHash() methods' type.
* <br>This is strictly to be used only by Debug classes such as {@code DSceneObjects} due to the overhead of Reflection.
* In cases of high usage, classes should be duplicated as usual in a custom API with the required changed type.
* @return An object, casted to either Long or Int
*/
public final Object resolveHash() {
Object hash = (int) 0;
try {
RefMethod hashMethod = new RefClass(Context.getInstance().getASMClassLoader().loadClass("org.rev317.min.accessors.SceneObjectTile"), accessor).getMethod("getHash");
if (hashMethod.getReturnType() == int.class) {
hash = (int) hashMethod.invoke();
} else {
hash = (long) hashMethod.invoke();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return hash;
}
/**
* Gets location of this tile
*
@@ -34,7 +34,7 @@ public class DSceneObjectsGroundDec extends AbstractDebugger {
if (enabled) {
SceneObject[] objects = getGroundDecorations();
if (objects == null || objects.length == 0) {
Logger.addMessage("There are no GameObjects around you.");
Logger.addMessage("There are no Ground Decorations around you.");
return;
}
java.util.List<SceneObject> objs = Arrays.asList(objects);
@@ -44,7 +44,7 @@ public class DSceneObjectsGroundDec extends AbstractDebugger {
for (int i = objects.length - 1; i >= 0; i--) {
System.out.println(
" ID: " + objects[i].getId() +
" UID: " + objects[i].getHash() +
" UID: " + objects[i].resolveHash() +
" Location: " + objects[i].getLocation() +
" Distance: " + objects[i].distanceTo());
}
@@ -34,7 +34,7 @@ public class DSceneObjectsGroundItems extends AbstractDebugger {
if (enabled) {
SceneObject[] objects = getGroundItems();
if (objects == null || objects.length == 0) {
Logger.addMessage("There are no GameObjects around you.");
Logger.addMessage("There are no Ground Items around you.");
return;
}
java.util.List<SceneObject> objs = Arrays.asList(objects);
@@ -44,7 +44,7 @@ public class DSceneObjectsGroundItems extends AbstractDebugger {
for (int i = objects.length - 1; i >= 0; i--) {
System.out.println(
" ID: " + objects[i].getId() +
" UID: " + objects[i].getHash() +
" UID: " + objects[i].resolveHash() +
" Location: " + objects[i].getLocation() +
" Distance: " + objects[i].distanceTo());
}
@@ -3,6 +3,8 @@ package org.rev317.min.debug;
import org.parabot.core.Context;
import org.parabot.core.paint.AbstractDebugger;
import org.parabot.core.paint.PaintDebugger;
import org.parabot.core.reflect.RefClass;
import org.parabot.core.reflect.RefMethod;
import org.parabot.core.ui.Logger;
import org.parabot.environment.api.utils.Filter;
import org.rev317.min.api.methods.SceneObjects;
@@ -35,7 +37,7 @@ public class DSceneObjectsInteractiveObj extends AbstractDebugger {
if (enabled) {
SceneObject[] objects = getInteractiveObjects();
if (objects == null || objects.length == 0) {
Logger.addMessage("There are no GameObjects around you.");
Logger.addMessage("There are no Interactive Objects around you.");
return;
}
java.util.List<SceneObject> objs = Arrays.asList(objects);
@@ -45,7 +47,7 @@ public class DSceneObjectsInteractiveObj extends AbstractDebugger {
for (int i = objects.length - 1; i >= 0; i--) {
System.out.println(
" ID: " + objects[i].getId() +
" UID: " + objects[i].getHash() +
" UID: " + objects[i].resolveHash() +
" Location: " + objects[i].getLocation() +
" Distance: " + objects[i].distanceTo());
}
@@ -34,7 +34,7 @@ public class DSceneObjectsWallDec extends AbstractDebugger {
if (enabled) {
SceneObject[] objects = getWallDecorations();
if (objects == null || objects.length == 0) {
Logger.addMessage("There are no GameObjects around you.");
Logger.addMessage("There are no Wall Decorations around you.");
return;
}
java.util.List<SceneObject> objs = Arrays.asList(objects);
@@ -44,7 +44,7 @@ public class DSceneObjectsWallDec extends AbstractDebugger {
for (int i = objects.length - 1; i >= 0; i--) {
System.out.println(
" ID: " + objects[i].getId() +
" UID: " + objects[i].getHash() +
" UID: " + objects[i].resolveHash() +
" Location: " + objects[i].getLocation() +
" Distance: " + objects[i].distanceTo());
}
@@ -34,7 +34,7 @@ public class DSceneObjectsWallObj extends AbstractDebugger {
if (enabled) {
SceneObject[] objects = getWallObjects();
if (objects == null || objects.length == 0) {
Logger.addMessage("There are no GameObjects around you.");
Logger.addMessage("There are no Wall Objects around you.");
return;
}
java.util.List<SceneObject> objs = Arrays.asList(objects);
@@ -44,7 +44,7 @@ public class DSceneObjectsWallObj extends AbstractDebugger {
for (int i = objects.length - 1; i >= 0; i--) {
System.out.println(
" ID: " + objects[i].getId() +
" UID: " + objects[i].getHash() +
" UID: " + objects[i].resolveHash() +
" Location: " + objects[i].getLocation() +
" Distance: " + objects[i].distanceTo());
}