Last active
December 12, 2015 14:38
-
-
Save PEMapModder/61105475d615393b295f to your computer and use it in GitHub Desktop.
SkinKick - Auto-generated gist plugin stub by pmt.mcpe.me InstaPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: SkinKick | |
author: PEMapModder | |
version: "1.0" | |
api: | |
- 1.13.0 | |
main: PEMapModder\SkinKick\Main | |
commands: | |
newskin: | |
usage: /ns | |
aliases: [ns] | |
skinauth: | |
description: Toggles/checks whether SkinAuth is enabled for you | |
usage: /skinauth [t|f] | |
aliases: [sa] | |
permissions: [] | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
newskin-timeout: 300 # NOTE: the number is in seconds | |
newskin-description: Kicks you and lets you join with a new skin from the same IP within the next 5 minutes | |
kick-messages: | |
newskin: "Please rejoin within 5 minutes with a different (or same) skin." | |
newskin-diff-ip: Attempt to join server from a different IP address while in newskin mode | |
diff-skin: "Your skin does not match the correct skin!" | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace PEMapModder\SkinKick; | |
use pocketmine\Player; | |
use pocketmine\command\CommandSender; | |
use pocketmine\command\Command; | |
use pocketmine\event\Listener; | |
use pocketmine\event\player\PlayerLoginEvent; | |
use pocketmine\plugin\PluginBase; | |
class Main extends PluginBase implements Listener{ | |
public function onEnable(){ | |
$this->saveDefaultConfig(); | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
@mkdir($this->getDataFolder() . "players/"); | |
$this->getCommand("newskin")->setDescription($this->getConfig()->get("newskin-description")); | |
} | |
public function onLogin(PlayerLoginEvent $event){ | |
$player = $event->getPlayer(); | |
$file = $this->getDataFolder() . "players/" . strtolower($player->getName()) . ".json"; | |
if(!is_file($file)){ | |
$config = new SkinConfig; | |
$config->lastIp = $player->getAddress(); | |
$config->skin = base64_encode($player->getSkinData()); | |
$config->skinSlim = $player->isSkinSlim(); | |
file_put_contents($file, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); | |
}else{ | |
$config = SkinConfig::fromFile($file); | |
if($config->newSkin < time()){ | |
if(base64_decode($config->skin) !== $player->getSkinData() or $config->skinSlim !== $player->isSkinSlim()){ | |
if($config->enforce){ | |
$event->setCancelled(); | |
$event->setKickMessage($this->getConfig()->getNested("kick-messages.diff-skin"), false); | |
return; | |
} | |
$this->getLogger()->notice("{$player->getName()} is using a new skin, but (s)he is opt-out for SkinAuth!"); | |
} | |
$config->lastIp = $player->getAddress(); | |
file_put_contents($file, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); | |
}else{ | |
if($player->getAddress() !== $config->lastIp){ | |
$event->setCancelled(); | |
$event->setKickMessage($this->getConfig()->getNested("kick-messages.newskin-diff-ip"), false); | |
return; | |
} | |
$config->skin = base64_encode($player->getSkinData()); | |
$config->skinSlim = $player->isSkinSlim(); | |
$config->newSkin = 0; | |
file_put_contents($file, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); | |
} | |
} | |
} | |
public function onCommand(CommandSender $issuer, Command $cmd, $label, array $params){ | |
switch($cmd->getName()){ | |
case "newskin": | |
if(!($issuer instanceof Player)){ | |
$issuer->sendMessage("Please run this command in-game."); | |
return true; | |
} | |
$file = $this->getDataFolder() . "players/" . strtolower($issuer->getName()) . ".json"; | |
$config = SkinConfig::fromFile($file); | |
$config->newSkin = time() + $this->getConfig()->get("newskin-timeout"); | |
file_put_contents($file, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); | |
$player->kick($this->getConfig()->getNested("kick-messages.newskin"), false); | |
return true; | |
case "skinauth": | |
if(!($issuer instanceof Player)){ | |
$issuer->sendMessage("Please run this command in-game."); | |
return true; | |
} | |
$file = $this->getDataFolder() . "players/" . strtolower($issuer->getName()) . ".json"; | |
$config = SkinConfig::fromFile($file); | |
if(isset($params[0])){ | |
$opt = strtolower($params[0]); | |
if($opt === "t" or $opt === "i" or $opt === "enable" or $opt === "on" or $opt === "in" or $opt === "true"){ | |
$optIn = true; | |
}elseif($opt === "f" or $opt === "o" or $opt === "disable" or $opt === "off" or $opt === "off" or $opt === "false"){ | |
$optIn = false; | |
} | |
} | |
if(!isset($optIn)){ | |
$inOut = $config->enforce ? "in" : "out"; | |
$reverse = $config->enforce ? "out" : "in"; | |
$reverseCmd = $config->enforce ? "/opt f" : "/opt t"; | |
$issuer->sendMessage("You are opt-$inOut to SkinAuth. Use `$reverseCmd` to opt-$reverse."); | |
return true; | |
} | |
$config->enforce = $optIn; | |
$inOut = $config->enforce ? "in" : "out"; | |
$reverse = $config->enforce ? "out" : "in"; | |
$reverseCmd = $config->enforce ? "/opt f" : "/opt t"; | |
$issuer->sendMessage("You are now opt-$inOut to SkinAuth. Use `$reverseCmd` to opt-$reverse."); | |
return true; | |
} | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace PEMapModder\SkinKick; | |
class SkinConfig{ | |
/** @type bool */ | |
public $enforce = false; | |
/** @type string */ | |
public $lastIp; | |
/** @type string (base64-encoded) */ | |
public $skin; | |
/** @type bool */ | |
public $skinSlim; | |
/** @type int */ | |
public $newSkin = 0; | |
public static function fromFile($file){ | |
$data = json_decode(file_get_contents($file)); | |
$self = new self; | |
if(is_object($data)){ | |
foreach($data as $k => $v){ | |
$self->{$k} = $v; | |
} | |
} | |
return $self; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome