Skip to content

Commit

Permalink
Bump to v2.1.0, API 5 update (#132)
Browse files Browse the repository at this point in the history
* First pass at API 5

* Swap forms virion

* Update libasynql virion

* Turn lint back on

* Revert "Turn lint back on"

This reverts commit db38df4.

* Update virions

* Use floats for degrees calculation

* Cast degrees to an int

---------

Co-authored-by: aericio <[email protected]>
  • Loading branch information
jasonw4331 and Aericio authored Jul 16, 2023
1 parent 9c29205 commit 5ab2604
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 35 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
wget -O vendor/ScoreHud.phar https://poggit.pmmp.io/r/161570/ScoreHud_dev-71.phar
- name: Download Virion Dependencies
run: |
wget -O vendor/libasynql.phar https://poggit.pmmp.io/r/204062/libasynql_dev-199.phar
wget -O vendor/libFormAPI.phar https://poggit.pmmp.io/r/207248/libFormAPI_dev-4.phar
wget -O vendor/libPiggyEconomy.phar https://poggit.pmmp.io/r/177191/libPiggyEconomy_dev-18.phar
wget -O vendor/libasynql.phar https://poggit.pmmp.io/r/213142/libasynql_dev-203.phar
wget -O vendor/FormsUI.phar https://poggit.pmmp.io/r/209836/FormsUI_dev-20.phar
wget -O vendor/libPiggyEconomy.phar https://poggit.pmmp.io/r/212853/libPiggyEconomy_dev-19.phar
wget -O vendor/libPiggyUpdateChecker.phar https://poggit.pmmp.io/r/163495/libPiggyUpdateChecker_dev-1.phar
wget -O vendor/Commando.phar https://poggit.pmmp.io/r/162923/Commando_dev-30.phar
wget -O vendor/Commando.phar https://poggit.pmmp.io/r/216831/Commando_dev-34.phar
- name: Run PHPStan
uses: paroxity/pmmp-phpstan-action@4.21.0
uses: paroxity/pmmp-phpstan-action@5.3.0
with:
phpstan-config: phpstan.neon.dist
10 changes: 5 additions & 5 deletions .poggit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ projects:
icon: "resources/PiggyFactions-icon.png"
libs:
- src: Paroxity/Commando/Commando
version: ^3.0.0
version: ^3.1.0
- src: poggit/libasynql/libasynql
version: ^4.1.6
- src: jojoe77777/FormAPI/libFormAPI
version: ^2.1.1
version: ^4.2.0
- src: Vecnavium/FormsUI/FormsUI
version: ^1.1.3
- src: DaPigGuy/libPiggyEconomy/libPiggyEconomy
version: ^3.0.1
version: ^3.0.2
- src: DaPigGuy/libPiggyUpdateChecker/libPiggyUpdateChecker
version: ^1.0.0
lint:
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parameters:
- phar:///source/vendor/HRKChat.phar/src/
- phar:///source/vendor/ScoreHud.phar/src/
- phar:///source/vendor/Commando.phar/src/
- phar:///source/vendor/libFormAPI.phar/src/
- phar:///source/vendor/FormsUI.phar/src/
- phar:///source/vendor/libasynql.phar/src/
- phar:///source/vendor/libPiggyEconomy.phar/src/
- phar:///source/vendor/libPiggyUpdateChecker.phar/src/
Expand Down
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PiggyFactions
main: DaPigGuy\PiggyFactions\PiggyFactions
version: 2.0.4
api: 4.21.0
version: 2.1.0
api: 5.0.0
author: DaPigGuy
softdepend: [EconomyAPI, BedrockEconomy, PiggyCustomEnchants, HRKChat, ScoreHud]
website: "https://github.com/DaPigGuy/PiggyFactions"
Expand Down
5 changes: 3 additions & 2 deletions src/DaPigGuy/PiggyFactions/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\player\chat\LegacyRawChatFormatter;
use pocketmine\player\Player;

class EventListener implements Listener
Expand Down Expand Up @@ -45,11 +46,11 @@ public function onChat(PlayerChatEvent $event): void
$event->setRecipients(array_merge($faction->getOnlineMembers(), ...array_map(function (Faction $ally): array {
return $ally->getOnlineMembers();
}, $faction->getAllies())));
$event->setFormat($this->plugin->getLanguageManager()->getMessage($this->plugin->getLanguageManager()->getDefaultLanguage(), "chat.ally", $placeholders));
$event->setFormatter(new LegacyRawChatFormatter($this->plugin->getLanguageManager()->getMessage($this->plugin->getLanguageManager()->getDefaultLanguage(), "chat.ally", $placeholders)));
break;
case ChatTypes::FACTION:
$event->setRecipients($faction->getOnlineMembers());
$event->setFormat($this->plugin->getLanguageManager()->getMessage($this->plugin->getLanguageManager()->getDefaultLanguage(), "chat.faction", $placeholders));
$event->setFormatter(new LegacyRawChatFormatter($this->plugin->getLanguageManager()->getMessage($this->plugin->getLanguageManager()->getDefaultLanguage(), "chat.faction", $placeholders)));
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/DaPigGuy/PiggyFactions/PiggyFactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
use DaPigGuy\PiggyFactions\tasks\UpdatePowerTask;
use DaPigGuy\PiggyFactions\utils\PoggitBuildInfo;
use Exception;
use jojoe77777\FormAPI\Form;
use pocketmine\entity\Entity;
use pocketmine\player\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use poggit\libasynql\DataConnector;
use poggit\libasynql\libasynql;
use Vecnavium\FormsUI\Form;

class PiggyFactions extends PluginBase
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public function onEnable(): void
foreach (
[
"Commando" => BaseCommand::class,
"libformapi" => Form::class,
"FormsUI" => Form::class,
"libasynql" => libasynql::class,
"libPiggyUpdateChecker" => libPiggyUpdateChecker::class
] as $virion => $class
Expand Down
28 changes: 17 additions & 11 deletions src/DaPigGuy/PiggyFactions/claims/ClaimsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\server\CommandEvent;
use pocketmine\player\Player;
use pocketmine\world\format\Chunk;
use pocketmine\world\Position;
Expand All @@ -34,25 +34,31 @@ public function onBreak(BlockBreakEvent $event): void

public function onPlace(BlockPlaceEvent $event): void
{
if (!$this->canAffectArea($event->getPlayer(), $event->getBlock()->getPosition())) $event->cancel();
foreach($event->getTransaction()->getBlocks() as [$x, $y, $z, $block]) {
if(!$this->canAffectArea($event->getPlayer(), new Position($x, $y, $z, $event->getPlayer()->getWorld()))) {
$event->cancel();
return;
}
}
}

public function onCommandPreprocess(PlayerCommandPreprocessEvent $event): void
public function onCommand(CommandEvent $event): void
{
$player = $event->getPlayer();
$message = $event->getMessage();
$player = $event->getSender();
if(!$player instanceof Player) {
return;
}
$message = $event->getCommand();
$member = $this->plugin->getPlayerManager()->getPlayer($player);
if ($member !== null) {
$faction = $member->getFaction();
$claim = $this->manager->getClaimByPosition($player->getPosition());
if (!$member->isInAdminMode() && $claim !== null && $claim->getFaction() !== $faction) {
$relation = $faction === null ? Relations::NONE : $faction->getRelation($claim->getFaction());
if (str_starts_with($message, "/")) {
$command = substr(explode(" ", $message)[0], 1);
if (in_array($command, $this->plugin->getConfig()->getNested("factions.claims.denied-commands." . $relation, []))) {
$member->sendMessage("claims.command-denied", ["{COMMAND}" => $command, "{RELATION}" => $relation === "none" ? "neutral" : $relation]);
$event->cancel();
}
$command = substr(explode(" ", $message)[0], 1);
if (in_array($command, $this->plugin->getConfig()->getNested("factions.claims.denied-commands." . $relation, []))) {
$member->sendMessage("claims.command-denied", ["{COMMAND}" => $command, "{RELATION}" => $relation === "none" ? "neutral" : $relation]);
$event->cancel();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/DaPigGuy/PiggyFactions/commands/FactionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
use DaPigGuy\PiggyFactions\commands\subcommands\VersionSubCommand;
use DaPigGuy\PiggyFactions\PiggyFactions;
use DaPigGuy\PiggyFactions\utils\ChatTypes;
use jojoe77777\FormAPI\SimpleForm;
use pocketmine\command\CommandSender;
use pocketmine\player\Player;
use Vecnavium\FormsUI\SimpleForm;

class FactionCommand extends BaseCommand
{
Expand All @@ -66,7 +66,7 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo
{
if ($this->plugin->areFormsEnabled() && $sender instanceof Player) {
$subcommands = array_filter($this->getSubCommands(), function (BaseSubCommand $subCommand, string $alias) use ($sender): bool {
return $subCommand->getName() === $alias && $sender->hasPermission($subCommand->getPermission());
return $subCommand->getName() === $alias && count(array_filter($subCommand->getPermissions(), $sender->hasPermission(...))) > 0;
}, ARRAY_FILTER_USE_BOTH);
$form = new SimpleForm(function (Player $player, ?int $data) use ($subcommands): void {
if ($data !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use DaPigGuy\PiggyFactions\PiggyFactions;
use DaPigGuy\PiggyFactions\players\FactionsPlayer;
use DaPigGuy\PiggyFactions\utils\PiggyArgument;
use jojoe77777\FormAPI\CustomForm;
use pocketmine\command\CommandSender;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use Vecnavium\FormsUI\CustomForm;

abstract class FactionSubCommand extends BaseSubCommand
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(PiggyFactions $plugin, FactionCommand $parentCommand
public function onBasicRun(CommandSender $sender, array $args): void
{
$subcommands = array_filter($this->parentCommand->getSubCommands(), function (BaseSubCommand $subCommand, string $alias) use ($sender): bool {
return $subCommand->getName() === $alias && $sender->hasPermission($subCommand->getPermission());
return $subCommand->getName() === $alias && count(array_filter($subCommand->getPermissions(), $sender->hasPermission(...))) > 0;
}, ARRAY_FILTER_USE_BOTH);

$commandsPerPage = $sender instanceof Player ? self::COMMANDS_PER_PAGE : count($subcommands);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use DaPigGuy\PiggyFactions\factions\Faction;
use DaPigGuy\PiggyFactions\logs\LogsManager;
use DaPigGuy\PiggyFactions\players\FactionsPlayer;
use jojoe77777\FormAPI\SimpleForm;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use Vecnavium\FormsUI\SimpleForm;

class LogsSubCommand extends FactionSubCommand
{
Expand Down
2 changes: 1 addition & 1 deletion src/DaPigGuy/PiggyFactions/logs/LogsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use DaPigGuy\PiggyFactions\factions\Faction;
use DaPigGuy\PiggyFactions\language\LanguageManager;
use DaPigGuy\PiggyFactions\PiggyFactions;
use jojoe77777\FormAPI\SimpleForm;
use pocketmine\player\Player;
use Vecnavium\FormsUI\SimpleForm;

class LogsManager
{
Expand Down
2 changes: 1 addition & 1 deletion src/DaPigGuy/PiggyFactions/utils/AsciiCompass.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function getAsciiCompass(float $degrees): array

public static function getDirectionsByDegrees(float $degrees): string
{
$degrees = ($degrees - 157) % 360;
$degrees = (int)($degrees - 157) % 360;
if ($degrees < 0) $degrees += 360;

return array_keys(self::DIRECTIONS)[(int)floor($degrees / 45)];
Expand Down

0 comments on commit 5ab2604

Please sign in to comment.