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

Getting Killed Player

Comments in 'Plugin Development' started by Radix, Jul 23, 2015.

  1. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    I was making a plugin that will ban a player on death. So as I went to test it I killed a plyer and it said player(6) has been banned for 5 Mins, instead of the name. I have no idea why this is happening.. The player also wasn't banned -_-

    Github Repo: https://github.com/DarkRealms/HardCorePvP/edit/master/src/DarkRealms/Main.php

    Lazy Devs :p
    PHP:
    <?php
    namespace DarkRealms;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\Event;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Player;
    use 
    pocketmine\command\ConsoleCommandSender;
    class 
    Main extends PluginBase implements Listener{
     
      public function 
    onEnable(){
      
    $this->getServer()->getPluginManager()->registerEvents($this$this);
      
    $this->saveDefaultConfig();
      }
     
      public function 
    onPlayerDeath(PlayerDeathEvent $event){
      
    $p $event->getEntity();
      if(
    $p instanceof Player){
      
    $time $this->getConfig()->get("bantime");
      
    $message $this->getConfig()->get("banmessage");
      
    $command "timerban add "$p." "$time." "$message;
      
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $command);
      
    $this->getServer()->broadcastMessage(TextFormat::YELLOW$p" has been banned for "$time ." minutes");
      }
      }
    }
    Did I need to add
    PHP:
    $this->getServer()->getPluginManager()->getPlugin("Timerban");
  2. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
  3. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Try this:
    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event){
    $p $event->getEntity();
    $pName $p->getName();
    if(
    $p instanceof Player){
    $time $this->getConfig()->get("bantime");
    $message $this->getConfig()->get("banmessage");
    $command "timerban add "$pName." "$time." "$message;
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $command);
    $this->getServer()->broadcastMessage(TextFormat::YELLOW$pName" has been banned for "$time ." minutes");
    }
    }
  4. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Still says player21 has been banned instead of the player name!
  5. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Strange... I'll test it out
  6. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    are u testing on a local host?
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Put the $p->getName(); after checking whether $p is instanceof Player
    MCPEPIG and jojoe77777 like this.
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    You calling me lazy? Ask me then I will help lol. Just some ******* telling me I am messing everything up... lol. Not you, @Radix.
    Radix likes this.
  9. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Huh? Code .. ??
    No My server...
    You know ILUVU
  10. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event){
    $p $event->getEntity();
    if(
    $p instanceof Player){
    $pName $p->getName();
    $time $this->getConfig()->get("bantime");
    $message $this->getConfig()->get("banmessage");
    $command "timerban add "$pName." "$time." "$message;
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $command);
    $this->getServer()->broadcastMessage(TextFormat::YELLOW$pName" has been banned for "$time ." minutes");
    }
    }
    MCPEPIG likes this.

Share This Page

Advertisement