From 18bff977b1c1a2fa0c43e166082a7370f47652f4 Mon Sep 17 00:00:00 2001 From: Luke Darling Date: Tue, 8 Mar 2016 21:33:15 -0500 Subject: [PATCH] Updated for PHP 7, fixed many bugs, and added list subcommand --- plugin.yml | 27 ++++++++++---------------- src/LDX/BanItem/Main.php | 41 +++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/plugin.yml b/plugin.yml index 2424b35..9f9bdf3 100644 --- a/plugin.yml +++ b/plugin.yml @@ -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 " + banitem: + description: "BanItem main command." + permission: banitem.command.banitem + usage: "/banitem [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." \ No newline at end of file diff --git a/src/LDX/BanItem/Main.php b/src/LDX/BanItem/Main.php index 1b1abb9..62ecde1 100644 --- a/src/LDX/BanItem/Main.php +++ b/src/LDX/BanItem/Main.php @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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; } @@ -134,4 +141,4 @@ public function saveItems() { } } -?> +?> \ No newline at end of file