Skip to content

Instantly share code, notes, and snippets.

@jasonw4331
Last active September 8, 2017 21:40
Show Gist options
  • Select an option

  • Save jasonw4331/a891435b14b2a7a1a9d911f09902c036 to your computer and use it in GitHub Desktop.

Select an option

Save jasonw4331/a891435b14b2a7a1a9d911f09902c036 to your computer and use it in GitHub Desktop.
A PocketMine script to prevent players from joining using a different IP than the ones allowed
<?php
/**
* @name PlayerIPLock
* @main jasonwynn10\PlayerIPLock\Main
* @version 0.1.0
* @api 3.0.0-ALPHA7
* @description A PocketMine plugin script to prevent players from joining using a different IP than the ones allowed
* @author jasonwynn10
*/
namespace jasonwynn10\PlayerIPLock {
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerPreLoginEvent;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
class Main extends PluginBase implements Listener {
public function onEnable() {
new Config($this->getDataFolder()."config.yml", Config::YAML, [
"jasonwynn10" => [
"74.141.54.178"
]
]);
$this->getConfig()->reload();
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
/**
* @priority HIGHEST
* @ignoreCancelled true
*
* @param PlayerPreLoginEvent $ev
*/
public function onPreLogin(PlayerPreLoginEvent $ev) {
if($ev->isCancelled())
return;
$player = $ev->getPlayer();
if($this->getConfig()->exists($player->getName())) {
if(empty($this->getConfig()->get($player->getName(), []))) {
$this->getConfig()->set($player->getName(), [$player->getAddress()]);
}else{
if(!in_array($player->getAddress(), $this->getConfig()->get($player->getName()))) {
$ev->setCancelled();
$ev->setKickMessage("This username can only join from a few set IP addresses.\nNo hacking accounts here :P");
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment