Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .poggit.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
--- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/luca28pet/AdvancedKits
--- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/skyss0fly/AdvancedKits
build-by-default: true
branches:
- master
projects:
AdvancedKits:
path: ""
libs:
- src: jojoe77777/FormAPI/libFormAPI
version: ^1.3
- src: dktapps-pm-pl/pmforms/pmforms
version: ^2.1.0
...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A PocketMine-MP plugin that adds kits to your server with many features and supp

*Latest release: https://poggit.pmmp.io/p/AdvancedKits/*

*Latest development phars: https://poggit.pmmp.io/ci/luca28pet/AdvancedKits/AdvancedKits*
*Latest development phars: https://poggit.pmmp.io/ci/skyss0fly/AdvancedKits/AdvancedKits*

This plugin only supports PocketMine-MP. It might work on other forks as well, but please Do NOT open issues if you have problems with AdvancedKits and you are using a fork.

Expand Down
45 changes: 22 additions & 23 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
name: AdvancedKits
main: AdvancedKits\Main
version: 5.3.0
api: [3.0.0]
author: luca28pet
main: AdvancedKits\AdvancedKits
version: 7.0.0
api: 5.0.0
author: [luca28pet,skyss0fly]
description: Add kits to your server
website: https://github.com/luca28pet/AdvancedKits
softdepend: [PiggyCustomEnchants]
website: https://github.com/skyss0fly/AdvancedKits
commands:
kit:
description: Get a kit!
usage: "/kit <kitName>"
aliases: [ak, advancedkits]
permission: advancedkits.command
akreload:
descrpition: Reload Kits settings
usage: "/akreload"
permission: advancedkits.admin
kit:
description: Get a kit!
usage: /kit <kitName>
permission: AdvancedKitsAK.command.kit
akreload:
descrpition: Reload Kits settings
usage: /akreload
permission: AdvancedKitsAK.command.akreload
givekit:
description: Give a kit to someone
usage: /givekit <kitName> <playerName>
permission: AdvancedKitsAK.command.givekit
permissions:
advancedkits:
description: "Root permission"
default: false
children:
advancedkits.command:
description: "Allows the user to run /kit command"
AdvancedKitsAK.command.kit:
default: true
advancedkits.admin:
description: "Allows to manage admin features"
AdvancedKitsAK.command.akreload:
default: op
AdvancedKitsAK.command.givekit:
default: op

6 changes: 3 additions & 3 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ sign-text: "[AdvancedKits]"
# Kits you don't have the permission to get will be hidden from the kits list
hide-no-perm-kits: false

# Show the kit list as a form when a player runs the command /kit (without arguments)
show-form-no-args: true
...
# "form" or "chat"
kit-list-type: "form"
...
73 changes: 24 additions & 49 deletions resources/kits.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
---
testkit:
# ITEM FORMAT: "id:damage:count:name:ench_name:ench_level"
# NO enchantments and NO custom name: "id:damage:count"

# ONLY custom name: "id:damage:count:custom name"

# ONLY enchantments: "id:damage:count:DEFAULT:enchantment1:level"
# (Put DEFAULT in the name field if you do not want a custom name)
# You can put as many enchantments as you want like this: "id:damage:count:DEFAULT:enchantment1:level:enchantment2:level" etc.

# Enchantments AND custom name: "id:damage:count:custom name:enchantment1:level"
# You can put as many enchantments as you want like this: "id:damage:count:custom name:enchantment1:level:enchantment2:level" etc.

# You can write both numeric or string IDs
- name: TestKit
# Items list
items:
- "260:0:10"
- "267:0:1:Sword Name"
helmet: "diamond_helmet:0:1"
chestplate: "diamond_chestplate:0:1:DEFAULT:protection:1"
leggings: "diamond_leggings:0:1:Leggings Name"
boots: "diamond_boots:0:1"
- alias: diamond_sword
count: 1
custom-name: My Diamond Sword
enchantments:
- name: protection
level: 1
- alias: apple
count: 5

# Armor
helmet:
alias: diamond_helmet
chestplate:
alias: diamond_chestplate
leggings:
alias: diamond_leggings
boots:
alias: diamond_boots

# Set items for specific slots, will override existing items. Only use if you want to assign items to specific slots, otherwise delete this.
slots:
9: "golden_apple:0:5"
12: "bow:0:1"
12:
alias: bow
count: 1

commands:
- "tell {player} you got an awesome kit thanks to AdvancedKits plugin!"
- "tell {player} you got an awesome kit thanks to AdvancedKits plugin!"

cooldown:
hours: 24
Expand All @@ -41,37 +42,11 @@ testkit:
# Put 0 if you want the kit to be free
money: 50

# If you do not use pureperms, use 'worlds' to specify in which worlds you want this kit to be used
# Leave blank to let use the kit in all worlds
worlds:
- "kitpvp"

# If you do not use pureperms, use 'users' to specify which players will be able to get this kit
# Leave blank to let all the players use this kit
users:
- "luca28pet"
- "dioconsole"

# FormAPI users:
# Img type: 'url' or 'path'
img-type: ''
# Put here the image URL/path
img-data: ''
# How the kit is displayed on the form
form-name: 'Test Kit: 50$'

sgkit:
items:
- 'bow:0:1'
- 'arrow:0:5'
- 'stone_sword:0:1'
- 'apple:0:5'
helmet: 'leather_cap:0:1'
chestplate: 'leather_tunic:0:1'
commands:
- 'tell {player} You got a SG example kit'
cooldown:
hours: 1
minutes: 0
money: 0
...
192 changes: 192 additions & 0 deletions src/AdvancedKits/AdvancedKits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?php
declare(strict_types=1);

namespace AdvancedKits;

use pocketmine\plugin\PluginBase;
use AdvancedKits\kit\KitsManager;
use AdvancedKits\kit\Kit;
use pocketmine\item\StringToItemParser;
use pocketmine\item\Item;
use pocketmine\item\enchantment\StringToEnchantmentParser;
use pocketmine\item\enchantment\EnchantmentInstance;
use AdvancedKits\perm\DefaultPermissionChecker;
use pocketmine\command\CommandSender;
use pocketmine\command\Command;
use pocketmine\player\Player;
use AdvancedKits\lang\LangManager;
use AdvancedKits\perm\PermissionChecker;
use dktapps\pmforms\{MenuForm, MenuOption};


final class AdvancedKits extends PluginBase {
private KitsManager $kitsManager;
private LangManager $langManager;
private PermissionChecker $permChecker;
private string $kitListType;
private bool $hideNoPermKits;

protected function onEnable() : void {
$kits = $this->loadKitsSettings();
if ($kits === null) {
return;
}
$this->loadOtherSettings();
$this->langManager = new LangManager($this->getDataFolder().'lang.properties', $this->getLogger());
$this->permChecker = new DefaultPermissionChecker($kits);
$this->kitsManager = new KitsManager(
array_combine(array_map(fn(Kit $kit) => $kit->getName(), $kits), $kits),
$this->permChecker,
$this->langManager
);
}

private function loadOtherSettings() : void {
$this->saveResource('config.yml');
$contents = file_get_contents($this->getDataFolder().'config.yml');
if ($contents === false) {
$this->getLogger()->error('Unable to open config.yml');
$this->getServer()->getPluginManager()->disablePlugin($this);
return;
}
$data = yaml_parse($contents);
if (!is_array($data)) {
$this->getLogger()->error('Configuration error in config.yml');
$this->getServer()->getPluginManager()->disablePlugin($this);
return;
}
try {
$this->kitListType = ConfigParser::getStringAlternative($data['kit-list-type'] ?? null, ['chat', 'form']);
$this->hideNoPermKits = ConfigParser::getBool($data['hide-no-perm-kits'] ?? null);
} catch (\InvalidArgumentException $e) {
$this->getLogger()->error('Configuration error in config.yml, details:');
do {
$this->getLogger()->error($e->getMessage());
} while (($e = $e->getPrevious()) !== null);
$this->getServer()->getPluginManager()->disablePlugin($this);
return;
}
}

/**
* @return array<Kit>
*/
private function loadKitsSettings() : ?array {
$this->saveResource('kits.yml');
$contents = file_get_contents($this->getDataFolder().'kits.yml');
if ($contents === false) {
$this->getLogger()->error('Unable to open kits.yml');
$this->getServer()->getPluginManager()->disablePlugin($this);
return null;
}
$data = yaml_parse($contents);
try {
$kits = ConfigParser::getList($data, [ConfigParser::class, 'getKit']);
} catch (\InvalidArgumentException $e) {
$this->getLogger()->error('Configuration error in kits.yml, details:');
do {
$this->getLogger()->error($e->getMessage());
} while (($e = $e->getPrevious()) !== null);
$this->getServer()->getPluginManager()->disablePlugin($this);
return null;
}
return $kits;
}

public function getKitsManager() : KitsManager {
return $this->kitsManager;
}

public function getLangManager() : LangManager {
return $this->langManager;
}

private function doKitRequest(Player $p, Kit $kit) : void {
$this->kitsManager->kitRequest($p, $kit, function(bool $reqAccepted, ?string $reason) use ($p, $kit) : void {
if (!$p->isOnline()) {
return;
}
if ($reqAccepted) {
$kit->giveTo($p);
$p->sendMessage($this->langManager->getTranslation('sel-kit', [$kit->getName()]));
} else {
$p->sendMessage($reason ?? '');
}
});
}

public function onCommand(CommandSender $sn, Command $cmd, string $lbl, array $args) : bool {
switch($cmd->getName()) {
case 'kit':
switch (count($args)) {
case 0:
if ($sn instanceof Player && $this->hideNoPermKits) {
$kits = array_filter($this->kitsManager->getKits(),
fn(Kit $kit) => $this->permChecker->canPlayerGetKit($sn, $kit));
} else {
$kits = $this->kitsManager->getKits();
}
switch ($this->kitListType) {
case 'chat':
$sn->sendMessage($this->langManager->getTranslation(
'av-kits', [implode(', ', array_map(fn(Kit $kit) => $kit->getName(), $kits))]));
break;
case 'form':
$options = array_map(fn(Kit $kit) => new MenuOption($kit->getName()), $kits);
$form = new MenuForm($this->langManager->getTranslation('form-title', []), '', $options, function(Player $p, int $opt) use (&$form) : void {
$option = $form?->getOption($opt);
if ($option === null) {
return;
}
$kit = $this->kitsManager->getKitByName($option->getText());
if ($kit === null) {
return;
}
$this->doKitRequest($p, $kit);
});
break;
default:
throw new \LogicException('This should never happen');
}
return true;
case 1:
if (!($sn instanceof Player)) {
return true;
}
$kitName =& $args[0];
$kit = $this->kitsManager->getKitByName($kitName);
if ($kit !== null) {
$this->doKitRequest($sn, $kit);
} else {
$sn->sendMessage($this->langManager->getTranslation('no-kit', [$kitName]));
}
return true;
default:
return false;
}
case 'givekit':
if (count($args) !== 2) {
return false;
}
$kitName =& $args[0];
$playerName =& $args[1];
$kit = $this->kitsManager->getKitByName($kitName);
if ($kit === null) {
$sn->sendMessage($this->langManager->getTranslation('no-kit', [$kitName]));
return true;
}
$player = $this->getServer()->getPlayerByPrefix($playerName);
if ($player === null) {
$sn->sendMessage($this->langManager->getTranslation('player-offline', [$playerName]));
return true;
}
$kit->giveTo($player);
return true;
case 'akreload':
//todo
return true;
}
return true;
}
}

Loading