Пример #1
0
 /**
  * Show a notice when the money API is found
  *
  * @param PluginBase $plugin - current plugin
  * @param PluginBase $api - found plugin
  * @param LogLevel $level - optional log level
  */
 public static function foundMoney(PluginBase $plugin, $api, $level = LogLevel::INFO)
 {
     if (class_exists(__NAMESPACE__ . "\\mc", false)) {
         $plugin->getLogger()->log($level, TextFormat::BLUE . mc::_("Using money API from %1%", $api->getFullName()));
     } else {
         $plugin->getLogger()->log($level, TextFormat::BLUE . "Using money API from " . $api->getFullName());
     }
 }
Пример #2
0
 public function promote(Player $player, $newscore)
 {
     if ($this->rankup === null) {
         return;
     }
     // OK, do we need to rank up?
     $nextrank = $this->rankup->getRankStore()->getNextRank($player);
     if ($newscore < $nextrank->getPrice()) {
         return;
     }
     // Yeah!  Levelling up!
     if ($this->rankup->getPermManager()->addToGroup($player, $nextrank->getName())) {
         $this->owner->getServer()->broadcastMessage(TextFormat::BLUE . mc::_("%1% is now %2%!", $player->getDisplayName(), $nextrank->getName()));
     } else {
         $player->sendMessage(TextFormat::RED . mc::_("Unable to award level %1%", $nextrank->getName()));
     }
 }
Пример #3
0
 /**
  * Checks message files and nags the user to submit translations...
  *
  * @param Plugin $plugin - owning plugin
  * @param str $path - output of $plugin->getFile()
  * @return int|false - false on error or the number of messages loaded
  */
 public static function plugin_init_alt($plugin, $path)
 {
     $lang = $plugin->getServer()->getProperty("settings.language");
     if (mc::plugin_init($plugin, $path) === false && $lang != "eng") {
         list($fp, $fill) = [$plugin->getResource("messages/eng.ini"), "English"];
         if ($fp === null) {
             list($fp, $fill) = [$plugin->getResource("messages/messages.ini"), "EMPTY"];
         }
         if ($fp === null) {
             return false;
         }
         file_put_contents($plugin->getDataFolder() . "messages.ini", stream_get_contents($fp) . "\n\"<nagme>\"=\"yes\"\n");
         mc::plugin_init($plugin, $path);
         $plugin->getLogger()->error(TextFormat::RED . "Your selected language \"" . $lang . "\" is not supported");
         $plugin->getLogger()->error(TextFormat::YELLOW . "Creating a custom \"messages.ini\" with " . $fill . " strings");
         $plugin->getLogger()->error(TextFormat::AQUA . "Please consider translating and submitting a translation");
         $plugin->getLogger()->error(TextFormat::AQUA . "to the developer");
         $plugin->getLogger()->error(TextFormat::YELLOW . "If you later change your language in \"pocketmine.yml\"");
         $plugin->getLogger()->error(TextFormat::YELLOW . "make sure you delete this \"messages.ini\"");
         $plugin->getLogger()->error(TextFormat::YELLOW . "otherwise your changes will not be recognized");
         return;
     }
     if (mc::_("<nagme>") !== "yes") {
         return;
     }
     // Potentially the language may exists since this was created...
     $fp = $plugin->getResource("messages/" . $lang . ".ini");
     if ($fp === null && $lang != "eng") {
         $plugin->getLogger()->error(TextFormat::RED . "Your selected language \"" . $lang . "\" is not supported");
         $plugin->getLogger()->error(TextFormat::AQUA . "Please consider translating \"messages.ini\"");
         $plugin->getLogger()->error(TextFormat::AQUA . "and submitting a translation to the  developer");
         return;
     }
     if ($fp !== null) {
         fclose($fp);
     }
     // This language is actually supported...
     $plugin->getLogger()->error(TextFormat::RED . "Using a supported language: \"" . $lang . "\"");
     $plugin->getLogger()->error(TextFormat::YELLOW . "Saving/Fixing \"messages.ini\" as");
     $plugin->getLogger()->error(TextFormat::YELLOW . "\"messages.bak\"...");
     $orig = file_get_contents($plugin->getDataFolder() . "messages.ini");
     file_put_contents($plugin->getDataFolder() . "messages.bak", strtr($orig, ["<nagme>" => "<don't nagme>"]));
     unlink($plugin->getDataFolder() . "messages.ini");
 }
Пример #4
0
 public function scoreStreak(Player $player)
 {
     if (!$this->enabled) {
         return false;
     }
     $n = strtolower($player->getName());
     $streak = $this->owner->updateDb($n, "streak");
     if ($streak < $this->minkills) {
         return false;
     }
     $this->owner->getServer()->getPluginManager()->callEvent(new KillRateNewStreakEvent($this->owner, $player, $streak));
     $this->owner->getServer()->broadcastMessage(TextFormat::YELLOW . mc::_("%1% has a %2%-kill streak", $player->getDisplayName(), $streak));
     if ($this->money === null) {
         return true;
     }
     list($points, $money) = $this->owner->getPrizes("streak");
     $this->owner->getServer()->getPluginManager()->callEvent($ev = new KillRateBonusScoreEvent($this->owner, $player, $money));
     if ($ev->isCancelled()) {
         return true;
     }
     $player->sendMessage(TextFormat::GREEN . mc::_("You earn an additional \$%1% for being in kill-streak!", $ev->getMoney()));
     MoneyAPI::grantMoney($this->money, $player, $ev->getMoney());
     return true;
 }
Пример #5
0
 protected function topSign($mode, $fmt, $title, $sign)
 {
     $col = "points";
     if ($sign[1] != "") {
         $title = $sign[1];
     }
     if ($sign[2] != "") {
         $col = $sign[2];
     }
     if ($sign[3] != "" && isset($this->cfg["formats"][$sign[3]])) {
         $fmt = $this->cfg["formats"][$sign[3]];
     } else {
         $fmt = $this->cfg["formats"][$fmt];
     }
     $text = ["", "", "", ""];
     if ($title == "^^^") {
         $cnt = 4;
         $start = 0;
     } else {
         $text[0] = $title;
         $cnt = 3;
         $start = 1;
     }
     $res = $this->getRankings($cnt, $mode, $col);
     if ($res == null) {
         $text[2] = mc::_("NO STATS FOUND!");
     } else {
         $i = 1;
         $j = $start;
         foreach ($res as $r) {
             $tr = ["{player}" => $r["player"], "{count}" => $r["count"], "{sname}" => substr($r["player"], 0, 8), "{n}" => $i++];
             $text[$j++] = strtr($fmt, $tr);
         }
     }
     return $text;
 }
Пример #6
0
 public function deadDealer($pv)
 {
     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
     if ($pv instanceof Player) {
         // Score that this player died!
         //echo __METHOD__.",".__LINE__."\n";//##DEBUG
         $deaths = $this->updateDb($pv->getName(), "deaths");
         if ($this->settings["reset-on-death"] && $settings["reset-on-death"] > 0) {
             if ($deaths >= $this->settings["reset-on-death"]) {
                 // We died too many times... reset scores...
                 $this->getServer()->getPluginManager()->callEvent($ev = new KillRateResetEvent($this, $pv));
                 if (!$ev->isCancelled()) {
                     $this->delScore($pv);
                     $this->ranks($pv);
                 }
             }
         }
         $this->kstreak->endStreak($pv);
     }
     $cause = $pv->getLastDamageCause();
     // If we don't know the real cause, we can score it!
     //echo __METHOD__.",".__LINE__."-".get_class($cause)."\n";//##DEBUG
     if (!$cause instanceof EntityDamageEvent) {
         return;
     }
     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
     switch ($cause->getCause()) {
         case EntityDamageEvent::CAUSE_PROJECTILE:
             $pp = $cause->getDamager();
             //echo get_class($pp)." PROJECTILE\n";//##DEBUG
             break;
         case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
             $pp = $cause->getDamager();
             break;
         case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
             $pp = $cause->getDamager();
             if ($pp instanceof Projectile) {
                 $pp = $pp->shootingEntity;
             }
             //echo get_class($pp)." EXPLOSION\n";//##DEBUG
             break;
         default:
             //echo "Cause: ".$cause->getCause()."\n";//##DEBUG
             return;
     }
     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
     if (!$pp instanceof Player) {
         return;
     }
     // Not killed by player...
     // No scoring for creative players...
     if ($pp->isCreative() && !$this->settings["creative"]) {
         return;
     }
     $perp = $pp->getName();
     $vic = $pv->getName();
     if ($pv instanceof Player) {
         $vic = "Player";
         // OK killed a player... check for a kill streak...
         $pv->sendMessage(TextFormat::RED . mc::_("You were killed by %1%!", $pp->getName()));
         if ($this->kstreak->scoreStreak($pp)) {
             $this->achievements->awardSerialKiller($pp);
         }
     }
     $perp = $pp->getName();
     list($points, $money) = $this->updateScores($pp, $perp, $vic);
     $this->announce($pp, $points, $money);
 }