mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-16 22:35:06 +00:00
Compare commits
345 Commits
Alpha_1.3
...
Alpha_1.3.
Author | SHA1 | Date | |
---|---|---|---|
ea17ff9d9b | |||
1b72ef8827 | |||
a34595292d | |||
e42314ade7 | |||
5683dca9f6 | |||
b5c935559f | |||
7a37b0e4bf | |||
19b3ac4a99 | |||
bf1b00f0e6 | |||
7102787aa9 | |||
d26d657b95 | |||
3374bbcc9e | |||
8d408996f4 | |||
68e78ba40b | |||
a7b739d17f | |||
78c242eac4 | |||
7e6758fb60 | |||
39658ef63f | |||
4f1ce9adee | |||
87a67804c4 | |||
04c641b79b | |||
9c9939440f | |||
ba9b800eff | |||
62b589295e | |||
b6d86c287c | |||
792a4bd98e | |||
28790e0fb3 | |||
b77e7dd05c | |||
4c73629b9e | |||
330e06b892 | |||
f3f6828699 | |||
c1e1f5195b | |||
a60d41d489 | |||
5975bd9d32 | |||
e67b583cbe | |||
4755dee47d | |||
fd5d981aa5 | |||
a93b2cf954 | |||
16e65560a8 | |||
32d658122b | |||
1cf2741f96 | |||
47c934cee2 | |||
3606c392f2 | |||
6d4465eb67 | |||
08000257fb | |||
ed9eadd1a0 | |||
b42222c461 | |||
635cd677eb | |||
56f500d520 | |||
3202678594 | |||
a68676a247 | |||
7efed17b74 | |||
b776d9d5fc | |||
5237867319 | |||
402fc087ca | |||
1727e18e31 | |||
03b4e40bf4 | |||
8f1c34fdc5 | |||
84bb66357e | |||
c00bfe3908 | |||
3fb99e118c | |||
1d2de1f038 | |||
d177af3297 | |||
8dcdf55264 | |||
5a168836c5 | |||
ce1e95195b | |||
cf5e2f63db | |||
d4c4f8817d | |||
b6a1d42870 | |||
84a5f0fce5 | |||
c136eb2b2e | |||
d0a021de73 | |||
155c918bb8 | |||
19d0c70669 | |||
02721c09a4 | |||
204a4ce831 | |||
a118e626c2 | |||
01d5612ed8 | |||
59aa317546 | |||
4c9cbaf1ee | |||
18562317c3 | |||
f51630c572 | |||
847590645d | |||
fbf22cec39 | |||
0dd3d4a457 | |||
f521d16ce3 | |||
72ec318481 | |||
99554caa69 | |||
bfffa35246 | |||
09a388f8de | |||
a7149ad9ef | |||
471de2d1c5 | |||
aa7d9b5e05 | |||
2e23ce8beb | |||
e4871ee0c4 | |||
86469a1031 | |||
533c179622 | |||
4321a03935 | |||
68f0a91d56 | |||
5e231c846c | |||
7d3992bcc2 | |||
c83d4d955f | |||
ff7fa066a5 | |||
9619ebc2af | |||
0a4beaf051 | |||
2957f35194 | |||
5afd26b1b6 | |||
152ebcbc17 | |||
73c155090c | |||
89cb879f1f | |||
a45858ad94 | |||
c8e157156e | |||
6563169527 | |||
7e67f50da5 | |||
393b57c535 | |||
bda5e62788 | |||
579175b3bc | |||
808f5473d0 | |||
4284211bd1 | |||
33733cd608 | |||
1e14485444 | |||
c42fd790ff | |||
2ef1f0c9d0 | |||
abcb5828ed | |||
ee7c767c16 | |||
affd67debe | |||
79555e4029 | |||
e1c0139ab3 | |||
ca8be7b047 | |||
3ab3526404 | |||
523c4390fa | |||
508ee7e1d6 | |||
4a5783b57b | |||
31490576d2 | |||
b4f95fad11 | |||
8c190ead7f | |||
fef0b27f7c | |||
cbe0692696 | |||
1cc19ae1e8 | |||
2976db25c3 | |||
2f6ddb6aa4 | |||
099bedf8ee | |||
bd1875f5e4 | |||
d82399e686 | |||
4f10b1cb7c | |||
ba53a0927f | |||
9b88a4a73f | |||
715b92b681 | |||
1014052a57 | |||
ac486ec970 | |||
5a278f8a16 | |||
7404279f15 | |||
5f40ab84f0 | |||
3061b8eb3c | |||
e58ef1f62c | |||
4803f14a21 | |||
409cc0931f | |||
9874bd199e | |||
1a822460d8 | |||
8d2862a744 | |||
4f3e49b6a9 | |||
f1c278915d | |||
169d122774 | |||
ccc5e1b628 | |||
5786ba7a35 | |||
cd932d5c07 | |||
bfa65e1e7d | |||
16a8566fca | |||
28480424c5 | |||
54227b1d86 | |||
04390e758d | |||
3e46fc1fdd | |||
97dd718e4f | |||
883b18078f | |||
8bef816061 | |||
13bfaaf7b8 | |||
164b420af6 | |||
38c50c2fec | |||
157237e3ef | |||
20b83319de | |||
1ce23ab8d7 | |||
4f3700f13a | |||
129e099f88 | |||
9d1369bfe9 | |||
6fa0ef652e | |||
71e556a181 | |||
51f4faf22e | |||
8e127e60a0 | |||
3023df2033 | |||
3463db04a6 | |||
e9683ff5d2 | |||
64dca86342 | |||
6a13705970 | |||
afbde5c7ac | |||
6f2b2f98d6 | |||
05ae6cdef3 | |||
e7c6a0c817 | |||
81524362c0 | |||
35c0c21c8d | |||
c37c6da42d | |||
3fa1bd3a05 | |||
fdb7af5df2 | |||
a463e0c09e | |||
67919a68e1 | |||
45ee7ea7ae | |||
e3e7919652 | |||
139d8b38b5 | |||
96c11adc89 | |||
82aa76be17 | |||
7970b8aeed | |||
ab3fcfc148 | |||
28f6a964d4 | |||
306cc9f00c | |||
c1f79fa2f8 | |||
1179369666 | |||
0bd8d0b0d0 | |||
67b0b97005 | |||
5e45567c1d | |||
adce1ad920 | |||
8b1c251a59 | |||
8b9b05991d | |||
5cb06579cd | |||
63933ed1fc | |||
4b408675cf | |||
1f4df559e0 | |||
89ef299333 | |||
3d3383bea7 | |||
c95c231cfc | |||
d614f3c9da | |||
6993528af2 | |||
18b437eec9 | |||
67b533a44d | |||
5def864aca | |||
911577e9b8 | |||
fbf897d1be | |||
a5bc95e733 | |||
2dd188a0bd | |||
a830555d90 | |||
8bf10c523e | |||
7e13ae2bda | |||
7527c57e1e | |||
06a0f169dd | |||
f12620f376 | |||
dce9b3140a | |||
be9676ebe5 | |||
bd6e3901a6 | |||
6f8963bdcd | |||
033a1673f0 | |||
0c7c36cc03 | |||
e01a3e6811 | |||
566cee2b0b | |||
03e059a190 | |||
f80326b714 | |||
1935e2bbf7 | |||
e43b4e67c6 | |||
45267ea074 | |||
45efcc5faa | |||
15c9b7214d | |||
be83eaf521 | |||
f2927df2b3 | |||
5bba03eb09 | |||
588379a430 | |||
dc22e1b81c | |||
f55fb8d490 | |||
d1f2f82c6d | |||
4b6e456c65 | |||
a8b8427065 | |||
ec22034ad7 | |||
c7a3fc4931 | |||
91e414fb87 | |||
1b50bd6e0f | |||
ffd8ac2879 | |||
9ead05a6fa | |||
4f39818cae | |||
15ab47070a | |||
b72d4ac407 | |||
0ca18864f3 | |||
54b73e5f82 | |||
24ba7cbbd1 | |||
722eb6d1f9 | |||
1638e68c53 | |||
75bb2a6399 | |||
a890cdc023 | |||
66fc483156 | |||
1376cc860d | |||
732f5f5168 | |||
66e635daeb | |||
3ac4b0af68 | |||
d7f74a6725 | |||
0522052c75 | |||
e6dbd61308 | |||
848554bc0c | |||
fc02572065 | |||
09efcec605 | |||
4507072980 | |||
2c8d527025 | |||
9919a709e9 | |||
3825edaaab | |||
6e5924a183 | |||
a795b64bab | |||
8d00ef381d | |||
b564868467 | |||
450b5d9560 | |||
25de7a68d5 | |||
6e2f7af6b4 | |||
2f05a03e51 | |||
ddec63c4d4 | |||
6242089b28 | |||
1fbf475ace | |||
2271d45fd9 | |||
f6ab39a526 | |||
71584288dc | |||
e67a7a510e | |||
8192b41693 | |||
4a969257d1 | |||
fde93debb4 | |||
620486a4a0 | |||
0d12039623 | |||
00427a076e | |||
58fd67d2ed | |||
cb03daf28a | |||
3d28f519c7 | |||
6b61bc11d0 | |||
c9d0cf3698 | |||
5d6669201b | |||
d8f6e9ff0e | |||
929c27e339 | |||
a92e4f6acd | |||
b7bc0826af | |||
044b25ccd2 | |||
90effd173b | |||
fc80a85c8c | |||
06c57a3aae | |||
6d54495402 | |||
838e7ad010 | |||
6262fbffcb | |||
7622151a21 | |||
aefcfad296 | |||
424dba2fdd | |||
7c3b8807e9 | |||
f6a395e7b7 | |||
d92056fe77 | |||
161a271127 | |||
8ec11b35ad | |||
df4a29d7d6 |
27
CONTRIBUTING.md
Normal file
27
CONTRIBUTING.md
Normal file
@ -0,0 +1,27 @@
|
||||

|
||||
|
||||
# PocketMine-MP Contribution Gidelines
|
||||
|
||||
Before contributing to PocketMine-MP, please read this.
|
||||
|
||||
|
||||
## I've a question
|
||||
* For questions, please refer to the _#mcpedevs_ IRC
|
||||
channel on Freenode. There is a [WebIRC](http://webchat.freenode.net?channels=mcpedevs&uio=d4) if you want.
|
||||
* You can ask directly to _[@PocketMine](https://twitter.com/PocketMine)_ in Twitter.
|
||||
|
||||
## I want to create an issue
|
||||
* First, use the [Issue Search](https://github.com/PocketMine/PocketMine-MP/search?ref=cmdform&type=Issues) to check if anyone has reported it.
|
||||
* Is your issue related to a Plugin? If so, please contact their original author instead of reporting it here.
|
||||
* And no, we won't update a Plugin because you need it.
|
||||
* When reporting, give as much info as you can, and if the Issue is a crash, give the Crash Dump.
|
||||
* Issues should be written in English.
|
||||
|
||||
## I want to contribute code
|
||||
* Use the [Pull Request](https://github.com/PocketMine/PocketMine-MP/pull/new) system, your request will be checked and discussed.
|
||||
* If you want to be part of PocketMine-MP, we will ask you to.
|
||||
* Code using the syntax as in PocketMine-MP.
|
||||
* The code must be clear and written in English, comments included.
|
||||
|
||||
|
||||
__Thanks for contributing to PocketMine-MP!__
|
@ -31,8 +31,8 @@ The entire server is done in PHP, and has been tested, profiled and optimized to
|
||||
|
||||
### [Twitter @PocketMine](https://twitter.com/PocketMine)
|
||||
|
||||
## IRC #mcpedevs @ irc.freenode.net
|
||||
* [WebIRC](http://webchat.freenode.net?channels=mcpedevs&uio=d4)
|
||||
## IRC #pocketmine @ irc.freenode.net
|
||||
* [WebIRC](http://webchat.freenode.net?channels=pocketmine,mcpedevs&uio=d4)
|
||||
|
||||
|
||||
## Third-party Libraries/Protocols Used
|
||||
|
@ -92,15 +92,15 @@ class BanAPI{
|
||||
break;
|
||||
case "console.command"://Checks if a command is allowed with the current user permissions.
|
||||
if(isset($this->cmdWhitelist[$data["cmd"]])){
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if($data["issuer"] instanceof Player){
|
||||
if($this->server->api->handle("console.check", $data) === true or $this->isOp($data["issuer"]->iusername)){
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
@ -138,13 +138,15 @@ class BanAPI{
|
||||
$user = strtolower($params[0]);
|
||||
$player = $this->server->api->player->get($user);
|
||||
if(!($player instanceof Player)){
|
||||
$output .= "Player not connected.\n";
|
||||
$this->ops->set($user, false);
|
||||
$this->ops->save($user);
|
||||
$output .= $user." is no longer op\n";
|
||||
break;
|
||||
}
|
||||
$this->ops->remove($player->iusername);
|
||||
$this->ops->save();
|
||||
$output .= $player->iusername." is not longer op\n";
|
||||
$this->server->api->chat->sendTo(false, "You are not longer op.", $player->iusername);
|
||||
$this->server->api->chat->sendTo(false, "You are no longer op.", $player->iusername);
|
||||
break;
|
||||
case "kick":
|
||||
if(!isset($params[0])){
|
||||
@ -296,13 +298,13 @@ class BanAPI{
|
||||
}
|
||||
|
||||
public function kick($username, $reason = "No Reason"){
|
||||
$this->commandHandler("kick", array($username, $reason));
|
||||
$this->commandHandler("kick", array($username, $reason), "console", "");
|
||||
}
|
||||
|
||||
public function reload(){
|
||||
$this->commandHandler("ban", array("reload"));
|
||||
$this->commandHandler("banip", array("reload"));
|
||||
$this->commandHandler("whitelist", array("reload"));
|
||||
$this->commandHandler("ban", array("reload"), "console", "");
|
||||
$this->commandHandler("banip", array("reload"), "console", "");
|
||||
$this->commandHandler("whitelist", array("reload"), "console", "");
|
||||
}
|
||||
|
||||
public function isIPBanned($ip){
|
||||
|
@ -25,20 +25,10 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
|
||||
define("BLOCK_UPDATE_NORMAL", 0);
|
||||
define("BLOCK_UPDATE_RANDOM", 1);
|
||||
define("BLOCK_UPDATE_SCHEDULED", 2);
|
||||
define("BLOCK_UPDATE_WEAK", 3);
|
||||
define("BLOCK_UPDATE_TOUCH", 4);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class BlockAPI{
|
||||
private $server;
|
||||
private $scheduledUpdates = array();
|
||||
private $randomUpdates = array();
|
||||
public static $creative = array(
|
||||
array(COBBLESTONE, 0),
|
||||
array(STONE_BRICKS, 0),
|
||||
@ -74,6 +64,7 @@ class BlockAPI{
|
||||
array(SLAB, 3),
|
||||
array(SLAB, 4),
|
||||
array(SLAB, 5),
|
||||
array(SLAB, 6),
|
||||
array(QUARTZ_BLOCK, 0),
|
||||
array(QUARTZ_BLOCK, 1),
|
||||
array(QUARTZ_BLOCK, 2),
|
||||
@ -111,6 +102,9 @@ class BlockAPI{
|
||||
array(LADDER, 0),
|
||||
array(TORCH, 0),
|
||||
array(GLASS_PANE, 0),
|
||||
array(BUCKET, 0),
|
||||
array(BUCKET, 8),
|
||||
array(BUCKET, 10),
|
||||
array(WOODEN_DOOR, 0),
|
||||
array(TRAPDOOR, 0),
|
||||
array(FENCE, 0),
|
||||
@ -140,9 +134,15 @@ class BlockAPI{
|
||||
array(MELON_SEEDS, 0),
|
||||
array(DYE, 15), //Bonemeal
|
||||
array(IRON_HOE, 0),
|
||||
array(CAKE, 0),
|
||||
array(EGG, 0),
|
||||
array(IRON_SWORD, 0),
|
||||
array(BOW, 0),
|
||||
array(SIGN, 0),
|
||||
array(SPAWN_EGG, MOB_CHICKEN),
|
||||
array(SPAWN_EGG, MOB_COW),
|
||||
array(SPAWN_EGG, MOB_PIG),
|
||||
array(SPAWN_EGG, MOB_SHEEP),
|
||||
);
|
||||
|
||||
public static function fromString($str, $multiple = false){
|
||||
@ -202,7 +202,7 @@ class BlockAPI{
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->event("server.tick", array($this, "blockUpdateTick"));
|
||||
$this->server->schedule(1, array($this, "blockUpdateTick"), array(), true);
|
||||
$this->server->api->console->register("give", "<player> <item[:damage]> [amount]", array($this, "commandHandler"));
|
||||
}
|
||||
|
||||
@ -228,11 +228,11 @@ class BlockAPI{
|
||||
$output .= "Player is in creative mode.\n";
|
||||
break;
|
||||
}
|
||||
if($this->server->api->getProperty("item-enforcement") === false){
|
||||
$this->server->api->entity->drop(new Position($player->entity->x - 0.5, $player->entity->y, $player->entity->z - 0.5, $player->level), $item, true);
|
||||
}else{
|
||||
$player->addItem($item->getID(), $item->getMetadata(), $item->count);
|
||||
if($item->getID() == 0) {
|
||||
$output .= "You cannot give an air block to a player.\n";
|
||||
break;
|
||||
}
|
||||
$player->addItem($item->getID(), $item->getMetadata(), $item->count);
|
||||
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username."\n";
|
||||
}else{
|
||||
$output .= "Unknown player.\n";
|
||||
@ -243,7 +243,7 @@ class BlockAPI{
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function cancelAction(Block $block, Player $player){
|
||||
private function cancelAction(Block $block, Player $player, $send = true){
|
||||
$player->dataPacket(MC_UPDATE_BLOCK, array(
|
||||
"x" => $block->x,
|
||||
"y" => $block->y,
|
||||
@ -251,8 +251,8 @@ class BlockAPI{
|
||||
"block" => $block->getID(),
|
||||
"meta" => $block->getMetadata()
|
||||
));
|
||||
if($player->itemEnforcement === true){
|
||||
$player->sendInventory();
|
||||
if($send === true){
|
||||
$player->sendInventorySlot($player->slot);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -260,30 +260,33 @@ class BlockAPI{
|
||||
public function playerBlockBreak(Player $player, Vector3 $vector){
|
||||
|
||||
$target = $player->level->getBlock($vector);
|
||||
$item = $player->equipment;
|
||||
$item = $player->getSlot($player->slot);
|
||||
|
||||
if($this->server->api->dhandle("player.block.touch", array("type" => "break", "player" => $player, "target" => $target, "item" => $item)) === false){
|
||||
return $this->cancelAction($target, $player);
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
|
||||
if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - 0.02) + $target->getBreakTime($item, $player)) >= microtime(true)){
|
||||
return $this->cancelAction($target, $player);
|
||||
if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - $player->getLag() / 1000) + $target->getBreakTime($item, $player) - 0.1) >= microtime(true)){
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
$player->lastBreak = microtime(true);
|
||||
$player->lastBreak = microtime(true);
|
||||
|
||||
if($this->server->api->dhandle("player.block.break", array("player" => $player, "target" => $target, "item" => $item)) !== false){
|
||||
$drops = $target->getDrops($item, $player);
|
||||
if($target->onBreak($item, $player) === false){
|
||||
return $this->cancelAction($target, $player);
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
if($item->useOn($target) and ($player->gamemode & 0x01) === 0 and $item->getMetadata() >= $item->getMaxDurability()){
|
||||
$player->setSlot($player->slot, new Item(AIR, 0, 0), false);
|
||||
}
|
||||
$drops = $target->getDrops($item, $player);
|
||||
}else{
|
||||
return $this->cancelAction($target, $player);
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
|
||||
|
||||
if(($player->gamemode & 0x01) === 0x00 and count($drops) > 0){
|
||||
foreach($drops as $drop){
|
||||
$this->server->api->entity->drop($target, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF));
|
||||
$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]));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -296,7 +299,7 @@ class BlockAPI{
|
||||
|
||||
$target = $player->level->getBlock($vector);
|
||||
$block = $target->getSide($face);
|
||||
$item = $player->equipment;
|
||||
$item = $player->getSlot($player->slot);
|
||||
|
||||
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ //If no block exists or not allowed in CREATIVE
|
||||
$this->cancelAction($target, $player);
|
||||
@ -315,44 +318,53 @@ class BlockAPI{
|
||||
}
|
||||
|
||||
if(($player->gamemode & 0x02) === 0x02){ //Adventure mode!!
|
||||
return $this->cancelAction($block, $player);
|
||||
return $this->cancelAction($block, $player, false);
|
||||
}
|
||||
|
||||
if($block->y > 127 or $block->y < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz)){
|
||||
return $this->cancelAction($block, $player);
|
||||
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);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if($item->isPlaceable()){
|
||||
$hand = $item->getBlock();
|
||||
$hand->position($block);
|
||||
}elseif($block->getID() === FIRE){
|
||||
$player->level->setBlock($block, new AirBlock());
|
||||
return false;
|
||||
}else{
|
||||
return $this->cancelAction($block, $player);
|
||||
return $this->cancelAction($block, $player, false);
|
||||
}
|
||||
|
||||
if(!($block->isReplaceable === true or ($hand->getID() === SLAB and $block->getID() === SLAB))){
|
||||
return $this->cancelAction($block, $player);
|
||||
return $this->cancelAction($block, $player, false);
|
||||
}
|
||||
|
||||
if($hand->isTransparent === false and $player->entity->inBlock($block)){
|
||||
return $this->cancelAction($block, $player); //Entity in block
|
||||
if($hand->isSolid === true and $player->entity->inBlock($block)){
|
||||
return $this->cancelAction($block, $player, false); //Entity in block
|
||||
}
|
||||
|
||||
if($this->server->api->dhandle("player.block.place", array("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);
|
||||
return $this->cancelAction($block, $player, false);
|
||||
}
|
||||
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){
|
||||
$t = $this->server->api->tileentity->addSign($player->level, $block->x, $block->y, $block->z);
|
||||
$t = $this->server->api->tile->addSign($player->level, $block->x, $block->y, $block->z);
|
||||
$t->data["creator"] = $player->username;
|
||||
}
|
||||
|
||||
if(($player->gamemode & 0x01) === 0x00){
|
||||
$player->removeItem($item->getID(), $item->getMetadata(), 1);
|
||||
--$item->count;
|
||||
if($item->count <= 0){
|
||||
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -715,29 +727,41 @@ class BlockAPI{
|
||||
}
|
||||
}*/
|
||||
|
||||
public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL){
|
||||
if(!($pos instanceof Block)){
|
||||
$block = $pos->level->getBlock($pos);
|
||||
public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){
|
||||
if($delay !== false){
|
||||
$this->scheduleBlockUpdate($pos->getSide(0), $delay, $type);
|
||||
$this->scheduleBlockUpdate($pos->getSide(1), $delay, $type);
|
||||
$this->scheduleBlockUpdate($pos->getSide(2), $delay, $type);
|
||||
$this->scheduleBlockUpdate($pos->getSide(3), $delay, $type);
|
||||
$this->scheduleBlockUpdate($pos->getSide(4), $delay, $type);
|
||||
$this->scheduleBlockUpdate($pos->getSide(5), $delay, $type);
|
||||
}else{
|
||||
$block = $pos;
|
||||
$this->blockUpdate($pos->getSide(0), $type);
|
||||
$this->blockUpdate($pos->getSide(1), $type);
|
||||
$this->blockUpdate($pos->getSide(2), $type);
|
||||
$this->blockUpdate($pos->getSide(3), $type);
|
||||
$this->blockUpdate($pos->getSide(4), $type);
|
||||
$this->blockUpdate($pos->getSide(5), $type);
|
||||
}
|
||||
$this->blockUpdate($block->getSide(0), $type);
|
||||
$this->blockUpdate($block->getSide(1), $type);
|
||||
$this->blockUpdate($block->getSide(2), $type);
|
||||
$this->blockUpdate($block->getSide(3), $type);
|
||||
$this->blockUpdate($block->getSide(4), $type);
|
||||
$this->blockUpdate($block->getSide(5), $type);
|
||||
}
|
||||
|
||||
public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){
|
||||
if(!($pos instanceof Block)){
|
||||
$block = $pos->level->getBlock($pos);
|
||||
}else{
|
||||
$block = $pos;
|
||||
$pos = new Position($pos->x, $pos->y, $pos->z, $pos->level);
|
||||
$block = $pos->level->getBlock($pos);
|
||||
}
|
||||
if($block === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
$level = $block->onUpdate($type);
|
||||
if($level === BLOCK_UPDATE_NORMAL){
|
||||
$this->blockUpdateAround($block, $level);
|
||||
$this->server->api->entity->updateRadius($pos, 1);
|
||||
}elseif($level === BLOCK_UPDATE_RANDOM){
|
||||
$this->nextRandomUpdate($pos);
|
||||
}
|
||||
return $level;
|
||||
}
|
||||
@ -748,37 +772,59 @@ class BlockAPI{
|
||||
return false;
|
||||
}
|
||||
|
||||
$index = $pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName();
|
||||
$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] = array(
|
||||
$pos,
|
||||
$type,
|
||||
$delay,
|
||||
);
|
||||
$this->server->query("INSERT INTO blockUpdates (x, y, z, level, delay) VALUES (".$pos->x.", ".$pos->y.", ".$pos->z.", '".$pos->level->getName()."', ".$delay.");");
|
||||
$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;
|
||||
}
|
||||
|
||||
public function blockUpdateTick($time, $event){
|
||||
if($event !== "server.tick"){ //WTF??
|
||||
return;
|
||||
public function nextRandomUpdate(Position $pos){
|
||||
if(!isset($this->scheduledUpdates[$pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".BLOCK_UPDATE_RANDOM])){
|
||||
$X = (($pos->x >> 4) << 4);
|
||||
$Y = (($pos->y >> 4) << 4);
|
||||
$Z = (($pos->z >> 4) << 4);
|
||||
$time = microtime(true);
|
||||
$i = 0;
|
||||
$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);
|
||||
if(count($this->scheduledUpdates) > 0){
|
||||
$update = $this->server->query("SELECT x,y,z,level FROM blockUpdates WHERE delay <= ".$time.";");
|
||||
if($update !== false and $update !== true){
|
||||
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= ".$time.";");
|
||||
if($update instanceof SQLite3Result){
|
||||
$upp = array();
|
||||
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"];
|
||||
$index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"].".".$up["type"];
|
||||
if(isset($this->scheduledUpdates[$index])){
|
||||
$up = $this->scheduledUpdates[$index];
|
||||
$upp[] = array((int) $up["type"], $this->scheduledUpdates[$index]);
|
||||
unset($this->scheduledUpdates[$index]);
|
||||
$this->blockUpdate($up[0], $up[1]);
|
||||
}
|
||||
}
|
||||
$this->server->query("DELETE FROM blockUpdates WHERE delay <= ".$time.";");
|
||||
foreach($upp as $b){
|
||||
$this->blockUpdate($b[1], $b[0]);
|
||||
}
|
||||
}
|
||||
$this->server->query("DELETE FROM blockUpdates WHERE delay <= ".$time.";");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,12 +36,11 @@ class ConsoleAPI{
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->event = $this->server->event("server.tick", array($this, "handle"));
|
||||
$this->server->schedule(2, array($this, "handle"), array(), true);
|
||||
$this->loop = new ConsoleLoop();
|
||||
$this->register("help", "[page|command name]", array($this, "defaultCommands"));
|
||||
$this->register("status", "", array($this, "defaultCommands"));
|
||||
$this->register("difficulty", "<0|1|2>", array($this, "defaultCommands"));
|
||||
$this->register("invisible", "<on|off>", array($this, "defaultCommands"));
|
||||
$this->register("difficulty", "<0|1|2|3>", array($this, "defaultCommands"));
|
||||
$this->register("stop", "", array($this, "defaultCommands"));
|
||||
$this->register("defaultgamemode", "<mode>", array($this, "defaultCommands"));
|
||||
$this->server->api->ban->cmdWhitelist("help");
|
||||
@ -81,26 +80,6 @@ class ConsoleAPI{
|
||||
$this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]);
|
||||
$output .= "Default Gamemode is now ".strtoupper($this->server->getGamemode()).".\n";
|
||||
break;
|
||||
case "invisible":
|
||||
$p = strtolower(array_shift($params));
|
||||
switch($p){
|
||||
case "on":
|
||||
case "true":
|
||||
case "1":
|
||||
$output .= "Server is invisible\n";
|
||||
$this->server->api->setProperty("server-invisible", true);
|
||||
break;
|
||||
case "off":
|
||||
case "false":
|
||||
case "0":
|
||||
$output .= "Server is visible\n";
|
||||
$this->server->api->setProperty("server-invisible", false);
|
||||
break;
|
||||
default:
|
||||
$output .= "Usage: /invisible <on | off>\n";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "status":
|
||||
if(!($issuer instanceof Player) and $issuer === "console"){
|
||||
$this->server->debugInfo(true);
|
||||
@ -118,8 +97,8 @@ class ConsoleAPI{
|
||||
break;
|
||||
case "difficulty":
|
||||
$s = trim(array_shift($params));
|
||||
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1)){
|
||||
$output .= "Usage: /difficulty <0|1>\n";
|
||||
if($s === "" or (((int) $s) > 3 and ((int) $s) < 0)){
|
||||
$output .= "Usage: /difficulty <0|1|2|3>\n";
|
||||
break;
|
||||
}
|
||||
$this->server->api->setProperty("difficulty", (int) $s);
|
||||
@ -257,15 +236,17 @@ class ConsoleAPI{
|
||||
$params = array();
|
||||
}
|
||||
|
||||
if($this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false
|
||||
or $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false){
|
||||
$output = "You don't have permission to use this command.\n";
|
||||
}else{
|
||||
if(($d1 = $this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false
|
||||
or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false){
|
||||
$output = "You don't have permissions to use this command.\n";
|
||||
}elseif($d1 !== true and $d2 !== true){
|
||||
if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){
|
||||
$output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias);
|
||||
}elseif($this->server->api->dhandle("console.command.unknown", array("cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias)) !== false){
|
||||
$output = $this->defaultCommands($cmd, $params, $issuer, $alias);
|
||||
}
|
||||
}else{
|
||||
$output = "";
|
||||
}
|
||||
if($output != "" and ($issuer instanceof Player)){
|
||||
$issuer->sendChat(trim($output));
|
||||
|
@ -43,9 +43,41 @@ class EntityAPI{
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->schedule(25, array($this, "updateEntities"), array(), true);
|
||||
}
|
||||
|
||||
public function updateEntities(){
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE hasUpdate = 1;");
|
||||
|
||||
if($l !== false and $l !== true){
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->get($e["EID"]);
|
||||
if($e instanceof Entity){
|
||||
$e->update();
|
||||
$this->server->query("UPDATE entities SET hasUpdate = 0 WHERE EID = ".$e->eid.";");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateRadius(Position $center, $radius = 15, $class = false){
|
||||
$this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '".$center->level->getName()."' ".($class !== false ? "AND class = $class ":"")."AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
|
||||
}
|
||||
|
||||
public function getRadius(Position $center, $radius = 15, $class = false){
|
||||
$entities = array();
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$center->level->getName()."' ".($class !== false ? "AND class = $class ":"")."AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
|
||||
if($l !== false and $l !== true){
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->get($e["EID"]);
|
||||
if($e instanceof Entity){
|
||||
$entities[$e->eid] = $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function getAll($level = null){
|
||||
if($level instanceof Level){
|
||||
$entities = array();
|
||||
@ -82,21 +114,9 @@ class EntityAPI{
|
||||
return $this->entities[$eid];
|
||||
}
|
||||
|
||||
public function spawnTo($eid, $player){
|
||||
$e = $this->get($eid);
|
||||
if($e === false){
|
||||
return false;
|
||||
}
|
||||
$e->spawn($player);
|
||||
}
|
||||
|
||||
public function spawnToAll(Level $level, $eid){
|
||||
$e = $this->get($eid);
|
||||
if($e === false){
|
||||
return false;
|
||||
}
|
||||
foreach($this->server->api->player->getAll($level) as $player){
|
||||
if($player->eid !== false and $player->eid !== $eid){
|
||||
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){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
@ -107,9 +127,12 @@ class EntityAPI{
|
||||
return;
|
||||
}
|
||||
$data = array(
|
||||
"x" => $pos->x + mt_rand(2, 8) / 10,
|
||||
"x" => $pos->x,
|
||||
"y" => $pos->y + 0.19,
|
||||
"z" => $pos->z + mt_rand(2, 8) / 10,
|
||||
"z" => $pos->z,
|
||||
//"speedX" => mt_rand(-3, 3) / 8,
|
||||
"speedY" => mt_rand(5, 8) / 2,
|
||||
//"speedZ" => mt_rand(-3, 3) / 8,
|
||||
"item" => $item,
|
||||
);
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
@ -117,17 +140,17 @@ class EntityAPI{
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
//$e->speedX = mt_rand(-10, 10) / 100;
|
||||
//$e->speedY = mt_rand(0, 5) / 100;
|
||||
//$e->speedZ = mt_rand(-10, 10) / 100;
|
||||
$this->spawnToAll($pos->level, $e->eid);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function spawnAll(Player $player){
|
||||
foreach($this->getAll($player->level) as $e){
|
||||
$e->spawn($player);
|
||||
if($e->class !== ENTITY_PLAYER){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,6 +161,16 @@ class EntityAPI{
|
||||
unset($this->entities[$eid]);
|
||||
$entity->closed = true;
|
||||
$this->server->query("DELETE FROM entities WHERE EID = ".$eid.";");
|
||||
if($entity->class === ENTITY_PLAYER){
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll(), MC_REMOVE_PLAYER, array(
|
||||
"clientID" => 0,
|
||||
"eid" => $entity->eid,
|
||||
));
|
||||
}else{
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), MC_REMOVE_ENTITY, array(
|
||||
"eid" => $entity->eid,
|
||||
));
|
||||
}
|
||||
$this->server->api->dhandle("entity.remove", $entity);
|
||||
$entity = null;
|
||||
unset($entity);
|
||||
|
@ -96,14 +96,16 @@ class LevelAPI{
|
||||
|
||||
if($generator !== false and class_exists($generator)){
|
||||
$generator = new $generator($options);
|
||||
}elseif($this->server->api->getProperty("generator") !== false and class_exists($this->server->api->getProperty("generator"))){
|
||||
$generator = $this->server->api->getProperty("generator");
|
||||
$generator = new $generator($options);
|
||||
}else{
|
||||
$generator = new SuperflatGenerator($options);
|
||||
if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){
|
||||
$generator = new SuperflatGenerator($options);
|
||||
}else{
|
||||
$generator = new TemporalGenerator($options);
|
||||
}
|
||||
}
|
||||
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed);
|
||||
$gen->generate();
|
||||
$gen->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -121,11 +123,12 @@ class LevelAPI{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function unloadLevel(Level $level){
|
||||
public function unloadLevel(Level $level, $force = false){
|
||||
$name = $level->getName();
|
||||
if($name === $this->default){
|
||||
if($name === $this->default and $force !== true){
|
||||
return false;
|
||||
}
|
||||
console("[INFO] Unloading level \"".$name."\"");
|
||||
$level->nextSave = PHP_INT_MAX;
|
||||
$level->save();
|
||||
foreach($this->server->api->player->getAll($level) as $player){
|
||||
@ -136,9 +139,10 @@ class LevelAPI{
|
||||
$entity->close();
|
||||
}
|
||||
}
|
||||
foreach($this->server->api->tileentity->getAll($level) as $tile){
|
||||
foreach($this->server->api->tile->getAll($level) as $tile){
|
||||
$tile->close();
|
||||
}
|
||||
$level->close();
|
||||
unset($this->levels[$name]);
|
||||
return true;
|
||||
}
|
||||
@ -154,8 +158,12 @@ class LevelAPI{
|
||||
console("[INFO] Preparing level \"".$name."\"");
|
||||
$level = new PMFLevel($path."level.pmf");
|
||||
$entities = new Config($path."entities.yml", CONFIG_YAML);
|
||||
$tileEntities = new Config($path."tileEntities.yml", CONFIG_YAML);
|
||||
$this->levels[$name] = new Level($level, $entities, $tileEntities, $name);
|
||||
if(file_exists($path."tileEntities.yml")){
|
||||
@rename($path."tileEntities.yml", $path."tiles.yml");
|
||||
}
|
||||
$tiles = new Config($path."tiles.yml", CONFIG_YAML);
|
||||
$blockUpdates = new Config($path."bupdates.yml", CONFIG_YAML);
|
||||
$this->levels[$name] = new Level($level, $entities, $tiles, $blockUpdates, $name);
|
||||
foreach($entities->getAll() as $entity){
|
||||
if(!isset($entity["id"])){
|
||||
break;
|
||||
@ -170,7 +178,11 @@ class LevelAPI{
|
||||
"yaw" => $entity["Rotation"][0],
|
||||
"pitch" => $entity["Rotation"][1],
|
||||
));
|
||||
}elseif($entity["id"] === OBJECT_PAINTING){ //Painting
|
||||
}elseif($entity["id"] === FALLING_SAND){
|
||||
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity);
|
||||
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
|
||||
$e->setHealth($entity["Health"]);
|
||||
}elseif($entity["id"] === OBJECT_PAINTING or $entity["id"] === OBJECT_ARROW){ //Painting
|
||||
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity);
|
||||
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
|
||||
$e->setHealth($entity["Health"]);
|
||||
@ -181,12 +193,18 @@ class LevelAPI{
|
||||
}
|
||||
}
|
||||
|
||||
foreach($tileEntities->getAll() as $tile){
|
||||
foreach($tiles->getAll() as $tile){
|
||||
if(!isset($tile["id"])){
|
||||
break;
|
||||
}
|
||||
$t = $this->server->api->tileentity->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile);
|
||||
$t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile);
|
||||
}
|
||||
|
||||
$timeu = microtime(true);
|
||||
foreach($blockUpdates->getAll() as $bupdate){
|
||||
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function handle($data, $event){
|
||||
@ -199,6 +217,13 @@ class LevelAPI{
|
||||
$level->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
$this->saveAll();
|
||||
foreach($this->levels as $level){
|
||||
$this->unloadLevel($level, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSpawn(){
|
||||
return $this->server->spawn;
|
||||
|
@ -25,10 +25,13 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class SnowLayerBlock extends FlowableBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(SNOW_LAYER, $meta, "Snow Layer");
|
||||
$this->isReplaceable = true;
|
||||
class MobAPI{
|
||||
private $server;
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
}
|
||||
public function init(){
|
||||
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ class PlayerAPI{
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->addHandler("server.regeneration", array($this, "handle"));
|
||||
$this->server->schedule(20 * 15, array($this, "handle"), 1, true, "server.regeneration");
|
||||
$this->server->addHandler("player.death", array($this, "handle"), 1);
|
||||
$this->server->api->console->register("list", "", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("kill", "<player>", array($this, "commandHandler"));
|
||||
@ -40,28 +40,32 @@ class PlayerAPI{
|
||||
$this->server->api->console->register("tp", "[target player] <destination player|w:world> OR /tp [target player] <x> <y> <z>", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("spawnpoint", "[player] [x] [y] [z]", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("spawn", "", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("lag", "", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("ping", "", array($this, "commandHandler"));
|
||||
$this->server->api->console->alias("lag", "ping");
|
||||
$this->server->api->console->alias("suicide", "kill");
|
||||
$this->server->api->console->alias("tppos", "tp");
|
||||
$this->server->api->ban->cmdWhitelist("list");
|
||||
$this->server->api->ban->cmdWhitelist("lag");
|
||||
$this->server->api->ban->cmdWhitelist("ping");
|
||||
$this->server->api->ban->cmdWhitelist("spawn");
|
||||
$this->server->preparedSQL->selectPlayersToHeal = $this->server->database->prepare("SELECT EID FROM entities WHERE class = ".ENTITY_PLAYER." AND health < 20;");
|
||||
}
|
||||
|
||||
public function handle($data, $event){
|
||||
switch($event){
|
||||
case "server.regeneration":
|
||||
$result = $this->server->query("SELECT EID FROM entities WHERE class = ".ENTITY_PLAYER." AND health < 20;");
|
||||
if($result !== true and $result !== false){
|
||||
while(($player = $result->fetchArray()) !== false){
|
||||
if(($player = $this->server->api->entity->get($player["EID"])) !== false){
|
||||
if($player->getHealth() <= 0){
|
||||
continue;
|
||||
if($this->server->difficulty === 0){
|
||||
$result = $this->server->preparedSQL->selectPlayersToHeal->execute();
|
||||
if($result !== false){
|
||||
while(($player = $result->fetchArray()) !== false){
|
||||
if(($player = $this->server->api->entity->get($player["EID"])) !== false){
|
||||
if($player->getHealth() <= 0){
|
||||
continue;
|
||||
}
|
||||
$player->setHealth(min(20, $player->getHealth() + $data), "regeneration");
|
||||
}
|
||||
$player->setHealth(min(20, $player->getHealth() + $data), "regeneration");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case "player.death":
|
||||
@ -70,7 +74,7 @@ class PlayerAPI{
|
||||
if($e instanceof Entity){
|
||||
switch($e->class){
|
||||
case ENTITY_PLAYER:
|
||||
$message .= " was killed by ".$e->name;
|
||||
$message = " was killed by ".$e->name;
|
||||
break;
|
||||
default:
|
||||
$message = " was killed";
|
||||
@ -152,12 +156,12 @@ class PlayerAPI{
|
||||
$spawn = $issuer->getSpawn();
|
||||
$issuer->teleport($spawn);
|
||||
break;
|
||||
case "lag":
|
||||
case "ping":
|
||||
if(!($issuer instanceof Player)){
|
||||
$output .= "Please run this command in-game.\n";
|
||||
break;
|
||||
}
|
||||
$output .= "Lag: ".round($issuer->getLag(), 2)."\n";
|
||||
$output .= "ping ".round($issuer->getLag(), 2)."ms, packet loss ".round($issuer->getPacketLoss() * 100, 2)."%, ".round($issuer->getBandwidth() / 1024, 2)." KB/s\n";
|
||||
break;
|
||||
case "gamemode":
|
||||
$player = false;
|
||||
@ -238,7 +242,8 @@ class PlayerAPI{
|
||||
$player = $this->get($params[0]);
|
||||
}
|
||||
if($player instanceof Player){
|
||||
$this->server->api->entity->harm($player->eid, 20, "console", true);
|
||||
$player->entity->harm(1000, "console", true);
|
||||
$player->sendChat("Ouch. That looks like it hurt.\n");
|
||||
}else{
|
||||
$output .= "Usage: /$cmd [player]\n";
|
||||
}
|
||||
@ -316,7 +321,7 @@ class PlayerAPI{
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->getByEID($e["EID"]);
|
||||
if($e instanceof Player){
|
||||
$clients[$e->clientID] = $e;
|
||||
$clients[$e->CID] = $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -343,16 +348,6 @@ class PlayerAPI{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getByClientID($clientID){
|
||||
$clientID = (int) $clientID;
|
||||
$CID = $this->server->query("SELECT ip,port FROM players WHERE clientID = '".$clientID."';", true);
|
||||
$CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]);
|
||||
if(isset($this->server->clients[$CID])){
|
||||
return $this->server->clients[$CID];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function online(){
|
||||
$o = array();
|
||||
foreach($this->server->clients as $p){
|
||||
@ -371,20 +366,55 @@ class PlayerAPI{
|
||||
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", array(
|
||||
"level" => $player->level->getName(),
|
||||
"x" => $player->level->getSpawn()->x,
|
||||
"y" => $player->level->getSpawn()->y,
|
||||
"z" => $player->level->getSpawn()->z,
|
||||
));
|
||||
"level" => $player->level->getName(),
|
||||
"x" => $player->level->getSpawn()->x,
|
||||
"y" => $player->level->getSpawn()->y,
|
||||
"z" => $player->level->getSpawn()->z,
|
||||
));
|
||||
}
|
||||
$this->server->query("INSERT OR REPLACE INTO players (CID, ip, port, name) VALUES (".$player->CID.", '".$player->ip."', ".$player->port.", '".strtolower($player->username)."');");
|
||||
}
|
||||
}
|
||||
|
||||
public function spawnAllPlayers(Player $player){
|
||||
foreach($this->getAll() as $p){
|
||||
if($p !== $player and ($p->entity instanceof Entity)){
|
||||
$p->entity->spawn($player);
|
||||
if($p->level !== $player->level){
|
||||
$player->dataPacket(MC_MOVE_ENTITY_POSROT, array(
|
||||
"eid" => $p->entity->eid,
|
||||
"x" => -256,
|
||||
"y" => 128,
|
||||
"z" => -256,
|
||||
"yaw" => 0,
|
||||
"pitch" => 0,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function spawnToAllPlayers(Player $player){
|
||||
foreach($this->getAll() as $p){
|
||||
if($p !== $player and ($p->entity instanceof Entity)){
|
||||
$player->entity->spawn($p);
|
||||
if($p->level !== $player->level){
|
||||
$p->dataPacket(MC_MOVE_ENTITY_POSROT, array(
|
||||
"eid" => $player->entity->eid,
|
||||
"x" => -256,
|
||||
"y" => 128,
|
||||
"z" => -256,
|
||||
"yaw" => 0,
|
||||
"pitch" => 0,
|
||||
));
|
||||
}
|
||||
}
|
||||
$this->server->query("INSERT OR REPLACE INTO players (clientID, ip, port, name) VALUES (".$player->clientID.", '".$player->ip."', ".$player->port.", '".strtolower($player->username)."');");
|
||||
}
|
||||
}
|
||||
|
||||
public function remove($CID){
|
||||
if(isset($this->server->clients[$CID])){
|
||||
$player = $this->server->clients[$CID];
|
||||
$this->server->clients[$CID] = null;
|
||||
unset($this->server->clients[$CID]);
|
||||
$player->close();
|
||||
if($player->username != "" and ($player->data instanceof Config)){
|
||||
@ -392,8 +422,8 @@ class PlayerAPI{
|
||||
}
|
||||
$this->server->query("DELETE FROM players WHERE name = '".$player->username."';");
|
||||
if($player->entity instanceof Entity){
|
||||
$player->entity->player = null;
|
||||
$player->entity = null;
|
||||
unset($player->entity->player);
|
||||
unset($player->entity);
|
||||
}
|
||||
$this->server->api->entity->remove($player->eid);
|
||||
$player = null;
|
||||
@ -417,18 +447,22 @@ class PlayerAPI{
|
||||
"y" => $this->server->spawn->y,
|
||||
"z" => $this->server->spawn->z,
|
||||
),
|
||||
"inventory" => array_fill(0, 36, array(AIR, 0, 0)),
|
||||
"armor" => array_fill(0, 4, array(AIR, 0, 0)),
|
||||
"inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, array(AIR, 0, 0)),
|
||||
"armor" => array_fill(0, 4, array(AIR, 0)),
|
||||
"gamemode" => $this->server->gamemode,
|
||||
"health" => 20,
|
||||
"lastIP" => "",
|
||||
"lastID" => 0,
|
||||
);
|
||||
$data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default);
|
||||
|
||||
if(!file_exists(DATA_PATH."players/".$iname.".yml")){
|
||||
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile");
|
||||
$data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default);
|
||||
$data->save();
|
||||
}else{
|
||||
$data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default);
|
||||
}
|
||||
|
||||
if(($this->server->gamemode & 0x01) === 0x01){
|
||||
$data->set("health", 20);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class PluginAPI extends stdClass{
|
||||
}else{
|
||||
$content = file_get_contents($file);
|
||||
$info = strstr($content, "*/", true);
|
||||
$content = substr(strstr($content, "*/"),2);
|
||||
$content = str_repeat(PHP_EOL, substr_count($info, "\n")).substr(strstr($content, "*/"),2);
|
||||
if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches
|
||||
console("[ERROR] Failed parsing of ".basename($file));
|
||||
return false;
|
||||
|
@ -50,7 +50,6 @@ class ServerAPI{
|
||||
}
|
||||
|
||||
public function load(){
|
||||
@mkdir(DATA_PATH."logs/", 0755, true);
|
||||
@mkdir(DATA_PATH."players/", 0755);
|
||||
@mkdir(DATA_PATH."worlds/", 0755);
|
||||
@mkdir(DATA_PATH."plugins/", 0755);
|
||||
@ -58,33 +57,34 @@ class ServerAPI{
|
||||
|
||||
console("[INFO] Loading properties...");
|
||||
$this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, array(
|
||||
"server-name" => "Minecraft PE Server",
|
||||
"server-name" => "Minecraft: PE Server",
|
||||
"description" => "Server made using PocketMine-MP",
|
||||
"motd" => "Welcome @player to this server!",
|
||||
"server-ip" => "",
|
||||
"server-port" => 19132,
|
||||
"server-type" => "normal",
|
||||
"server-invisible" => false,
|
||||
"memory-limit" => "128M",
|
||||
"last-update" => false,
|
||||
"white-list" => false,
|
||||
"spawn-protection" => 16,
|
||||
"view-distance" => 7,
|
||||
"view-distance" => 10,
|
||||
"max-players" => 20,
|
||||
"allow-flight" => false,
|
||||
"item-enforcement" => false,
|
||||
"spawn-animals" => true,
|
||||
"spawn-mobs" => true,
|
||||
"gamemode" => SURVIVAL,
|
||||
"hardcore" => false,
|
||||
"pvp" => true,
|
||||
"difficulty" => 1,
|
||||
"generator" => "",
|
||||
"generator-settings" => "",
|
||||
"level-name" => "world",
|
||||
"level-seed" => "",
|
||||
"level-type" => "FLAT",
|
||||
"level-type" => "DEFAULT",
|
||||
"enable-query" => true,
|
||||
"enable-rcon" => false,
|
||||
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
|
||||
"send-usage" => true,
|
||||
"auto-save" => true,
|
||||
));
|
||||
|
||||
$this->parseProperties();
|
||||
@ -95,16 +95,14 @@ class ServerAPI{
|
||||
$this->config->remove("invisible");
|
||||
}
|
||||
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0");
|
||||
self::$serverRequest = $this->server;
|
||||
$this->server->api = $this;
|
||||
self::$serverRequest = $this->server;
|
||||
|
||||
if($this->getProperty("upnp-forwarding") === true){
|
||||
console("[INFO] [UPnP] Trying to port forward...");
|
||||
UPnP_PortForward($this->getProperty("server-port"));
|
||||
}
|
||||
if(($ip = Utils::getIP()) !== false){
|
||||
console("[INFO] External IP: ".$ip);
|
||||
}
|
||||
|
||||
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
|
||||
console("[INFO] Checking for new server version");
|
||||
console("[INFO] Last check: \x1b[36m".date("Y-m-d H:i:s", $this->getProperty("last-update"))."\x1b[0m");
|
||||
@ -119,7 +117,6 @@ class ServerAPI{
|
||||
console("[NOTICE] \x1b[33mVersion \"".$info["development"]["version"]."\" [".substr($info["development"]["commit"], 0, 10)."]");
|
||||
console("[NOTICE] \x1b[36mGet it at PocketMine.net or ".$info["development"]["download"]);
|
||||
console("[NOTICE] This message will dissapear after issuing the command \"/update-done\"");
|
||||
sleep(3);
|
||||
}else{
|
||||
$this->setProperty("last-update", time());
|
||||
console("[INFO] \x1b[36mThis is the latest DEVELOPMENT version");
|
||||
@ -138,13 +135,11 @@ class ServerAPI{
|
||||
console("[NOTICE] \x1b[36mVersion \"".$info["stable"]["version"]."\" #".$updateN);
|
||||
console("[NOTICE] Get it at PocketMine.net or ".$info["stable"]["download"]);
|
||||
console("[NOTICE] This message will dissapear as soon as you update");
|
||||
sleep(5);
|
||||
}else{
|
||||
$this->setProperty("last-update", time());
|
||||
console("[INFO] \x1b[36mThis is the latest STABLE version");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,9 +152,10 @@ class ServerAPI{
|
||||
$this->loadAPI("chat", "ChatAPI");
|
||||
$this->loadAPI("ban", "BanAPI");
|
||||
$this->loadAPI("entity", "EntityAPI");
|
||||
$this->loadAPI("tileentity", "TileEntityAPI");
|
||||
$this->loadAPI("tile", "TileAPI");
|
||||
$this->loadAPI("player", "PlayerAPI");
|
||||
$this->loadAPI("time", "TimeAPI");
|
||||
$this->loadAPI("mob", "MobAPI");
|
||||
|
||||
foreach($this->apiList as $ob){
|
||||
if(is_callable(array($ob, "init"))){
|
||||
@ -184,6 +180,10 @@ class ServerAPI{
|
||||
unset($this->asyncCalls[$id]);
|
||||
return $ob;
|
||||
}
|
||||
public function autoSave(){
|
||||
console("[DEBUG] Saving....", true, true, 2);
|
||||
$this->server->api->level->saveAll();
|
||||
}
|
||||
|
||||
public function sendUsage(){
|
||||
console("[DEBUG] Sending usage data...", true, true, 2);
|
||||
@ -191,27 +191,31 @@ class ServerAPI{
|
||||
foreach($this->plugin->getList() as $p){
|
||||
$plist .= str_replace(array(";", ":"), "", $p["name"]).":".str_replace(array(";", ":"), "", $p["version"]).";";
|
||||
}
|
||||
Utils::curl_post("http://stats.pocketmine.net/usage.php", array(
|
||||
"serverid" => $this->server->serverID,
|
||||
"port" => $this->server->port,
|
||||
"os" => Utils::getOS(),
|
||||
"memory_total" => $this->getProperty("memory-limit"),
|
||||
"memory_usage" => memory_get_usage(true),
|
||||
"php_version" => PHP_VERSION,
|
||||
"version" => MAJOR_VERSION,
|
||||
"mc_version" => CURRENT_MINECRAFT_VERSION,
|
||||
"protocol" => CURRENT_PROTOCOL,
|
||||
"online" => count($this->server->clients),
|
||||
"max" => $this->server->maxClients,
|
||||
"plugins" => $plist,
|
||||
), 10);
|
||||
|
||||
$this->asyncOperation(ASYNC_CURL_POST, array(
|
||||
"url" => "http://stats.pocketmine.net/usage.php",
|
||||
"data" => array(
|
||||
"serverid" => $this->server->serverID,
|
||||
"port" => $this->server->port,
|
||||
"os" => Utils::getOS(),
|
||||
"memory_total" => $this->getProperty("memory-limit"),
|
||||
"memory_usage" => memory_get_usage(true),
|
||||
"php_version" => PHP_VERSION,
|
||||
"version" => MAJOR_VERSION,
|
||||
"mc_version" => CURRENT_MINECRAFT_VERSION,
|
||||
"protocol" => CURRENT_PROTOCOL,
|
||||
"online" => count($this->server->clients),
|
||||
"max" => $this->server->maxClients,
|
||||
"plugins" => $plist,
|
||||
),
|
||||
), NULL);
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
foreach($this->apiList as $ob){
|
||||
if(is_callable($ob, "__destruct")){
|
||||
foreach($this->apiList as $i => $ob){
|
||||
if(method_exists($ob, "__destruct")){
|
||||
$ob->__destruct();
|
||||
unset($this->apiList[$ob]);
|
||||
unset($this->apiList[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -226,14 +230,11 @@ class ServerAPI{
|
||||
}
|
||||
@ini_set("memory_limit", $memory);
|
||||
}else{
|
||||
$this->setProperty("memory-limit", "256M");
|
||||
}
|
||||
if(!$this->config->exists("server-invisible")){
|
||||
$this->config->set("server-invisible", false);
|
||||
$this->setProperty("memory-limit", "128M");
|
||||
}
|
||||
|
||||
if($this->server instanceof PocketMinecraftServer){
|
||||
$this->server->setType($this->getProperty("server-type"));
|
||||
$this->server->invisible = $this->getProperty("server-invisible");
|
||||
$this->server->maxClients = $this->getProperty("max-players");
|
||||
$this->server->description = $this->getProperty("description");
|
||||
$this->server->motd = $this->getProperty("motd");
|
||||
@ -273,15 +274,19 @@ class ServerAPI{
|
||||
}
|
||||
$this->config->set($n, $v);
|
||||
}
|
||||
if($this->getProperty("hardcore") == 1 and $this->getProperty("difficulty") < 3){
|
||||
$this->setProperty("difficulty", 3);
|
||||
}
|
||||
}
|
||||
|
||||
public function init(){
|
||||
if($this->getProperty("send-usage") !== false){
|
||||
$this->server->schedule(36000, array($this, "sendUsage"), array(), true); //Send usage data every 30 minutes
|
||||
$this->server->schedule(6000, array($this, "sendUsage")); //Send the info after 5 minutes have passed
|
||||
$this->server->schedule(6000, array($this, "sendUsage"), array(), true); //Send the info after 5 minutes have passed
|
||||
$this->sendUsage();
|
||||
}
|
||||
|
||||
if($this->getProperty("auto-save") === true){
|
||||
$this->server->schedule(18000, array($this, "autoSave"), array(), true);
|
||||
}
|
||||
if($this->getProperty("enable-rcon") === true){
|
||||
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
|
||||
}
|
||||
@ -289,7 +294,7 @@ class ServerAPI{
|
||||
if($this->getProperty("enable-query") === true){
|
||||
$this->query = new Query();
|
||||
}
|
||||
|
||||
CraftingRecipes::init();
|
||||
$this->server->init();
|
||||
unregister_tick_function(array($this->server, "tick"));
|
||||
$this->console->__destruct();
|
||||
@ -306,6 +311,10 @@ class ServerAPI{
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
public function asyncOperation($t, $d, $c = null){
|
||||
return $this->server->asyncOperation($t, $d, $c);
|
||||
}
|
||||
|
||||
public function addHandler($e, $c, $p = 5){
|
||||
return $this->server->addHandler($e, $c, $p);
|
||||
}
|
||||
@ -318,10 +327,6 @@ class ServerAPI{
|
||||
return $this->server->handle($e, $d);
|
||||
}
|
||||
|
||||
public function action($t, $c, $r = true){
|
||||
return $this->server->action($t, $c, $r);
|
||||
}
|
||||
|
||||
public function schedule($t, $c, $d, $r = false, $e = "server.schedule"){
|
||||
return $this->server->schedule($t, $c, $d, $r, $e);
|
||||
}
|
||||
@ -416,4 +421,4 @@ class ServerAPI{
|
||||
console("[".($internal === true ? "INTERNAL":"DEBUG")."] API \x1b[36m".$name."\x1b[0m [\x1b[30;1m".$class."\x1b[0m] loaded", true, true, ($internal === true ? 3:2));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -25,38 +25,28 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class TileEntityAPI{
|
||||
class TileAPI{
|
||||
private $server;
|
||||
private $tileEntities;
|
||||
private $tiles;
|
||||
private $tCnt = 1;
|
||||
function __construct(){
|
||||
$this->tileEntities = array();
|
||||
$this->tiles = array();
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
public function get(Position $pos){
|
||||
$tiles = $this->server->query("SELECT * FROM tileentities WHERE level = '".$pos->level->getName()."' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};");
|
||||
$ret = array();
|
||||
if($tiles !== false and $tiles !== true){
|
||||
while(($t = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
if(($tile = $this->getByID($t["ID"])) !== false){
|
||||
if($tile->normal === true){
|
||||
$ret[] = $tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
$tile = $this->server->query("SELECT * FROM tiles WHERE level = '".$pos->level->getName()."' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};", true);
|
||||
if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){
|
||||
return $tile;
|
||||
}
|
||||
if(count($ret) === 0){
|
||||
return false;
|
||||
}
|
||||
return $ret;
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getByID($id){
|
||||
if($id instanceof TileEntity){
|
||||
if($id instanceof Tile){
|
||||
return $id;
|
||||
}elseif(isset($this->tileEntities[$id])){
|
||||
return $this->tileEntities[$id];
|
||||
}elseif(isset($this->tiles[$id])){
|
||||
return $this->tiles[$id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -67,26 +57,26 @@ class TileEntityAPI{
|
||||
|
||||
public function getAll($level = null){
|
||||
if($level instanceof Level){
|
||||
$tileEntities = array();
|
||||
$l = $this->server->query("SELECT ID FROM tileentities WHERE level = '".$level->getName()."';");
|
||||
$tiles = array();
|
||||
$l = $this->server->query("SELECT ID FROM tiles WHERE level = '".$level->getName()."';");
|
||||
if($l !== false and $l !== true){
|
||||
while(($t = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$t = $this->getByID($t["ID"]);
|
||||
if($t instanceof TileEntity){
|
||||
$tileEntities[$t->id] = $t;
|
||||
if($t instanceof Tile){
|
||||
$tiles[$t->id] = $t;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tileEntities;
|
||||
return $tiles;
|
||||
}
|
||||
return $this->tileEntities;
|
||||
return $this->tiles;
|
||||
}
|
||||
|
||||
public function add(Level $level, $class, $x, $y, $z, $data = array()){
|
||||
$id = $this->tCnt++;
|
||||
$this->tileEntities[$id] = new TileEntity($level, $id, $class, $x, $y, $z, $data);
|
||||
$this->spawnToAll($level, $id);
|
||||
return $this->tileEntities[$id];
|
||||
$this->tiles[$id] = new Tile($level, $id, $class, $x, $y, $z, $data);
|
||||
$this->spawnToAll($this->tiles[$id]);
|
||||
return $this->tiles[$id];
|
||||
}
|
||||
|
||||
public function addSign(Level $level, $x, $y, $z, $lines = array("", "", "", "")){
|
||||
@ -102,20 +92,8 @@ class TileEntityAPI{
|
||||
));
|
||||
}
|
||||
|
||||
public function spawnTo($id, $player, $queue = false){
|
||||
$t = $this->getByID($id);
|
||||
if($t === false){
|
||||
return false;
|
||||
}
|
||||
$t->spawn($player, $queue);
|
||||
}
|
||||
|
||||
public function spawnToAll(Level $level, $id){
|
||||
$t = $this->getByID($id);
|
||||
if($t === false){
|
||||
return false;
|
||||
}
|
||||
foreach($this->server->api->player->getAll($level) as $player){
|
||||
public function spawnToAll(Tile $t){
|
||||
foreach($this->server->api->player->getAll($t->level) as $player){
|
||||
if($player->eid !== false){
|
||||
$t->spawn($player);
|
||||
}
|
||||
@ -129,13 +107,14 @@ class TileEntityAPI{
|
||||
}
|
||||
|
||||
public function remove($id){
|
||||
if(isset($this->tileEntities[$id])){
|
||||
$t = $this->tileEntities[$id];
|
||||
$this->tileEntities[$id] = null;
|
||||
unset($this->tileEntities[$id]);
|
||||
if(isset($this->tiles[$id])){
|
||||
$t = $this->tiles[$id];
|
||||
$this->tiles[$id] = null;
|
||||
unset($this->tiles[$id]);
|
||||
$t->closed = true;
|
||||
$t->close();
|
||||
$this->server->query("DELETE FROM tileentities WHERE ID = ".$id.";");
|
||||
$this->server->query("DELETE FROM tiles WHERE ID = ".$id.";");
|
||||
$this->server->api->dhandle("tile.remove", $t);
|
||||
$t = null;
|
||||
unset($t);
|
||||
}
|
@ -100,7 +100,6 @@ class TimeAPI{
|
||||
$level = $this->server->api->level->getDefault();
|
||||
}
|
||||
$level->setTime($level->getTime() + (int) $time);
|
||||
return $this->server->time;
|
||||
}
|
||||
|
||||
public function getDate($time = false){
|
||||
|
@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
class Deprecation{
|
||||
public static $events = array(
|
||||
"server.tick" => "ServerAPI::schedule()",
|
||||
"server.time" => "time.change",
|
||||
"world.block.change" => "block.change",
|
||||
"block.drop" => "item.drop",
|
||||
|
2153
src/Player.php
2153
src/Player.php
File diff suppressed because it is too large
Load Diff
@ -27,8 +27,8 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
class PocketMinecraftServer{
|
||||
public $tCnt;
|
||||
public $serverID, $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
|
||||
private $serverip, $database, $interface, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks;
|
||||
public $serverID, $interface, $database, $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
|
||||
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks, $memoryStats, $async = array(), $asyncID = 0;
|
||||
|
||||
private function load(){
|
||||
$this->version = new VersionString();
|
||||
@ -52,7 +52,7 @@ class PocketMinecraftServer{
|
||||
$this->invisible = false;
|
||||
$this->levelData = false;
|
||||
$this->difficulty = 1;
|
||||
$this->tileEntities = array();
|
||||
$this->tiles = array();
|
||||
$this->entities = array();
|
||||
$this->custom = array();
|
||||
$this->evCnt = 1;
|
||||
@ -63,15 +63,17 @@ class PocketMinecraftServer{
|
||||
$this->scheduleCnt = 1;
|
||||
$this->description = "";
|
||||
$this->whitelist = false;
|
||||
$this->memoryStats = array();
|
||||
$this->clients = array();
|
||||
$this->spawn = false;
|
||||
$this->saveEnabled = true;
|
||||
$this->tickMeasure = array_fill(0, 40, 0);
|
||||
$this->setType("normal");
|
||||
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false, $this->serverip);
|
||||
$this->interface = new MinecraftInterface($this, "255.255.255.255", $this->port, true, false, $this->serverip);
|
||||
$this->reloadConfig();
|
||||
$this->stop = false;
|
||||
$this->ticks = 0;
|
||||
$this->asyncThread = new AsyncMultipleQueue();
|
||||
}
|
||||
|
||||
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
||||
@ -93,42 +95,62 @@ class PocketMinecraftServer{
|
||||
}
|
||||
|
||||
public function titleTick(){
|
||||
$time = microtime(true);
|
||||
if(ENABLE_ANSI === true){
|
||||
echo "\x1b]0;PocketMine-MP ".MAJOR_VERSION." | Online ". count($this->clients)."/".$this->maxClients." | RAM ".round((memory_get_usage() / 1024) / 1024, 2)."MB | TPS ".$this->getTPS()."\x07";
|
||||
echo "\x1b]0;PocketMine-MP ".MAJOR_VERSION." | Online ". count($this->clients)."/".$this->maxClients." | RAM ".round((memory_get_usage() / 1024) / 1024, 2)."MB | U ".round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." D ".round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." kB/s | TPS ".$this->getTPS()."\x07";
|
||||
}
|
||||
$this->interface->bandwidth = array(0, 0, $time);
|
||||
}
|
||||
|
||||
public function loadEvents(){
|
||||
if(ENABLE_ANSI === true){
|
||||
$this->action(1500000, '$this->titleTick();');
|
||||
$this->schedule(30, array($this, "titleTick"), array(), true);
|
||||
}
|
||||
$this->schedule(20 * 15, array($this, "checkTicks"), array(), true);
|
||||
$this->schedule(20 * 60, array($this, "checkMemory"), array(), true);
|
||||
$this->schedule(20, array($this, "asyncOperationChecker"), array(), true);
|
||||
}
|
||||
|
||||
public function checkTicks(){
|
||||
if($this->getTPS() < 12){
|
||||
console("[WARNING] Can't keep up! Is the server overloaded?");
|
||||
}
|
||||
}
|
||||
|
||||
public function checkMemory(){
|
||||
$info = $this->debugInfo();
|
||||
$data = $info["memory_usage"].",".$info["players"].",".$info["entities"];
|
||||
$i = count($this->memoryStats) - 1;
|
||||
if($i < 0 or $this->memoryStats[$i] !== $data){
|
||||
$this->memoryStats[] = $data;
|
||||
}
|
||||
$this->action(5000000, 'if($this->difficulty < 2){$this->api->dhandle("server.regeneration", 1);}');
|
||||
$this->action(1000000 * 15, 'if($this->getTPS() < 15){console("[WARNING] Can\'t keep up! Is the server overloaded?");}');
|
||||
$this->action(1000000 * 60 * 10, '$this->custom = array();');
|
||||
}
|
||||
|
||||
public function startDatabase(){
|
||||
$this->preparedSQL = new stdClass();
|
||||
$this->preparedSQL->entity = new stdClass();
|
||||
$this->database = new SQLite3(":memory:");
|
||||
$this->query("PRAGMA journal_mode = OFF;");
|
||||
$this->query("PRAGMA encoding = \"UTF-8\";");
|
||||
$this->query("PRAGMA secure_delete = OFF;");
|
||||
$this->query("CREATE TABLE players (clientID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE COLLATE NOCASE);");
|
||||
$this->query("CREATE TABLE entities (EID INTEGER PRIMARY KEY, level TEXT, type NUMERIC, class NUMERIC, name TEXT, x NUMERIC, y NUMERIC, z NUMERIC, yaw NUMERIC, pitch NUMERIC, health NUMERIC);");
|
||||
$this->query("CREATE TABLE tileentities (ID INTEGER PRIMARY KEY, level TEXT, class TEXT, x NUMERIC, y NUMERIC, z NUMERIC, spawnable NUMERIC);");
|
||||
$this->query("CREATE TABLE players (CID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE COLLATE NOCASE);");
|
||||
$this->query("CREATE TABLE entities (EID INTEGER PRIMARY KEY, level TEXT, type NUMERIC, class NUMERIC, hasUpdate NUMERIC, name TEXT, x NUMERIC, y NUMERIC, z NUMERIC, yaw NUMERIC, pitch NUMERIC, health NUMERIC);");
|
||||
$this->query("CREATE TABLE tiles (ID INTEGER PRIMARY KEY, level TEXT, class TEXT, x NUMERIC, y NUMERIC, z NUMERIC, spawnable NUMERIC);");
|
||||
$this->query("CREATE TABLE actions (ID INTEGER PRIMARY KEY, interval NUMERIC, last NUMERIC, code TEXT, repeat NUMERIC);");
|
||||
$this->query("CREATE TABLE handlers (ID INTEGER PRIMARY KEY, name TEXT, priority NUMERIC);");
|
||||
$this->query("CREATE TABLE blockUpdates (level TEXT, x INTEGER, y INTEGER, z INTEGER, delay NUMERIC);");
|
||||
//$this->query("PRAGMA synchronous = OFF;");
|
||||
$this->query("CREATE TABLE blockUpdates (level TEXT, x INTEGER, y INTEGER, z INTEGER, type INTEGER, delay NUMERIC);");
|
||||
$this->query("CREATE TABLE recipes (id INTEGER PRIMARY KEY, type NUMERIC, recipe TEXT);");
|
||||
$this->query("PRAGMA synchronous = OFF;");
|
||||
$this->preparedSQL->selectHandlers = $this->database->prepare("SELECT DISTINCT ID FROM handlers WHERE name = :name ORDER BY priority DESC;");
|
||||
$this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);");
|
||||
$this->preparedSQL->updateActions = $this->database->prepare("UPDATE actions SET last = :time WHERE last <= (:time - interval);");
|
||||
$this->preparedSQL->updateAction = $this->database->prepare("UPDATE actions SET last = :time WHERE ID = :id;");
|
||||
$this->preparedSQL->entity->setPosition = $this->database->prepare("UPDATE entities SET x = :x, y = :y, z = :z, pitch = :pitch, yaw = :yaw WHERE EID = :eid ;");
|
||||
$this->preparedSQL->entity->setLevel = $this->database->prepare("UPDATE entities SET level = :level WHERE EID = :eid ;");
|
||||
}
|
||||
|
||||
public function query($sql, $fetch = false){
|
||||
console("[INTERNAL] [SQL] ".$sql, true, true, 3);
|
||||
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0);
|
||||
if($fetch === true and ($result !== false and $result !== true)){
|
||||
if($fetch === true and ($result instanceof SQLite3Result)){
|
||||
$result = $result->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
return $result;
|
||||
@ -145,6 +167,8 @@ class PocketMinecraftServer{
|
||||
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2)."MB";
|
||||
$info["entities"] = $this->query("SELECT count(EID) as count FROM entities;", true);
|
||||
$info["entities"] = $info["entities"]["count"];
|
||||
$info["players"] = $this->query("SELECT count(CID) as count FROM players;", true);
|
||||
$info["players"] = $info["players"]["count"];
|
||||
$info["events"] = count($this->eventsID);
|
||||
$info["handlers"] = $this->query("SELECT count(ID) as count FROM handlers;", true);
|
||||
$info["handlers"] = $info["handlers"]["count"];
|
||||
@ -158,7 +182,7 @@ class PocketMinecraftServer{
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function close($reason = "stop"){
|
||||
public function close($reason = "server stop"){
|
||||
if($this->stop !== true){
|
||||
if(is_int($reason)){
|
||||
$reason = "signal stop";
|
||||
@ -171,6 +195,7 @@ class PocketMinecraftServer{
|
||||
$this->stop = true;
|
||||
$this->trigger("server.close", $reason);
|
||||
$this->interface->close();
|
||||
@$this->asyncThread->stop = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,6 +211,59 @@ class PocketMinecraftServer{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function asyncOperation($type, array $data, callable $callable = null){
|
||||
$d = "";
|
||||
$type = (int) $type;
|
||||
switch($type){
|
||||
case ASYNC_CURL_GET:
|
||||
$d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
|
||||
break;
|
||||
case ASYNC_CURL_POST:
|
||||
$d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
|
||||
$d .= Utils::writeShort(count($data["data"]));
|
||||
foreach($data["data"] as $key => $value){
|
||||
$d .= Utils::writeShort(strlen($key)).$key . Utils::writeInt(strlen($value)).$value;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
$ID = $this->asyncID++;
|
||||
$this->async[$ID] = $callable;
|
||||
$this->asyncThread->input .= Utils::writeInt($ID).Utils::writeShort($type).$d;
|
||||
return $ID;
|
||||
}
|
||||
|
||||
public function asyncOperationChecker(){
|
||||
if(isset($this->asyncThread->output{5})){
|
||||
$offset = 0;
|
||||
$ID = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
|
||||
$offset += 4;
|
||||
$type = Utils::readShort(substr($this->asyncThread->output, $offset, 2));
|
||||
$offset += 2;
|
||||
$data = array();
|
||||
switch($type){
|
||||
case ASYNC_CURL_GET:
|
||||
case ASYNC_CURL_POST:
|
||||
$len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
|
||||
$offset += 4;
|
||||
$data["result"] = substr($this->asyncThread->output, $offset, $len);
|
||||
$offset += $len;
|
||||
break;
|
||||
}
|
||||
$this->asyncThread->output = substr($this->asyncThread->output, $offset);
|
||||
if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){
|
||||
if(is_array($this->async[$ID])){
|
||||
$method = $this->async[$ID][1];
|
||||
$result = $this->async[$ID][0]->$method($data, $type, $ID);
|
||||
}else{
|
||||
$result = $this->async[$ID]($data, $type, $ID);
|
||||
}
|
||||
}
|
||||
unset($this->async[$ID]);
|
||||
}
|
||||
}
|
||||
|
||||
public function addHandler($event,callable $callable, $priority = 5){
|
||||
if(!is_callable($callable)){
|
||||
@ -204,6 +282,10 @@ class PocketMinecraftServer{
|
||||
console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$hnid.")", true, true, 3);
|
||||
return $hnid;
|
||||
}
|
||||
|
||||
public function dhandle($e, $d){
|
||||
return $this->handle($e, $d);
|
||||
}
|
||||
|
||||
public function handle($event, &$data){
|
||||
$this->preparedSQL->selectHandlers->reset();
|
||||
@ -211,7 +293,7 @@ class PocketMinecraftServer{
|
||||
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
|
||||
$handlers = $this->preparedSQL->selectHandlers->execute();
|
||||
$result = null;
|
||||
if($handlers !== false and $handlers !== true){
|
||||
if($handlers instanceof SQLite3Result){
|
||||
$call = array();
|
||||
while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$call[(int) $hn["ID"]] = true;
|
||||
@ -334,7 +416,7 @@ class PocketMinecraftServer{
|
||||
$dump .= "Code: \r\n";
|
||||
$file = @file($er["file"], FILE_IGNORE_NEW_LINES);
|
||||
for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){
|
||||
$dump .= "[".($l + 1)."] ".$file[$l]."\r\n";
|
||||
$dump .= "[".($l + 1)."] ".@$file[$l]."\r\n";
|
||||
}
|
||||
$dump .= "\r\n\r\n";
|
||||
$version = new VersionString();
|
||||
@ -347,7 +429,11 @@ class PocketMinecraftServer{
|
||||
$dump .= "Debug Info: ".var_export($this->debugInfo(false), true)."\r\n\r\n\r\n";
|
||||
global $arguments;
|
||||
$dump .= "Parameters: ".var_export($arguments, true)."\r\n\r\n\r\n";
|
||||
$dump .= "server.properties: ".var_export($this->api->getProperties(), true)."\r\n\r\n\r\n";
|
||||
$p = $this->api->getProperties();
|
||||
if($p["rcon.password"] != ""){
|
||||
$p["rcon.password"] = "******";
|
||||
}
|
||||
$dump .= "server.properties: ".var_export($p, true)."\r\n\r\n\r\n";
|
||||
if($this->api->plugin instanceof PluginAPI){
|
||||
$plist = $this->api->plugin->getList();
|
||||
$dump .= "Loaded plugins:\r\n";
|
||||
@ -356,10 +442,16 @@ class PocketMinecraftServer{
|
||||
}
|
||||
$dump .= "\r\n\r\n";
|
||||
}
|
||||
$dump .= "Loaded Modules: ".var_export(get_loaded_extensions(), true)."\r\n\r\n```";
|
||||
$name = "error_dump_".time();
|
||||
$dump .= "Loaded Modules: ".var_export(get_loaded_extensions(), true)."\r\n";
|
||||
$dump .= "Memory Usage Tracking: \r\n".chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9)))."\r\n";
|
||||
ob_start();
|
||||
phpinfo();
|
||||
$dump .= "\r\nphpinfo(): \r\n".chunk_split(base64_encode(gzdeflate(ob_get_contents(), 9)))."\r\n";
|
||||
ob_end_clean();
|
||||
$dump .= "\r\n```";
|
||||
$name = "Error_Dump_".date("D_M_j-H.i.s-T_Y");
|
||||
logg($dump, $name, true, 0, true);
|
||||
console("[ERROR] Please submit the \"logs/{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
|
||||
console("[ERROR] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
|
||||
}
|
||||
|
||||
public function tick(){
|
||||
@ -369,7 +461,6 @@ class PocketMinecraftServer{
|
||||
unset($this->tickMeasure[key($this->tickMeasure)]);
|
||||
++$this->ticks;
|
||||
$this->tickerFunction($time);
|
||||
$this->trigger("server.tick", $time);
|
||||
}
|
||||
}
|
||||
|
||||
@ -382,12 +473,13 @@ class PocketMinecraftServer{
|
||||
$data =& $packet["data"];
|
||||
$CID = PocketMinecraftServer::clientID($packet["ip"], $packet["port"]);
|
||||
if(isset($this->clients[$CID])){
|
||||
$this->clients[$CID]->handle($packet["pid"], $data);
|
||||
$this->clients[$CID]->handlePacket($packet["pid"], $data);
|
||||
}else{
|
||||
if($this->handle("server.noauthpacket", $packet) === false){
|
||||
return;
|
||||
}
|
||||
switch($packet["pid"]){
|
||||
case 0x01:
|
||||
case 0x02:
|
||||
if($this->invisible === true){
|
||||
$this->send(0x1c, array(
|
||||
@ -441,15 +533,23 @@ class PocketMinecraftServer{
|
||||
$port = $data[2];
|
||||
$MTU = $data[3];
|
||||
$clientID = $data[4];
|
||||
$this->clients[$CID] = new Player($clientID, $packet["ip"], $packet["port"], $MTU); //New Session!
|
||||
$this->clients[$CID]->handle(0x07, $data);
|
||||
if(count($this->clients) < $this->maxClients){
|
||||
$this->clients[$CID] = new Player($clientID, $packet["ip"], $packet["port"], $MTU); //New Session!
|
||||
$this->send(0x08, array(
|
||||
RAKNET_MAGIC,
|
||||
$this->serverID,
|
||||
$this->port,
|
||||
$data[3],
|
||||
0,
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function send($pid, $data = array(), $raw = false, $dest = false, $port = false){
|
||||
$this->interface->writePacket($pid, $data, $raw, $dest, $port);
|
||||
return $this->interface->writePacket($pid, $data, $raw, $dest, $port);
|
||||
}
|
||||
|
||||
public function process(){
|
||||
@ -486,45 +586,44 @@ class PocketMinecraftServer{
|
||||
}
|
||||
}
|
||||
|
||||
public function schedule($ticks,callable $callback, $data = array(), $repeat = false, $eventName = "server.schedule"){
|
||||
public function schedule($ticks, callable $callback, $data = array(), $repeat = false, $eventName = "server.schedule"){
|
||||
if(!is_callable($callback)){
|
||||
return false;
|
||||
}
|
||||
$add = "";
|
||||
$chcnt = $this->scheduleCnt++;
|
||||
if($repeat === false){
|
||||
$add = '$this->schedule['.$chcnt.']=null;unset($this->schedule['.$chcnt.']);';
|
||||
}
|
||||
$this->schedule[$chcnt] = array($callback, $data, $eventName);
|
||||
$this->action(50000 * $ticks, '$schedule=$this->schedule['.$chcnt.'];'.$add.'if(!is_callable($schedule[0])){$this->schedule['.$chcnt.']=null;unset($this->schedule['.$chcnt.']);return false;}return call_user_func($schedule[0],$schedule[1],$schedule[2]);', (bool) $repeat);
|
||||
$this->query("INSERT INTO actions (ID, interval, last, repeat) VALUES(".$chcnt.", ".($ticks / 20).", ".microtime(true).", ".(((bool) $repeat) === true ? 1:0).");");
|
||||
return $chcnt;
|
||||
}
|
||||
|
||||
public function action($microseconds, $code, $repeat = true){
|
||||
$this->query("INSERT INTO actions (interval, last, code, repeat) VALUES(".($microseconds / 1000000).", ".microtime(true).", '".base64_encode($code)."', ".($repeat === true ? 1:0).");");
|
||||
}
|
||||
|
||||
public function tickerFunction($time){
|
||||
//actions that repeat every x time will go here
|
||||
$this->preparedSQL->selectActions->reset();
|
||||
$this->preparedSQL->selectActions->clear();
|
||||
$this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||
$actions = $this->preparedSQL->selectActions->execute();
|
||||
|
||||
if($actions === false or $actions === true){
|
||||
return;
|
||||
}
|
||||
while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$return = eval(base64_decode($action["code"]));
|
||||
if($action["repeat"] === 0 or $return === false){
|
||||
$this->query("DELETE FROM actions WHERE ID = ".$action["ID"].";");
|
||||
if($actions instanceof SQLite3Result){
|
||||
while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$cid = $action["ID"];
|
||||
$this->preparedSQL->updateAction->reset();
|
||||
$this->preparedSQL->updateAction->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||
$this->preparedSQL->updateAction->bindValue(":id", $cid, SQLITE3_INTEGER);
|
||||
$this->preparedSQL->updateAction->execute();
|
||||
$schedule = $this->schedule[$cid];
|
||||
if(!is_callable($schedule[0])){
|
||||
$return = false;
|
||||
}else{
|
||||
$return = call_user_func($schedule[0], $schedule[1], $schedule[2]);
|
||||
}
|
||||
|
||||
if($action["repeat"] === 0 or $return === false){
|
||||
$this->query("DELETE FROM actions WHERE ID = ".$action["ID"].";");
|
||||
$this->schedule[$cid] = null;
|
||||
unset($this->schedule[$cid]);
|
||||
}
|
||||
}
|
||||
$actions->finalize();
|
||||
}
|
||||
$actions->finalize();
|
||||
$this->preparedSQL->updateActions->reset();
|
||||
$this->preparedSQL->updateActions->clear();
|
||||
$this->preparedSQL->updateActions->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||
$this->preparedSQL->updateActions->execute();
|
||||
}
|
||||
|
||||
public function event($event,callable $func){
|
||||
|
@ -1,15 +1,15 @@
|
||||
#!/bin/bash
|
||||
COMPILER_VERSION="0.12"
|
||||
|
||||
PHP_VERSION="5.4.15"
|
||||
PHP_VERSION="5.4.16"
|
||||
ZEND_VM="GOTO"
|
||||
|
||||
LIBEDIT_VERSION="0.3"
|
||||
ZLIB_VERSION="1.2.8"
|
||||
PTHREADS_VERSION="e5d95dfb847c8963c100bd4fb601dde41e0b75d1"
|
||||
PTHREADS_VERSION="0.0.44"
|
||||
CURL_VERSION="curl-7_30_0"
|
||||
|
||||
echo "[PocketMine] PHP installer and compiler for Linux & Mac - v$COMPILER_VERSION"
|
||||
echo "[PocketMine] PHP installer and compiler for Linux & Mac"
|
||||
DIR="$(pwd)"
|
||||
date > "$DIR/install.log" 2>&1
|
||||
uname -a >> "$DIR/install.log" 2>&1
|
||||
@ -18,10 +18,78 @@ type make >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"mak
|
||||
type autoconf >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"autoconf\""; read -p "Press [Enter] to continue..."; exit 1; }
|
||||
type automake >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"automake\""; read -p "Press [Enter] to continue..."; exit 1; }
|
||||
type libtool >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"libtool\""; read -p "Press [Enter] to continue..."; exit 1; }
|
||||
type gcc >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"gcc\""; read -p "Press [Enter] to continue..."; exit 1; }
|
||||
type m4 >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"m4\""; read -p "Press [Enter] to continue..."; exit 1; }
|
||||
type wget >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"wget\""; read -p "Press [Enter] to continue..."; exit 1; }
|
||||
|
||||
export CC="gcc"
|
||||
COMPILE_FOR_ANDROID=no
|
||||
if [ "$1" == "rpi" ]; then
|
||||
[ -z "$march" ] && march=armv6zk;
|
||||
[ -z "$mtune" ] && mtune=arm1176jzf-s;
|
||||
[ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp";
|
||||
echo "[INFO] Compiling for Raspberry Pi ARMv6zk hard float"
|
||||
elif [ "$1" == "mac" ]; then
|
||||
[ -z "$march" ] && march=prescott;
|
||||
[ -z "$mtune" ] && mtune=generic;
|
||||
[ -z "$CFLAGS" ] && CFLAGS="-fomit-frame-pointer";
|
||||
echo "[INFO] Compiling for Intel MacOS"
|
||||
elif [ "$1" == "crosscompile" ]; then
|
||||
if [ "$2" == "android" ] || [ "$2" == "android-armv6" ]; then
|
||||
COMPILE_FOR_ANDROID=yes
|
||||
[ -z "$march" ] && march=armv6;
|
||||
[ -z "$mtune" ] && mtune=generic;
|
||||
TOOLCHAIN_PREFIX="arm-none-linux-gnueabi"
|
||||
export CC="$TOOLCHAIN_PREFIX-gcc"
|
||||
CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX"
|
||||
[ -z "$CFLAGS" ] && CFLAGS="-uclibc";
|
||||
echo "[INFO] Cross-compiling for Android ARMv6"
|
||||
elif [ "$2" == "android-armv7" ]; then
|
||||
COMPILE_FOR_ANDROID=yes
|
||||
[ -z "$march" ] && march=armv7;
|
||||
[ -z "$mtune" ] && mtune=generic;
|
||||
TOOLCHAIN_PREFIX="arm-none-linux-gnueabi"
|
||||
export CC="$TOOLCHAIN_PREFIX-gcc"
|
||||
CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX"
|
||||
[ -z "$CFLAGS" ] && CFLAGS="-uclibc";
|
||||
echo "[INFO] Cross-compiling for Android ARMv7"
|
||||
elif [ "$2" == "rpi" ]; then
|
||||
TOOLCHAIN_PREFIX="arm-linux-gnueabihf"
|
||||
[ -z "$march" ] && march=armv6zk;
|
||||
[ -z "$mtune" ] && mtune=arm1176jzf-s;
|
||||
[ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp";
|
||||
export CC="$TOOLCHAIN_PREFIX-gcc"
|
||||
CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX"
|
||||
[ -z "$CFLAGS" ] && CFLAGS="-uclibc";
|
||||
echo "[INFO] Cross-compiling for Raspberry Pi ARMv6zk hard float"
|
||||
else
|
||||
echo "Please supply a proper platform [android android-armv6 android-armv7 rpi] to cross-compile"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "[INFO] Compiling for current machine"
|
||||
fi
|
||||
|
||||
type $CC >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"$CC\""; read -p "Press [Enter] to continue..."; exit 1; }
|
||||
|
||||
[ -z "$THREADS" ] && THREADS=1;
|
||||
[ -z "$march" ] && march=native;
|
||||
[ -z "$mtune" ] && mtune=native;
|
||||
[ -z "$CFLAGS" ] && CFLAGS="";
|
||||
[ -z "$CONFIGURE_FLAGS" ] && CONFIGURE_FLAGS="";
|
||||
|
||||
$CC -O3 -march=$march -mtune=$mtune -fno-gcse $CFLAGS -Q --help=target >> "$DIR/install.log" 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
$CC -O3 -fno-gcse $CFLAGS -Q --help=target >> "$DIR/install.log" 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
export CFLAGS="-O3 -fno-gcse "
|
||||
else
|
||||
export CFLAGS="-O3 -fno-gcse $CFLAGS"
|
||||
fi
|
||||
else
|
||||
export CFLAGS="-O3 -march=$march -mtune=$mtune -fno-gcse $CFLAGS"
|
||||
fi
|
||||
|
||||
|
||||
rm -r -f install_data/ >> "$DIR/install.log" 2>&1
|
||||
rm -r -f php5/ >> "$DIR/install.log" 2>&1
|
||||
rm -r -f bin/ >> "$DIR/install.log" 2>&1
|
||||
@ -37,25 +105,29 @@ wget http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror -q -O - | tar -
|
||||
mv php-$PHP_VERSION php
|
||||
echo " done!"
|
||||
|
||||
#libedit
|
||||
echo -n "[libedit] downloading $LIBEDIT_VERSION..."
|
||||
wget http://download.sourceforge.net/project/libedit/libedit/libedit-$LIBEDIT_VERSION/libedit-$LIBEDIT_VERSION.tar.gz -q -O - | tar -zx >> "$DIR/install.log" 2>&1
|
||||
echo -n " checking..."
|
||||
cd libedit
|
||||
CFLAGS=-fPIC ./configure --prefix="$DIR/install_data/php/ext/libedit" --enable-static >> "$DIR/install.log" 2>&1
|
||||
echo -n " compiling..."
|
||||
if make >> "$DIR/install.log" 2>&1; then
|
||||
echo -n " installing..."
|
||||
make install >> "$DIR/install.log" 2>&1
|
||||
HAVE_LIBEDIT="--with-libedit=$DIR/install_data/php/ext/libedit"
|
||||
else
|
||||
echo -n " disabling..."
|
||||
if [ 1 ] || [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ]; then
|
||||
HAVE_LIBEDIT="--without-libedit"
|
||||
else
|
||||
#libedit
|
||||
echo -n "[libedit] downloading $LIBEDIT_VERSION..."
|
||||
wget http://download.sourceforge.net/project/libedit/libedit/libedit-$LIBEDIT_VERSION/libedit-$LIBEDIT_VERSION.tar.gz -q -O - | tar -zx >> "$DIR/install.log" 2>&1
|
||||
echo -n " checking..."
|
||||
cd libedit
|
||||
./configure --prefix="$DIR/install_data/php/ext/libedit" --enable-static >> "$DIR/install.log" 2>&1
|
||||
echo -n " compiling..."
|
||||
if make -j $THREADS >> "$DIR/install.log" 2>&1; then
|
||||
echo -n " installing..."
|
||||
make install >> "$DIR/install.log" 2>&1
|
||||
HAVE_LIBEDIT="--with-libedit=\"$DIR/install_data/php/ext/libedit\""
|
||||
else
|
||||
echo -n " disabling..."
|
||||
HAVE_LIBEDIT="--without-libedit"
|
||||
fi
|
||||
echo -n " cleaning..."
|
||||
cd ..
|
||||
rm -r -f ./libedit
|
||||
echo " done!"
|
||||
fi
|
||||
echo -n " cleaning..."
|
||||
cd ..
|
||||
rm -r -f ./libedit
|
||||
echo " done!"
|
||||
|
||||
#zlib
|
||||
echo -n "[zlib] downloading $ZLIB_VERSION..."
|
||||
@ -66,7 +138,7 @@ cd zlib
|
||||
./configure --prefix="$DIR/install_data/php/ext/zlib" \
|
||||
--static >> "$DIR/install.log" 2>&1
|
||||
echo -n " compiling..."
|
||||
make >> "$DIR/install.log" 2>&1
|
||||
make -j $THREADS >> "$DIR/install.log" 2>&1
|
||||
echo -n " installing..."
|
||||
make install >> "$DIR/install.log" 2>&1
|
||||
echo -n " cleaning..."
|
||||
@ -74,27 +146,46 @@ cd ..
|
||||
rm -r -f ./zlib
|
||||
echo " done!"
|
||||
|
||||
#curl
|
||||
echo -n "[cURL] downloading $CURL_VERSION..."
|
||||
wget https://github.com/bagder/curl/archive/$CURL_VERSION.tar.gz --no-check-certificate -q -O - | tar -zx >> "$DIR/install.log" 2>&1
|
||||
mv curl-$CURL_VERSION curl
|
||||
echo -n " checking..."
|
||||
cd curl
|
||||
./buildconf >> "$DIR/install.log" 2>&1
|
||||
./configure --prefix="$DIR/install_data/php/ext/curl" \
|
||||
--disable-shared >> "$DIR/install.log" 2>&1
|
||||
echo -n " compiling..."
|
||||
make >> "$DIR/install.log" 2>&1
|
||||
echo -n " installing..."
|
||||
make install >> "$DIR/install.log" 2>&1
|
||||
echo -n " cleaning..."
|
||||
cd ..
|
||||
rm -r -f ./curl
|
||||
echo " done!"
|
||||
if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ] && [ "$2" != "curl" ]; then
|
||||
HAVE_CURL="shared,/usr/local"
|
||||
else
|
||||
#curl
|
||||
echo -n "[cURL] downloading $CURL_VERSION..."
|
||||
wget https://github.com/bagder/curl/archive/$CURL_VERSION.tar.gz --no-check-certificate -q -O - | tar -zx >> "$DIR/install.log" 2>&1
|
||||
mv curl-$CURL_VERSION curl
|
||||
echo -n " checking..."
|
||||
cd curl
|
||||
./buildconf >> "$DIR/install.log" 2>&1
|
||||
./configure --enable-ipv6 \
|
||||
--enable-optimize \
|
||||
--enable-http \
|
||||
--enable-ftp \
|
||||
--disable-dict \
|
||||
--enable-file \
|
||||
--disable-gopher \
|
||||
--disable-imap \
|
||||
--disable-pop3 \
|
||||
--disable-rtsp \
|
||||
--disable-smtp \
|
||||
--disable-telnet \
|
||||
--disable-tftp \
|
||||
--prefix="$DIR/install_data/php/ext/curl" \
|
||||
--disable-shared \
|
||||
$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1
|
||||
echo -n " compiling..."
|
||||
make -j $THREADS >> "$DIR/install.log" 2>&1
|
||||
echo -n " installing..."
|
||||
make install >> "$DIR/install.log" 2>&1
|
||||
echo -n " cleaning..."
|
||||
cd ..
|
||||
rm -r -f ./curl
|
||||
echo " done!"
|
||||
HAVE_CURL="$DIR/install_data/php/ext/curl"
|
||||
fi
|
||||
|
||||
#pthreads
|
||||
echo -n "[PHP pthreads] downloading $PTHREADS_VERSION..."
|
||||
wget https://github.com/krakjoe/pthreads/archive/$PTHREADS_VERSION.tar.gz --no-check-certificate -q -O - | tar -zx >> "$DIR/install.log" 2>&1
|
||||
wget http://pecl.php.net/get/pthreads-$PTHREADS_VERSION.tgz --no-check-certificate -q -O - | tar -zx >> "$DIR/install.log" 2>&1
|
||||
mv pthreads-$PTHREADS_VERSION "$DIR/install_data/php/ext/pthreads"
|
||||
echo " done!"
|
||||
|
||||
@ -106,12 +197,11 @@ if which free >/dev/null; then
|
||||
else
|
||||
MAX_MEMORY=$(top -l 1 | grep PhysMem: | awk '{print $10}' | tr -d 'a-zA-Z')
|
||||
fi
|
||||
if [ $MAX_MEMORY -gt 512 ]
|
||||
then
|
||||
echo -n " enabling optimizations..."
|
||||
OPTIMIZATION="--enable-inline-optimization "
|
||||
if [ $MAX_MEMORY -gt 512 ] && [ "$1" != "crosscompile" ]; then
|
||||
echo -n " enabling optimizations..."
|
||||
OPTIMIZATION="--enable-inline-optimization "
|
||||
else
|
||||
OPTIMIZATION="--disable-inline-optimization "
|
||||
OPTIMIZATION="--disable-inline-optimization "
|
||||
fi
|
||||
set -e
|
||||
echo -n " checking..."
|
||||
@ -120,11 +210,15 @@ rm -rf ./aclocal.m4 >> "$DIR/install.log" 2>&1
|
||||
rm -rf ./autom4te.cache/ >> "$DIR/install.log" 2>&1
|
||||
rm -f ./configure >> "$DIR/install.log" 2>&1
|
||||
./buildconf --force >> "$DIR/install.log" 2>&1
|
||||
if [ "$1" == "crosscompile" ]; then
|
||||
sed -i 's/pthreads_working=no/pthreads_working=yes/' ./configure
|
||||
export LIBS="-lpthread -ldl"
|
||||
fi
|
||||
./configure $OPTIMIZATION--prefix="$DIR/php5" \
|
||||
--exec-prefix="$DIR/php5" \
|
||||
--with-curl="$DIR/install_data/php/ext/curl" \
|
||||
--with-curl="$HAVE_CURL" \
|
||||
--with-zlib="$DIR/install_data/php/ext/zlib" \
|
||||
"$HAVE_LIBEDIT" \
|
||||
$HAVE_LIBEDIT \
|
||||
--disable-libxml \
|
||||
--disable-xml \
|
||||
--disable-dom \
|
||||
@ -150,11 +244,15 @@ rm -f ./configure >> "$DIR/install.log" 2>&1
|
||||
--enable-cli \
|
||||
--without-pear \
|
||||
--without-iconv \
|
||||
--without-pdo \
|
||||
--disable-pdo \
|
||||
--without-pdo-sqlite \
|
||||
--with-zend-vm=$ZEND_VM >> "$DIR/install.log" 2>&1
|
||||
--with-zend-vm=$ZEND_VM \
|
||||
$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1
|
||||
echo -n " compiling..."
|
||||
make >> "$DIR/install.log" 2>&1
|
||||
if [ COMPILE_FOR_ANDROID == "yes" ]; then
|
||||
sed -i 's/-export-dynamic/-all-static/g' Makefile
|
||||
fi
|
||||
make -j $THREADS >> "$DIR/install.log" 2>&1
|
||||
echo -n " installing..."
|
||||
make install >> "$DIR/install.log" 2>&1
|
||||
echo " done!"
|
||||
@ -162,7 +260,7 @@ cd "$DIR"
|
||||
echo -n "[INFO] Cleaning up..."
|
||||
rm -r -f install_data/ >> "$DIR/install.log" 2>&1
|
||||
mv php5/bin/php bin/php
|
||||
rm -r -f php/ >> "$DIR/install.log" 2>&1
|
||||
rm -r -f php5/ >> "$DIR/install.log" 2>&1
|
||||
date >> "$DIR/install.log" 2>&1
|
||||
echo " done!"
|
||||
echo "[PocketMine] You should start the server now using \"./start.sh\""
|
||||
|
@ -26,13 +26,35 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
*/
|
||||
|
||||
set_time_limit(0);
|
||||
date_default_timezone_set(@date_default_timezone_get());
|
||||
|
||||
date_default_timezone_set("GMT");
|
||||
if(strpos(" ".strtoupper(php_uname("s")), " WIN") !== false){
|
||||
$time = time();
|
||||
$time -= $time % 60;
|
||||
exec("time.exe /T", $hour);
|
||||
$i = array_map("intval", explode(":", trim($hour[0])));
|
||||
exec("date.exe /T", $date);
|
||||
$j = array_map("intval", explode("/", trim($date[0])));
|
||||
$offset = round((mktime($i[0], $i[1], 0, $j[1], $j[0], $j[2]) - $time) / 60) * 60;
|
||||
}else{
|
||||
exec("date +%s", $t);
|
||||
$offset = round((intval(trim($t[0])) - time()) / 60) * 60;
|
||||
}
|
||||
|
||||
$daylight = (int) date("I");
|
||||
|
||||
if($daylight === 0){
|
||||
$offset -= 3600;
|
||||
}
|
||||
|
||||
date_default_timezone_set(timezone_name_from_abbr("", $offset, $daylight));
|
||||
|
||||
gc_enable();
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
ini_set("allow_url_fopen", 1);
|
||||
ini_set("display_errors", 1);
|
||||
ini_set("display_startup_errors", 1);
|
||||
ini_set('default_charset', 'utf-8');
|
||||
ini_set("default_charset", "utf-8");
|
||||
if(defined("POCKETMINE_COMPILE") and POCKETMINE_COMPILE === true){
|
||||
define("FILE_PATH", realpath(dirname(__FILE__))."/");
|
||||
}else{
|
||||
@ -43,11 +65,9 @@ set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH);
|
||||
ini_set("memory_limit", "128M"); //Default
|
||||
define("LOG", true);
|
||||
define("START_TIME", microtime(true));
|
||||
define("MAJOR_VERSION", "Alpha_1.3");
|
||||
define("CURRENT_STRUCTURE", 5);
|
||||
define("CURRENT_PROTOCOL", 9);
|
||||
define("CURRENT_MINECRAFT_VERSION", "0.6.1 alpha");
|
||||
define("CURRENT_API_VERSION", 7);
|
||||
define("MAJOR_VERSION", "Alpha_1.3.5");
|
||||
define("CURRENT_MINECRAFT_VERSION", "0.7.3 alpha");
|
||||
define("CURRENT_API_VERSION", 9);
|
||||
define("CURRENT_PHP_VERSION", "5.5");
|
||||
$gitsha1 = false;
|
||||
if(file_exists(FILE_PATH.".git/refs/heads/master")){ //Found Git information!
|
||||
|
@ -150,6 +150,7 @@ define("BRICK_STAIRS", 108);
|
||||
define("STONE_BRICK_STAIRS", 109);
|
||||
|
||||
define("NETHER_BRICKS", 112);
|
||||
define("NETHER_BRICK_BLOCK", 112);
|
||||
|
||||
define("NETHER_BRICKS_STAIRS", 114);
|
||||
|
||||
|
@ -25,6 +25,9 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
|
||||
define("PMF_LEVEL_DEFLATE_LEVEL", 6);
|
||||
|
||||
//Gamemodes
|
||||
define("SURVIVAL", 0);
|
||||
define("CREATIVE", 1);
|
||||
@ -34,13 +37,25 @@ define("VIEWER", 3);
|
||||
|
||||
|
||||
//Players
|
||||
define("PLAYER_RECOVERY_BUFFER", 2048);
|
||||
define("MAX_CHUNK_RATE", 20 / arg("max-chunks-per-second", 3.5)); //Default rate ~172 kB/s
|
||||
define("PLAYER_MAX_QUEUE", 1024);
|
||||
|
||||
define("PLAYER_SURVIVAL_SLOTS", 36);
|
||||
define("PLAYER_CREATIVE_SLOTS", 111);
|
||||
|
||||
|
||||
//Block Updates
|
||||
define("BLOCK_UPDATE_NORMAL", 1);
|
||||
define("BLOCK_UPDATE_RANDOM", 2);
|
||||
define("BLOCK_UPDATE_SCHEDULED", 3);
|
||||
define("BLOCK_UPDATE_WEAK", 4);
|
||||
define("BLOCK_UPDATE_TOUCH", 5);
|
||||
|
||||
|
||||
//Entities
|
||||
define("ENTITY_PLAYER", 0);
|
||||
define("ENTITY_PLAYER", 1);
|
||||
|
||||
define("ENTITY_MOB", 1);
|
||||
define("ENTITY_MOB", 2);
|
||||
define("MOB_CHICKEN", 10);
|
||||
define("MOB_COW", 11);
|
||||
define("MOB_PIG", 12);
|
||||
@ -52,10 +67,14 @@ define("ENTITY_MOB", 1);
|
||||
define("MOB_SPIDER", 35);
|
||||
define("MOB_PIGMAN", 36);
|
||||
|
||||
define("ENTITY_OBJECT", 2);
|
||||
define("ENTITY_OBJECT", 3);
|
||||
define("OBJECT_ARROW", 80);
|
||||
define("OBJECT_PAINTING", 83);
|
||||
|
||||
define("ENTITY_ITEM", 3);
|
||||
define("ENTITY_ITEM", 4);
|
||||
|
||||
define("ENTITY_FALLING", 5);
|
||||
define("FALLING_SAND", 66);
|
||||
|
||||
|
||||
//TileEntities
|
||||
|
@ -29,6 +29,7 @@ define("IRON_SHOVEL", 256);//Implemented
|
||||
define("IRON_PICKAXE", 257);//Implemented
|
||||
define("IRON_AXE", 258);//Implemented
|
||||
define("FLINT_STEEL", 259);
|
||||
define("FLINT_AND_STEEL", 259);
|
||||
define("APPLE", 260);//Implemented
|
||||
define("BOW", 261);
|
||||
define("ARROW", 262);
|
||||
@ -50,12 +51,17 @@ define("DIAMOND_SHOVEL", 277);
|
||||
define("DIAMOND_PICKAXE", 278);
|
||||
define("DIAMOND_AXE", 279);
|
||||
define("STICK", 280);//Implemented
|
||||
define("STICKS", 280);
|
||||
define("BOWL", 281);//Implemented
|
||||
define("MUSHROOM_STEW", 282);
|
||||
define("GOLD_SWORD", 283);
|
||||
define("GOLD_SHOVEL", 284);
|
||||
define("GOLD_PICKAXE", 285);
|
||||
define("GOLD_AXE", 286);
|
||||
define("GOLDEN_SWORD", 283);
|
||||
define("GOLDEN_SHOVEL", 284);
|
||||
define("GOLDEN_PICKAXE", 285);
|
||||
define("GOLDEN_AXE", 286);
|
||||
define("STRING", 287);
|
||||
define("FEATHER", 288);//Implemented
|
||||
define("GUNPOWDER", 289);
|
||||
@ -64,6 +70,7 @@ define("STONE_HOE", 291);
|
||||
define("IRON_HOE", 292);//Implemented
|
||||
define("DIAMOND_HOE", 293);
|
||||
define("GOLD_HOE", 294);
|
||||
define("GOLDEN_HOE", 294);
|
||||
define("SEEDS", 295);
|
||||
define("WHEAT_SEEDS", 295);
|
||||
define("WHEAT", 296);
|
||||
@ -74,19 +81,19 @@ define("LEATHER_PANTS", 300);
|
||||
define("LEATHER_BOOTS", 301);
|
||||
define("CHAIN_HELMET", 302);
|
||||
define("CHAIN_CHESTPLATE", 303);
|
||||
define("CHAIN_LEGGINS", 304);
|
||||
define("CHAIN_LEGGINGS", 304);
|
||||
define("CHAIN_BOOTS", 305);
|
||||
define("IRON_HELMET", 306);
|
||||
define("IRON_CHESTPLATE", 307);
|
||||
define("IRON_LEGGINS", 308);
|
||||
define("IRON_LEGGINGS", 308);
|
||||
define("IRON_BOOTS", 309);
|
||||
define("DIAMOND_HELMET", 310);
|
||||
define("DIAMOND_CHESTPLATE", 311);
|
||||
define("DIAMOND_LEGGINS", 312);
|
||||
define("DIAMOND_LEGGINGS", 312);
|
||||
define("DIAMOND_BOOTS", 313);
|
||||
define("GOLD_HELMET", 314);
|
||||
define("GOLD_CHESTPLATE", 315);
|
||||
define("GOLD_LEGGINS", 316);
|
||||
define("GOLD_LEGGINGS", 316);
|
||||
define("GOLD_BOOTS", 317);
|
||||
define("FLINT", 318);
|
||||
define("RAW_PORKCHOP", 319);
|
||||
@ -96,8 +103,6 @@ define("GOLDEN_APPLE", 322);
|
||||
define("SIGN", 323);
|
||||
define("WOODEN_DOOR", 324);
|
||||
define("BUCKET", 325);
|
||||
define("WATER_BUCKET", 326);
|
||||
define("LAVA_BUCKET", 327);
|
||||
|
||||
|
||||
define("IRON_DOOR", 330);
|
||||
@ -142,6 +147,8 @@ define("COOKED_BEEF", 364);
|
||||
define("RAW_CHICKEN", 365);
|
||||
define("COOKED_CHICKEN", 366);
|
||||
|
||||
define("SPAWN_EGG", 383);
|
||||
|
||||
define("NETHER_BRICK", 405);
|
||||
define("QUARTZ", 406);
|
||||
define("NETHER_QUARTZ", 406);
|
||||
|
@ -36,6 +36,10 @@ if(!function_exists("cli_set_process_title")){
|
||||
}
|
||||
}
|
||||
|
||||
function dummy(){
|
||||
|
||||
}
|
||||
|
||||
function safe_var_dump($var, $cnt = 0){
|
||||
switch(true){
|
||||
case is_array($var):
|
||||
@ -73,16 +77,12 @@ function safe_var_dump($var, $cnt = 0){
|
||||
function kill($pid){
|
||||
switch(Utils::getOS()){
|
||||
case "win":
|
||||
ob_start();
|
||||
passthru("%WINDIR%\\System32\\taskkill.exe /F /PID ".((int) $pid)." > NUL");
|
||||
ob_end_clean();
|
||||
exec("taskkill.exe /F /PID ".((int) $pid)." > NUL");
|
||||
break;
|
||||
case "mac":
|
||||
case "linux":
|
||||
default:
|
||||
ob_start();
|
||||
passthru("kill -9 ".((int) $pid)." > /dev/null 2>&1");
|
||||
ob_end_clean();
|
||||
exec("kill -9 ".((int) $pid)." > /dev/null 2>&1");
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,7 +266,7 @@ function logg($message, $name, $EOL = true, $level = 2, $close = false){
|
||||
$fpointers = array();
|
||||
}
|
||||
if(!isset($fpointers[$name]) or $fpointers[$name] === false){
|
||||
$fpointers[$name] = @fopen(DATA_PATH."logs/".$name.".log", "ab");
|
||||
$fpointers[$name] = @fopen(DATA_PATH."/".$name.".log", "ab");
|
||||
}
|
||||
@fwrite($fpointers[$name], $message);
|
||||
if($close === true){
|
||||
|
@ -140,12 +140,14 @@ abstract class Block extends Position{
|
||||
public $isActivable = false;
|
||||
public $breakable = true;
|
||||
public $isFlowable = false;
|
||||
public $isSolid = true;
|
||||
public $isTransparent = false;
|
||||
public $isReplaceable = false;
|
||||
public $isPlaceable = true;
|
||||
public $level = false;
|
||||
public $hasPhysics = false;
|
||||
public $isLiquid = false;
|
||||
public $isFullBlock = true;
|
||||
public $x = 0;
|
||||
public $y = 0;
|
||||
public $z = 0;
|
||||
@ -154,7 +156,7 @@ abstract class Block extends Position{
|
||||
$this->id = (int) $id;
|
||||
$this->meta = (int) $meta;
|
||||
$this->name = $name;
|
||||
$this->breakTime = 0.25;
|
||||
$this->breakTime = 0.20;
|
||||
}
|
||||
|
||||
final public function getName(){
|
||||
@ -188,7 +190,7 @@ abstract class Block extends Position{
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
return 0.15;
|
||||
}
|
||||
return $this->breakTime;
|
||||
}
|
||||
|
@ -33,14 +33,13 @@ class Item{
|
||||
SIGN => "SignItem",
|
||||
WOODEN_DOOR => "WoodenDoorItem",
|
||||
BUCKET => "BucketItem",
|
||||
WATER_BUCKET => "WaterBucketItem",
|
||||
LAVA_BUCKET => "LavaBucketItem",
|
||||
IRON_DOOR => "IronDoorItem",
|
||||
CAKE => "CakeItem",
|
||||
BED => "BedItem",
|
||||
PAINTING => "PaintingItem",
|
||||
COAL => "CoalItem",
|
||||
APPLE => "AppleItem",
|
||||
SPAWN_EGG => "SpawnEggItem",
|
||||
DIAMOND => "DiamondItem",
|
||||
STICK => "StickItem",
|
||||
BOWL => "BowlItem",
|
||||
@ -56,6 +55,7 @@ class Item{
|
||||
WOODEN_SHOVEL => "WoodenShovelItem",
|
||||
WOODEN_PICKAXE => "WoodenPickaxeItem",
|
||||
WOODEN_AXE => "WoodenAxeItem",
|
||||
FLINT_STEEL => "FlintSteelItem",
|
||||
);
|
||||
protected $block;
|
||||
protected $id;
|
||||
@ -75,6 +75,9 @@ class Item{
|
||||
$this->block = BlockAPI::get($this->id, $this->meta);
|
||||
$this->name = $this->block->getName();
|
||||
}
|
||||
if($this->isTool() !== false){
|
||||
$this->maxStackSize = 1;
|
||||
}
|
||||
}
|
||||
|
||||
final public function getName(){
|
||||
@ -109,7 +112,10 @@ class Item{
|
||||
if(!isset(FuelData::$duration[$this->id])){
|
||||
return false;
|
||||
}
|
||||
return FuelData::$duration[$this->id];
|
||||
if($this->id !== BUCKET or $this->meta === 10){
|
||||
return FuelData::$duration[$this->id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
final public function getSmeltItem(){
|
||||
@ -129,6 +135,52 @@ class Item{
|
||||
|
||||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if($this->isTool() or $force === true){
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
final public function isTool(){
|
||||
return ($this->id === FLINT_STEEL or $this->id === SHEARS or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false);
|
||||
}
|
||||
|
||||
final public function getMaxDurability(){
|
||||
if(!$this->isTool() and $this->isHoe() === false and $this->id !== BOW){
|
||||
return false;
|
||||
}
|
||||
|
||||
$levels = array(
|
||||
2 => 33,
|
||||
1 => 60,
|
||||
3 => 132,
|
||||
4 => 251,
|
||||
5 => 1562,
|
||||
FLINT_STEEL => 65,
|
||||
SHEARS => 239,
|
||||
BOW => 385,
|
||||
);
|
||||
|
||||
if(($type = $this->isPickaxe()) === false){
|
||||
if(($type = $this->isAxe()) === false){
|
||||
if(($type = $this->isSword()) === false){
|
||||
if(($type = $this->isShovel()) === false){
|
||||
if(($type = $this->isHoe()) === false){
|
||||
$type = $this->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $levels[$type];
|
||||
}
|
||||
|
||||
final public function isPickaxe(){ //Returns false or level of the pickaxe
|
||||
switch($this->id){
|
||||
case IRON_PICKAXE:
|
||||
@ -146,6 +198,57 @@ class Item{
|
||||
}
|
||||
}
|
||||
|
||||
final public function isAxe(){
|
||||
switch($this->id){
|
||||
case IRON_AXE:
|
||||
return 4;
|
||||
case WOODEN_AXE:
|
||||
return 1;
|
||||
case STONE_AXE:
|
||||
return 3;
|
||||
case DIAMOND_AXE:
|
||||
return 5;
|
||||
case GOLD_AXE:
|
||||
return 2;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final public function isSword(){
|
||||
switch($this->id){
|
||||
case IRON_SWORD:
|
||||
return 4;
|
||||
case WOODEN_SWORD:
|
||||
return 1;
|
||||
case STONE_SWORD:
|
||||
return 3;
|
||||
case DIAMOND_SWORD:
|
||||
return 5;
|
||||
case GOLD_SWORD:
|
||||
return 2;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final public function isShovel(){
|
||||
switch($this->id){
|
||||
case IRON_SHOVEL:
|
||||
return 4;
|
||||
case WOODEN_SHOVEL:
|
||||
return 1;
|
||||
case STONE_SHOVEL:
|
||||
return 3;
|
||||
case DIAMOND_SHOVEL:
|
||||
return 5;
|
||||
case GOLD_SHOVEL:
|
||||
return 2;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isHoe(){
|
||||
switch($this->id){
|
||||
case IRON_HOE:
|
||||
|
@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class DoorBlock extends TransparentBlock{
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isSolid = false;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
|
@ -25,9 +25,15 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class FallableBlock extends GenericBlock{
|
||||
class FallableBlock extends SolidBlock{
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->hasPhysics = true;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL);
|
||||
return $ret;
|
||||
}
|
||||
}
|
@ -29,5 +29,7 @@ class FlowableBlock extends TransparentBlock{
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isFlowable = true;
|
||||
$this->isFullBlock = false;
|
||||
$this->isSolid = false;
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ class GenericBlock extends Block{
|
||||
parent::__construct($id, $meta, $name);
|
||||
}
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
return $this->level->setBlock($block, $this);
|
||||
return $this->level->setBlock($this, $this, true, false, true);
|
||||
}
|
||||
|
||||
public function isBreakable(Item $item, Player $player){
|
||||
@ -39,14 +39,31 @@ class GenericBlock extends Block{
|
||||
}
|
||||
|
||||
public function onBreak(Item $item, Player $player){
|
||||
return $this->level->setBlock($this, new AirBlock());
|
||||
return $this->level->setBlock($this, new AirBlock(), true, false, true);
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === AIR or ($down instanceof LiquidBlock)){
|
||||
$data = array(
|
||||
"x" => $this->x + 0.5,
|
||||
"y" => $this->y + 0.5,
|
||||
"z" => $this->z + 0.5,
|
||||
"Tile" => $this->id,
|
||||
);
|
||||
$server = ServerAPI::request();
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
$server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
return ($this->isActivable);
|
||||
return $this->isActivable;
|
||||
}
|
||||
}
|
@ -31,5 +31,7 @@ class LiquidBlock extends TransparentBlock{
|
||||
$this->isLiquid = true;
|
||||
$this->breakable = false;
|
||||
$this->isReplaceable = true;
|
||||
$this->isSolid = false;
|
||||
$this->isFullBlock = true;
|
||||
}
|
||||
}
|
@ -28,5 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class SolidBlock extends GenericBlock{
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isSolid = true;
|
||||
$this->isFullBlock = true;
|
||||
}
|
||||
}
|
@ -28,6 +28,11 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class StairBlock extends TransparentBlock{
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
|
@ -33,6 +33,7 @@ class TransparentBlock extends GenericBlock{
|
||||
$this->isFlowable = false;
|
||||
$this->isTransparent = true;
|
||||
$this->isReplaceable = false;
|
||||
$this->isPlaceable = true;
|
||||
$this->isPlaceable = true;
|
||||
$this->isSolid = true;
|
||||
}
|
||||
}
|
@ -28,6 +28,8 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class LadderBlock extends TransparentBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(LADDER, $meta, "Ladder");
|
||||
$this->isSolid = false;
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($target->isTransparent === false){
|
||||
@ -37,9 +39,11 @@ class LadderBlock extends TransparentBlock{
|
||||
4 => 4,
|
||||
5 => 5,
|
||||
);
|
||||
$this->meta = $faces[$face];
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
if(isset($faces[$face])){
|
||||
$this->meta = $faces[$face];
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class SignPostBlock extends TransparentBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(SIGN_POST, $meta, "Sign Post");
|
||||
$this->isSolid = false;
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
@ -51,6 +53,17 @@ class SignPostBlock extends TransparentBlock{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->getID() === AIR){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SIGN, 0, 1));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onBreak(Item $item, Player $player){
|
||||
$this->level->setBlock($this, new AirBlock(), true, true);
|
||||
return true;
|
||||
|
@ -43,8 +43,8 @@ class TorchBlock extends FlowableBlock{
|
||||
0 => 0,
|
||||
);
|
||||
|
||||
if($this->getSide($faces[$side])->isTransparent === true){ //Replace wit hcommon break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
@ -64,7 +64,7 @@ class TorchBlock extends FlowableBlock{
|
||||
$this->meta = $faces[$face];
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
}elseif($this->getSide(0)->isTransparent === false){
|
||||
}elseif($this->getSide(0)->isTransparent === false or $this->getSide(0)->getID() === FENCE){
|
||||
$this->meta = 0;
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
|
@ -29,6 +29,11 @@ class TrapdoorBlock extends TransparentBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(TRAPDOOR, $meta, "Trapdoor");
|
||||
$this->isActivable = true;
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = false;
|
||||
}else{
|
||||
$this->isFullBlock = true;
|
||||
}
|
||||
}
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if(($target->isTransparent === false or $target->getID() === SLAB) and $face !== 0 and $face !== 1){
|
||||
|
@ -33,5 +33,8 @@ class WallSignBlock extends SignPostBlock{
|
||||
public function __construct($meta = 0){
|
||||
TransparentBlock::__construct(WALL_SIGN, $meta, "Wall Sign");
|
||||
}
|
||||
|
||||
|
||||
public function onUpdate($type){
|
||||
return false;
|
||||
}
|
||||
}
|
@ -28,28 +28,90 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class WaterBlock extends LiquidBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(WATER, $meta, "Water");
|
||||
}
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
return false;
|
||||
$level = $this->meta & 0x03;
|
||||
if($type !== BLOCK_UPDATE_NORMAL or $level === 0){
|
||||
$newId = $this->id;
|
||||
$level = $this->meta & 0x07;
|
||||
if($type !== BLOCK_UPDATE_NORMAL){
|
||||
return false;
|
||||
}
|
||||
|
||||
$falling = $this->meta >> 3;
|
||||
$down = $this->getSide(0);
|
||||
|
||||
if($falling === 0){
|
||||
$countSources = 0;
|
||||
$maxLevel = $level;
|
||||
$hasPath = false;
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b->isFlowable === true and $level < 0x07){
|
||||
$d = $b->getSide(0);
|
||||
$this->level->setBlock($b, new WaterBlock($level + 1), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
|
||||
}elseif($b instanceof WaterBlock){
|
||||
$oLevel = $b->getMetadata();
|
||||
$oFalling = $oLevel >> 3;
|
||||
$oLevel &= 0x07;
|
||||
if($oFalling === 0){
|
||||
if($oLevel === 0){
|
||||
++$countSources;
|
||||
$maxLevel = 1;
|
||||
$hasPath = true;
|
||||
}elseif($oLevel < 0x07 and ($oLevel + 1) <= $maxLevel){
|
||||
$maxLevel = $oLevel + 1;
|
||||
$hasPath = true;
|
||||
}elseif(($level + 1) < $oLevel){
|
||||
$this->level->setBlock($b, new WaterBlock($level + 1), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
|
||||
}elseif($level === $oLevel){
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($countSources >= 2){
|
||||
$level = 0; //Source block
|
||||
}elseif($maxLevel < $level){
|
||||
$level = $maxLevel;
|
||||
}elseif($maxLevel === $level and $level > 0 and $hasPath === false){
|
||||
if($level < 0x07){
|
||||
++$level;
|
||||
}else{
|
||||
$newId = AIR;
|
||||
$level = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($down->isFlowable){
|
||||
$this->level->setBlock($down, new WaterBlock(9), true); //1001
|
||||
return;
|
||||
}elseif($down instanceof WaterBlock and $down->getMetadata() === 9){
|
||||
$level = 1;
|
||||
$this->level->setBlock($down, new WaterBlock(0b1001), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
return false;
|
||||
}elseif($down instanceof LiquidBlock){
|
||||
if($down instanceof WaterBlock and ($down->getMetadata() >> 3) === 0){
|
||||
$this->level->setBlock($down, new WaterBlock(0b1000 & min($down->getMetadata(), 1)), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}else{
|
||||
$falling = 0;
|
||||
}
|
||||
|
||||
$up = $this->getSide(1);
|
||||
if($up instanceof WaterBlock){
|
||||
|
||||
$newMeta = ($falling << 0x03) | $level;
|
||||
if($newMeta !== $this->meta or $newId !== $this->id){
|
||||
$this->id = $newId;
|
||||
$this->meta = $newMeta;
|
||||
$this->level->setBlock($this, $this, false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -35,6 +35,9 @@ class AirBlock extends TransparentBlock{
|
||||
$this->isReplaceable = true;
|
||||
$this->isPlaceable = false;
|
||||
$this->hasPhysics = false;
|
||||
$this->isSolid = false;
|
||||
$this->isFullBlock = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -29,6 +29,7 @@ class BedBlock extends TransparentBlock{
|
||||
public function __construct($type = 0){
|
||||
parent::__construct(BED_BLOCK, $type, "Bed Block");
|
||||
$this->isActivable = true;
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
|
@ -30,6 +30,30 @@ class FireBlock extends FlowableBlock{
|
||||
parent::__construct(FIRE, $meta, "Fire");
|
||||
$this->isReplaceable = true;
|
||||
$this->breakable = false;
|
||||
$this->isFullBlock = true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
for($s = 0; $s <= 5; ++$s){
|
||||
$side = $this->getSide($s);
|
||||
if($side->getID() !== AIR and !($side instanceof LiquidBlock)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== NETHERRACK){
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
54
src/material/block/nonfull/Cake.php
Normal file
54
src/material/block/nonfull/Cake.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class CakeBlock extends TransparentBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(CAKE_BLOCK, 0, "Cake Block");
|
||||
$this->isFullBlock = false;
|
||||
$this->isActivable = true;
|
||||
$this->meta = $meta & 0x07;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($player->entity->getHealth() < 20){
|
||||
++$this->meta;
|
||||
$player->entity->heal(3, "cake");
|
||||
if($this->meta >= 0x06){
|
||||
$this->level->setBlock($this, new AirBlock());
|
||||
}else{
|
||||
$this->level->setBlock($this, $this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -25,9 +25,11 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class CobwebBlock extends TransparentBlock{
|
||||
class CobwebBlock extends FlowableBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(COBWEB, 0, "Cobweb");
|
||||
parent::__construct(COBWEB, 0, "Cobweb");
|
||||
$this->isSolid = true;
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class FenceBlock extends TransparentBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(FENCE, 0, "Fence");
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
|
||||
}
|
@ -29,6 +29,11 @@ class FenceGateBlock extends TransparentBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(FENCE_GATE, $meta, "Fence Gate");
|
||||
$this->isActivable = true;
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
}
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
@ -35,10 +35,15 @@ class SlabBlock extends TransparentBlock{
|
||||
3 => "Cobblestone",
|
||||
4 => "Brick",
|
||||
5 => "Stone Brick",
|
||||
6 => "Nether Brick",
|
||||
7 => "Quartz",
|
||||
//6 => "Nether Brick",
|
||||
6 => "Quartz",
|
||||
);
|
||||
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab";
|
||||
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab";
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
53
src/material/block/nonfull/SnowLayer.php
Normal file
53
src/material/block/nonfull/SnowLayer.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class SnowLayerBlock extends FlowableBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(SNOW_LAYER, $meta, "Snow Layer");
|
||||
$this->isReplaceable = true;
|
||||
$this->isSolid = false;
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->getID() === AIR){ //Replace wit common break method
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isShovel() !== false){
|
||||
return array(
|
||||
array(SNOWBALL, 0, 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -35,7 +35,7 @@ class GlowingRedstoneOreBlock extends SolidBlock{
|
||||
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false);
|
||||
return BLOCK_UPDATE_WEAK;
|
||||
}else{
|
||||
$this->level->scheduleBlockUpdate($this, mt_rand(45, 100));
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class RedstoneOreBlock extends SolidBlock{
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){
|
||||
$this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false);
|
||||
$this->level->scheduleBlockUpdate($this, mt_rand(45, 100));
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return BLOCK_UPDATE_WEAK;
|
||||
}
|
||||
return false;
|
||||
|
@ -28,13 +28,23 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class BrownMushroomBlock extends FlowableBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(BROWN_MUSHROOM, 0, "Brown Mushroom");
|
||||
$this->isFlowable = true;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === false){
|
||||
$this->level->setBlock($block, $this->id, $this->getMetadata());
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -26,23 +26,60 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
*/
|
||||
|
||||
class CactusBlock extends TransparentBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(CACTUS, 0, "Cactus");
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(CACTUS, $meta, "Cactus");
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === SAND or $down->getID() === CACTUS){
|
||||
$block0 = $this->getSide(2);
|
||||
$block1 = $this->getSide(3);
|
||||
$block2 = $this->getSide(4);
|
||||
$block3 = $this->getSide(5);
|
||||
if($block0->isFlowable === true and $block1->isFlowable === true and $block2->isFlowable === true and $block3->isFlowable === true){
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
}
|
||||
if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace wit common break method
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== CACTUS){
|
||||
if($this->meta == 0x0F){
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||
if($b->getID() === AIR){
|
||||
$this->level->setBlock($b, new CactusBlock());
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->meta = 0;
|
||||
$this->level->setBlock($this, $this);
|
||||
}else{
|
||||
++$this->meta;
|
||||
$this->level->setBlock($this, $this);
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === SAND or $down->getID() === CACTUS){
|
||||
$block0 = $this->getSide(2);
|
||||
$block1 = $this->getSide(3);
|
||||
$block2 = $this->getSide(4);
|
||||
$block3 = $this->getSide(5);
|
||||
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
|
||||
$this->level->setBlock($this, $this);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array($this->id, 0, 1),
|
||||
);
|
||||
}
|
||||
}
|
@ -28,8 +28,8 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class CyanFlowerBlock extends FlowableBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(CYAN_FLOWER, 0, "Cyan Flower");
|
||||
$this->isFlowable = true;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||
@ -37,5 +37,16 @@ class CyanFlowerBlock extends FlowableBlock{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -28,8 +28,8 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class DandelionBlock extends FlowableBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(DANDELION, 0, "Dandelion");
|
||||
$this->isFlowable = true;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||
@ -37,5 +37,16 @@ class DandelionBlock extends FlowableBlock{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -28,8 +28,17 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class DeadBushBlock extends FlowableBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(DEAD_BUSH, 0, "Dead Bush");
|
||||
$this->isFlowable = true;
|
||||
$this->isReplaceable = true;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class MelonStemBlock extends TransparentBlock{
|
||||
class MelonStemBlock extends FlowableBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(MELON_STEM, $meta, "Melon Stem");
|
||||
$this->isActivable = true;
|
||||
@ -34,15 +34,51 @@ class MelonStemBlock extends TransparentBlock{
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if(mt_rand(0, 2) == 1){
|
||||
if($this->meta < 0x07){
|
||||
++$this->meta;
|
||||
$this->level->setBlock($this, $this);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}else{
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b->getID() === MELON_BLOCK){
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
$side = $this->getSide(mt_rand(2,5));
|
||||
$d = $side->getSide(0);
|
||||
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
|
||||
$this->level->setBlock($side, new MelonBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||
$this->meta = 0x07;
|
||||
$this->level->setBlock($this, $this);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -28,15 +28,25 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class RedMushroomBlock extends FlowableBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(RED_MUSHROOM, 0, "Red Mushroom");
|
||||
$this->isFlowable = true;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === false){
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
}
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === false){
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class SaplingBlock extends TransparentBlock{
|
||||
class SaplingBlock extends FlowableBlock{
|
||||
const OAK = 0;
|
||||
const SPRUCE = 1;
|
||||
const BIRCH = 2;
|
||||
@ -34,7 +34,6 @@ class SaplingBlock extends TransparentBlock{
|
||||
public function __construct($meta = Sapling::OAK){
|
||||
parent::__construct(SAPLING, $meta, "Sapling");
|
||||
$this->isActivable = true;
|
||||
$this->isFlowable = true;
|
||||
$names = array(
|
||||
0 => "Oak Sapling",
|
||||
1 => "Spruce Sapling",
|
||||
@ -47,6 +46,7 @@ class SaplingBlock extends TransparentBlock{
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -54,21 +54,33 @@ class SaplingBlock extends TransparentBlock{
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||
TreeObject::growTree($this->level, $this, $this->meta);
|
||||
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_RANDOM and mt_rand(0,2) === 0){ //Growth
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
TreeObject::growTree($this->level, $this);
|
||||
}else{
|
||||
$this->meta |= 0x08;
|
||||
$this->level->setBlock($this, $this);
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){ //Growth
|
||||
if(mt_rand(1,7) === 1){
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||
}else{
|
||||
$this->meta |= 0x08;
|
||||
$this->level->setBlock($this, $this);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}else{
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class SugarcaneBlock extends TransparentBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(SUGARCANE_BLOCK, 0, "Sugarcane");
|
||||
class SugarcaneBlock extends FlowableBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(SUGARCANE_BLOCK, $meta, "Sugarcane");
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
@ -35,6 +35,36 @@ class SugarcaneBlock extends TransparentBlock{
|
||||
array(SUGARCANE, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){
|
||||
if($this->meta === 0x0F){
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||
if($b->getID() === AIR){
|
||||
$this->level->setBlock($b, new SugarcaneBlock());
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->meta = 0;
|
||||
$this->level->setBlock($this, $this);
|
||||
}else{
|
||||
++$this->meta;
|
||||
$this->level->setBlock($this, $this);
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
@ -42,19 +72,19 @@ class SugarcaneBlock extends TransparentBlock{
|
||||
$this->level->setBlock($block, new SugarcaneBlock());
|
||||
return true;
|
||||
}elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
|
||||
$block0 = $this->getSide(2);
|
||||
$block1 = $this->getSide(3);
|
||||
$block2 = $this->getSide(4);
|
||||
$block3 = $this->getSide(5);
|
||||
if($block0->getID() === WATER or $block0->getID() === STILL_WATER
|
||||
or $block1->getID() === WATER or $block1->getID() === STILL_WATER
|
||||
or $block2->getID() === WATER or $block2->getID() === STILL_WATER
|
||||
or $block3->getID() === WATER or $block3->getID() === STILL_WATER){
|
||||
$block0 = $down->getSide(2);
|
||||
$block1 = $down->getSide(3);
|
||||
$block2 = $down->getSide(4);
|
||||
$block3 = $down->getSide(5);
|
||||
if(($block0 instanceof WaterBlock)
|
||||
or ($block1 instanceof WaterBlock)
|
||||
or ($block2 instanceof WaterBlock)
|
||||
or ($block3 instanceof WaterBlock)){
|
||||
$this->level->setBlock($block, new SugarcaneBlock());
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -28,7 +28,6 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class TallGrassBlock extends FlowableBlock{
|
||||
public function __construct($meta = 1){
|
||||
parent::__construct(TALL_GRASS, $meta, "Tall Grass");
|
||||
$this->isFlowable = true;
|
||||
$this->isReplaceable = true;
|
||||
$names = array(
|
||||
0 => "Dead Shrub",
|
||||
@ -37,11 +36,21 @@ class TallGrassBlock extends FlowableBlock{
|
||||
);
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = array();
|
||||
if(mt_rand(1,10) === 1){//Seeds
|
||||
$drops[] = array(295, 0, 1);
|
||||
$drops[] = array(WHEAT_SEEDS, 0, 1);
|
||||
}
|
||||
return $drops;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ class WheatBlock extends FlowableBlock{
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -44,10 +45,34 @@ class WheatBlock extends FlowableBlock{
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||
$this->meta = 0x07;
|
||||
$this->level->setBlock($this, $this);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(WHEAT_SEEDS, 0, 1));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if(mt_rand(0, 2) == 1){
|
||||
if($this->meta < 0x07){
|
||||
++$this->meta;
|
||||
$this->level->setBlock($this, $this);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}else{
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = array();
|
||||
|
@ -25,7 +25,6 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class BurningFurnaceBlock extends SolidBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(BURNING_FURNACE, $meta, "Burning Furnace");
|
||||
@ -33,48 +32,31 @@ class BurningFurnaceBlock extends SolidBlock{
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
||||
0 => 4,
|
||||
1 => 2,
|
||||
2 => 5,
|
||||
3 => 3,
|
||||
);
|
||||
$this->meta = $faces[$player->entity->getDirection()];
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
$faces = array(
|
||||
0 => 4,
|
||||
1 => 2,
|
||||
2 => 5,
|
||||
3 => 3,
|
||||
);
|
||||
$this->meta = $faces[$player->entity->getDirection()];
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onBreak(Item $item, Player $player){
|
||||
$server = ServerAPI::request();
|
||||
$t = $server->api->tileentity->get($this);
|
||||
if($t !== false){
|
||||
if(is_array($t)){
|
||||
foreach($t as $ts){
|
||||
if($ts->class === TILE_FURNACE){
|
||||
$server->api->tileentity->remove($ts->id);
|
||||
}
|
||||
}
|
||||
}elseif($t->class === TILE_FURNACE){
|
||||
$server->api->tileentity->remove($t->id);
|
||||
}
|
||||
}
|
||||
$this->level->setBlock($this, new AirBlock());
|
||||
return true;
|
||||
$this->level->setBlock($this, new AirBlock(), true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
|
||||
$server = ServerAPI::request();
|
||||
$t = $server->api->tileentity->get($this);
|
||||
$t = $server->api->tile->get($this);
|
||||
$furnace = false;
|
||||
if($t !== false){
|
||||
if(is_array($t)){
|
||||
$furnace = array_shift($t);
|
||||
}else{
|
||||
$furnace = $t;
|
||||
}
|
||||
$furnace = $t;
|
||||
}else{
|
||||
$furnace = $server->api->tileentity->add($this->level, TILE_FURNACE, $this->x, $this->y, $this->z, array(
|
||||
$furnace = $server->api->tile->add($this->level, TILE_FURNACE, $this->x, $this->y, $this->z, array(
|
||||
"Items" => array(),
|
||||
"id" => TILE_FURNACE,
|
||||
"x" => $this->x,
|
||||
@ -87,7 +69,7 @@ class BurningFurnaceBlock extends SolidBlock{
|
||||
return true;
|
||||
}
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(1, $player->windowCnt % 255);
|
||||
$player->windowCnt = $id = max(2, $player->windowCnt % 16);
|
||||
$player->windows[$id] = $furnace;
|
||||
$player->dataPacket(MC_CONTAINER_OPEN, array(
|
||||
"windowid" => $id,
|
||||
@ -96,7 +78,7 @@ class BurningFurnaceBlock extends SolidBlock{
|
||||
"title" => "Furnace",
|
||||
));
|
||||
$slots = array();
|
||||
for($s = 0; $s <= FURNACE_SLOTS; ++$s){
|
||||
for($s = 0; $s < FURNACE_SLOTS; ++$s){
|
||||
$slot = $furnace->getSlot($s);
|
||||
if($slot->getID() > 0 and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
@ -133,12 +115,19 @@ class BurningFurnaceBlock extends SolidBlock{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = array();
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(FURNACE, 0, 1),
|
||||
);
|
||||
}else{
|
||||
return array();
|
||||
$drops[] = array(FURNACE, 0, 1);
|
||||
}
|
||||
$t = ServerAPI::request()->api->tile->get($this);
|
||||
if($t !== false and $t->class === TILE_FURNACE){
|
||||
for($s = 0; $s < FURNACE_SLOTS; ++$s){
|
||||
$slot = $t->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $drops;
|
||||
}
|
||||
}
|
@ -31,47 +31,55 @@ class ChestBlock extends TransparentBlock{
|
||||
$this->isActivable = true;
|
||||
}
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$block0 = $this->getSide(2);
|
||||
$block1 = $this->getSide(3);
|
||||
$block2 = $this->getSide(4);
|
||||
$block3 = $this->getSide(5);
|
||||
if($block0->getID() !== CHEST and $block1->getID() !== CHEST and $block2->getID() !== CHEST and $block3->getID() !== CHEST){
|
||||
$faces = array(
|
||||
0 => 4,
|
||||
1 => 2,
|
||||
2 => 5,
|
||||
3 => 3,
|
||||
);
|
||||
$this->meta = $faces[$player->entity->getDirection()];
|
||||
$this->level->setBlock($block, $this);
|
||||
$server = ServerAPI::request();
|
||||
$server->api->tileentity->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array(
|
||||
"Items" => array(),
|
||||
"id" => TILE_CHEST,
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z
|
||||
));
|
||||
return true;
|
||||
|
||||
$faces = array(
|
||||
0 => 4,
|
||||
1 => 2,
|
||||
2 => 5,
|
||||
3 => 3,
|
||||
);
|
||||
$facesc = array(
|
||||
2 => 4,
|
||||
3 => 2,
|
||||
4 => 5,
|
||||
5 => 3,
|
||||
);
|
||||
$chest = false;
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$c = $this->getSide($side);
|
||||
if($c instanceof ChestBlock){
|
||||
/*if($chest !== false){ //No chests in the middle
|
||||
return false;
|
||||
}*/
|
||||
$chest = array($side, $c);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if($chest !== false and ($chest[1]->getSide($chest[0]) instanceof ChestBlock)){ //Already double chest
|
||||
return false;
|
||||
}
|
||||
|
||||
if($chest !== false){
|
||||
$this->meta = $facesc[$chest[0]];
|
||||
$this->level->setBlock($chest[1], new ChestBlock($this->meta));
|
||||
}else{
|
||||
$this->meta = $faces[$player->entity->getDirection()];
|
||||
}
|
||||
$this->level->setBlock($block, $this);
|
||||
$server = ServerAPI::request();
|
||||
$server->api->tile->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array(
|
||||
"Items" => array(),
|
||||
"id" => TILE_CHEST,
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z
|
||||
));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onBreak(Item $item, Player $player){
|
||||
$server = ServerAPI::request();
|
||||
$t = $server->api->tileentity->get($this);
|
||||
if($t !== false){
|
||||
if(is_array($t)){
|
||||
foreach($t as $ts){
|
||||
if($ts->class === TILE_CHEST){
|
||||
$server->api->tileentity->remove($ts->id);
|
||||
}
|
||||
}
|
||||
}elseif($t->class === TILE_CHEST){
|
||||
$server->api->tileentity->remove($t->id);
|
||||
}
|
||||
}
|
||||
$this->level->setBlock($this, new AirBlock());
|
||||
$this->level->setBlock($this, new AirBlock(), true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -82,16 +90,12 @@ class ChestBlock extends TransparentBlock{
|
||||
}
|
||||
|
||||
$server = ServerAPI::request();
|
||||
$t = $server->api->tileentity->get($this);
|
||||
$t = $server->api->tile->get($this);
|
||||
$chest = false;
|
||||
if($t !== false){
|
||||
if(is_array($t)){
|
||||
$chest = array_shift($t);
|
||||
}else{
|
||||
$chest = $t;
|
||||
}
|
||||
$chest = $t;
|
||||
}else{
|
||||
$chest = $server->api->tileentity->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array(
|
||||
$chest = $server->api->tile->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array(
|
||||
"Items" => array(),
|
||||
"id" => TILE_CHEST,
|
||||
"x" => $this->x,
|
||||
@ -104,7 +108,7 @@ class ChestBlock extends TransparentBlock{
|
||||
return true;
|
||||
}
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(1, $player->windowCnt % 255);
|
||||
$player->windowCnt = $id = max(2, $player->windowCnt % 16);
|
||||
$player->windows[$id] = $chest;
|
||||
$player->dataPacket(MC_CONTAINER_OPEN, array(
|
||||
"windowid" => $id,
|
||||
@ -112,10 +116,17 @@ class ChestBlock extends TransparentBlock{
|
||||
"slots" => CHEST_SLOTS,
|
||||
"title" => "Chest",
|
||||
));
|
||||
$server->api->player->broadcastPacket($server->api->player->getAll($this->level), MC_TILE_EVENT, array(
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z,
|
||||
"case1" => 1,
|
||||
"case2" => 2,
|
||||
));
|
||||
$slots = array();
|
||||
for($s = 0; $s <= CHEST_SLOTS; ++$s){
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $chest->getSlot($s);
|
||||
if($slot->getID() > 0 and $slot->count > 0){
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
@ -131,8 +142,18 @@ class ChestBlock extends TransparentBlock{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
$drops = array(
|
||||
array($this->id, 0, 1),
|
||||
);
|
||||
$t = ServerAPI::request()->api->tile->get($this);
|
||||
if($t !== false and $t->class === TILE_CHEST){
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $t->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $drops;
|
||||
}
|
||||
}
|
@ -33,6 +33,9 @@ class DirtBlock extends SolidBlock{
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->isHoe()){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->useOn($this);
|
||||
}
|
||||
$this->level->setBlock($this, BlockAPI::get(FARMLAND, 0));
|
||||
return true;
|
||||
}
|
||||
|
@ -38,27 +38,15 @@ class GrassBlock extends SolidBlock{
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
|
||||
for($c = 0; $c < 15; ++$c){
|
||||
$x = mt_rand($this->x - 2, $this->x + 2);
|
||||
$z = mt_rand($this->z - 2, $this->z + 2);
|
||||
$b = $this->level->getBlock(new Vector3($x, $this->y + 1, $z));
|
||||
$d = $this->level->getBlock(new Vector3($x, $this->y, $z));
|
||||
if($b->getID() === AIR and $d->getID() === GRASS){
|
||||
$arr = array(
|
||||
array(DANDELION, 0),
|
||||
array(CYAN_FLOWER, 0),
|
||||
array(TALL_GRASS, 1),
|
||||
array(TALL_GRASS, 1),
|
||||
array(TALL_GRASS, 1),
|
||||
array(TALL_GRASS, 1),
|
||||
array(AIR, 0),
|
||||
);
|
||||
$t = $arr[mt_rand(0, count($arr) - 1)];
|
||||
$this->level->setBlock($b, BlockAPI::get($t[0], $t[1]));
|
||||
}
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->count--;
|
||||
}
|
||||
TallGrassObject::growGrass($this->level, $this, new Random());
|
||||
return true;
|
||||
}elseif($item->isHoe()){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->useOn($this);
|
||||
}
|
||||
$this->level->setBlock($this, new FarmlandBlock());
|
||||
return true;
|
||||
}
|
||||
|
@ -30,4 +30,15 @@ class GravelBlock extends FallableBlock{
|
||||
parent::__construct(GRAVEL, 0, "Gravel");
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if(mt_rand(1,10) === 1){
|
||||
return array(
|
||||
array(FLINT, 0, 1),
|
||||
);
|
||||
}
|
||||
return array(
|
||||
array(GRAVEL, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -35,16 +35,117 @@ class LeavesBlock extends TransparentBlock{
|
||||
LeavesBlock::OAK => "Oak Leaves",
|
||||
LeavesBlock::SPRUCE => "Spruce Leaves",
|
||||
LeavesBlock::BIRCH => "Birch Leaves",
|
||||
3 => "",
|
||||
);
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
}
|
||||
|
||||
private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){
|
||||
++$check;
|
||||
$index = $pos->x.".".$pos->y.".".$pos->z;
|
||||
if(isset($visited[$index])){
|
||||
return false;
|
||||
}
|
||||
if($pos->getID() === WOOD){
|
||||
return true;
|
||||
}elseif($pos->getID() === LEAVES and $distance < 3){
|
||||
$visited[$index] = true;
|
||||
$down = $pos->getSide(0)->getID();
|
||||
if($down === WOOD){
|
||||
return true;
|
||||
}
|
||||
if($fromSide === null){
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
if($this->findLog($pos->getSide($side), $visited, $distance + 1, $check, $side) === true){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}else{ //No more loops
|
||||
switch($fromSide){
|
||||
case 2:
|
||||
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if(($this->meta & 0b00001100) === 0){
|
||||
$this->meta |= 0x08;
|
||||
$this->level->setBlock($this, $this, false);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if(($this->meta & 0b00001100) === 0x08){
|
||||
$this->meta &= 0x03;
|
||||
$visited = array();
|
||||
$check = 0;
|
||||
if($this->findLog($this, $visited, 0, $check) === true){
|
||||
$this->level->setBlock($this, $this, false);
|
||||
}else{
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
if(mt_rand(1,20) === 1){ //Saplings
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1));
|
||||
}
|
||||
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
|
||||
}
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$this->meta |= 0x04;
|
||||
$this->level->setBlock($this, $this);
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = array();
|
||||
if(mt_rand(1,20) === 1){ //Saplings
|
||||
$drops[] = array(SAPLING, $this->meta & 0x03, 1);
|
||||
}
|
||||
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
|
||||
$drops[] = array(260, 0, 1);
|
||||
$drops[] = array(APPLE, 0, 1);
|
||||
}
|
||||
return $drops;
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ class StonecutterBlock extends SolidBlock{
|
||||
parent::__construct(STONECUTTER, $meta, "Stonecutter");
|
||||
$this->isActivable = true;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
$player->toCraft[-1] = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
|
@ -35,8 +35,10 @@ class WoodBlock extends SolidBlock{
|
||||
WoodBlock::OAK => "Oak Wood",
|
||||
WoodBlock::SPRUCE => "Spruce Wood",
|
||||
WoodBlock::BIRCH => "Birch Wood",
|
||||
3 => "",
|
||||
);
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
$this->meta &= 0x03;
|
||||
$this->name = $names[$this->meta];
|
||||
}
|
||||
|
||||
}
|
@ -30,10 +30,15 @@ class WorkbenchBlock extends SolidBlock{
|
||||
parent::__construct(WORKBENCH, $meta, "Crafting Table");
|
||||
$this->isActivable = true;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
$player->toCraft[-1] = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array($this->id, 0, 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,17 +27,36 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
class BucketItem extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(BUCKET, 0, $count, "Empty Bucket");
|
||||
parent::__construct(BUCKET, $meta, $count, "Bucket");
|
||||
$this->isActivable = true;
|
||||
$this->maxStackSize = 1;
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($target->getID() === STILL_WATER or $target->getID() === STILL_LAVA){
|
||||
$level->setBlock($target, new AirBlock());
|
||||
$player->removeItem($this->getID(), $this->getMetadata(), $this->count);
|
||||
$player->addItem(($target->getID() === STILL_LAVA ? LAVA_BUCKET:WATER_BUCKET), 0, 1);
|
||||
return true;
|
||||
if($this->meta === AIR){
|
||||
if($target instanceof LiquidBlock){
|
||||
$level->setBlock($target, new AirBlock());
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = ($target instanceof WaterBlock) ? WATER:LAVA;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}elseif($this->meta === WATER){
|
||||
if($block->getID() === AIR){
|
||||
$level->setBlock($block, new StillWaterBLock());
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}elseif($this->meta === LAVA){
|
||||
if($block->getID() === AIR){
|
||||
$level->setBlock($block, new StillLavaBlock());
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
class CoalItem extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(COAL, $meta & 0x01, $count, "Coal");
|
||||
if($this->meta === 1){
|
||||
$this->name = "Charcoal";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -32,7 +32,7 @@ class PaintingItem extends Item{
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($target->isTransparent === false and $face > 1 and $block->isFlowable === true){
|
||||
if($target->isTransparent === false and $face > 1 and $block->isSolid === false){
|
||||
$server = ServerAPI::request();
|
||||
$faces = array(
|
||||
2 => 1,
|
||||
@ -79,7 +79,7 @@ class PaintingItem extends Item{
|
||||
"Motive" => $motive[0],
|
||||
);
|
||||
$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data);
|
||||
$server->api->entity->spawnToAll($level, $e->eid);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
if(($player->gamemode & 0x01) === 0x00){
|
||||
$player->removeItem($this->getID(), $this->getMetadata(), 1);
|
||||
}
|
||||
|
@ -25,19 +25,31 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class LavaBucketItem extends Item{
|
||||
class SpawnEggItem extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(LAVA_BUCKET, 0, $count, "Lava Bucket");
|
||||
parent::__construct(SPAWN_EGG, 0, $count, "Spawn Egg");
|
||||
$this->meta = $meta;
|
||||
$this->isActivable = true;
|
||||
$this->maxStackSize = 1;
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($target->getID() === AIR){
|
||||
$level->setBlock($target, new StillLavaBlock());
|
||||
$player->removeItem($this->getID(), $this->getMetadata(), $this->count);
|
||||
$player->addItem(BUCKET, 0, 1);
|
||||
return true;
|
||||
switch($this->meta){
|
||||
case MOB_CHICKEN:
|
||||
case MOB_SHEEP:
|
||||
case MOB_COW:
|
||||
case MOB_PIG:
|
||||
$data = array(
|
||||
"x" => $block->x + 0.5,
|
||||
"y" => $block->y,
|
||||
"z" => $block->z + 0.5,
|
||||
);
|
||||
$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
|
||||
ServerAPI::request()->api->entity->spawnToAll($e);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
--$this->count;
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
@ -25,20 +25,22 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class WaterBucketItem extends Item{
|
||||
class FlintSteelItem extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(WATER_BUCKET, 0, $count, "Water Bucket");
|
||||
parent::__construct(FLINT_STEEL, $meta, $count, "Flint and Steel");
|
||||
$this->isActivable = true;
|
||||
$this->maxStackSize = 1;
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($target->getID() === AIR){
|
||||
$level->setBlock($target, new StillWaterBLock());
|
||||
$player->removeItem($this->getID(), $this->getMetadata(), $this->count);
|
||||
$player->addItem(BUCKET, 0, 1);
|
||||
if($block->getID() === AIR){
|
||||
$level->setBlock($block, new FireBlock(), true, false, true);
|
||||
$block->level->scheduleBlockUpdate(new Position($block, 0, 0, $block->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
if($this->useOn($block) and ($player->gamemode & 0x01) === 0 and $this->getMetadata() >= $this->getMaxDurability()){
|
||||
$player->setSlot($player->slot, new Item(AIR, 0, 0), false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
193
src/math/Matrix.php
Normal file
193
src/math/Matrix.php
Normal file
@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class Matrix implements ArrayAccess{
|
||||
private $matrix = array();
|
||||
private $rows = 0;
|
||||
private $columns = 0;
|
||||
|
||||
public function offsetExists($offset){
|
||||
return isset($this->matrix[(int) $offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset){
|
||||
return $this->matrix[(int) $offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value){
|
||||
$this->matrix[(int) $offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset){
|
||||
unset($this->matrix[(int) $offset]);
|
||||
}
|
||||
|
||||
public function __construct($rows, $columns, array $set = array()){
|
||||
$this->rows = max(1, (int) $rows);
|
||||
$this->columns = max(1, (int) $columns);
|
||||
$this->set($set);
|
||||
}
|
||||
|
||||
public function set(array $m){
|
||||
for($r = 0; $r < $this->rows; ++$r){
|
||||
$this->matrix[$r] = array();
|
||||
for($c = 0; $c < $this->columns; ++$c){
|
||||
$this->matrix[$r][$c] = isset($m[$r][$c]) ? $m[$r][$c] : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getRows(){
|
||||
return ($this->rows);
|
||||
}
|
||||
|
||||
public function getColumns(){
|
||||
return ($this->columns);
|
||||
}
|
||||
|
||||
public function setElement($row, $column, $value){
|
||||
if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
|
||||
return false;
|
||||
}
|
||||
$this->matrix[(int) $row][(int) $column] = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getElement($row, $column){
|
||||
if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
|
||||
return false;
|
||||
}
|
||||
return $this->matrix[(int) $row][(int) $column];
|
||||
}
|
||||
|
||||
public function isSquare(){
|
||||
return $this->rows === $this->columns;
|
||||
}
|
||||
|
||||
public function add(Matrix $matrix){
|
||||
if($this->rows !== $matrix->getRows() or $this->columns !== $matrix->getColumns()){
|
||||
return false;
|
||||
}
|
||||
$result = new Matrix($this->rows, $this->columns);
|
||||
for($r = 0; $r < $this->rows; ++$r){
|
||||
for($c = 0; $c < $this->columns; ++$c){
|
||||
$result->setElement($r, $c, $this->matrix[$r][$c] + $matrix->getElement($r, $c));
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function substract(Matrix $matrix){
|
||||
if($this->rows !== $matrix->getRows() or $this->columns !== $matrix->getColumns()){
|
||||
return false;
|
||||
}
|
||||
$result = clone $this;
|
||||
for($r = 0; $r < $this->rows; ++$r){
|
||||
for($c = 0; $c < $this->columns; ++$c){
|
||||
$result->setElement($r, $c, $this->matrix[$r][$c] - $matrix->getElement($r, $c));
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function multiplyScalar($number){
|
||||
$result = clone $this;
|
||||
for($r = 0; $r < $this->rows; ++$r){
|
||||
for($c = 0; $c < $this->columns; ++$c){
|
||||
$result->setElement($r, $c, $this->matrix[$r][$c] * $number);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function divideScalar($number){
|
||||
$result = clone $this;
|
||||
for($r = 0; $r < $this->rows; ++$r){
|
||||
for($c = 0; $c < $this->columns; ++$c){
|
||||
$result->setElement($r, $c, $this->matrix[$r][$c] / $number);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function transpose(){
|
||||
$result = new Matrix($this->columns, $this->rows);
|
||||
for($r = 0; $r < $this->rows; ++$r){
|
||||
for($c = 0; $c < $this->columns; ++$c){
|
||||
$result->setElement($c, $r, $this->matrix[$r][$c]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//Naive Matrix product, O(n^3)
|
||||
public function product(Matrix $matrix){
|
||||
if($this->columns !== $matrix->getRows()){
|
||||
return false;
|
||||
}
|
||||
$c = $matrix->getColumns();
|
||||
$result = new Matrix($this->rows, $c);
|
||||
for($i = 0; $i < $this->rows; ++$i){
|
||||
for($j = 0; $j < $c; ++$j){
|
||||
$sum = 0;
|
||||
for($k = 0; $k < $this->columns; ++$k){
|
||||
$sum += $this->matrix[$i][$k] * $matrix->getElement($k, $j);
|
||||
}
|
||||
$result->setElement($i, $j, $sum);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
//Computation of the determinant of 2x2 and 3x3 matrices
|
||||
public function determinant(){
|
||||
if($this->isSquare() !== true){
|
||||
return false;
|
||||
}
|
||||
switch($this->rows){
|
||||
case 1:
|
||||
return 0;
|
||||
case 2:
|
||||
return $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0];
|
||||
case 3:
|
||||
return $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function __toString(){
|
||||
$s = "";
|
||||
for($r = 0; $r < $this->rows; ++$r){
|
||||
$s .= implode(",", $this->matrix[$r]).";";
|
||||
}
|
||||
return "Matrix({$this->rows}x{$this->columns};".substr($s, 0, -1).")";
|
||||
}
|
||||
|
||||
}
|
@ -86,6 +86,14 @@ class Vector2{
|
||||
public function abs(){
|
||||
return new Vector2(abs($this->x), abs($this->y));
|
||||
}
|
||||
|
||||
public function multiply($number){
|
||||
return new Vector2($this->x * $number, $this->y * $number);
|
||||
}
|
||||
|
||||
public function divide($number){
|
||||
return new Vector2($this->x / $number, $this->y / $number);
|
||||
}
|
||||
|
||||
public function distance($x = 0, $y = 0){
|
||||
if(($x instanceof Vector2) === true){
|
||||
@ -102,6 +110,26 @@ class Vector2{
|
||||
return pow($this->x - $x, 2) + pow($this->y - $y, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public function length(){
|
||||
return sqrt($this->lengthSquared());
|
||||
}
|
||||
|
||||
public function lengthSquared(){
|
||||
return $this->x * $this->x + $this->y * $this->y;
|
||||
}
|
||||
|
||||
public function normalize(){
|
||||
$len = $this->length();
|
||||
if($len != 0){
|
||||
return $this->divide($len);
|
||||
}
|
||||
return new Vector2(0, 0);
|
||||
}
|
||||
|
||||
public function dot(Vector2 $v){
|
||||
return $this->x * $v->x + $this->y * $v->y;
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return "Vector2(x=".$this->x.",y=".$this->y.")";
|
||||
|
@ -97,6 +97,14 @@ class Vector3{
|
||||
return $this->add(-$x, -$y, -$z);
|
||||
}
|
||||
}
|
||||
|
||||
public function multiply($number){
|
||||
return new Vector3($this->x * $number, $this->y * $number, $this->z * $number);
|
||||
}
|
||||
|
||||
public function divide($number){
|
||||
return new Vector3($this->x / $number, $this->y / $number, $this->z / $number);
|
||||
}
|
||||
|
||||
public function ceil(){
|
||||
return new Vector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1));
|
||||
@ -156,6 +164,34 @@ class Vector3{
|
||||
return max(abs($this->x - $x), abs($this->z - $z));
|
||||
}
|
||||
}
|
||||
|
||||
public function length(){
|
||||
return sqrt($this->lengthSquared());
|
||||
}
|
||||
|
||||
public function lengthSquared(){
|
||||
return $this->x * $this->x + $this->y * $this->y + $this->z * $this->z;
|
||||
}
|
||||
|
||||
public function normalize(){
|
||||
$len = $this->length();
|
||||
if($len != 0){
|
||||
return $this->divide($len);
|
||||
}
|
||||
return new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
public function dot(Vector3 $v){
|
||||
return $this->x * $v->x + $this->y * $v->y + $this->z * $v->z;
|
||||
}
|
||||
|
||||
public function cross(Vector3 $v){
|
||||
return new Vector3(
|
||||
$this->y * $v->z - $this->z * $v->y,
|
||||
$this->z * $v->x - $this->x * $v->z,
|
||||
$this->x * $v->y - $this->y * $v->x
|
||||
);
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return "Vector3(x=".$this->x.",y=".$this->y.",z=".$this->z.")";
|
||||
|
@ -25,9 +25,10 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class CakeBlock extends TransparentBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(CAKE_BLOCK, 0, "Cake Block");
|
||||
class VectorMath{
|
||||
|
||||
public static function getDirection2D($azimuth){
|
||||
return new Vector2(cos($azimuth), sin($azimuth));
|
||||
}
|
||||
|
||||
}
|
@ -159,9 +159,14 @@ class CustomPacketHandler{
|
||||
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
$this->data["protocol1"] = Utils::readInt($this->get(4));
|
||||
$this->data["protocol2"] = Utils::readInt($this->get(4));
|
||||
$this->data["clientId"] = Utils::readInt($this->get(4));
|
||||
$this->data["realms_data"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
}else{
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"];
|
||||
$this->raw .= Utils::writeInt(CURRENT_PROTOCOL).Utils::writeInt(CURRENT_PROTOCOL);
|
||||
$this->raw .= Utils::writeInt(CURRENT_PROTOCOL).
|
||||
Utils::writeInt(CURRENT_PROTOCOL).
|
||||
Utils::writeInt($this->data["clientId"]);
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["realms_data"])).$this->data["realms_data"];
|
||||
}
|
||||
break;
|
||||
case MC_LOGIN_STATUS:
|
||||
@ -218,6 +223,8 @@ class CustomPacketHandler{
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
$this->data["pitch"] = Utils::readByte($this->get(1));
|
||||
$this->data["yaw"] = Utils::readByte($this->get(1));
|
||||
$this->data["metadata"] = Utils::readMetadata($this->get(true));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
@ -225,6 +232,8 @@ class CustomPacketHandler{
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
$this->raw .= Utils::writeByte($this->data["pitch"]);
|
||||
$this->raw .= Utils::writeByte($this->data["yaw"]);
|
||||
$this->raw .= Utils::writeMetadata($this->data["metadata"]);
|
||||
}
|
||||
break;
|
||||
@ -236,6 +245,10 @@ class CustomPacketHandler{
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
$this->data["pitch"] = Utils::readByte($this->get(1));
|
||||
$this->data["yaw"] = Utils::readByte($this->get(1));
|
||||
$this->data["unknown1"] = Utils::readShort($this->get(2));
|
||||
$this->data["unknown2"] = Utils::readShort($this->get(2));
|
||||
$this->data["metadata"] = Utils::readMetadata($this->get(true));
|
||||
}else{
|
||||
$this->raw .= Utils::writeLong($this->data["clientID"]);
|
||||
@ -244,32 +257,47 @@ class CustomPacketHandler{
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
$this->raw .= Utils::writeByte($this->data["pitch"]);
|
||||
$this->raw .= Utils::writeByte($this->data["yaw"]);
|
||||
$this->raw .= Utils::writeShort($this->data["unknown1"]);
|
||||
$this->raw .= Utils::writeShort($this->data["unknown2"]);
|
||||
$this->raw .= Utils::writeMetadata($this->data["metadata"]);
|
||||
}
|
||||
break;
|
||||
case MC_REMOVE_PLAYER:
|
||||
if($this->c === false){
|
||||
$this->data["clientID"] = Utils::readLong($this->get(8));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["clientID"] = Utils::readLong($this->get(8));
|
||||
}else{
|
||||
$this->raw .= Utils::writeLong($this->data["clientID"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeLong($this->data["clientID"]);
|
||||
}
|
||||
break;
|
||||
case MC_ADD_ENTITY: //Not used?
|
||||
case MC_ADD_ENTITY:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["type"] = ord($this->get(1));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
$this->data["did"] = Utils::readInt($this->get(4));
|
||||
if($this->data["did"] > 0){
|
||||
$this->data["speedX"] = Utils::readShort($this->get(2));
|
||||
$this->data["speedY"] = Utils::readShort($this->get(2));
|
||||
$this->data["speedZ"] = Utils::readShort($this->get(2));
|
||||
}
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= chr($this->data["type"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
$this->raw .= Utils::hexToStr("000000020000ffd30000");//Utils::writeInt(0);
|
||||
$this->raw .= Utils::writeInt($this->data["did"]);
|
||||
if($this->data["did"] > 0){
|
||||
$this->raw .= Utils::writeShort($this->data["speedX"]);
|
||||
$this->raw .= Utils::writeShort($this->data["speedY"]);
|
||||
$this->raw .= Utils::writeShort($this->data["speedZ"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_REMOVE_ENTITY:
|
||||
@ -379,7 +407,7 @@ class CustomPacketHandler{
|
||||
$this->raw .= chr($this->data["face"]);
|
||||
}
|
||||
break;
|
||||
case MC_REMOVE_BLOCK:
|
||||
case MC_REMOVE_BLOCK: //Sent when a player removes a block, not used
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
@ -464,6 +492,21 @@ class CustomPacketHandler{
|
||||
$this->raw .= Utils::writeInt($this->data["unknown5"]);
|
||||
}
|
||||
break;
|
||||
case MC_TILE_EVENT:
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["y"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
$this->data["case1"] = Utils::readInt($this->get(4));
|
||||
$this->data["case2"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||
$this->raw .= Utils::writeInt($this->data["y"]);
|
||||
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||
$this->raw .= Utils::writeInt($this->data["case1"]);
|
||||
$this->raw .= Utils::writeInt($this->data["case2"]);
|
||||
}
|
||||
break;
|
||||
case MC_ENTITY_EVENT:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
@ -498,10 +541,12 @@ class CustomPacketHandler{
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["block"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["meta"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["slot"] = ord($this->get(1));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeShort($this->data["block"]);
|
||||
$this->raw .= Utils::writeShort($this->data["meta"]);
|
||||
$this->raw .= chr($this->data["slot"]);
|
||||
}
|
||||
break;
|
||||
case MC_PLAYER_ARMOR_EQUIPMENT:
|
||||
@ -542,14 +587,41 @@ class CustomPacketHandler{
|
||||
$this->data["fx"] = Utils::readFloat($this->get(4));
|
||||
$this->data["fy"] = Utils::readFloat($this->get(4));
|
||||
$this->data["fz"] = Utils::readFloat($this->get(4));
|
||||
$this->data["posX"] = Utils::readFloat($this->get(4));
|
||||
$this->data["posY"] = Utils::readFloat($this->get(4));
|
||||
$this->data["posZ"] = Utils::readFloat($this->get(4));
|
||||
}else{
|
||||
/*$this->raw .= Utils::writeByte($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||
$this->raw .= Utils::writeInt($this->data["y"]);
|
||||
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||
$this->raw .= Utils::writeInt($this->data["face"]);
|
||||
$this->raw .= Utils::writeShort($this->data["block"]);
|
||||
$this->raw .= Utils::writeByte($this->data["meta"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeInt($this->data["target"]);*/
|
||||
$this->raw .= Utils::writeFloat($this->data["fx"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["fy"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["fz"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["posX"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["posY"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["posZ"]);
|
||||
}
|
||||
break;
|
||||
case MC_PLAYER_ACTION:
|
||||
//TODO
|
||||
if($this->c === false){
|
||||
$this->data["action"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["y"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
$this->data["face"] = Utils::readInt($this->get(4));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||
$this->raw .= Utils::writeInt($this->data["y"]);
|
||||
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||
$this->raw .= Utils::writeInt($this->data["face"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
}
|
||||
break;
|
||||
case MC_SET_ENTITY_DATA:
|
||||
if($this->c === false){
|
||||
|
@ -27,16 +27,25 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
class MinecraftInterface{
|
||||
public $client;
|
||||
public $bandwidth;
|
||||
private $socket;
|
||||
private $data;
|
||||
function __construct($server, $port = 25565, $listen = false, $client = false, $serverip = "0.0.0.0"){
|
||||
private $chunked;
|
||||
private $toChunk;
|
||||
private $needCheck;
|
||||
function __construct($object, $server, $port = 25565, $listen = false, $client = false, $serverip = "0.0.0.0"){
|
||||
$this->socket = new UDPSocket($server, $port, (bool) $listen, $serverip);
|
||||
if($this->socket->connected === false){
|
||||
console("[ERROR] Couldn't bind to $serverip:".$port, true, true, 0);
|
||||
exit(1);
|
||||
}
|
||||
$this->bandwidth = array(0, 0, microtime(true));
|
||||
$this->client = (bool) $client;
|
||||
$this->start = microtime(true);
|
||||
$this->chunked = array();
|
||||
$this->toChunk = array();
|
||||
$this->needCheck = array();
|
||||
$object->schedule(1, array($this, "checkChunked"), array(), true);
|
||||
}
|
||||
|
||||
public function close(){
|
||||
@ -50,41 +59,24 @@ class MinecraftInterface{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){
|
||||
if(LOG === true and DEBUG >= 3){
|
||||
$p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".(isset($data["id"]) ? "MC Packet ".Protocol::$dataName[$pid]:Protocol::$packetName[$pid])." (0x".Utils::strTohex(chr($pid)).") [length ".strlen($raw)."]".PHP_EOL;
|
||||
$p .= Utils::hexdump($raw);
|
||||
if(is_array($data)){
|
||||
foreach($data as $i => $d){
|
||||
if(!isset(Protocol::$raknet[$pid][$i])){
|
||||
$ty = "special";
|
||||
}else{
|
||||
$ty = Protocol::$raknet[$pid][$i];
|
||||
}
|
||||
$p .= $i ." => ".(!is_array($d) ? $ty."(".(($ty === "magic" or substr($ty, 0, 7) === "special" or is_int($ty)) ? Utils::strToHex($d):Utils::printable((string) $d)).")":$ty."(\"".serialize(array_map("Utils::printable", $d))."\")").PHP_EOL;
|
||||
}
|
||||
}
|
||||
$p .= PHP_EOL;
|
||||
logg($p, "packets", false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function readPacket(){
|
||||
$p = $this->popPacket();
|
||||
if($p !== false){
|
||||
return $p;
|
||||
}
|
||||
$pk = $this->popPacket();
|
||||
if($this->socket->connected === false){
|
||||
return false;
|
||||
return $pk;
|
||||
}
|
||||
$buf = "";
|
||||
$source = false;
|
||||
$port = 1;
|
||||
$len = $this->socket->read($buf, $source, $port);
|
||||
if($len === false){
|
||||
return false;
|
||||
return $pk;
|
||||
}
|
||||
$this->bandwidth[0] += $len;
|
||||
$this->parsePacket($buf, $source, $port);
|
||||
return ($pk !== false ? $pk : $this->popPacket());
|
||||
}
|
||||
|
||||
private function parsePacket($buf, $source, $port){
|
||||
$pid = ord($buf{0});
|
||||
$struct = $this->getStruct($pid);
|
||||
if($struct === false){
|
||||
@ -95,52 +87,181 @@ class MinecraftInterface{
|
||||
"ip" => $source,
|
||||
"port" => $port
|
||||
)) !== true){
|
||||
if(LOG === true and DEBUG >= 3){
|
||||
console("[ERROR] Unknown Packet ID 0x".Utils::strToHex(chr($pid)), true, true, 0);
|
||||
$p = "[".(microtime(true) - $this->start)."] [CLIENT->SERVER ".$source.":".$port."]: Error, bad packet id 0x".Utils::strToHex(chr($pid))." [length ".strlen($buf)."]".PHP_EOL;
|
||||
$p .= Utils::hexdump($buf);
|
||||
$p .= PHP_EOL;
|
||||
logg($p, "packets", true, 2);
|
||||
}
|
||||
console("[ERROR] Unknown Packet ID 0x".Utils::strToHex(chr($pid)), true, true, 2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$packet = new Packet($pid, $struct, $buf);
|
||||
@$packet->parse();
|
||||
if($pid === 0x99){
|
||||
$CID = PocketMinecraftServer::clientID($source, $port);
|
||||
if(!isset($this->chunked[$CID]) and $packet->data[0] !== 0){ //Drop packet
|
||||
return false;
|
||||
}
|
||||
switch($packet->data[0]){
|
||||
case 0:
|
||||
$this->initChunked($CID, $source, $port);
|
||||
return false;
|
||||
case 1:
|
||||
$this->stopChunked($CID);
|
||||
return false;
|
||||
case 3:
|
||||
$this->ackChunked($CID, $data[1]["id"], $data[1]["index"]);
|
||||
return false;
|
||||
case 4:
|
||||
$this->receiveChunked($CID, $data[1]["id"], $data[1]["index"], $data[1]["count"], $data[1]["data"]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$this->data[] = array($pid, $packet->data, $buf, $source, $port);
|
||||
return $this->popPacket();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkChunked($CID){
|
||||
$time = microtime(true);
|
||||
foreach($this->needCheck as $CID => $packets){
|
||||
if($packets[-1] < $time){
|
||||
$d = $this->chunked[$CID];
|
||||
unset($packets[-1]);
|
||||
foreach($packets as $packet){
|
||||
$this->writePacket(0x99, $packet, true, $d[1], $d[2], true);
|
||||
}
|
||||
$this->needCheck[$CID][-1] = $time + 5;
|
||||
}
|
||||
}
|
||||
foreach($this->toChunk as $CID => $packets){
|
||||
$d = $this->chunked[$CID];
|
||||
$raw = "";
|
||||
$MTU = 512;
|
||||
foreach($packets as $packet){
|
||||
$raw .= $packet;
|
||||
if(($len = strlen($packet)) > $MTU){
|
||||
$MTU = $len;
|
||||
}
|
||||
}
|
||||
if($MTU > $d[0][2]){
|
||||
$this->chunked[$CID][0][2] = $MTU;
|
||||
}else{
|
||||
$MTU = $d[0][2];
|
||||
}
|
||||
$raw = str_split(gzdeflate($raw, DEFLATEPACKET_LEVEL), $MTU - 9); // - 1 - 2 - 2 - 2 - 2
|
||||
$count = count($raw);
|
||||
$messageID = $this->chunked[$CID][0][0]++;
|
||||
$this->chunked[$CID][0][0] &= 0xFFFF;
|
||||
if(!isset($this->needCheck[$CID])){
|
||||
$this->needCheck[$CID] = array();
|
||||
}
|
||||
$this->needCheck[$CID][$messageID] = array(-1 => $time + 1);
|
||||
foreach($raw as $index => $r){
|
||||
$p = "\x99\x02".Utils::writeShort($messageID).Utils::writeShort($index).Utils::writeShort($count).Utils::writeShort(strlen($r)).$r;
|
||||
$this->needCheck[$CID][$messageID][$index] = $p;
|
||||
$this->writePacket(0x99, $p, true, $d[1], $d[2], true);
|
||||
}
|
||||
unset($this->toChunk[$CID]);
|
||||
}
|
||||
}
|
||||
|
||||
public function isChunked($CID){
|
||||
return isset($this->chunked[$CID]);
|
||||
}
|
||||
|
||||
private function initChunked($CID, $source, $port){
|
||||
console("[DEBUG] Starting DEFLATEPacket for $source:$port", true, true, 2);
|
||||
$this->chunked[$CID] = array(
|
||||
0 => array(0, 0, 0), //index, sent/received; MTU
|
||||
1 => $source,
|
||||
2 => $port,
|
||||
3 => array(), //Received packets
|
||||
);
|
||||
$this->writePacket(0x99, array(
|
||||
0 => 0, //start
|
||||
), false, $source, $port, true);
|
||||
}
|
||||
|
||||
public function stopChunked($CID){
|
||||
if(!isset($this->chunked[$CID])){
|
||||
return false;
|
||||
}
|
||||
$this->writePacket(0x99, array(
|
||||
0 => 1, //stop
|
||||
), false, $this->chunked[$CID][1], $this->chunked[$CID][2], true);
|
||||
console("[DEBUG] Stopping DEFLATEPacket for ".$this->chunked[$CID][1].":".$this->chunked[$CID][2], true, true, 2);
|
||||
$this->chunked[$CID][3] = null;
|
||||
$this->chunked[$CID][4] = null;
|
||||
unset($this->chunked[$CID]);
|
||||
unset($this->toChunk[$CID]);
|
||||
unset($this->needCheck[$CID]);
|
||||
}
|
||||
|
||||
private function ackChunked($CID, $ID, $index){
|
||||
unset($this->needCheck[$CID][$ID][$index]);
|
||||
if(count($this->needCheck[$CID][$ID]) <= 1){
|
||||
unset($this->needCheck[$CID][$ID]);
|
||||
}
|
||||
}
|
||||
|
||||
private function receiveChunked($CID, $ID, $index, $count, $data){
|
||||
if(!isset($this->chunked[$CID][3][$ID])){
|
||||
$this->chunked[$CID][3][$ID] = array();
|
||||
}
|
||||
$this->chunked[$CID][3][$ID][$index] = $data;
|
||||
|
||||
if(count($this->chunked[$CID][3][$ID]) === $count){
|
||||
ksort($this->chunked[$CID][3][$ID]);
|
||||
$data = gzinflate(implode($this->chunked[$CID][3][$ID]), 524280);
|
||||
unset($this->chunked[$CID][3][$ID]);
|
||||
if($data === false or strlen($data) === 0){
|
||||
console("[ERROR] Invalid DEFLATEPacket for ".$this->chunked[$CID][1].":".$this->chunked[$CID][2], true, true, 2);
|
||||
}
|
||||
$offset = 0;
|
||||
while(($plen = Utils::readShort(substr($data, $offset, 2), false)) !== 0xFFFF or $offset >= $len){
|
||||
$offset += 2;
|
||||
$packet = substr($data, $offset, $plen);
|
||||
$this->parsePacket($packet, $this->chunked[$CID][1], $this->chunked[$CID][2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function popPacket(){
|
||||
if(count($this->data) > 0){
|
||||
$p = array_shift($this->data);
|
||||
if(isset($p[1]["packets"]) and is_array($p[1]["packets"])){
|
||||
foreach($p[1]["packets"] as $d){
|
||||
$this->data[] = array($p[0], $d[1], $d[2], $p[3], $p[4]);
|
||||
}
|
||||
}
|
||||
$c = (isset($p[1]["id"]) ? true:false);
|
||||
$p[2] = $c ? chr($p[1]["id"]).$p[2]:$p[2];
|
||||
$this->writeDump(($c ? $p[1]["id"]:$p[0]), $p[2], $p[1], "server", $p[3], $p[4]);
|
||||
$p = each($this->data);
|
||||
unset($this->data[$p[0]]);
|
||||
$p = $p[1];
|
||||
return array("pid" => $p[0], "data" => $p[1], "raw" => $p[2], "ip" => $p[3], "port" => $p[4]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function writePacket($pid, $data = array(), $raw = false, $dest = false, $port = false){
|
||||
$struct = $this->getStruct($pid);
|
||||
public function writePacket($pid, $data = array(), $raw = false, $dest = false, $port = false, $force = false){
|
||||
$CID = PocketMinecraftServer::clientID($dest, $port);
|
||||
if($raw === false){
|
||||
$packet = new Packet($pid, $struct);
|
||||
$packet = new Packet($pid, $this->getStruct($pid));
|
||||
$packet->data = $data;
|
||||
@$packet->create();
|
||||
$write = $this->socket->write($packet->raw, $dest, $port);
|
||||
$this->writeDump($pid, $packet->raw, $data, "client", $dest, $port);
|
||||
@$packet->create();
|
||||
if($force === false and $this->isChunked($CID)){
|
||||
if(!isset($this->toChunk[$CID])){
|
||||
$this->toChunk[$CID] = array();
|
||||
}
|
||||
$this->toChunk[$CID][] = $packet->raw;
|
||||
$write = strlen($packet->raw);
|
||||
}else{
|
||||
$write = $this->socket->write($packet->raw, $dest, $port);
|
||||
$this->bandwidth[1] += $write;
|
||||
}
|
||||
}else{
|
||||
$write = $this->socket->write($data, $dest, $port);
|
||||
$this->writeDump($pid, $data, false, "client", $dest, $port);
|
||||
if($force === false and $this->isChunked($CID)){
|
||||
if(!isset($this->toChunk[$CID])){
|
||||
$this->toChunk[$CID] = array();
|
||||
}
|
||||
$this->toChunk[$CID][] = $data;
|
||||
$write = strlen($data);
|
||||
}else{
|
||||
$write = $this->socket->write($data, $dest, $port);
|
||||
$this->bandwidth[1] += $write;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return $write;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,13 +51,19 @@ class Packet{
|
||||
$this->addRaw($this->data[$field]);
|
||||
continue;
|
||||
}
|
||||
if(is_int($type)){
|
||||
$this->addRaw($this->data[$field]);
|
||||
continue;
|
||||
}
|
||||
switch($type){
|
||||
case "special1":
|
||||
switch($this->pid){
|
||||
case 0x99:
|
||||
if($this->data[0] >= 2){
|
||||
$this->addRaw(Utils::writeShort($this->data[1]["id"]));
|
||||
$this->addRaw(Utils::writeShort($this->data[1]["index"]));
|
||||
if($this->data[0] === 2){
|
||||
$this->addRaw(Utils::writeShort($this->data[1]["count"]));
|
||||
$this->addRaw(Utils::writeShort(strlen($this->data[1]["data"])).$this->data[1]["data"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xc0:
|
||||
case 0xa0:
|
||||
$payload = "";
|
||||
@ -181,13 +187,24 @@ class Packet{
|
||||
|
||||
public function parse(){
|
||||
foreach($this->struct as $field => $type){
|
||||
if(is_int($type)){
|
||||
$this->data[] = $this->get($type);
|
||||
continue;
|
||||
}
|
||||
switch($type){
|
||||
case "special1":
|
||||
switch($this->pid){
|
||||
case 0x07:
|
||||
$this->data[] = $this->get(5);
|
||||
break;
|
||||
case 0x99:
|
||||
if($this->data[0] >= 2){ //
|
||||
$messageID = Utils::readShort($this->get(2), false);
|
||||
$messageIndex = Utils::readShort($this->get(2), false);
|
||||
$this->data[1] = array("id" => $messageID, "index" => $messageIndex);
|
||||
if($this->data[0] === 2){
|
||||
$this->data[1]["count"] = Utils::readShort($this->get(2), false);
|
||||
$dataLength = Utils::readShort($this->get(2), false);
|
||||
$this->data[1]["data"] = $this->get($dataLength);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xc0:
|
||||
case 0xa0:
|
||||
$cnt = Utils::readShort($this->get(2), false);
|
||||
@ -216,7 +233,7 @@ class Packet{
|
||||
$this->data["packets"] = array();
|
||||
while($len > $offset){
|
||||
$pid = ord($raw{$offset});
|
||||
++$offset;
|
||||
++$offset;
|
||||
$reliability = ($pid & 0b11100000) >> 5;
|
||||
$hasSplit = ($pid & 0b00010000) >> 4;
|
||||
$length = Utils::readShort(substr($raw, $offset, 2), false);
|
||||
|
@ -25,6 +25,12 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
|
||||
define("DEFLATEPACKET_LEVEL", 1);
|
||||
|
||||
define("CURRENT_STRUCTURE", 5);
|
||||
define("CURRENT_PROTOCOL", 11);
|
||||
|
||||
define("RAKNET_MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78");
|
||||
|
||||
define("MC_PING", 0x00);
|
||||
@ -65,7 +71,7 @@ define("MC_UPDATE_BLOCK", 0x97);
|
||||
define("MC_ADD_PAINTING", 0x98);
|
||||
define("MC_EXPLOSION", 0x99);
|
||||
define("MC_LEVEL_EVENT", 0x9a);
|
||||
//define("MC_TILE_EVENT", 0x9b);
|
||||
define("MC_TILE_EVENT", 0x9b);
|
||||
define("MC_ENTITY_EVENT", 0x9c);
|
||||
define("MC_REQUEST_CHUNK", 0x9d);
|
||||
define("MC_CHUNK_DATA", 0x9e);
|
||||
@ -78,21 +84,22 @@ define("MC_PLAYER_ACTION", 0xa3);
|
||||
define("MC_HURT_ARMOR", 0xa5);
|
||||
define("MC_SET_ENTITY_DATA", 0xa6);
|
||||
define("MC_SET_ENTITY_MOTION", 0xa7);
|
||||
define("MC_SET_HEALTH", 0xa8);
|
||||
define("MC_SET_SPAWN_POSITION", 0xa9);
|
||||
define("MC_ANIMATE", 0xaa);
|
||||
define("MC_RESPAWN", 0xab);
|
||||
define("MC_SEND_INVENTORY", 0xac);
|
||||
define("MC_DROP_ITEM", 0xad);
|
||||
define("MC_CONTAINER_OPEN", 0xae);
|
||||
define("MC_CONTAINER_CLOSE", 0xaf);
|
||||
define("MC_CONTAINER_SET_SLOT", 0xb0);
|
||||
define("MC_CONTAINER_SET_DATA", 0xb1);
|
||||
define("MC_CONTAINER_SET_CONTENT", 0xb2);
|
||||
//define("MC_CONTAINER_ACK", 0xb3);
|
||||
define("MC_CLIENT_MESSAGE", 0xb4);
|
||||
define("MC_SIGN_UPDATE", 0xb5);
|
||||
define("MC_ADVENTURE_SETTINGS", 0xb6);
|
||||
//define("MC_SET_RIDING_PACKET", 0xa8);
|
||||
define("MC_SET_HEALTH", 0xa9);
|
||||
define("MC_SET_SPAWN_POSITION", 0xaa);
|
||||
define("MC_ANIMATE", 0xab);
|
||||
define("MC_RESPAWN", 0xac);
|
||||
define("MC_SEND_INVENTORY", 0xad);
|
||||
define("MC_DROP_ITEM", 0xae);
|
||||
define("MC_CONTAINER_OPEN", 0xaf);
|
||||
define("MC_CONTAINER_CLOSE", 0xb0);
|
||||
define("MC_CONTAINER_SET_SLOT", 0xb1);
|
||||
define("MC_CONTAINER_SET_DATA", 0xb2);
|
||||
define("MC_CONTAINER_SET_CONTENT", 0xb3);
|
||||
//define("MC_CONTAINER_ACK", 0xb4);
|
||||
define("MC_CLIENT_MESSAGE", 0xb5);
|
||||
define("MC_SIGN_UPDATE", 0xb6);
|
||||
define("MC_ADVENTURE_SETTINGS", 0xb7);
|
||||
|
||||
|
||||
class Protocol{
|
||||
@ -164,6 +171,7 @@ class Protocol{
|
||||
);
|
||||
|
||||
public static $packetName = array(
|
||||
0x01 => "ID_CONNECTED_PING_OPEN_CONNECTIONS", //RakNet
|
||||
0x02 => "ID_UNCONNECTED_PING_OPEN_CONNECTIONS", //RakNet
|
||||
0x05 => "ID_OPEN_CONNECTION_REQUEST_1", //RakNet
|
||||
0x06 => "ID_OPEN_CONNECTION_REPLY_1", //RakNet
|
||||
@ -181,6 +189,10 @@ class Protocol{
|
||||
);
|
||||
|
||||
public static $raknet = array(
|
||||
0x01 => array(
|
||||
"long", //Ping ID
|
||||
"magic",
|
||||
),
|
||||
0x02 => array(
|
||||
"long", //Ping ID
|
||||
"magic",
|
||||
@ -201,7 +213,7 @@ class Protocol{
|
||||
|
||||
0x07 => array(
|
||||
"magic",
|
||||
5, //Security Cookie (idk why it's sent here)
|
||||
"special1", //Security Cookie
|
||||
"short", //Server UDP Port
|
||||
"short", //MTU Size
|
||||
"long", //Client GUID
|
||||
@ -316,6 +328,11 @@ class Protocol{
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x99 => array(
|
||||
"byte",
|
||||
"special1",
|
||||
),
|
||||
|
||||
0xa0 => array(
|
||||
"special1",
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user