-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprizon.php
132 lines (113 loc) · 4.22 KB
/
prizon.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/*
__PocketMine Plugin__
name=Prizon
description=Prizon
version=0.1
author=WreWolf
class=Prizon
apiversion=9
*/
/*
Small Changelog
===============
0.1:
*/
class Prizon implements Plugin
{
private $api, $prizons;
public function __construct(ServerAPI $api, $server = false)
{
$this->api = $api;
$this->interval = array();
}
public function init()
{
$this->createConfig();
$this->api->event('player.join', array($this, 'handle'));
$this->api->console->register('prizon', 'Jail player on the server.', array($this, 'commandH'));
$this->api->console->register('unprizon', 'Release player on the server.', array($this, 'commandH'));
$this->api->console->register('prizonlist', 'Prizon players on the server.', array($this, 'commandH'));
$this->api->console->register('setprizon', 'setprizon <x> <y> <z>', array($this, 'commandH'));
}
public function createConfig()
{
$default = array("prizon" => array("x" => 0, "y" => 0, "z" => 0), "users" => array());
$this->path = $this->api->plugin->createConfig($this, $default);
$this->prizons = $this->api->plugin->readYAML($this->path . "config.yml");
}
public function saveConfig()
{
$this->api->plugin->writeYAML($this->path . "config.yml", $this->prizons);
}
public function commandH($cmd, $params, $issuer, $alias)
{
$output = "";
switch ($cmd) {
case 'setprizon':
array_push($this->prizons['users'], $issuer->username);
$this->prizons['prizon']['x'] = $issuer->entity->x;
$this->prizons['prizon']['y'] = $issuer->entity->y;
$this->prizons['prizon']['z'] = $issuer->entity->z;
$this->saveConfig();
$this->api->chat->sendTo(false, "Prison position seted", $issuer->username);
break;
case 'prizon':
$user = $this->api->player->get($params[0]);
if ($user instanceof Player) {
array_push($this->prizons['users'], $user->username);
$this->saveConfig();
$level = $this->api->level->getDefault();
$prisonPos = new Position($this->prizons['prizon']['x'], $this->prizons['prizon']['y'], $this->prizons['prizon']['z'], $level);
$user->setSpawn($prisonPos);
$user->teleport($prisonPos);
$this->api->chat->broadcast("User " . $user->username . " jailed by " . $issuer->username);
}
break;
case "unprizon":
$user = $this->api->player->get($params[0]);
if ($user instanceof Player) {
$this->prizons['users'] = array_diff($this->prizons['users'], array($user->username));
$this->saveConfig();
$level = $this->api->level->getDefault();
$user->setSpawn($level->getSpawn());
$user->teleport($level->getSpawn());
$this->api->chat->broadcast("User " . $user->username . " released from jail by " . $issuer->username);
}
break;
case "prizonlist":
$x = $this->prizons['prizon']['x'];
$y = $this->prizons['prizon']['y'];
$z = $this->prizons['prizon']['z'];
$output = "Prizon position ($x, $y, $z) \n ";
foreach ($this->prizons['users'] as $users) {
$output .= $users . ", ";
}
break;
}
return $output;
}
public function __destruct()
{
}
public function handle(&$data, $event)
{
switch ($event) {
case "player.join":
$time_start= microtime(true);
//console("[debug] join " . $data->username);
$level = $this->api->level->getDefault();
$prisonPos = new Position($this->prizons['prizon']['x'], $this->prizons['prizon']['y'], $this->prizons['prizon']['z'], $level);
$user = $data->username;
if (in_array($user, $this->prizons['users'])) {
$target = $this->api->player->get($user);
if(!isset($target)) break;
$target->setSpawn($prisonPos);
$target->teleport($prisonPos);
}
$time = microtime(true) - $time_start;
console("prizone registered. runtime: $time");
break;
}
}
}