public function __construct(array $titles, LegionPE $main) { $this->nextReport = StatsReportMinuteTask::hourOfDay() + 1; foreach ($titles as $t) { $this->stats[$t] = []; for ($h = 0; $h < 24; $h++) { $this->stats[$t][$h] = 0; } } $main->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new StatsReportMinuteTask($main, $this), 1200, 1200); }
public function getStats($new = 604800) { $info = new TeamInfo(); $data = $this->main->getMySQLi()->query("SELECT COUNT(*)AS cnt,SUM((SELECT kills FROM kitpvp WHERE uid=players.uid))AS kills,SUM((SELECT deaths FROM kitpvp WHERE uid=players.uid))AS deaths,MAX((SELECT maxstreak FROM kitpvp WHERE uid=players.uid))AS pvpmaxstreak,SUM((SELECT completions FROM parkour WHERE uid=players.uid))AS completions,SUM((SELECT falls FROM parkour WHERE uid=players.uid))AS falls,SUM((SELECT tmpfalls FROM parkour WHERE uid=players.uid))AS tmpfalls,SUM((SELECT wins FROM spleef WHERE uid=players.uid))AS wins,SUM((SELECT losses FROM spleef WHERE uid=players.uid))AS losses,SUM((SELECT draws FROM spleef WHERE uid=players.uid))AS draws,MAX((SELECT maxstreak FROM spleef WHERE uid=players.uid))AS spleefmaxstreak FROM players WHERE tid={$this->tid} AND teamjointime<=unix_timestamp()-{$new}", MysqlConnection::ASSOC); $info->oldMembers = $data["cnt"]; $info->totalMembers = count($this->members); $info->pvpKills = $data["kills"]; $info->pvpDeaths = $data["deaths"]; $info->pvpMaxStreak = $data["pvpmaxstreak"]; $info->parkourWins = $data["completions"]; $info->parkourFalls = $data["falls"]; $info->parkourTmpFalls = $data["tmpfalls"]; $info->spleefWins = $data["wins"]; $info->spleefLosses = $data["losses"]; $info->spleefDraws = $data["draws"]; $info->spleefMaxStreak = $data["spleefmaxstreak"]; return $info; }
public function onDamage(EntityDamageEvent $event) { $damaged = $event->getEntity(); if (!$damaged instanceof Player or !($session = $this->getMain()->getSessions()->getSession($damaged)) instanceof Session or !$session->inSession($this)) { return; } if ($event instanceof EntityDamageByChildEntityEvent) { $entity = $event->getDamager(); if ($entity instanceof Player) { $ses = $this->main->getSessions()->getSession($entity); if ($ses instanceof Session and $ses->inSession($this)) { $data = $this->getPlayerData($ses); if ($data->isPlaying() and $data->getArena()->isPlaying()) { $projectile = $event->getChild(); if ($projectile instanceof Snowball) { $event->setCancelled(false); $event->setKnockBack($event->getKnockBack() * 2); } } } } } }
public function __construct(LegionPE $main) { parent::__construct($main); $this->main = $main; $main->getServer()->getScheduler()->scheduleDelayedRepeatingTask($this, 2400, 2400); $this->sql = new \SQLite3(":memory:"); $this->sql->exec("CREATE TABLE teams (id INTEGER PRIMARY KEY, name TEXT COLLATE NOCASE, open INTEGER)"); $this->main->getMySQLi()->query("UPDATE teams SET has_founder=0 WHERE isnull((SELECT uid FROM players WHERE tid=teams.tid AND teamrank=%d))", MysqlConnection::RAW, Team::RANK_LEADER); $this->main->getMySQLi()->query("UPDATE players SET tid=-1,teamrank=0 WHERE(SELECT has_founder FROM teams WHERE tid=players.tid)=0", MysqlConnection::RAW); $this->main->getMySQLi()->query("DELETE FROM teams WHERE(SELECT COUNT(*)FROM players WHERE players.tid=teams.tid)=0", MysqlConnection::RAW); foreach ($this->main->getMySQLi()->query("SELECT *,(SELECT rank FROM players WHERE tid=teams.tid AND teamrank=4 LIMIT 1)AS leaderrank FROM teams", MysqlConnection::ALL) as $row) { $tid = (int) $row["tid"]; $members = []; foreach ($this->main->getMySQLi()->query("SELECT uid,teamrank FROM players WHERE tid={$tid}", MysqlConnection::ALL) as $member) { $members[(int) $member["uid"]] = (int) $member["teamrank"]; } $this->teams[$tid] = new Team($main, $tid, $row["name"], Settings::team_maxCapacity($row["leaderrank"]), (bool) (int) $row["open"], $members, isset($row["invited"]) ? $row["invited"] : "", isset($row["requires"]) ? $row["requires"] : "", isset($row["rules"]) ? $row["rules"] : ""); $op = $this->sql->prepare("INSERT INTO teams (id, name, open)VALUES(:id, :name, :open)"); $op->bindValue(":id", $tid); $op->bindValue(":name", $row["name"]); $op->bindValue(":open", $row["open"]); $op->execute(); } }
/** * @param Player|string $player * @return Session|null */ protected function getSession($player) { $ses = $this->main->getSessions()->getSession($player); return $ses instanceof Session ? $ses : null; }
public function update() { if ($this->changed) { $this->main->getMySQLi()->query("INSERT INTO parkour(uid,progress,completions,falls,tmpfalls)VALUES({$this->session->getUID()},{$this->progress},{$this->completions},{$this->falls},{$this->tmpFalls})ON DUPLICATE KEY UPDATE progress={$this->progress},completions={$this->completions},falls={$this->falls},tmpfalls={$this->tmpFalls};", MysqlConnection::RAW); } }
public function getGame() { return $this->main->getGame($this->session); }