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

Solved SignChangeEvent

Comments in 'Plugin Development' started by FlamingGenius, Oct 13, 2015.

  1. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    So when i put [Lottery] on a sign nothing happens •_• heres my code theres no crashes,errors anything just mothig happens
    PHP:
    <?php

    namespace FlamingGenius\Lottery;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\event\PlayerInteractEvent;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\event\block\SignChangeEvent;

    class 
    Lottery extends PluginBase{

    public function 
    onEnable(){
      
    $this->saveDefaultConfig();
      
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }

    public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
      
    $player $sender->getName();
      
    $cmd $command->getName();
      
    $winT $this->getConfig()->get("winning-number");
      if(
    strtolower($cmd) == "lottery"){
       
    $numbers $this->getConfig()->get("lotto-numbers");
      
       
    $draw array_rand($numbers);
      
       
    $ticket $numbers[$draw];
      
       
    $sender->sendMessage("§1§l[Lottery]" "§4Your ticket number is" " " $ticket);
       if(
    $ticket == $winT){
      
        
    $this->getServer()->broadcastMessage("§1§l[Lottery]" "§b" $player " " "§aGot a winning lottery ticket" " " "Ticket Number:" "§6" $ticket);
        
    $id $this->getConfig()->get("item-id");
        
    $rid array_rand($id);
        
    $damage $this->getConfig()->get("item-damage");
        
    $amount $this->getConfig()->get("item-amount");
        
    $item Item::get($rid,$damage,$amount);
        
    $sender->getInventory()->addItem($item);
        
    $sender->sendMessage("§1§l[Lottery]" "§aYou recieved" " " $amount " " $id);
       }
       elseif(
    $ticket != $winT){
        
    $sender->sendMessage("§1§l[Lottery]" "§4Sorry your ticket is not a winning number");
       }
      }
    }

    public function 
    onSignChange(SignChangeEvent $event){
      
    $block $event->getPlayer()->getLevel()->getTile($event->getBlock());
      
    $player $event->getServer()->getPlayer()->getName();
      if(
    $block instanceof Sign){
       
    $signtext $block->getText();
       if(
    $signtext[0] == "[Lottery]"){
        
    $block->setText(
         
    "§6[Lottery]",
         
    "§bTap to play"
        
    );
        
    $player->sendMessage("§1§l[Lottery]" " " "§6Lottery sign created");
       }
      }
    }

    public function 
    lottoGame(PlayerInteractEvent $event){
      
    $block $event->getPlayer()->getLevel()->getTile($event->getBlock());
      
    $player $event->getServer()->getPlayer()->getName();
      if(
    $block instanceof Sign){
       
    $signtext $block->getText();
      
       if(
    $signtext[0] == "§6[Lottery]"){
        if(
    $signtext[1] == "§bTap to play"){
         
    $cmd "lottery";
         
    $this->getServer()->dispatchCommand($sender,$cmd);
        }
       }
      }
    }





    }





    ?>
    Last edited: Oct 13, 2015
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    OMG You did not register events.. nothing will work.
    add this in onEnable :
    PHP:
    $this->getServer()->getPluginManager()->registerEvents($this$this);// this will register events.
    Last edited: Oct 13, 2015
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    $event->getLine(0); // or 1 for first line. Actually event self can return sign text. By doing that way its not wrong but not handy at all.
    Taha_The_Hacker likes this.
  4. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Omg i cant believe i forgot to add events lol i need rest
  5. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    why don't you use
    PHP:
    $event->getLine(0);
    instead?
  6. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    I didn't see that.
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Need to rest?
  8. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Yeah i am using my phone right now -_-
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I'd never prefer such resolution.
  10. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Add to this thread the Solved Prefix so we know that we will no longer need to post here for nothing.
  11. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    I added the events but its still not working
    TryoneLegendZzz likes this.
  12. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    try
    PHP:
    $block->setText("§6[Lottery]","§bTap to play","","");
  13. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    also had this issue try adding
    Code:
    if($block instanceof Vector3 /*or*/ Tile){
  14. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    I dont think this is gonna make a difference
    Taha_The_Hacker likes this.
  15. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Wouldnt make a difference
  16. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    try vector3 it worked for me
  17. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    PHP:
        public function onSignCreate(SignChangeEvent $event){
            
    $player $event->getPlayer(); //Get the player
            
    $line_0 $event->getLine(0); //The sign's line 1 (Despite the number)

           
    if(strtolower($line_0) === "[lottery]"){ //Check if the line 1 is equal to [lottery] (Since strtolower)


                  
    $player->sendMessage("Error"); //lel
                    
    return false//Return a boolean value of false
                
    }
                
    $player->sendMessage("Created signs successfully!"); //Haha, LEL
                   
    $event->setLine(0"[Lottery");
                   
    $event->setLine(1"Tap to play");


       }
  18. Syntaxious
    Offline

    Syntaxious New Member

    Joined:
    Sep 15, 2015
    Posts:
    19
    Minecraft User:
    Syntaxious
    There's no point into adding that.

  19. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    Code:
    $event->setText(" ");
  20. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    hmmm i miss understood his sentence

Share This Page

Advertisement