mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
fixes, entity info command
This commit is contained in:
parent
102a0f4862
commit
0206d7fb7f
@ -248,15 +248,20 @@ public abstract class Entity {
|
|||||||
|
|
||||||
public TreeMap<String, Object> getEntityMetaDataFormatted() {
|
public TreeMap<String, Object> getEntityMetaDataFormatted() {
|
||||||
// scan all methods of current class for EntityMetaDataFunction annotation and write it into a list
|
// scan all methods of current class for EntityMetaDataFunction annotation and write it into a list
|
||||||
Class<? extends Entity> clazz = this.getClass();
|
|
||||||
TreeMap<String, Object> values = new TreeMap<>();
|
TreeMap<String, Object> values = new TreeMap<>();
|
||||||
for (Method method : clazz.getMethods()) {
|
if (this.metaData == null) {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
Class<?> clazz = this.getClass();
|
||||||
|
while (clazz != Object.class) {
|
||||||
|
for (Method method : clazz.getDeclaredMethods()) {
|
||||||
if (!method.isAnnotationPresent(EntityMetaDataFunction.class)) {
|
if (!method.isAnnotationPresent(EntityMetaDataFunction.class)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (method.getParameterCount() > 0) {
|
if (method.getParameterCount() > 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
method.setAccessible(true);
|
||||||
try {
|
try {
|
||||||
String identifier = method.getAnnotation(EntityMetaDataFunction.class).identifier();
|
String identifier = method.getAnnotation(EntityMetaDataFunction.class).identifier();
|
||||||
if (values.containsKey(identifier)) {
|
if (values.containsKey(identifier)) {
|
||||||
@ -271,6 +276,8 @@ public abstract class Entity {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
clazz = clazz.getSuperclass();
|
||||||
|
}
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,12 @@
|
|||||||
package de.bixilon.minosoft.terminal.commands.commands;
|
package de.bixilon.minosoft.terminal.commands.commands;
|
||||||
|
|
||||||
import com.github.freva.asciitable.AsciiTable;
|
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.CommandLiteralNode;
|
||||||
import de.bixilon.minosoft.data.commands.CommandNode;
|
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;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@ -24,7 +28,7 @@ public class CommandEntities extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public CommandNode build(CommandNode parent) {
|
public CommandNode build(CommandNode parent) {
|
||||||
parent.addChildren(
|
parent.addChildren(
|
||||||
new CommandLiteralNode("entities",
|
new CommandLiteralNode("entity",
|
||||||
new CommandLiteralNode("list", (connection, stack) -> {
|
new CommandLiteralNode("list", (connection, stack) -> {
|
||||||
ArrayList<Object[]> tableData = new ArrayList<>();
|
ArrayList<Object[]> 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])));
|
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<Object[]> 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;
|
return parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user