1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2018 VectorNetworkProject. All rights reserved. MIT license. |
4
|
|
|
* |
5
|
|
|
* GitHub: https://github.com/VectorNetworkProject/TheMix |
6
|
|
|
* Website: https://www.vector-network.tk |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace VectorNetworkProject\TheMix\game\kit; |
10
|
|
|
|
11
|
|
|
use pocketmine\item\Armor; |
12
|
|
|
use pocketmine\item\Durable; |
13
|
|
|
use pocketmine\item\Item; |
14
|
|
|
use pocketmine\Player; |
15
|
|
|
use pocketmine\utils\Color; |
16
|
|
|
|
17
|
|
View Code Duplication |
class RedKit |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param Player $player |
21
|
|
|
*/ |
22
|
|
|
public static function sendItem(Player $player) |
23
|
|
|
{ |
24
|
|
|
$armors = [ |
25
|
|
|
'leather_cap' => Item::get(Item::LEATHER_CAP), |
26
|
|
|
'leather_tunic' => Item::get(Item::LEATHER_TUNIC), |
27
|
|
|
'leather_pants' => Item::get(Item::LEATHER_PANTS), |
28
|
|
|
'leather_boots' => Item::get(Item::LEATHER_BOOTS), |
29
|
|
|
]; |
30
|
|
|
$weapons = [ |
31
|
|
|
'wooden_sword' => Item::get(Item::WOODEN_SWORD), |
32
|
|
|
'bow' => Item::get(Item::BOW), |
33
|
|
|
'stone_pickaxe' => Item::get(Item::STONE_PICKAXE), |
34
|
|
|
'stone_axe' => Item::get(Item::STONE_AXE), |
35
|
|
|
'stone_shovel' => Item::get(Item::STONE_SHOVEL), |
36
|
|
|
]; |
37
|
|
|
foreach ($armors as $armor) { |
38
|
|
|
if ($armor instanceof Durable and $armor instanceof Armor) { |
39
|
|
|
$armor->setUnbreakable(true); |
40
|
|
|
$armor->setCustomColor(new Color(255, 0, 50)); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
foreach ($weapons as $weapon) { |
44
|
|
|
if ($weapon instanceof Durable) { |
45
|
|
|
$weapon->setUnbreakable(true); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
$player->getInventory()->clearAll(); |
49
|
|
|
$armor = $player->getArmorInventory(); |
50
|
|
|
$armor->setHelmet($armors['leather_cap']); |
51
|
|
|
$armor->setChestplate($armors['leather_tunic']); |
52
|
|
|
$armor->setLeggings($armors['leather_pants']); |
53
|
|
|
$armor->setBoots($armors['leather_boots']); |
54
|
|
|
$player->getInventory()->addItem($weapons['wooden_sword']); |
55
|
|
|
$player->getInventory()->addItem($weapons['bow']); |
56
|
|
|
$player->getInventory()->addItem($weapons['stone_pickaxe']); |
57
|
|
|
$player->getInventory()->addItem($weapons['stone_axe']); |
58
|
|
|
$player->getInventory()->addItem($weapons['stone_shovel']); |
59
|
|
|
$player->getInventory()->setItem(8, Item::get(Item::ARROW, 0, 64)); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.