-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- config - new /1vs1 join command - customizable kits - new PlayerEquipEvent
- Loading branch information
Showing
12 changed files
with
296 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
# | ||
## 1vs1 v1.0.1 configuration file | ||
# | ||
|
||
# Kits are randomly selected | ||
kits: | ||
diamond: | ||
helmet: [310, 0, 1] # [id, damage, count] | ||
chestplate: [311, 0, 1] | ||
leggings: [312, 0, 1] | ||
boots: [313, 0, 1] | ||
0: [267, 0, 1] # 1. inventory slot | ||
1: [322, 0, 5] # 2. inventory slot | ||
8: [364, 0, 16] # 9. inventory slot | ||
#steve: [] # add more kits like 'steve' kit here without any items | ||
|
||
# Set false to disable hunger in game | ||
hunger: true | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2018-2019 GamakCZ | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace vixikhd\onevsone; | ||
|
||
use vixikhd\onevsone\arena\Arena; | ||
|
||
/** | ||
* Class EmptyArenaChooser | ||
* @package vixikhd\onevsone | ||
*/ | ||
class EmptyArenaChooser { | ||
|
||
/** @var OneVsOne $plugin */ | ||
public $plugin; | ||
|
||
/** | ||
* EmptyArenaQueue constructor. | ||
* @param OneVsOne $plugin | ||
*/ | ||
public function __construct(OneVsOne $plugin) { | ||
$this->plugin = $plugin; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return null|Arena | ||
* | ||
* 1. Choose all arenas | ||
* 2. Remove in-game arenas | ||
* 3. Sort arenas by players | ||
* 4. Sort arenas by rand() | ||
*/ | ||
public function getRandomArena(): ?Arena { | ||
//1. | ||
|
||
/** @var Arena[] $availableArenas */ | ||
$availableArenas = []; | ||
foreach ($this->plugin->arenas as $index => $arena) { | ||
$availableArenas[$index] = $arena; | ||
} | ||
|
||
//2. | ||
foreach ($availableArenas as $index => $arena) { | ||
if($arena->phase !== 0 || $arena->setup) { | ||
unset($availableArenas[$index]); | ||
} | ||
} | ||
|
||
//3. | ||
$arenasByPlayers = []; | ||
foreach ($availableArenas as $index => $arena) { | ||
$arenasByPlayers[$index] = count($arena->players); | ||
} | ||
|
||
arsort($arenasByPlayers); | ||
$top = -1; | ||
$availableArenas = []; | ||
|
||
foreach ($arenasByPlayers as $index => $players) { | ||
if($top == -1) { | ||
$top = $players; | ||
$availableArenas[] = $index; | ||
} | ||
else { | ||
if($top == $players) { | ||
$availableArenas[] = $index; | ||
} | ||
} | ||
} | ||
|
||
if(empty($availableArenas)) { | ||
return null; | ||
} | ||
|
||
return $this->plugin->arenas[$availableArenas[array_rand($availableArenas, 1)]]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.