diff --git a/src/Matthww/PlayerInfo/utils/SpoonDetector.php b/src/Matthww/PlayerInfo/utils/SpoonDetector.php index 877fc4c..684aefa 100644 --- a/src/Matthww/PlayerInfo/utils/SpoonDetector.php +++ b/src/Matthww/PlayerInfo/utils/SpoonDetector.php @@ -1,5 +1,4 @@ getName(), self::$thingsThatAreNotSpoons); + + public final static function simpleCheck(Server $server) : bool { + return !in_array(Server::getInstance()->getName(), SpoonDetector::THINGS_THAT_ARE_NOT_SPOONS); } - private static function contentValid(string $content): bool { + public static final function contentCheck(Server $server): bool{ + $reflectionClass = new \ReflectionClass($server); + $method = $reflectionClass->getMethod("getName"); + $start = $method->getStartLine(); + $end = $method->getEndLine(); + + $filename = $method->getFileName(); + $length = $end - $start; + + $source = file($filename); + $body = implode("", array_slice($source, $start, $length)); + + if(strpos($body, "(") !== false || strpos($body, ")") !== false){ + $server->getLogger()->info("Your server may be attempting to block SpoonDetector from running. SpoonDetector will continue to run regardless. If you are the developer of this spoon would like to be exempted from spoon detection, create a new API versioning system so existing PM plugins don't run, and then create an issue at Falkirks/spoondetector."); + return true; + } + foreach ($source as $line){ + if(strpos($line, "SpoonDetector") !== false){ + $server->getLogger()->info("Your server may be attempting to block SpoonDetector from running. SpoonDetector will continue to run regardless. If you are the developer of this spoon would like to be exempted from spoon detection, create a new API versioning system so existing PM plugins don't run, and then create an issue at Falkirks/spoondetector."); + return true; + } + } + return false; + } + + public final static function isThisSpoon() : bool { + $server = Server::getInstance(); + return self::simpleCheck($server) || self::contentCheck($server); + + } + + private final static function contentValid(string $content): bool { return (strpos($content, self::$spoonTxtContent) !== false) && (strrpos($content, "yes") > strrpos($content, "?")); } - public static function printSpoon(PluginBase $pluginBase, $fileToCheck = "spoon.txt") { - if (self::isThisSpoon()) { - if (!file_exists($pluginBase->getDataFolder() . $fileToCheck)) { + public final static function printSpoon(PluginBase $pluginBase, $fileToCheck = "spoon.txt"){ + if(self::isThisSpoon()){ + if(!file_exists($pluginBase->getDataFolder() . $fileToCheck)){ file_put_contents($pluginBase->getDataFolder() . $fileToCheck, self::$spoonTxtContent); } - if (!self::contentValid(file_get_contents($pluginBase->getDataFolder() . $fileToCheck))) { + if(!self::contentValid(file_get_contents($pluginBase->getDataFolder() . $fileToCheck))) { $pluginBase->getLogger()->info(self::$subtleAsciiSpoon); $pluginBase->getLogger()->warning("You are attempting to run " . $pluginBase->getDescription()->getName() . " on a SPOON!"); $pluginBase->getLogger()->warning("Before using the plugin you will need to open /plugins/" . $pluginBase->getDescription()->getName() . "/" . $fileToCheck . " in a text editor and agree to the terms."); $pluginBase->getServer()->getPluginManager()->disablePlugin($pluginBase); + return false; } } + return true; } -} + +} \ No newline at end of file