This repository has been archived by the owner on Feb 6, 2022. It is now read-only.
forked from TableStudio/BanInfo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
279 additions
and
7 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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
name: "BanInfo" | ||
main: BanInfo\Loader | ||
main: TSt\BanInfo\Loader | ||
api: 3.0.1 | ||
version: 1.13.0 | ||
authors: [TableStudio Team (TSt), "WeekThor"] | ||
description: "Infromation about banned players or ips" | ||
description: "Inforamtion about banned players or ips" | ||
permissions: | ||
baninfo.commands.baninfo: | ||
description: '/bi' | ||
description: 'Acceess to command /bi' | ||
default: op | ||
baninfo.commands.banip: | ||
description: '/bi-ip' | ||
description: 'Acceess to command /bi-ip' | ||
default: op | ||
baninfo.commands.bancid: | ||
description: '/bi-cid' | ||
default: op | ||
# baninfo.commands.bancid: | ||
# description: 'Acceess to command /bi-cid' # actualy not work | ||
# default: op |
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,51 @@ | ||
<?php | ||
namespace TSt\BanInfo\APIs; | ||
|
||
use TSt\BanInfo\Loader; | ||
use pocketmine\command\Command; | ||
use pocketmine\command\PluginIdentifiableCommand; | ||
use pocketmine\plugin\Plugin; | ||
abstract class API extends Command implements PluginIdentifiableCommand{ | ||
/** @var Loader */ | ||
private $plugin; | ||
/** @var null|string */ | ||
private $consoleUsageMessage = null; | ||
/** | ||
* @param Loader $plugin | ||
* @param string $name | ||
* @param string $description | ||
* @param null|string $usageMessage | ||
* @param bool|null|string $consoleUsageMessage | ||
* @param array $aliases | ||
*/ | ||
public function __construct(Loader $plugin, $name, $description = "", $usageMessage = null, $consoleUsageMessage = null, array $aliases = []){ | ||
parent::__construct($name, $description, $usageMessage, $aliases); | ||
$this->plugin = $plugin; | ||
$this->consoleUsageMessage = $consoleUsageMessage; | ||
} | ||
/** | ||
* @return Loader | ||
*/ | ||
public final function getPlugin() : Plugin{ | ||
return $this->plugin; | ||
} | ||
/** | ||
* @return string | ||
*/ | ||
public function getConsoleUsage(){ | ||
if($this->consoleUsageMessage === null){ | ||
$message = "Usage: " . str_replace("[player]", "<player>", $this->getUsage()); | ||
}elseif(!$this->consoleUsageMessage){ | ||
$message = "[Error] Please run this command in-game"; | ||
}else{ | ||
$message = $this->consoleUsageMessage; | ||
} | ||
return $message; | ||
} | ||
/** | ||
* @return string | ||
*/ | ||
public function getUsage(): string{ | ||
return parent::getUsage(); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
namespace TSt\BanInfo\APIs; | ||
|
||
class BanInfoClass{ | ||
private $file; | ||
private $bans; | ||
public function __construct(string $file) { | ||
$this->file = $file; | ||
$this->load(); | ||
} | ||
|
||
private function load() { | ||
$bans = file_get_contents($this->file); | ||
// echo $bans; | ||
$bans = str_replace(" victim name | ban date | banned by | banned until | reason\n", '', $bans); | ||
$bans = explode("#", $bans); | ||
unset($bans[0]); | ||
unset($bans[1]); | ||
|
||
$bans = implode('#', $bans); | ||
$banslist = explode("\n", $bans); | ||
$banlist = array(); | ||
for($k = 0; $k<count($banslist); $k++){ | ||
$banedinfo = explode("|", $banslist[$k]); | ||
try{ | ||
$banlist[$banedinfo[0]] = new BannedPlayer($banedinfo[0], strtotime($banedinfo[1]), $banedinfo[2], strtotime($banedinfo[3]), $banedinfo[4]); | ||
}catch (\Exception $e){ | ||
//... | ||
} | ||
} | ||
$this->bans = $banlist; | ||
} | ||
|
||
public function get($name) : ? BannedPlayer{ | ||
$name = mb_strtolower($name, "UTF-8"); | ||
if(isset($this->bans[$name])){ | ||
return $this->bans[$name]; | ||
}else{ | ||
return null; | ||
} | ||
|
||
} | ||
} | ||
|
||
class BannedPlayer{ | ||
|
||
public $player; | ||
public $bannedDate; | ||
public $bannedBy; | ||
public $unbanDate; | ||
public $reason; | ||
|
||
public function __construct(string $name, int $date, string $admin, int $banUntil, string $reason) { | ||
$this->player = $name; | ||
$this->bannedBy = $admin; | ||
$this->bannedDate = $date; | ||
$this->reason = $reason; | ||
$this->unbanDate = $banUntil; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
namespace TSt\BanInfo\APIs; | ||
//RUSSIAN MONTH | ||
class DateFormatter{ | ||
private $month = [ | ||
'января', | ||
'февраля', | ||
'марта', | ||
'апреля', | ||
'мая', | ||
'июня', | ||
'июля', | ||
'августа', | ||
'сентября', | ||
'октября', | ||
'ноября', | ||
'декабря' | ||
]; | ||
|
||
/** | ||
* @param int $month | ||
* @return string | ||
*/ | ||
public function getMonth($month) { | ||
return $this->month[$month-1]; | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
namespace TSt\BanInfo; | ||
|
||
use TSt\BanInfo\commands\BanInfoCommand; | ||
use TSt\BanInfo\commands\BanInfoIP; | ||
use TSt\BanInfo\APIs\BanInfoClass as BanInfo; | ||
|
||
use pocketmine\plugin\PluginBase; | ||
|
||
|
||
class Loader extends PluginBase{ | ||
public function onLoad(){ | ||
$this->registerCommands(); | ||
if(!(file_exists($this->getServer()->getDataPath(). 'banned-ips.txt') and file_exists($this->getServer()->getDataPath(). 'banned-players.txt') and file_exists($this->getServer()->getDataPath(). 'banned-cids.txt'))){ | ||
$this->getServer()->getLogger()->warning("Plugin can't work on your server, sorry! Need banned-players.txt and banned-ips.txt files!"); | ||
$this->setEnabled(false); | ||
} | ||
} | ||
|
||
private function unregisterCommands(array $commands){ | ||
$commandmap = $this->getServer()->getCommandMap(); | ||
foreach($commands as $commandlabel){ | ||
$command = $commandmap->getCommand($commandlabel); | ||
$command->setLabel($commandlabel . "_disabled"); | ||
$command->unregister($commandmap); | ||
} | ||
} | ||
private function registerCommands(){ | ||
$this->unregisterCommands([ | ||
|
||
]); | ||
$this->getServer()->getCommandMap()->registerAll("BanInfo", [ | ||
new BanInfoCommand($this), | ||
new BanInfoIP($this) | ||
]); | ||
} | ||
|
||
public function getBanInfo($file) : BanInfo { | ||
return new BanInfo($file); | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
namespace TSt\BanInfo\commands; | ||
|
||
use TSt\BanInfo\Loader; | ||
use TSt\BanInfo\APIs\BanInfoClass as BanInfo; | ||
use TSt\BanInfo\APIs\API; | ||
use TSt\BanInfo\APIs\DateFormatter; | ||
use pocketmine\command\CommandSender; | ||
|
||
class BanInfoCommand extends API{ | ||
public function __construct(Loader $plugin){ | ||
parent::__construct($plugin, "baninfo", "Information about ban", "/bi <nick>", null, ["bi", "tbi"]); | ||
$this->setPermission("baninfo.commands.baninfo"); | ||
} | ||
|
||
public function execute(CommandSender $sender, $currentAlias, array $args){ | ||
$dateFormatter = new DateFormatter(); | ||
if(!$this->testPermission($sender)){ | ||
return true; | ||
} | ||
|
||
if(count($args) === 0){ | ||
$sender->sendMessage("§4Use: §c/bi <nick>"); | ||
|
||
return false; | ||
} | ||
$value = array_shift($args); | ||
$banInfoClass = new BanInfo($sender->getServer()->getDataPath() . 'banned-players.txt'); | ||
$baninfo = $banInfoClass->get($value); | ||
|
||
if($baninfo == null){ | ||
$sender->sendMessage('§4[BanInfo] §cError: player not banned.'); | ||
}else{ | ||
$date = date('j M Y H:i:s', $baninfo->bannedDate); | ||
if($baninfo->unbanDate != null){ | ||
$until = date('j M Y H:i:s', $baninfo->unbanDate); | ||
}else{ | ||
$until = "Never"; | ||
} | ||
if($baninfo->reason == ''){ | ||
$baninfo->reason = "§7(not specified)"; | ||
} | ||
$sender->sendMessage("§6--=== §c".$baninfo->player."§6 ===--\n§6Banned:§c ".$date."\n§6Banned by: §c".$baninfo->bannedBy."\n§6Ban until: §c".$until."\n§6Ban reason: §c".$baninfo->reason); | ||
} | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
namespace TSt\BanInfo\commands; | ||
|
||
use TSt\BanInfo\Loader; | ||
use TSt\BanInfo\APIs\API; | ||
use TSt\BanInfo\APIs\DateFormatter; | ||
use TSt\BanInfo\APIs\BanInfoClass as BanInfo; | ||
use pocketmine\command\CommandSender; | ||
|
||
class BanInfoIP extends API{ | ||
public function __construct(Loader $plugin){ | ||
parent::__construct($plugin, "baninfo-ip", "Information about IP ban", "/bi-ip <IP aress>", null, ["bi-ip", "tbiip", "biip"]); | ||
$this->setPermission("baninfo.commands.baninfo.ip"); | ||
} | ||
|
||
public function execute(CommandSender $sender, $currentAlias, array $args){ | ||
$dateFormatter = new DateFormatter(); | ||
if(!$this->testPermission($sender)){ | ||
return true; | ||
} | ||
|
||
if(count($args) === 0){ | ||
$sender->sendMessage("§4Use: §c/bi-ip <IP adress>"); | ||
|
||
return false; | ||
} | ||
$value = array_shift($args); | ||
$banInfoClass = new BanInfo($sender->getServer()->getDataPath() . 'banned-ips.txt'); | ||
$baninfo = $banInfoClass->get($value); | ||
|
||
if($baninfo == null){ | ||
$sender->sendMessage('§4[BanInfo] §cError: IP adress not banned!'); | ||
}else{ | ||
$date = date('j M Y H:i:s', $baninfo->bannedDate); | ||
if($baninfo->unbanDate != null){ | ||
$until = date('j M Y H:i:s', $baninfo->unbanDate); | ||
}else{ | ||
$until = "Never"; | ||
} | ||
if($baninfo->reason == ''){ | ||
$baninfo->reason = "§7(not specified)"; | ||
} | ||
$sender->sendMessage("§6--=== §c".$baninfo->player."§6 ===--\n§6Banned:§c ".$date."\n§6Banned by: §c".$baninfo->bannedBy."\n§6Ban until: §c".$until."\n§6Ban reason: §c".$baninfo->reason); | ||
} | ||
|
||
} | ||
} |