-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProtectItemFrame.php
106 lines (94 loc) · 3.57 KB
/
ProtectItemFrame.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
<?php
/**
* ____ _ _ ___
* | _ \ _ __ ___ ___ ___ _ __ | |_| |/ (_)_ __ ___
* | |_) | '__/ _ \/ __|/ _ \ '_ \| __| ' /| | '_ ` _ \
* | __/| | | __/\__ \ __/ | | | |_| . \| | | | | | |
* |_| |_| \___||___/\___|_| |_|\__|_|\_\_|_| |_| |_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the MIT License. see <https://opensource.org/licenses/MIT>.
*
*
* @author PresentKim ([email protected])
* @link https://github.com/PresentKim
* @license https://opensource.org/licenses/MIT MIT License
*
* @name ProtectItemFrame
* @main kim\present\singleton\ProtectItemFrame
* @version 1.1.0
* @api 3.0.0-ALPHA11
* @description Protect item frame by stick
*
* @DEPRECATED : Tile->namedtag was removed (Accoding to https://github.com/pmmp/PocketMine-MP/commit/fa21cd96c570a19dd4db3204779e24a163652f28)
*
* (\ /)
* ( . .) ♥
* c(")(")
*/
declare(strict_types=1);
namespace kim\present\singleton {
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\item\Item;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\permission\Permission;
use pocketmine\plugin\PluginBase;
use pocketmine\tile\ItemFrame;
use pocketmine\utils\TextFormat;
class ProtectItemFrame extends PluginBase implements Listener{
public const PROTECTED_NONE = 0;
public const PROTECTED_DROP = 1;
public const PROTECTED_ROTATE = 2;
public function onEnable() : void{
$this->getServer()->getPluginManager()->registerEvents($this, $this);
try{
Permission::loadPermission('itemframe.protect', [
'description' => 'Itemframe protect',
'children' => [
'itemframe.protect.make' => ['description' => 'Make itemframe protect'],
'itemframe.protect.drop' => ['description' => 'Drop itemframe item'],
'itemframe.protect.rotate' => ['description' => 'Rotate itemframe item'],
],
]);
}catch(\Exception $e){
}
}
/**
* @priority HIGHEST
*
* @param PlayerInteractEvent $event
*/
public function onPlayerInteractEvent(PlayerInteractEvent $event) : void{
if(!$event->isCancelled()){
$block = $event->getBlock();
$tile = $block->getLevel()->getTile($block);
if($tile instanceof ItemFrame && $tile->hasItem()){
$mode = $tile->namedtag->getTagValue('itemframe-protect', ByteTag::class, 0, true);
$player = $event->getPlayer();
if($event->getAction() === PlayerInteractEvent::LEFT_CLICK_BLOCK){
if($player->getInventory()->getItemInHand()->getId() === Item::STICK){
if($player->hasPermission('itemframe.protect.make')){
$tile->namedtag->setTagValue('itemframe-protect', ByteTag::class, $mode = ++$mode % 3, true);
if($mode === self::PROTECTED_DROP){
$player->sendMessage(TextFormat::GREEN . '[Protect] protected drop');
}elseif($mode === self::PROTECTED_ROTATE){
$player->sendMessage(TextFormat::GREEN . '[Protect] protected drop & rotate');
}else{
$player->sendMessage(TextFormat::DARK_GREEN . '[Protect] unprotected');
}
}else{
$player->sendMessage(TextFormat::RED . '[Protect] You don\'t have permission');
}
$event->setCancelled(true);
}elseif(($mode === self::PROTECTED_DROP || $mode === self::PROTECTED_ROTATE) && !$player->hasPermission('itemframe.protect.drop')){
$event->setCancelled(true);
}
}elseif($mode === self::PROTECTED_ROTATE && !$player->hasPermission('itemframe.protect.rotate')){
$event->setCancelled(true);
}
}
}
}
}
}