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

Send Message at night/day

Comments in 'Plugin Development' started by Radix, Aug 13, 2015.

  1. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Is there anyway to send a message when its turns day/night?
  2. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    PHP:
    class NightPVP extends PluginBase implements Listener{
      public function 
    onEnable(){
      
    $this->getServer()->getPluginManager()->registerEvents($this$this);
      }
      public function 
    onEntityDamageByEntity(EntityDamageEvent $event){
      if(
    $event instanceof EntityDamageByEntityEvent){
      if(!
    $this->isNight($event->getEntity()->getLevel()->getTime())){
      if(
    $event->getEntity() instanceof Player && $event->getDamager() instanceof Player){
      if(!
    $event->getDamager()->hasPermission("nightpvp.exempt.victim") && !$event->getDamager()->hasPermission("nightpvp.exempt.damager")){
      
    $event->setCancelled();
      }
      }
      }
      }
      }
      public function 
    isNight($t){
      return (
    $t >= 10900 && $t 17800);
       
    $this->getServer()->broadcastMessage('§b§o§lPvP§8§o§l >> mesage'); // < - Will this work , Idk how to send message when it turns day
      
    }
    }

  3. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    PHP:
    if($this->isNight()){
    //define player or send to all online player
    $p->sendMessage("It Is Now Night!");


    }
    Skullex likes this.
  4. basprohop
    Offline

    basprohop Active Member Plugin Developer

    Joined:
    Aug 8, 2015
    Posts:
    128
    Plugins:
    3
    Minecraft User:
    basprohop
    Thats not what he needed help with
  5. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
  6. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
  7. basprohop
    Offline

    basprohop Active Member Plugin Developer

    Joined:
    Aug 8, 2015
    Posts:
    128
    Plugins:
    3
    Minecraft User:
    basprohop
    He knows how to send the message just not how to send the message during day.
  8. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    please use your eyes this is what he wanted "how to send a message during day/night" it might not be the day part but its there
  9. basprohop
    Offline

    basprohop Active Member Plugin Developer

    Joined:
    Aug 8, 2015
    Posts:
    128
    Plugins:
    3
    Minecraft User:
    basprohop
    Wow thats extremely rude of you, I guess that's what you get to even remotely engage in a conversation with a 13 year old these days.

    Anyways, if you read his code you would understand the nature of his request.
    Last edited: Aug 13, 2015
    Radix likes this.
  10. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Do you want it to broadcast the message the instant it turns day or do you want to check the time when player pvp?
    Radix likes this.
  11. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Yes you are right , when it just turns day I want to broadcast a message to all player. Then when turns night broadcast a message!
  12. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Yes!
  13. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    In the main class, onEnable function:
    PHP:
    $this->getServer()->getScheduler()->scheduleRepeatingTask(
                        new 
    CheckTime($this),
                        
    1
            
    );
    The task to run:
    PHP:
    <?php
    namespace PluginName;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\level\Level;

    class 
    CheckTime extends PluginTask {
      public function 
    __construct($plugin) {
        
    $this->plugin $plugin;
        
    parent::__construct($plugin);
      }
      public function 
    onRun($ticks) {
        
    $server $this->plugin->getServer();
        
    $l $server->getDefaultLevel();
        
    $time $l->getTime() % Level::TIME_FULL;
        if (
    $time === Level::TIME_NIGHT$server->broadcastMessage("It is now night");
        if (
    $time === Level::TIME_DAY$server->broadcastMessage("It is now day");
      }
    }
    ?>
    Primus and TryoneLegendZzz like this.
  14. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    or that
  15. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Any way to ban untill night ? :p
  16. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Seems like it doesnt work well , U can pvp turning day ... I went and set time to 0 and no message was sent , & I could aslo pvp players as I said

    PHP:
    <?php
    namespace nightpvp;

    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\level\Level;

    class 
    NightPVP extends PluginBase implements Listener{
      public function 
    onEnable(){
      
    $this->getServer()->getPluginManager()->registerEvents($this$this);
      
    $this->getServer()->getScheduler()->scheduleRepeatingTask(
      new 
    CheckTime($this),
      
    1
      
    );
      }
      public function 
    onEntityDamageByEntity(EntityDamageEvent $event){
      if(
    $event instanceof EntityDamageByEntityEvent){
      if(!
    $this->isNight($event->getEntity()->getLevel()->getTime())){
      if(
    $event->getEntity() instanceof Player && $event->getDamager() instanceof Player){
      if(!
    $event->getDamager()->hasPermission("nightpvp.exempt.victim") && !$event->getDamager()->hasPermission("nightpvp.exempt.damager")){
      
    $event->setCancelled();
      }
      }
      }
      }
      }
      public function 
    isNight($t){
      return (
    $t >= 10900 && $t 17800);
      }
    }
    class 
    CheckTime extends PluginTask {
      public function 
    __construct($plugin) {
      
    $this->plugin $plugin;
      
    parent::__construct($plugin);
      }
      public function 
    onRun($ticks) {
      
    $server $this->plugin->getServer();
      
    $l $server->getDefaultLevel();
      
    $time $l->getTime() % Level::TIME_FULL;
      if (
    $time === Level::TIME_NIGHT$server->broadcastMessage("§b§o§lPurgePvP§8§o§l >> May the purge begin!");
      if (
    $time === Level::TIME_DAY$server->broadcastMessage("§b§o§lPurgePvP§8§o§l >> You survived the purge!\n§b§o§lPurgePvP§8§o§l >> Time to build you base and prepare for nightfall\n§b§o§lPurgePvP§8§o§l >> Remeber to vote for kit & rewards!\n§b§o§lPurgePvP§8§o§l >> Don't die! ;)");
      }
    }
  17. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    You mean to unban all players when night?
    PHP:
    if ($time === Level::TIME_NIGHT) {
    $server->broadcastMessage("It is now night");
    //unban code, i dont know how to unban all players :p
    }
  18. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Ok , I have the idea , But it doesnt broadcast the message ....
  19. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
  20. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    1. learn php 2. learn pm api. 3. the code he gave u is for a plugintask u put in main class...

Share This Page

Advertisement