Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 3.0.0-ALPHA11 #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 19 additions & 18 deletions src/FantasyProtection/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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));
}
}
}
Expand All @@ -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));
}
}
}
Expand All @@ -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();
}
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/FantasyProtection/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
9 changes: 3 additions & 6 deletions src/FantasyProtection/ProtectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{

Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down