diff --git a/plugin.yml b/plugin.yml index 74c19e9..3c83b19 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: FantasyProtection version: 2.0 author: Enrick3344 main: FantasyProtection\Main -api: [3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9, 3.0.0-ALPHA10] +api: [3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9, 3.0.0-ALPHA10, 3.0.0-ALPHA11] permission: fantasyprotection.break.bypass: diff --git a/src/FantasyProtection/EventListener.php b/src/FantasyProtection/EventListener.php index 14ed21e..b0d83c9 100644 --- a/src/FantasyProtection/EventListener.php +++ b/src/FantasyProtection/EventListener.php @@ -40,11 +40,16 @@ class EventListener implements Listener{ /** @var Main */ private $plugin; + + private $prefix; + + /** * @param Main $plugin */ public function __construct(Main $plugin) { $this->plugin = $plugin; + $this->prefix = $this->plugin->getConfig()->get("Prefix"); } public function onExhaust(PlayerExhaustEvent $event){ $player = $event->getPlayer(); @@ -56,7 +61,6 @@ public function onExhaust(PlayerExhaustEvent $event){ } public function onBreak(BlockBreakEvent $event){ - $prefix = $this->plugin->getConfig()->get("Prefix"); $message = $this->plugin->getConfig()->get("Break-Message"); $lockmessage = $this->plugin->getConfig()->get("Lock-Message"); $player = $event->getPlayer(); @@ -65,19 +69,18 @@ public function onBreak(BlockBreakEvent $event){ $lock = $this->plugin->getConfig()->get("Lock"); if(in_array($world, $lock)){ $event->setCancelled(true); - $player->sendMessage($this->plugin->translateColors($prefix . " " . $lockmessage)); + $player->sendMessage($this->plugin->translateColors($this->prefix . " " . $lockmessage)); }elseif(in_array($world, $break)){ if($player->hasPermission("fantasyplus.break.bypass")){ return true; }else{ $event->setCancelled(); - $player->sendMessage($this->plugin->translateColors($prefix . " " . $message)); + $player->sendMessage($this->plugin->translateColors($this->prefix . " " . $message)); } } } public function onPlace(BlockPlaceEvent $event){ - $prefix = $this->plugin->getConfig()->get("Prefix"); $message = $this->plugin->getConfig()->get("Place-Message"); $lockmessage = $this->plugin->getConfig()->get("Lock-Message"); $player = $event->getPlayer(); @@ -86,19 +89,18 @@ public function onPlace(BlockPlaceEvent $event){ $lock = $this->plugin->getConfig()->get("Lock"); if(in_array($world, $lock)){ $event->setCancelled(true); - $player->sendMessage($this->plugin->translateColors($prefix . " " . $lockmessage)); + $player->sendMessage($this->plugin->translateColors($this->prefix . " " . $lockmessage)); }elseif(in_array($world, $place)){ if($player->hasPermission("fantasyprotection.place.bypass")){ return true; }else{ $event->setCancelled(); - $player->sendMessage($this->plugin->translateColors($prefix . " " . $message)); + $player->sendMessage($this->plugin->translateColors($this->prefix . " " . $message)); } } } public function onDrop(PlayerDropItemEvent $event){ - $prefix = $this->plugin->getConfig()->get("Prefix"); $message = $this->plugin->getConfig()->get("Drop-Message"); $player = $event->getPlayer(); $world = $player->getLevel()->getName(); @@ -109,7 +111,7 @@ public function onDrop(PlayerDropItemEvent $event){ return true; }else{ $event->setCancelled(); - $player->sendMessage($this->plugin->translateColors($prefix . " " . $message)); + $player->sendMessage($this->plugin->translateColors($this->prefix . " " . $message)); } } } @@ -125,7 +127,7 @@ public function onLevelChange(EntityLevelChangeEvent $event){ return true; }else{ $event->setCancelled(); - $player->sendMessage($this->plugin->translateColors($prefix . " " . $message)); + $player->sendMessage($this->plugin->translateColors($this->prefix . " " . $message)); } } } @@ -139,16 +141,15 @@ public function onHurt(EntityDamageEvent $event){ if(in_array($world, $damage)){ $event->setCancelled(); } - } - if($event->getEntity() instanceof Player && $event instanceof EntityDamageByEntityEvent) { - if($event->getDamager() instanceof Player){ - $prefix = $this->plugin->getConfig()->get("Prefix"); - $message = $this->plugin->getConfig()->get("PVP-Message"); - $pvp = $this->plugin->getConfig()->get("PVP"); + if($event->getEntity() instanceof Player && $event instanceof EntityDamageByEntityEvent){ $player = $event->getDamager(); - if(in_array($world, $pvp)){ - $event->getDamager()->sendMessage($this->plugin->translateColors($prefix . " " . $message)); - $event->setCancelled(); + if($player instanceof Player){ + $message = $this->plugin->getConfig()->get("PVP-Message"); + $pvp = $this->plugin->getConfig()->get("PVP"); + if(in_array($world, $pvp)){ + $player->sendMessage($this->plugin->translateColors($this->prefix . " " . $message)); + $event->setCancelled(); + } } } } diff --git a/src/FantasyProtection/Main.php b/src/FantasyProtection/Main.php index 01355ff..dbcde04 100644 --- a/src/FantasyProtection/Main.php +++ b/src/FantasyProtection/Main.php @@ -25,12 +25,7 @@ namespace FantasyProtection; use pocketmine\plugin\PluginBase; -use pocketmine\Player; -use pocketmine\Server; -use pocketmine\utils\Config; use pocketmine\utils\TextFormat; -//Plugin File -use FantasyProtection\ProtectionCommand; class Main extends PluginBase{ diff --git a/src/FantasyProtection/ProtectionCommand.php b/src/FantasyProtection/ProtectionCommand.php index 0a8492d..b61b3e7 100644 --- a/src/FantasyProtection/ProtectionCommand.php +++ b/src/FantasyProtection/ProtectionCommand.php @@ -26,11 +26,8 @@ use pocketmine\command\Command; use pocketmine\command\CommandSender; -use pocketmine\utils\TextFormat; use pocketmine\Player; -use pocketmine\level\Level; //Plugins Files. -use FantasyProtection\Main; class ProtectionCommand extends Command{ @@ -46,7 +43,7 @@ public function __construct(Main $plugin){ } public function execute(CommandSender $sender, string $label, array $args) : bool{ - if(isset($args[0])){ + if(isset($args[0]) and $sender instanceof Player){ switch($args[0]){ case "placing":{ if(count($args) == 2) { @@ -251,7 +248,7 @@ public function execute(CommandSender $sender, string $label, array $args) : boo $world = $sender->getLevel()->getName(); $lock = $this->plugin->getConfig()->get("Lock"); if(in_array($world, $lock)){ - $sender->sendMessage("§r§f`•§5>§c Level ".$level." Is Already Locked!"); + $sender->sendMessage("§r§f`•§5>§c Level ".$world." Is Already Locked!"); break; } $level = $sender->getLevel()->getName(); @@ -284,7 +281,7 @@ public function execute(CommandSender $sender, string $label, array $args) : boo $this->plugin->getConfig()->save(); $sender->sendMessage("§r§f`•§5>§b You've sucessfully Unlocked Level " . $level); }else{ - $sender->sendMessage("§r§f`•§5>§c Level ".$level." Was not Locked!"); + $sender->sendMessage("§r§f`•§5>§c Level ".$world." Was not Locked!"); } } break;