From 4b71a06000c0b312dd2c90fc26cdce15bb8f644b Mon Sep 17 00:00:00 2001 From: alejandroliu Date: Mon, 31 Oct 2016 13:55:48 +0100 Subject: [PATCH] 1.1.0 --- README.md | 100 +++++++++++++- media/portal-icon.jpg | Bin 0 -> 2878 bytes plugin.yml | 19 +++ src/aliuly/mtp/Main.php | 283 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 400 insertions(+), 2 deletions(-) create mode 100644 media/portal-icon.jpg create mode 100644 plugin.yml create mode 100644 src/aliuly/mtp/Main.php diff --git a/README.md b/README.md index 1de233b..6d4ad7c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,98 @@ -# MagicTelePortal- -Very EASY to use portal (aka Me Too Portal) + +# MeTooPortal + +* Summary: Easy to use Portal plugin +* Dependency Plugins: N/A +* PocketMine-MP version: 1.4 - API 1.10.0 +* DependencyPlugins: - +* OptionalPlugins: FastTransfer +* Categories: Fun +* Plugin Access: Blocks, Commands + +Overview +-------- + +Simple plugin to make creation of portals easy. + +Documentation +------------- + +### Commands + +You use one command: + + [CODE] + /mtp [world|server:port] [x y z] + [/CODE] + +Examples: + +* Portal to another world: + * /mtp minigames +* Portal to another location in the same world: + * /mtp 128 70 128 +* Portal to an specific location in another world: + * /mtp minigames 392 70 939 +* FastTransfer portal + * /mtp example.com:19132 + +### Configuration + +~~~~ +[CODE] +# How far can the portals be created +max-dist: 8 +# Block-id of the border block (defaults to Nether Bricks) +border: 112 +# Block-id of the center block (defaults to Still Water) +center: 9 +# Block-id of the corners (defaults to Nether Brick Stairs) +corner: 114 +# Broadcast teleports (UNIMPLEMENTED) +broadcast-tp: true +[/CODE] +~~~~ + + +### Permission Nodes: + +* metooportal.cmd.mtp: Permission to create portals + +FAQ +--- + +* Q: How do I prevent people from breaking my portal? +* A: Use an anti-grief plugin. + +Todo +---- + +* Add broadcast-tp option. + +Changes +------- + +* 1.1.0 : Next release + * Support for FastTransfer + * Some configuration options +* 1.0.0 : First submission + +Copyright +--------- + + MeTooPortal + Copyright (C) 2015 Alejandro Liu + All Rights Reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . diff --git a/media/portal-icon.jpg b/media/portal-icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a8778c20a5f48e68e4cc18e7b138f2a72bee2fbc GIT binary patch literal 2878 zcmb7@`8N~_8^>pieYs{ZV~-ieuCjy?(bz|cF_y6=+`=gPMAF5Sk$r3>OQDp?J}8r= zu`hM4AxmQqV}DV$*L}~qf57{FetFLMexJ_|-*cXm(UTtlFvirv6aWMQ0Kn4$oO}n6 z09@=GoE+?2oE)6o+*~|-Fn&H>UOsUlC>SO!i9kq8N=eBoXsXD{smV)8sp_k$UC`Fm z)s;~;FgDOJ(nRTM1G%}m`FQ!n`1!@Oky1$Q|63=`00<`_5YPnzA^wqEN}~m;z;G1CnvBLmv&^l@ z)>ZyIv8KhVsLZ{=A5UIdRWOE)gJ{O#@A?Y$dTj6o-~~L(a8ZJy=e3W7D7^)_q&v4x-5a^wyg~us% zLOt7ZokC;+u;7|546B^s3#hR*nhkQ%BINFu)RspYOSY-ZCk^8ei2GSdk zQS8GR5Y8PKjA*Y!l@Bl)Yj=@wMdS8aQ=Pm|H@TAI_KoIy(y$+`&3PZSHS@(^N>7P* zxq>0!;_zF6+div@Fm9A=JY%DCe@ZJ@!pW@W?690~JL8r|d1S8`(0Zh6GoYz0^5+tB zvOe$F9b3?eRen>}#J7O$%0$H^Q7QJ2aaGEBf+M5zke})^x#NiuCl2X3`dVh^U;lL= z_9E57s#~jm$()>g4lH>mX6G>O$=hvP-^s_da6SV7r1d*T`u*QYTCR5QSKK`4>GGlV zHP!XR{)D&luS+A>lGDCY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*JR>?%roc$HH4)_0N@QnNY^=GI($rst zKQz^dAE>DF)MV7Iod9^G_w>h6Ys7@d0f#YMrg`@pV5NW5LYsendMessage(TextFormat::RED. + "You can only use this command in-game"); + return false; + } + + public function onEnable(){ + if (!is_dir($this->getDataFolder())) mkdir($this->getDataFolder()); + $this->getServer()->getPluginManager()->registerEvents($this, $this); + $defaults = [ + "max-dist" => 8, + "border" => Block::NETHER_BRICKS, + "center" => Block::STILL_WATER, + "corner" => Block::NETHER_BRICKS_STAIRS, + "broadcast-tp" => false, + ]; + $cfg = (new Config($this->getDataFolder()."config.yml", + Config::YAML,$defaults))->getAll(); + $this->max_dist = $cfg["max-dist"]; + $this->border = $cfg["border"]; + $this->center = $cfg["center"]; + $this->corner = $cfg["corner"]; + + $this->portals=(new Config($this->getDataFolder()."portals.yml", + Config::YAML,[]))->getAll(); + if ($this->getServer()->getPluginManager()->getPlugin("FastTransfer")){ + $this->getLogger()->info(TextFormat::GREEN."FastTransfer available!"); + } + } + private function checkLevel($w) { + if (!$this->getServer()->isLevelGenerated($w)) return null; + if (!$this->getServer()->isLevelLoaded($w)) { + if (!$this->getServer()->loadLevel($w)) return null; + } + return $this->getServer()->getLevelByName($w); + } + + private function checkTarget($args) { + switch (count($args)) { + case 1: + $ft_server = explode(":",$args[0],2); + if (count($ft_server) == 2 && !empty($ft_server[0]) && + is_numeric($ft_server[1])) { + // This is a Fast Transfer target! + return $ft_server; + } + list($world) = $args; + $l = $this->checkLevel($world); + if ($l) return $l->getSafeSpawn(); + return null; + case 3: + list($x,$y,$z) = $args; + if (is_numeric($x) && is_numeric($y) && is_numeric($z)) { + return new Vector3($x,$y,$z); + } + return null; + case 4: + list($world,$x,$y,$z) = $args; + $l = $this->checkLevel($world); + if ($l && is_numeric($x) && is_numeric($y) && is_numeric($z)) { + return new Position($x,$y,$z,$l); + } + return null; + } + return null; + } + + protected function targetPos($pos,$dir) { + $lv = $pos->getLevel(); + for($start=new Vector3($pos->getX(),$pos->getY(),$pos->getZ()); + $start->distance($pos) < $this->max_dist ; + $pos = $pos->add($dir)) { + $block = $lv->getBlock($pos->floor()); + if ($block->getId() != 0) break; + } + while ($block->getId() !=0) { + $block = $block->getSide(Vector3::SIDE_UP); + } + return $block; + } + + protected function buildPortal($center,$dir) { + $lv = $center->getLevel(); + $x = $center->getX(); + $y = $center->getY(); + $z = $center->getZ(); + + $border = Block::get($this->border); + $center = Block::get($this->center); + + $x_off = $z_off = 0; $mx_off=0; $mz_off = 0; + if (abs($dir->getX()) > abs(($dir->getZ()))) { + $x_off = 0; $z_off = 1; + $mx_off = 1; $mz_off =0; + + $corner1 = Block::get($this->corner,3); + $corner2 = Block::get($this->corner,2); + $corner3 = Block::get($this->corner,7); + $corner4 = Block::get($this->corner,6); + $front = Block::get($this->corner,1); + $back = Block::get($this->corner,0); + } else { + $x_off = 1; $z_off = 0; + $mx_off = 0; $mz_off =1; + + $corner1 = Block::get($this->corner,1); + $corner2 = Block::get($this->corner,0); + $corner3 = Block::get($this->corner,5); + $corner4 = Block::get($this->corner,4); + $front = Block::get($this->corner,3); + $back = Block::get($this->corner,2); + } + + $lv->setBlock(new Vector3($x,$y+4,$z),$border); + $lv->setBlock(new Vector3($x+$x_off,$y+4,$z+$z_off),$border); + $lv->setBlock(new Vector3($x-$x_off,$y+4,$z-$z_off),$border); + $lv->setBlock(new Vector3($x+$x_off*2,$y+4,$z+$z_off*2),$corner1); + $lv->setBlock(new Vector3($x-$x_off*2,$y+4,$z-$z_off*2),$corner2); + + $lv->setBlock(new Vector3($x+$x_off*2,$y,$z+$z_off*2),$corner3); + $lv->setBlock(new Vector3($x-$x_off*2,$y,$z-$z_off*2),$corner4); + $lv->setBlock(new Vector3($x,$y,$z),$center); + $lv->setBlock(new Vector3($x+$x_off,$y,$z+$z_off),$center); + $lv->setBlock(new Vector3($x-$x_off,$y,$z-$z_off),$center); + + $lv->setBlock(new Vector3($x+$mx_off,$y,$z+$mz_off),$front); + $lv->setBlock(new Vector3($x+$mx_off+$x_off,$y,$z+$mz_off+$z_off),$front); + $lv->setBlock(new Vector3($x+$mx_off-$x_off,$y,$z+$mz_off-$z_off),$front); + + $lv->setBlock(new Vector3($x-$mx_off,$y,$z-$mz_off),$back); + $lv->setBlock(new Vector3($x-$mx_off+$x_off,$y,$z-$mz_off+$z_off),$back); + $lv->setBlock(new Vector3($x-$mx_off-$x_off,$y,$z-$mz_off-$z_off),$back); + + for ($i=1;$i<=3;++$i) { + $lv->setBlock(new Vector3($x-$x_off*2,$y+$i,$z-$z_off*2),$border); + $lv->setBlock(new Vector3($x+$x_off*2,$y+$i,$z+$z_off*2),$border); + for($j=-1;$j<=1;++$j) { + $lv->setBlock(new Vector3($x+$x_off*$j,$y+$i,$z+$z_off*$j),$center); + } + } + + $bb1 = [ $x-$x_off, $y, $z-$z_off, $x+$x_off+1, $y+4,$z+$z_off+1 ]; + $bb2 = [ $x-$x_off*2, $y, $z-$z_off*2, $x+$x_off*2+1, $y+5,$z+$z_off*2+1 ]; + return [$bb1,$bb2]; + } + + protected function saveCfg() { + $yaml=new Config($this->getDataFolder()."portals.yml",Config::YAML,[]); + $yaml->setAll($this->portals); + $yaml->save(); + } + + + public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { + switch($cmd->getName()) { + case "mtp": + if (!$this->inGame($sender)) return true; + $dest = $this->checkTarget($args); + if (!$dest) { + $sender->sendMessage(TextFormat::RED."Invalid target for portal"); + return true; + } + $bl = $this->targetPos($sender,$sender->getDirectionVector()); + list($bb1,$bb2) = $this->buildPortal($bl,$sender->getDirectionVector()); + $lv = $sender->getLevel()->getName(); + if (!isset($this->portals[$lv])) $this->portals[$lv] = []; + $this->portals[$lv][] = [ $bb1, $bb2, $args ]; + $this->saveCfg(); + return true; + } + return false; + } + + public function onMove(PlayerMoveEvent $ev) { + if ($ev->isCancelled()) return; + $pl = $ev->getPlayer(); + $l = $pl->getLevel(); + $world = $l->getName(); + + if (!isset($this->portals[$world])) return; + + $x = $ev->getTo()->getX(); + $y = $ev->getTo()->getY(); + $z = $ev->getTo()->getZ(); + + foreach ($this->portals[$world] as $p) { + list($bb1,$bb2,$target) = $p; + if ($bb1[0] <= $x && $bb1[1] <= $y && $bb1[2] <= $z && + $x <= $bb1[3] && $y <= $bb1[4] && $z <= $bb1[5]) { + + $dest = $this->checkTarget($target); + if (!$dest) { + $pl->sendMessage("Nothing happens!"); + return; + } + if ($dest instanceof Vector3) { + $pl->sendMessage("Teleporting..."); + if (($mw = $this->getServer()->getPluginManager()->getPlugin("ManyWorlds")) != null) { + $mw->mwtp($pl,$dest); + } else { + $pl->teleport($dest); + } + return; + } + // If it is not a position + $ft = $this->getServer()->getPluginManager()->getPlugin("FastTransfer"); + if (!$ft) { + $this->getLogger()->info(TextFormat::RED."FAST TRANSFER NOT INSTALLED"); + $pl->sendMessage("Nothing happens!"); + $pl->sendMessage(TextFormat::RED."Somebody removed FastTransfer!"); + return; + } + list($addr,$port) = $dest; + $this->getLogger()->info(TextFormat::RED."FastTransfer being used hope it works!"); + $this->getLogger()->info("- Player: ".$pl->getName()." => ". + $addr.":".$port); + $ft->transferPlayer($pl,$addr,$port); + return; + } + } + } + + public function onBlockBreak(BlockBreakEvent $ev){ + if ($ev->isCancelled()) return; + $bl = $ev->getBlock(); + $l = $bl->getLevel(); + if (!$l) return; + $world = $l->getName(); + if (!isset($this->portals[$world])) return; + + $x = $bl->getX(); + $y = $bl->getY(); + $z = $bl->getZ(); + + foreach ($this->portals[$world] as $i=>$p) { + list($bb1,$bb2,$target) = $p; + if ($bb2[0] <= $x && $bb2[1] <= $y && $bb2[2] <= $z && + $x <= $bb2[3] && $y <= $bb2[4] && $z <= $bb2[5]) { + // Breaking a portal! + $air = Block::get(Block::AIR); + for($bx=$bb1[0];$bx<$bb1[3];$bx++) { + for($by=$bb1[1];$by<$bb1[4];$by++) { + for($bz=$bb1[2];$bz<$bb1[5];$bz++) { + $l->setBlock(new Vector3($bx,$by,$bz),$air); + } + } + } + $pl = $ev->getPlayer(); + $pl->sendMessage("Portal broken!"); + unset($this->portals[$world][$i]); + $this->saveCfg(); + return; + } + } + } +}