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

Commit

Permalink
Updated for PHP 7, fixed many bugs, and added list subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Darling committed Mar 9, 2016
1 parent c1825c8 commit 18bff97
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
27 changes: 10 additions & 17 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
name: BanItem
author: LDX
version: "2.1"
api: [1.0.0]
version: 2.2
api: [1.0.0, 2.0.0]
main: LDX\BanItem\Main
load: POSTWORLD
website: https://github.com/LDX-MCPE/BanItem
commands:
item:
description: "Bans or unbans an item."
permission: banitem.command.item
usage: "/item <ban/unban> <ID[:Damage]>"
banitem:
description: "BanItem main command."
permission: banitem.command.banitem
usage: "/banitem <ban/unban/list> [ID[:Damage]]"
permissions:
banitem:
default: false
description: "Allows access to all BanItem features."
children:
banitem.*:
default: false
description: "Allows access to all BanItem features."
banitem.bypass:
default: op
default: false
description: "Allows access to using banned items."
banitem.command:
default: false
description: "Allows access to all BanItem commands."
children:
banitem.command.*:
default: false
description: "Allows access to all BanItem commands."
children:
banitem.command.item:
default: op
description: "Allows access to the item command."
banitem.command.banitem:
default: op
description: "Allows access to the item command."
41 changes: 24 additions & 17 deletions src/LDX/BanItem/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function onEnable() {
public function onTouch(PlayerInteractEvent $event) {
$p = $event->getPlayer();
if($this->isBanned($event->getItem())) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
$p->sendMessage("[BanItem] That item is banned.");
$event->setCancelled();
}
Expand All @@ -34,7 +34,7 @@ public function onTouch(PlayerInteractEvent $event) {
public function onBlockPlace(BlockPlaceEvent $event) {
$p = $event->getPlayer();
if($this->isBanned($event->getItem())) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
$p->sendMessage("[BanItem] That item is banned.");
$event->setCancelled();
}
Expand All @@ -45,7 +45,7 @@ public function onHurt(EntityDamageEvent $event) {
if($event instanceof EntityDamageByEntityEvent && $event->getDamager() instanceof Player) {
$p = $event->getDamager();
if($this->isBanned($p->getInventory()->getItemInHand())) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
$p->sendMessage("[BanItem] That item is banned.");
$event->setCancelled();
}
Expand All @@ -56,7 +56,7 @@ public function onHurt(EntityDamageEvent $event) {
public function onEat(PlayerItemConsumeEvent $event) {
$p = $event->getPlayer();
if($this->isBanned($event->getItem())) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
$p->sendMessage("[BanItem] That item is banned.");
$event->setCancelled();
}
Expand All @@ -67,7 +67,7 @@ public function onShoot(EntityShootBowEvent $event) {
if($event->getEntity() instanceof Player) {
$p = $event->getEntity();
if($this->isBanned($event->getBow())) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
if(!($p->hasPermission("banitem") || $p->hasPermission("banitem.bypass"))) {
$p->sendMessage("[BanItem] That item is banned.");
$event->setCancelled();
}
Expand All @@ -76,38 +76,45 @@ public function onShoot(EntityShootBowEvent $event) {
}

public function onCommand(CommandSender $p,Command $cmd,$label,array $args) {
if(!isset($args[0]) || !isset($args[1])) {
if(!isset($args[0])) {
return false;
}
$item = explode(":",$args[1]);
if(!is_numeric($item[0]) || (isset($item[1]) && !is_numeric($item[1]))) {
$p->sendMessage("[BanItem] Please only use an item's ID value, and damage if needed.");
return true;
if(strtolower($args[0]) == "ban" || strtolower($args[0]) == "unban") {
if(!isset($args[1])) {
return false;
}
$item = explode(":",$args[1]);
if(!is_numeric($item[0]) || (isset($item[1]) && !is_numeric($item[1]))) {
$p->sendMessage("[BanItem] §cPlease only use an item's ID value, and damage if needed.");
return true;
}
}
if($args[0] == "ban") {
if(strtolower($args[0]) == "ban") {
$i = $item[0];
if(isset($item[1])) {
$i = $i . "#" . $item[1];
}
if(in_array($i,$this->items)) {
$p->sendMessage("[BanItem] That item is already banned.");
$p->sendMessage("[BanItem] §cThat item is already banned.");
} else {
array_push($this->items,$i);
$this->saveItems();
$p->sendMessage("[BanItem] The item " . str_replace("#",":",$i) . " has been banned.");
$p->sendMessage("[BanItem] §aThe item " . str_replace("#",":",$i) . " has been banned.");
}
} else if($args[0] == "unban") {
} else if(strtolower($args[0]) == "unban") {
$i = $item[0];
if(isset($item[1])) {
$i = $i . "#" . $item[1];
}
if(!in_array($i,$this->items)) {
$p->sendMessage("[BanItem] That item wasn't banned.");
$p->sendMessage("[BanItem] §cThat item wasn't banned.");
} else {
array_splice($this->items,array_search($i,$this->items),1);
$this->saveItems();
$p->sendMessage("[BanItem] The item " . str_replace("#",":",$i) . " has been unbanned.");
$p->sendMessage("[BanItem] §aThe item " . str_replace("#",":",$i) . " has been unbanned.");
}
} else if(strtolower($args[0]) == "list") {
$p->sendMessage("[BanItem] §eBanned item" . (count($this->items) == 1 ? "" : "s") . ": §f" . str_replace("#", ":", implode(", ", $this->items)) . (count($this->items) > 0 ? "." : "§7None."));
} else {
return false;
}
Expand All @@ -134,4 +141,4 @@ public function saveItems() {
}

}
?>
?>

0 comments on commit 18bff97

Please sign in to comment.