Beispiel #1
0
 public function onTick()
 {
     if (--$this->tick > 0) {
         if ($this->tick % 6 === 0) {
             $this->getServer()->broadcastMessage(TextFormat::DARK_AQUA . self::tag . $this->getTimeText() . "lefts to result announcement!");
         }
     } else {
         $count = count($this->box);
         if ($count > 0) {
             $winner = $this->box[array_rand($this->box)];
             $winningAmount = $count * $this->price;
             $this->economyAPI->addMoney($winner, $winningAmount);
             $winnerInst = $this->getServer()->getPlayer($winner);
             if ($winnerInst !== null) {
                 $winnerInst->sendMessage(TextFormat::GREEN . self::tag . " Congratulations! You've won the lottery!");
                 $winnerInst->sendMessage(TextFormat::GREEN . self::tag . " Please check your money :)");
             }
             $this->getServer()->broadcastMessage(TextFormat::DARK_AQUA . self::tag . " The winner is " . $winner . "! Congratulations!");
             $this->getServer()->broadcastMessage(TextFormat::DARK_AQUA . self::tag . " Today's winning amount: " . $winningAmount);
         }
         $this->save();
         $this->box = [];
         $this->tick = self::interval;
     }
 }
Beispiel #2
0
 /**
  * @priority LOWEST
  * @ignoreCancelled true
  * @param BlockPlaceEvent $event
  */
 public function onBlockPlace(BlockPlaceEvent $event)
 {
     $player = $event->getPlayer();
     $block = $event->getBlock();
     $job = $this->jobs->get($this->player->get($player->getName()));
     if ($job !== false) {
         if (isset($job[$block->getID() . ":" . $block->getDamage() . ":place"])) {
             $this->api->addMoney($player, $job[$block->getID() . ":" . $block->getDamage() . ":place"]);
         }
     }
 }
 public function onDataPacketRecieve(CustomPacketReceiveEvent $event)
 {
     $packet = $event->getPacket();
     $array = json_decode($packet->data);
     if ($array[0] != "MoneyTransfer") {
         return;
     }
     $player = $array[1];
     $amount = $array[2];
     $this->economy->addMoney($player, $amount);
     $this->getLogger()->info("플레이어 {$player}가 {$amount}원을 다른서버에서 옮겨왔습니다.");
 }
Beispiel #4
0
 public function onCommand(CommandSender $sender, Command $command, $label, array $params)
 {
     switch ($command->getName()) {
         case "casino":
             $sub = array_shift($params);
             switch ($sub) {
                 case "start":
                     if (!$sender instanceof Player) {
                         $sender->sendMessage("Please run this command in-game.");
                         break;
                     }
                     if (!$sender->hasPermission("economycasino.command.casino.start")) {
                         return true;
                     }
                     if ($this->config->get("max-game") <= count($this->casino)) {
                         $sender->sendMessage("There are too many games in progress. Please join the other games.");
                         break;
                     }
                     if (isset($this->casino[$sender->getName()])) {
                         $sender->sendMessage("You already have joined casino.");
                         return true;
                     } else {
                         foreach ($this->casino as $player => $casino) {
                             if (isset($casino["players"][$sender->getName()])) {
                                 $sender->sendMessage("You already have joined casino.");
                                 return true;
                             }
                         }
                     }
                     $this->casino[$sender->getName()] = array("players" => array($sender->getName() => true));
                     $this->getServer()->broadcastMessage("[EconomyCasino] Casino of " . $sender->getName() . " has just started.");
                     break;
                 case "stop":
                     if (!$sender instanceof Player) {
                         $sender->sendMessage("Please run this command in-game.");
                         break;
                     }
                     if (!$sender->hasPermission("economycasino.command.casino.stop")) {
                         return true;
                     }
                     if ($sender instanceof Player and !$sender->isOp()) {
                         if (isset($this->casino[$sender->getName()])) {
                             foreach ($this->casino[$sender->getName()]["players"] as $player => $v) {
                                 $this->getServer()->getPlayerExact($player)->sendMessage("[EconomyCasino] You have left the casino due to stop.");
                             }
                             unset($this->casino[$sender->getName()]);
                             $sender->sendMessage("You have stopped your casino.");
                         } else {
                             $sender->sendMessage("You don't have any casino game to quit.");
                         }
                     } else {
                         $player = array_shift($params);
                         if (trim($player) === "") {
                             $sender->sendMessage("Usage: /casino stop <player>");
                             break;
                         }
                         if (isset($this->casino[$player])) {
                             foreach ($this->casino[$player]["players"] as $player => $v) {
                                 $this->getServer()->getPlayerExact($player)->sendMessage("[EconomyCasino] You have left the casino game due to stop.");
                             }
                             $sender->sendMessage("[EconomyCasino] The game by \"{$player}\" has successfully stopped.");
                             unset($this->casino[$player]);
                         }
                     }
                     break;
                 case "join":
                     if (!$sender instanceof Player) {
                         $sender->sendMessage("Please run this command in-game.");
                         break;
                     }
                     if (!$sender->hasPermission("economycasino.command.casino.join")) {
                         return true;
                     }
                     $player = array_shift($params);
                     if (trim($player) === "") {
                         $sender->sendMessage("Usage: /casino join <player>");
                         break;
                     }
                     if (isset($this->casino[$player])) {
                         foreach ($this->casino[$player]["players"] as $player => $v) {
                             if (($p = $this->getServer()->getPlayerExact($player)) instanceof Player) {
                                 $p->sendMessage("[EconomyCasino] " . $sender->getName() . " has joined the game.");
                             }
                         }
                         $this->casino[$player]["players"][$sender->getName()] = true;
                         $sender->sendMessage("You've joined the casino.");
                     } else {
                         $sender->sendMessage("There's no casino where are looking for.");
                     }
                     break;
                 case "leave":
                     if (!$sender instanceof Player) {
                         $sender->sendMessage("Please run this command in-game.");
                         break;
                     }
                     if (!$sender->hasPermission("economycasino.command.casino.leave")) {
                         return true;
                     }
                     foreach ($this->casino as $player => $casino) {
                         if (isset($casino["players"][$sender->getName()])) {
                             unset($this->casino[$player]["players"][$sender->getName()]);
                             foreach ($casino["players"] as $p => $v) {
                                 $this->getServer()->getPlayerExact($p)->sendMessage("[EconomyCasino] " . $sender->getName() . " left the game.");
                             }
                             break;
                         }
                     }
                     $sender->sendMessage("[EconomyCasino] You have no casino game to leave.");
                     break;
                 case "list":
                     if (!$sender->hasPermission("economycasino.command.casino.list")) {
                         return true;
                     }
                     $player = array_shift($params);
                     if (trim($player) === "") {
                         list_general:
                         $output = "[EconomyCasino] Game list : \n";
                         foreach ($this->casino as $player => $casino) {
                             $output .= "{$player} : " . count($this->casino[$player]["players"]) . " \n";
                         }
                         $output = substr($output, 0, -2);
                         $sender->sendMessage($output);
                     } else {
                         if (isset($this->casino[$player])) {
                             $output = "[EconomyCasino] Player list of casino game by : {$player} \n";
                             foreach ($this->casino[$player]["players"] as $p) {
                                 $output .= "{$p}, ";
                             }
                             $output = substr($output, 0, -2);
                         } else {
                             goto list_general;
                         }
                     }
                     break;
                 case "gamble":
                     if (!$sender instanceof Player) {
                         $sender->sendMessage("Please run this command in-game.");
                         break;
                     }
                     if (!$sender->hasPermission("economycasino.command.casino.gamble")) {
                         return true;
                     }
                     $money = array_shift($params);
                     if (!is_numeric($money)) {
                         $sender->sendMessage("Usage: /casino gamble <money>");
                         break;
                     }
                     $money = (int) $money;
                     if ($this->api->myMoney($sender) < $money) {
                         $sender->sendMessage("You don't have money to gamble " . $this->api->getMonetaryUnit() . "{$money}");
                         break;
                     }
                     if (isset($this->casino[$sender->getName()])) {
                         $all = 0;
                         foreach ($this->casino[$sender->getName()]["players"] as $player => $v) {
                             $tmp = min($money, $this->api->myMoney($player));
                             $this->api->reduceMoney($player, $tmp);
                             $all += $tmp;
                         }
                         $got = array_rand($this->casino[$sender->getName()]["players"]);
                         $this->api->addMoney($got, $all, true, "EconomyCasino");
                         foreach ($this->casino[$sender->getName()]["players"] as $p => $v) {
                             if ($got === $p) {
                                 $this->getServer()->getPlayerExact($p)->sendMessage("You've win " . $this->api->getMonetaryUnit() . "{$all}!");
                             } else {
                                 $this->getServer()->getPlayerExact($p)->sendMessage("You've lost " . $this->api->getMonetaryUnit() . "{$money}");
                             }
                         }
                     } else {
                         foreach ($this->casino as $player => $casino) {
                             if (isset($casino["players"][$sender->getName()])) {
                                 $all = 0;
                                 foreach ($this->casino[$player]["players"] as $p => $true) {
                                     $tmp = min($this->api->myMoney($p), $money);
                                     $this->api->reduceMoney($p, $tmp);
                                     $all += $tmp;
                                 }
                                 $got = array_rand($this->casino[$player]["players"]);
                                 $this->api->addMoney($got, $all, true, "EconomyCasino");
                                 foreach ($this->casino[$player]["players"] as $p => $v) {
                                     if ($got === $p) {
                                         $this->getServer()->getPlayerExact($p)->sendMessage("You've win " . $this->api->getMonetaryUnit() . "{$all}!");
                                     } else {
                                         $this->getServer()->getPlayerExact($p)->sendMessage("You've lost " . $this->api->getMonetaryUnit() . "{$money}");
                                     }
                                 }
                             }
                         }
                     }
                     break;
                 default:
                     $sender->sendMessage("Usage: " . $command->getUsage());
             }
             break;
         case "jackpot":
             if (!$sender instanceof Player) {
                 $sender->sendMessage("Please run this command in-game.");
                 break;
             }
             $money = array_shift($params);
             if (!is_numeric($money)) {
                 $sender->sendMessage("Usage: " . $command->getUsage());
                 break;
             }
             $money = (int) $money;
             if ($this->api->myMoney($sender) < $money) {
                 $sender->sendMessage("You don't have money to jackpot " . $this->api->getMonetaryUnit() . "{$money}");
                 break;
             }
             $rand = rand(0, $this->config->get("jackpot-winning"));
             if ($rand === 0) {
                 $this->api->addMoney($sender, $money);
                 $sender->sendMessage("You've wined jackpot! You've got " . $this->api->getMonetaryUnit() . "{$money}");
             } else {
                 $this->api->reduceMoney($sender, $money);
                 $sender->sendMessage("You've failed your jackpot! You've lost " . $this->api->getMonetaryUnit() . "{$money}");
             }
             break;
     }
     return true;
 }
Beispiel #5
0
 public function onPacketReceive(CustomPacketReceiveEvent $ev)
 {
     $data = $ev->getPacket()->data;
     // json 화 필요할 수도 있음
     if (!is_array($data)) {
         echo "[테스트] 어레이가 아닌 정보 전달됨";
         return;
     }
     if ($data[0] != $this->db["passcode"]) {
         echo "[테스트] 패스코드가 다른 정보 전달됨";
         return;
     }
     if ($this->db["mode"] == "master") {
         // 마스터 서버 코딩
         switch ($data[1]) {
             case "createBank":
                 // slave->master = [0패스코드, 1createBank, 2계좌명, 3username, 4비용]
                 // master->slave = [0패스코드, 1createBank, 2계좌명, 3username, 4true:success|false:failed]
                 if (isset($this->db["bank"][$data[2]])) {
                     $data[4] = false;
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                     break;
                 }
                 $this->db["bank"][$data[2]]["price"] = $data[4];
                 $this->db["bank"][$data[2]]["username"] = $data[3];
                 $data[4] = true;
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                 break;
             case "useBank":
                 // slave->master = [0패스코드, 1useBank, 2계좌명, 3username]
                 // master->slave = [0패스코드, 1useBank, 2계좌명, 3username, 4true:success|false:failed]
                 if (!isset($this->db["bank"][$data[2]])) {
                     $data[4] = false;
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                     break;
                 }
                 $price = $this->db["bank"][$data[2]]["price"];
                 $playerMoney = $this->economyAPI->myMoney($this->db["bank"][$data[2]]["username"]);
                 if ($playerMoney >= $price) {
                     // 해당계좌 돈뺏기
                     $this->economyAPI->reduceMoney($this->db["bank"][$data[2]]["username"], $price);
                     // 해당 돈 유저에게 지급하기
                     $this->economyAPI->addMoney($data[3], $price);
                     $data[4] = true;
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                 } else {
                     $data[4] = false;
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                 }
                 unset($this->db["bank"][$data[2]]);
                 break;
         }
     } else {
         // 슬레이브 서버 코딩
         $player = $this->getServer()->getPlayer($data[1]);
         if (!$player instanceof Player) {
             return;
         }
         switch ($data[1]) {
             case "createBank":
                 // master->slave = [0패스코드, 1createBank, 2계좌명, 3username, 4true:success|false:failed]
                 // failed-createBank
                 if ($data[4] == false) {
                     $this->message($player, $this->get("failed-createBank"));
                     break;
                 }
                 $this->db["bank"][$data[0]]["price"] = $data[1];
                 $this->db["bank"][$data[0]]["username"] = $player->getName();
                 $this->message($player, $this->get("passcode-created"));
                 break;
             case "useBank":
                 // slave->master = [0패스코드, 1useBank, 2계좌명, 3username]
                 // master->slave = [0패스코드, 1useBank, 2계좌명, 3username, 4true:success|false:failed]
                 break;
         }
     }
 }