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

Prevent peoples to join your account if they not on your ip

Comments in 'Plugin Development' started by AvivShopenCraft, Dec 8, 2015.

  1. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    so.. I coded a plugin which kick players that connecting with my name, and the plugin let them join and after 0.5 sec its kicking them, but before they getting kicked the server broadcasting " AvivShopen Joined the game" and " server op AvivShopen joined the game" and they always joining with my name, what spamming player's chat:(, someone have a code that prevent peoples from getting connected?
    here is my code
    PHP:
    public function onJoin(PlayerJoinEvent $event) {

    $player $event->getPlayer();
            
    $name $player->getName();

    if (
    $name == "AvivShopen"); {
    $ip $event->getPlayer()->getAddress(); }
      
    if (
    $ip == " myip" or $ip == "otherip") {
    $player->sendMessage("message");}
            else {
    $player->close(TextFormat::RED "Don't use the owner name!"); $this->getServer()->broadcastMessage(TextFormat::RED "SOMEONE WITH THE IP: $ip TRIED TO JOIN WITH THE OWNER NAME");  }
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    i'll give you a working code without entering the server or say he joined "He'll get kicked fastly"
    PHP:
    public function PreLogin(\pocketmine\event\player\PlayerPreLoginEvent $event){
    if(
    strtolower($event->getPlayer()->getName()) == "AvivShopen" && $event->getPlayer()->getAddress() !== "Your ip"){
    $event->setKickMessage("§c§lDon't try to get in with the Owner's account!");//the message is red and bold
    $event->setCancelled(true);
    $this->getServer()->broadcastMessage("SOMEONE TRIED TO GET IN WITH THE SERVER OWNER ACCOUNT WITH THE IP " $event->getPlayer()->getAddress() . " !!!");
    }
    }
    Last edited: Dec 8, 2015
    AvivShopenCraft likes this.
  3. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    Thank you! I just founded it by myself but I still like:D
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    oh PlayerPreLoginEvent..
    use my code, it's better, your code kicks any player with any name if he's not using your ip.
    also, No Problem :D
    AvivShopenCraft likes this.
  5. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    saved me.... thx again!
  6. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    new problem..
    Parse error: syntax error, unexpected 'Don' (T_STRING) in C:\PocketMine-MP\plugins\BanProtect\src\AvivShopen\BanProtect\MainClass.php on line 51
  7. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    show me the WHOLE File
    AvivShopenCraft likes this.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why the whole? Line 51 is enough.
  9. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    I don't know, but OK XD
    AvivShopenCraft likes this.
  10. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    here you go
    PHP:
    <?php


    namespace AvivShopen\BanProtect;


    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerPreLoginEvent;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\Listener;

    use 
    pocketmine\utils\TextFormat;

    class 
    MainClass extends PluginBase implements Listener {
          
          

    public function 
    PreLogin(\pocketmine\event\player\PlayerPreLoginEvent $event){
    if(
    strtolower($event->getPlayer()->getName()) == "AvivShopen" && $event->getPlayer()->getAddress() !== "ip" or "ip) {

    $event->setKickMessage(TextFormat::RED . TextFormat::BOLD . "Don't try to get in with the Owner's account!");
    $event->setCancelled(true);
    $this->getServer()->broadcastMessage("SOMEONE TRIED TO GET IN WITH THE SERVER OWNER ACCOUNT WITH THE IP " . $event->getPlayer()->getAddress() . " !!!");
    }
    its ok to add ip?
  11. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    oh lol the quetos xD
  12. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    ok now it suppose to be ok
    PHP:
    $event->setKickMessage("" TextFormat::RED TextFormat::BOLD "Dont try to get in with the Owner account!");
  13. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    THE PROBLEM :
    you forgot to end the ip thing after or with an "
    AvivShopenCraft likes this.
  14. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    If you didn't understand my message, here's the fixed code
    PHP:
    <?php
    namespace AvivShopen\BanProtect;


    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerPreLoginEvent;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\Listener;

    use 
    pocketmine\utils\TextFormat;

    class 
    MainClass extends PluginBase implements Listener {



    public function 
    PreLogin(\pocketmine\event\player\PlayerPreLoginEvent $event){
    if(
    strtolower($event->getPlayer()->getName()) == "AvivShopen" && $event->getPlayer()->getAddress() !== "ip" or "ip") {$event->setKickMessage(TextFormat::RED TextFormat::BOLD "Don't try to get in with the Owner's account!");$event->setCancelled(true);$this->getServer()->broadcastMessage("SOMEONE TRIED TO GET IN WITH THE SERVER OWNER ACCOUNT WITH THE IP " $event->getPlayer()->getAddress() . " !!!");
    }
    }
    Learn PHP!
    AvivShopenCraft likes this.
  15. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    I just now readed the post cuz I just now reloaded the webo_O lol I'm gonna try the code
  16. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    lol worked thx
  17. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    well, still not working, I decided to do not post this till now cuz I LEARNED PHP(a little bit lol) and I will continue learning, but for now, I'm still a noob:cool: can you tell me why its not working?
  18. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    did you type your ip correctly?
  19. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    and btw I told my ip xD
  20. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    error
    it must be
    PHP:
    if(strtolower($event->getPlayer()->getName()) == "AvivShopen" && $event->getPlayer()->getAddress() !== "192.168.1.16" or $event->getPlayer()->getAddress() !== "84.111.108.90"){
    that's about PHP
    NOW IT MUST WORK

Share This Page

Advertisement