mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
Merge branch 'master'
# Conflicts: # src/API/AchievementAPI.php # src/API/BanAPI.php # src/API/BlockAPI.php # src/API/EntityAPI.php # src/API/PlayerAPI.php # src/Player.php # src/PocketMinecraftServer.php # src/config.php # src/entity/Animal.php # src/entity/Breedable.php # src/entity/Creature.php # src/entity/Entity.php # src/entity/animal/Sheep.php # src/entity/monster/Creeper.php # src/entity/monster/Zombie.php # src/entity/object/Arrow.php # src/entity/object/FallingSand.php # src/entity/object/ItemEntity.php # src/entity/object/Minecart.php # src/entity/object/Painting.php # src/entity/object/PrimedTNT.php # src/material/Block.php # src/material/Item.php # src/material/Material.php # src/material/StaticBlock.php # src/material/block/DoorBlock.php # src/material/block/GenericBlock.php # src/material/block/attachable/WallSignBlock.php # src/material/block/liquid/LiquidBlockDynamic.php # src/material/block/misc/AirBlock.php # src/material/block/misc/BedBlock.php # src/material/block/misc/TNTBlock.php # src/material/block/nonfull/CarpetBlock.php # src/material/block/nonfull/FenceBlock.php # src/material/block/nonfull/PoweredRailBlock.php # src/material/block/nonfull/RailBlock.php # src/material/block/nonfull/SnowLayerBlock.php # src/material/block/nonfull/WoodSlabBlock.php # src/material/block/plant/BrownMushroomBlock.php # src/material/block/plant/DandelionBlock.php # src/material/block/plant/MelonStemBlock.php # src/material/block/plant/PumpkinStemBlock.php # src/material/block/plant/RedMushroomBlock.php # src/material/block/plant/SugarcaneBlock.php # src/material/block/solid/GrassBlock.php # src/material/block/solid/IceBlock.php # src/material/block/solid/LeavesBlock.php # src/material/block/solid/ObsidianBlock.php # src/material/block/solid/PumpkinBlock.php # src/material/block/solid/WoolBlock.php # src/material/item/base/ItemHoe.php # src/material/item/base/ItemTool.php # src/material/item/generic/DyeItem.php # src/material/item/generic/SpawnEggItem.php # src/material/item/tool/FlintSteelItem.php # src/material/item/tool/ShearsItem.php # src/math/AxisAlignedBB.php # src/network/MinecraftInterface.php # src/network/UDPSocket.php # src/network/protocol/packet/AddItemEntityPacket.php # src/network/protocol/packet/ContainerSetContentPacket.php # src/network/raknet/RakNetDataPacket.php # src/network/raknet/RakNetParser.php # src/pmf/PMFLevel.php # src/utils/Utils.php # src/world/Explosion.php # src/world/Level.php # src/world/MobSpawner.php
This commit is contained in:
commit
3fbab46e60
245 changed files with 6118 additions and 3408 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class AchievementAPI{
|
||||
|
||||
|
||||
public static $achievements = [
|
||||
/*"openInventory" => array(
|
||||
"name" => "Taking Inventory",
|
||||
|
|
@ -79,20 +79,21 @@ class AchievementAPI{
|
|||
"buildSword",
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
|
||||
/** @var PocketMinecraftServer */
|
||||
private $server;
|
||||
|
||||
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an achievement
|
||||
* @param string $achievementId
|
||||
* @param string $achievementName
|
||||
* @return boolean
|
||||
* @param string $achievementName display name
|
||||
* @param array $requires a list of achievement ids, optional
|
||||
* @return boolean true if the achievement was added. false if the achievement with this id already exists.
|
||||
*/
|
||||
public static function addAchievement($achievementId, $achievementName, array $requires = []){
|
||||
if(!isset(self::$achievements[$achievementId])){
|
||||
|
|
@ -104,7 +105,13 @@ class AchievementAPI{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gives the achievement to player
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
* @return boolean
|
||||
*/
|
||||
public static function grantAchievement(Player $player, $achievementId){
|
||||
if(isset(self::$achievements[$achievementId]) and !self::hasAchievement($player, $achievementId)){
|
||||
foreach(self::$achievements[$achievementId]["requires"] as $requerimentId){
|
||||
|
|
@ -122,19 +129,29 @@ class AchievementAPI{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasAchievement(Player $player, $achievementId){
|
||||
if(!isset(self::$achievements[$achievementId]) or !isset($player->achievements)){
|
||||
$player->achievements = [];
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(!isset($player->achievements[$achievementId]) or !$player->achievements[$achievementId]){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
* @return boolean
|
||||
*/
|
||||
public static function broadcastAchievement(Player $player, $achievementId){
|
||||
if(isset(self::$achievements[$achievementId])){
|
||||
$result = ServerAPI::request()->api->dhandle("achievement.broadcast", ["player" => $player, "achievementId" => $achievementId]);
|
||||
|
|
@ -149,13 +166,18 @@ class AchievementAPI{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes achievement from player.
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
*/
|
||||
public static function removeAchievement(Player $player, $achievementId){
|
||||
if(self::hasAchievement($player, $achievementId)){
|
||||
$player->achievements[$achievementId] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function viewAchievements($cmd, $params, $issuer, $alias)
|
||||
{
|
||||
if(!isset($params[0])){
|
||||
|
|
@ -170,17 +192,17 @@ class AchievementAPI{
|
|||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(!$data){
|
||||
return "Player is not found.";
|
||||
}
|
||||
|
||||
|
||||
if($data instanceof Config){
|
||||
$achs = $data->get("achievements");
|
||||
}else{
|
||||
$achs = $data;
|
||||
}
|
||||
|
||||
|
||||
if(count($achs) <= 0){
|
||||
return "Player {$params[0]} unlocked 0 achievements";
|
||||
}
|
||||
|
|
@ -191,9 +213,9 @@ class AchievementAPI{
|
|||
$output .= "{$info["name"]}, ";
|
||||
}
|
||||
}
|
||||
return substr($output, 0, -2);
|
||||
return substr($output, 0, - 2);
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("ach", "<player>", [$this, "viewAchievements"]);
|
||||
$this->server->api->console->alias("getplayerachievements", "ach");
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
<?php
|
||||
|
||||
class BanAPI{
|
||||
|
||||
/** @var PocketMinecraftServer */
|
||||
private $server;
|
||||
/*
|
||||
* I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878
|
||||
*/
|
||||
/** @var Config */
|
||||
private $whitelist;
|
||||
/** @var Config */
|
||||
|
|
@ -14,10 +11,14 @@ class BanAPI{
|
|||
private $ops;
|
||||
/** @var Config */
|
||||
private $bannedIPs;
|
||||
/**
|
||||
* Contains commands that can be used by anyone on the server.
|
||||
* Keys: lowercased command name. Values don't matter.
|
||||
* @var array
|
||||
*/
|
||||
public $cmdWhitelist = [];
|
||||
|
||||
public $cmdWhitelist = [];//Command WhiteList
|
||||
|
||||
function __construct(){
|
||||
public function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +57,6 @@ class BanAPI{
|
|||
/**
|
||||
* @param mixed $data
|
||||
* @param string $event
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function permissionsCheck($data, $event){
|
||||
|
|
@ -106,11 +106,11 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks is player op or not
|
||||
* @param string $username
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isOp($username){//Is a player op?
|
||||
public function isOp($username){
|
||||
$username = strtolower($username);
|
||||
if($this->server->api->dhandle("op.check", $username) === true){
|
||||
return true;
|
||||
|
|
@ -121,6 +121,7 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Bans a player.
|
||||
* @param string $username
|
||||
*/
|
||||
public function ban($username){
|
||||
|
|
@ -316,14 +317,16 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $reason
|
||||
* Kicks a player
|
||||
* @param string $username - player's username
|
||||
* @param string $reason - kick reason, optional
|
||||
*/
|
||||
public function kick($username, $reason = "No Reason"){
|
||||
$this->commandHandler("kick", [$username, $reason], "console", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbans a player
|
||||
* @param string $username
|
||||
*/
|
||||
public function pardon($username){
|
||||
|
|
@ -331,6 +334,7 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Bans some ip
|
||||
* @param string $ip
|
||||
*/
|
||||
public function banIP($ip){
|
||||
|
|
@ -338,12 +342,16 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Unbans some ip
|
||||
* @param string $ip
|
||||
*/
|
||||
public function pardonIP($ip){
|
||||
$this->commandHandler("banip", ["pardon", $ip], "console", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Rereads ban list, kick list and banip list
|
||||
*/
|
||||
public function reload(){
|
||||
$this->commandHandler("ban", ["reload"], "console", "");
|
||||
$this->commandHandler("banip", ["reload"], "console", "");
|
||||
|
|
@ -351,8 +359,8 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks is ip banned or not
|
||||
* @param string $ip
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isIPBanned($ip){
|
||||
|
|
@ -366,8 +374,8 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks is username banned or not.
|
||||
* @param string $username
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isBanned($username){
|
||||
|
|
@ -382,8 +390,8 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks is username in the whitelist or not
|
||||
* @param string $username
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function inWhitelist($username){
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
class BlockAPI{
|
||||
|
||||
public static $creativeHotbarSlots = [];
|
||||
public static $reverseCreativeLookup = [];
|
||||
public static $creative = [
|
||||
|
||||
//Building
|
||||
[STONE, 0],
|
||||
[COBBLESTONE, 0],
|
||||
|
|
@ -201,8 +201,33 @@ class BlockAPI{
|
|||
private $scheduledUpdates = [];
|
||||
private $randomUpdates = [];
|
||||
|
||||
/**
|
||||
* @param int $id item id
|
||||
* @param int $meta item metadata
|
||||
* @return false|int false if item is not accessible from creative mode, otherwise slot id in BlockAPI::$creative
|
||||
*/
|
||||
public static function hasCreativeItem($id, $meta){
|
||||
$rind = ($id << 24) | ($meta);
|
||||
return static::$reverseCreativeLookup[$rind] ?? false;
|
||||
}
|
||||
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
foreach(static::$creative as $slot => [$id, $meta]){
|
||||
$rind = ($id << 24) | ($meta);
|
||||
static::$reverseCreativeLookup[$rind] = $slot;
|
||||
}
|
||||
|
||||
self::$creativeHotbarSlots[0] = static::hasCreativeItem(STONE, 0);
|
||||
self::$creativeHotbarSlots[1] = static::hasCreativeItem(COBBLESTONE, 0);
|
||||
self::$creativeHotbarSlots[2] = static::hasCreativeItem(DIRT, 0);
|
||||
self::$creativeHotbarSlots[3] = static::hasCreativeItem(PLANKS, 0);
|
||||
self::$creativeHotbarSlots[4] = static::hasCreativeItem(PLANKS, 1);
|
||||
self::$creativeHotbarSlots[5] = static::hasCreativeItem(TORCH, 0);
|
||||
self::$creativeHotbarSlots[6] = static::hasCreativeItem(BRICK_STAIRS, 0);
|
||||
self::$creativeHotbarSlots[7] = static::hasCreativeItem(COBBLE_WALL, 0);
|
||||
self::$creativeHotbarSlots[8] = static::hasCreativeItem(SAPLING, 0);
|
||||
|
||||
}
|
||||
|
||||
public static function get($id, $meta = 0, $v = false){
|
||||
|
|
@ -259,7 +284,7 @@ class BlockAPI{
|
|||
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$level = $issuer->entity->level;
|
||||
$block = self::fromString($args[3])->getBlock();
|
||||
}
|
||||
|
|
@ -294,8 +319,8 @@ class BlockAPI{
|
|||
break;
|
||||
case "give":
|
||||
$player = $this->server->api->player->get($args[0] ?? "");
|
||||
|
||||
if($player instanceof Player){
|
||||
|
||||
if($player instanceof Player){
|
||||
$item = self::fromString($args[1] ?? "");
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return "Player is in creative mode.";
|
||||
|
|
@ -303,18 +328,18 @@ class BlockAPI{
|
|||
if($item->getID() === 0){
|
||||
return "You cannot give an air block to a player.";
|
||||
}
|
||||
|
||||
|
||||
if(!isset($args[2])){
|
||||
$item->count = $item->getMaxStackSize();
|
||||
}else{
|
||||
$item->count = (int) $args[2];
|
||||
}
|
||||
|
||||
|
||||
$player->addItem($item->getID(), $item->getMetadata(), $item->count);
|
||||
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username;
|
||||
break;
|
||||
}else{
|
||||
$item = self::fromString($args[0] ?? "");
|
||||
$item = self::fromString($args[0] ?? "");
|
||||
if(!($issuer instanceof Player)){
|
||||
return "You cant give an item to a non-player.";
|
||||
}
|
||||
|
|
@ -341,6 +366,16 @@ class BlockAPI{
|
|||
return $output;
|
||||
}
|
||||
|
||||
public static function blockIDFromString($str){
|
||||
if(defined(strtoupper($str))){
|
||||
$ida = explode(":", constant(strtoupper($str)));
|
||||
if(count($ida) === 2){}
|
||||
return (int) $ida[0];
|
||||
}else if(is_numeric($str)){
|
||||
return (int) $str;
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromString($str, $multiple = false){
|
||||
if($multiple === true){
|
||||
$blocks = [];
|
||||
|
|
@ -392,26 +427,50 @@ class BlockAPI{
|
|||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
}
|
||||
|
||||
if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", ["player" => $player, "target" => $target, "item" => $item]) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - $player->getLag() / 1000) + $target->getBreakTime($item, $player) - 0.2) >= microtime(true)){
|
||||
|
||||
$currentTime = microtime(true);
|
||||
$isIndestructible = (!$target->isBreakable($item, $player) && $this->server->api->dhandle("player.block.break.invalid", ["player" => $player, "target" => $target, "item" => $item]) !== true);
|
||||
$isAdventure = ($player->gamemode & 0x02) === 0x02;
|
||||
$progress = $target->getDestroyProgress($player);
|
||||
|
||||
$tooFast = false;
|
||||
if($progress == 0 || is_nan($progress)){
|
||||
$exceptedTimeMS = INF;
|
||||
$tooFast = true;
|
||||
}else{
|
||||
$exceptedTimeMS = ceil(PocketMinecraftServer::$BLOCK_BREAKING_PROGRESS / $progress)*0.05;
|
||||
|
||||
}
|
||||
|
||||
if($player->gamemode == 1){ //creative
|
||||
$exceptedTimeMS = 0.05; //1 block/tick
|
||||
$tooFast = false;
|
||||
}
|
||||
|
||||
$exceptedTimeAfter = $player->lastBreak + $exceptedTimeMS;
|
||||
if($currentTime < $exceptedTimeAfter) $tooFast = true;
|
||||
if($isIndestructible || $isAdventure || $tooFast){
|
||||
if($this->server->api->dhandle("player.block.break.bypass", ["player" => $player, "target" => $target, "item" => $item]) !== true){
|
||||
if($tooFast){
|
||||
ConsoleAPI::warn("{$player->username} tried destroying block({$target->getID()} {$target->getMetadata()}) too fast($currentTime < $exceptedTimeAfter)");
|
||||
}
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
}
|
||||
$player->lastBreak = microtime(true);
|
||||
$player->lastBreak = $currentTime;
|
||||
|
||||
if($this->server->api->dhandle("player.block.break", ["player" => $player, "target" => $target, "item" => $item]) !== false){
|
||||
$drops = $target->getDrops($item, $player);
|
||||
if($target->onBreak($item, $player) === false){
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){
|
||||
$player->setSlot($player->slot, new Item(AIR, 0, 0), false);
|
||||
}
|
||||
|
||||
$item->mineBlock($target, $player);
|
||||
}else{
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
|
||||
|
||||
if(is_array($drops) && ($player->gamemode & 0x01) === 0x00 and count($drops) > 0){
|
||||
foreach($drops as $drop){
|
||||
$this->server->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2]));
|
||||
|
|
@ -421,15 +480,9 @@ class BlockAPI{
|
|||
}
|
||||
|
||||
private function cancelAction(Block $block, Player $player, $send = true){
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk->x = $block->x;
|
||||
$pk->y = $block->y;
|
||||
$pk->z = $block->z;
|
||||
$pk->block = $block->getID();
|
||||
$pk->meta = $block->getMetadata();
|
||||
$player->dataPacket($pk);
|
||||
$player->addBlockUpdateIntoQueue($block->x, $block->y, $block->z, $block->getID(), $block->getMetadata());
|
||||
if($send === true){
|
||||
$player->sendInventorySlot($player->slot);
|
||||
$player->sendInventory();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -441,7 +494,7 @@ class BlockAPI{
|
|||
|
||||
$target = $player->level->getBlock($vector);
|
||||
$block = $target->getSide($face);
|
||||
$item = $player->getSlot($player->slot);
|
||||
$item = $player->getHeldItem();
|
||||
|
||||
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ //If no block exists or not allowed in CREATIVE
|
||||
if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
|
||||
|
|
@ -455,7 +508,7 @@ class BlockAPI{
|
|||
return $this->cancelAction($block, $player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
StaticBlock::getBlock($target->getID())::interact($target->level, $target->x, $target->y, $target->z, $player);
|
||||
|
||||
if($target->isActivable === true){
|
||||
|
|
@ -466,7 +519,7 @@ class BlockAPI{
|
|||
|
||||
if(($player->gamemode & 0x02) === 0x02){ //Adventure mode!!
|
||||
if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
|
||||
return $this->cancelAction($block, $player, false);
|
||||
return $this->cancelAction($block, $player);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -474,10 +527,7 @@ class BlockAPI{
|
|||
return false;
|
||||
}
|
||||
|
||||
if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){
|
||||
if($item->count <= 0){
|
||||
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false);
|
||||
}
|
||||
if($item->isActivable === true && $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -485,14 +535,14 @@ class BlockAPI{
|
|||
$hand = $item->getBlock();
|
||||
$hand->position($block);
|
||||
}elseif($block->getID() === FIRE){
|
||||
$player->level->setBlock($block, new AirBlock(), true, false, true);
|
||||
$player->level->fastSetBlockUpdate($block->x, $block->y, $block->z, 0, 0, true, false);
|
||||
return false;
|
||||
}else{
|
||||
return $this->cancelAction($block, $player, false);
|
||||
}
|
||||
|
||||
if(!($block->isReplaceable === true or ($hand->getID() === SLAB and $block->getID() === SLAB))){
|
||||
return $this->cancelAction($block, $player, false);
|
||||
return $this->cancelAction($block, $player);
|
||||
}
|
||||
|
||||
if($target->isReplaceable === true){
|
||||
|
|
@ -500,32 +550,32 @@ class BlockAPI{
|
|||
$hand->position($block);
|
||||
//$face = -1;
|
||||
}
|
||||
|
||||
|
||||
if($hand->isSolid === true && ($hand->getID() != BED_BLOCK && $hand->getID() != CARPET)){
|
||||
$aabb = $hand->getAABB($block->level, $block->x, $block->y, $block->z);
|
||||
$playerbb = $player->entity->boundingBox;
|
||||
if(($aabb->maxX > $playerbb->minX && $aabb->minX < $playerbb->maxX) && ($aabb->maxY > ($playerbb->minY + 0.21) && $aabb->minY < $playerbb->maxY) && ($aabb->maxZ > $playerbb->minZ && $aabb->minZ < $playerbb->maxZ)){
|
||||
return $this->cancelAction($block, $player, false); //Entity in block
|
||||
foreach($block->level->players as $pl){
|
||||
$aabbs = $hand->getCollisionBoundingBoxes($block->level, $block->x, $block->y, $block->z, $pl->entity);
|
||||
foreach($aabbs as $aabb){
|
||||
$playerbb = $pl->entity->boundingBox;
|
||||
if(($aabb->maxX > $playerbb->minX && $aabb->minX < $playerbb->maxX) && ($aabb->maxY > ($playerbb->minY+0.21) && $aabb->minY < $playerbb->maxY) && ($aabb->maxZ > $playerbb->minZ && $aabb->minZ < $playerbb->maxZ)){
|
||||
return $this->cancelAction($block, $player); //Entity in block
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if($this->server->api->dhandle("player.block.place", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) === false){
|
||||
return $this->cancelAction($block, $player);
|
||||
}elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){
|
||||
return $this->cancelAction($block, $player, false);
|
||||
return $this->cancelAction($block, $player);
|
||||
}
|
||||
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){
|
||||
$t = $this->server->api->tile->addSign($player->level, $block->x, $block->y, $block->z);
|
||||
$t->data["creator"] = $player->username;
|
||||
}
|
||||
|
||||
if(($player->gamemode & 0x01) === 0x00){
|
||||
--$item->count;
|
||||
if($item->count <= 0){
|
||||
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false);
|
||||
}
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -536,12 +586,14 @@ class BlockAPI{
|
|||
return false;
|
||||
}
|
||||
$level = $block::onUpdate($pos->level, $pos->x, $pos->y, $pos->z, $type);
|
||||
|
||||
|
||||
return $level;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){
|
||||
|
||||
|
||||
if($type == BLOCK_UPDATE_NORMAL){
|
||||
try{
|
||||
throw new Exception("Deprecated: tried updating $pos using BLOCK_UPDATE_NORMAL.");
|
||||
|
|
@ -551,7 +603,7 @@ class BlockAPI{
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if($delay !== false){
|
||||
$this->scheduleBlockUpdate($pos->getSide(0), $delay, $type);
|
||||
$this->scheduleBlockUpdate($pos->getSide(1), $delay, $type);
|
||||
|
|
@ -568,12 +620,24 @@ class BlockAPI{
|
|||
$this->blockUpdate($pos->getSide(5), $type);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAllBlockUpdates(Level $level){
|
||||
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE level = '{$level->getName()}';");
|
||||
if($update instanceof SQLite3Result){
|
||||
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$index = $up["x"] . "." . $up["y"] . "." . $up["z"] . "." . $up["level"] . "." . $up["type"];
|
||||
unset($this->scheduledUpdates[$index]);
|
||||
}
|
||||
$this->server->query("DELETE FROM blockUpdates WHERE level = '{$level->getName()}';");
|
||||
}
|
||||
}
|
||||
|
||||
public function scheduleBlockUpdateXYZ(Level $level, $x, $y, $z, $type = BLOCK_UPDATE_SCHEDULED, $delay = false){
|
||||
$type = (int) $type;
|
||||
if($delay < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$index = $x . "." . $y . "." . $z . "." . $level->getName() . "." . $type;
|
||||
$delay = microtime(true) + $delay * 0.05;
|
||||
if(!isset($this->scheduledUpdates[$index])){
|
||||
|
|
@ -583,43 +647,11 @@ class BlockAPI{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){
|
||||
$type = (int) $type;
|
||||
if($delay < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
$index = $pos->x . "." . $pos->y . "." . $pos->z . "." . $pos->level->getName() . "." . $type;
|
||||
$delay = microtime(true) + $delay * 0.05;
|
||||
if(!isset($this->scheduledUpdates[$index])){
|
||||
$this->scheduledUpdates[$index] = $pos;
|
||||
$this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES (" . $pos->x . ", " . $pos->y . ", " . $pos->z . ", '" . $pos->level->getName() . "', " . $type . ", " . $delay . ");");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return $this->scheduleBlockUpdateXYZ($pos->level, $pos->x, $pos->y, $pos->z, $type, $delay);
|
||||
}
|
||||
|
||||
public function nextRandomUpdate(Position $pos){
|
||||
if(!isset($this->scheduledUpdates[$pos->x . "." . $pos->y . "." . $pos->z . "." . $pos->level->getName() . "." . BLOCK_UPDATE_RANDOM])){
|
||||
$time = microtime(true);
|
||||
$offset = 0;
|
||||
while(true){
|
||||
$t = $offset + Utils::getRandomUpdateTicks() * 0.05;
|
||||
$update = $this->server->query("SELECT COUNT(*) FROM blockUpdates WHERE level = '" . $pos->level->getName() . "' AND type = " . BLOCK_UPDATE_RANDOM . " AND delay >= " . ($time + $t - 1) . " AND delay <= " . ($time + $t + 1) . ";");
|
||||
if($update instanceof SQLite3Result){
|
||||
$update = $update->fetchArray(SQLITE3_NUM);
|
||||
if($update[0] < 3){
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
$offset += mt_rand(25, 75);
|
||||
}
|
||||
$this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM);
|
||||
}
|
||||
}
|
||||
|
||||
public function blockUpdateTick(){
|
||||
$time = microtime(true);
|
||||
|
|
@ -641,31 +673,11 @@ class BlockAPI{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 方块/物品id转换,防止新版本影响旧版本视觉效果
|
||||
* @deprecated random updates are handled differently now.
|
||||
*/
|
||||
public static function convertHighItemIdsToOldItemIds(int $protocolId, int $itemId) : int{
|
||||
if ($protocolId >= ProtocolInfo12::CURRENT_PROTOCOL_12) {
|
||||
return $itemId;
|
||||
}
|
||||
|
||||
$idMap = [ //default for protocol < 12
|
||||
LIT_PUMPKIN => MELON_BLOCK, //block
|
||||
PUMPKIN_SEEDS => MELON_SEEDS, //item
|
||||
PUMPKIN_PIE => BREAD, //item
|
||||
BEETROOT => BREAD, //item
|
||||
BEETROOT_SEEDS => SEEDS, //item
|
||||
];
|
||||
|
||||
if ($protocolId < ProtocolInfo9::CURRENT_PROTOCOL_9) {
|
||||
$idMap += [
|
||||
NETHERRACK => OBSIDIAN, //block
|
||||
NETHER_BRICK => BRICK, //item
|
||||
NETHER_QUARTZ => BRICK, //item
|
||||
];
|
||||
}
|
||||
|
||||
return $idMap[$itemId] ?? $itemId;
|
||||
public function nextRandomUpdate(Position $pos){
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,18 +3,21 @@
|
|||
class ChatAPI{
|
||||
|
||||
private $server;
|
||||
|
||||
public $lastTells = [];
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("tell", "<player> <private message ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("reply", "<private message ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("me", "<action ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("say", "<message ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->cmdWhitelist("tell");
|
||||
$this->server->api->console->cmdWhitelist("reply");
|
||||
$this->server->api->console->cmdWhitelist("me");
|
||||
$this->server->api->console->alias("msg", "tell");
|
||||
$this->server->api->console->alias("r", "reply");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -26,23 +29,20 @@ class ChatAPI{
|
|||
* @return string
|
||||
*/
|
||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||
$output = "";
|
||||
switch($cmd){
|
||||
case "say":
|
||||
$s = implode(" ", $params);
|
||||
if(trim($s) == ""){
|
||||
$output .= "Usage: /say <message>\n";
|
||||
break;
|
||||
return "Usage: /say <message>";
|
||||
}
|
||||
$sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer);
|
||||
if(Utils::hasEmoji($s)) return "Your message contains illegal characters!";
|
||||
if(Player::$disableEmojisInChat && Utils::hasEmoji($s)) return "Your message contains illegal characters!";
|
||||
$this->server->api->chat->broadcast("[$sender] " . $s);
|
||||
break;
|
||||
case "me":
|
||||
$s = implode(" ", $params);
|
||||
if(trim($s) == ""){
|
||||
$output .= "Usage: /me <message>\n";
|
||||
break;
|
||||
return "Usage: /me <message>";
|
||||
}
|
||||
if(!($issuer instanceof Player)){
|
||||
if($issuer === "rcon"){
|
||||
|
|
@ -54,46 +54,62 @@ class ChatAPI{
|
|||
$sender = $issuer->username;
|
||||
}
|
||||
$msg = implode(" ", $params);
|
||||
if(Utils::hasEmoji($msg)) return "Your message contains illegal characters!";
|
||||
if(Player::$disableEmojisInChat && Utils::hasEmoji($msg)) return "Your message contains illegal characters!";
|
||||
$this->broadcast("* $sender $msg");
|
||||
break;
|
||||
case "tell":
|
||||
if(!isset($params[0]) or !isset($params[1])){
|
||||
$output .= "Usage: /$cmd <player> <message>\n";
|
||||
break;
|
||||
}
|
||||
if(!($issuer instanceof Player)){
|
||||
$sender = ucfirst($issuer);
|
||||
}else{
|
||||
$sender = $issuer->username;
|
||||
}
|
||||
if(!isset($params[0]) or !isset($params[1])) return "Usage: /$cmd <player> <message>\n";
|
||||
|
||||
if(!($issuer instanceof Player)) $sender = ucfirst($issuer);
|
||||
else $sender = $issuer->username;
|
||||
|
||||
$n = array_shift($params);
|
||||
$target = $this->server->api->player->get($n);
|
||||
if($target instanceof Player){
|
||||
$target = $target->username;
|
||||
}else{
|
||||
$target = strtolower($n);
|
||||
if($target === "server" or $target === "console" or $target === "rcon"){
|
||||
if($target === "server" || $target === "console" || $target === "rcon"){
|
||||
$target = "Console";
|
||||
}else{
|
||||
return "The player is offline.";
|
||||
return "$target is offline.";
|
||||
}
|
||||
}
|
||||
if(strtolower($target) === strtolower($issuer)){
|
||||
return "You can't send message to yourself.";
|
||||
if(strtolower($target) === strtolower($sender)) return "You can't send message to yourself.";
|
||||
|
||||
$mes = implode(" ", $params);
|
||||
if(Utils::hasEmoji($mes)) return "Your message contains illegal characters!";
|
||||
|
||||
if($target !== "Console" && $target !== "Rcon") $this->sendTo(false, "$sender whispers to you: $mes", $target);
|
||||
if($target === "Console" || $sender === "Console") console("[INFO] $sender whispers to $target: $mes");
|
||||
|
||||
|
||||
$this->lastTells[strtolower($target)] = strtolower($sender);
|
||||
$this->lastTells[strtolower($sender)] = strtolower($target);
|
||||
|
||||
return "You're whispering to $target: $mes";
|
||||
case "reply":
|
||||
if(!($issuer instanceof Player)) $sender = ucfirst($issuer);
|
||||
else $sender = $issuer->username;
|
||||
|
||||
if(!isset($this->lastTells[strtolower($sender)])) return "You have no one to reply to.";
|
||||
$target = $this->lastTells[strtolower($sender)];
|
||||
if($target !== "server" && $target !== "console" && $target !== "rcon"){
|
||||
if(!($this->server->api->player->get($target) instanceof Player)){
|
||||
return "$target is offline.";
|
||||
}
|
||||
}
|
||||
$mes = implode(" ", $params);
|
||||
if(Utils::hasEmoji($mes)) return "Your message contains illegal characters!";
|
||||
$output .= "You're whispering to " . $target . ": " . $mes . "\n";
|
||||
if($target !== "Console" and $target !== "Rcon"){
|
||||
$this->sendTo(false, $sender . " whispers to you: " . $mes, $target);
|
||||
}
|
||||
if($target === "Console" or $sender === "Console"){
|
||||
console("[INFO] " . $sender . " whispers to " . $target . ": " . $mes);
|
||||
}
|
||||
break;
|
||||
|
||||
if($target !== "Console" && $target !== "Rcon") $this->sendTo(false, "$sender whispers to you: $mes", $target);
|
||||
if($target === "Console" || $sender === "Console") console("[INFO] $sender whispers to $target: $mes");
|
||||
|
||||
$this->lastTells[strtolower($target)] = strtolower($sender);
|
||||
$this->lastTells[strtolower($sender)] = strtolower($target);
|
||||
|
||||
return "You're whispering to $target: $mes";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class ConsoleAPI{
|
||||
private static $loop; //why no Thread::kill in pthreads3
|
||||
private $loop; //why no Thread::kill in pthreads3. Making it static causes crashes of other threads on some servers(hi nper)
|
||||
private $server, $event, $help, $cmds, $alias;
|
||||
public $last;
|
||||
function __construct(){
|
||||
|
|
@ -15,7 +15,7 @@ class ConsoleAPI{
|
|||
public function init(){
|
||||
$this->server->schedule(2, [$this, "handle"], [], true);
|
||||
if(!defined("NO_THREADS")){
|
||||
self::$loop = new ConsoleLoop();
|
||||
$this->loop = new ConsoleLoop();
|
||||
}
|
||||
$this->register("help", "[page|command name]", [$this, "defaultCommands"]);
|
||||
$this->register("status", "", [$this, "defaultCommands"]);
|
||||
|
|
@ -51,8 +51,8 @@ class ConsoleAPI{
|
|||
function __destruct(){
|
||||
$this->server->deleteEvent($this->event);
|
||||
if(!defined("NO_THREADS")){
|
||||
self::$loop->stop();
|
||||
self::$loop->notify();
|
||||
$this->loop->stop();
|
||||
$this->loop->notify();
|
||||
usleep(50000);
|
||||
}
|
||||
}
|
||||
|
|
@ -66,10 +66,10 @@ class ConsoleAPI{
|
|||
if(defined("NO_THREADS")){
|
||||
return;
|
||||
}
|
||||
$line = self::$loop->line;
|
||||
$line = $this->loop->line;
|
||||
if($line !== false){
|
||||
$line = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", trim($line));
|
||||
self::$loop->line = false;
|
||||
$this->loop->line = false;
|
||||
$output = $this->run($line, "console");
|
||||
if($output != ""){
|
||||
$mes = explode("\n", trim($output));
|
||||
|
|
@ -78,7 +78,7 @@ class ConsoleAPI{
|
|||
}
|
||||
}
|
||||
}else{
|
||||
self::$loop->notify();
|
||||
$this->loop->notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -202,24 +202,25 @@ class ConsoleAPI{
|
|||
"v" => VIEW,
|
||||
];
|
||||
if(!isset($params[0]) or !isset($gms[strtolower($params[0])])){
|
||||
$output .= "Usage: /$cmd <mode>\n";
|
||||
break;
|
||||
return "Usage: /$cmd <mode>";
|
||||
}
|
||||
$this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]);
|
||||
$output .= "Default Gamemode is now " . strtoupper($this->server->getGamemode()) . ".\n";
|
||||
break;
|
||||
case "status":
|
||||
if(!($issuer instanceof Player) and $issuer === "console"){
|
||||
$info = $this->server->debugInfo(true);
|
||||
}else{
|
||||
$info = $this->server->debugInfo();
|
||||
$info = $this->server->debugInfo();
|
||||
if(!($issuer instanceof Player) && $issuer === "console"){
|
||||
$lightUpdates = 0;
|
||||
foreach($this->server->api->level->levels as $level){
|
||||
$lightUpdates += count($level->lightUpdates);
|
||||
}
|
||||
return "TPS: {$info["tps"]}, Memory usage: {$info["memory_usage"]} (Peak {$info["memory_peak_usage"]}), Entities: {$info["entities"]}, Events: {$info["events"]}, Handlers: {$info["handlers"]}, Actions: {$info["actions"]}, Garbage: {$info["garbage"]}, Light updates: {$lightUpdates}";
|
||||
}
|
||||
return "TPS: " . $info["tps"] . ", Memory usage: " . $info["memory_usage"] . " (Peak " . $info["memory_peak_usage"] . ")";
|
||||
return "TPS: {$info["tps"]}, Memory usage: {$info["memory_usage"]} (Peak {$info["memory_peak_usage"]})";
|
||||
case "stop":
|
||||
self::$loop->stop = true;
|
||||
$output .= "Stopping the server\n";
|
||||
$this->loop->stop = true;
|
||||
$this->server->close();
|
||||
break;
|
||||
return "Stopping the server\n";
|
||||
case "difficulty":
|
||||
$s = trim(array_shift($params));
|
||||
if($s === "" or (((int) $s) > 3 and ((int) $s) < 0)){
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
class EntityAPI{
|
||||
/**
|
||||
* @var Entity[]
|
||||
*/
|
||||
public $entities;
|
||||
private $server;
|
||||
private $eCnt = 1;
|
||||
|
|
@ -8,25 +11,26 @@ class EntityAPI{
|
|||
function __construct(){
|
||||
$this->entities = [];
|
||||
$this->server = ServerAPI::request();
|
||||
|
||||
|
||||
$this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals");
|
||||
$this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs");
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("despawn", "", [$this, "CommandHandler"]);
|
||||
$this->server->api->console->register("entcnt", "", [$this, "CommandHandler"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function commandHandler($cmd, $args, $issuer, $alias){
|
||||
$mob = [
|
||||
"chicken" => 10,
|
||||
"cow" => 11,
|
||||
"pig" => 12,
|
||||
"sheep" => 13,
|
||||
|
||||
|
||||
"zombie" => 32,
|
||||
"creeper" => 33,
|
||||
"skeleton" => 34,
|
||||
|
|
@ -45,24 +49,55 @@ class EntityAPI{
|
|||
if((count($args) < 1) or (count($args) > 3)){
|
||||
return "Usage: /$cmd <mob> [amount] [baby]";
|
||||
}
|
||||
|
||||
|
||||
if(is_int($args[0])) $type = $args[0];
|
||||
else $type = $mob[strtolower($args[0])] ?? 0;
|
||||
if($type < 10 || $type > 36){
|
||||
return "Unknown mob.";
|
||||
if($args[0] != "secret") return "Unknown mob.";
|
||||
}
|
||||
$mobName = ucfirst(array_flip($mob)[$type]);
|
||||
|
||||
$mobName = $args[0] == "secret" ? "" : ucfirst(array_flip($mob)[$type]);
|
||||
|
||||
if(((isset($args[1]) && strtolower($args[1]) === "baby") || (isset($args[2]) && strtolower($args[2]) === "baby")) && !Utils::in_range($type, 10, 13)){
|
||||
return "$mobName cannot be a baby!";
|
||||
}
|
||||
|
||||
|
||||
$x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP);
|
||||
$y = round($issuer->entity->y, 2, PHP_ROUND_HALF_UP);
|
||||
$z = round($issuer->entity->z, 2, PHP_ROUND_HALF_UP);
|
||||
$level = $issuer->entity->level;
|
||||
$pos = new Position($x, $y, $z, $level);
|
||||
|
||||
|
||||
if($args[0] == "secret"){
|
||||
$data = [
|
||||
"x" => $pos->x,
|
||||
"y" => $pos->y,
|
||||
"z" => $pos->z
|
||||
];
|
||||
$e = $this->add($level, ENTITY_MOB, MOB_SPIDER, $data);
|
||||
$e2 = $this->add($level, ENTITY_MOB, MOB_SKELETON, $data);
|
||||
$e3 = $this->add($level, ENTITY_MOB, MOB_ZOMBIE, $data);
|
||||
$e4 = $this->add($level, ENTITY_MOB, MOB_SKELETON, $data);
|
||||
$e5 = $this->add($level, ENTITY_MOB, MOB_SKELETON, $data);
|
||||
$e6 = $this->add($level, ENTITY_MOB, MOB_SKELETON, $data);
|
||||
$e7 = $this->add($level, ENTITY_MOB, MOB_SKELETON, $data);
|
||||
|
||||
$this->spawnToAll($e7);
|
||||
$this->spawnToAll($e6);
|
||||
$this->spawnToAll($e5);
|
||||
$this->spawnToAll($e4);
|
||||
$this->spawnToAll($e3);
|
||||
$this->spawnToAll($e2);
|
||||
$this->spawnToAll($e);
|
||||
|
||||
$e2->setRiding($e);
|
||||
$e3->setRiding($e2);
|
||||
$e4->setRiding($e3);
|
||||
$e5->setRiding($e4);
|
||||
$e6->setRiding($e5);
|
||||
$e7->setRiding($e6);
|
||||
return "???";
|
||||
}
|
||||
|
||||
if(count($args) === 1){//summon <mob>
|
||||
$this->summon($pos, ENTITY_MOB, $type);
|
||||
return "$mobName spawned in $x, $y, $z.";
|
||||
|
|
@ -76,11 +111,11 @@ class EntityAPI{
|
|||
if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon <mob> [amount] [baby]
|
||||
$isBaby = true;
|
||||
}
|
||||
|
||||
|
||||
for($cnt = $amount; $cnt > 0; --$cnt){
|
||||
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]);
|
||||
}
|
||||
|
||||
|
||||
return "$amount ".($isBaby ? "Baby " : "")."$mobName(s) spawned in $x, $y, $z.";
|
||||
}
|
||||
elseif(strtolower($args[1]) == "baby"){//summon <mob> [baby]
|
||||
|
|
@ -93,7 +128,7 @@ class EntityAPI{
|
|||
if(!isset($args[0])){
|
||||
return "/despawn <all|mobs|objects|items|fallings|minecarts>";
|
||||
}
|
||||
|
||||
|
||||
$despawnclass = 0;
|
||||
$despawntype = 0;
|
||||
switch($args[0]){
|
||||
|
|
@ -137,12 +172,12 @@ class EntityAPI{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return "$cnt entities have been despawned!";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
public function summon(Position $pos, $class, $type, array $data = []){
|
||||
$entity = $this->add($pos->level, $class, $type, [
|
||||
"x" => $pos->x,
|
||||
|
|
@ -151,16 +186,16 @@ class EntityAPI{
|
|||
] + $data);
|
||||
$this->spawnToAll($entity);
|
||||
}
|
||||
|
||||
|
||||
public function getNextEID(){
|
||||
return $this->eCnt++;
|
||||
}
|
||||
|
||||
|
||||
public function addRaw(Entity $e){
|
||||
$eid = $e->eid;
|
||||
$this->entities[$eid] = $e;
|
||||
$cX = (int) $this->entities[$eid]->x >> 4;
|
||||
$cZ = (int) $this->entities[$eid]->z >> 4;
|
||||
$cX = (int)$this->entities[$eid]->x >> 4;
|
||||
$cZ = (int)$this->entities[$eid]->z >> 4;
|
||||
$e->level->entityListPositioned["$cX $cZ"][$eid] = $eid;
|
||||
$e->level->entityList[$eid] = &$this->entities[$eid];
|
||||
$this->server->handle("entity.add", $this->entities[$eid]);
|
||||
|
|
@ -177,26 +212,31 @@ class EntityAPI{
|
|||
}
|
||||
return $this->addRaw($e);
|
||||
}
|
||||
|
||||
|
||||
public function spawnToAll(Entity $e){
|
||||
foreach($this->server->api->player->getAll($e->level) as $player){
|
||||
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
|
||||
if($player->spawned && $player->eid != false && $player->eid != $e->eid && $e->class != ENTITY_PLAYER && $e instanceof Entity){
|
||||
if($e->closed !== false || ($player->level !== $e->level && $e->class !== ENTITY_PLAYER)){
|
||||
return false;
|
||||
}
|
||||
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get($eid){
|
||||
return $this->entities[$eid] ?? false;
|
||||
}
|
||||
|
||||
|
||||
public function remove($eid){
|
||||
if(isset($this->entities[$eid])){
|
||||
$e = $this->entities[$eid];
|
||||
$level = $this->entities[$eid]->level;
|
||||
$this->entities[$eid]->closed = true;
|
||||
if($level instanceof Level){
|
||||
$cX = (int) $this->entities[$eid]->x >> 4;
|
||||
$cZ = (int) $this->entities[$eid]->z >> 4;
|
||||
$cX = (int)$this->entities[$eid]->x >> 4;
|
||||
$cZ = (int)$this->entities[$eid]->z >> 4;
|
||||
$index = "$cX $cZ";
|
||||
unset($level->entityListPositioned[$index][$eid]);
|
||||
if(isset($level->mobSpawner->entityAffectedPlayers[$eid])){
|
||||
|
|
@ -209,23 +249,36 @@ class EntityAPI{
|
|||
$pk = new RemovePlayerPacket;
|
||||
$pk->eid = $eid;
|
||||
$pk->clientID = 0;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll(), $pk);
|
||||
foreach($this->server->api->player->getAll() as $player){
|
||||
$player->entityQueueDataPacket(clone $pk);
|
||||
$player->removeEntity($e);
|
||||
}
|
||||
}else{
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $eid;
|
||||
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
|
||||
foreach($this->entities[$eid]->level->players as $player){
|
||||
$player->entityQueueDataPacket(clone $pk);
|
||||
$player->removeEntity($e);
|
||||
}
|
||||
}
|
||||
$this->server->api->dhandle("entity.remove", $this->entities[$eid]);
|
||||
unset($this->entities[$eid]->level->entityList[$eid]);
|
||||
unset($this->entities[$eid]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Position $center
|
||||
* @param number $radius
|
||||
* @param boolean $class
|
||||
* @return Entity[]
|
||||
*/
|
||||
public function getRadius(Position $center, $radius = 15, $class = false){
|
||||
$minChunkX = ((int) ($center->x - $radius)) >> 4;
|
||||
$minChunkZ = ((int) ($center->z - $radius)) >> 4;
|
||||
$maxChunkX = ((int) ($center->x + $radius)) >> 4;
|
||||
$maxChunkZ = ((int) ($center->z + $radius)) >> 4;
|
||||
$minChunkX = ((int)($center->x - $radius)) >> 4;
|
||||
$minChunkZ = ((int)($center->z - $radius)) >> 4;
|
||||
$maxChunkX = ((int)($center->x + $radius)) >> 4;
|
||||
$maxChunkZ = ((int)($center->z + $radius)) >> 4;
|
||||
$ents = [];
|
||||
//TODO also index by chunkY?
|
||||
for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){
|
||||
|
|
@ -243,11 +296,11 @@ class EntityAPI{
|
|||
}
|
||||
return $ents;
|
||||
}
|
||||
|
||||
|
||||
public function heal($eid, $heal, $cause){
|
||||
$this->harm($eid, -$heal, $cause);
|
||||
}
|
||||
|
||||
|
||||
public function harm($eid, $attack, $cause, $force = false){
|
||||
$e = $this->get($eid);
|
||||
if($e === false or $e->dead === true){
|
||||
|
|
@ -255,7 +308,7 @@ class EntityAPI{
|
|||
}
|
||||
$e->setHealth($e->getHealth() - $attack, $cause, $force);
|
||||
}
|
||||
|
||||
|
||||
public function dropRawPos(Level $level, $x, $y, $z, $item, $speedX, $speedY, $speedZ){
|
||||
if($item->getID() === AIR or $item->count <= 0){
|
||||
return;
|
||||
|
|
@ -271,7 +324,7 @@ class EntityAPI{
|
|||
"item" => $item,
|
||||
"itemID" => $item->getID()
|
||||
];
|
||||
|
||||
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
for($count = $item->count; $count > 0;){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
|
|
@ -282,7 +335,7 @@ class EntityAPI{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function drop(Position $pos, Item $item, $pickupDelay = 10){
|
||||
if($item->getID() === AIR or $item->count <= 0){
|
||||
return;
|
||||
|
|
@ -309,7 +362,7 @@ class EntityAPI{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function spawnAll(Player $player){
|
||||
foreach($player->level->entityList as $e){
|
||||
if($e->class !== ENTITY_PLAYER){
|
||||
|
|
@ -317,18 +370,18 @@ class EntityAPI{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getAll($level = null){
|
||||
if($level instanceof Level){
|
||||
return $level->entityList;
|
||||
}
|
||||
return $this->entities;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated this function doesnt do anything
|
||||
*/
|
||||
public function updateRadius(Position $center, $radius = 15, $class = false){
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class LevelAPI{
|
|||
$this->server->api->console->register("save-on", "", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("save-off", "", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("setwspawn", "Set the spawn position for your current world. ", [$this, "commandHandler"]);
|
||||
|
||||
$this->default = $this->server->api->getProperty("level-name");
|
||||
if($this->loadLevel($this->default) === false){
|
||||
$this->generateLevel($this->default, $this->server->seed);
|
||||
|
|
@ -108,8 +109,9 @@ class LevelAPI{
|
|||
return true;
|
||||
}
|
||||
/**
|
||||
* Gets a level by name. Returns false if no level with such name exists.
|
||||
* @param string $name
|
||||
* @return Level|boolean
|
||||
* @return Level|false
|
||||
*/
|
||||
public function get($name){
|
||||
if(isset($this->levels[$name])){
|
||||
|
|
@ -224,19 +226,6 @@ class LevelAPI{
|
|||
return false;
|
||||
}
|
||||
console("[INFO] Unloading level \"" . $name . "\"");
|
||||
$level->nextSave = PHP_INT_MAX;
|
||||
$level->save();
|
||||
foreach($this->server->api->player->getAll($level) as $player){
|
||||
$player->teleport($this->server->spawn);
|
||||
}
|
||||
foreach($this->server->api->entity->getAll($level) as $entity){
|
||||
if($entity->class !== ENTITY_PLAYER){
|
||||
$entity->close();
|
||||
}
|
||||
}
|
||||
foreach($this->server->api->tile->getAll($level) as $tile){
|
||||
$tile->close();
|
||||
}
|
||||
$level->close();
|
||||
unset($this->levels[$name]);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class PlayerAPI{
|
|||
$this->registerCmd("ping");
|
||||
$this->registerCmd("loc");
|
||||
$this->registerCmd("hotbar", "<slotcount>");
|
||||
|
||||
|
||||
$this->server->api->console->alias("lag", "ping");
|
||||
$this->server->api->console->alias("gm", "gamemode");
|
||||
$this->server->api->console->alias("who", "list");
|
||||
|
|
@ -49,9 +49,9 @@ class PlayerAPI{
|
|||
if($e->shotByEntity && isset($this->server->api->entity->entities[$e->shooterEID]) && $this->server->api->entity->entities[$e->shooterEID] instanceof Entity){
|
||||
$message = " was shot by {$this->server->api->entity->entities[$e->shooterEID]->name}";
|
||||
}else{
|
||||
$message = " was shot";
|
||||
$message = " was shot";
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
$message = " was killed by {$e->name}";
|
||||
}
|
||||
|
|
@ -104,12 +104,12 @@ class PlayerAPI{
|
|||
case "hotbar":
|
||||
if(!($issuer instanceof Player)) return "Please run this command in-game.";
|
||||
if(count($args) < 1) return "Slots in hotbar on server: {$issuer->slotCount}";
|
||||
|
||||
|
||||
$scrw = $args[0];
|
||||
if(is_numeric($scrw)){
|
||||
$sc = (int) $scrw;
|
||||
$sc = (int)$scrw;
|
||||
if($sc < 5 || $sc > 9) return "Slot count must be between 5 and 9.";
|
||||
|
||||
|
||||
$issuer->setSlotCount($sc);
|
||||
$issuer->sendInventory();
|
||||
return "Changed slot count to $sc";
|
||||
|
|
@ -123,10 +123,35 @@ class PlayerAPI{
|
|||
$issuer->teleport($this->server->spawn);
|
||||
return "You were teleported to the spawn.";
|
||||
case "ping":
|
||||
$additional = false;
|
||||
if(!($issuer instanceof Player)){
|
||||
return "Please run this command in-game.";
|
||||
if(isset($args[0])){
|
||||
goto get_ping_of_others;
|
||||
}
|
||||
return "Usage: /$cmd <username>.";
|
||||
}
|
||||
return "ping " . round($issuer->getLag(), 2) . "ms, packet loss " . round($issuer->getPacketLoss() * 100, 2) . "%, " . round($issuer->getBandwidth() / 1024, 2) . " KB/s\n";
|
||||
|
||||
if(isset($args[0]) && $this->server->api->ban->isOp($issuer->iusername)){
|
||||
get_ping_of_others:
|
||||
$additional = true;
|
||||
$p = $this->get($args[0]);
|
||||
if(!($p instanceof Player)){
|
||||
return "Player with username '{$args[0]}' is not on server.";
|
||||
}
|
||||
}else{
|
||||
$p = $issuer;
|
||||
}
|
||||
$ping = round($p->getLag(), 2);
|
||||
$pkLoss = round($p->getPacketLoss() * 100, 2);
|
||||
$transfer = round($p->getBandwidth() / 1024, 2);
|
||||
$additionalInfo = "";
|
||||
if($additional){
|
||||
$arqCnt = count($p->packetAlwaysRecoverQueue);
|
||||
$rqCnt = count($p->recoveryQueue);
|
||||
$additionalInfo = "ARQ/RQ/EMPS: $arqCnt/$rqCnt";
|
||||
}
|
||||
$chunksCnt = count($p->chunkDataSent);
|
||||
return "{$p->username}'s ping: {$ping}ms, packet loss {$pkLoss}%, $transfer KB/s. Chunks: $chunksCnt/256\n$additionalInfo";
|
||||
case "gamemode":
|
||||
$player = false;
|
||||
$setgm = false;
|
||||
|
|
@ -207,7 +232,8 @@ class PlayerAPI{
|
|||
}
|
||||
case "kill":
|
||||
case "suicide":
|
||||
if(!isset($args[0]) and ($issuer instanceof Player)){
|
||||
if(!isset($args[0])){
|
||||
if(!($issuer instanceof Player)) return "Usage: /kill <player>";
|
||||
$player = $issuer;
|
||||
}else{
|
||||
$player = $this->get($args[0]);
|
||||
|
|
@ -228,18 +254,37 @@ class PlayerAPI{
|
|||
}
|
||||
return substr($output, 0, -2) . "\n";
|
||||
case "loc":
|
||||
if(!($issuer instanceof Player)) return "Please run this command in-game.";
|
||||
$x = round($issuer->entity->x, 1, PHP_ROUND_HALF_UP);
|
||||
$y = round($issuer->entity->y, 1, PHP_ROUND_HALF_UP);
|
||||
$z = round($issuer->entity->z, 1, PHP_ROUND_HALF_UP);
|
||||
$level = $issuer->entity->level->getName();
|
||||
if(!($issuer instanceof Player)){
|
||||
if(isset($args[0])){
|
||||
goto get_coords_of_others;
|
||||
}
|
||||
return "Usage: /$cmd <username>.";
|
||||
}
|
||||
|
||||
if(isset($args[0]) && $this->server->api->ban->isOp($issuer->iusername)){
|
||||
get_coords_of_others:
|
||||
$p = $this->get($args[0]);
|
||||
if(!($p instanceof Player)){
|
||||
return "Player with username '{$args[0]}' is not on server.";
|
||||
}
|
||||
$ent = $p->entity;
|
||||
$username = $p->username;
|
||||
}else{
|
||||
$ent = $issuer->entity;
|
||||
$username = $issuer->username;
|
||||
}
|
||||
|
||||
$x = round($ent->x, 1, PHP_ROUND_HALF_UP);
|
||||
$y = round($ent->y, 1, PHP_ROUND_HALF_UP);
|
||||
$z = round($ent->z, 1, PHP_ROUND_HALF_UP);
|
||||
$level = $ent->level->getName();
|
||||
$compass = [0 => "X+", 1 => "Z+", 2 => "X-", 3 => "Z-", null => "null"];
|
||||
$direction = $compass[$issuer->entity->getDirection()];
|
||||
|
||||
$direction = $compass[$ent->getDirection()];
|
||||
|
||||
$xChunk = $x >> 4;
|
||||
$zChunk = $z >> 4;
|
||||
|
||||
return "Your coordinates: X: $x ($xChunk), Y: $y, Z: $z ($zChunk), world: $level.\nDirection: $direction";
|
||||
$brightness = $ent->level->getRawBrightness((int)$x, (int)$y, (int)$z);
|
||||
return "$username's coordinates: X: $x ($xChunk), Y: $y, Z: $z ($zChunk), world: $level.\nDirection: $direction Brightness: $brightness";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
@ -249,7 +294,10 @@ class PlayerAPI{
|
|||
if($name === ""){
|
||||
return false;
|
||||
}
|
||||
$query = $this->server->query("SELECT ip,port,name FROM players WHERE name " . ($alike === true ? "LIKE '" . $name . "%'" : "= '" . $name . "'") . ";");
|
||||
$this->server->preparedSQL->player->getEq->reset();
|
||||
$this->server->preparedSQL->player->getEq->bindValue(":name", $name);
|
||||
$query = $this->server->preparedSQL->player->getEq->execute();
|
||||
|
||||
$players = [];
|
||||
if($query !== false and $query !== true){
|
||||
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
|
|
@ -262,7 +310,23 @@ class PlayerAPI{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($alike === true){
|
||||
$this->server->preparedSQL->player->getLike->reset();
|
||||
$query = $this->server->preparedSQL->player->getLike->bindValue(":name", "$name%");
|
||||
$query = $this->server->preparedSQL->player->getLike->execute(); //try getting player with non-full name match if none was found
|
||||
if($query !== false and $query !== true){
|
||||
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$CID = PocketMinecraftServer::clientID($d["ip"], $d["port"]);
|
||||
if(isset($this->server->clients[$CID])){
|
||||
$players[$CID] = $this->server->clients[$CID];
|
||||
if($multiple === false and $d["name"] === $name){
|
||||
return $players[$CID];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($multiple === false){
|
||||
if(count($players) > 0){
|
||||
return array_shift($players);
|
||||
|
|
@ -292,6 +356,7 @@ class PlayerAPI{
|
|||
$origin = $this->get($name);
|
||||
if($origin instanceof Player){
|
||||
$name = $origin->username;
|
||||
$target = $player->username;
|
||||
return $origin->teleport($player->entity);
|
||||
}
|
||||
}
|
||||
|
|
@ -327,22 +392,12 @@ class PlayerAPI{
|
|||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public static function decodeProtocol($ip){
|
||||
foreach(ServerAPI::request()->clients as $p) {
|
||||
if($p->ip == $ip){
|
||||
return $p->PROTOCOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function add($CID){
|
||||
if(isset($this->server->clients[$CID])){
|
||||
$player = $this->server->clients[$CID];
|
||||
$player->data = $this->getOffline($player->username);
|
||||
$player->gamemode = $player->data->get("gamemode");
|
||||
$player->saveInventory = ($player->gamemode & 1) == SURVIVAL;
|
||||
if(($player->level = $this->server->api->level->get($player->data->get("position")["level"])) === false){
|
||||
$player->level = $this->server->api->level->getDefault();
|
||||
$player->data->set("position", [
|
||||
|
|
@ -374,32 +429,41 @@ class PlayerAPI{
|
|||
"z" => $this->server->spawn->z,
|
||||
],
|
||||
"inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, [AIR, 0, 0]),
|
||||
"hotbar" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
|
||||
"armor" => array_fill(0, 4, [AIR, 0]),
|
||||
"gamemode" => $this->server->gamemode,
|
||||
"health" => 20,
|
||||
"lastIP" => "",
|
||||
"lastID" => 0,
|
||||
"achievements" => [],
|
||||
"slot-count" => 7
|
||||
"slot-count" => 7,
|
||||
"bed-position" => null,
|
||||
];
|
||||
|
||||
if(!file_exists(DATA_PATH . "players/" . $iname . ".yml")){
|
||||
$ev = true;
|
||||
$sav = false;
|
||||
if(!file_exists(DATA_PATH . "players/$iname.yml")){
|
||||
if(PocketMinecraftServer::$SAVE_PLAYER_DATA && $create){
|
||||
console("[NOTICE] Player data not found for \"" . $iname . "\", creating new profile");
|
||||
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
|
||||
$data->save();
|
||||
console("[NOTICE] Player data not found for \"$iname\", creating new profile");
|
||||
$data = new Config(DATA_PATH . "players/$iname.yml", CONFIG_YAML, $default);
|
||||
$sav = true;
|
||||
}else{
|
||||
return new Config(DATA_PATH . "players/$iname.yml", CONFIG_YAML, $default);
|
||||
$data = new Config(DATA_PATH . "players/$iname.yml", CONFIG_YAML, $default);
|
||||
$ev = false;
|
||||
}
|
||||
}else{
|
||||
$data = new Config(DATA_PATH . "players/$iname.yml", CONFIG_YAML, $default);
|
||||
}
|
||||
|
||||
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
|
||||
|
||||
|
||||
if(($data->get("gamemode") & 0x01) === 1){
|
||||
$data->set("health", 20);
|
||||
}
|
||||
$this->server->handle("player.offline.get", $data);
|
||||
if(!$data->exists("hotbar")){
|
||||
if(($data->get("gamemode") & 1) == CREATIVE) $hb = BlockAPI::$creativeHotbarSlots;
|
||||
else $hb = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||
$data->set("hotbar", $hb);
|
||||
}
|
||||
if($ev) $this->server->handle("player.offline.get", $data);
|
||||
if($sav) $data->save();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
@ -415,7 +479,7 @@ class PlayerAPI{
|
|||
$pk->z = -256;
|
||||
$pk->yaw = 0;
|
||||
$pk->pitch = 0;
|
||||
$player->dataPacket($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -442,7 +506,7 @@ class PlayerAPI{
|
|||
|
||||
public function spawnToAllPlayers(Player $player){
|
||||
foreach($this->getAll() as $p){
|
||||
if($p !== $player and ($p->entity instanceof Entity) and ($player->entity instanceof Entity)){
|
||||
if($p->spawned && $p !== $player && ($p->entity instanceof Entity) && ($player->entity instanceof Entity)){
|
||||
$player->entity->spawn($p);
|
||||
if($p->level !== $player->level){
|
||||
$pk = new MoveEntityPacket_PosRot;
|
||||
|
|
@ -452,7 +516,7 @@ class PlayerAPI{
|
|||
$pk->z = -256;
|
||||
$pk->yaw = 0;
|
||||
$pk->pitch = 0;
|
||||
$p->dataPacket($pk);
|
||||
$p->entityQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -466,14 +530,18 @@ class PlayerAPI{
|
|||
if($player->username != "" and ($player->data instanceof Config)){
|
||||
$this->saveOffline($player->data);
|
||||
}
|
||||
$this->server->query("DELETE FROM players WHERE name = '" . $player->username . "';");
|
||||
|
||||
$this->server->preparedSQL->player->deleteCID->reset();
|
||||
$this->server->preparedSQL->player->deleteCID->bindValue(":CID", $CID);
|
||||
$this->server->preparedSQL->player->getEq->execute();
|
||||
|
||||
$this->server->api->entity->remove($player->eid);
|
||||
unset($player->level->players[$player->CID]);
|
||||
if($player->entity instanceof Entity){
|
||||
unset($player->entity->player);
|
||||
//unset($player->entity);
|
||||
}
|
||||
|
||||
|
||||
$player = null;
|
||||
unset($player);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,6 +149,10 @@ class PluginAPI extends stdClass{
|
|||
break;
|
||||
}
|
||||
}
|
||||
if(count($pluginInfo) == 0){
|
||||
ConsoleAPI::error("Failed to load PHAR plugin from $file: pluginInfo has no information(PHAR was made for PMMP 1.4+?)");
|
||||
continue;
|
||||
}
|
||||
console("[INFO] Loading PHAR plugin \"".FORMAT_GREEN.$pluginInfo["name"].FORMAT_RESET."\" ".FORMAT_AQUA.$pluginInfo["version"].FORMAT_RESET." by ".FORMAT_AQUA.$pluginInfo["author"].FORMAT_RESET);
|
||||
|
||||
$aver = CURRENT_API_VERSION;
|
||||
|
|
|
|||
|
|
@ -136,8 +136,55 @@ class ServerAPI{
|
|||
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
|
||||
"auto-save" => true,
|
||||
"enable-mob-ai" => true,
|
||||
"abort-reading-after-N-packets" => PocketMinecraftServer::$PACKET_READING_LIMIT
|
||||
"abort-reading-after-N-packets" => PocketMinecraftServer::$PACKET_READING_LIMIT,
|
||||
"ticking-mode" => "legacy",
|
||||
"mushroom-spread" => Block::$mushroomSpread
|
||||
], comments: [
|
||||
"level-type" => [
|
||||
"Alowed types:",
|
||||
"FLAT - flat world",
|
||||
"DEFAULT - use one of the 4 pregenerated worlds from pocketmine",
|
||||
"VANILLA - unfinished, attempts to generate vanilla 0.8.1 world. This geneeator is very slow."
|
||||
],
|
||||
"abort-reading-after-N-packets" => [
|
||||
"Sets max amount of packets the server can read before forcing tick check."
|
||||
],
|
||||
"ticking-mode" => [
|
||||
"Sets ticking mode. Allowed modes:",
|
||||
"legacy - sleep while waiting for the next tick. same ticking as in old PocketMine. The server won't use a lot of cpu, but tps may be not stable(causes 16 TPS on Windows)",
|
||||
"nodelay - unused time is not used for anything.. May cause to use 100% of CPU.",
|
||||
"netwait - uses unused time to wait for packets. Should always give max tps. Untested on windows."
|
||||
],
|
||||
"server-type" => [
|
||||
"Changes server type. Does not affect anything in 0.8.1. Allowed types:",
|
||||
"normal - changes unconnected_pong reply to use MCCPP;Demo;",
|
||||
"demo - same as normal",
|
||||
"minecon - changes unconnected_pong reply to use MCCPP;MINECON;",
|
||||
],
|
||||
"generator-settings" => [
|
||||
"Used to set level settings when generating a world. Currently affects only FLAT world.",
|
||||
"FLAT world preset format: VERSION;LAYERS;STARTY;PARAMS",
|
||||
"The string contains multiple parameters split by ;",
|
||||
"VERSION - preset version (2)",
|
||||
"LAYERS - defines layers and their sizes",
|
||||
" each layer is formatted as <ID>x<CNT>",
|
||||
" <ID> - block id to fill the layer",
|
||||
" <CNT> - layer height",
|
||||
"Multiple layers are separated by ,",
|
||||
"STARTY - start y level. Must be more than 0",
|
||||
"PARAMS - additional patamaters",
|
||||
" spawn(radius=<N> block=<ID>) - sets spawn parameters",
|
||||
" radius=<N> - sets spawn radius to <N>",
|
||||
" block=<ID> - sets block to fill spawn area with",
|
||||
" decoration(treecount=<N> grasscount=<M>) - sets amount of decorations",
|
||||
"Preset example:",
|
||||
"2;7,59x1,3x3,2;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=45)"
|
||||
],
|
||||
"mushroom-spread" => [
|
||||
"Enable or disable mushroom spreading"
|
||||
]
|
||||
]);
|
||||
Block::$mushroomSpread = $this->getProperty("mushroom-spread", Block::$mushroomSpread);
|
||||
Entity::$allowFly = $this->getProperty("allow-flight", true);
|
||||
if(!Entity::$allowFly){
|
||||
ConsoleAPI::warn("Fly checking is enabled! Players may experience issues with kicking while not flying!");
|
||||
|
|
@ -146,6 +193,11 @@ class ServerAPI{
|
|||
MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50);
|
||||
Entity::$allowedAI = $this->getProperty("enable-mob-ai", true);
|
||||
PocketMinecraftServer::$PACKET_READING_LIMIT = $this->getProperty("abort-reading-after-N-packets", PocketMinecraftServer::$PACKET_READING_LIMIT);
|
||||
PocketMinecraftServer::$TICKING_MODE = match(strtolower($this->getProperty("ticking-mode"))){
|
||||
default => PocketMinecraftServer::TICK_LEGACY,
|
||||
"nodelay" => PocketMinecraftServer::TICK_F20TPS,
|
||||
"netwait" => PocketMinecraftServer::TICK_NETWAIT
|
||||
};
|
||||
//Load advanced properties
|
||||
define("DEBUG", $this->getProperty("debug", 1));
|
||||
define("ADVANCED_CACHE", false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue