This repository has been archived by the owner on Mar 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 1.0.0 existed also, but it was private
- Loading branch information
1 parent
007c18c
commit 5381761
Showing
5 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (©) 2016 kvetinac97 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this plugin and associated documentation files (the "Plugin"), to deal | ||
in the Plugin without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Plugin is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Plugin. | ||
|
||
THE PLUGIN IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
PLUGIN. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# LinkSlots | ||
Link Slots of all your servers! | ||
LinkSlots v1.1.0 for ImagicalMine | ||
=================================== | ||
- All plugin rights reserved © kvetinac97 2016 | ||
- All MinecraftQuery rights reserved © xPaw 2015, edited by kvetinac97 | ||
|
||
Link Slots of all your servers - just write IP:port into config! | ||
Supports unlimited server count! | ||
|
||
MinecraftQuery part is located at http://queryapi.minetox.cz, | ||
so the whole plugin copyright is by © kvetinac97 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: LinkSlots | ||
author: kvetinac97 | ||
version: 1.1.0 | ||
api: ["2.0.0"] | ||
main: kvetinac97\Main | ||
description: "Link slots of all your servers!" | ||
load: STARTUP | ||
commands: [] | ||
permissions: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#Config version, do not change this | ||
version: 1 | ||
|
||
#Write interval to refresh the query (in minutes) | ||
interval: 3 | ||
|
||
#Do you want to add the server this plugin is running on slots? | ||
add_self_slots: true | ||
|
||
#Write your server IPs and ports like this: | ||
|
||
# server.myip.com: 19132 | ||
#WARNING!!! If you write IP like this: | ||
#server.myip.com:19132, plugin won't crash, but it won't change slots | ||
|
||
servers: | ||
"play.example.com": 19132 | ||
"my.server.net": 19754 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace kvetinac97; | ||
|
||
use pocketmine\event\Listener; | ||
use pocketmine\event\server\QueryRegenerateEvent; | ||
use pocketmine\plugin\PluginBase; | ||
use pocketmine\scheduler\Task; | ||
use pocketmine\utils\Config; | ||
|
||
class Main extends PluginBase implements Listener { | ||
|
||
/** @var Config $config */ | ||
public $config; | ||
|
||
/** @var int $players */ | ||
public $players = 0; | ||
/** @var int $maxPlayers */ | ||
public $maxPlayers = 0; | ||
|
||
public function onEnable() { | ||
$this->getLogger()->info("§bLinkSlots §aENABLED!"); | ||
$this->getLogger()->info("§7Running version §e1.1.0..."); | ||
$this->saveDefaultConfig(); | ||
$this->config = new Config($this->getDataFolder()."config.yml", Config::YAML); | ||
$this->getServer()->getPluginManager()->registerEvents($this, $this); | ||
$this->setPlayers(); | ||
$this->getServer()->getScheduler()->scheduleRepeatingTask(new RefreshTask($this), $this->config->get("interval")*60*20); | ||
} | ||
|
||
public function onDisable() { | ||
$this->getLogger()->info("§bLinkSlots §cDISABLED!"); | ||
} | ||
|
||
|
||
public function setPlayers($task = false){ | ||
$this->players = 0; | ||
$this->maxPlayers = 0; | ||
if (!$task && ($this->config->get("servers") === [] || !$this->config->get("servers"))){ | ||
$this->getLogger()->critical("§4Could not load plugin: you haven't set any servers to config.yml!"); | ||
$this->getLogger()->warning("§cDisabling §bLinkSlots..."); | ||
$this->getServer()->getPluginManager()->disablePlugin($this); | ||
} | ||
foreach ($this->config->get("servers") as $ip => $port){ | ||
/** @var int $onl */ | ||
$onl = file_get_contents("http://queryapi.minetox.cz/online.php?ip=$ip&port=$port"); | ||
/** @var int $max */ | ||
$max = file_get_contents("http://queryapi.minetox.cz/maxonline.php?ip=$ip&port=$port"); | ||
if ($onl == -1 || $max == -1){ | ||
if (!$task){ | ||
$this->getLogger()->warning("§cCould not connect to §e$ip:§b$port; §cThe server is offline"); | ||
} | ||
continue; | ||
} | ||
$this->players += $onl; | ||
$this->maxPlayers += $max; | ||
} | ||
if ($this->config->get("add_self_slots") == "true"){ | ||
$this->players += \count($this->getServer()->getOnlinePlayers()); | ||
$this->maxPlayers += $this->getServer()->getMaxPlayers(); | ||
} | ||
} | ||
|
||
public function onQuery(QueryRegenerateEvent $e){ | ||
$e->setPlayerCount($this->players); | ||
$e->setMaxPlayerCount($this->maxPlayers); | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
class RefreshTask extends Task{ | ||
|
||
public $plugin; | ||
|
||
public function __construct(Main $plugin){ | ||
$this->plugin = $plugin; | ||
} | ||
|
||
public function onRun($currentTick) { | ||
$this->plugin->setPlayers(true); | ||
} | ||
} |