Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
inxomnyaa committed Feb 19, 2017
2 parents f442b21 + 20c7e51 commit 37c3a41
Show file tree
Hide file tree
Showing 67 changed files with 260 additions and 1,318 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Yes, you can! Contributions are welcomed provided that they comply with our [Con
## Third-party Libraries/Protocols Used
* __[PHP Sockets](http://php.net/manual/en/book.sockets.php)__
* __[PHP mbstring](http://php.net/manual/en/book.mbstring.php)__
* __[PHP SQLite3](http://php.net/manual/en/book.sqlite3.php)__
* __[PHP BCMath](http://php.net/manual/en/book.bc.php)__
* __[PHP pthreads](http://pthreads.org/)__ by _[krakjoe](https://github.com/krakjoe)_: Threading for PHP - Share Nothing, Do Everything.
* __[PHP YAML](https://code.google.com/p/php-yaml/)__ by _Bryan Davis_: The Yaml PHP Extension provides a wrapper to the LibYAML library.
Expand Down
14 changes: 8 additions & 6 deletions src/pocketmine/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityShootBowEvent;
use pocketmine\event\player\PlayerTransferEvent;
use pocketmine\event\entity\ProjectileLaunchEvent;
use pocketmine\event\inventory\CraftItemEvent;
use pocketmine\event\inventory\InventoryCloseEvent;
Expand Down Expand Up @@ -67,6 +66,7 @@
use pocketmine\event\player\PlayerToggleGlideEvent;
use pocketmine\event\player\PlayerToggleSneakEvent;
use pocketmine\event\player\PlayerToggleSprintEvent;
use pocketmine\event\player\PlayerTransferEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\event\TextContainer;
Expand Down Expand Up @@ -1949,7 +1949,7 @@ public function handleDataPacket(DataPacket $packet){
case ProtocolInfo::MOVE_PLAYER_PACKET:
$newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z);

if($newPos->distanceSquared($this) < 0.01 and ($packet->yaw % 360) === $this->yaw and ($packet->pitch % 360) === $this->pitch){ //player hasn't moved, just client spamming packets
if($newPos->distanceSquared($this) < 0.0001 and ($packet->yaw % 360) === $this->yaw and ($packet->pitch % 360) === $this->pitch){ //player hasn't moved, just client spamming packets
break;
}

Expand Down Expand Up @@ -2512,7 +2512,7 @@ public function handleDataPacket(DataPacket $packet){

$oldItem = clone $item;

if($this->canInteract($vector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 6) and $this->level->useBreakOn($vector, $item, $this)){
if($this->canInteract($vector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 6) and $this->level->useBreakOn($vector, $item, $this, true)){
if($this->isSurvival()){
if(!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()){
$this->inventory->setItemInHand($item);
Expand Down Expand Up @@ -2847,6 +2847,7 @@ public function handleDataPacket(DataPacket $packet){
if($recipe instanceof ShapedRecipe){
for($x = 0; $x < 3 and $canCraft; ++$x){
for($y = 0; $y < 3; ++$y){
/** @var Item $item */
$item = $packet->input[$y * 3 + $x];
$ingredient = $recipe->getIngredient($x, $y);
if($item->getCount() > 0){
Expand All @@ -2862,6 +2863,7 @@ public function handleDataPacket(DataPacket $packet){

for($x = 0; $x < 3 and $canCraft; ++$x){
for($y = 0; $y < 3; ++$y){
/** @var Item $item */
$item = clone $packet->input[$y * 3 + $x];

foreach($needed as $k => $n){
Expand Down Expand Up @@ -3109,7 +3111,7 @@ public function handleDataPacket(DataPacket $packet){
}
break;
case ProtocolInfo::ITEM_FRAME_DROP_ITEM_PACKET:
if($this->spawned === false or !$this->isAlive()){
if ($this->spawned === false or !$this->isAlive()) {
break;
}
$tile = $this->level->getTile($this->temporalVector->setComponents($packet->x, $packet->y, $packet->z));
Expand All @@ -3121,11 +3123,11 @@ public function handleDataPacket(DataPacket $packet){
$this->getServer()->getPluginManager()->callEvent($ev = new ItemFrameDropItemEvent($this->getLevel()->getBlock($tile), $this, $tile->getItem(), $tile->getItemDropChance()));
if (!$ev->isCancelled()) {
if (lcg_value() <= $ev->getItemDropChance() && $packet->item->getId() !== Item::AIR) {
if($this->getGamemode() !== self::CREATIVE && $this->getGamemode() !== self::SPECTATOR)
if ($this->getGamemode() !== self::CREATIVE && $this->getGamemode() !== self::SPECTATOR)
$this->level->dropItem($tile, $ev->getDropItem());
}
$tile->setItem();
//$tile->setItemRotation(0); //This actually doesn't happen.
//$tile->setItemRotation(0); #blamedktapps
}
}
break;
Expand Down
10 changes: 2 additions & 8 deletions src/pocketmine/PocketMine.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ function dummy(){
}

namespace pocketmine {
use pocketmine\network\protocol\Info as ProtocolInfo;
use pocketmine\utils\Binary;
use pocketmine\utils\MainLogger;
use pocketmine\utils\ServerKiller;
use pocketmine\utils\Terminal;
use pocketmine\utils\Utils;
use pocketmine\wizard\Installer;
use pocketmine\wizard\SetupWizard;
use raklib\RakLib;

const VERSION = "1.6.2dev";
Expand Down Expand Up @@ -442,11 +441,6 @@ function cleanPath($path){
++$errors;
}

if(!extension_loaded("sqlite3")){
$logger->critical("Unable to find the SQLite3 extension.");
++$errors;
}

if(!extension_loaded("zlib")){
$logger->critical("Unable to find the Zlib extension.");
++$errors;
Expand Down Expand Up @@ -480,7 +474,7 @@ function cleanPath($path){


if(!file_exists(\pocketmine\DATA . "server.properties") and !isset($opts["no-wizard"])){
$installer = new Installer();
$installer = new SetupWizard();
if(!$installer->run()){
$logger->shutdown();
$logger->join();
Expand Down
7 changes: 4 additions & 3 deletions src/pocketmine/block/Bed.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace pocketmine\block;

use pocketmine\event\TranslationContainer;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
Expand Down Expand Up @@ -65,7 +66,7 @@ public function onActivate(Item $item, Player $player = null){
$isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);

if($player instanceof Player and !$isNight){
$player->sendMessage(TextFormat::GRAY . "You can only sleep at night");
$player->sendMessage(new TranslationContainer(TextFormat::GRAY . "%tile.bed.noSleep"));
return true;
}

Expand Down Expand Up @@ -94,7 +95,7 @@ public function onActivate(Item $item, Player $player = null){
}

if($player instanceof Player and $player->sleepOn($b) === false){
$player->sendMessage(TextFormat::GRAY . "This bed is occupied");
$player->sendMessage(new TranslationContainer(TextFormat::GRAY . "%tile.bed.occupied"));
}

return true;
Expand Down Expand Up @@ -162,4 +163,4 @@ public function getDrops(Item $item){
];
}

}
}
3 changes: 2 additions & 1 deletion src/pocketmine/block/BurningFurnace.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public function onBreak(Item $item){

public function onActivate(Item $item, Player $player = null){
if($player instanceof Player){
if(!(($furnace = $this->getLevel()->getTile($this)) instanceof TileFurnace)){
$furnace = $this->getLevel()->getTile($this);
if(!($furnace instanceof TileFurnace)){
$nbt = new CompoundTag("", [
new ListTag("Items", []),
new StringTag("id", Tile::FURNACE),
Expand Down
6 changes: 4 additions & 2 deletions src/pocketmine/block/ItemFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public function canBeActivated(){
}

public function onActivate(Item $item, Player $player = null){
if(!(($tile = $this->level->getTile($this)) instanceof TileItemFrame)){
$tile = $this->level->getTile($this);
if(!($tile instanceof TileItemFrame)){
$nbt = new CompoundTag("", [
new StringTag("id", Tile::ITEM_FRAME),
new IntTag("x", $this->x),
Expand Down Expand Up @@ -76,7 +77,8 @@ public function onActivate(Item $item, Player $player = null){
}

public function onBreak(Item $item){
if(($tile = $this->level->getTile($this)) instanceof TileItemFrame){
$tile = $this->level->getTile($this);
if($tile instanceof TileItemFrame){
//TODO: add events
if(lcg_value() <= $tile->getItemDropChance() and $tile->getItem()->getId() !== Item::AIR){
$this->level->dropItem($tile->getBlock(), $tile->getItem());
Expand Down
6 changes: 3 additions & 3 deletions src/pocketmine/block/MobHead.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ public function place(Item $item, Block $block, Block $target, $face, $fx, $fy,
return false;
}

public function getDrops(Item $item) {
/** @var SkullTile $tile */
if (($tile = $this->level->getTile($this)) instanceof SkullTile) {
public function getDrops(Item $item){
$tile = $this->level->getTile($this);
if($tile instanceof SkullTile){
return [
[Item::MOB_HEAD, $tile->getType(), 1]
];
Expand Down
4 changes: 2 additions & 2 deletions src/pocketmine/block/Prismarine.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getName(){
self::DARK => "Dark Prismarine",
self::BRICKS => "Prismarine Bricks",
];
return $names[$this->meta & 0x0f];
return $names[$this->meta & 0x03] ?? "Unknown";
}

public function getToolType(){
Expand All @@ -56,7 +56,7 @@ public function getToolType(){
public function getDrops(Item $item){
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [
[$this->id, $this->meta & 0x0f, 1],
[$this->id, $this->meta & 0x03, 1],
];
}else{
return [];
Expand Down
3 changes: 0 additions & 3 deletions src/pocketmine/command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ abstract class Command{
/** @var string */
protected $usageMessage;

/** @var string */
private $permission = null;

/** @var string */
private $permissionMessage = null;

Expand Down
2 changes: 1 addition & 1 deletion src/pocketmine/command/CommandReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class CommandReader extends Thread{
protected $buffer;
private $shutdown = false;
private $type = self::TYPE_STREAM;
private $lastLine = -1;

public function __construct(){
$this->buffer = new \Threaded;
Expand Down Expand Up @@ -89,6 +88,7 @@ private function initStdin(){
/**
* Checks if the specified stream is a FIFO pipe.
*
* @param resource $stream
* @return bool
*/
private function isPipe($stream) : bool{
Expand Down
4 changes: 2 additions & 2 deletions src/pocketmine/command/defaults/GamemodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public function execute(CommandSender $sender, $currentAlias, array $args){
$sender->sendMessage("Game mode change for " . $target->getName() . " failed!");
}else{
if($target === $sender){
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.gamemode.success.self", [Server::getGamemodeString($gameMode)]));
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.gamemode.success.self", ['blame', 'mojang', Server::getGamemodeString($gameMode)]));
}else{
$target->sendMessage(new TranslationContainer("gameMode.changed"));
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.gamemode.success.other", [$target->getName(), Server::getGamemodeString($gameMode)]));
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.gamemode.success.other", ['blame mojang', $target->getName(), Server::getGamemodeString($gameMode)]));
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/pocketmine/entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,21 @@ public function setNameTagVisible($value = true){
public function setNameTagAlwaysVisible($value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value);
}


/**
* @return float
*/
public function getScale(): float{
return $this->getDataProperty(self::DATA_SCALE);
}

/**
* @param float $value
*/
public function setScale(float $value){
$this->setDataProperty(self::DATA_SCALE, self::DATA_TYPE_FLOAT, $value);
}

public function isSneaking(){
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING);
}
Expand Down Expand Up @@ -1686,8 +1700,8 @@ public function close(){
if($this->chunk !== null){
$this->chunk->removeEntity($this);
}
if($this->level !== null){
$this->level->removeEntity($this);
if($this->getLevel() !== null){
$this->getLevel()->removeEntity($this);
}
}
}
Expand Down
51 changes: 26 additions & 25 deletions src/pocketmine/lang/BaseLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ class BaseLang{

const FALLBACK_LANGUAGE = "eng";

public static function getLanguageList(string $path = "") : array{
if($path === ""){
$path = \pocketmine\PATH . "src/pocketmine/lang/locale/";
}

$files = array_filter(scandir($path), function($filename){
return substr($filename, -4) === ".ini";
});

$result = [];

foreach($files as $file){
$strings = [];
self::loadLang($path . $file, $strings);
if(isset($strings["language.name"])){
$result[substr($file, 0, -4)] = $strings["language.name"];
}
}

return $result;
}

protected $langName;

protected $lang = [];
Expand All @@ -42,10 +64,10 @@ public function __construct($lang, $path = null, $fallback = self::FALLBACK_LANG
$path = \pocketmine\PATH . "src/pocketmine/lang/locale/";
}

if(!$this->loadLang($file = $path . $this->langName . ".ini", $this->lang)){
if(!self::loadLang($file = $path . $this->langName . ".ini", $this->lang)){
MainLogger::getLogger()->error("Missing required language file $file");
}
if(!$this->loadLang($file = $path . $fallback . ".ini", $this->fallbackLang)){
if(!self::loadLang($file = $path . $fallback . ".ini", $this->fallbackLang)){
MainLogger::getLogger()->error("Missing required language file $file");
}
}
Expand All @@ -58,30 +80,9 @@ public function getLang(){
return $this->langName;
}

protected function loadLang($path, array &$d){
protected static function loadLang($path, array &$d){
if(file_exists($path)){
if(strlen($content = file_get_contents($path)) > 0){
foreach(explode("\n", $content) as $line){
$line = trim($line);
if($line === "" or $line{0} === "#"){
continue;
}

$t = explode("=", $line, 2);
if(count($t) < 2){
continue;
}

$key = trim($t[0]);
$value = trim($t[1]);

if($value === ""){
continue;
}

$d[$key] = $value;
}
}
$d = parse_ini_file($path, false, INI_SCANNER_RAW);
return true;
}else{
return false;
Expand Down
6 changes: 0 additions & 6 deletions src/pocketmine/lang/Installer/af_ZA.ini

This file was deleted.

23 changes: 0 additions & 23 deletions src/pocketmine/lang/Installer/ar_SA.ini

This file was deleted.

Loading

0 comments on commit 37c3a41

Please sign in to comment.