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

HeLp

Comments in 'Plugin Development' started by Marcelo234, Jan 29, 2016.

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey guys...Here is a code (Main.php) so if a player tap with the id 388 on a Block, his language should checked and he should get a special Message...But if a player tap with the item 388 on the ground, nothing happens!The Server do nothing...
    Main.php
    PHP:
    .....
    public 
    $messagesEN;
    public 
    $messagesDE;
    //...A few codes later....
    //Save English Messages
            
    $this->saveResource("recources/English.yml");
            
    $this->messagesEN = new Config($this->getDataFolder() ."resources/English.yml",Config::YAML);
            
    //Save Deutsch Messages
            
    $this->saveResource("recources/Deutsch.yml");
            
    $this->messagesDE = new Config($this->getDataFolder() ."resources/Deutsch.yml",Config::YAML);
    //.....A few codes...
    public function onPlayerInteract(PlayerInteractEvent $event) {
            
    $player $event->getPlayer();
            
    $this->player = new Config($this->getDataFolder() . "PlayersInfo/" strtolower($player->getName()), Config::YAML);
            
    $language $this->player->get("Language");
            
    $this->config = new config($this->getDataFolder() . "config.yml"Config::YAML, array());
            
    $playerlevel $player->getLevel()->getName();
            if(
    $event->getItem()->getId()==388){
               if(
    $playerlevel == $this->config->get("lobby_spawn_world")) {
                     
    $this->PlayerLanguage($player$language"buildteam");
                }
            }
             if(
    $event->getItem()->getId() == 369){
                
    $this->PlayerLanguage($player$language"vip");

            }
        }
      
        public function 
    PlayerLanguage(Player $player$language$message) {
            if (
    strtolower($language) == "DE") {
                
    $player->sendMessage($this->messagesDE->get($message));
            }
            if (
    strtolower($language) == "EN") {
                
    $player->sendMessage($this->messagesEN->get($message));
            }
        }
    English.yml:
    PHP:
    buildteam"§6BildTeam TEST English"
    vip"§7VIP Test English"
    Deutsch.yml:
    PHP:
    buildteam"§6BildTeam TEST Deutsch"
    vip"§7VIP Test Deutsch"
    Thanks Marcelo234
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Is the language set in $this->player? Did you register the events in onEnable()?
  3. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    If A Player join this will be create :

    Playername.yml:

    Code:
    ...
    Language: "EN"
    ...
    The Player can change this Language too....
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
  5. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    I only register this :

    $this->getServer()->getPluginManager()->registerEvents($this, $this);
  6. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    The config files "messagesDE" and "messagesEN" have any content?
    You're saving resources two times on a unknow directory: "recources".
    I suggest you save they on a indepent directory (languages, for example.)
    Last edited: Jan 30, 2016
    applqpak likes this.
  7. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    What Do you mean with content ?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why save resources from recources/English.yml? You must have the file resources/recources/English.yml in your phar in that case.
    PocketKiller and applqpak like this.
  9. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    PHP:
    public $messagesEN;
    public 
    $messagesDE;
    //....
    public function onEnable(){
    //Save English Messages
            
    $this->messagesEN = new Config($this->getDataFolder() ."languages/English.yml",Config::YAML);
    //Save Deutsch Messages       
            
    $this->messagesDE = new Config($this->getDataFolder() ."languages/Deutsch.yml",Config::YAML);

    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }
    //.....A few codes...
    public function onPlayerInteract(PlayerInteractEvent $event) {
            
    $player $event->getPlayer();
            
    $this->player = new Config($this->getDataFolder() . "PlayersInfo/" strtolower($player->getName()), Config::YAML);
            
    $language $this->player->get("Language");
            
    $this->config = new config($this->getDataFolder() . "config.yml"Config::YAML, array());
            
    $playerlevel $player->getLevel()->getName();
            if(
    $event->getItem()->getId()==388){
               if(
    $playerlevel == $this->config->get("lobby_spawn_world")) {
                     
    $this->PlayerLanguage($player$language"buildteam");
                }
            }
             if(
    $event->getItem()->getId() == 369){
                
    $this->PlayerLanguage($player$language"vip");

            }
        }
     
        public function 
    PlayerLanguage(Player $player$language$message) {
            if (
    strtolower($language) == "DE") {
                
    $player->sendMessage($this->messagesDE->get($message));
            }
            if (
    strtolower($language) == "EN") {
                
    $player->sendMessage($this->messagesEN->get($message));
            }
        } 
    I changed:
    -I renamed the Folder "resources" to "languages"
    -Edited a few things in the onEnble Part!

    Hope anybody can help..,.
    If a player tap with one of the two items at the ground, the server do nothing.....
    Hope anybody find the Problem....Thanks Marcelo234
  10. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    I know why!
    Correctly code:
    PHP:
    public function PlayerLanguage(Player $player$message) {
            
    $this->player = new Config($this->getDataFolder() . "PlayersInfo/" strtolower($player->getName()), Config::YAML);
            
    $language $this->player->get("Language");
            if(
    $language == "DE") {
                
    $player->sendMessage($this->messagesDE->get($message));
            }
            if(
    $language == "EN") {
                
    $player->sendMessage($this->messagesEN->get($message));
            }
        }
    Thanks

Share This Page

Advertisement