├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── phpunit.xml
├── resources
├── game_info
│ ├── Arena.json
│ ├── Arena.php
│ ├── Battlegrounds.json
│ ├── Battlegrounds.php
│ ├── Paintball.json
│ ├── Paintball.php
│ ├── README.md
│ ├── SkyClash.json
│ ├── SkyClash.php
│ ├── SkyWars.json
│ ├── SkyWars.php
│ ├── SuperSmash.json
│ ├── SuperSmash.php
│ ├── SurvivalGames.json
│ ├── SurvivalGames.php
│ ├── Walls3.json
│ ├── Walls3.php
│ └── tntgames
│ │ ├── Wizards.php
│ │ └── wizards.json
└── guild
│ └── RankWhitelist.php
├── src
├── HypixelPHP.php
├── cache
│ ├── CacheHandler.php
│ ├── CacheTimes.php
│ ├── CacheTypes.php
│ └── impl
│ │ ├── FlatFileCacheHandler.php
│ │ ├── MongoCacheHandler.php
│ │ └── NoCacheHandler.php
├── classes
│ ├── APIHolding.php
│ ├── APIObject.php
│ ├── DataHolding.php
│ ├── HypixelObject.php
│ ├── Module.php
│ └── serverType
│ │ ├── GameType.php
│ │ ├── LobbyType.php
│ │ ├── ServerType.php
│ │ └── ServerTypes.php
├── color
│ ├── ColorParser.php
│ └── ColorUtils.php
├── exceptions
│ ├── BadResponseCodeException.php
│ ├── CurlException.php
│ ├── ExceptionCodes.php
│ ├── FileGetContentsException.php
│ ├── HypixelPHPException.php
│ ├── InvalidUUIDException.php
│ └── NoPairsException.php
├── fetch
│ ├── FetchParams.php
│ ├── FetchTypes.php
│ ├── Fetcher.php
│ ├── Response.php
│ ├── adapter
│ │ └── ResponseAdapter.php
│ └── impl
│ │ ├── DefaultCurlFetcher.php
│ │ └── DefaultFGCFetcher.php
├── log
│ ├── Formatter.php
│ ├── Logger.php
│ └── impl
│ │ ├── BasicLogger.php
│ │ ├── NoLogger.php
│ │ └── SysLogger.php
├── provider
│ └── Provider.php
├── resources
│ ├── GameResources.php
│ ├── GeneralResources.php
│ ├── GuildResources.php
│ ├── ResourceManager.php
│ ├── Resources.php
│ └── games
│ │ └── SkyBlockResources.php
├── responses
│ ├── KeyInfo.php
│ ├── Leaderboards.php
│ ├── PunishmentStats.php
│ ├── RecentGames.php
│ ├── Resource.php
│ ├── Status.php
│ ├── booster
│ │ ├── Booster.php
│ │ └── Boosters.php
│ ├── counts
│ │ ├── Counts.php
│ │ └── GameCount.php
│ ├── guild
│ │ ├── Guild.php
│ │ ├── GuildLevelUtil.php
│ │ ├── GuildMember.php
│ │ ├── GuildMemberList.php
│ │ ├── GuildRank.php
│ │ └── GuildRanks.php
│ ├── player
│ │ ├── GameStats.php
│ │ ├── Player.php
│ │ ├── Rank.php
│ │ ├── RankTypes.php
│ │ └── Stats.php
│ └── skyblock
│ │ └── SkyBlockProfile.php
├── util
│ ├── CacheUtil.php
│ ├── CachedGetter.php
│ ├── InputType.php
│ ├── Leveling.php
│ ├── Utilities.php
│ ├── Validator.php
│ └── games
│ │ ├── BlitzUtils.php
│ │ ├── GameUtils.php
│ │ ├── MegaWallsUtils.php
│ │ ├── bedwars
│ │ ├── BedWarsPrestige.php
│ │ ├── BedWarsUtils.php
│ │ └── ExpCalculator.php
│ │ └── skywars
│ │ ├── ExpCalculator.php
│ │ └── SkyWarsUtils.php
└── wrappers
│ ├── Kart.php
│ ├── PetStats.php
│ └── battlegrounds
│ ├── Abilities.php
│ ├── Ability.php
│ ├── AbilityType.php
│ ├── PlayerClass.php
│ ├── PlayerClasses.php
│ ├── Spec.php
│ └── weapon
│ ├── Rarity.php
│ ├── RarityValues.php
│ ├── Weapon.php
│ ├── WeaponGrader.php
│ ├── WeaponInventory.php
│ ├── WeaponStat.php
│ └── WeaponStats.php
└── tests
├── CacheTest.php
├── ColorTest.php
├── DataHoldingTest.php
├── ResponseTest.php
├── ValidatorTest.php
├── bootstrap.php
├── games
└── bedwars
│ └── LevelTest.php
└── util
└── TestUtil.php
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/*
2 |
3 | ### Composer template
4 | composer.phar
5 | /vendor/
6 |
7 | # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
8 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
9 | composer.lock
10 |
11 | /.phpunit.*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Aäron Plancke
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Hypixel PHP
2 |
3 | This is a PHP wrapper for the [Hypixel Public API](https://api.hypixel.net)
4 |
5 | ## Requirements
6 | - PHP 7+
7 | - Hypixel API key
8 |
9 | ## Installation
10 |
11 | The preferred method of installing this library is with [Composer](https://getcomposer.org) by running the following from your project root:
12 |
13 | $ composer require "plancke/hypixel-php=^1.4.0"
14 |
15 | ## Usage
16 |
17 | To interact with the API you need an API key, you can get a key by doing "/api" on the Hypixel Network.
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "plancke/hypixel-php",
3 | "description": "A PHP wrapper for the Hypixel Public API",
4 | "homepage": "https://plancke.io",
5 | "license": "MIT",
6 | "authors": [
7 | {
8 | "name": "Plancke",
9 | "email": "admin@plancke.io",
10 | "role": "Developer"
11 | }
12 | ],
13 | "keywords": [
14 | "hypixel",
15 | "plancke",
16 | "api",
17 | "wrapper"
18 | ],
19 | "support": {
20 | "issues": "https://github.com/Plancke/hypixel-php/issues"
21 | },
22 | "require": {
23 | "php": "^7.0",
24 | "ext-curl": "*",
25 | "ext-json": "*"
26 | },
27 | "suggest": {
28 | "ext-mongodb": "^1.4.2",
29 | "mongodb/mongodb": "^1.4.2"
30 | },
31 | "autoload": {
32 | "psr-4": {
33 | "Plancke\\HypixelPHP\\": "src/"
34 | }
35 | },
36 | "require-dev": {
37 | "phpunit/phpunit": "8.0.6",
38 | "ext-mongodb": "^1.4.2",
39 | "mongodb/mongodb": "^1.4.2"
40 | },
41 | "autoload-dev": {
42 | "psr-4": {
43 | "Plancke\\Tests\\": "tests/"
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 | ./tests/
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/resources/game_info/Arena.json:
--------------------------------------------------------------------------------
1 | {
2 | "skills": {
3 | "offensive": {
4 | "boulder_toss": {
5 | "display": "Boulder Toss",
6 | "cost": 2800,
7 | "energy": 80
8 | },
9 | "cookie_shotgun": {
10 | "display": "Cookie Shotgun",
11 | "cost": 12000,
12 | "energy": 60
13 | },
14 | "fireball": {
15 | "display": "Fireball",
16 | "cost": 0,
17 | "energy": 40
18 | },
19 | "flame_breath": {
20 | "display": "Flame Breath",
21 | "cost": 25000,
22 | "energy": 60
23 | },
24 | "freezing_breath": {
25 | "display": "Freezing Breath",
26 | "cost": 25000,
27 | "energy": 80
28 | },
29 | "guided_pig_2000": {
30 | "display": "Guided Pig 2000",
31 | "cost": 0,
32 | "energy": 100
33 | },
34 | "lightning_strike": {
35 | "display": "Lightning Strike",
36 | "cost": 1200,
37 | "energy": 70
38 | },
39 | "melon_launcher": {
40 | "display": "Melon Launcher",
41 | "cost": 9000,
42 | "energy": 60
43 | },
44 | "proximity_mine": {
45 | "display": "Proximity Mine",
46 | "cost": 12000,
47 | "energy": 100
48 | },
49 | "rocket_chicken": {
50 | "display": "Rocket Chicken",
51 | "cost": 1000,
52 | "energy": 30
53 | },
54 | "seismic_wave": {
55 | "display": "Seismic Wave",
56 | "cost": 12000,
57 | "energy": 100
58 | },
59 | "snowball": {
60 | "display": "Snowball",
61 | "cost": 120,
62 | "energy": 20
63 | }
64 | },
65 | "utility": {
66 | "barricade": {
67 | "display": "Barricade",
68 | "cost": 600,
69 | "cooldown": 30
70 | },
71 | "bull_charge": {
72 | "display": "Bull Charge",
73 | "cost": 0,
74 | "cooldown": 40
75 | },
76 | "golemfall": {
77 | "display": "Golemfall",
78 | "cost": 12000,
79 | "cooldown": 40
80 | },
81 | "polymorph": {
82 | "display": "Polymorph",
83 | "cost": 12000,
84 | "cooldown": 40
85 | },
86 | "shadow_step": {
87 | "display": "Shadow Step",
88 | "cost": 3600,
89 | "cooldown": 40
90 | },
91 | "swap": {
92 | "display": "Swap",
93 | "cost": 12000,
94 | "cooldown": 30
95 | },
96 | "wall_of_vines": {
97 | "display": "Wall of Vines",
98 | "cost": 3600,
99 | "cooldown": 30
100 | }
101 | },
102 | "support": {
103 | "bone_shield": {
104 | "display": "Bone Shield",
105 | "cost": 2400,
106 | "cooldown": 30
107 | },
108 | "healing_totem": {
109 | "display": "Healing Totem",
110 | "cost": 0,
111 | "cooldown": 40
112 | },
113 | "holy_water": {
114 | "display": "Holy Water",
115 | "cost": 600,
116 | "cooldown": 30
117 | },
118 | "life_leech": {
119 | "display": "Life Leech",
120 | "cost": 12000,
121 | "cooldown": 30
122 | },
123 | "song_of_power": {
124 | "display": "Song of Power",
125 | "cost": 4500,
126 | "cooldown": 60
127 | },
128 | "star_shield": {
129 | "display": "Star Shield",
130 | "cost": 0,
131 | "cooldown": 45
132 | },
133 | "tree_of_lifeTree of Life": {
134 | "display": "Tree of Life",
135 | "cost": 12000,
136 | "cooldown": 40
137 | }
138 | },
139 | "ultimate": {
140 | "shield_wall": {
141 | "display": "shield_wall",
142 | "cost": 0
143 | },
144 | "berserk": {
145 | "display": "Beserk",
146 | "cost": 1200
147 | },
148 | "arachnid": {
149 | "display": "Broodmother",
150 | "cost": 25000
151 | }
152 | }
153 | },
154 | "runes": {
155 | "types": {
156 | "damage": {
157 | },
158 | "speed": {
159 | },
160 | "energy": {
161 | },
162 | "slowing": {
163 | }
164 | },
165 | "prices": [
166 | 3250,
167 | 13000,
168 | 29250,
169 | 52000,
170 | 81250,
171 | 117000
172 | ]
173 | }
174 | }
--------------------------------------------------------------------------------
/resources/game_info/Arena.php:
--------------------------------------------------------------------------------
1 |
4 | array(
5 | 'offensive' =>
6 | array(
7 | 'boulder_toss' =>
8 | array(
9 | 'display' => 'Boulder Toss',
10 | 'cost' => 2800,
11 | 'energy' => 80,
12 | ),
13 | 'cookie_shotgun' =>
14 | array(
15 | 'display' => 'Cookie Shotgun',
16 | 'cost' => 12000,
17 | 'energy' => 60,
18 | ),
19 | 'fireball' =>
20 | array(
21 | 'display' => 'Fireball',
22 | 'cost' => 0,
23 | 'energy' => 40,
24 | ),
25 | 'flame_breath' =>
26 | array(
27 | 'display' => 'Flame Breath',
28 | 'cost' => 25000,
29 | 'energy' => 60,
30 | ),
31 | 'freezing_breath' =>
32 | array(
33 | 'display' => 'Freezing Breath',
34 | 'cost' => 25000,
35 | 'energy' => 80,
36 | ),
37 | 'guided_pig_2000' =>
38 | array(
39 | 'display' => 'Guided Pig 2000',
40 | 'cost' => 0,
41 | 'energy' => 100,
42 | ),
43 | 'lightning_strike' =>
44 | array(
45 | 'display' => 'Lightning Strike',
46 | 'cost' => 1200,
47 | 'energy' => 70,
48 | ),
49 | 'melon_launcher' =>
50 | array(
51 | 'display' => 'Melon Launcher',
52 | 'cost' => 9000,
53 | 'energy' => 60,
54 | ),
55 | 'proximity_mine' =>
56 | array(
57 | 'display' => 'Proximity Mine',
58 | 'cost' => 12000,
59 | 'energy' => 100,
60 | ),
61 | 'rocket_chicken' =>
62 | array(
63 | 'display' => 'Rocket Chicken',
64 | 'cost' => 1000,
65 | 'energy' => 30,
66 | ),
67 | 'seismic_wave' =>
68 | array(
69 | 'display' => 'Seismic Wave',
70 | 'cost' => 12000,
71 | 'energy' => 100,
72 | ),
73 | 'snowball' =>
74 | array(
75 | 'display' => 'Snowball',
76 | 'cost' => 120,
77 | 'energy' => 20,
78 | ),
79 | ),
80 | 'utility' =>
81 | array(
82 | 'barricade' =>
83 | array(
84 | 'display' => 'Barricade',
85 | 'cost' => 600,
86 | 'cooldown' => 30,
87 | ),
88 | 'bull_charge' =>
89 | array(
90 | 'display' => 'Bull Charge',
91 | 'cost' => 0,
92 | 'cooldown' => 40,
93 | ),
94 | 'golemfall' =>
95 | array(
96 | 'display' => 'Golemfall',
97 | 'cost' => 12000,
98 | 'cooldown' => 40,
99 | ),
100 | 'polymorph' =>
101 | array(
102 | 'display' => 'Polymorph',
103 | 'cost' => 12000,
104 | 'cooldown' => 40,
105 | ),
106 | 'shadow_step' =>
107 | array(
108 | 'display' => 'Shadow Step',
109 | 'cost' => 3600,
110 | 'cooldown' => 40,
111 | ),
112 | 'swap' =>
113 | array(
114 | 'display' => 'Swap',
115 | 'cost' => 12000,
116 | 'cooldown' => 30,
117 | ),
118 | 'wall_of_vines' =>
119 | array(
120 | 'display' => 'Wall of Vines',
121 | 'cost' => 3600,
122 | 'cooldown' => 30,
123 | ),
124 | ),
125 | 'support' =>
126 | array(
127 | 'bone_shield' =>
128 | array(
129 | 'display' => 'Bone Shield',
130 | 'cost' => 2400,
131 | 'cooldown' => 30,
132 | ),
133 | 'healing_totem' =>
134 | array(
135 | 'display' => 'Healing Totem',
136 | 'cost' => 0,
137 | 'cooldown' => 40,
138 | ),
139 | 'holy_water' =>
140 | array(
141 | 'display' => 'Holy Water',
142 | 'cost' => 600,
143 | 'cooldown' => 30,
144 | ),
145 | 'life_leech' =>
146 | array(
147 | 'display' => 'Life Leech',
148 | 'cost' => 12000,
149 | 'cooldown' => 30,
150 | ),
151 | 'song_of_power' =>
152 | array(
153 | 'display' => 'Song of Power',
154 | 'cost' => 4500,
155 | 'cooldown' => 60,
156 | ),
157 | 'star_shield' =>
158 | array(
159 | 'display' => 'Star Shield',
160 | 'cost' => 0,
161 | 'cooldown' => 45,
162 | ),
163 | 'tree_of_lifeTree of Life' =>
164 | array(
165 | 'display' => 'Tree of Life',
166 | 'cost' => 12000,
167 | 'cooldown' => 40,
168 | ),
169 | ),
170 | 'ultimate' =>
171 | array(
172 | 'shield_wall' =>
173 | array(
174 | 'display' => 'shield_wall',
175 | 'cost' => 0,
176 | ),
177 | 'berserk' =>
178 | array(
179 | 'display' => 'Beserk',
180 | 'cost' => 1200,
181 | ),
182 | 'arachnid' =>
183 | array(
184 | 'display' => 'Broodmother',
185 | 'cost' => 25000,
186 | ),
187 | ),
188 | ),
189 | 'runes' =>
190 | array(
191 | 'types' =>
192 | array(
193 | 'damage' =>
194 | array(),
195 | 'speed' =>
196 | array(),
197 | 'energy' =>
198 | array(),
199 | 'slowing' =>
200 | array(),
201 | ),
202 | 'prices' =>
203 | array(
204 | 0 => 3250,
205 | 1 => 13000,
206 | 2 => 29250,
207 | 3 => 52000,
208 | 4 => 81250,
209 | 5 => 117000,
210 | ),
211 | ),
212 | );
--------------------------------------------------------------------------------
/resources/game_info/Battlegrounds.json:
--------------------------------------------------------------------------------
1 | {
2 | "classes": {
3 | "mage": {
4 | "spec": {
5 | "pyromancer": {
6 | "display": "Pyromancer",
7 | "cost": 0
8 | },
9 | "cryomancer": {
10 | "display": "Cryomancer",
11 | "cost": 5000
12 | },
13 | "aquamancer": {
14 | "display": "Aquamancer",
15 | "cost": 15000
16 | }
17 | },
18 | "display": "Mage"
19 | },
20 | "warrior": {
21 | "spec": {
22 | "berserker": {
23 | "display": "Berserker",
24 | "cost": 0
25 | },
26 | "defender": {
27 | "display": "Defender",
28 | "cost": 15000
29 | }
30 | },
31 | "display": "Warrior"
32 | },
33 | "paladin": {
34 | "spec": {
35 | "avenger": {
36 | "display": "Avenger",
37 | "cost": 0
38 | },
39 | "crusader": {
40 | "display": "Crusader",
41 | "cost": 5000
42 | },
43 | "protector": {
44 | "display": "Protector",
45 | "cost": 15000
46 | }
47 | },
48 | "display": "Paladin"
49 | },
50 | "shaman": {
51 | "spec": {
52 | "thunderlord": {
53 | "display": "Thunderlord",
54 | "cost": 0
55 | },
56 | "earthwarden": {
57 | "display": "Earthwarden",
58 | "cost": 15000
59 | }
60 | }
61 | }
62 | },
63 | "classUpgrades": {
64 | "skill": {
65 | "fields": [
66 | "skill1",
67 | "skill2",
68 | "skill3",
69 | "skill4",
70 | "skill5"
71 | ],
72 | "costs": [
73 | 1560,
74 | 2350,
75 | 3750,
76 | 6400,
77 | 11500,
78 | 21900,
79 | 43750,
80 | 91900,
81 | 202500
82 | ]
83 | },
84 | "combat": {
85 | "fields": [
86 | "energy",
87 | "health",
88 | "cooldown",
89 | "critchance",
90 | "critmultiplier"
91 | ],
92 | "costs": [
93 | 780,
94 | 1175,
95 | 1875,
96 | 3200,
97 | 5750,
98 | 10950,
99 | 21875,
100 | 45950,
101 | 101250
102 | ]
103 | }
104 | },
105 | "repairCost": 10
106 | }
--------------------------------------------------------------------------------
/resources/game_info/Battlegrounds.php:
--------------------------------------------------------------------------------
1 |
4 | array(
5 | 'mage' =>
6 | array(
7 | 'spec' =>
8 | array(
9 | 'pyromancer' =>
10 | array(
11 | 'display' => 'Pyromancer',
12 | 'cost' => 0,
13 | ),
14 | 'cryomancer' =>
15 | array(
16 | 'display' => 'Cryomancer',
17 | 'cost' => 5000,
18 | ),
19 | 'aquamancer' =>
20 | array(
21 | 'display' => 'Aquamancer',
22 | 'cost' => 15000,
23 | ),
24 | ),
25 | 'display' => 'Mage',
26 | ),
27 | 'warrior' =>
28 | array(
29 | 'spec' =>
30 | array(
31 | 'berserker' =>
32 | array(
33 | 'display' => 'Berserker',
34 | 'cost' => 0,
35 | ),
36 | 'defender' =>
37 | array(
38 | 'display' => 'Defender',
39 | 'cost' => 15000,
40 | ),
41 | ),
42 | 'display' => 'Warrior',
43 | ),
44 | 'paladin' =>
45 | array(
46 | 'spec' =>
47 | array(
48 | 'avenger' =>
49 | array(
50 | 'display' => 'Avenger',
51 | 'cost' => 0,
52 | ),
53 | 'crusader' =>
54 | array(
55 | 'display' => 'Crusader',
56 | 'cost' => 5000,
57 | ),
58 | 'protector' =>
59 | array(
60 | 'display' => 'Protector',
61 | 'cost' => 15000,
62 | ),
63 | ),
64 | 'display' => 'Paladin',
65 | ),
66 | 'shaman' =>
67 | array(
68 | 'spec' =>
69 | array(
70 | 'thunderlord' =>
71 | array(
72 | 'display' => 'Thunderlord',
73 | 'cost' => 0,
74 | ),
75 | 'earthwarden' =>
76 | array(
77 | 'display' => 'Earthwarden',
78 | 'cost' => 0,
79 | ),
80 | ),
81 | ),
82 | ),
83 | 'classUpgrades' =>
84 | array(
85 | 'skill' =>
86 | array(
87 | 'fields' =>
88 | array(
89 | 0 => 'skill1',
90 | 1 => 'skill2',
91 | 2 => 'skill3',
92 | 3 => 'skill4',
93 | 4 => 'skill5',
94 | ),
95 | 'costs' =>
96 | array(
97 | 0 => 1560,
98 | 1 => 2350,
99 | 2 => 3750,
100 | 3 => 6400,
101 | 4 => 11500,
102 | 5 => 21900,
103 | 6 => 43750,
104 | 7 => 91900,
105 | 8 => 202500,
106 | ),
107 | ),
108 | 'combat' =>
109 | array(
110 | 'fields' =>
111 | array(
112 | 0 => 'energy',
113 | 1 => 'health',
114 | 2 => 'cooldown',
115 | 3 => 'critchance',
116 | 4 => 'critmultiplier',
117 | ),
118 | 'costs' =>
119 | array(
120 | 0 => 780,
121 | 1 => 1175,
122 | 2 => 1875,
123 | 3 => 3200,
124 | 4 => 5750,
125 | 5 => 10950,
126 | 6 => 21875,
127 | 7 => 45950,
128 | 8 => 101250,
129 | ),
130 | ),
131 | ),
132 | 'repairCost' => 10,
133 | );
--------------------------------------------------------------------------------
/resources/game_info/Paintball.json:
--------------------------------------------------------------------------------
1 | {
2 | "perks": {
3 | "endurance": {
4 | "display": "Endurance",
5 | "increment": 7500,
6 | "max": 50
7 | },
8 | "godfather": {
9 | "display": "Godfather",
10 | "increment": 5000,
11 | "max": 50
12 | },
13 | "superluck": {
14 | "display": "Superluck",
15 | "costs": [
16 | 250,
17 | 500,
18 | 750,
19 | 1000,
20 | 1250,
21 | 1500,
22 | 1750,
23 | 2000,
24 | 2500,
25 | 5000,
26 | 5500,
27 | 6000,
28 | 7000,
29 | 8000,
30 | 9000,
31 | 10000,
32 | 12500,
33 | 15000,
34 | 17500,
35 | 20000
36 | ]
37 | },
38 | "fortune": {
39 | "display": "Fortune",
40 | "costs": [
41 | 1000,
42 | 2000,
43 | 3000,
44 | 4000,
45 | 5000,
46 | 6000,
47 | 7000,
48 | 8000,
49 | 9000,
50 | 10000,
51 | 20000,
52 | 30000,
53 | 40000,
54 | 50000,
55 | 60000,
56 | 70000,
57 | 80000,
58 | 90000,
59 | 100000,
60 | 200000
61 | ]
62 | },
63 | "headstart": {
64 | "display": "HeadStart",
65 | "costs": [
66 | 10000,
67 | 25000,
68 | 45000,
69 | 70000,
70 | 100000
71 | ]
72 | },
73 | "transfusion": {
74 | "display": "Transfusion",
75 | "costs": [
76 | 100,
77 | 500,
78 | 1000,
79 | 7500,
80 | 12000,
81 | 18000,
82 | 24000,
83 | 30000,
84 | 38000,
85 | 45000
86 | ]
87 | },
88 | "adrenaline": {
89 | "display": "Adrenaline",
90 | "increment": 10000,
91 | "max": 10
92 | }
93 | },
94 | "killstreaks": {
95 | "flashbang": {
96 | "display": "Flashbang",
97 | "desc": "A smoke grenade with an area of effect",
98 | "cost": 2500,
99 | "killcoins": 2
100 | },
101 | "tripleshot": {
102 | "display": "Triple Shot",
103 | "desc": "Throw three balls at once",
104 | "cost": 2500,
105 | "killcoins": 3
106 | },
107 | "strongarm": {
108 | "display": "Strong Arm",
109 | "desc": "Throw more snowballs faster",
110 | "cost": 0,
111 | "killcoins": 4
112 | },
113 | "plusthree": {
114 | "display": "+3",
115 | "desc": "Regain 3 lives for your team",
116 | "cost": 0,
117 | "killcoins": 5
118 | },
119 | "creeperhead": {
120 | "display": "Creeper Head",
121 | "desc": "Spawn creepers to fight for you",
122 | "cost": 2500,
123 | "killcoins": 8
124 | },
125 | "rambo": {
126 | "display": "RAMBO",
127 | "desc": "Respawn instantly with no loss of lives",
128 | "cost": 0,
129 | "killcoins": 10
130 | },
131 | "tntrain": {
132 | "display": "TNT Rain",
133 | "desc": "Rain TNT down on your enemies.",
134 | "cost": 2500,
135 | "killcoins": 10
136 | },
137 | "plusten": {
138 | "display": "+10",
139 | "desc": "Regain 10 lives for your team.",
140 | "cost": 2500,
141 | "killcoins": 15
142 | },
143 | "nuke": {
144 | "display": "Nuke",
145 | "desc": "Destroys the enemy team with 100% accuracy",
146 | "cost": 5500,
147 | "killcoins": 25
148 | },
149 | "ammo": {
150 | "display": "Ammo",
151 | "desc": "Get a stack of 32 snowballs",
152 | "cost": 0,
153 | "killcoins": 3
154 | },
155 | "leeroyjenkins": {
156 | "display": "LEEROYJENKINS",
157 | "desc": "Spawn 30 chickens on the enemy spawn",
158 | "cost": 0,
159 | "killcoins": 5
160 | },
161 | "superstrongarm": {
162 | "display": "Super Strong Arm",
163 | "desc": "A stronger variant of strongarm",
164 | "cost": 2500,
165 | "killcoins": 7
166 | },
167 | "teamammo": {
168 | "display": "Team Ammo",
169 | "desc": "32 paintballs for everyone in your team",
170 | "cost": 0,
171 | "killcoins": 5
172 | },
173 | "revenge": {
174 | "display": "Revenge",
175 | "desc": "Kills the player who killed you last",
176 | "cost": 0,
177 | "killcoins": 10
178 | },
179 | "lightning": {
180 | "display": "Lightning",
181 | "desc": "Strike down enemies within 10 blocks",
182 | "cost": 2500,
183 | "killcoins": 12
184 | },
185 | "enderpearl": {
186 | "display": "Enderpearl",
187 | "desc": "Teleport to where you last died.",
188 | "cost": 2500,
189 | "killcoins": 15
190 | },
191 | "endereye": {
192 | "display": "Endereye",
193 | "desc": "Swap places with a random enemy.",
194 | "cost": 2500,
195 | "killcoins": 15
196 | },
197 | "forcefield": {
198 | "display": "Force Field",
199 | "desc": "Reflect paintballs for 15 seconds",
200 | "cost": 6500,
201 | "killcoins": 50
202 | },
203 | "bomberman": {
204 | "display": "Bomber Man",
205 | "desc": "Explode all enemies within 20 blocks, also kills yourself!",
206 | "cost": 2500,
207 | "killcoins": 20
208 | },
209 | "backstab": {
210 | "display": "Backstab",
211 | "desc": "Teleport to where your next kill dies",
212 | "cost": 2500,
213 | "killcoins": 7
214 | },
215 | "sentry": {
216 | "display": "Sentry",
217 | "desc": "Spawn a Sentry that kills for you!",
218 | "cost": 2500,
219 | "killcoins": 7
220 | },
221 | "quintupleshot": {
222 | "display": "Quintuple Shot",
223 | "desc": "Shoot 5 paintballs at once",
224 | "cost": 5000,
225 | "killcoins": 9
226 | },
227 | "landmine": {
228 | "display": "Landmine",
229 | "desc": "Spawn a Landmine where you're standing.",
230 | "cost": 2500,
231 | "killcoins": 3
232 | }
233 | },
234 | "hats": {
235 | "tnt_hat": {
236 | "cost": 4200,
237 | "display": "TNT"
238 | },
239 | "speed_hat": {
240 | "cost": 3000,
241 | "display": "Speed"
242 | },
243 | "snow_hat": {
244 | "cost": 4200,
245 | "display": "Snow"
246 | },
247 | "hard_hat": {
248 | "cost": 4200,
249 | "display": "Hard"
250 | },
251 | "ender_hat": {
252 | "cost": 4200,
253 | "display": "Ender"
254 | },
255 | "hat_of_darkness": {
256 | "cost": 4200,
257 | "display": "Dark"
258 | },
259 | "trololol_hat": {
260 | "cost": 4200,
261 | "display": "Troll"
262 | },
263 | "normal_hat": {
264 | "cost": 2000,
265 | "display": "Normal"
266 | },
267 | "drunk_hat": {
268 | "cost": 4200,
269 | "display": "Drunk"
270 | },
271 | "squid_hat": {
272 | "cost": 4200,
273 | "display": "Squid"
274 | },
275 | "spider_hat": {
276 | "cost": 4200,
277 | "display": "Spider"
278 | },
279 | "shaky_hat": {
280 | "cost": 4200,
281 | "display": "Shaky"
282 | },
283 | "vip_agentk_hat": {
284 | "cost": 75000,
285 | "display": "AgentK"
286 | },
287 | "vip_kevinkool_hat": {
288 | "cost": 75000,
289 | "display": "KevinKool"
290 | },
291 | "vip_rezzus_hat": {
292 | "cost": 100000,
293 | "display": "Rezzus"
294 | },
295 | "vip_neonmaster_hat": {
296 | "cost": 75000,
297 | "display": "Mystery"
298 | },
299 | "vip_hypixel_hat": {
300 | "cost": 75000,
301 | "display": "hypixel"
302 | },
303 | "vip_codename_b_hat": {
304 | "cost": 75000,
305 | "display": "codename_b"
306 | },
307 | "vip_paintballkitty_hat": {
308 | "cost": 75000,
309 | "display": "PaintBallKitty"
310 | },
311 | "vip_noxyd_hat": {
312 | "cost": 50000,
313 | "display": "NoxyD"
314 | },
315 | "vip_ghost_hat": {
316 | "cost": 50000,
317 | "display": "Ghost"
318 | }
319 | },
320 | "teams": {
321 | "1": [
322 | "red",
323 | "yellow",
324 | "orange",
325 | "white"
326 | ],
327 | "2": [
328 | "blue",
329 | "aqua",
330 | "green",
331 | "purple"
332 | ]
333 | },
334 | "maps": {
335 | "Herobrine": {
336 | "size": "large",
337 | "players": 32,
338 | "team": 2
339 | },
340 | "Victorian": {
341 | "size": "large",
342 | "players": 28,
343 | "team": 1
344 | },
345 | "OhCanada": {
346 | "size": "normal",
347 | "players": 24,
348 | "team": 1
349 | },
350 | "Swamps": {
351 | "size": "normal",
352 | "players": 16,
353 | "team": 1
354 | },
355 | "Mansion": {
356 | "size": "small",
357 | "players": 16,
358 | "team": 0
359 | },
360 | "Lalaland": {
361 | "size": "normal",
362 | "players": 24,
363 | "team": 0
364 | },
365 | "Babyland": {
366 | "size": "normal",
367 | "players": 24,
368 | "team": 1
369 | },
370 | "Juice": {
371 | "size": "normal",
372 | "players": 24,
373 | "team": 2
374 | },
375 | "LaMente": {
376 | "size": "medium",
377 | "players": 24,
378 | "team": 1
379 | },
380 | "Egypt": {
381 | "size": "medium",
382 | "players": 24,
383 | "team": 2
384 | }
385 | }
386 | }
--------------------------------------------------------------------------------
/resources/game_info/README.md:
--------------------------------------------------------------------------------
1 | This contains some files that have data for gamemodes
2 |
3 | It includes some of my custom data needed for generators/stats page on my website
4 |
5 | This data format could change at any point but if it does, the project version should also change.
--------------------------------------------------------------------------------
/resources/game_info/SuperSmash.json:
--------------------------------------------------------------------------------
1 | {
2 | "prestigePrices": [
3 | 50000,
4 | 120000,
5 | 250000,
6 | 400000,
7 | 750000
8 | ],
9 | "masterSkinPrice": 250000,
10 | "classes": {
11 | "THE_BULK": {
12 | "display": "Bulk"
13 | },
14 | "GENERAL_CLUCK": {
15 | "display": "General Cluck"
16 | },
17 | "SPODERMAN": {
18 | "display": "Spooderman"
19 | },
20 | "DUSK_CRAWLER": {
21 | "display": "Void Crawler"
22 | },
23 | "TINMAN": {
24 | "display": "Tinman"
25 | },
26 | "GOKU": {
27 | "display": "Karakot"
28 | },
29 | "PUG": {
30 | "display": "Pug"
31 | },
32 | "FROSTY": {
33 | "display": "Cryomancer"
34 | },
35 | "CAKE_MONSTER": {
36 | "display": "Cake Monster"
37 | },
38 | "BOTMUN": {
39 | "display": "Botmon"
40 | },
41 | "SKULLFIRE": {
42 | "display": "Skullfire"
43 | },
44 | "SHOOP_DA_WHOOP": {
45 | "display": "Shoop"
46 | },
47 | "MARAUDER": {
48 | "display": "Marauder"
49 | },
50 | "SERGEANT_SHIELD": {
51 | "display": "Sgt. Shield"
52 | },
53 | "GREEN_HOOD": {
54 | "display": "Green Hood"
55 | },
56 | "SANIC": {
57 | "display": "Sanic"
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/resources/game_info/SuperSmash.php:
--------------------------------------------------------------------------------
1 |
4 | array(
5 | 0 => 50000,
6 | 1 => 120000,
7 | 2 => 250000,
8 | 3 => 400000,
9 | 4 => 750000,
10 | ),
11 | 'masterSkinPrice' => 250000,
12 | 'classes' =>
13 | array(
14 | 'THE_BULK' =>
15 | array(
16 | 'display' => 'Bulk',
17 | ),
18 | 'GENERAL_CLUCK' =>
19 | array(
20 | 'display' => 'General Cluck',
21 | ),
22 | 'SPODERMAN' =>
23 | array(
24 | 'display' => 'Spooderman',
25 | ),
26 | 'DUSK_CRAWLER' =>
27 | array(
28 | 'display' => 'Void Crawler',
29 | ),
30 | 'TINMAN' =>
31 | array(
32 | 'display' => 'Tinman',
33 | ),
34 | 'GOKU' =>
35 | array(
36 | 'display' => 'Karakot',
37 | ),
38 | 'PUG' =>
39 | array(
40 | 'display' => 'Pug',
41 | ),
42 | 'FROSTY' =>
43 | array(
44 | 'display' => 'Cryomancer',
45 | ),
46 | 'CAKE_MONSTER' =>
47 | array(
48 | 'display' => 'Cake Monster',
49 | ),
50 | 'BOTMUN' =>
51 | array(
52 | 'display' => 'Botmon',
53 | ),
54 | 'SKULLFIRE' =>
55 | array(
56 | 'display' => 'Skullfire',
57 | ),
58 | 'SHOOP_DA_WHOOP' =>
59 | array(
60 | 'display' => 'Shoop',
61 | ),
62 | 'MARAUDER' =>
63 | array(
64 | 'display' => 'Marauder',
65 | ),
66 | 'SERGEANT_SHIELD' =>
67 | array(
68 | 'display' => 'Sgt. Shield',
69 | ),
70 | 'GREEN_HOOD' =>
71 | array(
72 | 'display' => 'Green Hood',
73 | ),
74 | 'SANIC' =>
75 | array(
76 | 'display' => 'Sanic',
77 | ),
78 | ),
79 | );
--------------------------------------------------------------------------------
/resources/game_info/tntgames/Wizards.php:
--------------------------------------------------------------------------------
1 |
4 | array(
5 | 'list' =>
6 | array(
7 | 'firewizard' =>
8 | array(
9 | 'display' => 'Fire'
10 | ),
11 | 'kineticwizard' =>
12 | array(
13 | 'display' => 'Kinetic'
14 | ),
15 | 'icewizard' =>
16 | array(
17 | 'display' => 'Ice'
18 | ),
19 | 'witherwizard' =>
20 | array(
21 | 'display' => 'Wither'
22 | ),
23 | 'bloodwizard' =>
24 | array(
25 | 'display' => 'Blood'
26 | ),
27 | ),
28 | )
29 | );
--------------------------------------------------------------------------------
/resources/game_info/tntgames/wizards.json:
--------------------------------------------------------------------------------
1 | {
2 | "classes": {
3 | "list": {
4 | "firewizard": {
5 | "display": "Fire"
6 | },
7 | "kineticwizard": {
8 | "display": "Kinetic"
9 | },
10 | "icewizard": {
11 | "display": "Ice"
12 | },
13 | "witherwizard": {
14 | "display": "Wither"
15 | },
16 | "bloodwizard": {
17 | "display": "Blood"
18 | }
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/resources/guild/RankWhitelist.php:
--------------------------------------------------------------------------------
1 |
6 | array(
7 | 'guild master',
8 | 'guildmaster',
9 | 'founder',
10 | 'co-founder',
11 | 'owner',
12 | 'co-owner',
13 | 'co owner',
14 | 'guild leader',
15 | 'leader',
16 | 'officer',
17 | 'adviser',
18 | 'advisor',
19 | 'veteran',
20 | 'trusted',
21 | 'trusted member',
22 | 'retired',
23 | 'retiree',
24 | 'trial',
25 | 'trial member',
26 | 'elder',
27 | 'trainee',
28 | 'manager',
29 | 'head officer',
30 | 'co-master',
31 | 'sergeant',
32 | 'lieutenant',
33 | 'newbie',
34 | 'elite',
35 | 'senior',
36 | 'senior officer',
37 | 'crew',
38 | 'crew member',
39 | 'trial officer',
40 | 'junior officer',
41 | 'elite member',
42 | 'captain',
43 | 'general',
44 | 'rookie',
45 | 'private',
46 | 'active',
47 | 'active Member',
48 | 'recruiter',
49 | 'initiate',
50 | 'commander'
51 | )
52 | );
--------------------------------------------------------------------------------
/src/cache/CacheHandler.php:
--------------------------------------------------------------------------------
1 | 3 * 60 * 60,
32 |
33 | CacheTimes::PLAYER => 10 * 60,
34 | CacheTimes::UUID => 6 * 60 * 60,
35 | CacheTimes::UUID_NOT_FOUND => 2 * 60 * 60,
36 |
37 | CacheTimes::GUILD => 10 * 60,
38 | CacheTimes::GUILD_NOT_FOUND => 10 * 60,
39 |
40 | CacheTimes::LEADERBOARDS => 10 * 60,
41 | CacheTimes::BOOSTERS => 10 * 60,
42 | CacheTimes::STATUS => 10 * 60,
43 | CacheTimes::KEY_INFO => 10 * 60,
44 | CacheTimes::PUNISHMENT_STATS => 10 * 60,
45 | CacheTimes::COUNTS => 10 * 60,
46 |
47 | CacheTimes::SKYBLOCK_PROFILE => 10 * 60
48 | ];
49 | protected $globalTime = 0;
50 |
51 | /**
52 | * @return int
53 | */
54 | public function getGlobalTime() {
55 | return $this->globalTime;
56 | }
57 |
58 | /**
59 | * @param int $globalTime
60 | */
61 | public function setGlobalTime($globalTime) {
62 | $this->globalTime = $globalTime;
63 | }
64 |
65 | /**
66 | * @return array
67 | */
68 | public function getCacheTimes() {
69 | return $this->cacheTimes;
70 | }
71 |
72 | /**
73 | * Returns the currently set cache time
74 | * @param $for
75 | * @return int
76 | */
77 | public function getCacheTime($for) {
78 | if (isset($this->cacheTimes[$for])) {
79 | return max($this->globalTime, $this->cacheTimes[$for]);
80 | }
81 | return $this->globalTime;
82 | }
83 |
84 | /**
85 | * @param string $for
86 | * @param int $int
87 | * @return $this
88 | */
89 | public function setCacheTime($for, $int) {
90 | $this->cacheTimes[$for] = $int;
91 | return $this;
92 | }
93 |
94 | /**
95 | * @param $resource
96 | * @return Resource
97 | */
98 | public abstract function getResource($resource);
99 |
100 | /**
101 | * @param Resource $resource
102 | * @return void
103 | */
104 | public abstract function setResource($resource);
105 |
106 | /**
107 | * @param $uuid
108 | * @return Player|null
109 | */
110 | public abstract function getPlayer($uuid);
111 |
112 | /**
113 | * @param Player $player
114 | * @return void
115 | */
116 | public abstract function setPlayer(Player $player);
117 |
118 | /**
119 | * @param $username
120 | * @return string|null
121 | */
122 | public abstract function getUUID($username);
123 |
124 | /**
125 | * @param $username
126 | * @param $uuid
127 | * @return void
128 | */
129 | public abstract function setPlayerUUID($username, $uuid);
130 |
131 | /**
132 | * @param $id
133 | * @return Guild|null
134 | */
135 | public abstract function getGuild($id);
136 |
137 | /**
138 | * @param Guild $guild
139 | * @return void
140 | */
141 | public abstract function setGuild(Guild $guild);
142 |
143 | /**
144 | * @param $uuid
145 | * @return Guild|string|null
146 | */
147 | public abstract function getGuildIDForUUID($uuid);
148 |
149 | /**
150 | * @param $uuid
151 | * @param $id
152 | * @return void
153 | */
154 | public abstract function setGuildIDForUUID($uuid, $id);
155 |
156 | /**
157 | * @param $name
158 | * @return Guild|string|null
159 | */
160 | public abstract function getGuildIDForName($name);
161 |
162 | /**
163 | * @param $name
164 | * @param $id
165 | * @return void
166 | */
167 | public abstract function setGuildIDForName($name, $id);
168 |
169 | /**
170 | * @param $uuid
171 | * @return Status|null
172 | */
173 | public abstract function getStatus($uuid);
174 |
175 | /**
176 | * @param Status $status
177 | * @return void
178 | */
179 | public abstract function setStatus(Status $status);
180 |
181 | /**
182 | * @param $uuid
183 | * @return RecentGames|null
184 | */
185 | public abstract function getRecentGames($uuid);
186 |
187 | /**
188 | * @param RecentGames $recentGames
189 | * @return void
190 | */
191 | public abstract function setRecentGames(RecentGames $recentGames);
192 |
193 | /**
194 | * @param $key
195 | * @return KeyInfo|null
196 | */
197 | public abstract function getKeyInfo($key);
198 |
199 | /**
200 | * @param KeyInfo $keyInfo
201 | * @return void
202 | */
203 | public abstract function setKeyInfo(KeyInfo $keyInfo);
204 |
205 | /**
206 | * @return Leaderboards|null
207 | */
208 | public abstract function getLeaderboards();
209 |
210 | /**
211 | * @param Leaderboards $leaderboards
212 | * @return void
213 | */
214 | public abstract function setLeaderboards(Leaderboards $leaderboards);
215 |
216 | /**
217 | * @return Boosters|null
218 | */
219 | public abstract function getBoosters();
220 |
221 | /**
222 | * @param Boosters $boosters
223 | * @return void
224 | */
225 | public abstract function setBoosters(Boosters $boosters);
226 |
227 | /**
228 | * @return PunishmentStats|null
229 | */
230 | public abstract function getPunishmentStats();
231 |
232 | /**
233 | * @param PunishmentStats $punishmentStats
234 | * @return void
235 | */
236 | public abstract function setPunishmentStats(PunishmentStats $punishmentStats);
237 |
238 | /**
239 | * @return Counts|null
240 | */
241 | public abstract function getCounts();
242 |
243 | /**
244 | * @param Counts $counts
245 | * @return void
246 | */
247 | public abstract function setCounts(Counts $counts);
248 |
249 | /**
250 | * @param $profile_id
251 | * @return SkyBlockProfile|null
252 | */
253 | public abstract function getSkyBlockProfile($profile_id);
254 |
255 | /**
256 | * @param SkyBlockProfile $profile
257 | * @return void
258 | */
259 | public abstract function setSkyBlockProfile(SkyBlockProfile $profile);
260 |
261 | /**
262 | * Convert given input to an array in order to cache it
263 | *
264 | * @param $obj
265 | * @return array
266 | * @throws InvalidArgumentException
267 | */
268 | protected function objToArray($obj) {
269 | if ($obj instanceof HypixelObject) {
270 | return $obj->getRaw();
271 | } else if (is_array($obj)) {
272 | return $obj;
273 | }
274 | throw new InvalidArgumentException();
275 | }
276 |
277 | /**
278 | * @param Closure $provider
279 | * @param $data
280 | * @return mixed|null
281 | */
282 | protected function wrapProvider(Closure $provider, $data) {
283 | if ($data == null) return null;
284 | return $provider($this->getHypixelPHP(), $data);
285 | }
286 | }
--------------------------------------------------------------------------------
/src/cache/CacheTimes.php:
--------------------------------------------------------------------------------
1 | HypixelPHP = $HypixelPHP;
20 | }
21 |
22 | /**
23 | * @return HypixelPHP
24 | */
25 | public function getHypixelPHP() {
26 | return $this->HypixelPHP;
27 | }
28 |
29 | /**
30 | * @param $HypixelPHP
31 | * @return $this
32 | */
33 | public function setHypixelPHP($HypixelPHP) {
34 | $this->HypixelPHP = $HypixelPHP;
35 | return $this;
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/src/classes/APIObject.php:
--------------------------------------------------------------------------------
1 | data = $data;
26 | }
27 |
28 | /**
29 | * @return array
30 | */
31 | public function getData() {
32 | return $this->getRaw();
33 | }
34 |
35 | /**
36 | * @return array
37 | */
38 | public function getRaw() {
39 | return $this->data;
40 | }
41 | }
--------------------------------------------------------------------------------
/src/classes/DataHolding.php:
--------------------------------------------------------------------------------
1 | get($key, $default);
20 | if (is_array($ret)) return $ret;
21 | return $default;
22 | }
23 |
24 | /**
25 | * @param $key
26 | * @param null $default
27 | * @param string $delimiter
28 | * @return mixed
29 | */
30 | public function get($key, $default = null, $delimiter = '.') {
31 | if (!is_array($this->getData())) {
32 | return $default;
33 | }
34 | return Utilities::getRecursiveValue($this->getData(), $key, $default, $delimiter);
35 | }
36 |
37 | /**
38 | * @return array
39 | */
40 | abstract function getData();
41 |
42 | /**
43 | * @param $key
44 | * @param int $default
45 | * @return int
46 | */
47 | public function getInt($key, $default = 0) {
48 | $ret = $this->get($key, $default);
49 | if (is_int($ret)) return $ret;
50 | return $default;
51 | }
52 |
53 | /**
54 | * @param $key
55 | * @param double $default
56 | * @return double
57 | */
58 | public function getDouble($key, $default = 0.0) {
59 | $ret = $this->get($key, $default);
60 | if (is_double($ret)) return $ret;
61 | return $default;
62 | }
63 |
64 | /**
65 | * @param $key
66 | * @param $default
67 | * @return number
68 | */
69 | public function getNumber($key, $default = 0) {
70 | $ret = $this->get($key, $default);
71 | if (is_numeric($ret)) return $ret + 0;
72 | return $default;
73 | }
74 | }
--------------------------------------------------------------------------------
/src/classes/HypixelObject.php:
--------------------------------------------------------------------------------
1 | data['record']) || !is_array($this->data['record'])) {
25 | $this->data['record'] = [];
26 | }
27 | }
28 |
29 | /**
30 | * @return array
31 | */
32 | public function getData() {
33 | return $this->data['record'];
34 | }
35 |
36 | /**
37 | * Called when an object is fetched freshly
38 | * @param HypixelObject|null $cached The previous document, null or expired cached
39 | */
40 | public function handleNew($cached = null) {
41 | $this->data['timestamp'] = time();
42 | }
43 |
44 | /**
45 | * @param int $leeway
46 | * @return bool
47 | */
48 | public function isCached($leeway = 1) {
49 | return abs(time() - $this->getCachedTime()) > $leeway;
50 | }
51 |
52 | /**
53 | * @return int
54 | */
55 | public function getCachedTime() {
56 | return $this->data['timestamp'];
57 | }
58 |
59 | /**
60 | * @param int $extra extra time to be added to the check
61 | * @return bool
62 | */
63 | public function isCacheExpired($extra = 0) {
64 | return CacheUtil::isExpired($this->getCachedTime() * 1000, $this->getHypixelPHP()->getCacheHandler()->getCacheTime($this->getCacheTimeKey()) * 1000, $extra);
65 | }
66 |
67 | /**
68 | * @return string
69 | */
70 | public abstract function getCacheTimeKey();
71 |
72 | public abstract function save();
73 |
74 | /**
75 | * @return string
76 | */
77 | public function getID() {
78 | return $this->get('_id');
79 | }
80 |
81 | /**
82 | * @param Response $response
83 | * @return $this
84 | */
85 | public function attachResponse(Response $response) {
86 | $this->response = $response;
87 | return $this;
88 | }
89 |
90 | /**
91 | * @return Response|null
92 | */
93 | public function getResponse() {
94 | return $this->response;
95 | }
96 |
97 | }
--------------------------------------------------------------------------------
/src/classes/Module.php:
--------------------------------------------------------------------------------
1 | enum = $enum;
22 | $this->db = $db;
23 | $this->name = $name;
24 | $this->short = $short;
25 | $this->id = $id;
26 | }
27 |
28 | /**
29 | * @return string
30 | */
31 | public function getEnum() {
32 | return $this->enum;
33 | }
34 |
35 | /**
36 | * @return string
37 | */
38 | public function getDb() {
39 | return $this->db;
40 | }
41 |
42 | /**
43 | * @return string
44 | */
45 | public function getName() {
46 | return $this->name;
47 | }
48 |
49 | /**
50 | * @return string
51 | */
52 | public function getShort() {
53 | return $this->short;
54 | }
55 |
56 | /**
57 | * @return int
58 | */
59 | public function getId() {
60 | return $this->id;
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/src/classes/serverType/ServerTypes.php:
--------------------------------------------------------------------------------
1 | getDb()) == strtolower($db);
52 | });
53 | }
54 |
55 | /**
56 | * @param Closure $test
57 | * @return ServerType|null
58 | */
59 | public static function fromX(Closure $test) {
60 | foreach (self::values() as $id) {
61 | $serverType = self::fromID($id);
62 | if ($serverType != null) {
63 | if ($test($serverType)) {
64 | return $serverType;
65 | }
66 | }
67 | }
68 | return null;
69 | }
70 |
71 | /**
72 | * @return int[]
73 | */
74 | public static function values() {
75 | return [
76 | self::QUAKE,
77 | self::WALLS,
78 | self::PAINTBALL,
79 | self::SURVIVAL_GAMES,
80 | self::TNTGAMES,
81 | self::VAMPIREZ,
82 | self::WALLS3,
83 | self::ARCADE,
84 | self::ARENA,
85 | self::UHC,
86 | self::MCGO,
87 | self::BATTLEGROUND,
88 | self::SUPER_SMASH,
89 | self::GINGERBREAD,
90 | self::HOUSING,
91 | self::SKYWARS,
92 | self::TRUE_COMBAT,
93 | self::SPEED_UHC,
94 | self::SKYCLASH,
95 | self::LEGACY,
96 | self::PROTOTYPE,
97 | self::BEDWARS,
98 | self::MURDER_MYSTERY,
99 | self::BUILD_BATTLE,
100 | self::DUELS,
101 | self::SKYBLOCK,
102 | self::PIT,
103 | self::REPLAY,
104 | self::SMP,
105 | self::WOOL_GAMES,
106 |
107 | self::MAIN
108 | ];
109 | }
110 |
111 | /**
112 | * @param $id
113 | *
114 | * @return GameType|ServerType|null
115 | */
116 | public static function fromID($id) {
117 | switch ($id) {
118 | case self::QUAKE:
119 | return new GameType('QUAKE', 'Quake', 'Quake', 'Quake', self::QUAKE, false);
120 | case self::WALLS:
121 | return new GameType('WALLS', 'Walls', 'Walls', 'Walls', self::WALLS, false);
122 | case self::PAINTBALL:
123 | return new GameType('PAINTBALL', 'Paintball', 'Paintball', 'Paintball', self::PAINTBALL, false);
124 | case self::SURVIVAL_GAMES:
125 | return new GameType('SURVIVAL_GAMES', 'HungerGames', 'Blitz Survival Games', 'BSG', self::SURVIVAL_GAMES);
126 | case self::TNTGAMES:
127 | return new GameType('TNTGAMES', 'TNTGames', 'TNT Games', 'TNT Games', self::TNTGAMES);
128 | case self::VAMPIREZ:
129 | return new GameType('VAMPIREZ', 'VampireZ', 'VampireZ', 'VampireZ', self::VAMPIREZ, false);
130 | case self::WALLS3:
131 | return new GameType('WALLS3', 'Walls3', 'Mega Walls', 'MW', self::WALLS3);
132 | case self::ARCADE:
133 | return new GameType('ARCADE', 'Arcade', 'Arcade', 'Arcade', self::ARCADE);
134 | case self::ARENA:
135 | return new GameType('ARENA', 'Arena', 'Arena Brawl', 'Arena', self::ARENA, false);
136 | case self::UHC:
137 | return new GameType('UHC', 'UHC', 'UHC Champions', 'UHC', self::UHC);
138 | case self::MCGO:
139 | return new GameType('MCGO', 'MCGO', 'Cops and Crims', 'CaC', self::MCGO);
140 | case self::BATTLEGROUND:
141 | return new GameType('BATTLEGROUND', 'Battleground', 'Warlords', 'Warlords', self::BATTLEGROUND);
142 | case self::SUPER_SMASH:
143 | return new GameType('SUPER_SMASH', 'SuperSmash', 'Smash Heroes', 'Smash Heroes', self::SUPER_SMASH);
144 | case self::GINGERBREAD:
145 | return new GameType('GINGERBREAD', 'GingerBread', 'Turbo Kart Racers', 'TKR', self::GINGERBREAD, false);
146 | case self::HOUSING:
147 | return new GameType('HOUSING', 'Housing', 'Housing', 'Housing', self::HOUSING, false);
148 | case self::SKYWARS:
149 | return new GameType('SKYWARS', 'SkyWars', 'SkyWars', 'SkyWars', self::SKYWARS);
150 | case self::TRUE_COMBAT:
151 | return new GameType('TRUE_COMBAT', 'TrueCombat', 'Crazy Walls', 'Crazy Walls', self::TRUE_COMBAT);
152 | case self::SPEED_UHC:
153 | return new GameType('SPEED_UHC', 'SpeedUHC', 'Speed UHC', 'Speed UHC', self::SPEED_UHC);
154 | case self::SKYCLASH:
155 | return new GameType('SKYCLASH', 'SkyClash', 'SkyClash', 'SkyClash', self::SKYCLASH);
156 | case self::LEGACY:
157 | return new GameType('LEGACY', 'Legacy', 'Classic Games', 'Classic', self::LEGACY);
158 | case self::PROTOTYPE:
159 | return new GameType('PROTOTYPE', 'Prototype', 'Prototype', 'Prototype', self::PROTOTYPE, false);
160 | case self::BEDWARS:
161 | return new GameType('BEDWARS', 'Bedwars', 'Bed Wars', 'Bed Wars', self::BEDWARS, false);
162 | case self::MURDER_MYSTERY:
163 | return new GameType('MURDER_MYSTERY', 'MurderMystery', 'Murder Mystery', 'Murder Mystery', self::MURDER_MYSTERY, false);
164 | case self::BUILD_BATTLE:
165 | return new GameType('BUILD_BATTLE', 'BuildBattle', 'Build Battle', 'Build Battle', self::BUILD_BATTLE, false);
166 | case self::DUELS:
167 | return new GameType('DUELS', 'Duels', 'Duels', 'Duels', self::DUELS, false);
168 | case self::SKYBLOCK:
169 | return new GameType('SKYBLOCK', 'SkyBlock', 'SkyBlock', 'SkyBlock', self::SKYBLOCK, false);
170 | case self::PIT:
171 | return new GameType('PIT', 'Pit', 'Pit', 'Pit', self::PIT, false);
172 | case self::REPLAY:
173 | return new GameType('REPLAY', 'Replay', 'Replay', 'Replay', self::REPLAY, false);
174 | case self::SMP:
175 | return new GameType('SMP', 'SMP', 'SMP', 'SMP', self::SMP, false);
176 | case self::WOOL_GAMES:
177 | return new GameType('WOOL_GAMES', 'WoolGames', 'Wool Games', 'Wool Games', self::WOOL_GAMES, false);
178 |
179 | # Lobby Types
180 | case self::MAIN:
181 | return new LobbyType('MAIN', 'MainLobby', 'Main Lobby', 'Main Lobby', self::MAIN);
182 | }
183 | return null;
184 | }
185 |
186 | /**
187 | * @param $short
188 | * @return ServerType|null
189 | */
190 | public static function fromShort($short) {
191 | return self::fromX(function (ServerType $serverType) use ($short) {
192 | return strtolower($serverType->getShort()) == strtolower($short);
193 | });
194 | }
195 |
196 | /**
197 | * @param $name
198 | * @return ServerType|null
199 | */
200 | public static function fromName($name) {
201 | return self::fromX(function (ServerType $serverType) use ($name) {
202 | return strtolower($serverType->getName()) == strtolower($name);
203 | });
204 | }
205 |
206 | /**
207 | * @param $name
208 | * @return ServerType|null
209 | */
210 | public static function fromEnum($name) {
211 | return self::fromX(function (ServerType $serverType) use ($name) {
212 | return strtolower($serverType->getEnum()) == strtolower($name);
213 | });
214 | }
215 | }
--------------------------------------------------------------------------------
/src/color/ColorParser.php:
--------------------------------------------------------------------------------
1 | '#000000',
13 | ColorUtils::DARK_BLUE => '#0000AA',
14 | ColorUtils::DARK_GREEN => '#008000',
15 | ColorUtils::DARK_AQUA => '#00AAAA',
16 | ColorUtils::DARK_RED => '#AA0000',
17 | ColorUtils::DARK_PURPLE => '#AA00AA',
18 | ColorUtils::GOLD => '#FFAA00',
19 | ColorUtils::GRAY => '#AAAAAA',
20 | ColorUtils::DARK_GRAY => '#555555',
21 | ColorUtils::BLUE => '#5555FF',
22 | ColorUtils::GREEN => '#3CE63C',
23 | ColorUtils::AQUA => '#3CE6E6',
24 | ColorUtils::RED => '#FF5555',
25 | ColorUtils::LIGHT_PURPLE => '#FF55FF',
26 | ColorUtils::YELLOW => '#FFFF55',
27 | ColorUtils::WHITE => '#FFFFFF'
28 | ];
29 | const DEFAULT_FORMATTING_CSS = [
30 | ColorUtils::BOLD => 'font-weight: bold;',
31 | ColorUtils::STRIKETHROUGH => 'text-decoration: line-through;',
32 | ColorUtils::UNDERLINE => 'text-decoration: underline;',
33 | ColorUtils::ITALIC => 'font-style: italic;'
34 | ];
35 |
36 | /**
37 | * Parses MC encoded colors to HTML
38 | *
39 | * @param $string
40 | * @return string
41 | */
42 | public function parse($string) {
43 | $explodedString = $this->explodeColoredString($string);
44 | if ($explodedString == null) return null;
45 |
46 | return $this->handleExploded($explodedString);
47 | }
48 |
49 | /**
50 | * Explode a string into an array of segments for the ColorParser
51 | *
52 | * @param $string
53 | * @return array|null
54 | */
55 | protected function explodeColoredString($string) {
56 | if ($string == null || strlen($string) == 0) return null;
57 |
58 | $actualExplode = [];
59 |
60 | $explosion = explode(ColorUtils::COLOR_CHAR, $string);
61 | foreach ($explosion as $part) {
62 | if (strlen($explosion[0]) != 0 && sizeof($actualExplode) == 0) {
63 | array_push($actualExplode, [[
64 | 'code' => null,
65 | 'part' => $part
66 | ]]);
67 | continue;
68 | }
69 |
70 | if (strlen($part) == 0) {
71 | continue;
72 | }
73 |
74 | $code = ColorUtils::COLOR_CHAR . strtolower(substr($part, 0, 1));
75 |
76 | // new part
77 | if (array_search($code, ColorUtils::getAllColors())) {
78 | array_push($actualExplode, []);
79 | } else if ($code == ColorUtils::RESET) {
80 | array_push($actualExplode, []);
81 | } else if (sizeof($actualExplode) == 0) {
82 | array_push($actualExplode, []);
83 | }
84 |
85 | // append to last grouping
86 | array_push($actualExplode[sizeof($actualExplode) - 1], [
87 | 'code' => $code,
88 | 'part' => strlen($part) > 1 ? substr($part, 1) : null
89 | ]);
90 | }
91 |
92 | return $actualExplode;
93 | }
94 |
95 | /**
96 | * @param array $segments
97 | * @return string
98 | */
99 | protected function handleExploded($segments) {
100 | $out = '';
101 | foreach ($segments as $segment) {
102 | $out .= $this->handleSegment($segment);
103 | }
104 | return $out;
105 | }
106 |
107 | /**
108 | * @param array $parts
109 | * @return string
110 | */
111 | protected function handleSegment($parts) {
112 | $out = '';
113 | foreach (array_reverse($parts, true) as $part) {
114 | $out = $this->handlePart($part['code'], $part['part'] . $out);
115 | }
116 | return $out;
117 | }
118 |
119 | /**
120 | * @param string $code
121 | * @param string $part
122 | * @return string
123 | */
124 | protected function handlePart($code, $part) {
125 | if (in_array($code, ColorUtils::getAllFormattingCodes())) {
126 | return $this->_handleFormatting($code, $part);
127 | } else if (in_array($code, ColorUtils::getAllColors())) {
128 | return $this->_handleColor($code, $part);
129 | } else {
130 | return $part;
131 | }
132 | }
133 |
134 | /**
135 | * @param string $code
136 | * @param string $part
137 | * @return string
138 | */
139 | protected function _handleFormatting($code, $part) {
140 | $css = self::DEFAULT_FORMATTING_CSS[$code];
141 | return "" . $part . "";
142 | }
143 |
144 | /**
145 | * @param string $color
146 | * @param string $part
147 | * @return string
148 | */
149 | protected function _handleColor($color, $part) {
150 | $color = self::DEFAULT_COLOR_HEX_MAP[$color];
151 | return "" . $part . "";
152 | }
153 |
154 | }
--------------------------------------------------------------------------------
/src/color/ColorUtils.php:
--------------------------------------------------------------------------------
1 | self::BLACK,
41 | "DARK_BLUE" => self::DARK_BLUE,
42 | "DARK_GREEN" => self::DARK_GREEN,
43 | "DARK_AQUA" => self::DARK_AQUA,
44 | "DARK_RED" => self::DARK_RED,
45 | "DARK_PURPLE" => self::DARK_PURPLE,
46 | "GOLD" => self::GOLD,
47 | "GRAY" => self::GRAY,
48 | "DARK_GRAY" => self::DARK_GRAY,
49 | "BLUE" => self::BLUE,
50 | "GREEN" => self::GREEN,
51 | "AQUA" => self::AQUA,
52 | "RED" => self::RED,
53 | "LIGHT_PURPLE" => self::LIGHT_PURPLE,
54 | "YELLOW" => self::YELLOW,
55 | "WHITE" => self::WHITE,
56 | "MAGIC" => self::MAGIC,
57 | "BOLD" => self::BOLD,
58 | "STRIKETHROUGH" => self::STRIKETHROUGH,
59 | "UNDERLINE" => self::UNDERLINE,
60 | "ITALIC" => self::ITALIC,
61 | "RESET" => self::RESET,
62 | ];
63 | const STRIP_COLOR_REGEX = '/§[0-9a-flmnokr]/i';
64 | protected static $COLOR_PARSER;
65 |
66 | //
67 |
68 | /**
69 | * Return an array of all color codes
70 | *
71 | * @return array
72 | */
73 | public static function getAllColors() {
74 | return [
75 | self::BLACK,
76 | self::DARK_BLUE,
77 | self::DARK_GREEN,
78 | self::DARK_AQUA,
79 | self::DARK_RED,
80 | self::DARK_PURPLE,
81 | self::GOLD,
82 | self::GRAY,
83 | self::DARK_GRAY,
84 | self::BLUE,
85 | self::GREEN,
86 | self::AQUA,
87 | self::RED,
88 | self::LIGHT_PURPLE,
89 | self::YELLOW,
90 | self::WHITE
91 | ];
92 | }
93 |
94 | /**
95 | * Return an array of all formatting codes
96 | *
97 | * @return array
98 | */
99 | public static function getAllFormattingCodes() {
100 | return [
101 | self::BOLD,
102 | self::STRIKETHROUGH,
103 | self::UNDERLINE,
104 | self::ITALIC
105 | ];
106 | }
107 | //
108 |
109 |
110 | //
111 | /**
112 | * Removes all MC encoded colors from a string
113 | * @param $string
114 | * @return string
115 | */
116 | public static function stripColors($string) {
117 | if ($string == null) {
118 | return null;
119 | }
120 |
121 | return preg_replace(self::STRIP_COLOR_REGEX, '', $string);
122 | }
123 |
124 | /**
125 | * @return ColorParser
126 | */
127 | public static function getColorParser() {
128 | if (self::$COLOR_PARSER == null) {
129 | self::$COLOR_PARSER = new ColorParser();
130 | }
131 | return self::$COLOR_PARSER;
132 | }
133 |
134 | /**
135 | * @param ColorParser $colorParser
136 | */
137 | public static function setColorParser(ColorParser $colorParser) {
138 | self::$COLOR_PARSER = $colorParser;
139 | }
140 | //
141 |
142 | }
--------------------------------------------------------------------------------
/src/exceptions/BadResponseCodeException.php:
--------------------------------------------------------------------------------
1 | expectedCode = $expectedCode;
22 | $this->actualCode = $actualCode;
23 | }
24 |
25 | /**
26 | * @return int
27 | */
28 | public function getExpected() {
29 | return $this->expectedCode;
30 | }
31 |
32 | /**
33 | * @return int
34 | */
35 | public function getActualCode() {
36 | return $this->actualCode;
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/src/exceptions/CurlException.php:
--------------------------------------------------------------------------------
1 | error = $error;
21 | }
22 |
23 | /**
24 | * @return string
25 | */
26 | public function getError() {
27 | return $this->error;
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/src/exceptions/ExceptionCodes.php:
--------------------------------------------------------------------------------
1 | fileName = $fileName;
21 | }
22 |
23 | /**
24 | * @return string
25 | */
26 | public function getFileName() {
27 | return $this->fileName;
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/src/exceptions/HypixelPHPException.php:
--------------------------------------------------------------------------------
1 | val = $val;
17 | }
18 |
19 | /**
20 | * @return string
21 | */
22 | public function getVal(): string {
23 | return $this->val;
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/src/exceptions/NoPairsException.php:
--------------------------------------------------------------------------------
1 | setResponseAdapterGetter(function ($HypixelPHP) {
31 | return new ResponseAdapter($HypixelPHP);
32 | });
33 | }
34 |
35 | /**
36 | * @param Closure $getter
37 | * @return $this
38 | */
39 | public function setResponseAdapterGetter(Closure $getter): Fetcher {
40 | $this->responseAdapterGetter = $getter;
41 | $this->responseAdapter = null;
42 | return $this;
43 | }
44 |
45 | /**
46 | * @return ResponseAdapter
47 | */
48 | public function getResponseAdapter(): ResponseAdapter {
49 | if ($this->responseAdapter == null) {
50 | $getter = $this->responseAdapterGetter;
51 | $this->responseAdapter = $getter($this->getHypixelPHP());
52 | }
53 | return $this->responseAdapter;
54 | }
55 |
56 | /**
57 | * @param ResponseAdapter $responseAdapter
58 | * @return $this
59 | */
60 | public function setResponseAdapter(ResponseAdapter $responseAdapter): Fetcher {
61 | $this->responseAdapter = $responseAdapter;
62 | $this->responseAdapterGetter = null;
63 | return $this;
64 | }
65 |
66 | /**
67 | * @return int
68 | */
69 | public function getTimeOut(): int {
70 | return $this->timeOut;
71 | }
72 |
73 | /**
74 | * @param int $timeOut
75 | * @return $this
76 | */
77 | public function setTimeOut(int $timeOut): Fetcher {
78 | $this->timeOut = $timeOut;
79 | return $this;
80 | }
81 |
82 | /**
83 | * @param string $fetch
84 | * @param array $keyValues
85 | * @return string
86 | */
87 | public function createUrl(string $fetch, $keyValues = []): string {
88 | $requestURL = Fetcher::BASE_URL . $fetch;
89 | if (sizeof($keyValues) > 0) {
90 | $requestURL .= '?';
91 | foreach ($keyValues as $key => $value) {
92 | $value = urlencode(trim($value));
93 | $requestURL .= '&' . $key . '=' . $value;
94 | }
95 | }
96 | return $requestURL;
97 | }
98 |
99 | /**
100 | * @param string $fetch
101 | * @param string $url
102 | * @param array $options
103 | * @return Response
104 | * @throws HypixelPHPException
105 | */
106 | public function fetch(string $fetch, string $url, $options = []): Response {
107 | if (!is_array($options)) {
108 | throw new HypixelPHPException("options is not an array");
109 | }
110 |
111 | $this->getHypixelPHP()->getLogger()->log(LOG_DEBUG, 'Starting Fetch: ' . $url);
112 |
113 | $response = $this->getURLContents($url, $options);
114 | if (!$response->wasSuccessful()) {
115 | $this->getHypixelPHP()->getLogger()->log(LOG_DEBUG, 'Fetch Failed! ' . var_export($response, true));
116 |
117 | // If one fails, stop trying for that status
118 | // ideally also have a cached check before
119 | $this->getHypixelPHP()->getCacheHandler()->setGlobalTime(CacheHandler::MAX_CACHE_TIME);
120 | } else {
121 | $this->getHypixelPHP()->getLogger()->log(LOG_DEBUG, 'Fetch successful!');
122 | }
123 |
124 | return $this->getResponseAdapter()->adaptResponse($fetch, $response);
125 | }
126 |
127 | /**
128 | * @param string $url
129 | * @param array $options
130 | * @return Response
131 | */
132 | abstract function getURLContents(string $url, $options = []): Response;
133 | }
--------------------------------------------------------------------------------
/src/fetch/Response.php:
--------------------------------------------------------------------------------
1 | success;
23 | }
24 |
25 | /**
26 | * @param boolean $success
27 | * @return $this
28 | */
29 | public function setSuccessful($success) {
30 | $this->success = $success;
31 | return $this;
32 | }
33 |
34 | /**
35 | * @return array
36 | */
37 | public function getData() {
38 | return $this->data;
39 | }
40 |
41 | /**
42 | * @param $data
43 | * @return $this
44 | */
45 | public function setData($data) {
46 | $this->data = $data;
47 | return $this;
48 | }
49 |
50 | /**
51 | * @return mixed
52 | */
53 | public function getHeaders() {
54 | return $this->responseHeaders;
55 | }
56 |
57 | /**
58 | * @param mixed $responseHeaders
59 | * @return $this
60 | */
61 | public function setHeaders($responseHeaders) {
62 | $this->responseHeaders = $responseHeaders;
63 | return $this;
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/src/fetch/adapter/ResponseAdapter.php:
--------------------------------------------------------------------------------
1 | wrapRecord($response);
26 | }
27 |
28 | switch ($fetch) {
29 | case FetchTypes::PLAYER:
30 | return $this->remapField('player', $response);
31 | case FetchTypes::GUILD:
32 | return $this->remapField('guild', $response);
33 | case FetchTypes::BOOSTERS:
34 | return $this->remapField('boosters', $response);
35 | case FetchTypes::LEADERBOARDS:
36 | return $this->remapField('leaderboards', $response);
37 | case FetchTypes::SKYBLOCK_PROFILE:
38 | return $this->remapField('profile', $response);
39 |
40 | case FetchTypes::STATUS:
41 | case FetchTypes::PUNISHMENT_STATS:
42 | case FetchTypes::COUNTS:
43 | case FetchTypes::RECENT_GAMES:
44 | return $this->wrapRecord($response);
45 |
46 | case FetchTypes::KEY:
47 | case FetchTypes::FIND_GUILD:
48 | return $response;
49 |
50 | default:
51 | throw new HypixelPHPException("Invalid Adapter Key: " . $fetch, ExceptionCodes::INVALID_ADAPTER_KEY);
52 | }
53 | }
54 |
55 | /**
56 | * @param Response $response
57 | * @return Response
58 | */
59 | protected function wrapRecord(Response $response): Response {
60 | return $response->setData(['record' => $response->getData()]);
61 | }
62 |
63 | /**
64 | * @param $key
65 | * @param Response $response
66 | * @return Response
67 | */
68 | protected function remapField($key, Response $response): Response {
69 | if (!array_key_exists($key, $response->getData())) return $response;
70 | return $response->setData(['record' => $response->getData()[$key]]);
71 | }
72 |
73 | }
--------------------------------------------------------------------------------
/src/fetch/impl/DefaultCurlFetcher.php:
--------------------------------------------------------------------------------
1 | timeOut);
30 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->timeOut);
31 | curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
32 | if (array_key_exists('headers', $options)) {
33 | curl_setopt($ch, CURLOPT_HTTPHEADER, $options['headers']);
34 | }
35 | $responseHeaders = [];
36 | curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$responseHeaders) {
37 | $len = strlen($header);
38 | $header = explode(':', $header, 2);
39 | if (count($header) < 2) // ignore invalid headers
40 | return $len;
41 |
42 | $responseHeaders[strtolower(trim($header[0]))][] = trim($header[1]);
43 |
44 | return $len;
45 | });
46 |
47 | $curlOut = curl_exec($ch);
48 |
49 | $error = curl_error($ch);
50 | if ($error != null && $error != '') {
51 | throw new CurlException($error);
52 | }
53 | if ($curlOut === false) {
54 | return $response;
55 | }
56 |
57 | $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
58 | if ($responseCode != '200') {
59 | throw new BadResponseCodeException(200, $responseCode);
60 | }
61 |
62 | $data = json_decode($curlOut, true);
63 | if (isset($data['success'])) {
64 | $response->setSuccessful($data['success']);
65 | unset($data['success']);
66 | } else {
67 | $response->setSuccessful(true);
68 | }
69 | $response->setData($data);
70 | $response->setHeaders($responseHeaders);
71 | } finally {
72 | curl_close($ch);
73 | }
74 | return $response;
75 | }
76 |
77 | }
--------------------------------------------------------------------------------
/src/fetch/impl/DefaultFGCFetcher.php:
--------------------------------------------------------------------------------
1 | [
29 | 'timeout' => $this->timeOut / 1000
30 | ]
31 | ];
32 | if (array_key_exists('headers', $options)) {
33 | $stream_options['http']['header'] = implode("\r\n", $options['headers']);
34 | }
35 |
36 | $ctx = stream_context_create($stream_options);
37 |
38 | $out = file_get_contents($url, 0, $ctx);
39 | if ($out === false) {
40 | throw new FileGetContentsException($url);
41 | }
42 |
43 | $data = json_decode($out, true);
44 | if (isset($data['success'])) {
45 | $response->setSuccessful($data['success']);
46 | unset($data['success']);
47 | } else {
48 | $response->setSuccessful(true);
49 | }
50 | $response->setData($data);
51 | return $response;
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/src/log/Formatter.php:
--------------------------------------------------------------------------------
1 | isEnabled()) return;
22 |
23 | if ($this->getFormatter() != null) {
24 | $line = $this->getFormatter()->formatLine($level, $line);
25 | }
26 |
27 | $this->actuallyLog($level, $line);
28 | }
29 |
30 | /**
31 | * @return boolean
32 | */
33 | public function isEnabled() {
34 | return $this->enabled;
35 | }
36 |
37 | /**
38 | * @param mixed $enabled
39 | * @return $this
40 | */
41 | public function setEnabled($enabled) {
42 | $this->enabled = $enabled;
43 | return $this;
44 | }
45 |
46 | /**
47 | * @return Formatter|null
48 | */
49 | public function getFormatter() {
50 | return $this->formatter;
51 | }
52 |
53 | /**
54 | * @param Formatter $formatter
55 | * @return $this
56 | */
57 | public function setFormatter($formatter) {
58 | $this->formatter = $formatter;
59 | return $this;
60 | }
61 |
62 | /**
63 | * @param int $level
64 | * @param string $line
65 | */
66 | protected abstract function actuallyLog($level, $line);
67 |
68 | }
--------------------------------------------------------------------------------
/src/log/impl/BasicLogger.php:
--------------------------------------------------------------------------------
1 | setFormatter(new class() extends Formatter {
29 | public function formatLine($level, $line) {
30 | return '[' . date("d-m-Y H:i:s") . '] [' . $level . '] ' . $line;
31 | }
32 | });
33 | }
34 |
35 | /**
36 | * @return string
37 | */
38 | public function getLogFolder() {
39 | return $this->log_folder;
40 | }
41 |
42 | /**
43 | * @param string $log_folder
44 | * @return $this
45 | */
46 | public function setLogFolder($log_folder) {
47 | $this->log_folder = $log_folder;
48 | return $this;
49 | }
50 |
51 | /**
52 | * @return int
53 | */
54 | public function getSize() {
55 | return $this->size;
56 | }
57 |
58 | /**
59 | * @param int $size
60 | * @return $this
61 | */
62 | public function setSize($size) {
63 | $this->size = $size;
64 | return $this;
65 | }
66 |
67 | /**
68 | * Log $string to log files
69 | * Directory setup:
70 | * - LOG_FOLDER/DATE/0.log
71 | * - LOG_FOLDER/DATE/1.log
72 | * separated every {@link $this->size}
73 | * @param $level
74 | * @param string $line
75 | */
76 | public function actuallyLog($level, $line) {
77 | $dirName = $this->log_folder . DIRECTORY_SEPARATOR . date("Y-m-d");
78 | if (!file_exists($dirName)) {
79 | mkdir($dirName, 0777, true);
80 | }
81 |
82 | $scanDir = array_diff(scandir($dirName), ['.', '..']);
83 | $numberOfLogs = max(sizeof($scanDir) - 1, 0);
84 |
85 | $filename = $dirName . DIRECTORY_SEPARATOR . $numberOfLogs . '.log';
86 | if (file_exists($filename)) {
87 | if (filesize($filename) > $this->size) {
88 | // file is bigger than supplied size
89 | // make a new file
90 | $filename = $dirName . DIRECTORY_SEPARATOR . (++$numberOfLogs) . '.log';
91 | }
92 | }
93 | // save the log, with newline
94 | file_put_contents($filename, $line . "\r\n", FILE_APPEND);
95 | }
96 | }
--------------------------------------------------------------------------------
/src/log/impl/NoLogger.php:
--------------------------------------------------------------------------------
1 | enabled = false;
18 | }
19 |
20 | public function actuallyLog($level, $line) {
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/src/log/impl/SysLogger.php:
--------------------------------------------------------------------------------
1 | skyblock = new SkyBlockResources($this->resourceManager);
24 | }
25 |
26 | /**
27 | * @return Resource
28 | */
29 | public function getTNTWizards() {
30 | return $this->requireResourceFile('game_info/tntgames/Wizards.php');
31 | }
32 |
33 | /**
34 | * @return Resource
35 | */
36 | public function getArena() {
37 | return $this->requireResourceFile('game_info/Arena.php');
38 | }
39 |
40 | /**
41 | * @return Resource
42 | */
43 | public function getBattlegrounds() {
44 | return $this->requireResourceFile('game_info/Battlegrounds.php');
45 | }
46 |
47 | /**
48 | * @return Resource
49 | */
50 | public function getSurvivalGames() {
51 | return $this->requireResourceFile('game_info/SurvivalGames.php');
52 | }
53 |
54 | /**
55 | * @return Resource
56 | */
57 | public function getPaintball() {
58 | return $this->requireResourceFile('game_info/Paintball.php');
59 | }
60 |
61 | /**
62 | * @return Resource
63 | */
64 | public function getSkyClash() {
65 | return $this->requireResourceFile('game_info/SkyClash.php');
66 | }
67 |
68 | /**
69 | * @return Resource
70 | */
71 | public function getSuperSmash() {
72 | return $this->requireResourceFile('game_info/SuperSmash.php');
73 | }
74 |
75 | /**
76 | * @return Resource
77 | */
78 | public function getWallsThree() {
79 | return $this->requireResourceFile('game_info/Walls3.php');
80 | }
81 |
82 | /**
83 | * @return Resource
84 | */
85 | public function getSkyWars() {
86 | return $this->requireResourceFile('game_info/SkyWars.php');
87 | }
88 |
89 | /**
90 | * @return SkyBlockResources
91 | */
92 | public function getSkyBlock() {
93 | return $this->skyblock;
94 | }
95 | }
--------------------------------------------------------------------------------
/src/resources/GeneralResources.php:
--------------------------------------------------------------------------------
1 | gameResources = new GameResources($this);
26 | $this->generalResources = new GeneralResources($this);
27 | $this->guildResources = new GuildResources($this);
28 | }
29 |
30 | /**
31 | * @return GameResources
32 | */
33 | public function getGameResources() {
34 | return $this->gameResources;
35 | }
36 |
37 | /**
38 | * @return GeneralResources
39 | */
40 | public function getGeneralResources() {
41 | return $this->generalResources;
42 | }
43 |
44 | /**
45 | * @return GuildResources
46 | */
47 | public function getGuildResources() {
48 | return $this->guildResources;
49 | }
50 |
51 | }
--------------------------------------------------------------------------------
/src/resources/Resources.php:
--------------------------------------------------------------------------------
1 | resourceManager = $resourceManager;
23 | }
24 |
25 | /**
26 | * @param string $path
27 | * @return Resource
28 | */
29 | protected function requireResourceFile($path) {
30 | /** @noinspection PhpIncludeInspection */
31 | return new Resource($this->resourceManager->getHypixelPHP(), ['record' => require(self::BASE_RESOURCES_DIR . $path)], $path);
32 | }
33 |
34 | /**
35 | * @param $path
36 | * @return Resource
37 | */
38 | protected function requireRemoteResourceFile($path) {
39 | $return = $this->resourceManager->getHypixelPHP()->getResource($path);
40 | if ($return instanceof Resource) return $return;
41 | return null;
42 | }
43 | }
--------------------------------------------------------------------------------
/src/resources/games/SkyBlockResources.php:
--------------------------------------------------------------------------------
1 | requireRemoteResourceFile('skyblock/news');
15 | }
16 |
17 | /**
18 | * @return Resource
19 | */
20 | public function getSkills() {
21 | return $this->requireRemoteResourceFile('skyblock/skills');
22 | }
23 |
24 | /**
25 | * @return Resource
26 | */
27 | public function getCollections() {
28 | return $this->requireRemoteResourceFile('skyblock/collections');
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/src/responses/KeyInfo.php:
--------------------------------------------------------------------------------
1 | getNumber("queriesInPastMin");
19 | }
20 |
21 | /**
22 | * @return int
23 | */
24 | public function getTotalQueries() {
25 | return $this->getNumber("totalQueries");
26 | }
27 |
28 | /**
29 | * @return string
30 | */
31 | public function getKey() {
32 | return $this->get('key');
33 | }
34 |
35 | /**
36 | * @return string
37 | */
38 | public function getCacheTimeKey() {
39 | return CacheTimes::KEY_INFO;
40 | }
41 |
42 | public function save() {
43 | $this->getHypixelPHP()->getCacheHandler()->setKeyInfo($this);
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/src/responses/Leaderboards.php:
--------------------------------------------------------------------------------
1 | getHypixelPHP()->getCacheHandler()->setLeaderboards($this);
23 | }
24 | }
--------------------------------------------------------------------------------
/src/responses/PunishmentStats.php:
--------------------------------------------------------------------------------
1 | getNumber('watchdog_lastMinute');
18 | }
19 |
20 | /**
21 | * @return int
22 | */
23 | public function getTotal() {
24 | return $this->getNumber('watchdog_lastMinute');
25 | }
26 |
27 | /**
28 | * @return int
29 | */
30 | public function getRollingDaily() {
31 | return $this->getNumber('watchdog_rollingDaily');
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | public function getCacheTimeKey() {
38 | return CacheTimes::PUNISHMENT_STATS;
39 | }
40 |
41 | public function save() {
42 | $this->getHypixelPHP()->getCacheHandler()->setPunishmentStats($this);
43 | }
44 | }
--------------------------------------------------------------------------------
/src/responses/RecentGames.php:
--------------------------------------------------------------------------------
1 | get("uuid");
16 | }
17 |
18 | /**
19 | * @return array
20 | */
21 | public function getGames(): array {
22 | return $this->getArray('games');
23 | }
24 |
25 | /**
26 | * @return string
27 | */
28 | public function getCacheTimeKey(): string {
29 | return CacheTimes::RECENT_GAMES;
30 | }
31 |
32 | public function save() {
33 | $this->getHypixelPHP()->getCacheHandler()->setRecentGames($this);
34 | }
35 | }
--------------------------------------------------------------------------------
/src/responses/Resource.php:
--------------------------------------------------------------------------------
1 | resource = $resource;
20 | }
21 |
22 | /**
23 | * @return string
24 | */
25 | public function getResource() {
26 | return $this->resource;
27 | }
28 |
29 | public function save() {
30 | $this->getHypixelPHP()->getCacheHandler()->setResource($this);
31 | }
32 |
33 | /**
34 | * @return string
35 | */
36 | public function getCacheTimeKey() {
37 | return CacheTimes::RESOURCES;
38 | }
39 | }
--------------------------------------------------------------------------------
/src/responses/Status.php:
--------------------------------------------------------------------------------
1 | get("uuid");
18 | }
19 |
20 | /**
21 | * @return bool
22 | */
23 | public function isOnline() {
24 | return $this->get('session.online', false);
25 | }
26 |
27 | /**
28 | * @return ServerType
29 | */
30 | public function getGameType() {
31 | $val = $this->get('session.gameType');
32 | if ($val == null) return null;
33 | return ServerTypes::fromEnum($val);
34 | }
35 |
36 | /**
37 | * @return string
38 | */
39 | public function getMode() {
40 | return $this->get('session.mode');
41 | }
42 |
43 | /**
44 | * @return string
45 | */
46 | public function getCacheTimeKey() {
47 | return CacheTimes::STATUS;
48 | }
49 |
50 | public function save() {
51 | $this->getHypixelPHP()->getCacheHandler()->setStatus($this);
52 | }
53 | }
--------------------------------------------------------------------------------
/src/responses/booster/Booster.php:
--------------------------------------------------------------------------------
1 | getHypixelPHP()->getPlayer([FetchParams::PLAYER_BY_UUID => $this->getOwnerUUID()]);
25 | }
26 |
27 | public function getOwnerUUID() {
28 | return $this->get('purchaserUuid');
29 | }
30 |
31 | /**
32 | * @return ServerType|null
33 | */
34 | public function getGameType() {
35 | return ServerTypes::fromID($this->getGameTypeID());
36 | }
37 |
38 | /**
39 | * @return int
40 | */
41 | public function getGameTypeID() {
42 | return $this->get('gameType');
43 | }
44 |
45 | /**
46 | * @return bool
47 | */
48 | public function isActive() {
49 | // make sure it has ticked once at least
50 | return $this->getLength() != $this->getOriginalLength();
51 | }
52 |
53 | /**
54 | * @return int
55 | * @internal param bool $original
56 | */
57 | public function getLength() {
58 | return $this->getNumber('length');
59 | }
60 |
61 | /**
62 | * @return int
63 | */
64 | public function getOriginalLength() {
65 | // default to 1 hour
66 | return $this->getNumber('originalLength', 3600);
67 | }
68 |
69 | /**
70 | * @return int
71 | */
72 | public function getActivateTime() {
73 | return $this->getNumber('dateActivated');
74 | }
75 |
76 | /**
77 | * @return array
78 | */
79 | public function getStacked() {
80 | return $this->getArray('stacked');
81 | }
82 |
83 | /**
84 | * @return double
85 | */
86 | public function getAmount() {
87 | return $this->getDouble('amount');
88 | }
89 | }
--------------------------------------------------------------------------------
/src/responses/booster/Boosters.php:
--------------------------------------------------------------------------------
1 | [],
23 | 'total' => 0
24 | ];
25 | foreach ($this->getData() as $boosterInfo) {
26 | $booster = new Booster($this->getHypixelPHP(), $boosterInfo);
27 | if ($booster->getGameTypeID() == $gameType) {
28 | if ($return['total'] < $max) {
29 | array_push($return['boosters'], $booster);
30 | }
31 | $return['total']++;
32 | }
33 | }
34 | return $return;
35 | }
36 |
37 | /**
38 | * Get queued boosters by uuid
39 | *
40 | * @param string $uuid
41 | * @return Booster[]
42 | */
43 | public function getBoosters($uuid) {
44 | $uuid = Utilities::ensureNoDashesUUID($uuid);
45 | $dashedUuid = Utilities::ensureDashedUUID($uuid);
46 |
47 | $boosters = [];
48 | foreach ($this->getData() as $boosterInfo) {
49 | if (isset($boosterInfo['purchaserUuid']) && $boosterInfo['purchaserUuid'] == $uuid) {
50 | array_push($boosters, new Booster($this->getHypixelPHP(), $boosterInfo));
51 | }
52 | if (isset($boosterInfo['stacked']) && is_array($boosterInfo['stacked']) && in_array($dashedUuid, $boosterInfo['stacked'])) {
53 | array_push($boosters, new Booster($this->getHypixelPHP(), $boosterInfo));
54 | }
55 | }
56 | return $boosters;
57 | }
58 |
59 | /**
60 | * @return string
61 | */
62 | public function getCacheTimeKey() {
63 | return CacheTimes::BOOSTERS;
64 | }
65 |
66 | public function save() {
67 | $this->getHypixelPHP()->getCacheHandler()->setBoosters($this);
68 | }
69 | }
--------------------------------------------------------------------------------
/src/responses/counts/Counts.php:
--------------------------------------------------------------------------------
1 | games)) {
24 | $this->games[$gameTypeId] = new GameCount($this->getHypixelPHP(), $this->getArray(ServerTypes::fromID($gameTypeId)->getEnum()));
25 | }
26 | return $this->games[$gameTypeId];
27 | }
28 |
29 | /**
30 | * @return int
31 | */
32 | public function getPlayerCount(): int {
33 | return $this->playerCount;
34 | }
35 |
36 | /**
37 | * @return string
38 | */
39 | public function getCacheTimeKey() {
40 | return CacheTimes::COUNTS;
41 | }
42 |
43 | public function save() {
44 | $this->getHypixelPHP()->getCacheHandler()->setCounts($this);
45 | }
46 | }
--------------------------------------------------------------------------------
/src/responses/counts/GameCount.php:
--------------------------------------------------------------------------------
1 | getNumber('players');
21 | }
22 |
23 | /**
24 | * @return array
25 | */
26 | public function getModes() {
27 | return $this->getArray('modes');
28 | }
29 |
30 | /**
31 | * @return string
32 | */
33 | public function getCacheTimeKey() {
34 | return CacheTimes::COUNTS;
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/src/responses/guild/Guild.php:
--------------------------------------------------------------------------------
1 | ranks = new GuildRanks($HypixelPHP, $this->getArray("ranks"));
23 | $this->members = new GuildMemberList($this->getHypixelPHP(), $this);
24 | }
25 |
26 | /**
27 | * @return string
28 | */
29 | public function getName() {
30 | return $this->get('name');
31 | }
32 |
33 | /**
34 | * @return GuildRanks
35 | */
36 | public function getRanks() {
37 | return $this->ranks;
38 | }
39 |
40 | /**
41 | * @return string
42 | */
43 | public function getTag() {
44 | return $this->get('tag');
45 | }
46 |
47 | /**
48 | * @return string
49 | */
50 | public function getTagColor() {
51 | $color = $this->get('tagColor', 'GRAY');
52 | if (isset(ColorUtils::NAME_TO_CODE[$color])) {
53 | return ColorUtils::NAME_TO_CODE[$color];
54 | }
55 | return ColorUtils::GRAY;
56 | }
57 |
58 | /**
59 | * @return int
60 | */
61 | public function getMemberCount() {
62 | return $this->getMemberList()->getMemberCount();
63 | }
64 |
65 | /**
66 | * @return GuildMemberList
67 | */
68 | public function getMemberList() {
69 | return $this->members;
70 | }
71 |
72 | /**
73 | * @return string
74 | */
75 | function getCacheTimeKey() {
76 | return CacheTimes::GUILD;
77 | }
78 |
79 | /**
80 | * @return int
81 | */
82 | public function getLevel() {
83 | return GuildLevelUtil::getLevel($this->getExp());
84 | }
85 |
86 | /**
87 | * @return int
88 | */
89 | public function getExp() {
90 | return $this->getNumber('exp');
91 | }
92 |
93 | /**
94 | * @return array
95 | */
96 | public function getAchievements() {
97 | return $this->getArray("achievements");
98 | }
99 |
100 | /**
101 | * @return bool
102 | */
103 | public function isJoinable() {
104 | return $this->get('joinable', false);
105 | }
106 |
107 | /**
108 | * @return bool
109 | */
110 | public function isPubliclyListed() {
111 | return $this->get('publiclyListed', false);
112 | }
113 |
114 | /**
115 | * @return int
116 | */
117 | public function getLegacyRank() {
118 | return $this->getNumber('legacyRanking', -1);
119 | }
120 |
121 | /**
122 | * @return string
123 | */
124 | public function getDescription() {
125 | return $this->get("description");
126 | }
127 |
128 | /**
129 | * @return array
130 | */
131 | public function getPreferredGames() {
132 | return $this->getArray("preferredGames");
133 | }
134 |
135 | /**
136 | * @return array
137 | */
138 | public function getBanner() {
139 | return $this->getArray("banner");
140 | }
141 |
142 | /**
143 | * @return array
144 | */
145 | public function getExpByGameType() {
146 | return $this->getArray("guildExpByGameType");
147 | }
148 |
149 | public function save() {
150 | $this->getHypixelPHP()->getCacheHandler()->setGuild($this);
151 | }
152 | }
--------------------------------------------------------------------------------
/src/responses/guild/GuildLevelUtil.php:
--------------------------------------------------------------------------------
1 | = sizeof(GuildLevelUtil::EXP_NEEDED) ? GuildLevelUtil::EXP_NEEDED[sizeof(GuildLevelUtil::EXP_NEEDED) - 1] : GuildLevelUtil::EXP_NEEDED[$i];
31 | $exp -= $need;
32 | if ($exp < 0) {
33 | return $level;
34 | } else {
35 | $level++;
36 | }
37 | }
38 |
39 | // should never happen
40 | return -1;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/responses/guild/GuildMember.php:
--------------------------------------------------------------------------------
1 | rank = $guild->getRanks()->getRank($this->get("rank"));
24 | }
25 |
26 | /**
27 | * @return Player
28 | * @throws HypixelPHPException
29 | */
30 | public function getPlayer() {
31 | return $this->getHypixelPHP()->getPlayer([FetchParams::PLAYER_BY_UUID => $this->getUUID()]);
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | public function getUUID() {
38 | return $this->get("uuid");
39 | }
40 |
41 | /**
42 | * @return GuildRank
43 | */
44 | public function getRank() {
45 | return $this->rank;
46 | }
47 |
48 | /**
49 | * @return int
50 | */
51 | public function getJoinTimeStamp() {
52 | return $this->getNumber("joined");
53 | }
54 |
55 | /**
56 | * @return int
57 | */
58 | public function getQuestParticipation() {
59 | return $this->getNumber("questParticipation");
60 | }
61 |
62 | /**
63 | * @return array[string]int
64 | */
65 | public function getExpHistory() {
66 | return $this->getArray("expHistory");
67 | }
68 | }
--------------------------------------------------------------------------------
/src/responses/guild/GuildMemberList.php:
--------------------------------------------------------------------------------
1 | getArray('members'));
23 |
24 | $this->count = sizeof($this->data);
25 |
26 | $ranks = $guild->getRanks();
27 | $defaultRank = $ranks->getDefaultRank();
28 | foreach ($this->data as $player) {
29 | $rank = $player['rank'];
30 | if ($ranks->getRank($rank) == null) $rank = null;
31 | if ($rank == null && $defaultRank != null) $rank = $defaultRank->getName();
32 | $rank = strtolower($rank);
33 | if (!in_array($rank, array_keys($this->list))) $this->list[$rank] = [];
34 | array_push($this->list[$rank], new GuildMember($HypixelPHP, $guild, $player));
35 | }
36 |
37 | uksort($this->list, function ($k1, $k2) use ($ranks) {
38 | /** @var GuildRank $rank1 */
39 | $rank1 = $ranks->getRank($k1);
40 | /** @var GuildRank $rank2 */
41 | $rank2 = $ranks->getRank($k2);
42 | if ($rank1 == null) return -1;
43 | if ($rank2 == null) return 1;
44 |
45 | return $rank2->getPriority() <=> $rank1->getPriority();
46 | });
47 | }
48 |
49 | /**
50 | * @return array[string]GuildMember[]
51 | */
52 | public function getList() {
53 | return $this->list;
54 | }
55 |
56 | /**
57 | * @param $rank
58 | * @return GuildMember[]
59 | */
60 | public function getListByRank($rank) {
61 | return $this->list[strtolower($rank)];
62 | }
63 |
64 |
65 | /**
66 | * @return int
67 | */
68 | public function getMemberCount() {
69 | return sizeof($this->data);
70 | }
71 | }
--------------------------------------------------------------------------------
/src/responses/guild/GuildRank.php:
--------------------------------------------------------------------------------
1 | get("name");
23 | }
24 |
25 | /**
26 | * @return bool
27 | */
28 | public function isDefault() {
29 | return $this->get('default', false);
30 | }
31 |
32 | /**
33 | * @return string
34 | */
35 | public function getTag() {
36 | return $this->get("tag");
37 | }
38 |
39 | /**
40 | * @return int
41 | */
42 | public function getCreated() {
43 | return $this->getNumber("created");
44 | }
45 |
46 | /**
47 | * @return int
48 | */
49 | public function getPriority() {
50 | return $this->getNumber('priority');
51 | }
52 | }
--------------------------------------------------------------------------------
/src/responses/guild/GuildRanks.php:
--------------------------------------------------------------------------------
1 | 'MEMBER',
23 | 'priority' => 1
24 | ]);
25 | array_push($ranks, [
26 | 'name' => 'OFFICER',
27 | 'priority' => 2
28 | ]);
29 | }
30 | array_push($ranks, [
31 | 'name' => 'GUILDMASTER',
32 | 'priority' => PHP_INT_MAX,
33 | 'tag' => 'GM'
34 | ]);
35 |
36 | $this->ranks = [];
37 | foreach ($ranks as $rank) {
38 | $guildRank = new GuildRank($HypixelPHP, $rank);
39 | $this->ranks[strtolower($guildRank->getName())] = $guildRank;
40 |
41 | if ($guildRank->isDefault()) $this->defaultRank = $guildRank;
42 | }
43 | }
44 |
45 | /**
46 | * @return array[string]GuildRank
47 | */
48 | public function getRanks() {
49 | return $this->ranks;
50 | }
51 |
52 | /**
53 | * @param $rank
54 | * @return GuildRank
55 | */
56 | public function getRank($rank) {
57 | $lower = strtolower($rank);
58 | if (array_key_exists($lower, $this->ranks)) {
59 | return $this->ranks[$lower];
60 | }
61 | $lower = str_replace(" ", "", $lower);
62 | if (array_key_exists($lower, $this->ranks)) {
63 | return $this->ranks[$lower];
64 | }
65 | return null;
66 | }
67 |
68 | /**
69 | * @return GuildRank
70 | */
71 | public function getDefaultRank() {
72 | return $this->defaultRank;
73 | }
74 | }
--------------------------------------------------------------------------------
/src/responses/player/GameStats.php:
--------------------------------------------------------------------------------
1 | getArray('packages');
18 | }
19 |
20 | /**
21 | * @param $package
22 | * @return bool
23 | */
24 | public function hasPackage($package) {
25 | return in_array($package, $this->getArray('packages'));
26 | }
27 |
28 | /**
29 | * @return int
30 | */
31 | public function getCoins() {
32 | return $this->getNumber('coins');
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/src/responses/player/Rank.php:
--------------------------------------------------------------------------------
1 | id = $id;
22 | $this->name = $name;
23 | $this->options = $options;
24 | $this->staff = $staff;
25 | }
26 |
27 | /**
28 | * @return int
29 | */
30 | public function getId() {
31 | return $this->id;
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | public function getName() {
38 | return $this->name;
39 | }
40 |
41 | /**
42 | * @return string
43 | */
44 | public function getCleanName() {
45 | if ($this->name == 'NON_DONOR' || $this->name == 'NONE') return 'DEFAULT';
46 | if ($this->name == 'SUPERSTAR') return 'MVP++';
47 | return str_replace("_", ' ', str_replace('_PLUS', '+', $this->name));
48 | }
49 |
50 | /**
51 | * @return array
52 | */
53 | public function getOptions() {
54 | return $this->options;
55 | }
56 |
57 | /**
58 | * @return bool
59 | */
60 | public function isStaff() {
61 | return $this->staff;
62 | }
63 |
64 | /**
65 | * @param Player $player
66 | * @return string|null
67 | */
68 | public function getPrefix(Player $player) {
69 | if ($player->get("rankPlusColor") != null) {
70 | $plusColor = ColorUtils::NAME_TO_CODE[$player->get("rankPlusColor")];
71 | if ($plusColor != null) {
72 | if ($this->id == RankTypes::MVP_PLUS) {
73 | return '§b[MVP' . $plusColor . '+§b]';
74 | } else if ($this->id == RankTypes::SUPERSTAR) {
75 | $superStarColor = $player->getSuperStarColor();
76 | if ($superStarColor == null) $superStarColor = ColorUtils::GOLD;
77 | return $superStarColor . '[MVP' . $plusColor . '++' . $superStarColor . ']';
78 | }
79 | }
80 | }
81 | return isset($this->options['prefix']) ? $this->options['prefix'] : null;
82 | }
83 |
84 | /**
85 | * @return string|null
86 | */
87 | public function getColor() {
88 | return isset($this->options['color']) ? $this->options['color'] : null;
89 | }
90 |
91 | /**
92 | * @return int
93 | */
94 | public function getMultiplier() {
95 | return isset($this->options['eulaMultiplier']) ? $this->options['eulaMultiplier'] : 1;
96 | }
97 |
98 | /**
99 | * @return string
100 | */
101 | public function __toString() {
102 | return json_encode([$this->name => $this->options]);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/responses/player/RankTypes.php:
--------------------------------------------------------------------------------
1 | getName() == $db) {
60 | return $rank;
61 | }
62 | }
63 | }
64 | return null;
65 | }
66 |
67 | /**
68 | * @return array
69 | */
70 | public static function values() {
71 | return [
72 | self::NON_DONOR,
73 | self::VIP,
74 | self::VIP_PLUS,
75 | self::MVP,
76 | self::MVP_PLUS,
77 | self::SUPERSTAR,
78 | self::ADMIN,
79 | self::GAME_MASTER,
80 | self::MODERATOR,
81 | self::HELPER,
82 | self::JR_HELPER,
83 | self::YOUTUBER
84 | ];
85 | }
86 |
87 | /**
88 | * @param $id
89 | *
90 | * @return Rank|null
91 | */
92 | public static function fromID($id) {
93 | if (!isset(RankTypes::$cache[$id])) {
94 | $rank = null;
95 | switch ($id) {
96 | case RankTypes::NON_DONOR:
97 | $rank = new Rank(RankTypes::NON_DONOR, 'NON_DONOR', [
98 | 'prefix' => '§7',
99 | 'color' => '§7'
100 | ]);
101 | break;
102 | case RankTypes::VIP:
103 | $rank = new Rank(RankTypes::VIP, 'VIP', [
104 | 'prefix' => '§a[VIP]',
105 | 'color' => '§a',
106 | 'eulaMultiplier' => 2
107 | ]);
108 | break;
109 | case RankTypes::VIP_PLUS:
110 | $rank = new Rank(RankTypes::VIP_PLUS, 'VIP_PLUS', [
111 | 'prefix' => '§a[VIP§6+§a]',
112 | 'color' => '§a',
113 | 'eulaMultiplier' => 3
114 | ]);
115 | break;
116 | case RankTypes::MVP:
117 | $rank = new Rank(RankTypes::MVP, 'MVP', [
118 | 'prefix' => '§b[MVP]',
119 | 'color' => '§b',
120 | 'eulaMultiplier' => 4
121 | ]);
122 | break;
123 | case RankTypes::MVP_PLUS:
124 | $rank = new Rank(RankTypes::MVP_PLUS, 'MVP_PLUS', [
125 | 'prefix' => '§b[MVP§c+§b]',
126 | 'color' => '§b',
127 | 'eulaMultiplier' => 5
128 | ]);
129 | break;
130 | case RankTypes::SUPERSTAR:
131 | $rank = new Rank(RankTypes::SUPERSTAR, 'SUPERSTAR', [
132 | 'prefix' => '§6[MVP§c++§6]',
133 | 'color' => '§6'
134 | ]);
135 | break;
136 | case RankTypes::YOUTUBER:
137 | $rank = new Rank(RankTypes::YOUTUBER, 'YOUTUBER', [
138 | 'prefix' => '§c[§fYOUTUBE§c]',
139 | 'color' => '§c',
140 | 'eulaMultiplier' => 7
141 | ]);
142 | break;
143 | case RankTypes::JR_HELPER:
144 | $rank = new Rank(RankTypes::JR_HELPER, 'JR_HELPER', [
145 | 'prefix' => '§9[JR HELPER]',
146 | 'color' => '§9'
147 | ], true);
148 | break;
149 | case RankTypes::HELPER:
150 | $rank = new Rank(RankTypes::HELPER, 'HELPER', [
151 | 'prefix' => '§9[HELPER]',
152 | 'color' => '§9'
153 | ], true);
154 | break;
155 | case RankTypes::MODERATOR:
156 | $rank = new Rank(RankTypes::MODERATOR, 'MODERATOR', [
157 | 'prefix' => '§2[MOD]',
158 | 'color' => '§2'
159 | ], true);
160 | break;
161 | case RankTypes::GAME_MASTER:
162 | $rank = new Rank(RankTypes::GAME_MASTER, 'GAME_MASTER', [
163 | 'prefix' => '§2[GM]',
164 | 'color' => '§2'
165 | ], true);
166 | break;
167 | case RankTypes::ADMIN:
168 | $rank = new Rank(RankTypes::ADMIN, 'ADMIN', [
169 | 'prefix' => '§c[ADMIN]',
170 | 'color' => '§c'
171 | ], true);
172 | break;
173 | }
174 |
175 | RankTypes::$cache[$id] = $rank;
176 | }
177 |
178 | return RankTypes::$cache[$id];
179 | }
180 | }
--------------------------------------------------------------------------------
/src/responses/player/Stats.php:
--------------------------------------------------------------------------------
1 | getGame($gameType->getDb());
22 | }
23 | return null;
24 | }
25 |
26 | /**
27 | * @param $game
28 | *
29 | * @return GameStats
30 | */
31 | public function getGame($game) {
32 | $game = $this->getArray($game);
33 | return new GameStats($this->getHypixelPHP(), $game);
34 | }
35 | }
--------------------------------------------------------------------------------
/src/responses/skyblock/SkyBlockProfile.php:
--------------------------------------------------------------------------------
1 | get('profile_id');
19 | }
20 |
21 | /**
22 | * @return array
23 | */
24 | public function getMembers() {
25 | return $this->get('members');
26 | }
27 |
28 | /**
29 | * @return string
30 | */
31 | public function getCacheTimeKey() {
32 | return CacheTimes::SKYBLOCK_PROFILE;
33 | }
34 |
35 | public function save() {
36 | $this->getHypixelPHP()->getCacheHandler()->setSkyBlockProfile($this);
37 | }
38 | }
--------------------------------------------------------------------------------
/src/util/CacheUtil.php:
--------------------------------------------------------------------------------
1 | 0;
27 | }
28 |
29 | /**
30 | * Check how much time is left in the cache
31 | * All times supplied should be in milliseconds
32 | *
33 | * @param int $cachedTime timestamp of when something was cached
34 | * @param int $duration duration of cache
35 | * @param array|int $offset offset can be a number or array of numbers where a random will be picked
36 | *
37 | * @return int remaining time to keep cache
38 | */
39 | public static function getRemainingTime($cachedTime, $duration, $offset = 0) {
40 | $offsetValue = 0;
41 | if (is_array($offset)) {
42 | if (sizeof($offset) == 2) {
43 | try {
44 | $offsetValue = random_int($offset[0], $offset[1]);
45 | } catch (Exception $e) {
46 | $offsetValue = $offset[0]; // fallback
47 | }
48 | }
49 | } elseif (is_numeric($offset)) {
50 | $offsetValue = $offset;
51 | }
52 |
53 | return (time() * 1000) + $offsetValue - $duration - $cachedTime;
54 | }
55 |
56 | /**
57 | * Generate a filename for a given input, first few characters
58 | * become directories so less files per directory.
59 | * This improves speed for the OS
60 | *
61 | * @param $input
62 | * @param int $dirs
63 | *
64 | * @return string
65 | */
66 | public static function getCacheFileName($input, $dirs = 2) {
67 | $input = strtolower($input);
68 | $input = trim($input);
69 | $input = str_replace(' ', '%20', $input);
70 |
71 | if (strlen($input) <= $dirs) {
72 | $parts = str_split($input, 1);
73 | } else {
74 | $parts = [];
75 | for ($i = 0; $i < $dirs; $i++) {
76 | array_push($parts, substr($input, $i, 1));
77 | }
78 | array_push($parts, substr($input, $dirs));
79 | }
80 |
81 | return implode(DIRECTORY_SEPARATOR, $parts);
82 | }
83 |
84 | }
--------------------------------------------------------------------------------
/src/util/CachedGetter.php:
--------------------------------------------------------------------------------
1 | closure = $closure;
21 | }
22 |
23 |
24 | /**
25 | * @return mixed
26 | */
27 | public function get() {
28 | if (!$this->generated) {
29 | $this->generated = true;
30 | $this->value = ($this->closure)();
31 | }
32 | return $this->value;
33 | }
34 |
35 | /**
36 | * @return bool
37 | */
38 | public function isGenerated(): bool {
39 | return $this->generated;
40 | }
41 |
42 | /**
43 | * @return Closure
44 | */
45 | public function getClosure(): Closure {
46 | return $this->closure;
47 | }
48 |
49 | }
--------------------------------------------------------------------------------
/src/util/InputType.php:
--------------------------------------------------------------------------------
1 |
33 | * Examples:
34 | * - 0 XP = 1.0
35 | * - 5000 XP = 1.5
36 | * - 10000 XP = 2.0
37 | * - 50000 XP = 4.71...
38 | * - 79342431 XP = 249.46...
39 | *
40 | * @param float $exp Total experience gathered by the player.
41 | * @return float Exact level of player (Smallest value is 1.0)
42 | */
43 | static function getExactLevel(float $exp) {
44 | return Leveling::getLevel($exp) + Leveling::getPercentageToNextLevel($exp);
45 | }
46 |
47 | /**
48 | * This method returns the level of a player calculated by the current experience gathered. The result is
49 | * a precise level of the player The value is not zero-indexed and represents the absolute visible level
50 | * for the player.
51 | * The result can't be smaller than 1 and negative experience results in level 1.
52 | *
53 | * Examples:
54 | * - 0 XP = 1.0
55 | * - 5000 XP = 1.0
56 | * - 10000 XP = 2.0
57 | * - 50000 XP = 4.0
58 | * - 79342431 XP = 249.0
59 | *
60 | * @param float $exp Absolute level of player (Smallest value is 1.0)
61 | * @return float Total exp experience gathered by the player.
62 | */
63 | static function getLevel(float $exp) {
64 | return $exp < 0 ? 1 : floor(1 + Leveling::REVERSE_PQ_PREFIX + sqrt(Leveling::REVERSE_CONST + Leveling::GROWTH_DIVIDES_2 * $exp));
65 | }
66 |
67 | /**
68 | * This method returns the current progress of this level to reach the next level. This method is as
69 | * precise as possible due to rounding errors on the mantissa. The first 10 decimals are totally
70 | * accurate.
71 | *
72 | * Examples:
73 | * - 5000.0 XP (Lv. 1) = 0.5 (50 %)
74 | * - 22499.0 XP (Lv. 2) = 0.99992 (99.992 %)
75 | * - 5324224.0 XP (Lv. 62) = 0.856763076923077 (85.6763076923077 %)
76 | * - 23422443.0 XP (Lv. 134) = 0.4304905109489051 (43.04905109489051 %)
77 | *
78 | * @param float $exp Current experience gathered by the player
79 | * @return float Current progress to the next level
80 | */
81 | static function getPercentageToNextLevel(float $exp) {
82 | $lv = Leveling::getLevel($exp);
83 | $x0 = Leveling::getTotalExpToLevel($lv);
84 | return ($exp - $x0) / (Leveling::getTotalExpToLevel($lv + 1) - $x0);
85 | }
86 |
87 | /**
88 | * This method returns the experience it needs to reach that level. If you want to reach the given level
89 | * you have to gather the amount of experience returned by this method. This method is precise, that means
90 | * you can pass any progress of a level to receive the experience to reach that progress. (5.764 to get
91 | * the experience to reach level 5 with 76.4% of level 6.
92 | *
93 | * Examples:
94 | * - 1.0 = 0.0 XP
95 | * - 2.0 = 10000.0 XP
96 | * - 3.0 = 22500.0 XP
97 | * - 5.0 = 55000.0 XP
98 | * - 5.764 = 70280.0 XP
99 | * - 130.0 = 21930000.0 XP
100 | * - 250.43 = 79951975.0 XP
101 | *
102 | * @param float $level The level and progress of the level to reach
103 | * @return float The experience required to reach that level and progress
104 | */
105 | static function getTotalExpToLevel(float $level) {
106 | $lv = floor($level);
107 | $x0 = Leveling::getTotalExpToFullLevel($lv);
108 | if ($level == $lv) return $x0;
109 | return (Leveling:: getTotalExpToFullLevel($lv + 1) - $x0) * ($level % 1) + $x0;
110 | }
111 |
112 | /**
113 | * Helper method that may only be called by full levels and has the same functionality as getTotalExpToLevel()
114 | * but doesn't support progress and returns wrong values for progress due to perfect curve shape.
115 | *
116 | * @param float $level Level to receive the amount of experience to
117 | * @return float Experience to reach the given level
118 | */
119 | static function getTotalExpToFullLevel(float $level) {
120 | return (Leveling::HALF_GROWTH * ($level - 2) + Leveling::BASE) * ($level - 1);
121 | }
122 |
123 | /**
124 | * This method returns the amount of experience that is needed to progress from level to level + 1. (5 to 6)
125 | * The levels passed must absolute levels with the smallest level being 1. Smaller values always return
126 | * the BASE constant. The calculation is precise and if a decimal is passed it returns the XP from the
127 | * progress of this level to the next level with the same progress. (5.5 to 6.5)
128 | *
129 | * Examples:
130 | * - 1 (to 2) = 10000.0 XP
131 | * - 2 (to 3) = 12500.0 XP
132 | * - 3 (to 4) = 15000.0 XP
133 | * - 5 (to 6) = 20000.0 XP
134 | * - 5.5 (to 6.5) = 21250.0 XP
135 | * - 130 (to 131) = 332500.0 XP
136 | * - 250 (to 251) = 632500.0 XP
137 | *
138 | * @param float $level Level from which you want to get the next level with the same level progress
139 | * @return float Experience to reach the next level with same progress
140 | */
141 | static function getExpFromLevelToNext(float $level) {
142 | return $level < 1 ? Leveling::BASE : Leveling::GROWTH * ($level - 1) + Leveling::BASE;
143 | }
144 |
145 | /**
146 | * @param Player $player
147 | * @return float
148 | */
149 | static function getExperience(Player $player) {
150 | $exp = $player->getNumber(Leveling::EXP_FIELD);
151 | $exp += Leveling::getTotalExpToFullLevel((float)$player->getNumber(Leveling::LVL_FIELD) + 1);
152 | return (float)$exp;
153 | }
154 |
155 | }
--------------------------------------------------------------------------------
/src/util/Utilities.php:
--------------------------------------------------------------------------------
1 | 0
40 | && preg_match(Validator::USERNAME_MATCHER, $input); // actually check layout
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/util/games/BlitzUtils.php:
--------------------------------------------------------------------------------
1 | getNumber($kit);
21 | if ($purchased_level > 0) return $purchased_level;
22 |
23 | $exp = $stats->getNumber('exp_' . $kit);
24 | if ($exp > 0) {
25 | $last = 0;
26 | foreach ($resources['kits']['levels'] as $ordinal => $level) {
27 | if ($exp < $level['exp']) {
28 | break;
29 | }
30 | $last = $ordinal;
31 | }
32 | return $last;
33 | }
34 |
35 | return 0;
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/src/util/games/GameUtils.php:
--------------------------------------------------------------------------------
1 | getNumber(str_replace("%class%", strtolower($class['id']), $skill['field']), 1);
32 | return max($minLevel, $level);
33 | }
34 |
35 | /**
36 | * @param GameStats $stats
37 | * @param array $class
38 | * @param array $field
39 | * @return int
40 | */
41 | public function getFieldLevel($stats, $class, $field) {
42 | return $stats->getNumber(str_replace("%class%", strtolower($class['id']), $field['field']), 0);
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/src/util/games/bedwars/BedWarsPrestige.php:
--------------------------------------------------------------------------------
1 | ordinal = $ordinal;
42 | $this->name = $name;
43 | $this->color = $color;
44 | }
45 |
46 | /**
47 | * @return array
48 | */
49 | public static function values() {
50 | return [
51 | self::NONE,
52 | self::IRON,
53 | self::GOLD,
54 | self::DIAMOND,
55 | self::EMERALD,
56 | self::SAPPHIRE,
57 | self::CRYSTAL,
58 | self::OPAL,
59 | self::AMETHYST,
60 | self::RAINBOW
61 | ];
62 | }
63 |
64 | /**
65 | * @param $id
66 | *
67 | * @return BedWarsPrestige|null
68 | */
69 | public static function fromID($id) {
70 | if (!isset(BedWarsPrestige::$cache[$id])) {
71 | BedWarsPrestige::$cache[$id] = BedWarsPrestige::fromID0($id);
72 | }
73 | return BedWarsPrestige::$cache[$id];
74 | }
75 |
76 | /**
77 | * @param $id
78 | *
79 | * @return BedWarsPrestige|null
80 | */
81 | private static function fromID0($id) {
82 | switch ($id) {
83 | case BedWarsPrestige::NONE:
84 | return new BedWarsPrestige(BedWarsPrestige::NONE, "None", ColorUtils::GRAY);
85 | case BedWarsPrestige::IRON:
86 | return new BedWarsPrestige(BedWarsPrestige::IRON, "Iron", ColorUtils::WHITE);
87 | case BedWarsPrestige::GOLD:
88 | return new BedWarsPrestige(BedWarsPrestige::GOLD, "Gold", ColorUtils::GOLD);
89 | case BedWarsPrestige::DIAMOND:
90 | return new BedWarsPrestige(BedWarsPrestige::DIAMOND, "Diamond", ColorUtils::AQUA);
91 | case BedWarsPrestige::EMERALD:
92 | return new BedWarsPrestige(BedWarsPrestige::EMERALD, "Emerald", ColorUtils::DARK_GREEN);
93 | case BedWarsPrestige::SAPPHIRE:
94 | return new BedWarsPrestige(BedWarsPrestige::SAPPHIRE, "Sapphire", ColorUtils::DARK_AQUA);
95 | case BedWarsPrestige::RUBY:
96 | return new BedWarsPrestige(BedWarsPrestige::RUBY, "Ruby", ColorUtils::DARK_RED);
97 | case BedWarsPrestige::CRYSTAL:
98 | return new BedWarsPrestige(BedWarsPrestige::CRYSTAL, "Crystal", ColorUtils::LIGHT_PURPLE);
99 | case BedWarsPrestige::OPAL:
100 | return new BedWarsPrestige(BedWarsPrestige::OPAL, "Opal", ColorUtils::BLUE);
101 | case BedWarsPrestige::AMETHYST:
102 | return new BedWarsPrestige(BedWarsPrestige::AMETHYST, "Amethyst", ColorUtils::DARK_PURPLE);
103 | case BedWarsPrestige::RAINBOW:
104 | return new BedWarsPrestige(BedWarsPrestige::RAINBOW, "Rainbow", ColorUtils::WHITE);
105 | default:
106 | return null;
107 | }
108 | }
109 |
110 | /**
111 | * @return array
112 | */
113 | public static function getRainbowColors(): array {
114 | return self::$rainbowColors;
115 | }
116 |
117 | /**
118 | * @return mixed
119 | */
120 | public function getOrdinal() {
121 | return $this->ordinal;
122 | }
123 |
124 | /**
125 | * @return string
126 | */
127 | public function getName() {
128 | return $this->name;
129 | }
130 |
131 | /**
132 | * @return string
133 | */
134 | public function getColor() {
135 | return $this->color;
136 | }
137 | }
--------------------------------------------------------------------------------
/src/util/games/bedwars/BedWarsUtils.php:
--------------------------------------------------------------------------------
1 | BedWarsPrestige::HIGHEST_PRESTIGE * self::LEVELS_PER_PRESTIGE) {
76 | return $level - BedWarsPrestige::HIGHEST_PRESTIGE * self::LEVELS_PER_PRESTIGE;
77 | } else {
78 | return $level % self::LEVELS_PER_PRESTIGE;
79 | }
80 | }
81 |
82 | }
--------------------------------------------------------------------------------
/src/util/games/skywars/ExpCalculator.php:
--------------------------------------------------------------------------------
1 | getLevelForExp($exp);
29 | $levelExp = $this->getTotalExpForLevel($level);
30 | return $exp - $levelExp;
31 | }
32 |
33 | public function getLevelForExp($exp) {
34 | $easyLevelsCount = sizeof(self::EASY_LEVEL_EXP);
35 |
36 | $easyLevelExp = 0;
37 | for ($i = 1; $i <= $easyLevelsCount; $i++) {
38 | $expPerLevel = $this->getExpForLevel($i);
39 | $easyLevelExp += $expPerLevel;
40 | if ($exp < $easyLevelExp) {
41 | return $i - 1;//57965
42 | }
43 | }
44 | $extraLevels = ($exp - $easyLevelExp) / self::EXP_PER_LEVEL;
45 | return $easyLevelsCount + $extraLevels;
46 | }
47 |
48 | public function getExpForLevel($level) {
49 | if ($level <= sizeof(self::EASY_LEVEL_EXP)) {
50 | return self::EASY_LEVEL_EXP[$level - 1];
51 | }
52 |
53 | return self::EXP_PER_LEVEL;
54 | }
55 |
56 | public function getTotalExpForLevel($level) {
57 | $easyLevelsCount = sizeof(self::EASY_LEVEL_EXP);
58 |
59 | $totalExp = 0;
60 | $easyLevels = min($level, $easyLevelsCount);
61 | for ($i = 0; $i < $easyLevels; $i++) {
62 | $totalExp += self::EASY_LEVEL_EXP[$i];
63 | }
64 |
65 | if ($level > $easyLevelsCount) {
66 | $extraLevels = $level - $easyLevelsCount;
67 | $totalExp += ($extraLevels * self::EXP_PER_LEVEL);
68 | }
69 | return $totalExp;
70 | }
71 |
72 | /**
73 | * @param $prestiges array format from resources files
74 | * @param $level
75 | * @return mixed
76 | */
77 | public function getPrestigeForLevel(array $prestiges, $level) {
78 | foreach (array_reverse($prestiges) as $prestige) {
79 | if ($level >= $prestige["requiredLevel"]) {
80 | return $prestige;
81 | }
82 | }
83 |
84 | return end($prestiges);
85 | }
86 |
87 | }
--------------------------------------------------------------------------------
/src/util/games/skywars/SkyWarsUtils.php:
--------------------------------------------------------------------------------
1 | ENGINE = $this->convert($ENGINE)['GingerbreadPart'];
21 | $this->TURBOCHARGER = $this->convert($TURBOCHARGER)['GingerbreadPart'];
22 | $this->FRAME = $this->convert($FRAME)['GingerbreadPart'];
23 | }
24 |
25 | function convert($input) {
26 | if (is_string($input)) {
27 | return json_decode($this->fix_json($input), true);
28 | }
29 | return $input;
30 | }
31 |
32 | function fix_json($s) {
33 | $s = preg_replace('/(\w+):/i', '"\1":', $s);
34 | $s = preg_replace('/:(\w+)/i', ':"\1"', $s);
35 | return $s;
36 | }
37 |
38 | function getEngine() {
39 | return new Engine($this->ENGINE);
40 | }
41 |
42 | function getTurbocharger() {
43 | return new Turbocharger($this->TURBOCHARGER);
44 | }
45 |
46 | function getFrame() {
47 | return new Frame($this->FRAME);
48 | }
49 | }
50 |
51 | class Part {
52 | protected $PART;
53 | protected $PREFIXES = [
54 | "Default",
55 | "Starter",
56 | "Mini",
57 |
58 | "Auxiliary",
59 | "Standard",
60 | "Primary",
61 | "Experimental",
62 |
63 | "Dynamic",
64 | "Stellar",
65 | "Kinetic",
66 | "Multi-phase",
67 |
68 | "Turbocharged",
69 | "Quantum",
70 | "Superluminal",
71 | "Psi",
72 |
73 | "Eternal"
74 | ];
75 |
76 | function __construct($PART) {
77 | $this->PART = $PART;
78 | }
79 |
80 | function getAttributes() {
81 | return $this->PART['Attributes'];
82 | }
83 |
84 | function getColor() {
85 | $level = $this->getLevel();
86 | if ($level == 15) {
87 | return '§5';
88 | } else if ($level >= 11 && $level <= 14) {
89 | return '§d';
90 | } else if ($level >= 7 && $level <= 10) {
91 | return '§9';
92 | } else if ($level >= 3 && $level <= 6) {
93 | return '§a';
94 | }
95 | return '§7';
96 | }
97 |
98 | function getLevel() {
99 | $LEVEL = 0;
100 | if ($this->PART == null) return 0;
101 | if (!array_key_exists('Attributes', $this->PART)) return $LEVEL;
102 | foreach ($this->PART['Attributes'] as $ATTRIBUTE) {
103 | $LEVEL += $ATTRIBUTE['Level'];
104 | }
105 | return $LEVEL;
106 | }
107 |
108 | function getName() {
109 | return $this->getPrefix() . ' ' . ucfirst(strtolower($this->getRarity())) . ' ' . ucfirst(strtolower($this->getType()));
110 | }
111 |
112 | function getPrefix() {
113 | return $this->PREFIXES[$this->getLevel()];
114 | }
115 |
116 | function getRarity() {
117 | return $this->PART['PartRarity'];
118 | }
119 |
120 | function getType() {
121 | return $this->PART['PartType'];
122 | }
123 |
124 | function getAttributeLevel($TYPE) {
125 | if ($this->PART == null) return 0;
126 | if (!array_key_exists('Attributes', $this->PART)) return 0;
127 | foreach ($this->PART['Attributes'] as $ATTRIBUTE) {
128 | if ($ATTRIBUTE['KartAttributeType'] == $TYPE) {
129 | return $ATTRIBUTE['Level'];
130 | }
131 | }
132 | return 0;
133 | }
134 | }
135 |
136 | class Engine extends Part {
137 | function getRecovery() {
138 | return $this->getAttributeLevel('RECOVERY');
139 | }
140 |
141 | function getTopSpeed() {
142 | return $this->getAttributeLevel('TOP_SPEED');
143 | }
144 |
145 | function getAcceleration() {
146 | return $this->getAttributeLevel('ACCELERATION');
147 | }
148 | }
149 |
150 | class Turbocharger extends Part {
151 | function getDriftingEfficiency() {
152 | return $this->getAttributeLevel('DRIFTING_EFFICIENCY');
153 | }
154 |
155 | function getBrakes() {
156 | return $this->getAttributeLevel('BRAKES');
157 | }
158 |
159 | function getBoosterSpeed() {
160 | return $this->getAttributeLevel('BOOSTER_SPEED');
161 | }
162 | }
163 |
164 | class Frame extends Part {
165 | function getStartPosition() {
166 | return $this->getAttributeLevel('START_POSITION');
167 | }
168 |
169 | function getTraction() {
170 | return $this->getAttributeLevel('TRACTION');
171 | }
172 |
173 | function getHandling() {
174 | return $this->getAttributeLevel('HANDLING');
175 | }
176 | }
--------------------------------------------------------------------------------
/src/wrappers/PetStats.php:
--------------------------------------------------------------------------------
1 | $PET_INFO) {
36 | $this->PET_MAP[$PET] = new Pet($PET_INFO);
37 | }
38 | }
39 |
40 | /**
41 | * Calculate total amount of experience to reach given pet level
42 | *
43 | * @param $level
44 | * @return int
45 | */
46 | static function getExperienceUntilLevel($level) {
47 | $exp = 0;
48 | for ($i = 0; $i < min($level - 1, sizeof(PetStats::LEVELS) - 1); $i++) {
49 | $exp += PetStats::LEVELS[$i];
50 | }
51 |
52 | return $exp;
53 | }
54 |
55 | /**
56 | * @param $PET
57 | * @return Pet
58 | */
59 | function getPet($PET) {
60 | return $this->PET_MAP[$PET];
61 | }
62 |
63 | /**
64 | * @return Pet[]
65 | */
66 | function getAllPets() {
67 | return $this->PET_MAP;
68 | }
69 | }
70 |
71 | /**
72 | * Class Pet
73 | * @package Plancke\HypixelPHP\wrappers
74 | */
75 | class Pet {
76 |
77 | protected $PET_STATS;
78 | protected $LEVEL;
79 |
80 | /**
81 | * Pet constructor.
82 | * @param array $PET_STATS
83 | */
84 | function __construct($PET_STATS) {
85 | $this->PET_STATS = $PET_STATS;
86 |
87 | $this->updateLevel();
88 | }
89 |
90 | /**
91 | * Internally update level
92 | */
93 | function updateLevel() {
94 | $this->LEVEL = 1;
95 | $curExp = $this->getExperience();
96 | foreach (PetStats::LEVELS as $EXP_LEVEL) {
97 | if ($curExp < $EXP_LEVEL) {
98 | break;
99 | } else {
100 | $curExp -= $EXP_LEVEL;
101 | $this->LEVEL++;
102 | }
103 | }
104 | }
105 |
106 | /**
107 | * Get current pet experience
108 | *
109 | * @return int
110 | */
111 | function getExperience() {
112 | return array_key_exists('experience', $this->PET_STATS) ? $this->PET_STATS['experience'] : 0;
113 | }
114 |
115 | /**
116 | * Gets the value for $ATTRIBUTE_TYPE for this pet
117 | * taking into account the last timestamp to modify
118 | * the value
119 | *
120 | * @param $PET_ATTRIBUTE_TYPE
121 | * @return int
122 | */
123 | function getAttributeValue($PET_ATTRIBUTE_TYPE) {
124 | switch ($PET_ATTRIBUTE_TYPE) {
125 | case PetAttributeType::THIRST:
126 | return $this->modifyAttributeValue($PET_ATTRIBUTE_TYPE, $this->getAttr('THIRST'));
127 | case PetAttributeType::HUNGER:
128 | return $this->modifyAttributeValue($PET_ATTRIBUTE_TYPE, $this->getAttr('HUNGER'));
129 | case PetAttributeType::EXERCISE:
130 | return $this->modifyAttributeValue($PET_ATTRIBUTE_TYPE, $this->getAttr('EXERCISE'));
131 | }
132 | return null;
133 | }
134 |
135 | /**
136 | * Get value for given attribute while taking the last update
137 | * timestamp into account
138 | *
139 | * @param $ATTRIBUTE_TYPE
140 | * @param $ATTRIBUTE
141 | * @return int
142 | */
143 | function modifyAttributeValue($ATTRIBUTE_TYPE, $ATTRIBUTE) {
144 | $currentTime = round(microtime(true) * 1000);
145 | $timestamp = $ATTRIBUTE['timestamp'];
146 | $value = $ATTRIBUTE['value'];
147 |
148 | $timeElapsed = $currentTime - $timestamp;
149 | $minutesPassed = $timeElapsed / (1000 * 60);
150 | $iterations = floor($minutesPassed / 5);
151 |
152 | return max(0, round($value - $iterations * PetAttributeType::getDecay($ATTRIBUTE_TYPE)));
153 | }
154 |
155 | /**
156 | * @param $key
157 | * @return mixed
158 | */
159 | protected function getAttr($key) {
160 | if (!array_key_exists($key, $this->PET_STATS)) {
161 | return [
162 | 'timestamp' => 0,
163 | 'value' => 0
164 | ];
165 | }
166 | return $this->PET_STATS[$key];
167 | }
168 |
169 | /**
170 | *
171 | * Get pet level
172 | *
173 | * @return int
174 | */
175 | function getLevel() {
176 | return $this->LEVEL;
177 | }
178 |
179 | /**
180 | * @return int
181 | */
182 | function getLevelProgress() {
183 | return $this->getExperience() - PetStats::getExperienceUntilLevel($this->LEVEL);
184 | }
185 |
186 | /**
187 | * @return array
188 | */
189 | function getRaw() {
190 | return $this->PET_STATS;
191 | }
192 |
193 | }
194 |
195 | /**
196 | * Class PetAttributeType
197 | * @package Plancke\HypixelPHP\wrappers
198 | */
199 | class PetAttributeType {
200 |
201 | const THIRST = 1;
202 | const HUNGER = 2;
203 | const EXERCISE = 3;
204 |
205 | /**
206 | *
207 | * Get decay rate for given type
208 | *
209 | * @param $ATTRIBUTE_TYPE
210 | * @return int
211 | */
212 | static function getDecay($ATTRIBUTE_TYPE) {
213 | return 1;
214 | }
215 | }
--------------------------------------------------------------------------------
/src/wrappers/battlegrounds/Abilities.php:
--------------------------------------------------------------------------------
1 | name = $name;
16 | $this->spec = $spec;
17 | $this->type = $type;
18 | }
19 |
20 | /**
21 | * @return string
22 | */
23 | function getName() {
24 | return $this->name;
25 | }
26 |
27 | /**
28 | * @return string
29 | */
30 | function getSpec() {
31 | return $this->spec;
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | function getType() {
38 | return $this->type;
39 | }
40 | }
--------------------------------------------------------------------------------
/src/wrappers/battlegrounds/AbilityType.php:
--------------------------------------------------------------------------------
1 | [0 => "Pyromancer", 1 => "Cryomancer", 2 => "Aquamancer"],
10 | PlayerClasses::WARRIOR => [0 => "Berserker", 1 => "Defender", 2 => "Revenant"],
11 | PlayerClasses::PALADIN => [0 => "Avenger", 1 => "Crusader", 2 => "Protector"],
12 | PlayerClasses::SHAMAN => [0 => "Thunderlord", 1 => "Earthwarden", 2 => "Spiritguard"],
13 | ];
14 |
15 | /**
16 | * PlayerClass constructor.
17 | * @param string $name
18 | * @param int $spec
19 | * @param int $id
20 | */
21 | function __construct($name, $spec, $id) {
22 | $this->name = $name;
23 | $this->spec = $spec;
24 | $this->id = $id;
25 | }
26 |
27 | /**
28 | * @return int
29 | */
30 | function getID() {
31 | return $this->id;
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | function getName() {
38 | return $this->name;
39 | }
40 |
41 | /**
42 | * @return string
43 | */
44 | function getDisplay() {
45 | return ucfirst($this->name);
46 | }
47 |
48 | /**
49 | * @return Spec
50 | */
51 | function getSpec() {
52 | return new Spec($this->specs[$this->id][$this->spec], $this->spec);
53 | }
54 | }
--------------------------------------------------------------------------------
/src/wrappers/battlegrounds/PlayerClasses.php:
--------------------------------------------------------------------------------
1 | name = $name;
15 | $this->id = $id;
16 | }
17 |
18 | /**
19 | * @return string
20 | */
21 | function getName() {
22 | return $this->name;
23 | }
24 |
25 | /**
26 | * @return int
27 | */
28 | function getID() {
29 | return $this->id;
30 | }
31 | }
--------------------------------------------------------------------------------
/src/wrappers/battlegrounds/weapon/Rarity.php:
--------------------------------------------------------------------------------
1 | addValue(WeaponStats::DAMAGE, 90, 100)
35 | ->addValue(WeaponStats::CHANCE, 10, 18)
36 | ->addValue(WeaponStats::MULTIPLIER, 150, 170)
37 | ->addValue(WeaponStats::ABILITY_BOOST, 4, 6)
38 | ->addValue(WeaponStats::HEALTH, 180, 220);
39 |
40 | RarityValues::$cache[Rarity::RARE] = (new RarityValues())
41 | ->addValue(WeaponStats::DAMAGE, 95, 105)
42 | ->addValue(WeaponStats::CHANCE, 12, 20)
43 | ->addValue(WeaponStats::MULTIPLIER, 160, 180)
44 | ->addValue(WeaponStats::ABILITY_BOOST, 6, 8)
45 | ->addValue(WeaponStats::HEALTH, 200, 250)
46 | ->addValue(WeaponStats::ENERGY, 10, 18);
47 |
48 | RarityValues::$cache[Rarity::EPIC] = (new RarityValues())
49 | ->addValue(WeaponStats::DAMAGE, 100, 110)
50 | ->addValue(WeaponStats::CHANCE, 15, 20)
51 | ->addValue(WeaponStats::MULTIPLIER, 160, 190)
52 | ->addValue(WeaponStats::ABILITY_BOOST, 7, 9)
53 | ->addValue(WeaponStats::HEALTH, 220, 275)
54 | ->addValue(WeaponStats::ENERGY, 15, 20)
55 | ->addValue(WeaponStats::COOLDOWN, 3, 5);
56 |
57 | RarityValues::$cache[Rarity::LEGENDARY] = (new RarityValues())
58 | ->addValue(WeaponStats::DAMAGE, 110, 120)
59 | ->addValue(WeaponStats::CHANCE, 15, 25)
60 | ->addValue(WeaponStats::MULTIPLIER, 180, 200)
61 | ->addValue(WeaponStats::ABILITY_BOOST, 10, 15)
62 | ->addValue(WeaponStats::HEALTH, 250, 400)
63 | ->addValue(WeaponStats::ENERGY, 20, 25)
64 | ->addValue(WeaponStats::COOLDOWN, 5, 10)
65 | ->addValue(WeaponStats::MOVEMENT, 5, 10);
66 | }
67 |
68 | /**
69 | * @param $id
70 | * @param $min
71 | * @param $max
72 | * @return $this
73 | */
74 | public function addValue($id, $min, $max) {
75 | $this->values[$id] = [
76 | 'min' => $min,
77 | 'max' => $max
78 | ];
79 | return $this;
80 | }
81 |
82 | /**
83 | * @return array[int]array[string]int
84 | */
85 | public function getValues(): array {
86 | return $this->values;
87 | }
88 |
89 | /**
90 | * @param WeaponStat $weaponStat
91 | * @return array[string]int|null
92 | */
93 | public function getValue(WeaponStat $weaponStat) {
94 | if (array_key_exists($weaponStat->getID(), $this->values)) {
95 | return $this->values[$weaponStat->getID()];
96 | }
97 | return null;
98 | }
99 |
100 | }
--------------------------------------------------------------------------------
/src/wrappers/battlegrounds/weapon/WeaponGrader.php:
--------------------------------------------------------------------------------
1 | getCategory());
13 | if ($rarityValues == null) return 0;
14 |
15 | $percentages = [];
16 |
17 | foreach (WeaponStats::values() as $id) {
18 | $weaponStat = WeaponStats::fromID($id);
19 | $value = $rarityValues->getValue($weaponStat);
20 | if ($value == null) continue;
21 | if (!array_key_exists('min', $value)) continue;
22 | if (!array_key_exists('max', $value)) continue;
23 |
24 | array_push($percentages, ($weapon->getBaseStat($weaponStat) - $value['min']) / ($value['max'] - $value['min']));
25 | }
26 |
27 | if (sizeof($percentages) == 0) return 0; // just in case
28 | return array_sum($percentages) / sizeof($percentages);
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/src/wrappers/battlegrounds/weapon/WeaponInventory.php:
--------------------------------------------------------------------------------
1 | [],
9 | Rarity::RARE => [],
10 | Rarity::EPIC => [],
11 | Rarity::LEGENDARY => []
12 | ];
13 | protected $weaponsById = [];
14 |
15 | public function __construct($weapons) {
16 | foreach ($weapons as $weaponRaw) {
17 | $weapon = new Weapon($weaponRaw);
18 | array_push($this->weapons[$weapon->getCategory()], $weapon);
19 | $this->weaponsById[$weapon->getID()] = $weapon;
20 | }
21 | }
22 |
23 | /**
24 | * @return array[string]Weapon[]
25 | */
26 | public function getWeapons() {
27 | return $this->weapons;
28 | }
29 |
30 | public function getWeapon($id) {
31 | return array_key_exists($id, $this->weaponsById) ? $this->weaponsById[$id] : null;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/wrappers/battlegrounds/weapon/WeaponStat.php:
--------------------------------------------------------------------------------
1 | name = $name;
17 | $this->field = $field;
18 | $this->upgrade = $upgrade;
19 | $this->id = $id;
20 | }
21 |
22 | /**
23 | * @return string
24 | */
25 | public function getName() {
26 | return $this->name;
27 | }
28 |
29 | /**
30 | * @return string
31 | */
32 | public function getField() {
33 | return $this->field;
34 | }
35 |
36 | /**
37 | * @return double
38 | */
39 | public function getUpgrade() {
40 | return $this->upgrade;
41 | }
42 |
43 | /**
44 | * @return int
45 | */
46 | public function getID() {
47 | return $this->id;
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/src/wrappers/battlegrounds/weapon/WeaponStats.php:
--------------------------------------------------------------------------------
1 | getCurrentTimePlusOne();
17 | $this->assertTrue(CacheUtil::isExpired($cachedTime, 0, 5000));
18 |
19 | // will it still be valid in 5 seconds?
20 | $cachedTime = $this->getCurrentTimePlusOne();
21 | $this->assertFalse(CacheUtil::isExpired($cachedTime, 2000, -5000));
22 |
23 | $cachedTime = $this->getCurrentTimePlusOne();
24 | $remain = CacheUtil::getRemainingTime($cachedTime, 0, [2000, 3000]);
25 | $this->assertTrue($remain >= 2000 && $remain <= 3000);
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/tests/ColorTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(ColorUtils::stripColors($colored) == $unColored);
14 | }
15 | }
--------------------------------------------------------------------------------
/tests/DataHoldingTest.php:
--------------------------------------------------------------------------------
1 | 1,
14 | 'double' => 0.5,
15 | 'array' => []
16 | ]);
17 |
18 | $this->assertTrue($resource->getDouble('double') == 0.5);
19 | $this->assertTrue($resource->getNumber('int') == 1);
20 |
21 | // not an array, fall back to default
22 | $this->assertTrue($resource->getArray('int') == []);
23 | }
24 |
25 | }
26 |
27 | class DataHoldingImpl {
28 |
29 | use DataHolding;
30 |
31 | protected $data;
32 |
33 | /**
34 | * Resource constructor.
35 | * @param $data
36 | */
37 | public function __construct($data) {
38 | $this->data = $data;
39 | }
40 |
41 | /**
42 | * @return mixed
43 | */
44 | public function getData() {
45 | return $this->data;
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/tests/ResponseTest.php:
--------------------------------------------------------------------------------
1 | getCounts();
19 | $this->assertTrue($counts instanceof Counts);
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/tests/ValidatorTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(Validator::isAnyUUID('f025c1c7-f55a-4ea0-b8d9-3f47d17dfe0f')); // dashes
12 | $this->assertTrue(Validator::isAnyUUID('f025c1c7f55a4ea0b8d93f47d17dfe0f')); // no dashes
13 |
14 | $this->assertFalse(Validator::isAnyUUID('f025c1c7f55a9ea0b8d93f47d17dfe0f')); // bad version
15 | $this->assertFalse(Validator::isAnyUUID('f025c1c7f55a4ea0b8d93f47d17dfe0g')); // bad last character
16 | $this->assertFalse(Validator::isAnyUUID('f025c1c7f55a4ea0b8d93f47d17dfe0')); // too short
17 | $this->assertFalse(Validator::isAnyUUID('f025c1c7-f55a-4ea0-b8d9-3f47d17dfe0ff')); // too long
18 | }
19 |
20 | function testUsername() {
21 | $this->assertTrue(Validator::isUsername('Plancke'));
22 | $this->assertTrue(Validator::isUsername('Plancke_R')); // underscore
23 | $this->assertTrue(Validator::isUsername('G')); // 1 letter og
24 |
25 | $this->assertFalse(Validator::isUsername('Plancke-R'));// dash
26 | $this->assertFalse(Validator::isUsername('hello world')); // spaces
27 | }
28 |
29 | /**
30 | * @depends testUUID
31 | */
32 | function testAPIKey() {
33 | // any uuid will do but just double checking separately in case anything changes down the line
34 | $this->assertTrue(Validator::isValidAPIKey('f025c1c7-f55a-4ea0-b8d9-3f47d17dfe0f'));
35 | $this->assertTrue(Validator::isValidAPIKey('f025c1c7f55a4ea0b8d93f47d17dfe0f'));
36 |
37 | $this->assertFalse(Validator::isValidAPIKey('Plancke'));
38 | }
39 | }
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | _testLevel(0, 0, 0);
12 |
13 | $this->_testLevel(708325, 146, 1);
14 | $this->_testLevel(199146, 42, 0);
15 | $this->_testLevel(1174460, 242, 2);
16 | }
17 |
18 | /**
19 | * @param $exp
20 | * @param $expectedLevel
21 | * @param $expectedPrestigeOrdinal
22 | */
23 | function _testLevel($exp, $expectedLevel, $expectedPrestigeOrdinal) {
24 | $level = GameUtils::getBedWars()->getExpCalculator()->getLevelForExp($exp);
25 | $this->assertEquals($expectedLevel, $level);
26 | $prestige = GameUtils::getBedWars()->getExpCalculator()->getPrestigeForLevel($level);
27 | $this->assertEquals($expectedPrestigeOrdinal, $prestige->getOrdinal());
28 | }
29 | }
--------------------------------------------------------------------------------
/tests/util/TestUtil.php:
--------------------------------------------------------------------------------
1 | setLogger(new class ($HypixelPHP) extends Logger {
22 | public function actuallyLog($level, $line) {
23 | echo $level . ': ' . $line . "\n";
24 | }
25 | });
26 |
27 | $HypixelPHP->setCacheHandler(new NoCacheHandler($HypixelPHP));
28 | $HypixelPHP->setFetcher(new DefaultFGCFetcher($HypixelPHP));
29 |
30 | return $HypixelPHP;
31 | }
32 |
33 | public static function getAPIKey() {
34 | if (isset($_ENV['API_KEY'])) return $_ENV['API_KEY'];
35 | if (isset($_SERVER['API_KEY'])) return $_SERVER['API_KEY'];
36 | return null;
37 | }
38 |
39 | }
--------------------------------------------------------------------------------