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

how to make a leave command without plugin crashing

Discussion in 'Development' started by WEATHERCRAFTYT1, Jul 1, 2020.

  1. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    take a look at this code.

    PHP:
    public function onInteract(PlayerInteractEvent $event)

        {

            
    $player $event->getPlayer();

            
    $block $event->getBlock();

            
    $tile $player->getLevel()->getTile($block);

            

            if(
    $tile instanceof Sign)

            {

                if(
    $this->mode==26)

                {

                    
    $tile->setText(TE::AQUA "§a§l[§r§fJoin§a§l]§r§f",TE::YELLOW  "0 / 20","§b" $this->currentLevel,$this->prefix);

                    
    $this->refreshArenas();

                    
    $this->currentLevel "";

                    
    $this->mode 0;

                    
    $player->sendMessage($this->prefix "Arena Registered!");

                }

                else

                {

                    
    $text $tile->getText();

                    if(
    $text[3] == $this->prefix)

                      {

                        if(
    $text[0]==TE::AQUA "§a§l[§r§fJoin§a§l]§r§f")

                        {

                            

                            
    $config = new Config($this->getDataFolder() . "/config.yml"Config::YAML);

                                                    
    $slots = new Config($this->getDataFolder() . "/slots.yml"Config::YAML);

                                                    
    $namemap str_replace("§b"""$text[2]);

                            
    $level $this->getServer()->getLevelByName($namemap);

                                                    if(
    $slots->get("slot1".$namemap)==null)

                                                    {



                                                            
    $thespawn $config->get($namemap "Spawn1");

                                                            
    $slots->set("slot1".$namemap$player->getName());

                                                             
    $player->setNameTag("§3");

                                                              
    $player->getInventory()->setItem(8Item::get(Item::BLAZE_ROD01));

                                                            

                                                            
    $slots->save();

                                                            foreach(
    $level->getPlayers() as $playersinarena)

                                                            {

                                                            
    $playersinarena->sendMessage($player->getName() . "§ehas joined [§b1§e/§b20§e]");

                                                            }

                                                    }

                                                    else if(
    $slots->get("slot2".$namemap)==null)

                                                    {

                                                  
    $player->getInventory()->setItem(8Item::get(Item::BLAZE_ROD01));

                                                            
    $slots->set("slot2".$namemap$player->getName());

                                                            
    $thespawn $config->get($namemap "Spawn1");

                     
    $player->setNameTag("§b");

                                                            

                                                            
    $slots->save();

                                                            foreach(
    $level->getPlayers() as $playersinarena)

                                                            {

                                                            
    $playersinarena->sendMessage($player->getName() . "§ehas joined [§b2§e/§b20§e]");

                                                            }

                                                    

                                                    }

                                                    else if(
    $slots->get("slot3".$namemap)==null)

                                                    {

                                                        
    //detective

     
    $player->getInventory()->setItem(8Item::get(Item::BLAZE_ROD01));

                                                            
    $thespawn $config->get($namemap "Spawn1");

                                                            
    $slots->set("slot3".$namemap$player->getName());

                                                            
    $player->setNameTag("§b");

                                                            foreach(
    $level->getPlayers() as $playersinarena)

                                                            {

                                                            
    $playersinarena->sendMessage($player->getName() . "§ehas joined [§b3§e/§b20§e]");

                                                            }

                                                            
    $slots->save();

                                                    }

                                                    else if(
    $slots->get("slot4".$namemap)==null)

                                                    {

                                                        
    $player->setNameTag("§b");

     
    $player->getInventory()->setItem(8Item::get(Item::BLAZE_ROD01));

                                                            
    $thespawn $config->get($namemap "Spawn1");

                                                            
    $slots->set("slot4".$namemap$player->getName());

                                                            

                                                            foreach(
    $level->getPlayers() as $playersinarena)

                                                            {

                                                            
    $playersinarena->sendMessage($player->getName() . " §ehas joined [§b4§e/§b20§e]");

                                                            }

                                                            
    $slots->save();

                                                    }

                                                    else if(
    $slots->get("slot5".$namemap)==null)

                                                    {

                                                        
    //murder

                                                    
    $player->setNameTag("§b");
    how can i make that it sends a messgae that players can leave the arena plus a leave messgae saying the player has left, because if a players leave then the slots keep going and skips the slots and then later the plugin crashes.
     
  2. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    so what is this for i need info is this like a ffa arena or a what. and if ur trying to have a sign say the amount of players in an arena theres a way easier way to do that.
     
  3. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    This is for murder mystery and What is happening is that when a player leave like for example if a player leaves 2/20 and the next players join it will say 3/20 instead for 2/20 and I want to fix that
     
  4. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    i would recommend using a command like /spawn so that it would bring them out of the arena and what are u using as the place u store the players in the arena
     
  5. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    ur using a config data file nvmm
     
  6. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    I have a /hub and this code is when a players join the arena. What I want is this. Let’s say a players join 2/20 then a player leaves. But what happens is that a new players joins. Instead saying 2/20 because the player just left it is saying 3/20. And I want to fix it because if the game start the plugin can get corrupted
     
  7. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    well instead of a config for holding the slots how bout u use a public variable and when the plugin enables set its value and everytime a player joins the arena add 1 to the value and if they leave subtract one
     
  8. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    What code will be the best. If you want I can send the entire main.php. Idk if this is wasting ur time
     
  9. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    EX:
    PHP:
     public $playersinnodebuff;
        public 
    $playersingapple;
        public 
    $playerinsoup;
     public function 
    onEnable()
        {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info(TextFormat::GREEN "Practice Core Is Now Online");
            
    $this->prefix TextFormat::AQUA "[" TextFormat::RED "Practice Core" TextFormat::AQUA "] ";
            
    $this->playersinnodebuff 0;
            
    $this->playersingapple 0;
            
    $this->playerinsoup 0;
        }
     case 
    0:
                        
    $this->getServer()->loadLevel("nodebuff");
                        
    $sender->teleport($this->getServer()->getLevelByName("nodebuff")->getSpawnLocation());
                        
    $sender->sendMessage(TextFormat::RED.$this->prefix." You Have Joined The FFA nodebuff Arena!");
                        
    $this->addnode();
                        
    $sender->getInventory()->clearAll();
                        
    $player $sender->getPlayer();
                        
    $this->nodebuffitems($player);
                        return 
    true;
                        break;
    public function 
    addnode () {
            
    $this->playersinnodebuff $this->playersinnodebuff 1;
        }
     
  10. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    I Use This For My Practice core its alot easier then using a data file for the slots
     
  11. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    I see but idk where I can put this in the code.
     
  12. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    any where in ur join area would be easiest i guess
     
  13. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    Ok what happens if a player leaves the area what will the code do
     
  14. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    put this in ur /hub command
    PHP:
     if ($world == 'nodebuff') {
                            
    $this->removenode();
                        }
    outside of ur hub command put this:
     public function 
    removenode () {
            
    $this->playersinnodebuff $this->playersinnodebuff 1;
        }
     
  15. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    Ok this will take a while but thanks :)
     
  16. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    yeah its gonna take a lot of redoing of ur code if u send the entire main i could help
     
  17. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    i cant really doing much because i dont know the rest of the code
     
  18. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    That will be perfect I will send the entire code
     
  19. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
  20. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    tell when u finished
     
  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.