Skip to content

Commit 496c775

Browse files
authored
Add files via upload
1 parent 79a78a0 commit 496c775

File tree

1 file changed

+75
-51
lines changed

1 file changed

+75
-51
lines changed

src/Ree/elevator/main.php

Lines changed: 75 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,36 @@ class main extends PluginBase implements Listener
1515
{
1616
const block = 42;
1717
const elevator = 148;
18-
19-
public function onEnable ()
18+
19+
public function onEnable()
2020
{
21-
$this->getLogger()->info(">>loading now...");
21+
$this->getLogger()->info("loading now...");
2222
$this->getServer()->getPluginManager()->registerEvents($this, $this);
23-
$this->elevator = new Config($this->getDataFolder() . "elevator.yml" ,Config::YAML ,array(
23+
$this->elevator = new Config($this->getDataFolder() . "elevator.yml", Config::YAML, array(
2424
'Authority required for use//使用に必要な権限[op or true]' => 'op',
25-
'Available world//使用可能なワールド[string]' => 'world,lobby'
26-
));
25+
'Available world//使用可能なワールド[string]' => 'world,lobby',
26+
'message//メッセージ[true or false]' => 'true'
27+
));
28+
$this->authority = $this->elevator->get("Authority required for use//使用に必要な権限[op or true]");
2729
$this->world = $this->elevator->get("Available world//使用可能なワールド[string]");
28-
$this->world = explode("," , $this->world);
30+
$this->world = explode(",", $this->world);
31+
$this->message = $this->elevator->get("message//メッセージ[true or false]");
2932
}
3033

31-
public function onJump (PlayerJumpEvent $ev)
34+
private function elevator($level, $x, $y, $z)
35+
{
36+
$vector3 = new Vector3($x, $y, $z);
37+
38+
if (self::elevator == $level->getBlock(new Vector3($x, $y, $z))->getId()) {
39+
if (self::block == $level->getBlock(new Vector3($x, $y - 1, $z))->getId()) {
40+
return true;
41+
}
42+
}
43+
44+
return false;
45+
}
46+
47+
public function onJump(PlayerJumpEvent $ev)
3248
{
3349
$p = $ev->getPlayer();
3450
$n = $p->getName();
@@ -37,31 +53,29 @@ public function onJump (PlayerJumpEvent $ev)
3753
$y = $p->getY();
3854
$z = $p->getZ();
3955

40-
foreach($this->world as $world)
41-
{
42-
$world = $this->getServer()->getLevelByName($world);
43-
if($level == $world)
44-
{
45-
if($this->elevator($level ,$x ,$y ,$z))
46-
{
47-
for($i = 2 ;$i <= 15 ;$i++)
48-
{
49-
if(self::elevator == $level->getBlock(new Vector3($x ,$y + $i ,$z))->getId())
50-
{
51-
if(self::block == $level->getBlock(new Vector3($x ,$y + $i - 1 ,$z))->getId())
52-
{
53-
$p->teleport(new Vector3($x ,$y + $i ,$z));
54-
$p->sendMessage("エレベーターを使用して".$i."ブロック上がりました");
55-
break;
56-
}
57-
}
58-
}
56+
if($this->request($p)) {
57+
foreach ($this->world as $world) {
58+
$world = $this->getServer()->getLevelByName($world);
59+
if ($level == $world) {
60+
if ($this->elevator($level, $x, $y, $z)) {
61+
for ($i = 2; $i <= 15; $i++) {
62+
if (self::elevator == $level->getBlock(new Vector3($x, $y + $i, $z))->getId()) {
63+
if (self::block == $level->getBlock(new Vector3($x, $y + $i - 1, $z))->getId()) {
64+
$p->teleport(new Vector3($x, $y + $i, $z));
65+
if ($this->message === true) {
66+
$p->sendMessage("エレベーターを使用して" . $i . "ブロック上がりました");
67+
}
68+
break;
69+
}
70+
}
71+
}
72+
}
5973
}
6074
}
6175
}
6276
}
6377

64-
public function onSneak (PlayerToggleSneakEvent $ev)
78+
public function onSneak(PlayerToggleSneakEvent $ev)
6579
{
6680
$p = $ev->getPlayer();
6781
$n = $p->getName();
@@ -70,42 +84,52 @@ public function onSneak (PlayerToggleSneakEvent $ev)
7084
$y = $p->getY();
7185
$z = $p->getZ();
7286

73-
foreach($this->world as $world)
87+
if(empty($this->sneak[$n]))
7488
{
75-
$world = $this->getServer()->getLevelByName($world);
76-
if($level == $world)
77-
{
78-
if($this->elevator($level ,$x ,$y ,$z))
79-
{
80-
for ($i = 2; $i <= 15; $i++)
81-
{
82-
if (self::elevator == $level->getBlock(new Vector3($x, $y - $i, $z))->getId())
83-
{
84-
if (self::block == $level->getBlock(new Vector3($x, $y - $i - 1, $z))->getId())
85-
{
86-
$p->teleport(new Vector3($x, $y - $i, $z));
87-
$p->sendMessage("エレベーターを使用して" . $i . "ブロック下りました");
88-
break;
89+
$this->sneak[$n] = true;
90+
}
91+
92+
if ($ev->isSneaking()) {
93+
if($this->request($p)) {
94+
if ($this->sneak[$n]) {
95+
foreach ($this->world as $world) {
96+
$world = $this->getServer()->getLevelByName($world);
97+
if ($level == $world) {
98+
if ($this->elevator($level, $x, $y, $z)) {
99+
for ($i = 2; $i <= 15; $i++) {
100+
if (self::elevator == $level->getBlock(new Vector3($x, $y - $i, $z))->getId()) {
101+
if (self::block == $level->getBlock(new Vector3($x, $y - $i - 1, $z))->getId()) {
102+
$p->teleport(new Vector3($x, $y - $i, $z));
103+
if ($this->message === true) {
104+
$p->sendMessage("エレベーターを使用して" . $i . "ブロック下りました");
105+
}
106+
$this->sneak[$n] = false;
107+
break;
108+
}
109+
}
110+
}
89111
}
90112
}
91113
}
92114
}
93115
}
116+
} else {
117+
$this->sneak[$n] = true;
94118
}
95119
}
96120

97-
private function elevator ($level ,$x ,$y ,$z)
121+
private function request ($p)
98122
{
99-
$vector3 = new Vector3($x ,$y ,$z);
100-
101-
if(self::elevator == $level->getBlock(new Vector3($x ,$y ,$z))->getId())
123+
if($this->authority)
102124
{
103-
if(self::block == $level->getBlock(new Vector3($x ,$y - 1 ,$z))->getId())
125+
return true;
126+
}else{
127+
if($p->isOp())
104128
{
105129
return true;
130+
}else{
131+
return false;
106132
}
107133
}
108-
109-
return false;
110134
}
111-
}
135+
}

0 commit comments

Comments
 (0)