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

Commit

Permalink
Importing 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Aug 26, 2016
1 parent 1d55a2f commit 196c42d
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 2 deletions.
115 changes: 113 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,113 @@
# SignWarp
PocketMine-MP plugin for teleportation
SignWarp
========

* Summary: Warp between places using signs
* Dependency Plugins: n/a
* PocketMine-MP version: 1.4 - API 1.10.0
* OptionalPlugins: ManyWorlds
* Categories: Teleportation
* Plugin Access: Commands, Tile Entities, Items/Blocks
* WebSite: [github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/SignWarp)

Overview
--------

A very basic Plugin implementing simple _Sign_ based warps.

Basic Usage:

Place a Sign with the following text:

[SWARP]
x y z

Where `x`, `y` and `z` are numbers containing the target warp
coordinates.

Or for a warp between worlds:

[WORLD]
world_name
x y z

Where `world_name` is the world to warp to, and *optionally* the
`x`, `y` and `z` warp location.

Documentation
-------------

This plugin implements _warps_ through the placement of _signs_. You
need to create a sign with the text:

[SWARP]
x y z

`x`, `y` and `z` are integers containing the target coordinates for
this warp.

To activate a _warp_ the player must touch a sign. That will teleport
the player to the new location described by the `x`, `y`, `z`
coordinates.

The third and four lines of the sign are ignored and can be used to
describe the _warp_.

To teleport between worlds, the sign text should look like:

[WORLD]
world_name
x y z

`world_name` is the target world to teleport to. `x`, `y`, `z` is the
target location. If not specified it defaults to the `spawn` world.

The fourth line of the sign is ignored and can be contain any
descriptive text.

To help identify potential _warp_ targets, the command `xyz` is
provided. Entering `/xyz` in-game will display the current
coordinates of the player.

### Permission Nodes:

* signwarp.cmd.xyz - Allows the user to show current x,y,z coordinates
* signwarp.place.sign - Allow user to create warp signs
* signwarp.touch.sign - Allow user to use warp signs

TODO
----

* Add support for MultipleWorlds:
* to spawn point
* to a specific x,y,z coordinate

Changes
-------

* 1.1.0 :
* Added support for multiple worlds
* Added permissions for teleporting
* 1.0.0 : First release

Copyright
=========

SignWarp
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 <http://www.gnu.org/licenses/>.

128 70 128
X:-100 Y:69 Z:1072
Binary file added media/SignWarp-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: SignWarp
api: 1.10.0
version: 1.0.0
load: POSTWORLD
main: alejandroliu\SignWarp\Main
author: aliuly

commands:
xyz:
description: Return x,y,z coordinates
usage: "/xyz"

permissions:
signwarp.place.sign:
default: op
description: "Allow user to create warp"
signwarp.touch.sign:
default: true
description: "Allow user to use warp"
signwarp.cmd.xyz:
default: true
description: "Shows current x,y,z coordinates"
183 changes: 183 additions & 0 deletions src/alejandroliu/SignWarp/Main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php

namespace alejandroliu\SignWarp;

use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\Server;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\math\Vector3;
use pocketmine\tile\Sign;
use pocketmine\event\block\SignChangeEvent;
/** Not currently used but may be later used */
use pocketmine\level\Position;
use pocketmine\entity\Entity;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\item\Item;
use pocketmine\tile\Tile;
use pocketmine\Player;

class Main extends PluginBase implements Listener {
const MAX_COORD = 30000000;
const MIN_COORD = -30000000;
const MAX_HEIGHT = 128;
const MIN_HEIGHT = 0;

const SHORT_WARP = "[SWARP]";
const LONG_WARP = "[WORLD]";

//** private $api, $server, $path;

private function check_coords($line,array &$vec) {
$mv = array();
if (!preg_match('/^\s*(-?\d+)\s+(-?\d+)\s+(-?\d+)\s*$/',$line,$mv))
return false;

list($line,$x,$y,$z) = $mv;

//$this->getLogger()->info("x=$x y=$y z=$z");

if ($x <= self::MIN_COORD || $z <= self::MIN_COORD) return false;
if ($x >= self::MAX_COORD || $z >= self::MAX_COORD) return false;
if ($y <= self::MIN_HEIGHT || $y >= self::MAX_HEIGHT) return false;
$vec = [$x,$y,$z];
return true;
}
public function onEnable(){
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}

private function shortWarp(PlayerInteractEvent $event,$sign){
if(empty($sign[1])){
$event->getPlayer()->sendMessage("[SignWarp] Missing coordinates");
return;
}
$mv = [];
if (!$this->check_coords($sign[1],$mv)) {
$event->getPlayer()->sendMessage("[SignWarp] Invalid coordinates ".$sign[1]);
return;
}
if(!$event->getPlayer()->hasPermission("signwarp.touch.sign")) {
$event->getPlayer()->sendMessage("Nothing happens...");
return;
}
list($x,$y,$z) = $mv;
$event->getPlayer()->sendMessage("Warping to $x,$y,$z...");
$event->getPlayer()->teleport(new Vector3($x,$y,$z));
Server::getInstance()->broadcastMessage($event->getPlayer()->getName()." teleported!");
}
private function longWarp(PlayerInteractEvent $event,$sign){
if(empty($sign[1])){
$event->getPlayer()->sendMessage("[SignWarp] Missing world name");
return;
}
if (!$this->getServer()->isLevelGenerated($sign[1])) {
$event->getPlayer()->sendMessage("[SignWarp] World \"".$sign[1]."\" does not exist!");
return;
}
if(!$event->getPlayer()->hasPermission("signwarp.touch.sign")) {
$event->getPlayer()->sendMessage("Nothing happens...");
return;
}
$level = $sign[1];
if (!$this->getServer()->isLevelLoaded($level)) {
$event->getPlayer()->sendMessage("[SignWarp] Preparing world \"$level\"");
if (!$this->getServer()->loadLevel($level)) {
$event->getPlayer()->sendMessage("[SignWarp] Unable to load World \"$level\"");
return;
}
}
$mv = [];
if ($this->check_coords($sign[2],$mv)) {
list($x,$y,$z) = $mv;
$mv = new Vector3($x,$y,$z);
} else {
$mv = null;
}
$event->getPlayer()->sendMessage("Teleporting...");
$world = $this->getServer()->getLevelByName($level);
$event->getPlayer()->teleport($world->getSafeSpawn($mv));
$this->getServer()->broadcastMessage($event->getPlayer()->getName()." teleported to $level");
}

public function playerBlockTouch(PlayerInteractEvent $event){
if($event->getBlock()->getID() == 323 || $event->getBlock()->getID() == 63 || $event->getBlock()->getID() == 68){
$sign = $event->getPlayer()->getLevel()->getTile($event->getBlock());
if(!($sign instanceof Sign)){
return;
}
$sign = $sign->getText();
if($sign[0]== self::SHORT_WARP){
$this->shortWarp($event,$sign);
} elseif ($sign[0]== self::LONG_WARP){
$this->longWarp($event,$sign);
}
}
}
private function breakSign(SignChangeEvent $event,$msg) {
$event->getPlayer()->sendMessage("[SignWarp] $msg");
$event->setLine(0,"[BROKEN]");
return false;
}

private function validateLongWarp(SignChangeEvent $event,$sign) {
if(!$event->getPlayer()->hasPermission("signwarp.place.sign"))
return $this->breakSign($event,"You are not allow to make Warp sign");
if(empty($sign[1]) === true)
return $this->breakSign($event,"World name not set");
if (!$this->getServer()->isLevelGenerated($sign[1]))
return $this->breakSign($event,"World \"".$sign[1]."\" does not exist!");
$event->getPlayer()->sendMessage("[SignWarp] Portal to world \"".$sign[1]."\" created!");
return true;
}
private function validateShortWarp(SignChangeEvent $event,$sign) {
if(!$event->getPlayer()->isOp())
return $this->breakSign($event,"You are not allow to make Warp sign");
if(empty($sign[1]) === true)
return $this->breakSign($event,"World name not set");
$mv = array();
if (!$this->check_coords($sign[1],$mv))
return $this->breakSign($event,"Invalid coordinates ".$sign[1]);

$event->getPlayer()->sendMessage("[SignWarp] Warp to ".implode(',',$mv)." created");
return true;
}

public function tileupdate(SignChangeEvent $event){
if($event->getBlock()->getID() == 323 || $event->getBlock()->getID() == 63 || $event->getBlock()->getID() == 68){
$sign = $event->getPlayer()->getLevel()->getTile($event->getBlock());
if(!($sign instanceof Sign)){
return true;
}
$sign = $event->getLines();
if($sign[0]==self::SHORT_WARP){
return $this->validateShortWarp($event,$sign);
} elseif($sign[0]==self::LONG_WARP){
return $this->validateLongWarp($event,$sign);
}
}
return true;
}

public function onCommand(CommandSender $sender,Command $cmd,$label, array $args) {
switch ($cmd->getName()) {
case "xyz":
if ($sender instanceof Player) {
if ($sender->hasPermission("signwarp.cmd.xyz")) {
$pos = $sender->getPosition();
$sender->sendMessage("You are at ".intval($pos->getX()).",".intval($pos->getY()).",".intval($pos->getZ()));
} else {
$sender->sendMessage("[SignWarp] You do not have permission to do that.");
}
} else {
$sender->sendMessage("[SignWarp] This command may only be used in-game");
}
return true;
}
return false;
}

}

0 comments on commit 196c42d

Please sign in to comment.