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

Commit

Permalink
MagicTelePortal-1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Jun 7, 2015
1 parent 7618a12 commit 1283983
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 35 deletions.
17 changes: 8 additions & 9 deletions MagicTelePortal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
* Plugin Access: Commands, Data Saving, World Editing
* WebSite: [github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/MagicTelePortal)

Overview
--------
## Overview

**DO NOT POST QUESTION/BUG-REPORTS/REQUESTS IN THE REVIEWS**

Expand Down Expand Up @@ -64,20 +63,21 @@ corner: 114
[/CODE]
```

### Permission Nodes:
### Permission Nodes

* mtp.cmd.mtp: Permission to create portals
* mtp.destroy: Permission to destroy portals

FAQ
---
## FAQ


* Q: How do I prevent people from breaking my portal?
* A: Use an anti-grief plugin or the `mtp.destroy` permission.

Changes
-------
## Changes

* 1.3.1 : More fixes
* Fixed the double teleport issue.
* 1.3.0 : Bug-fix
* Removed `manyworld` dependancy
* Added a base to the portal (so water won't leak)
Expand All @@ -93,8 +93,7 @@ Changes
* Some configuration options
* 1.0.0 : First submission

Copyright
---------
## Copyright

MagicTelePortal
Copyright (C) 2015 Alejandro Liu
Expand Down
2 changes: 1 addition & 1 deletion MagicTelePortal/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load: POSTWORLD

name: MagicTelePortal
description: A simple portal plugin
version: 1.3.0
version: 1.3.1
author: aliuly

commands:
Expand Down
1 change: 1 addition & 0 deletions MagicTelePortal/resources/messages/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"Somebody removed FastTransfer!"=""
"Spectator"=""
"Survival"=""
"Teleporting..."=""
"You are not allowed to do that!"=""
"You can only do this in-game"=""
"You do not have permission to do that."=""
Expand Down
3 changes: 2 additions & 1 deletion MagicTelePortal/resources/messages/spa.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"Invalid target for portal"="Destino del portal no es reconocido"
"Nothing happens!"="No pasa nada!"
"Portal broken!"="Portal roto!"
"Somebody removed FastTransfer!"="Alguien borró FastTransfer"
"Somebody removed FastTransfer!"="Alguien borró FastTransfer"
"Spectator"="Espectador"
"Survival"="Supervivencia"
"Teleporting..."="Teletransportando..."
"You are not allowed to do that!"="No puedes hacer eso!"
"You can only do this in-game"="Solo se puede hacer esto dentro del juego"
"You do not have permission to do that."="No tienes permiso para hacer eso."
73 changes: 49 additions & 24 deletions MagicTelePortal/src/aliuly/mtp/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@
use pocketmine\level\Position;
use pocketmine\utils\Config;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;

use aliuly\worldprotect\common\mc;
use aliuly\worldprotect\common\MPMU;
use aliuly\worldprotect\common\PluginCallbackTask;

class Main extends PluginBase implements CommandExecutor,Listener {
protected $portals;
protected $max_dist;
protected $border;
protected $center;
protected $corner;
protected $tweak;

public function onEnable(){
$this->tweak = [];
if (!is_dir($this->getDataFolder())) mkdir($this->getDataFolder());
mc::plugin_init($this,$this->getFile());
$this->getServer()->getPluginManager()->registerEvents($this, $this);
Expand Down Expand Up @@ -205,6 +209,10 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
}
return false;
}
public function onQuit(PlayerQuitEvent $ev) {
$n = strtolower($ev->getPlayer()->getName());
if (isset($this->tweak[$n])) unset($this->tweak[$n]);
}

public function onMove(PlayerMoveEvent $ev) {
if ($ev->isCancelled()) return;
Expand All @@ -228,35 +236,52 @@ public function onMove(PlayerMoveEvent $ev) {
$pl->sendMessage(mc::_("Nothing happens!"));
return;
}
if ($dest instanceof Vector3) {
$pl->sendMessage("Teleporting...");
$pl->teleport($dest);
return;
$n = strtolower($pl->getName());
$now = time();
if (isset($this->tweak[$n])) {
// Already in here...
if ($this->tweak[$n][0] > $now) return;
}
// If it is not a position
$ft = $this->getServer()->getPluginManager()->getPlugin("FastTransfer");
if (!$ft) {
$this->getLogger()->error(TextFormat::RED.mc::_("FAST TRANSFER NOT INSTALLED"));
$pl->sendMessage(mc::_("Nothing happens!"));
$pl->sendMessage(TextFormat::RED.mc::_("Somebody removed FastTransfer!"));
return;
}
list($addr,$port) = $dest;
$this->getLogger()->info(TextFormat::RED.mc::_("FastTransfer being used hope it works!"));
$this->getLogger()->info(mc::_("- Player: %1% => %2%:%3%",
$pl->getName(),$addr,$port));
$spawn = $pl->getLevel()->getSafeSpawn();

$ft->transferPlayer($pl,$addr,$port);

$pl->x = $spawn->x;
$pl->y = $spawn->y;
$pl->z = $spawn->z;

$this->tweak[$n] = [ $now + 3, $dest ];
$this->getServer()->getScheduler()->scheduleDelayedTask(
new PluginCallbackTask($this,[$this,"portalActiveSg1"],[$n]),
1);
return;
}
}
}
public function portalActiveSg1($n) {
if (!isset($this->tweak[$n])) return;
$pl = $this->getServer()->getPlayer($n);
if ($pl === null) return;
list(,$dest) = $this->tweak[$n];
unset($this->tweak[$n]);
if ($dest instanceof Vector3) {
$pl->sendMessage(mc::_("Teleporting..."));
$pl->teleport($dest);
return;
}
// If it is not a position... It is a FAST TRANSFER!

$ft = $this->getServer()->getPluginManager()->getPlugin("FastTransfer");
if (!$ft) {
$this->getLogger()->error(TextFormat::RED.mc::_("FAST TRANSFER NOT INSTALLED"));
$pl->sendMessage(mc::_("Nothing happens!"));
$pl->sendMessage(TextFormat::RED.mc::_("Somebody removed FastTransfer!"));
return;
}
// First we teleport to spawn to make sure that we do not enter
// this server in the portal location!
$spawn = $pl->getLevel()->getSafeSpawn();
$pl->teleport($spawn);

list($addr,$port) = $dest;
$this->getLogger()->info(TextFormat::RED.mc::_("FastTransfer being used hope it works!"));
$this->getLogger()->info(mc::_("- Player: %1% => %2%:%3%",
$pl->getName(),$addr,$port));

$ft->transferPlayer($pl,$addr,$port);
}

/**
* @priority HIGH
Expand Down
64 changes: 64 additions & 0 deletions MagicTelePortal/src/aliuly/mtp/common/PluginCallbackTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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.
*
* @author PocketMine Team
*
*
*/
namespace aliuly\mtp\common;

use pocketmine\scheduler\PluginTask;
use pocketmine\plugin\Plugin;

/**
* Allows the creation of simple callbacks with extra data
* The last parameter in the callback will be this object
*
*/
class PluginCallbackTask extends PluginTask{

/** @var callable */
protected $callable;

/** @var array */
protected $args;

/**
* @param Plugin $owner
* @param callable $callable
* @param array $args
*/
public function __construct(Plugin $owner, callable $callable, array $args = []){
parent::__construct($owner);
$this->callable = $callable;
$this->args = $args;
$this->args[] = $this;
}

/**
* @return callable
*/
public function getCallable(){
return $this->callable;
}

public function onRun($currentTicks){
$c = $this->callable;
$args = $this->args;
$args[] = $currentTicks;
$c(...$args);
}

}

0 comments on commit 1283983

Please sign in to comment.