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

Commit

Permalink
Merge pull request #31 from Xenophilicy/PM4
Browse files Browse the repository at this point in the history
Merging API 4.0.0 into master.
  • Loading branch information
Vecnavium committed Dec 5, 2021
2 parents 0132576 + 7992f32 commit 1ad8fc3
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 198 deletions.
1 change: 0 additions & 1 deletion .poggit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
build-by-default: true
branches:
- master
- PM4
projects:
NaviCompass:
path: ""
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
<a href="https://discord.gg/6M9tGyWPjr"><img src="https://img.shields.io/discord/837701868649709568?label=discord&color=7289DA&logo=discord" alt="Discord" /></a>
</p>

This plugin uses FormAPI to easily display your servers and worlds listed in a simple interface. It's easy, all you need to do is enter your IPs and ports of the servers or the names of your worlds you would like to add, along with a label to show up as the name in the UI, all inside the config.yml file. After that, the plugin will do the rest and you're good to go! Players will either have option to interact with the selector item, or type your custom command in chat to access the UI. You also have the option to play sounds and show titles to the players during different events in the plugin! All of these things can also be customized in the config.yml file. Server networks simplified!

### **NaviCompass now supports the WaterDog MCBE proxy!**

***
Expand Down
9 changes: 5 additions & 4 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: NaviCompass
author: [Vecnavium, Xenophilicy]
version: 2.3.7
authors: [Vecnavium, Xenophilicy]
version: 2.3.6
main: Xenophilicy\NaviCompass\NaviCompass
api: 3.0.0
api: 4.0.0
mcpe-protocol: [471]
description: View all your servers or worlds in a list using FormAPI!
commands:
navicompass:
description: Get info on NaviCompass
permission: navicompass.info
permissions:
navicompass.info:
default: true
default: true
222 changes: 112 additions & 110 deletions src/Xenophilicy/NaviCompass/NaviCompass.php

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions src/Xenophilicy/NaviCompass/Task/CompassCooldownTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Xenophilicy\NaviCompass\Task;

use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\scheduler\Task;
use Xenophilicy\NaviCompass\NaviCompass;

Expand All @@ -25,25 +25,24 @@
*/
class CompassCooldownTask extends Task {

private $plugin;
private $player;
private NaviCompass $plugin;
private Player $player;

/**
* CompassCooldownTask constructor.
* @param NaviCompass $plugin
* @param Player $player
*/
public function __construct(NaviCompass $plugin, Player $player){
public function __construct(NaviCompass $plugin, Player $player) {
$this->plugin = $plugin;
$this->player = $player;
}

/**
* Actions to execute when run
* @param int $currentTick
* @return void
*/
public function onRun(int $currentTick){
public function onRun(): void {
unset($this->plugin->compassCooldown[$this->player->getName()]);
}
}
25 changes: 11 additions & 14 deletions src/Xenophilicy/NaviCompass/Task/QueryTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@
*/
class QueryTask extends AsyncTask {

private $host;
private $port;
private $timeout;
private string $host;
private int $port;
private int $timeout;

/**
* QueryTask constructor.
* @param string $host
* @param int $port
*/
public function __construct(string $host, int $port){
public function __construct(string $host, int $port) {
$this->host = $host;
$this->port = $port;
$this->timeout = NaviCompass::$settings["Timeout"];
}

public function onRun(){
public function onRun(): void {
$queryServer = $this->sendQuery($this->host, $this->port);
$status = $queryServer === null ? 'offline' : 'online';
if($status == "online" && count($queryServer) >= 16){
if($status == "online" && count($queryServer) >= 16) {
$this->setResult(["online", $queryServer[15], $queryServer[17]]);
}else{
} else {
$this->setResult(["offline", 0, 0]);
}
}
Expand All @@ -55,9 +55,9 @@ public function onRun(){
/**
* @param string $host
* @param int $port
* @return false|string[]|null
* @return array|null
*/
private function sendQuery(string $host, int $port){
private function sendQuery(string $host, int $port) {
$socket = @fsockopen("udp://" . $host, $port);
if(!$socket) return null;
stream_set_timeout($socket, (int)$this->timeout);
Expand All @@ -80,11 +80,8 @@ private function sendQuery(string $host, int $port){
@fclose($socket);
return $response;
}

/**
* @param Server $server
*/
public function onCompletion(Server $server){

public function onCompletion(): void {
NaviCompass::getPlugin()->queryTaskCallback($this->getResult(), $this->host, $this->port);
}
}
15 changes: 6 additions & 9 deletions src/Xenophilicy/NaviCompass/Task/QueryTaskCaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,23 @@
*/
class QueryTaskCaller extends Task {

private $plugin;
private $host;
private $port;
private NaviCompass $plugin;
private string $host;
private int $port;

/**
* QueryTaskCaller constructor.
* @param NaviCompass $plugin
* @param string $host
* @param int $port
*/
public function __construct(NaviCompass $plugin, string $host, int $port){
public function __construct(NaviCompass $plugin, string $host, int $port) {
$this->plugin = $plugin;
$this->host = $host;
$this->port = $port;
}

/**
* @param int $currentTick
*/
public function onRun(int $currentTick){

public function onRun(): void {
$this->plugin->getServer()->getAsyncPool()->submitTask(new QueryTask($this->host, $this->port));
}
}
37 changes: 17 additions & 20 deletions src/Xenophilicy/NaviCompass/Task/TeleportTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

namespace Xenophilicy\NaviCompass\Task;

use pocketmine\command\ConsoleCommandSender;
use pocketmine\console\ConsoleCommandSender;
use pocketmine\network\mcpe\protocol\ScriptCustomEventPacket;
use pocketmine\Player;
use pocketmine\network\mcpe\protocol\TransferPacket;
use pocketmine\player\Player;
use pocketmine\scheduler\Task;
use pocketmine\utils\Binary;
use Xenophilicy\NaviCompass\NaviCompass;
Expand All @@ -28,10 +29,10 @@
*/
class TeleportTask extends Task {

private $plugin;
private $cmdString;
private $player;
private $waterdog;
private NaviCompass $plugin;
private string $cmdString;
private Player $player;
private bool $waterdog;

/**
* TeleportTask constructor.
Expand All @@ -40,28 +41,24 @@ class TeleportTask extends Task {
* @param Player $player
* @param bool $waterdog
*/
public function __construct(NaviCompass $plugin, string $cmdString, Player $player, bool $waterdog = false){
public function __construct(NaviCompass $plugin, string $cmdString, Player $player, bool $waterdog = false) {
$this->plugin = $plugin;
$this->cmdString = $cmdString;
$this->player = $player;
$this->waterdog = $waterdog;
}

/**
* @param int $currentTick
*/
public function onRun(int $currentTick){
if($this->waterdog){
$pk = new ScriptCustomEventPacket();
$pk->eventName = "bungeecord:main";
$pk->eventData = Binary::writeShort(strlen("Connect")) . "Connect" . Binary::writeShort(strlen($this->cmdString)) . $this->cmdString;
$this->player->sendDataPacket($pk);

public function onRun(): void {
if($this->waterdog) {
$pk = new TransferPacket();
$pk->address = $this->cmdString;
$this->player->getNetworkSession()->sendDataPacket($pk);
return;
}
if(strtolower(NaviCompass::$settings["World-CMD-Mode"]) == "player"){
if(strtolower(NaviCompass::$settings["World-CMD-Mode"]) == "player") {
$this->plugin->getServer()->getCommandMap()->dispatch($this->player, $this->cmdString);
}else if(strtolower(NaviCompass::$settings["World-CMD-Mode"]) == "console"){
$this->plugin->getServer()->getCommandMap()->dispatch(new ConsoleCommandSender(), $this->cmdString);
} else if(strtolower(NaviCompass::$settings["World-CMD-Mode"]) == "console") {
$this->plugin->getServer()->getCommandMap()->dispatch(new ConsoleCommandSender($this->plugin->getServer(), $this->plugin->getServer()->getLanguage()), $this->cmdString);
}
}
}
19 changes: 8 additions & 11 deletions src/Xenophilicy/NaviCompass/Task/TransferTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Xenophilicy\NaviCompass\Task;

use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\scheduler\Task;

/**
Expand All @@ -24,26 +24,23 @@
*/
class TransferTask extends Task {

private $host;
private $port;
private $player;
private string $host;
private int $port;
private Player $player;

/**
* TransferTask constructor.
* @param string $host
* @param int $port
* @param Player $player
*/
public function __construct(string $host, int $port, Player $player){
public function __construct(string $host, string $port, Player $player) {
$this->host = $host;
$this->port = $port;
$this->port = (int)$port;
$this->player = $player;
}

/**
* @param int $currentTick
*/
public function onRun(int $currentTick){

public function onRun(): void {
$this->player->transfer($this->host, $this->port);
}
}
20 changes: 10 additions & 10 deletions src/Xenophilicy/NaviCompass/libs/jojoe77777/FormAPI/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Xenophilicy\NaviCompass\libs\jojoe77777\FormAPI;

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

/**
* Class Form
Expand All @@ -14,14 +14,14 @@
abstract class Form implements IForm {

/** @var array */
protected $data = [];
protected array $data = [];
/** @var callable */
private $callable;

/**
* @param callable $callable
* @param callable|null $callable
*/
public function __construct(?callable $callable){
public function __construct(?callable $callable) {
$this->callable = $callable;
}

Expand All @@ -30,15 +30,15 @@ public function __construct(?callable $callable){
* @see Player::sendForm()
* @deprecated
*/
public function sendToPlayer(Player $player): void{
public function sendToPlayer(Player $player): void {
$player->sendForm($this);
}

/**
* @param Player $player
* @param mixed $data
*/
public function handleResponse(Player $player, $data): void{
public function handleResponse(Player $player, $data): void {
$this->processData($data);
$callable = $this->getCallable();
if($callable !== null){
Expand All @@ -49,24 +49,24 @@ public function handleResponse(Player $player, $data): void{
/**
* @param $data
*/
public function processData(&$data): void{
public function processData(&$data): void {
}

public function getCallable(): ?callable{
public function getCallable(): ?callable {
return $this->callable;
}

/**
* @param callable|null $callable
*/
public function setCallable(?callable $callable){
public function setCallable(?callable $callable) {
$this->callable = $callable;
}

/**
* @return array|mixed
*/
public function jsonSerialize(){
public function jsonSerialize() {
return $this->data;
}
}
Loading

0 comments on commit 1ad8fc3

Please sign in to comment.