diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.java index 2fce49e12..e6c507b59 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.java @@ -248,28 +248,35 @@ public abstract class Entity { public TreeMap getEntityMetaDataFormatted() { // scan all methods of current class for EntityMetaDataFunction annotation and write it into a list - Class clazz = this.getClass(); TreeMap values = new TreeMap<>(); - for (Method method : clazz.getMethods()) { - if (!method.isAnnotationPresent(EntityMetaDataFunction.class)) { - continue; - } - if (method.getParameterCount() > 0) { - continue; - } - try { - String identifier = method.getAnnotation(EntityMetaDataFunction.class).identifier(); - if (values.containsKey(identifier)) { + if (this.metaData == null) { + return values; + } + Class clazz = this.getClass(); + while (clazz != Object.class) { + for (Method method : clazz.getDeclaredMethods()) { + if (!method.isAnnotationPresent(EntityMetaDataFunction.class)) { continue; } - Object methodRetValue = method.invoke(this); - if (methodRetValue == null) { + if (method.getParameterCount() > 0) { continue; } - values.put(identifier, methodRetValue); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); + method.setAccessible(true); + try { + String identifier = method.getAnnotation(EntityMetaDataFunction.class).identifier(); + if (values.containsKey(identifier)) { + continue; + } + Object methodRetValue = method.invoke(this); + if (methodRetValue == null) { + continue; + } + values.put(identifier, methodRetValue); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } } + clazz = clazz.getSuperclass(); } return values; } diff --git a/src/main/java/de/bixilon/minosoft/terminal/commands/commands/CommandEntities.java b/src/main/java/de/bixilon/minosoft/terminal/commands/commands/CommandEntities.java index 6de3ac7f4..edd9d59c9 100644 --- a/src/main/java/de/bixilon/minosoft/terminal/commands/commands/CommandEntities.java +++ b/src/main/java/de/bixilon/minosoft/terminal/commands/commands/CommandEntities.java @@ -14,8 +14,12 @@ package de.bixilon.minosoft.terminal.commands.commands; import com.github.freva.asciitable.AsciiTable; +import de.bixilon.minosoft.data.commands.CommandArgumentNode; import de.bixilon.minosoft.data.commands.CommandLiteralNode; import de.bixilon.minosoft.data.commands.CommandNode; +import de.bixilon.minosoft.data.commands.parser.IntegerParser; +import de.bixilon.minosoft.data.commands.parser.properties.IntegerParserProperties; +import de.bixilon.minosoft.data.entities.entities.Entity; import java.util.ArrayList; @@ -24,7 +28,7 @@ public class CommandEntities extends Command { @Override public CommandNode build(CommandNode parent) { parent.addChildren( - new CommandLiteralNode("entities", + new CommandLiteralNode("entity", new CommandLiteralNode("list", (connection, stack) -> { ArrayList tableData = new ArrayList<>(); @@ -33,7 +37,33 @@ public class CommandEntities extends Command { } print(AsciiTable.getTable(new String[]{"ID", "UUID", "TYPE", "EQUIPMENT", "LOCATION", "ROTATION"}, tableData.toArray(new Object[0][0]))); - }))); + }), + new CommandLiteralNode("info", new CommandArgumentNode("entityId", IntegerParser.INTEGER_PARSER, new IntegerParserProperties(0, Integer.MAX_VALUE), (connection, stack) -> { + // ToDo: entity uuids + + Entity entity = connection.getPlayer().getWorld().getEntity(stack.getInt(0)); + if (entity == null) { + printError("Entity %d not found!", stack.getInt(0)); + return; + } + ArrayList tableData = new ArrayList<>(); + + tableData.add(new Object[]{"entity id", entity.getEntityId()}); + tableData.add(new Object[]{"uuid", entity.getUUID()}); + tableData.add(new Object[]{"type", entity.getEntityInformation()}); + tableData.add(new Object[]{"class", entity.getClass().getName()}); + tableData.add(new Object[]{"location", entity.getLocation()}); + tableData.add(new Object[]{"rotation", entity.getRotation()}); + tableData.add(new Object[]{"equipment", entity.getEquipment()}); + tableData.add(new Object[]{"effects", entity.getEffectList()}); + tableData.add(new Object[]{"attached to", entity.getAttachedEntity() == -1 ? "" : entity.getAttachedEntity()}); + + for (var entry : entity.getEntityMetaDataFormatted().entrySet()) { + tableData.add(new Object[]{entry.getKey(), entry.getValue()}); + } + + print(AsciiTable.getTable(new String[]{"PROPERTY", "VALUE"}, tableData.toArray(new Object[0][0]))); + })))); return parent; } }