1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

God mode plugin

Discussion in 'Development' started by FresherGAMING, Aug 22, 2021.

  1. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    42
    GitHub:
    FresherGAMING
    I'm trying to create god mode plugin, the god mode enabled and disabled message is shown but I'm still taking damage


    My code :

    In main :
    PHP:
           public function onHurt(EntityDamageEvent $hurt){
               
    $hurted $hurt->getEntity();
                  if(isset(
    $this->god[$hurted->getName()])){
                     
    $hurt->setCancelled(true);
                  }
           }
    In commands\godcmd :
    PHP:
    class GodCmd extends PluginCommand {
     
        public 
    $god = [];
          
           public function 
    __construct(string $nameLytraSystem $plugin){
               
    parent::__construct($name$plugin);
               
    $this->setDescription("Toggle god mode");
               
    $this->plugin $plugin;
           }
          
           public function 
    execute(CommandSender $senderstring $alias, array $args) : bool{
               if(!
    $sender->hasPermission("godmode.toggle")){
               
    $sender->sendMessage("No perm!");
               return 
    false;
               }
               if(!
    $sender instanceof Player){
                  
    $sender->sendMessage("§cConsole cant use this command");
                  return 
    false;
               }
               if(isset(
    $this->god[$sender->getName()])){
                  unset(
    $this->god[$sender->getName()]);
                  
    $sender->sendMessage("§cGod mode has been disabled");
                  return 
    true;
               } else {
                  
    $this->god[$sender->getName()] = $sender->getName();
                  
    $sender->sendMessage("§bGod mode has been enabled");
                  return 
    true;
               }
           }
    }
     
  2. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    42
    GitHub:
    FresherGAMING
    I've use the main class too
     
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    The array $god is in a different location :facepalm:
     
    Agent and Primus like this.
  4. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    42
    GitHub:
    FresherGAMING
    I've know where the problem, te problem is just I didn't put $plugin, thanks for helping me
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.