Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Even more bug fixes, include logic change in addPlayer to handle inva…
Browse files Browse the repository at this point in the history
…lid arena/world
  • Loading branch information
JaxkDev committed Jun 23, 2019
1 parent e968b53 commit b98f1e9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
20 changes: 16 additions & 4 deletions src/Jackthehack21/KOTH/Arena.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,21 @@ public function updateNameTags() : void{
/**
* @param Player $player
* @param bool $random
* @return bool
*/
private function spawnPlayer(Player $player, $random = false) : void{
private function spawnPlayer(Player $player, $random = false) : bool{
if(strtolower($player->getLevel()->getName()) !== strtolower($this->world)){
if(!$this->plugin->getServer()->isLevelGenerated($this->world)) {
$player->sendMessage($this->plugin->prefix.C::RED."World set for '".$this->name."' does not exist.");
return;
return false;
}
if(!$this->plugin->getServer()->isLevelLoaded($this->world)) {
$this->plugin->getServer()->loadLevel($this->world);
}

}
$player->teleport($this->getSpawn($random));
return true;
}

/**
Expand Down Expand Up @@ -586,6 +588,12 @@ public function addPlayer(Player $player) : bool{
case self::STATUS_FULL:
$player->sendMessage($this->plugin->prefix.C::RED."This arena is full.");
return false;
case self::STATUS_INVALID:
$player->sendMessage($this->plugin->prefix.C::RED."This arena has been setup in a place that no longer exists.");
return false;
case self::STATUS_UNKNOWN:
$player->sendMessage($this->plugin->prefix.C::RED."This arena has a unknown status.");
return false;
}
$event = new ArenaAddPlayerEvent($this->plugin, $this, $player);
try {
Expand All @@ -599,11 +607,15 @@ public function addPlayer(Player $player) : bool{
$player->sendMessage($this->plugin->prefix.C::RED."Unable to join arena, reason: ".$event->getReason());
return false;
}

$this->playerOldPositions[strtolower($player->getName())] = [$player->getLevel()->getName(),$player->getX(), $player->getY(), $player->getZ()];
if(!$this->spawnPlayer($player)){
unset($this->playerOldPositions[strtolower($player->getName())]);
return false;
}
$player->setGamemode(0); //todo Beta4 configurable.
$this->players[] = strtolower($player->getName());
$this->playerOldPositions[strtolower($player->getName())] = [$player->getLevel()->getName(),$player->getX(), $player->getY(), $player->getZ()];
$this->broadcastJoin($player);
$this->spawnPlayer($player);
if(count($this->players) >= $this->minPlayers && $this->timerTask === null && $this->plugin->config["auto_start"] === true){
$this->startTimer();
}
Expand Down
9 changes: 2 additions & 7 deletions src/Jackthehack21/KOTH/CommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function handleCommand(CommandSender $sender, Command $cmd, /** @noinspec
}
$name = $arena->getName();
$status = $arena->getFriendlyStatus();
$players = count($arena->players);
$players = count($arena->getPlayers());
$spawns = count($arena->spawns);
$rewards = $arena->rewards;
$gameTime = $arena->time;
Expand Down Expand Up @@ -427,7 +427,7 @@ private function createArena(CommandSender $sender, array $args) : void{
$sender->sendMessage($this->prefix.C::RED."Min value must be a number.");
return;
}
if(intval($min) < 1){
if(intval($min) < 2){
$sender->sendMessage($this->prefix.C::RED."minimum value must be above 2.");
return;
}
Expand All @@ -449,11 +449,6 @@ private function createArena(CommandSender $sender, array $args) : void{
return;
}

if($this->plugin->getArenaByName($name) !== null){
$sender->sendMessage($this->prefix.C::RED."A arena under that name already exists.");
return;
}

$event = new ArenaCreateEvent($this->plugin, $sender, $name, intval($min), intval($max), intval($gameTime));
try {
$event->call();
Expand Down
1 change: 1 addition & 0 deletions src/Jackthehack21/KOTH/Events/KothEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ abstract class KothEvent extends PluginEvent implements Cancellable{

public function __construct(Main $plugin)
{
$plugin->debug("Event '".$this->getEventName()."' is being constructed...");
parent::__construct($plugin);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Jackthehack21/KOTH/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public function getAllArenas(): array
public function getArenaByPlayer(string $name)
{
foreach ($this->arenas as $arena) {
if (in_array(strtolower($name), $arena->players)) {
if (in_array(strtolower($name), $arena->getPlayers())) {
return $arena;
}
}
Expand Down

0 comments on commit b98f1e9

Please sign in to comment.