Skip to content
This repository was archived by the owner on Oct 21, 2018. It is now read-only.

Commit 18bff97

Browse files
author
Luke Darling
committed
Updated for PHP 7, fixed many bugs, and added list subcommand
1 parent c1825c8 commit 18bff97

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

plugin.yml

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
name: BanItem
22
author: LDX
3-
version: "2.1"
4-
api: [1.0.0]
3+
version: 2.2
4+
api: [1.0.0, 2.0.0]
55
main: LDX\BanItem\Main
66
load: POSTWORLD
77
website: https://github.com/LDX-MCPE/BanItem
88
commands:
9-
item:
10-
description: "Bans or unbans an item."
11-
permission: banitem.command.item
12-
usage: "/item <ban/unban> <ID[:Damage]>"
9+
banitem:
10+
description: "BanItem main command."
11+
permission: banitem.command.banitem
12+
usage: "/banitem <ban/unban/list> [ID[:Damage]]"
1313
permissions:
1414
banitem:
1515
default: false
1616
description: "Allows access to all BanItem features."
1717
children:
18-
banitem.*:
19-
default: false
20-
description: "Allows access to all BanItem features."
2118
banitem.bypass:
22-
default: op
19+
default: false
2320
description: "Allows access to using banned items."
2421
banitem.command:
2522
default: false
2623
description: "Allows access to all BanItem commands."
2724
children:
28-
banitem.command.*:
29-
default: false
30-
description: "Allows access to all BanItem commands."
31-
children:
32-
banitem.command.item:
33-
default: op
34-
description: "Allows access to the item command."
25+
banitem.command.banitem:
26+
default: op
27+
description: "Allows access to the item command."

src/LDX/BanItem/Main.php

+24-17
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function onEnable() {
2424
public function onTouch(PlayerInteractEvent $event) {
2525
$p = $event->getPlayer();
2626
if($this->isBanned($event->getItem())) {
27-
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
27+
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
2828
$p->sendMessage("[BanItem] That item is banned.");
2929
$event->setCancelled();
3030
}
@@ -34,7 +34,7 @@ public function onTouch(PlayerInteractEvent $event) {
3434
public function onBlockPlace(BlockPlaceEvent $event) {
3535
$p = $event->getPlayer();
3636
if($this->isBanned($event->getItem())) {
37-
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
37+
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
3838
$p->sendMessage("[BanItem] That item is banned.");
3939
$event->setCancelled();
4040
}
@@ -45,7 +45,7 @@ public function onHurt(EntityDamageEvent $event) {
4545
if($event instanceof EntityDamageByEntityEvent && $event->getDamager() instanceof Player) {
4646
$p = $event->getDamager();
4747
if($this->isBanned($p->getInventory()->getItemInHand())) {
48-
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
48+
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
4949
$p->sendMessage("[BanItem] That item is banned.");
5050
$event->setCancelled();
5151
}
@@ -56,7 +56,7 @@ public function onHurt(EntityDamageEvent $event) {
5656
public function onEat(PlayerItemConsumeEvent $event) {
5757
$p = $event->getPlayer();
5858
if($this->isBanned($event->getItem())) {
59-
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
59+
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
6060
$p->sendMessage("[BanItem] That item is banned.");
6161
$event->setCancelled();
6262
}
@@ -67,7 +67,7 @@ public function onShoot(EntityShootBowEvent $event) {
6767
if($event->getEntity() instanceof Player) {
6868
$p = $event->getEntity();
6969
if($this->isBanned($event->getBow())) {
70-
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
70+
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
7171
$p->sendMessage("[BanItem] That item is banned.");
7272
$event->setCancelled();
7373
}
@@ -76,38 +76,45 @@ public function onShoot(EntityShootBowEvent $event) {
7676
}
7777

7878
public function onCommand(CommandSender $p,Command $cmd,$label,array $args) {
79-
if(!isset($args[0]) || !isset($args[1])) {
79+
if(!isset($args[0])) {
8080
return false;
8181
}
82-
$item = explode(":",$args[1]);
83-
if(!is_numeric($item[0]) || (isset($item[1]) && !is_numeric($item[1]))) {
84-
$p->sendMessage("[BanItem] Please only use an item's ID value, and damage if needed.");
85-
return true;
82+
if(strtolower($args[0]) == "ban" || strtolower($args[0]) == "unban") {
83+
if(!isset($args[1])) {
84+
return false;
85+
}
86+
$item = explode(":",$args[1]);
87+
if(!is_numeric($item[0]) || (isset($item[1]) && !is_numeric($item[1]))) {
88+
$p->sendMessage("[BanItem] §cPlease only use an item's ID value, and damage if needed.");
89+
return true;
90+
}
8691
}
87-
if($args[0] == "ban") {
92+
if(strtolower($args[0]) == "ban") {
8893
$i = $item[0];
8994
if(isset($item[1])) {
9095
$i = $i . "#" . $item[1];
9196
}
9297
if(in_array($i,$this->items)) {
93-
$p->sendMessage("[BanItem] That item is already banned.");
98+
$p->sendMessage("[BanItem] §cThat item is already banned.");
9499
} else {
95100
array_push($this->items,$i);
96101
$this->saveItems();
97-
$p->sendMessage("[BanItem] The item " . str_replace("#",":",$i) . " has been banned.");
102+
$p->sendMessage("[BanItem] §aThe item " . str_replace("#",":",$i) . " has been banned.");
98103
}
99-
} else if($args[0] == "unban") {
104+
} else if(strtolower($args[0]) == "unban") {
100105
$i = $item[0];
101106
if(isset($item[1])) {
102107
$i = $i . "#" . $item[1];
103108
}
104109
if(!in_array($i,$this->items)) {
105-
$p->sendMessage("[BanItem] That item wasn't banned.");
110+
$p->sendMessage("[BanItem] §cThat item wasn't banned.");
106111
} else {
107112
array_splice($this->items,array_search($i,$this->items),1);
108113
$this->saveItems();
109-
$p->sendMessage("[BanItem] The item " . str_replace("#",":",$i) . " has been unbanned.");
114+
$p->sendMessage("[BanItem] §aThe item " . str_replace("#",":",$i) . " has been unbanned.");
110115
}
116+
} else if(strtolower($args[0]) == "list") {
117+
$p->sendMessage("[BanItem] §eBanned item" . (count($this->items) == 1 ? "" : "s") . ": §f" . str_replace("#", ":", implode(", ", $this->items)) . (count($this->items) > 0 ? "." : "§7None."));
111118
} else {
112119
return false;
113120
}
@@ -134,4 +141,4 @@ public function saveItems() {
134141
}
135142

136143
}
137-
?>
144+
?>

0 commit comments

Comments
 (0)