diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a74619b..3f229b5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,16 +5,8 @@ - - - - - - - - - - + + diff --git a/src/main/java/me/tofaa/entitylib/EntityLib.java b/src/main/java/me/tofaa/entitylib/EntityLib.java index 160039a..d1e4176 100644 --- a/src/main/java/me/tofaa/entitylib/EntityLib.java +++ b/src/main/java/me/tofaa/entitylib/EntityLib.java @@ -127,12 +127,11 @@ public final class EntityLib { * @param entityType the entity type * @return the created entity, or null if the entity could not be created */ - public static @Nullable WrapperEntity createEntity(int entityId, UUID uuid, EntityType entityType) { + public static @NotNull WrapperEntity createEntity(int entityId, UUID uuid, EntityType entityType) { checkInit(); if (entities.containsKey(uuid)) throw new RuntimeException("An entity with that uuid already exists"); if (entitiesById.containsKey(entityId)) throw new RuntimeException("An entity with that id already exists"); EntityMeta meta = createMeta(entityId, entityType); - if (meta == null) return null; WrapperEntity entity; if (meta instanceof LivingEntityMeta) { entity = new WrapperLivingEntity(entityId, uuid, entityType, meta); @@ -145,7 +144,7 @@ public final class EntityLib { return entity; } - public static @Nullable WrapperEntity createEntity(@NotNull UUID uuid, EntityType entityType) { + public static @NotNull WrapperEntity createEntity(@NotNull UUID uuid, EntityType entityType) { return createEntity(entityIdProvider.provide(), uuid, entityType); } @@ -182,11 +181,11 @@ public final class EntityLib { * @param entityType the entity type * @return the created EntityMeta */ - public static EntityMeta createMeta(int entityId, EntityType entityType) { + public static @NotNull EntityMeta createMeta(int entityId, EntityType entityType) { checkInit(); Metadata m = new Metadata(entityId); BiFunction function = metaRegistry.get(entityType); - EntityMeta meta = function.apply(entityId, m); + EntityMeta meta = function.apply(entityId, m); metadata.put(entityId, meta); return meta; } diff --git a/test-plugin/src/main/java/me/tofaa/entitylib/TestDisplayCommand.java b/test-plugin/src/main/java/me/tofaa/entitylib/TestDisplayCommand.java index 99fedd4..6e11437 100644 --- a/test-plugin/src/main/java/me/tofaa/entitylib/TestDisplayCommand.java +++ b/test-plugin/src/main/java/me/tofaa/entitylib/TestDisplayCommand.java @@ -6,6 +6,7 @@ import me.tofaa.entitylib.entity.WrapperEntity; import me.tofaa.entitylib.meta.display.TextDisplayMeta; import me.tofaa.entitylib.meta.types.DisplayMeta; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -18,14 +19,13 @@ public class TestDisplayCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { - + Player player = (Player) commandSender; WrapperEntity e = EntityLib.createEntity(UUID.randomUUID(), EntityTypes.TEXT_DISPLAY); TextDisplayMeta meta = (TextDisplayMeta) e.getMeta(); - meta.setText(Component.text("Hello World!")); + meta.setText(Component.text("Hello World!", NamedTextColor.GOLD)); meta.setBillboardConstraints(DisplayMeta.BillboardConstraints.CENTER); - e.addViewer(((Player) commandSender).getUniqueId()); - e.spawn(SpigotConversionUtil.fromBukkitLocation(((Player) commandSender).getLocation())); - commandSender.sendMessage("Entity spawned! ID: " + e.getEntityId() + " Type: " + e.getEntityType() + " Text: " + meta.getText()); + e.addViewer((player.getUniqueId())); + e.spawn(SpigotConversionUtil.fromBukkitLocation((player.getLocation().clone().add(0, 2, 0)))); return true; } }