├── images └── model.png ├── resources ├── config.yml ├── kor.yml └── eng.yml ├── .poggit.yml ├── src └── alvin0319 │ └── NPC │ ├── util │ ├── FileNotFoundException.php │ ├── InvalidLanguageException.php │ ├── ExtensionNotLoadedException.php │ ├── Image.php │ └── Promise.php │ ├── Queue.php │ ├── task │ └── CheckVersionAsyncTask.php │ ├── config │ ├── ImageConfig.php │ └── EntityConfig.php │ ├── lang │ └── PluginLang.php │ ├── entity │ ├── CustomEntity.php │ ├── NPCHuman.php │ └── EntityBase.php │ ├── EventListener.php │ └── NPCPlugin.php ├── plugin.yml ├── .github └── ISSUE_TEMPLATE │ ├── api_change.md │ ├── feature_request.md │ ├── issue_template.md │ └── bug_report.md ├── Custom_Modeling_usage.md ├── updates.json ├── README.md └── LICENSE /images/model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Plugins-PocketMineMP/NPC/HEAD/images/model.png -------------------------------------------------------------------------------- /resources/config.yml: -------------------------------------------------------------------------------- 1 | images: [] 2 | 3 | lang: eng 4 | 5 | spawn-radius: 10 6 | 7 | disable-see-player: false 8 | 9 | config-version: 1.0.1 -------------------------------------------------------------------------------- /.poggit.yml: -------------------------------------------------------------------------------- 1 | --- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/alvin0319/NPC 2 | branches: 3 | - stable 4 | projects: 5 | NPC: 6 | path: "" 7 | ... 8 | -------------------------------------------------------------------------------- /src/alvin0319/NPC/util/FileNotFoundException.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | What do you want to change? 7 | --------------------------- 8 | 9 | 10 | 11 | * Function 1: ... 12 | 13 | * Function 2: ... 14 | 15 | Additional content 16 | ------------------ 17 | .... -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Issue Description 11 | ----------------- 12 | 13 | 14 | 15 | What do you want to change? 16 | --------------------------- 17 | 18 | 19 | 20 | * Function 1: ... 21 | 22 | * Function 2: ... 23 | 24 | Additional content 25 | ------------------ 26 | .... 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issue_template.md: -------------------------------------------------------------------------------- 1 | Issue Description 2 | ----------------- 3 | 4 | 5 | 6 | How do you reproduce it? 7 | ------------------------ 8 | 9 | 10 | 11 | * Step 1: ... 12 | 13 | * Step 2: ... 14 | 15 | Your System information 16 | -------------------------- 17 | 18 | * OS: Ubuntu/Windows 19 | 20 | * Your PocketMine-MP Version: 21 | 22 | * Plugin Version: -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Issue Description 11 | ----------------- 12 | 13 | 14 | 15 | How do you reproduce it? 16 | ------------------------ 17 | 18 | 19 | 20 | * Step 1: ... 21 | 22 | * Step 2: ... 23 | 24 | Your System information 25 | -------------------------- 26 | 27 | * OS: Ubuntu/Windows 28 | 29 | * Your PocketMine-MP Version: 30 | 31 | * Plugin Version: 32 | -------------------------------------------------------------------------------- /Custom_Modeling_usage.md: -------------------------------------------------------------------------------- 1 | # Description 2 | If you want to add your custom skin or modeling, you can do it. 3 | 4 | Follow this step if you want to do. 5 | 6 | 1. Put skin/modeling png file to `your_server_folder/plugin_data/NPC/images` folder. 7 | 2. If you want to apply geometry file, also put .json file to `your_server_folder/plugin_data/NPC/images` folder. 8 | 3. And, Join the server and type `/npc create your_npc_name npc your_skinfile_name.png your_geometry_file.json`. The geometry option is optional. 9 | 4. You can apply your Modeling like this! ![](https://raw.githubusercontent.com/alvin0319/NPC/master/images/model.png) 10 | 11 | 12 | And, to apply modeling, you need to have the gd extension installed in your php binary. -------------------------------------------------------------------------------- /updates.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.8", "updates": { 3 | "1.0.0": { 4 | "message": "First release", "mustUpdate": false 5 | }, "1.0.1": { 6 | "message": "stable support", "mustUpdate": false 7 | }, "1.0.3": { 8 | "message": "add scale, and fix some bugs, and rewrite EntityBase code.", "mustUpdate": true 9 | }, "1.0.4": { 10 | "message": "Fixed an error message when not in remove mode, and added plugin dependencies.", "mustUpdate": true 11 | }, "1.0.5": { 12 | "message": "Add item", "mustUpdate": false 13 | }, "1.0.6": { 14 | "message": "Fix some bugs", "mustUpdate": false 15 | }, "1.0.7": { 16 | "message": "Fix for plugin", "mustUpdate": false 17 | }, "1.0.8": { 18 | "message": "Off hand, and fix some bugs", "mustUpdate": false 19 | }, "1.0.9": { 20 | "message": "Update with latest PMMP changes", "mustUpdate": false 21 | }, "1.0.10": { 22 | "message": "Fix code logic, Update protocol, added disable npc rotation follow option.", "mustUpdate": false 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NPC 2 | 3 | The NPC plugin for [PocketMine-MP](https://github.com/pmmp/PocketMine-MP) 4 | 5 | This plugin is designed for **[PocketMine-MP](https://github.com/pmmp/PocketMine-MP)** and may not work with other **spoons or forks**. 6 | 7 | [![](https://poggit.pmmp.io/shield.state/NPC)](https://poggit.pmmp.io/p/NPC) 8 | 9 | |command|usage| 10 | |------|---| 11 | |/npc create [type] [name] [skinPath(optional)] [geometryPath(optional)|Create an entity. 12 | |/npc remove|Remove an entity. 13 | |/npc edit [message/command/scale] [args...]|Edit an entity. 14 | |/npc get|Get an entities. 15 | 16 | ### Feature 17 | 18 | >Doesn't use entity class. 19 | > 20 | >You can create & modify the entities you want. 21 | > 22 | >You can apply your own skin. 23 | > 24 | >Modeling can also be applied. 25 | 26 | If you want to apply modeling, you need to put geometryName: "your geometry name" in the json file created with BlockBench. 27 | 28 | ![](https://raw.githubusercontent.com/alvin0319/NPC/stable/images/model.png) 29 | 30 | [Custom Modeling usage](https://github.com/alvin0319/NPC/blob/stable/Custom_Modeling_usage.md) -------------------------------------------------------------------------------- /resources/kor.yml: -------------------------------------------------------------------------------- 1 | plugin.prefix: "§b§l[NPC] §r§7" 2 | ext-gd.missing: "현재 실행중인 PHP 바이너리에 gd 라이브러리가 설치되어 있지 않습니다." 3 | path.notExist: "{%0} 파일이 존재하지 않습니다." 4 | entity.spawn: "{%0} 엔티티가 생성되었습니다." 5 | entity.path: "스킨 파일이나 모델링 파일의 경로를 입력해주세요." 6 | entity.geometry: "해당 geometry 파일에 geometryName이 존재하지 않습니다." 7 | entity.notExist: "해당 종류의 엔티티가 존재하지 않습니다." 8 | entity.delete: "엔티티를 성공적으로 제거했습니다." 9 | entity.notExistId: "해당 엔티티는 존재하지 않습니다." 10 | command.create.usage: "/npc create [타입] [이름] [스킨 경로(필요시)] [geometry 경로(필요시)] - 엔티티를 생성합니다." 11 | command.delete.usage: "/npc remove [아이디] - 엔티티를 제거합니다." 12 | command.edit.usage: "/npc edit [command|message|scale] [text...] - 엔티티를 수정합니다." 13 | command.get.usage: "/npc get - 엔티티 목록을 불러옵니다." 14 | command.item.usage: "/npc item - 엔피시의 아이템을 설정합니다." 15 | command.onlyAccept: "{%0}은(는) {%1}만 허용합니다." 16 | command.entity.list: "사용 가능한 엔티티: " 17 | command.list.empty: "등록된 엔티티가 없습니다." 18 | command.list: "엔티티 목록: " 19 | command.remove.message: "제거되길 원하는 엔티티를 터치해주세요." 20 | command.edit.message: "적용되길 원하는 엔티티를 터치해주세요." 21 | message.notExtend: "해당 엔티티는 NPC가 아닙니다." 22 | message.edit.success: "성공적으로 엔티티를 수정했습니다." -------------------------------------------------------------------------------- /resources/eng.yml: -------------------------------------------------------------------------------- 1 | plugin.prefix: "§b§l[NPC] §r§7" 2 | ext-gd.missing: "The gd-extension is not installed" 3 | path.notExist: "The file {%0} is not exist" 4 | entity.spawn: "{%0} entity created" 5 | entity.path: "Please input the Skin or Geometry file path" 6 | entity.geometry: "GeometryName does not exist in the geometry file" 7 | entity.notExist: "That entity is not exist" 8 | entity.delete: "Entity delete successfully" 9 | entity.notExistId: "That entity is not exist" 10 | command.create.usage: "/npc create [type] [name] [skinPath(optional)] [geometryPath(optional)] - Create entity" 11 | command.delete.usage: "/npc remove [id] - Delete entity" 12 | command.edit.usage: "/npc edit [command|message|scale] [text...] - Edit entity" 13 | command.get.usage: "/npc get - Get entities" 14 | command.item.usage: "/npc item - Set item to NPC" 15 | command.onlyAccept: "{%0} is only accept {%1}" 16 | command.entity.list: "Entity list: " 17 | command.list.empty: "The list is empty" 18 | command.list: "The entity list: " 19 | command.remove.message: "Please attack the entity that want to remove npc" 20 | command.edit.message: "Please attack the entity that want to edit" 21 | message.notExtend: "That entity is not NPC" 22 | message.noGeometryName: "Please insert geometryName in {%0}" -------------------------------------------------------------------------------- /src/alvin0319/NPC/util/Image.php: -------------------------------------------------------------------------------- 1 | skinBytes = $skinBytes; 21 | $this->geometryName = $geometryName; 22 | $this->geometryData = $geometryData; 23 | } 24 | 25 | public function getSkinBytes() : string{ 26 | return $this->skinBytes; 27 | } 28 | 29 | public function getGeometryName() : string{ 30 | return $this->geometryName; 31 | } 32 | 33 | public function getGeometryData() : string{ 34 | return $this->geometryData; 35 | } 36 | 37 | public function toSkin(Player $player) : Skin{ 38 | return new Skin($player->getSkin()->getSkinId(), $this->skinBytes, '', $this->geometryName, $this->geometryData); 39 | } 40 | 41 | public function toSkinData(Player $player) : SkinData{ 42 | $skin = new Skin($player->getSkin()->getSkinId(), $this->skinBytes, '', $this->geometryName, $this->geometryData); 43 | 44 | return SkinAdapterSingleton::get()->toSkinData($skin); 45 | } 46 | } -------------------------------------------------------------------------------- /src/alvin0319/NPC/task/CheckVersionAsyncTask.php: -------------------------------------------------------------------------------- 1 | storeLocal($promise); 18 | } 19 | 20 | public function onRun(){ 21 | $url = Internet::getURL("https://raw.githubusercontent.com/alvin0319/NPC/stable/updates.json"); 22 | 23 | if(is_bool($url)){ 24 | $this->setResult(null); 25 | }else{ 26 | $data = json_decode($url, true); 27 | 28 | if($data !== null){ 29 | $lastVersion = $data["version"]; 30 | $lastMessage = $data["updates"] [$lastVersion] ["message"]; 31 | $mustUpdate = $data["updates"] [$lastVersion] ["mustUpdate"]; 32 | 33 | $this->setResult(["version" => $lastVersion, "message" => $lastMessage, "update" => $mustUpdate]); 34 | }else{ 35 | $this->setResult(null); 36 | } 37 | } 38 | } 39 | 40 | public function onCompletion(Server $server){ 41 | /** @var Promise $promise */ 42 | $promise = $this->fetchLocal(); 43 | if($this->getResult() === null){ 44 | $promise->reject("Update check failed: Failed to connect Github server."); 45 | }else{ 46 | $promise->resolve($this->getResult()); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/alvin0319/NPC/util/Promise.php: -------------------------------------------------------------------------------- 1 | now === self::FULFILLED){ 33 | $callback($this->value); 34 | return $this; 35 | } 36 | $this->fulfilled[] = $callback; 37 | return $this; 38 | } 39 | 40 | public function catch(Closure $callback) : Promise{ 41 | if($this->now === self::REJECTED){ 42 | $callback($this->value); 43 | return $this; 44 | } 45 | $this->rejected[] = $callback; 46 | return $this; 47 | } 48 | 49 | public function resolve($value) : Promise{ 50 | $this->setNow(self::FULFILLED, $value); 51 | return $this; 52 | } 53 | 54 | public function reject($reason) : Promise{ 55 | $this->setNow(self::REJECTED, $reason); 56 | return $this; 57 | } 58 | 59 | public function setNow(string $now, $value) : Promise{ 60 | $this->now = $now; 61 | $this->value = $value; 62 | 63 | $callbacks = $this->now === self::FULFILLED ? $this->fulfilled : $this->rejected; 64 | foreach($callbacks as $closure){ 65 | $closure($this->value); 66 | } 67 | $this->fulfilled = $this->rejected = []; 68 | return $this; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/alvin0319/NPC/config/ImageConfig.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 25 | 26 | $data = (new Config($plugin->getDataFolder() . "ImageData.yml", Config::YAML))->getAll(); 27 | 28 | foreach($data as $name => $datum){ 29 | $image = new Image($datum["skinBytes"], $datum["geometryName"], $datum["geometryData"]); 30 | $this->images[$name] = $image; 31 | } 32 | } 33 | 34 | /** 35 | * @param string $key 36 | * 37 | * @return Image|null 38 | */ 39 | public function getImageData(string $key) : ?Image{ 40 | return $this->images[$key] ?? null; 41 | } 42 | 43 | /** 44 | * @return Image[] 45 | */ 46 | public function getAllImages() : array{ 47 | return $this->images; 48 | } 49 | 50 | public function addImage(string $name, string $skinBytes, string $geometryName, string $geometryData){ 51 | $this->images[$name] = new Image($skinBytes, $geometryName, $geometryData); 52 | } 53 | 54 | public function removeImage(string $name){ 55 | unset($this->images[$name]); 56 | } 57 | 58 | public function save(){ 59 | $config = new Config($this->plugin->getDataFolder() . "ImageData.yml", Config::YAML); 60 | $arr = []; 61 | 62 | foreach($this->images as $name => $image){ 63 | $arr[$name] = [ 64 | "skinBytes" => $image->getSkinBytes(), 65 | "geometryName" => $image->getGeometryName(), 66 | "geometryData" => $image->getGeometryData() 67 | ]; 68 | } 69 | 70 | $config->setAll($arr); 71 | $config->save(); 72 | } 73 | } -------------------------------------------------------------------------------- /src/alvin0319/NPC/lang/PluginLang.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 38 | 39 | $this->lang = $plugin->getConfig()->getNested("lang", "eng"); 40 | 41 | $plugin->saveResource($this->lang . ".yml"); 42 | 43 | $this->data = yaml_parse(file_get_contents($plugin->getDataFolder() . $this->lang . ".yml")); 44 | 45 | if(!is_array($this->data)){ 46 | throw new InvalidLanguageException("Language name with " . $this->lang . "is not found."); 47 | } 48 | 49 | self::$prefix = $this->data["plugin.prefix"]; 50 | } 51 | 52 | public function saveNewLang(){ 53 | unlink($this->plugin->getDataFolder() . $this->lang . ".yml"); 54 | $this->plugin->saveResource($this->lang . ".yml"); 55 | } 56 | 57 | /** 58 | * @param string $str 59 | * @param array $params 60 | * 61 | * @return string 62 | */ 63 | public function translateLanguage(string $str, array $params = []) : string{ 64 | $string = $this->data[$str]; 65 | foreach($params as $i => $param){ 66 | $string = str_replace("{%" . $i . "}", $param, $this->data[$str]); 67 | } 68 | 69 | return $string; 70 | } 71 | 72 | /** 73 | * @param string $str 74 | * 75 | * @return string 76 | */ 77 | public function getRealMessage(string $str) : string{ 78 | return $this->data[$str]; 79 | } 80 | } -------------------------------------------------------------------------------- /src/alvin0319/NPC/entity/CustomEntity.php: -------------------------------------------------------------------------------- 1 | networkId = $networkId; 39 | 40 | $this->width = EntityConfig::WIDTHS[$this->id]; 41 | $this->height = EntityConfig::HEIGHTS[$this->id]; 42 | 43 | if($nbt->hasTag("width", FloatTag::class) && $nbt->hasTag("height", FloatTag::class)){ 44 | $this->width = $nbt->getFloat("width"); 45 | $this->height = $nbt->getFloat("height"); 46 | } 47 | 48 | $this->scale = $nbt->getFloat("scale", 1.0); 49 | } 50 | 51 | public function getNetworkId() : int{ 52 | return $this->networkId; 53 | } 54 | 55 | public function spawnTo(Player $player) : void{ 56 | if(in_array($player, $this->hasSpawned, true)){ 57 | return; 58 | } 59 | $pk = new AddActorPacket(); 60 | $pk->entityRuntimeId = $this->getId(); 61 | $pk->type = AddActorPacket::LEGACY_ID_MAP_BC[$this->id]; 62 | $pk->position = $this->location->asVector3(); 63 | $pk->motion = null; 64 | $pk->yaw = $this->location->yaw; 65 | $pk->headYaw = $this->location->yaw; 66 | $pk->pitch = $this->location->pitch; 67 | $pk->metadata = $data = $this->getSyncedNetworkData(false); 68 | 69 | $player->sendDataPacket($pk); 70 | $this->hasSpawned[] = $player; 71 | } 72 | 73 | public static function nbtDeserialize(CompoundTag $nbt){ 74 | [$x, $y, $z, $world] = explode(":", $nbt->getString("pos")); 75 | return new CustomEntity($nbt->getInt("networkId"), new Location((float) $x, (float) $y, (float) $z, 0.0, 0.0, Server::getInstance()->getLevelByName($world)), $nbt); 76 | } 77 | 78 | public function nbtSerialize() : CompoundTag{ 79 | $nbt = parent::nbtSerialize(); 80 | $nbt->setInt("networkId", $this->networkId); 81 | $nbt->setInt("type", self::NETWORK_ID); 82 | return $nbt; 83 | } 84 | } -------------------------------------------------------------------------------- /src/alvin0319/NPC/EventListener.php: -------------------------------------------------------------------------------- 1 | getPlayer(); 21 | $packet = $event->getPacket(); 22 | 23 | if($packet instanceof InventoryTransactionPacket){ 24 | if($packet->transactionType === InventoryTransactionPacket::TYPE_USE_ITEM_ON_ENTITY){ 25 | $entity = NPCPlugin::getInstance()->getEntity($packet->trData->entityRuntimeId); 26 | 27 | if(isset(Queue::$removeQueue[$player->getName()])){ 28 | if($entity instanceof EntityBase){ 29 | $player->sendMessage(PluginLang::$prefix . NPCPlugin::getInstance()->getLanguage()->translateLanguage("entity.delete")); 30 | foreach($entity->getViewers() as $player){ 31 | $entity->despawnTo($player); 32 | } 33 | 34 | NPCPlugin::getInstance()->removeEntity($entity); 35 | unset(Queue::$removeQueue[$player->getName()]); 36 | }else{ 37 | $player->sendMessage(PluginLang::$prefix . NPCPlugin::getInstance()->getLanguage()->translateLanguage("message.notExtend")); 38 | } 39 | return; 40 | } 41 | 42 | if(isset(Queue::$editQueue[$player->getName()])){ 43 | if($entity instanceof EntityBase){ 44 | if(Queue::$editQueue[$player->getName()] ["mode"] === "command"){ 45 | $entity->setCommand(Queue::$editQueue[$player->getName()] ["target"]); 46 | }elseif(Queue::$editQueue[$player->getName()] ["mode"] === "message"){ 47 | $entity->setMessage(Queue::$editQueue[$player->getName()] ["target"]); 48 | }else{ 49 | if(is_numeric(Queue::$editQueue[$player->getName()] ["target"])){ 50 | $entity->setScale((float) Queue::$editQueue[$player->getName()] ["target"]); 51 | }else{ 52 | $player->sendMessage(PluginLang::$prefix . NPCPlugin::getInstance()->getLanguage()->translateLanguage("command.onlyAccept", [ 53 | "scale", 54 | "float" 55 | ])); 56 | } 57 | } 58 | $player->sendMessage(PluginLang::$prefix . "Edit success."); 59 | unset(Queue::$editQueue[$player->getName()]); 60 | }else{ 61 | $player->sendMessage(PluginLang::$prefix . NPCPlugin::getInstance()->getLanguage()->translateLanguage("message.notExtend")); 62 | } 63 | return; 64 | } 65 | 66 | if(isset(Queue::$itemQueue[$player->getName()])){ 67 | if($entity instanceof EntityBase){ 68 | if($entity instanceof NPCHuman){ 69 | $entity->setItem(Queue::$itemQueue[$player->getName()]); 70 | unset(Queue::$itemQueue[$player->getName()]); 71 | $player->sendMessage(PluginLang::$prefix . "Succeed to set item."); 72 | }else{ 73 | $player->sendMessage(PluginLang::$prefix . "That entity is not NPCHuman"); 74 | } 75 | }else{ 76 | $player->sendMessage(PluginLang::$prefix . NPCPlugin::getInstance()->getLanguage()->translateLanguage("message.notExtend")); 77 | } 78 | return; 79 | } 80 | 81 | if(isset(Queue::$offItemQueue[$player->getName()])){ 82 | if($entity instanceof NPCHuman){ 83 | $entity->setItem(Queue::$offItemQueue[$player->getName()], true); 84 | unset(Queue::$offItemQueue[$player->getName()]); 85 | $player->sendMessage(PluginLang::$prefix . "Succeed to set offhand item."); 86 | }else{ 87 | $player->sendMessage(PluginLang::$prefix . "That entity is not NPCHuman"); 88 | } 89 | } 90 | 91 | if($entity instanceof EntityBase || $entity instanceof NPCHuman){ 92 | $entity->interact($player); 93 | } 94 | } 95 | } 96 | } 97 | 98 | public function handleQuit(PlayerQuitEvent $event){ 99 | $player = $event->getPlayer(); 100 | foreach(NPCPlugin::getInstance()->getEntities() as $entityBase){ 101 | $entityBase->despawnTo($player); 102 | } 103 | } 104 | 105 | public function handleMove(PlayerMoveEvent $event){ 106 | $player = $event->getPlayer(); 107 | if(NPCPlugin::getInstance()->getConfig()->getNested("disable-see-player", false)){ 108 | return; 109 | } 110 | foreach(NPCPlugin::getInstance()->getEntities() as $entityBase){ 111 | if($entityBase->getLocation()->getLevel()->getFolderName() === $player->getLevel()->getFolderName()){ 112 | if($entityBase->getLocation()->distance($player->getLocation()) <= (int) NPCPlugin::getInstance()->getConfig()->getNested("spawn-radius", 10)){ 113 | $entityBase->spawnTo($player); 114 | $entityBase->lookAt($player); 115 | }else{ 116 | $entityBase->despawnTo($player); 117 | } 118 | }else{ 119 | $entityBase->despawnTo($player); 120 | } 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /src/alvin0319/NPC/config/EntityConfig.php: -------------------------------------------------------------------------------- 1 | 19, 17 | "blaze" => 43, 18 | "cave_spider" => 40, 19 | "chicken" => 10, 20 | "cod" => 112, 21 | "cow" => 11, 22 | "creeper" => 33, 23 | "dolphin" => 31, 24 | "donkey" => 24, 25 | "elder_guardian" => 50, 26 | "ender_charge" => 79, 27 | "ender_dragon" => 53, 28 | "enderman" => 38, 29 | "endermite" => 55, 30 | "evoker" => 104, 31 | "ghast" => 41, 32 | "guardian" => 49, 33 | "horse" => 23, 34 | "husk" => 47, 35 | "iron_golem" => 20, 36 | "large_fireball" => 85, 37 | "llama" => 29, 38 | "magma_cube" => 42, 39 | "mooshroom" => 16, 40 | "mule" => 25, 41 | "ocelot" => 22, 42 | "parrot" => 30, 43 | "pig" => 12, 44 | "pig_zombie" => 36, 45 | "polar_bear" => 28, 46 | "pufferfish" => 108, 47 | "rabbit" => 18, 48 | "salmon" => 109, 49 | "sheep" => 13, 50 | "shulker" => 54, 51 | "silverfish" => 39, 52 | "skeleton" => 34, 53 | "skeleton_horse" => 26, 54 | "slime" => 37, 55 | "small_fireball" => 94, 56 | "snow_golem" => 21, 57 | "spider" => 35, 58 | "squid" => 17, 59 | "stray" => 46, 60 | "tropicalfish" => 111, 61 | "vex" => 105, 62 | "villager" => 15, 63 | "vindicator" => 57, 64 | "witch" => 45, 65 | "wither_skeleton" => 48, 66 | "wither" => 52, 67 | "wolf" => 14, 68 | "zombie" => 32, 69 | "zombie_pigman" => 36, 70 | "zombie_villager" => 44 71 | ]; 72 | 73 | public const WIDTHS = [ 74 | self::NETWORK_IDS["bat"] => 0.484, 75 | self::NETWORK_IDS["blaze"] => 1.25, 76 | self::NETWORK_IDS["cave_spider"] => 1.438, 77 | self::NETWORK_IDS["chicken"] => 1, 78 | self::NETWORK_IDS["cod"] => 0.5, 79 | self::NETWORK_IDS["cow"] => 1.5, 80 | self::NETWORK_IDS["creeper"] => 0.7, 81 | self::NETWORK_IDS["donkey"] => 1.2, 82 | self::NETWORK_IDS["dolphin"] => 1.2, 83 | self::NETWORK_IDS["elder_guardian"] => 1.9975, 84 | self::NETWORK_IDS["ender_charge"] => 1.0, 85 | self::NETWORK_IDS["ender_dragon"] => 2.5, 86 | self::NETWORK_IDS["enderman"] => 1.094, 87 | self::NETWORK_IDS["endermite"] => 0.4, 88 | self::NETWORK_IDS["evoker"] => 1.031, 89 | self::NETWORK_IDS["ghast"] => 4.5, 90 | self::NETWORK_IDS["guardian"] => 0, 91 | self::NETWORK_IDS["horse"] => 1.3, 92 | self::NETWORK_IDS["husk"] => 1.031, 93 | self::NETWORK_IDS["iron_golem"] => 2.688, 94 | self::NETWORK_IDS["large_fireball"] => 0.5, 95 | self::NETWORK_IDS["llama"] => 0.9, 96 | self::NETWORK_IDS["magma_cube"] => 1.2, 97 | self::NETWORK_IDS["mooshroom"] => 1.781, 98 | self::NETWORK_IDS["mule"] => 1.2, 99 | self::NETWORK_IDS["ocelot"] => 0.8, 100 | self::NETWORK_IDS["parrot"] => 0.5, 101 | self::NETWORK_IDS["pig"] => 1.5, 102 | self::NETWORK_IDS["pig_zombie"] => 1.125, 103 | self::NETWORK_IDS["polar_bear"] => 1.3, 104 | self::NETWORK_IDS["pufferfish"] => 0.35, 105 | self::NETWORK_IDS["rabbit"] => 0.4, 106 | self::NETWORK_IDS["sheep"] => 0.9, 107 | self::NETWORK_IDS["shulker"] => 1.0, 108 | self::NETWORK_IDS["silverfish"] => 1.094, 109 | self::NETWORK_IDS["skeleton"] => 0.875, 110 | self::NETWORK_IDS["skeleton_horse"] => 1.3, 111 | self::NETWORK_IDS["slime"] => 1.2, 112 | self::NETWORK_IDS["small_fireball"] => 0.25, 113 | self::NETWORK_IDS["snow_golem"] => 1.281, 114 | self::NETWORK_IDS["stray"] => 0.875, 115 | self::NETWORK_IDS["spider"] => 2.062, 116 | self::NETWORK_IDS["squid"] => 0, 117 | self::NETWORK_IDS["tropicalfish"] => 0.5, 118 | self::NETWORK_IDS["vex"] => 0.4, 119 | self::NETWORK_IDS["villager"] => 0.938, 120 | self::NETWORK_IDS["vindicator"] => 0.6, 121 | self::NETWORK_IDS["witch"] => 0.6, 122 | self::NETWORK_IDS["wither"] => 0.9, 123 | self::NETWORK_IDS["wither_skeleton"] => 0.875, 124 | self::NETWORK_IDS["wolf"] => 1.2, 125 | self::NETWORK_IDS["zombie"] => 1.031, 126 | self::NETWORK_IDS["zombie_pigman"] => 2.0, 127 | self::NETWORK_IDS["zombie_villager"] => 1.031 128 | ]; 129 | // Entity Heights 130 | const HEIGHTS = [ 131 | self::NETWORK_IDS["bat"] => 0.5, 132 | self::NETWORK_IDS["blaze"] => 1.5, 133 | self::NETWORK_IDS["cave_spider"] => 0.547, 134 | self::NETWORK_IDS["chicken"] => 0.8, 135 | self::NETWORK_IDS["cod"] => 0.3, 136 | self::NETWORK_IDS["cow"] => 1.2, 137 | self::NETWORK_IDS["creeper"] => 1.7, 138 | self::NETWORK_IDS["donkey"] => 1.562, 139 | self::NETWORK_IDS["dolphin"] => 1.562, 140 | self::NETWORK_IDS["elder_guardian"] => 1.9975, 141 | self::NETWORK_IDS["ender_charge"] => 1.0, 142 | self::NETWORK_IDS["ender_dragon"] => 1.0, 143 | self::NETWORK_IDS["enderman"] => 2.875, 144 | self::NETWORK_IDS["endermite"] => 0.3, 145 | self::NETWORK_IDS["evoker"] => 2.125, 146 | self::NETWORK_IDS["ghast"] => 4.5, 147 | self::NETWORK_IDS["guardian"] => 0, 148 | self::NETWORK_IDS["horse"] => 1.5, 149 | self::NETWORK_IDS["husk"] => 2.0, 150 | self::NETWORK_IDS["iron_golem"] => 1.625, 151 | self::NETWORK_IDS["large_fireball"] => 0.5, 152 | self::NETWORK_IDS["llama"] => 1.87, 153 | self::NETWORK_IDS["magma_cube"] => 1.2, 154 | self::NETWORK_IDS["mooshroom"] => 1.875, 155 | self::NETWORK_IDS["mule"] => 1.562, 156 | self::NETWORK_IDS["ocelot"] => 0.8, 157 | self::NETWORK_IDS["parrot"] => 0.9, 158 | self::NETWORK_IDS["pig"] => 1.0, 159 | self::NETWORK_IDS["pig_zombie"] => 2.03, 160 | self::NETWORK_IDS["polar_bear"] => 1.4, 161 | self::NETWORK_IDS["pufferfish"] => 0.35, 162 | self::NETWORK_IDS["rabbit"] => 0.5, 163 | self::NETWORK_IDS["sheep"] => 1.3, 164 | self::NETWORK_IDS["shulker"] => 1.0, 165 | self::NETWORK_IDS["silverfish"] => 0.438, 166 | self::NETWORK_IDS["skeleton"] => 2.0, 167 | self::NETWORK_IDS["skeleton_horse"] => 1.5, 168 | self::NETWORK_IDS["slime"] => 1.2, 169 | self::NETWORK_IDS["small_fireball"] => 0.25, 170 | self::NETWORK_IDS["snow_golem"] => 1.875, 171 | self::NETWORK_IDS["stray"] => 2.0, 172 | self::NETWORK_IDS["spider"] => 0.781, 173 | self::NETWORK_IDS["squid"] => 0.0, 174 | self::NETWORK_IDS["tropicalfish"] => 0.5, 175 | self::NETWORK_IDS["vex"] => 0.8, 176 | self::NETWORK_IDS["villager"] => 2.0, 177 | self::NETWORK_IDS["vindicator"] => 1.95, 178 | self::NETWORK_IDS["witch"] => 1.95, 179 | self::NETWORK_IDS["wither"] => 3.5, 180 | self::NETWORK_IDS["wither_skeleton"] => 2.0, 181 | self::NETWORK_IDS["wolf"] => 0.969, 182 | self::NETWORK_IDS["zombie"] => 2.01, 183 | self::NETWORK_IDS["zombie_pigman"] => 2.0, 184 | self::NETWORK_IDS["zombie_villager"] => 2.125 185 | ]; 186 | } -------------------------------------------------------------------------------- /src/alvin0319/NPC/entity/NPCHuman.php: -------------------------------------------------------------------------------- 1 | uuid = UUID::fromRandom(); 52 | 53 | $skinTag = $nbt->getCompoundTag("Skin"); 54 | 55 | if($skinTag === null){ 56 | throw new \InvalidStateException((new \ReflectionClass($this))->getShortName() . " must have a valid skin set"); 57 | } 58 | 59 | $this->skin = new Skin($skinTag->getString("Name"), $skinTag->hasTag("Data", StringTag::class) ? $skinTag->getString("Data") : $skinTag->getByteArray("Data"), $skinTag->getByteArray("CapeData", ""), $skinTag->getString("GeometryName", ""), $skinTag->getByteArray("GeometryData", "")); 60 | 61 | $this->isCustomSkin = $nbt->getByte("isCustomSkin", 0) === 1 ? true : false; 62 | 63 | if($nbt->hasTag("width", FloatTag::class) && $nbt->hasTag("height", FloatTag::class)){ 64 | $this->width = $nbt->getFloat("width"); 65 | $this->height = $nbt->getFloat("height"); 66 | } 67 | 68 | $this->scale = $nbt->getFloat("scale", 1.0); 69 | 70 | if($nbt->hasTag("item", CompoundTag::class)){ 71 | $this->item = Item::nbtDeserialize($nbt->getCompoundTag("item")); 72 | }else{ 73 | $this->item = ItemFactory::get(0); 74 | } 75 | if($nbt->hasTag("offHand", CompoundTag::class)){ 76 | $this->offHandItem = Item::nbtDeserialize($nbt->getCompoundTag("offHand")); 77 | }else{ 78 | $this->offHandItem = ItemFactory::get(0); 79 | } 80 | } 81 | 82 | public function getName() : string{ 83 | return (new \ReflectionClass($this))->getShortName(); 84 | } 85 | 86 | public function spawnTo(Player $player) : void{ 87 | if(in_array($player, $this->hasSpawned, true)){ 88 | return; 89 | } 90 | 91 | $pk = new PlayerListPacket(); 92 | $pk->entries = [PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), SkinAdapterSingleton::get()->toSkinData($this->skin))]; 93 | $pk->type = PlayerListPacket::TYPE_ADD; 94 | $player->sendDataPacket($pk); 95 | 96 | $pk = new AddPlayerPacket(); 97 | $pk->uuid = $this->uuid; 98 | $pk->username = $this->getRealName(); 99 | $pk->entityRuntimeId = $this->getId(); 100 | $pk->position = $this->location->asVector3(); 101 | $pk->motion = null; 102 | $pk->yaw = $this->location->yaw; 103 | $pk->pitch = $this->location->pitch; 104 | $pk->item = $this->item; 105 | $pk->metadata = $this->getSyncedNetworkData(false); 106 | $player->sendDataPacket($pk); 107 | 108 | $this->sendData($player, [Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $this->getRealName()]]); 109 | 110 | $pk = new PlayerListPacket(); 111 | $pk->entries = [PlayerListEntry::createRemovalEntry($this->uuid)]; 112 | $pk->type = PlayerListPacket::TYPE_REMOVE; 113 | $player->sendDataPacket($pk); 114 | 115 | $this->hasSpawned[] = $player; 116 | 117 | if($this->offHandItem->getId() !== 0){ 118 | $pk = new MobEquipmentPacket(); 119 | $pk->windowId = ContainerIds::OFFHAND; 120 | $pk->entityRuntimeId = $this->getId(); 121 | $pk->inventorySlot = $pk->hotbarSlot = 0; 122 | $pk->item = $this->offHandItem; 123 | $this->server->broadcastPacket($this->hasSpawned, $pk); 124 | } 125 | } 126 | 127 | public function despawnTo(Player $player) : void{ 128 | parent::despawnTo($player); 129 | $pk = new PlayerListPacket(); 130 | $pk->entries = [PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), SkinAdapterSingleton::get()->toSkinData($this->skin))]; 131 | $pk->type = PlayerListPacket::TYPE_REMOVE; 132 | $player->sendDataPacket($pk); 133 | } 134 | 135 | public static function nbtDeserialize(CompoundTag $nbt) : NPCHuman{ 136 | [$x, $y, $z, $world] = explode(":", $nbt->getString("pos")); 137 | return new NPCHuman(new Location((float) $x, (float) $y, (float) $z, 0.0, 0.0, Server::getInstance()->getLevelByName($world)), $nbt); 138 | } 139 | 140 | public function nbtSerialize() : CompoundTag{ 141 | $nbt = parent::nbtSerialize(); 142 | $nbt->setInt("type", self::NETWORK_ID); 143 | 144 | $nbt->setString("command", $this->command); 145 | $nbt->setString("message", $this->message); 146 | 147 | $nbt->setTag(NPCPlugin::getInstance()->getSkinCompound($this->skin)); 148 | $nbt->setByte("isCustomSkin", $this->isCustomSkin ? 1 : 0); 149 | $nbt->setTag($this->item->nbtSerialize(-1, "item")); 150 | $nbt->setTag($this->offHandItem->nbtSerialize(-1, "offHand")); 151 | return $nbt; 152 | } 153 | 154 | /** 155 | * @param Vector3 $target 156 | * 157 | * @see Living::lookAt() 158 | */ 159 | public function lookAt(Vector3 $target){ 160 | $horizontal = sqrt(($target->x - $this->location->x) ** 2 + ($target->z - $this->location->z) ** 2); 161 | $vertical = $target->y - $this->location->y; 162 | $this->location->pitch = -atan2($vertical, $horizontal) / M_PI * 180; //negative is up, positive is down 163 | 164 | $xDist = $target->x - $this->location->x; 165 | $zDist = $target->z - $this->location->z; 166 | $this->location->yaw = atan2($zDist, $xDist) / M_PI * 180 - 90; 167 | if($this->location->yaw < 0){ 168 | $this->location->yaw += 360.0; 169 | } 170 | 171 | $pk = new MovePlayerPacket(); 172 | $pk->position = $this->location->add(0, 1.62); 173 | $pk->yaw = $this->location->yaw; 174 | $pk->pitch = $this->location->pitch; 175 | $pk->entityRuntimeId = $this->id; 176 | $pk->headYaw = $this->location->yaw; 177 | 178 | foreach($this->getViewers() as $player){ 179 | $player->sendDataPacket($pk); 180 | } 181 | } 182 | 183 | public function getItem() : Item{ 184 | return $this->item; 185 | } 186 | 187 | public function setItem(?Item $item, bool $offHand = false){ 188 | if($item === null){ 189 | $item = ItemFactory::get(0); 190 | } 191 | 192 | if($offHand) 193 | $this->offHandItem = $item;else 194 | $this->item = $item; 195 | } 196 | } -------------------------------------------------------------------------------- /src/alvin0319/NPC/entity/EntityBase.php: -------------------------------------------------------------------------------- 1 | location = $location; 69 | $this->initEntity($nbt); 70 | $this->id = Entity::$entityCount++; 71 | $this->networkProperties = new DataPropertyManager(); 72 | $this->server = Server::getInstance(); 73 | } 74 | 75 | /** 76 | * @param CompoundTag $nbt 77 | */ 78 | public function initEntity(CompoundTag $nbt) : void{ 79 | if($nbt->hasTag("name", StringTag::class)){ 80 | $this->name = $nbt->getString("name"); 81 | } 82 | 83 | if($nbt->hasTag("scale", FloatTag::class)){ 84 | $this->scale = $nbt->getFloat("scale"); 85 | } 86 | 87 | $this->command = $nbt->getString("command", ""); 88 | $this->message = $nbt->getString("message", ""); 89 | } 90 | 91 | public function getRealName() : string{ 92 | return $this->name; 93 | } 94 | 95 | /** 96 | * @param Vector3 $target 97 | * 98 | * @see Living::lookAt() 99 | */ 100 | public function lookAt(Vector3 $target){ 101 | $horizontal = sqrt(($target->x - $this->location->x) ** 2 + ($target->z - $this->location->z) ** 2); 102 | $vertical = $target->y - $this->location->y; 103 | $this->location->pitch = -atan2($vertical, $horizontal) / M_PI * 180; //negative is up, positive is down 104 | 105 | $xDist = $target->x - $this->location->x; 106 | $zDist = $target->z - $this->location->z; 107 | $this->location->yaw = atan2($zDist, $xDist) / M_PI * 180 - 90; 108 | if($this->location->yaw < 0){ 109 | $this->location->yaw += 360.0; 110 | } 111 | 112 | $pk = new MoveActorAbsolutePacket(); 113 | $pk->xRot = $this->location->pitch; 114 | $pk->yRot = $this->location->yaw; 115 | $pk->zRot = $this->location->yaw; 116 | $pk->position = $this->location; 117 | $pk->entityRuntimeId = $this->id; 118 | 119 | foreach($this->getViewers() as $player){ 120 | $player->sendDataPacket($pk); 121 | } 122 | } 123 | 124 | /** 125 | * @return string 126 | */ 127 | public function getMessage() : string{ 128 | return $this->message; 129 | } 130 | 131 | /** 132 | * @return string 133 | */ 134 | public function getCommand() : string{ 135 | return $this->command; 136 | } 137 | 138 | /** 139 | * @param string $message 140 | */ 141 | public function setMessage(string $message){ 142 | $this->message = $message; 143 | } 144 | 145 | /** 146 | * @param string $command 147 | */ 148 | public function setCommand(string $command){ 149 | $this->command = $command; 150 | } 151 | 152 | /** 153 | * @return Location 154 | */ 155 | public function getLocation() : Location{ 156 | return $this->location; 157 | } 158 | 159 | /** 160 | * @return int 161 | */ 162 | public function getId() : int{ 163 | return $this->id; 164 | } 165 | 166 | /** 167 | * @return Server 168 | */ 169 | public function getServer() : Server{ 170 | return $this->server; 171 | } 172 | 173 | /** 174 | * @param $player 175 | * @param array|null $data 176 | * 177 | * @see Entity::sendData() 178 | */ 179 | public function sendData($player, ?array $data = null) : void{ 180 | if(!is_array($player)){ 181 | $player = [$player]; 182 | } 183 | 184 | $pk = new SetActorDataPacket(); 185 | $pk->entityRuntimeId = $this->getId(); 186 | $pk->metadata = $data ?? $this->getSyncedNetworkData(false); 187 | 188 | foreach($player as $p){ 189 | if($p === $this){ 190 | continue; 191 | } 192 | $p->sendDataPacket(clone $pk); 193 | } 194 | } 195 | 196 | /** 197 | * @see Entity::syncNetworkData() 198 | */ 199 | protected function syncNetworkData() : void{ 200 | $this->networkProperties->setByte(Entity::DATA_ALWAYS_SHOW_NAMETAG, 1); 201 | $this->networkProperties->setFloat(Entity::DATA_BOUNDING_BOX_HEIGHT, $this->height); 202 | $this->networkProperties->setFloat(Entity::DATA_BOUNDING_BOX_WIDTH, $this->width); 203 | $this->networkProperties->setFloat(Entity::DATA_SCALE, $this->scale); 204 | $this->networkProperties->setLong(Entity::DATA_LEAD_HOLDER_EID, -1); 205 | $this->networkProperties->setLong(Entity::DATA_OWNER_EID, -1); 206 | $this->networkProperties->setLong(Entity::DATA_TARGET_EID, 0); 207 | $this->networkProperties->setString(Entity::DATA_NAMETAG, $this->name); 208 | 209 | $this->setGenericFlag(Entity::DATA_FLAG_AFFECTED_BY_GRAVITY, true); 210 | $this->setGenericFlag(Entity::DATA_FLAG_CAN_SHOW_NAMETAG, true); 211 | $this->setGenericFlag(Entity::DATA_FLAG_HAS_COLLISION, true); 212 | $this->setGenericFlag(Entity::DATA_FLAG_IMMOBILE, false); 213 | $this->setGenericFlag(Entity::DATA_FLAG_INVISIBLE, false); 214 | $this->setGenericFlag(Entity::DATA_FLAG_ONFIRE, false); 215 | $this->setGenericFlag(Entity::DATA_FLAG_SNEAKING, false); 216 | $this->setGenericFlag(Entity::DATA_FLAG_WALLCLIMBING, false); 217 | $this->setGenericFlag(Entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG, true); 218 | } 219 | 220 | /** 221 | * @param bool $dirtyOnly 222 | * 223 | * @return array 224 | */ 225 | final protected function getSyncedNetworkData(bool $dirtyOnly) : array{ 226 | $this->syncNetworkData(); 227 | 228 | return $dirtyOnly ? $this->networkProperties->getDirty() : $this->networkProperties->getAll(); 229 | } 230 | 231 | abstract public static function nbtDeserialize(CompoundTag $nbt); 232 | 233 | public function nbtSerialize() : CompoundTag{ 234 | $nbt = new CompoundTag(); 235 | $nbt->setString("name", $this->name); 236 | $nbt->setString("message", $this->message); 237 | $nbt->setString("command", $this->command); 238 | $nbt->setString("pos", implode(":", [ 239 | $this->location->x, 240 | $this->location->y, 241 | $this->location->z, 242 | $this->location->level->getFolderName() 243 | ])); 244 | $nbt->setFloat("scale", $this->scale); 245 | $nbt->setFloat("width", $this->width); 246 | $nbt->setFloat("height", $this->height); 247 | return $nbt; 248 | } 249 | 250 | public function spawnTo(Player $player) : void{ 251 | 252 | } 253 | 254 | public function despawnTo(Player $player) : void{ 255 | if(!in_array($player, $this->hasSpawned, true)){ 256 | return; 257 | } 258 | 259 | $pk = new RemoveActorPacket(); 260 | $pk->entityUniqueId = $this->id; 261 | $player->sendDataPacket($pk); 262 | 263 | $key = array_search($player, $this->hasSpawned, true); 264 | if($key !== false){ 265 | unset($this->hasSpawned[$key]); 266 | } 267 | } 268 | 269 | /** 270 | * @return Player[] 271 | */ 272 | public function getViewers() : array{ 273 | return $this->hasSpawned; 274 | } 275 | 276 | public function setScale(float $scale){ 277 | $this->scale = $scale; 278 | 279 | $multiplier = $scale / $this->scale; 280 | 281 | $this->width *= $multiplier; 282 | $this->height *= $multiplier; 283 | } 284 | 285 | /** 286 | * @param int $propertyId 287 | * @param int $flagId 288 | * @param bool $value 289 | * @param int $propertyType 290 | */ 291 | public function setDataFlag(int $propertyId, int $flagId, bool $value = true, int $propertyType = Entity::DATA_TYPE_LONG) : void{ 292 | if($this->getDataFlag($propertyId, $flagId) !== $value){ 293 | $flags = (int) $this->networkProperties->getPropertyValue($propertyId, $propertyType); 294 | $flags ^= 1 << $flagId; 295 | $this->networkProperties->setPropertyValue($propertyId, $propertyType, $flags); 296 | } 297 | } 298 | 299 | /** 300 | * @param int $propertyId 301 | * @param int $flagId 302 | * 303 | * @return bool 304 | */ 305 | public function getDataFlag(int $propertyId, int $flagId) : bool{ 306 | return (((int) $this->networkProperties->getPropertyValue($propertyId, -1)) & (1 << $flagId)) > 0; 307 | } 308 | 309 | /** 310 | * Wrapper around {@link Entity#getDataFlag} for generic data flag reading. 311 | * 312 | * @param int $flagId 313 | * 314 | * @return bool 315 | */ 316 | public function getGenericFlag(int $flagId) : bool{ 317 | return $this->getDataFlag($flagId >= 64 ? Entity::DATA_FLAGS2 : Entity::DATA_FLAGS, $flagId % 64); 318 | } 319 | 320 | /** 321 | * Wrapper around {@link Entity#setDataFlag} for generic data flag setting. 322 | * 323 | * @param int $flagId 324 | * @param bool $value 325 | */ 326 | public function setGenericFlag(int $flagId, bool $value = true) : void{ 327 | $this->setDataFlag($flagId >= 64 ? Entity::DATA_FLAGS2 : Entity::DATA_FLAGS, $flagId % 64, $value, Entity::DATA_TYPE_LONG); 328 | } 329 | 330 | public function interact(Player $player){ 331 | if(trim($this->getMessage()) !== ""){ 332 | $player->sendMessage($this->getMessage()); 333 | } 334 | 335 | if(trim($this->getCommand()) !== ""){ 336 | $player->getServer()->dispatchCommand($player, $this->getCommand()); 337 | } 338 | } 339 | } -------------------------------------------------------------------------------- /src/alvin0319/NPC/NPCPlugin.php: -------------------------------------------------------------------------------- 1 | getDataFolder() . "images/") or !is_dir($this->getDataFolder() . "images/")){ 80 | mkdir($this->getDataFolder() . "images/"); 81 | } 82 | 83 | $this->lang = new PluginLang($this); 84 | 85 | $this->saveResource("config.yml"); 86 | 87 | if(version_compare(self::CONFIG_VERSION, $this->getConfig()->getNested("config-version", self::CONFIG_VERSION)) > 0){ 88 | $this->getLogger()->debug("Found old config data, replacing..."); 89 | unlink($this->getDataFolder() . "config.yml"); 90 | $this->saveResource("config.yml"); 91 | $this->lang->saveNewLang(); 92 | } 93 | 94 | $this->getServer()->getPluginManager()->registerEvents(new EventListener(), $this); 95 | 96 | $this->data = $this->getConfig()->getAll(); 97 | 98 | if(!file_exists($file = $this->getDataFolder() . "npc.dat")){ 99 | $nbt = new CompoundTag(); 100 | $nbt->setTag(new ListTag("npc")); 101 | file_put_contents($file, (new LittleEndianNBTStream())->writeCompressed($nbt)); 102 | } 103 | 104 | $data = (new LittleEndianNBTStream())->readCompressed(file_get_contents($file)); 105 | 106 | foreach($data->getListTag("npc")->getValue() as $tag){ 107 | if($tag instanceof CompoundTag){ 108 | switch($tag->getInt("type")){ 109 | case NPCHuman::NETWORK_ID: 110 | $class = NPCHuman::nbtDeserialize($tag); 111 | break; 112 | case CustomEntity::NETWORK_ID: 113 | $class = CustomEntity::nbtDeserialize($tag); 114 | break; 115 | default: 116 | throw new \InvalidStateException("Unknown entity type " . $tag->getInt("type")); 117 | } 118 | 119 | if(!$class->getLocation()->getLevel() instanceof Level){ 120 | $this->getLogger()->debug("Skip registering " . $class->getRealName() . " due to not level loaded."); 121 | continue; 122 | } 123 | 124 | $this->entities[$class->getId()] = $class; 125 | } 126 | } 127 | 128 | $promise = new Promise(); 129 | 130 | $this->getServer()->getAsyncPool()->submitTask(new CheckVersionAsyncTask($promise)); 131 | 132 | $promise->then(function(array $result){ 133 | $ver = $this->getDescription()->getVersion(); 134 | 135 | $lastVer = $result["version"]; 136 | 137 | if(version_compare($lastVer, $ver) > 0){ 138 | $mustUpdate = $result["update"] ?? false; 139 | $message = $result["message"] ?? ""; 140 | 141 | $this->getLogger()->notice("The New version of NPC was released. Now version: " . $ver . ", Last version: " . $lastVer); 142 | $this->getLogger()->info("Update message: " . $message); 143 | 144 | if($mustUpdate){ 145 | $this->getLogger()->emergency("You must update this plugin before you can use it."); 146 | $this->getServer()->getPluginManager()->disablePlugin($this); 147 | } 148 | }else{ 149 | $this->getLogger()->info("The latest version."); 150 | } 151 | })->catch(function(string $err){ 152 | $this->getLogger()->critical($err); 153 | }); 154 | 155 | $this->imageConfig = new ImageConfig($this); 156 | } 157 | 158 | public function onDisable() : void{ 159 | $nbt = new CompoundTag(); 160 | $tag = new ListTag("npc"); 161 | 162 | foreach(array_values($this->entities) as $baseEntity){ 163 | $tag->push($baseEntity->nbtSerialize()); 164 | } 165 | $nbt->setTag($tag); 166 | file_put_contents($this->getDataFolder() . "npc.dat", (new LittleEndianNBTStream())->writeCompressed($nbt)); 167 | 168 | $this->imageConfig->save(); 169 | } 170 | 171 | public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{ 172 | if(!$sender instanceof Player){ 173 | return false; 174 | } 175 | switch($args[0] ?? "x"){ 176 | case "create": 177 | if(isset($args[1])){// type 178 | if(isset($args[2])){// nametag 179 | if($args[1] === "npc"){ 180 | if(isset($args[3])){// path, or something 181 | $path = $args[3]; 182 | $bool = true; 183 | if(isset($args[4])){// geometry path, or something 184 | if(file_exists($this->getDataFolder() . "images/" . $args[4])){ 185 | $data = json_decode(file_get_contents($this->getDataFolder() . "images/" . $args[4]), true); 186 | 187 | if(!is_string($geometryName = $this->findGeometryName($data))){ 188 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("entity.geometry")); 189 | break; 190 | } 191 | 192 | $geometryData = json_encode($data); 193 | }else{ 194 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("path.notExist", [$args[4]])); 195 | break; 196 | } 197 | } 198 | try{ 199 | $skin = $this->imageToSkin($sender, $path, isset($geometryName) ? $geometryName : "", isset($geometryData) ? $geometryData : ""); 200 | }catch(ExtensionNotLoadedException $e){ 201 | $bool = false; 202 | $sender->sendMessage(PluginLang::$prefix . $e->getMessage()); 203 | }catch(FileNotFoundException $e){ 204 | $bool = false; 205 | $sender->sendMessage(PluginLang::$prefix . $e->getMessage()); 206 | } 207 | 208 | $nbt = new CompoundTag("Skin"); 209 | 210 | if($bool && isset($skin)){ 211 | $nbt->setString("name", $args[2]); 212 | $nbt->setByte("isCustomSkin", 1); 213 | $nbt->setTag($this->getSkinCompound($skin)); 214 | 215 | /** @var NPCHuman $entity */ 216 | $entity = new NPCHuman($sender->getLocation(), $nbt); 217 | $this->entities[$entity->getId()] = $entity; 218 | 219 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("entity.spawn", [$entity->getRealName()])); 220 | } 221 | }else{ 222 | $skin = $sender->getSkin(); 223 | $nbt = new CompoundTag(); 224 | $nbt->setString("name", $args[2]); 225 | $nbt->setTag($this->getSkinCompound($skin)); 226 | 227 | /** @var NPCHuman $entity */ 228 | $entity = new NPCHuman($sender->getLocation(), $nbt); 229 | $this->entities[$entity->getId()] = $entity; 230 | 231 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("entity.spawn", [$entity->getRealName()])); 232 | } 233 | }else{ 234 | if(in_array($args[1], array_keys(EntityConfig::NETWORK_IDS))){ 235 | $nbt = new CompoundTag(); 236 | $nbt->setString("name", $args[2]); 237 | /** @var EntityBase $entity */ 238 | $entity = new CustomEntity(EntityConfig::NETWORK_IDS[$args[1]], $sender->getLocation(), $nbt); 239 | $this->entities[$entity->getId()] = $entity; 240 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("entity.spawn", [$entity->getRealName()])); 241 | }else{ 242 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("entity.notExist")); 243 | } 244 | } 245 | }else{ 246 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.create.usage")); 247 | } 248 | }else{ 249 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.create.usage")); 250 | } 251 | break; 252 | case "remove": 253 | Queue::$removeQueue[$sender->getName()] = time(); 254 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.remove.message")); 255 | break; 256 | case "get": 257 | if(count($this->entities) === 0){ 258 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.list.empty")); 259 | break; 260 | } 261 | 262 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.list") . implode(", ", array_map(function(EntityBase $entityBase) : string{ 263 | return "#" . $entityBase->getId() . " " . $entityBase->getRealName() . ": " . self::pos2hash($entityBase->getLocation()); 264 | }, array_values($this->entities)))); 265 | break; 266 | case "edit": 267 | if(isset($args[1])){ 268 | if(isset($args[2])){ 269 | if(in_array($args[1], ["command", "message", "scale"])){ 270 | Queue::$editQueue[$sender->getName()] = [ 271 | "mode" => $args[1], 272 | "target" => $args[2] 273 | ]; 274 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.edit.message")); 275 | }else{ 276 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.edit.usage")); 277 | } 278 | }else{ 279 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.edit.usage")); 280 | } 281 | }else{ 282 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.edit.usage")); 283 | } 284 | break; 285 | case "item": 286 | $item = $sender->getInventory()->getItemInHand(); 287 | Queue::$itemQueue[$sender->getName()] = $item; 288 | $sender->sendMessage(PluginLang::$prefix . "Please attack the entity that you want to set item."); 289 | break; 290 | case "offhand": 291 | $item = $sender->getInventory()->getItemInHand(); 292 | Queue::$offItemQueue[$sender->getName()] = $item; 293 | $sender->sendMessage(PluginLang::$prefix . "Please attack the entity that you want to set offhand item."); 294 | break; 295 | default: 296 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.create.usage")); 297 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.delete.usage")); 298 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.edit.usage")); 299 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.get.usage")); 300 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.item.usage")); 301 | $sender->sendMessage(PluginLang::$prefix . $this->lang->translateLanguage("command.entity.list") . implode(", ", array_keys(EntityConfig::NETWORK_IDS)) . ", npc"); 302 | } 303 | return true; 304 | } 305 | 306 | /** 307 | * @param Player $player 308 | * @param string $path 309 | * @param string $geometryName 310 | * @param string $geometryData 311 | * 312 | * @return Skin 313 | * @throws ExtensionNotLoadedException 314 | * @throws FileNotFoundException 315 | * 316 | * TO-DO: Process this as asynchronous 317 | */ 318 | private function imageToSkin(Player $player, string $path, string $geometryName = "", string $geometryData = "") : Skin{ 319 | if(!extension_loaded("gd")){ 320 | throw new ExtensionNotLoadedException($this->lang->translateLanguage("ext-gd.missing")); 321 | } 322 | 323 | if(!file_exists($path = $this->getDataFolder() . "images/" . $path)){ 324 | throw new FileNotFoundException($this->lang->translateLanguage("path.notExist", [$path])); 325 | } 326 | 327 | $img = imagecreatefrompng($path); 328 | $bytes = ''; 329 | for($y = 0; $y < imagesy($img); $y++){ 330 | for($x = 0; $x < imagesx($img); $x++){ 331 | $rgba = @imagecolorat($img, $x, $y); 332 | $a = ((~((int) ($rgba >> 24))) << 1) & 0xff; 333 | $r = ($rgba >> 16) & 0xff; 334 | $g = ($rgba >> 8) & 0xff; 335 | $b = $rgba & 0xff; 336 | $bytes .= chr($r) . chr($g) . chr($b) . chr($a); 337 | } 338 | } 339 | @imagedestroy($img); 340 | return new Skin($player->getSkin()->getSkinId(), $bytes, "", $geometryName, $geometryData); 341 | } 342 | 343 | private function findGeometryName(array $decodedJsonData) : ?string{ 344 | if(isset($decodedJsonData["geometryName"])){ 345 | return $decodedJsonData["geometryName"]; 346 | } 347 | if(isset($decodedJsonData["minecraft:geometry"][0]["description"]["identifier"])) 348 | return $decodedJsonData["minecraft:geometry"][0]["description"]["identifier"]; 349 | return null; 350 | } 351 | 352 | /** 353 | * @param Skin $skin 354 | * 355 | * @return CompoundTag 356 | */ 357 | public function getSkinCompound(Skin $skin) : CompoundTag{ 358 | $nbt = new CompoundTag("Skin"); 359 | $nbt->setString("Name", $skin->getSkinId()); 360 | $nbt->setByteArray("Data", $skin->getSkinData()); 361 | $nbt->setByteArray("CapeData", $skin->getCapeData()); 362 | $nbt->setString("GeometryName", $skin->getGeometryName()); 363 | $nbt->setByteArray("GeometryData", $skin->getGeometryData()); 364 | 365 | return $nbt; 366 | } 367 | 368 | /** 369 | * @param Location $pos 370 | * 371 | * @return string 372 | */ 373 | public static function pos2hash(Location $pos) : string{ 374 | return implode(":", [$pos->x, $pos->y, $pos->z, $pos->level->getFolderName()]); 375 | } 376 | 377 | /** 378 | * @return PluginLang 379 | * @internal 380 | */ 381 | public function getLanguage() : PluginLang{ 382 | return $this->lang; 383 | } 384 | 385 | /** 386 | * @return ImageConfig 387 | * @deprecated 388 | */ 389 | public function getImageConfig() : ImageConfig{ 390 | return $this->imageConfig; 391 | } 392 | 393 | /** 394 | * @param EntityBase $entityBase 395 | */ 396 | public function removeEntity(EntityBase $entityBase){ 397 | unset($this->entities[$entityBase->getId()]); 398 | } 399 | 400 | /** 401 | * @return EntityBase[] 402 | */ 403 | public function getEntities() : array{ 404 | return array_values($this->entities); 405 | } 406 | 407 | /** 408 | * @param int $runtimeId 409 | * 410 | * @return EntityBase|null 411 | */ 412 | public function getEntity(int $runtimeId) : ?EntityBase{ 413 | return $this->entities[$runtimeId] ?? null; 414 | } 415 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------