Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Optimize code.

Comments in 'Plugin Development' started by AndrewBit, Jan 10, 2016.

  1. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Hi, I'm trying to optimize as well my plugin.
    PHP:
    public function OnMove(PlayerMoveEvent $event) {
            
    $player $event->getPlayer();
            
    $games = ["PvP-1","PvP-2","PvP-3","PvP-4","PvP-5","PvP-6","PvP-7","PvP-8","PvP-9","PvP-10"];
            foreach(
    $games as $game){
                if(
    $player->getLevel()->getName() == $game and $this->getGameValue($game) == false){
                    
    $event->setCancelled(true);
                }
            }
        }
    Here is a thing that I'm not pretty sure if it's good at all...
    I was thinking that is maybe faster use this:
    PHP:
    public function OnMove(PlayerMoveEvent $event) {
            
    /*$player = $event->getPlayer();
            $games = ["PvP-1","PvP-2","PvP-3","PvP-4","PvP-5","PvP-6","PvP-7","PvP-8","PvP-9","PvP-10"];
            foreach($games as $game){
                if($player->getLevel()->getName() == $game and $this->getGameValue($game) == false){
                    $event->setCancelled(true);
                }
            }*/
            
    $level $event->getPlayer()->getLevel();
            if(
    $level != $this->getServer()->getDefaultLevel() and $this->getGameValue($level->getName()) == false){
                
    $event->setCancelled();
            }
        }
    What do you all think?
    It's the best way?
    Last edited: Jan 11, 2016
  2. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
  3. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Hm, what?
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    The first way would be better if you plan on not only have "game" worlds.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    AndrewBit and iDirtPlayzMC like this.
  6. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
  7. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    If you want to check that the player is not in a specific world,use @luca28pet 's method, if you want to check if the player is in any of the specified worlds,use @PEMapModder 's method

Share This Page

Advertisement