Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Updated to PM5 (#47)
Browse files Browse the repository at this point in the history
* Updated to PM5
  • Loading branch information
Superomarking authored Jul 16, 2023
1 parent a3e958e commit eade12f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 50 deletions.
8 changes: 5 additions & 3 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: NaviCompass
authors: [Vecnavium, Xenophilicy]
version: 3.0.4
version: 3.0.5
main: Xenophilicy\NaviCompass\NaviCompass
api: 4.0.0
mcpe-protocol: [527]
api: 5.0.0
mcpe-protocol: [589] #Why use this now?
description: View all your servers or worlds in a list using FormAPI!
commands:
navicompass:
Expand All @@ -12,3 +12,5 @@ commands:
permissions:
navicompass.info:
default: true
navicompass.use:
default: true
7 changes: 0 additions & 7 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ Command:
# This is the command's description shown in the command window
Description: "Open the server list!"

Permission:
# Choose whether to require players to have permission to use the command
Enabled: false

# This is the command's usage permission
Node: "navicompass.use"

Selector:
# Choose whether the selector item should be enabled
Enabled: true
Expand Down
74 changes: 37 additions & 37 deletions src/Xenophilicy/NaviCompass/NaviCompass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@
use pocketmine\event\inventory\InventoryTransactionEvent;
use pocketmine\event\Listener;
use pocketmine\event\player\{PlayerDeathEvent,
PlayerInteractEvent,
PlayerItemUseEvent,
PlayerJoinEvent,
PlayerQuitEvent,
PlayerRespawnEvent};
use pocketmine\inventory\transaction\action\{DropItemAction, SlotChangeAction};
use pocketmine\item\enchantment\{Enchantment, EnchantmentInstance, ItemFlags, Rarity};
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\network\mcpe\protocol\PlaySoundPacket;
use pocketmine\player\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat as TF;
use pocketmine\world\format\io\GlobalItemDataHandlers;
use Xenophilicy\NaviCompass\libs\jojoe77777\FormAPI\SimpleForm;
use Xenophilicy\NaviCompass\Task\CompassCooldownTask;
use Xenophilicy\NaviCompass\Task\QueryTaskCaller;
Expand Down Expand Up @@ -88,9 +87,8 @@ public function onEnable(): void {
} else {
$cmd = new PluginCommand($cmdName, $this, $this);
$cmd->setDescription(self::$settings["Command"]["Description"]);
if (self::$settings["Command"]["Permission"]["Enabled"]) {
$cmd->setPermission(self::$settings["Command"]["Permission"]["Node"]);
}
$cmd->setPermission("navicompass.use");

$this->getServer()->getCommandMap()->register("NaviCompass", $cmd, $cmdName);
}
} else {
Expand Down Expand Up @@ -348,18 +346,10 @@ private function sendActions(string $type, Player $player): void {
$player->sendTitle(self::$settings["Titles"][$type]);
}
}

public function onJoin(PlayerJoinEvent $event): void {
if (self::$settings["Selector"]["Enabled"]) {
$player = $event->getPlayer();
$item = ItemFactory::getInstance()->get(self::$settings["Selector"]["Item"]);
$item->setCustomName(self::$settings["Selector"]["Name"]);
$item->setLore([self::$settings["Selector"]["Lore"]]);
$item->addEnchantment($this->enchInst);
$slot = self::$settings["Selector"]["Slot"];
$player->getInventory()->setItem($slot, $item);
}
}

public function onJoin(PlayerJoinEvent $event) : void{
$this->giveItemToPlayer($event->getPlayer());
}

public function onQuit(PlayerQuitEvent $event): void {
$player = $event->getPlayer();
Expand All @@ -370,15 +360,17 @@ public function onQuit(PlayerQuitEvent $event): void {
}
}
}

private function isSelectorItem(Item $item): bool {
if (self::$settings["Selector"]["Enabled"]) {
if ($item->getCustomName() == self::$settings["Selector"]["Name"] && $item->getId() == self::$settings["Selector"]["Item"] && $item->getLore() == [self::$settings["Selector"]["Lore"]]) {
return true;
}
}
return false;
}

private function isSelectorItem(Item $item) : bool{
if(self::$settings["Selector"]["Enabled"]){
$savedData = GlobalItemDataHandlers::getUpgrader()->upgradeItemTypeDataInt(self::$settings["Selector"]["Item"], 0, 1, null);
$typeId = GlobalItemDataHandlers::getDeserializer()->deserializeStack($savedData)->getTypeId();
if($item->getCustomName() == self::$settings["Selector"]["Name"] && $item->getTypeId() == $typeId && $item->getLore() == [self::$settings["Selector"]["Lore"]]){
return true;
}
}
return false;
}

public function onInteract(PlayerItemUseEvent $event): void {
if (self::$settings["Selector"]["Enabled"]) {
Expand Down Expand Up @@ -419,16 +411,24 @@ public function onDeath(PlayerDeathEvent $event) {
$event->setDrops(array_diff($player->getInventory()->getContents(), [$player->getInventory()->getItem(self::$settings["Selector"]["Slot"])]));
}

public function onRespawn(PlayerRespawnEvent $event) {
if (self::$settings["Selector"]["Enabled"]) {
$player = $event->getPlayer();
$item = ItemFactory::getInstance()->get(self::$settings["Selector"]["Item"]);
$item->setCustomName(self::$settings["Selector"]["Name"]);
$item->setLore([self::$settings["Selector"]["Lore"]]);
$item->addEnchantment($this->enchInst);
$slot = self::$settings["Selector"]["Slot"];
$player->getInventory()->setItem($slot, $item, true);
}
}
public function onRespawn(PlayerRespawnEvent $event) : void{
$this->giveItemToPlayer($event->getPlayer());
}

/**
* @param Player $player
* @return void
*/
public function giveItemToPlayer(Player $player) : void{
if(self::$settings["Selector"]["Enabled"]){
$savedData = GlobalItemDataHandlers::getUpgrader()->upgradeItemTypeDataInt(self::$settings["Selector"]["Item"], 0, 1, null);
$item = GlobalItemDataHandlers::getDeserializer()->deserializeStack($savedData);
$item->setCustomName(self::$settings["Selector"]["Name"]);
$item->setLore([self::$settings["Selector"]["Lore"]]);
$item->addEnchantment($this->enchInst);
$slot = self::$settings["Selector"]["Slot"];
$player->getInventory()->setItem($slot, $item);
}
}

}
7 changes: 4 additions & 3 deletions src/Xenophilicy/NaviCompass/libs/jojoe77777/FormAPI/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use pocketmine\form\Form as IForm;
use pocketmine\player\Player;
use ReturnTypeWillChange;

/**
* Class Form
Expand Down Expand Up @@ -64,9 +65,9 @@ public function setCallable(?callable $callable) {
}

/**
* @return array|mixed
*/
public function jsonSerialize() {
* @return array
*/
#[ReturnTypeWillChange] public function jsonSerialize() : array{
return $this->data;
}
}

0 comments on commit eade12f

Please sign in to comment.