JonyGamesYT9 / EntityAPI

An API of entities so that they can create entities easily.
Apache License 2.0
5 stars 2 forks source link

EntityAPI | v2.0

An API of entities so that they can create entities easily.

🎮 API Usage:

Import the class:

Put these classes in your plugin, so you can easily access the API.

<?php 

use JonyGamesYT9\EntityAPI\EntityAPI;
use JonyGamesYT9\EntityAPI\entity\types\NPC;
use JonyGamesYT9\EntityAPI\entity\EntityFactory;

Code to spawn entity:

Use this method to make an entity appear.

<?php 

EntityFactory::getInstance()->create($location, $skin, $name, $scale);

The $location variable is getting the Location class, In the variable $skin is getting the Skin class, In the variable $name replace it with the name of the entity (No Nametag) (String Tag), In the variable $scale put the size of the entity (Float Scale) (Default: 1.0)

Example:

<?php

EntityFactory::getInstance()->create(Player->getLocation(), Player->getSkin(), "minigame_1", 1.4);

Code to kill entity:

Use this code to disappear an entity.

<?php 

EntityFactory::getInstance()->eliminate($name, $world); // Replace the variable $name with the name of the entity, Replace the variable $world for delete a entities in that world.

Example:

<?php

EntityFactory::getInstance()->eliminate("minigame_1", Player->getPosition()->getWorld());

Or to remove all entities use:

<?php 

EntityFactory::getInstance()->eliminateAll($name); // Doing this will eliminate entities with selected name from all worlds.

Code to create repeating task:

To create a task with the entity you can use this example:

Import Class:

<?php

use pocketmine\Server;
use JonyGamesYT9\EntityAPI\entity\types\NPC;

Code:

<?php 

public function onRun(): void {
  foreach (Server::getInstance()->getWorldManager()->getWorlds() as $worlds) {
    foreach ($worlds->getEntities() as $entities) {
      if ($entities instanceof NPC) {
        switch ($entities->getIdName()) {
          case "name":
          $entities->setNameTag("Entity NameTag");
          $entities->setScale($entities->getScaleCustom());
          $entities->setNameTagAlwaysVisible(true);
          break;
        }
      }
    }
  }
}

Code to create an event:

By doing this example you will make hitting the entity do an action.

Import Class:

<?php 

use pocketmine\event\entity\EntityDamageEventByEntityEvent;
use pocketmine\player\Player;
use pocketmine\Server;
use JonyGamesYT9\EntityAPI\entity\types\NPC;

Code:

<?php 

public function onDamageNpc(EntityDamageEventByEntityEvent $event): void {
  $npc = $event->getEntity();
  $player = $event->getDamager();
  if ($player instanceof Player && $npc instanceof NPC) {
    switch ($npc->getIdName()) {
      case "name":
      // This is an example that if you hit the entity the player executes the command /me
      Server::getInstance()->dispatchCommand($player, "me Tap an entity with the JonyGamesYT9 API :D");
      $event->cancel(); // Hitting the entity does not take damage
      break;
    }
  }
}

âš¡ Features:

📋 Icon:

Icon Credits: https://co.pinterest.com/edison4138/skins-de-minecraft/

📖 Project information:

Plugin Version PocketMine API PHP Version Plugin Status
2.0 4.0.0 8 Completed