public function __construct(KillRatePlugin $owner, $mode)
 {
     $this->owner = $owner;
     $this->enabled = $mode;
     if ($this->enabled) {
         Achievement::add("killer", "First Blood!", []);
         Achievement::add("serialKiller", "Killer Streak!", ["killer"]);
         Achievement::add("ranked1", "Ranked #1!", ["killer"]);
         Achievement::add("kill10", "Achieved 10 Kills!", ["killer"]);
         Achievement::add("kill100", "Achieved 100 Kills!", ["kill10"]);
         Achievement::add("kill1000", "Achieved 1,000 Kills!", ["kill100"]);
     }
 }
Example #2
0
 public function onEnable()
 {
     $this->saveDefaultConfig();
     $this->saveResource("server-icon.png", false);
     $this->saveResource("steve.yml", false);
     $this->saveResource("alex.yml", false);
     $this->reloadConfig();
     $this->onlineMode = (bool) $this->getConfig()->get("online-mode");
     if ($this->onlineMode and !function_exists("mcrypt_generic_init")) {
         $this->onlineMode = false;
         $this->getLogger()->notice("no mcrypt detected, online-mode has been disabled. Try using the latest PHP binaries");
     }
     if (!$this->getConfig()->exists("motd")) {
         $this->getLogger()->warning("No motd has been set. The server description will be empty.");
         return;
     }
     if (Info::CURRENT_PROTOCOL === 84) {
         $this->translator = new Translator_84();
         $this->rsa = new RSA();
         $this->getServer()->getPluginManager()->registerEvents($this, $this);
         Achievement::add("openInventory", "Taking Inventory");
         //this for DesktopPlayer
         if ($this->onlineMode) {
             $this->getLogger()->info("Server is being started in the background");
             $this->getLogger()->info("Generating keypair");
             $this->rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
             $this->rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
             $keys = $this->rsa->createKey(1024);
             $this->privateKey = $keys["privatekey"];
             $this->publicKey = $keys["publickey"];
             $this->rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
             $this->rsa->loadKey($this->privateKey);
         }
         $this->getLogger()->info("Starting Minecraft: PC server on " . ($this->getIp() === "0.0.0.0" ? "*" : $this->getIp()) . ":" . $this->getPort() . " version " . MCInfo::VERSION);
         $disable = true;
         foreach ($this->getServer()->getNetwork()->getInterfaces() as $interface) {
             if ($interface instanceof ProtocolInterface) {
                 $disable = false;
             }
         }
         if ($disable) {
             $this->interface = new ProtocolInterface($this, $this->getServer(), $this->translator);
             $this->getServer()->getNetwork()->registerInterface($this->interface);
         }
     } else {
         $this->getLogger()->critical("Couldn't find a protocol translator for #" . Info::CURRENT_PROTOCOL . ", disabling plugin");
         $this->getPluginLoader()->disablePlugin($this);
     }
 }
Example #3
0
 /**
  * @param string $achievementId
  *
  * @return bool
  */
 public function awardAchievement($achievementId)
 {
     if (isset(Achievement::$list[$achievementId]) and !$this->hasAchievement($achievementId)) {
         foreach (Achievement::$list[$achievementId]["requires"] as $requerimentId) {
             if (!$this->hasAchievement($requerimentId)) {
                 return false;
             }
         }
         $this->server->getPluginManager()->callEvent($ev = new PlayerAchievementAwardedEvent($this, $achievementId));
         if (!$ev->isCancelled()) {
             $this->achievements[$achievementId] = true;
             Achievement::broadcast($this, $achievementId);
             return true;
         } else {
             return false;
         }
     }
     return false;
 }
Example #4
0
 public function onEnable()
 {
     $this->dbm = null;
     if (!is_dir($this->getDataFolder())) {
         mkdir($this->getDataFolder());
     }
     mc::plugin_init($this, $this->getFile());
     $this->api = new KillRateAPI($this);
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
     $defaults = ["version" => $this->getDescription()->getVersion(), "# settings" => "Configuration settings", "settings" => ["# points" => "award points.", "points" => true, "# rewards" => "award money.", "rewards" => true, "# creative" => "track creative kills.", "creative" => false, "# dynamic-updates" => "Update signs.", "dynamic-updates" => 80, "# reset-on-death" => "Reset counters on death.", "reset-on-death" => false, "# kill-streak" => "Enable kill-streak tracking.", "kill-streak" => false, "# achievements" => "Enable PocketMine achievements", "achievements" => true], "# values" => "configure awards. (1st.money, 2nd.points)", "values" => ["*" => [1, 10], "Player" => [100, 100]], "# formats" => "Sign formats.", "formats" => ["default" => "{sname} {count}", "names" => "{n}.{player}", "scores" => "{count}"], "# backend" => "Use SQLiteMgr or MySqlMgr", "backend" => "SQLiteMgr", "# MySql" => "MySQL settings.", "MySql" => ["host" => "localhost", "user" => "nobody", "password" => "secret", "database" => "KillRateDb", "port" => 3306], "# signs" => "placed signs text.", "signs" => ["[STATS]" => "stats", "[ONLINE TOPS]" => "online-tops", "[RANKINGS]" => "rankings", "[RANKNAMES]" => "rankings-names", "[RANKPOINTS]" => "rankings-points", "[TOPNAMES]" => "online-top-names", "[TOPPOINTS]" => "online-top-points"]];
     $this->cfg = (new Config($this->getDataFolder() . "config.yml", Config::YAML, $defaults))->getAll();
     if (version_compare($this->cfg["version"], "1.2.0") < 0) {
         $this->getLogger()->warning(TextFormat::RED . mc::_("Configuration has been changed"));
         $this->getLogger()->warning(mc::_("It is recommended to delete old config.yml"));
     }
     $backend = __NAMESPACE__ . "\\" . $this->cfg["backend"];
     $this->dbm = new $backend($this);
     if ($this->cfg["backend"] != "SQLiteMgr") {
         $this->getLogger()->warning(TextFormat::RED . mc::_("Using %1% backend is untested", $this->cfg["backend"]));
         $this->getLogger()->warning(TextFormat::RED . mc::_("Please report bugs"));
     } else {
         $this->getLogger()->info(mc::_("Using %1% as backend", $this->cfg["backend"]));
     }
     if (isset($this->cfg["settings"]["rewards"])) {
         $this->money = MoneyAPI::moneyPlugin($this);
         if ($this->money) {
             MoneyAPI::foundMoney($this, $this->money);
         } else {
             MoneyAPI::noMoney($this);
         }
     }
     if ($this->cfg["settings"]["dynamic-updates"] && $this->cfg["settings"]["dynamic-updates"] > 0) {
         $this->getServer()->getScheduler()->scheduleRepeatingTask(new PluginCallbackTask($this, [$this, "updateTimer"], []), $this->cfg["settings"]["dynamic-updates"]);
     }
     $this->stats = [];
     if ($this->cfg["settings"]["achievements"]) {
         Achievement::add("killer", "First Blood!", []);
         Achievement::add("serialKiller", "Killer Streak!", ["killer"]);
     }
     $this->saveResource("KillRateEx.php");
 }