Skip to content

Commit

Permalink
Project resumed! Woohoo!
Browse files Browse the repository at this point in the history
Fixed issues:
- Undefined variables
- Death-Match suddenly begins
- Players can move from their spot

I still don't know if player that died gets announced but I attemped to fix it. Try it and let me know!
  • Loading branch information
xBeastMode committed Apr 1, 2016
1 parent 975bd3d commit 3e98bea
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 35 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ api: 2.0.0
load: STARTUP
name: HungerGames
description: "the hunger games"
version: build#07
version: build#10
author: xbeastmode

permissions:
Expand Down
28 changes: 10 additions & 18 deletions src/xbeastmode/hg/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use xbeastmode\hg\event\player\PlayerJoinGameEvent;
use xbeastmode\hg\event\player\PlayerQuitGameEvent;
use xbeastmode\hg\utils\FMT;
use xbeastmode\hg\utils\exc;
class Events implements Listener{
/** @var Loader */
private $main;
Expand All @@ -34,12 +35,12 @@ public function onSignChange(SignChangeEvent $e){
if (strtolower($line[0]) === strtolower("HG") and $p->isOp()){
if(!$e->getPlayer()->isOp()) return;
if(!isset($this->main->getConfig()->getAll()["hg_games"][color::clean($line[1])])){
$p->sendMessage(FMT::colorMessage("&cError[CS-1]: &egame does not exist."));
$p->sendMessage(exc::_("%c%Error[CS-1]: %e%game does not exist."));
return;
}
$e->setLine(0, FMT::colorMessage($this->main->getConfig()->getAll()["sign"]["line1"]));
$e->setLine(1, $line[1]);
$p->sendMessage(color::GREEN . "Successfully created sign for game '" . $line[1] . "'!");
$p->sendMessage(exc::_("Successfully created sign for game '%0%'!", [$line[1]]));
}
}
/**
Expand All @@ -54,13 +55,12 @@ public function onInteract(PlayerInteractEvent $e)
$e->getPlayer()->getInventory()->clearAll();
foreach(HGGame::getApi()->players as $g){
if(isset($g[spl_object_hash($e->getPlayer())])){
$e->getPlayer()->sendMessage(FMT::colorMessage("&cError[J-1]: &ealready joined game."));
$e->getPlayer()->sendMessage(exc::_("%c%Error[J-1]: %e%Already joined game."));
return;
}
break;
}
if(isset(HGGame::getApi()->players[$clean][spl_object_hash($e->getPlayer())])){
$clean->sendMessage(FMT::colorMessage("&cError[J-1]: &ealready joined game."));
$clean->sendMessage(exc::_("%c%Error[J-1]: %e%Already joined game."));
return;
}
if(HGGame::getApi()->tpToOpenSlot($e->getPlayer(), $clean) === false){
Expand Down Expand Up @@ -90,11 +90,9 @@ public function onMove(PlayerMoveEvent $e){
$player = $e->getPlayer();
if(!isset(HGManagement::$data[$e->getPlayer()->getName()])) return;
if(isset(HGManagement::$players[HGManagement::$data[$e->getPlayer()->getName()]][$player->getName()])){
$from = clone $e->getFrom();
$to = $e->getTo();
$from->yaw = $to->yaw;
$from->pitch = $to->pitch;
$e->setTo($from);
if(!$e->getFrom()->equals($t = $e->getTo())){
$e->setCancelled();
}
}
}
/**
Expand All @@ -109,15 +107,12 @@ public function onKill(PlayerDeathEvent $e){
$onWait = HGGame::getApi()->onWait[HGManagement::$data[$player->getName()]];
if($onWait == 0){
$this->main->e->deleteGameData(HGManagement::$data[$player->getName()]);
$this->main->e->deletePlayerData($player);
return;
}
if ($onWait == 1) {
$this->main->e->endGame(HGManagement::$data[$player->getName()]);
$this->main->e->deleteGameData(HGManagement::$data[$player->getName()]);
$this->main->e->deletePlayerData($player);
return;
}
$this->main->e->deletePlayerData($player);
}
}
}
Expand All @@ -136,16 +131,13 @@ public function onQuit(PlayerQuitEvent $e){
if($onWait == 0){
$this->main->e->resetMap(HGManagement::$data[$player->getName()]);
$this->main->e->deleteGameData(HGManagement::$data[$player->getName()]);
$this->main->e->deletePlayerData($player);
return;
}
if ($onWait == 1) {
$this->main->e->resetMap(HGManagement::$data[$player->getName()]);
$this->main->e->endGame(HGManagement::$data[$player->getName()]);
$this->main->e->deleteGameData(HGManagement::$data[$player->getName()]);
$this->main->e->deletePlayerData($player);
return;
}
$this->main->e->deletePlayerData($player);
}
}
/**
Expand Down
4 changes: 4 additions & 0 deletions src/xbeastmode/hg/HGManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ class HGManagement{
public static $players = [];
/** @var array */
public static $data = [];
/** @var array */
public static $PBlocks = [];
/** @var array */
public static $BBlocks = [];
}
2 changes: 1 addition & 1 deletion src/xbeastmode/hg/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function onEnable(){
(new HGGame($this));
@mkdir($this->getDataFolder());
$this->saveDefaultConfig();
$this->msg = new Config($this->getDataFolder()."messages.yml", Config::YAML, $messages);
$this->msg = new Config($this->getDataFolder()."messages.yml", Config::YAML, yaml_emit($messages));
$this->getServer()->getCommandMap()->register("hg", new hgCmd($this));
$this->getServer()->getPluginManager()->registerEvents(new Events($this), $this);
$this->getServer()->getScheduler()->scheduleRepeatingTask(new RefreshSignTask($this), 20);
Expand Down
5 changes: 1 addition & 4 deletions src/xbeastmode/hg/commands/hgCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,13 @@ public function execute(CommandSender $sender, $commandLabel, array $args)
if($onWait == 0){
$this->main->e->resetMap(HGManagement::$data[$sender->getName()]);
$this->main->e->deleteGameData(HGManagement::$data[$sender->getName()]);
$this->main->e->deletePlayerData($sender);
return;
}
if($onWait == 1){
$this->main->e->resetMap(HGManagement::$data[$sender->getName()]);
$this->main->e->endGame(HGManagement::$data[$sender->getName()]);
$this->main->e->deleteGameData(HGManagement::$data[$sender->getName()]);
$this->main->e->deletePlayerData($sender);
return;
}
$this->main->e->deletePlayerData($sender);
$sender->sendMessage(FMT::colorMessage("&aQuiting..."));
}else{
$sender->sendMessage(FMT::colorMessage("&cYou are not in a game."));
Expand Down
4 changes: 2 additions & 2 deletions src/xbeastmode/hg/tasks/GameTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(Loader $main, $game){
*/
public function onRun($currentTick)
{
if(!isset(HGGame::getApi()->players[$this->game])){
if(!empty(HGManagement::$players[$this->game])){
$this->main->getServer()->getScheduler()->cancelTask($this->getTaskId());
return;
}
Expand All @@ -47,7 +47,7 @@ public function onRun($currentTick)
break;
}
}
if(!isset(HGGame::getApi()->players[$this->game])){
if(!empty(HGManagement::$players[$this->game])){
$this->main->getServer()->getScheduler()->cancelTask($this->getTaskId());
return;
}
Expand Down
19 changes: 10 additions & 9 deletions src/xbeastmode/hg/tasks/RefreshSignTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use xbeastmode\hg\HGManagement;
use xbeastmode\hg\Loader;
use xbeastmode\hg\api\HGGame;
use xbeastmode\hg\utils\exc;
use xbeastmode\hg\utils\FMT;
class RefreshSignTask extends PluginTask{
/** @var Loader */
Expand All @@ -31,21 +32,21 @@ public function onRun($currentTick)
$max = HGGame::getApi()->getMaxPlayers($game);
if (isset(HGGame::getApi()->onWait[$game]) and isset(HGManagement::$games[$game])) {
$l1 = FMT::colorMessage($cf["sign"]["line1"]);
$l2 = FMT::colorMessage(str_replace("{game}", $game, $cf["sign"]["line2"]));
$l3 = FMT::colorMessage(str_replace(["{count}", "{max}"], [HGGame::getApi()->onWait[$game], $max], $cf["sign"]["line3"]));
$l4 = FMT::colorMessage(str_replace("{status}", FMT::colorMessage($cf["status"]["running"]), $cf["sign"]["line4"]));
$l2 = FMT::colorMessage(str_replace(exc::_("%0%", ["{game}"]), $game, $cf["sign"]["line2"]));
$l3 = FMT::colorMessage(str_replace([exc::_("%0%", ["{count}"]), exc::_("%0%", ["{max}"])], [HGGame::getApi()->onWait[$game], $max], $cf["sign"]["line3"]));
$l4 = FMT::colorMessage(str_replace(exc::_("%0%", ["{status}"]), FMT::colorMessage($cf["status"]["running"]), $cf["sign"]["line4"]));
$t->setText($l1, $l2, $l3, $l4);
} elseif (!isset(HGGame::getApi()->onWait[$game]) and !isset(HGManagement::$games[$game])){
$l1 = FMT::colorMessage($cf["sign"]["line1"]);
$l2 = FMT::colorMessage(str_replace("{game}", $game, $cf["sign"]["line2"]));
$l3 = FMT::colorMessage(str_replace(["{count}", "{max}"], [0, $max], $cf["sign"]["line3"]));
$l4 = FMT::colorMessage(str_replace("{status}", FMT::colorMessage($cf["status"]["waiting"]), $cf["sign"]["line4"]));
$l2 = FMT::colorMessage(str_replace(exc::_("%0%", ["{game}"]), $game, $cf["sign"]["line2"]));
$l3 = FMT::colorMessage(str_replace([exc::_("%0%", ["{count}"]), exc::_("%0%", ["{max}"])], [0, $max], $cf["sign"]["line3"]));
$l4 = FMT::colorMessage(str_replace(exc::_("%0%", ["{status}"]), FMT::colorMessage($cf["status"]["waiting"]), $cf["sign"]["line4"]));
$t->setText($l1, $l2, $l3, $l4);
}elseif(isset(HGGame::getApi()->onWait[$game]) and !isset(HGManagement::$games[$game])){
$l1 = FMT::colorMessage($cf["sign"]["line1"]);
$l2 = FMT::colorMessage(str_replace("{game}", $game, $cf["sign"]["line2"]));
$l3 = FMT::colorMessage(str_replace(["{count}", "{max}"], [HGGame::getApi()->onWait[$game], $max], $cf["sign"]["line3"]));
$l4 = FMT::colorMessage(str_replace("{status}", FMT::colorMessage($cf["status"]["waiting"]), $cf["sign"]["line4"]));
$l2 = FMT::colorMessage(str_replace(exc::_("%0%", ["{game}"]), $game, $cf["sign"]["line2"]));
$l3 = FMT::colorMessage(str_replace([exc::_("%0%", ["{count}"]), exc::_("%0%", ["{max}"])], [HGGame::getApi()->onWait[$game], $max], $cf["sign"]["line3"]));
$l4 = FMT::colorMessage(str_replace(exc::_("%0%", ["{status}"]), FMT::colorMessage($cf["status"]["waiting"]), $cf["sign"]["line4"]));
$t->setText($l1, $l2, $l3, $l4);
}
}
Expand Down
130 changes: 130 additions & 0 deletions src/xbeastmode/hg/utils/exc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
namespace xbeastmode\hg\utils;
####################################################
# ATTENTION! #
# THIS CLASS IS FOR PLUGIN USE ONLY. #
# IT CAN ALSO BE USED ON PLUGINS WITH CORRECT USE! #
####################################################
use pocketmine\level\Position;
use pocketmine\Player;

class exc{
##all chars;;;;;;;;;
const CHARS = [
"=", "&", "<", ">", "/", "$", "#", "!", "-", "_", "+", ".", "@",
"(", ")", "*", "^", "%", ";", ":", "?", "[", "]", "{", "}", "~"
];
private static $t = [];
public static function _($string, array $elements= null){
$f = $string;
if(isset(exc::$t[$f])) $f = exc::$t[$f];
if (count($elements)) {
$v = [ "%" => "%" ];
$i = 0;
foreach ($elements as $ret) {
$v["%$i%"] = $ret;
++$i;
}
$f = strtr($f, $v);
}
$f = str_replace("%n", "\n", $f);
$f = str_replace("%%", "\xc2\xa7", $f);
return $f;##formatter;;;;;;;;;
}
public static function dob($val, $exploder = '.'){
##rounds value of number;;;;;;;;;
return number_format((float)$val, 2, $exploder, '');
}
public static function cNum($v){
##checks if value is a valid number;;;;;;;;;
if(is_numeric($v)):return (1|true);
elseif(is_int($v)):return (1|true);
elseif(is_float($v)):return (1|true);
endif;
return (0|null);
}
public static function toN($val){
##turn string numbers to int;;;;;;;;;
$val = intval($val);
return $val;
}
public static function rndAlt(array $val){
if(
empty($val)
)return null;
##choose random value from array;;;;;;;;;
return $val[mt_rand() % (count($val)-1)-(0)];
}
public static function rndN($length){
$num = range(0, 9);
$n = "";
for ($i = 0; $i < $length; ++$i) {
$n .= exc::rndAlt($num);
}
return intval($n);
}
public static function rndStr($length, $numbers = true, $chars = false){
##generates random string;;;;;;;;;
$abc = range('A', 'Z');
$num = range(0, 9);
$str = "";
if(!$numbers and !$chars){
for ($i = 0; $i < $length; ++$i) {
$str .= exc::rndAlt($abc);##chooses random letters from A to Z;;;;;;;;;
}
}
if($numbers) {
for ($i = 0; $i < $length / 2; ++$i) {
$str .= exc::rndAlt($abc);##chooses random letters from A to Z;;;;;;;;;
$str .= exc::rndAlt($num);##chooses random number from 0 to 9;;;;;;;;;
}
}
if($chars){
for($i = 0; $i < $length / 2; ++$i){
$str .= exc::rndAlt($abc);##chooses random letters from A to Z;;;;;;;;;
$str .= exc::rndAlt(exc::CHARS);##chooses random chars;;;;;;;;;
}
}
##gives random string;;;;;;;;;
return $str;
}
public static function mxStr($string, $numbers = false, $chars = false){
$num = range(0, 9);
$str = "";
if(!$numbers and !$chars){
for($i = 0; $i < strlen($string); ++$i){
$str .= $string[$i];##chooses letter ;;;;;;;;;
}
}
if($numbers) {
for ($i = 0; $i < strlen($string); ++$i) {
$str .= $string[$i];##chooses letter ;;;;;;;;;
$str .= exc::rndAlt($num);##chooses number from 0 to 9 ;;;;;;;;;
}
}
if($chars){
for($i = 0; $i < strlen($string); ++$i){
$str .= $string[$i];##chooses letter ;;;;;;;;;
$str .= exc::rndAlt(exc::CHARS);##chooses random chars;;;;;;;;;
}
}
return $str;
}
public static function cngCh($string){
preg_match_all("/[[:punct:]]/", $string, $m);
return $m[0];##gets all types of chars;;;;;;;;;
}
public static function rCh($string){
foreach(exc::cngCh($string) as $char){
$string = str_replace($char, "", $string);
}
return $string;##replaces chars in string;;;;;;;;;
}

public static function mirrorY(Player $p, $farness = 2){
return new Position($p->x-$farness, $p->y, $p->z);##PLUGIN USE;;;;;;;;;
}
public static function mirrorX(Player $p, $farness = 2){
return new Position($p->x-$farness, $p->y-$farness, $p->z);##PLUGIN USE;;;;;;;;;
}
}

0 comments on commit 3e98bea

Please sign in to comment.