Skip to content

Commit

Permalink
Merge branch 'Dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
supercrafter333 committed Jun 21, 2021
2 parents cf72cbf + b0d3743 commit 01203b3
Show file tree
Hide file tree
Showing 23 changed files with 1,691 additions and 18 deletions.
13 changes: 13 additions & 0 deletions .changelogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@
- add Discord-Webhook Message for unbanning
- add Ban, BanEdit and Pardon Event
- Discord-Webhooks will now only send on (not cancelled) event calling
- Version bump

### Changelog V2.2.0 » V3.0.0
> This version does contain many major code changes from the previous version. This version is a very big feature-update.
- add new command: `/banip <ip> [reason: ...] [time: ...]` - Ban a Ip-Address
- add new command: `/editipban <ip> <addbantime|reducebantime> <time>` - Edit a IP-Ban
- add new command: `/pardonip <ip>` - Unban a IP-Address
- add new command: `/kick <player>` - Kick a player from the server
- add new command: `/betterban` - Open the BetterBan-Form
- add IpBan, IpBanEdit, IpPardon and Kick Event
- add Discord-Webhook Messages for the new functions
- add Forms
- when the `config.yml` is outdated, the config data will be renamed to `oldconfig.yml` and a new config.yml will be created now
- Version bump
5 changes: 4 additions & 1 deletion .poggit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ projects:
icon: "icon.gif"
virions:
- DiscordWebhookAPI
...
libs:
- src: dktapps-pm-pl/pmforms/pmforms
version: ^1.0.0
...
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
[![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg)](https://discord.gg/ca6cWPpERp)
# BetterBan - V2.2.0 [![](https://poggit.pmmp.io/shield.state/BetterBan)](https://poggit.pmmp.io/p/BetterBan) [![](https://poggit.pmmp.io/shield.dl.total/BetterBan)](https://poggit.pmmp.io/p/BetterBan)


- add random(/multi)-hubs ([#12](https://github.com/supercrafter333/theSpawn/issues/12))
- Commands are now hidden for players who are not authorized to do so ([#13](https://github.com/supercrafter333/theSpawn/issues/13))
- add new functions for random(/multi)-hubs
# BetterBan - V3.0.0 [![](https://poggit.pmmp.io/shield.state/BetterBan)](https://poggit.pmmp.io/p/BetterBan) [![](https://poggit.pmmp.io/shield.dl.total/BetterBan)](https://poggit.pmmp.io/p/BetterBan)

**Would you like to ban players for a certain period of time? Then BetterBan is just right for you! Easily ban players for a certain time and configure a bit in `config.yml`.**

I would be very happy if you leave a star for this project.

### Features
- Ban players easy per time
- Ban players and Ips easy per time
- Edit bans
- Custom Kicks
- See how often was a player banned
- See ban informations of bans
- configure something in the `config.yml`
Expand All @@ -26,6 +22,9 @@ I would be very happy if you leave a star for this project.
- [X] Edited Unban Command ([#2](https://github.com/supercrafter333/BetterBan/issues/2)) [Only maybe]
- [X] Editban Command ([#2](https://github.com/supercrafter333/BetterBan/issues/2)) [as last, later]
- [X] Events
- [X] Ip-Bans
- [X] Custom Kick
- [X] Forms

### Bugs - none
You've found a Bug?
Expand All @@ -38,11 +37,16 @@ You've found a Bug?
### Commands
|**Command**|**Description**|
|-----------|---------------|
|`/ban <player> [reason: ...] [time: ...]`|Ban a player (this overrides the PMMP Ban commmand)|
|`/ban <player> [reason: ...] [time: ...]`|Ban a player|
|`/banlog <player>`|See the ban-count of an player|
|`/baninfo <player>`|See ban informations for a player|
|`/editban <player> <addbantime/reducebantime> <time>`|Edit a ban of a player|
|`/pardon <player>`|Unban a player|
|`/ban-ip <ip> [reason: ...] [time: ...]`|Ban a ip|
|`/editipban <ip> <addbantime/reducebantime> <time>`|Edit a Ip-Ban|
|`/pardon-ip <ip>`|Unban a ip|
|`/kick <player>`|Kick a player|
|`/betterban`|Open the BetterBan-Form|

### License:
This Pluginis licensed under the [Apache License 2.0](/LICENSE)! Plugin by supercrafter333!
Expand Down
5 changes: 4 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: BetterBan
version: 2.2.0
version: 3.0.0
api: 3.0.0
main: supercrafter333\BetterBan\BetterBan
author: supercrfafter333
Expand All @@ -15,5 +15,8 @@ permissions:
description: Command permission
default: op
BetterBan.baninfo.cmd:
description: Command permission
default: op
BetterBan.editipban.cmd:
description: Command permission
default: op
34 changes: 33 additions & 1 deletion resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@
# Configuration

# Messages
#ban
kick-message: "Banned by admin."
kick-message-with-reason: "Banned by admin. Reason: {reason}"
kick-message-with-time: "Banned by admin. {line} Reason: {reason} {line} Ends at: {time}"
kick-ip-message: "IP Banned."
kick-ip-message-with-reason: "IP Banned. Reason: {reason}"
kick-ip-message-with-time: "IP Banned. {line} Reason: {reason} {line} Ends at: {time}"
banlog-message-log: "§eBans of player §7{name}§e: §b{log}"
baninfo-message-list: "§7---====§eBan Informations of §b{name}§7====---{line}§7source: §b{source}{line}§7reason: §b{reason}{line}§7date: §b{date}{line}§7log: §b{log}{line}§7---====§eBan Informations of §b{name}§7====---"
#kick
kicked-message: "Kicked by admin."
kicked-with-reason-message: "Kicked by admin.{line}Reason: {reason}"

# Error messages
use-DateInterval-format: "§4Please use the the right format!§4 For example: §81d"
error-not-banned: "§4The player called §7{name}§4 isn't banned!"
error-not-ipbanned: "§4The player called §7{name}§4 isn't banned!"
error-no-tempban-found: "§4The player called §7{name}§4 isn't temp banned!"
error-no-iptempban-found: "§4The player called §7{name}§4 isn't temp banned!"

# Discord Webhook Settings
use-discord: "false"
Expand All @@ -35,6 +44,29 @@ pardon-message: "The player `{target}` was unbanned by `{source}`!"
#Colors: https://gist.github.com/thomasbnt/b6f455e2c7d743b796917fa3c205f812
pardon-color: 3066993

# Ip-Ban
banip-title: "Ip-Ban!"
banip-message: "The ip `{ip}` was banned by `{source}`!"
#Colors: https://gist.github.com/thomasbnt/b6f455e2c7d743b796917fa3c205f812
banip-color: 15158332
# Ip-Ban Updated
ipban-updated-title: "Ip-Ban Updated!"
ipban-updated-message: "The ban of the ip {ip} was updated!"
#Colors: https://gist.github.com/thomasbnt/b6f455e2c7d743b796917fa3c205f812
ipban-updated-color: 16776960

# Ip-Pardon / Ip-Unban
pardonip-title: "IP Unbanned!"
pardonip-message: "The ip `{ip}` was unbanned by `{source}`!"
#Colors: https://gist.github.com/thomasbnt/b6f455e2c7d743b796917fa3c205f812
pardonip-color: 3066993

# Kick
kick-dc-title: "Kick!"
kick-dc-message: "The player `{target}` was kicked by `{source}`!"
#Colors: https://gist.github.com/thomasbnt/b6f455e2c7d743b796917fa3c205f812
kick-dc-color: 16776960


#don't change this
version: "2.2.0"
version: "3.0.0"
148 changes: 141 additions & 7 deletions src/supercrafter333/BetterBan/BetterBan.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
use CortexPE\DiscordWebhookAPI\Message;
use CortexPE\DiscordWebhookAPI\Webhook;
use DateInterval;
use dktapps\pmforms\BaseForm;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use supercrafter333\BetterBan\Commands\BanCommand;
use supercrafter333\BetterBan\Commands\BaninfoCommand;
use supercrafter333\BetterBan\Commands\BanIpCommand;
use supercrafter333\BetterBan\Commands\BanlogCommand;
use supercrafter333\BetterBan\Commands\BetterBanCommand;
use supercrafter333\BetterBan\Commands\EditbanCommand;
use supercrafter333\BetterBan\Commands\EditipbanCommand;
use supercrafter333\BetterBan\Commands\KickCommand;
use supercrafter333\BetterBan\Commands\PardonCommand;
use supercrafter333\BetterBan\Commands\PardonIpCommand;

/**
* Class BetterBan
Expand All @@ -22,36 +28,65 @@ class BetterBan extends PluginBase
{

/**
* @var
* @var self
*/
protected static $instance;

public const VERSION = "2.2.0";
/**
* Version of BetterBan
*/
public const VERSION = "3.0.0";

/**
* @var null
*/
public static $DISCORD_WEBHOOK_URL = null;

/**
* On Plugin Loading
*/
public function onLoad()
{
self::$instance = $this;
$this->saveResource("config.yml");
$this->versionCheck(self::VERSION);
if (!class_exists(BaseForm::class)) {
$this->getLogger()->error("pmforms missing!! Please download BetterBan from Poggit!");
}
if (!class_exists(Webhook::class)) {
$this->getLogger()->error("DiscordWebhookAPI missing!! Please download BetterBan from Poggit!");
}
$dc_webhook = $this->getConfig()->get("discord-webhook") !== "" ? $this->getConfig()->get("discord-webhook") : null;
self::$DISCORD_WEBHOOK_URL = $dc_webhook;
}

/**
* On Plugin Enabling
*/
public function onEnable()
{
$cmdMap = $this->getServer()->getCommandMap();
$pmmpBanCmd = $cmdMap->getCommand("ban");
$pmmpPardonCmd = $cmdMap->getCommand("pardon");
$pmmpBanIpCmd = $cmdMap->getCommand("ban-ip");
$pmmpPardonIpCmd = $cmdMap->getCommand("pardon-ip");
$pmmpKickCmd = $cmdMap->getCommand("kick");
$cmdMap->unregister($pmmpBanCmd);
$cmdMap->unregister($pmmpPardonCmd);
$cmdMap->unregister($pmmpBanIpCmd);
$cmdMap->unregister($pmmpPardonIpCmd);
$cmdMap->unregister($pmmpKickCmd);
$cmdMap->registerAll("BetterBan", [
new BanCommand("ban"),
new BanlogCommand("banlog"),
new BaninfoCommand("baninfo"),
new EditbanCommand("editban"),
new PardonCommand("pardon")
new PardonCommand("pardon"),
new BanIpCommand("banip"),
new EditipbanCommand("editipban"),
new PardonIpCommand("pardonip"),
new KickCommand("kick"),
new BetterBanCommand("betterban")
]);
$this->getServer()->getPluginManager()->registerEvents(new EventListener(), $this);
}
Expand All @@ -69,12 +104,11 @@ public static function getInstance(): self
*/
private function versionCheck($version)
{
if (!$this->getConfig()->exists("version") || !$this->getConfig()->get("version") == $version) {
if (!$this->getConfig()->exists("version") || $this->getConfig()->get("version") !== $version) {
$this->getLogger()->debug("OUTDATED CONFIG.YML!! You config.yml is outdated! Your config.yml will automatically updated!");
unlink($this->getConfig()->getPath());
rename($this->getDataFolder() . "config.yml", $this->getDataFolder() . "oldConfig.yml");
$this->saveResource("config.yml");
$this->getConfig()->reload();
$this->getLogger()->debug("confg.yml Updated for version: §b$version");
$this->getLogger()->debug("config.yml Updated for version: §b$version");
}
}

Expand Down Expand Up @@ -266,6 +300,11 @@ public function stringToTimestampReduce(string $string, \DateTime $time): ?array
return [$t, ltrim(str_replace($found[0], "", $string))];
}

/**
* @param string $banned
* @param string $source
* @param string $reason
*/
public function sendBanMessageToDC(string $banned, string $source, string $reason)
{
$title = str_replace(["{banned}", "{source}", "{reason}", "{line}"], [$banned, $source, $reason, "\n"], $this->getConfig()->get("ban-title"));
Expand All @@ -284,6 +323,9 @@ public function sendBanMessageToDC(string $banned, string $source, string $reaso
}
}

/**
* @param string $banned
*/
public function sendBanUpdatedMessageToDC(string $banned)
{
$title = str_replace(["{banned}", "{line}"], [$banned, "\n"], $this->getConfig()->get("ban-updated-title"));
Expand All @@ -302,6 +344,10 @@ public function sendBanUpdatedMessageToDC(string $banned)
}
}

/**
* @param string $target
* @param string $source
*/
public function sendPardonMessageToDC(string $target, string $source)
{
$title = str_replace(["{target}", "{source}", "{line}"], [$target, $source, "\n"], $this->getConfig()->get("pardon-title"));
Expand All @@ -319,4 +365,92 @@ public function sendPardonMessageToDC(string $target, string $source)
$webhook->send($msg);
}
}

/**
* @param string $ip
* @param string $source
* @param string $reason
*/
public function sendIpBanMessageToDC(string $ip, string $source, string $reason)
{
$title = str_replace(["{ip}", "{source}", "{reason}", "{line}"], [$ip, $source, $reason, "\n"], $this->getConfig()->get("banip-title"));
$message = str_replace(["{ip}", "{source}", "{reason}", "{line}"], [$ip, $source, $reason, "\n"], $this->getConfig()->get("banip-message"));
$color = $this->getConfig()->get("banip-color");
if ($this->getConfig()->get("use-discord") == "true" && self::$DISCORD_WEBHOOK_URL !== null) {
$webhook = new Webhook(self::$DISCORD_WEBHOOK_URL);
$msg = new Message();
$embed = new Embed();
$embed->setTitle($title);
$embed->setDescription($message);
$embed->setColor($color);
$embed->setTimestamp(new \DateTime('now'));
$msg->addEmbed($embed);
$webhook->send($msg);
}
}

/**
* @param string $ip
*/
public function sendIpBanUpdatedMessageToDC(string $ip)
{
$title = str_replace(["{ip}", "{line}"], [$ip, "\n"], $this->getConfig()->get("ipban-updated-title"));
$message = str_replace(["{ip}", "{line}"], [$ip, "\n"], $this->getConfig()->get("ipban-updated-message"));
$color = $this->getConfig()->get("ipban-updated-color");
if ($this->getConfig()->get("use-discord") == "true" && self::$DISCORD_WEBHOOK_URL !== null) {
$webhook = new Webhook(self::$DISCORD_WEBHOOK_URL);
$msg = new Message();
$embed = new Embed();
$embed->setTitle($title);
$embed->setDescription($message);
$embed->setColor($color);
$embed->setTimestamp(new \DateTime('now'));
$msg->addEmbed($embed);
$webhook->send($msg);
}
}

/**
* @param string $ip
* @param string $source
*/
public function sendPardonIpMessageToDC(string $ip, string $source)
{
$title = str_replace(["{ip}", "{source}", "{line}"], [$ip, $source, "\n"], $this->getConfig()->get("pardonip-title"));
$message = str_replace(["{ip}", "{source}", "{line}"], [$ip, $source, "\n"], $this->getConfig()->get("pardonip-message"));
$color = $this->getConfig()->get("pardonip-color");
if ($this->getConfig()->get("use-discord") == "true" && self::$DISCORD_WEBHOOK_URL !== null) {
$webhook = new Webhook(self::$DISCORD_WEBHOOK_URL);
$msg = new Message();
$embed = new Embed();
$embed->setTitle($title);
$embed->setDescription($message);
$embed->setColor($color);
$embed->setTimestamp(new \DateTime('now'));
$msg->addEmbed($embed);
$webhook->send($msg);
}
}

/**
* @param string $target
* @param string $source
*/
public function sendKickMessageToDC(string $target, string $source)
{
$title = str_replace(["{target}", "{source}", "{line}"], [$target, $source, "\n"], $this->getConfig()->get("kick-dc-title"));
$message = str_replace(["{target}", "{source}", "{line}"], [$target, $source, "\n"], $this->getConfig()->get("kick-dc-message"));
$color = $this->getConfig()->get("kick-dc-color");
if ($this->getConfig()->get("use-discord") == "true" && self::$DISCORD_WEBHOOK_URL !== null) {
$webhook = new Webhook(self::$DISCORD_WEBHOOK_URL);
$msg = new Message();
$embed = new Embed();
$embed->setTitle($title);
$embed->setDescription($message);
$embed->setColor($color);
$embed->setTimestamp(new \DateTime('now'));
$msg->addEmbed($embed);
$webhook->send($msg);
}
}
}
Loading

0 comments on commit 01203b3

Please sign in to comment.