-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplewarp.php
117 lines (105 loc) · 5.57 KB
/
simplewarp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/*
__PocketMine Plugin__
name=SimpleWarp
description=Simple plugin to create warps
version=0.2.3
author=Falk
class=SimpleWarp
apiversion=10,11,12,13
*/
class SimpleWarp implements Plugin {
private $api, $path;
private $config;
public function __construct(ServerAPI $api, $server = false) {
$this->api = $api;
}
public function init() {
$this->api->console->register("addwarp", "Create a new warp", array($this, "command"));
$this->api->console->register("delwarp", "Delete a warp", array($this, "command"));
$this->api->console->register("warp", "Warp to a location", array($this, "command"));
$this->api->console->register("openwarp", "Make a warp open to everyone", array($this, "command"));
$this->api->console->register("closewarp", "Make warp OPS only", array($this, "command"));
$this->config = new Config($this->api->plugin->configPath($this) . "warps.yml", CONFIG_YAML, array());
$this->api->ban->cmdWhitelist("warp");
console("[INFO] SimpleWarp Loaded!");
}
public function __destruct() {
}
public function command($cmd, $params, $issuer, $alias, $args) {
switch ($cmd) {
case "addwarp":
if (!($issuer instanceof Player)) return "Please run this command in-game.";
if (isset($params[0])) {
$data = $this->api->plugin->readYAML($this->api->plugin->configPath($this) . "warps.yml");
if (array_key_exists($params[0], $data)) return "[SimpleWarp] Warp exists with that name!";
else {
$x = round($issuer->entity->x);
$y = round($issuer->entity->y);
$z = round($issuer->entity->z);
$level = $issuer->level->getName();
$data[$params[0]] = array($x, $y, $z, $level);
$this->api->plugin->writeYAML($this->api->plugin->configPath($this) . "warps.yml", $data);
return "[SimpleWarp] Warp Added!";
}
} else return "Usage: /addwarp <NAME>";
break;
case "delwarp":
if (isset($params[0])) {
$data = $this->api->plugin->readYAML($this->api->plugin->configPath($this) . "warps.yml");
if (array_key_exists($params[0], $data)) {
unset($data[$params[0]]);
$this->api->plugin->writeYAML($this->api->plugin->configPath($this) . "warps.yml", $data);
return "[SimpleWarp] Warp removed!";
} else return "[SimpleWarp] Warp doesn't exist!";
} else return "Usage: /delwarp <NAME>";
break;
case "warp":
$data = $this->api->plugin->readYAML($this->api->plugin->configPath($this) . "warps.yml");
if (isset($params[0]) && $issuer instanceof Player) {
if (array_key_exists($params[0], $data)) {
$x = $data[$params[0]][0];
$y = $data[$params[0]][1];
$z = $data[$params[0]][2];
$status = $data[$params[0]][4];
if (($level = $this->api->level->get($data[$params[0]][3])) === false) return "[SimpleWarp] Warp level is not loaded";
if ($status === true) {
$issuer->teleport(new Position($x, $y, $z, $level));
return "[SimpleWarp] You have been warped to " . $params[0];
} else {
if ($this->api->ban->isOP($issuer->username) === true) {
$issuer->teleport(new Position($x, $y, $z, $level));
return "[SimpleWarp] You have been warped to " . $params[0];
} else return "[SimpleWarp] Warp is private";
}
} else return "[SimpleWarp] Warp doesn't exist!";
} else {
if (count($data) == 0) return "[SimpleWarp] No warps found.";
$ret = "Warp list: ";
foreach ($data as $n => $more) $ret .= $n . ", ";
return substr($ret, 0, strlen($ret) - 2);
}
break;
case "openwarp":
if (isset($params[0])) {
$data = $this->api->plugin->readYAML($this->api->plugin->configPath($this) . "warps.yml");
if (array_key_exists($params[0], $data)) {
$data[$params[0]][4] = true;
$this->api->plugin->writeYAML($this->api->plugin->configPath($this) . "warps.yml", $data);
return "[SimpleWarp] Warp Opened!";
} else return "[SimpleWarp] Warp doesn't exist!";
} else return "Usage: /openwarp <NAME>";
break;
case "closewarp":
if (isset($params[0])) {
$data = $this->api->plugin->readYAML($this->api->plugin->configPath($this) . "warps.yml");
if (array_key_exists($params[0], $data)) {
unset($data[$params[0]][4]);
$this->api->plugin->writeYAML($this->api->plugin->configPath($this) . "warps.yml", $data);
return "[SimpleWarp] Warp Closed";
} else return "[SimpleWarps] Warp doesn't exist!";
} else return "Usage: /closewarp <NAME>";
break;
}
}
}