Skip to content

Commit

Permalink
Fixed a bug related to /sp command and API bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavius12 committed Feb 23, 2018
1 parent 5a1f19a commit ec68eb2
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 118 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,22 @@ PocketMine-MP plugins

## Requirements

PocketMine-MP 1.7dev API 3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9, 3.0.0-ALPHA10
PocketMine-MP 1.7dev API 3.0.0-ALPHA7 -> 3.0.0-ALPHA11

## Overview

**Broadcaster** is an advanced Broadcasting plugin for PocketMine-MP.
With Broadcaster you can set custom message, popup and title broadcasts. You can also send messages with /sm, popups with /sp and titles with /st commands.
This plugin let you also customize colors (you can use the & sign instead of § for text format), prefixes, suffixes and intervals.

**EvolSoft Website:** https://www.evolsoft.tk

***This Plugin uses the New API. You can't install it on old versions of PocketMine.***

With Broadcaster you can set custom message/popup and title broadcasts. You can also send messages with /sm, send popups with /sp and send titles with /st commands.<br>
You can also customize colors, prefixes, suffixes and intervals. You can use the & sign instead of §.

**Commands:**

<dd><i><b>/broadcaster</b> - Broadcaster commands</i></dd>
<dd><i><b>/sendmessage</b> - Send message to the specified player (* for all players)</i></dd>
<dd><i><b>/sendpopup</b> - Send popup to the specified player (* for all players)</i></dd>
<dd><i><b>/sendtitle</b> - Send title to the specified player (* for all players)</i></dd>
<br>

## Donate

Support the development of this plugin with a small donation by clicking [:dollar: here](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&[email protected]&lc=US&item_name=www.evolsoft.tk&no_note=0&cn=&curency_code=EUR&bn=PP-DonationsBF:btn_donateCC_LG.gif:NonHosted). Thank you :smile:
Please support the development of this plugin with a small donation by clicking [:dollar: here](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&[email protected]&lc=US&item_name=www.evolsoft.tk&no_note=0&cn=&curency_code=EUR&bn=PP-DonationsBF:btn_donateCC_LG.gif:NonHosted).
Your small donation will help me paying web hosting, domains, buying programs (such as IDEs, debuggers, etc...) and new hardware to improve software development. Thank you :smile:

## Documentation

Expand Down
7 changes: 5 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Broadcaster
main: Broadcaster\Broadcaster
version: 1.2
api: [3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9, 3.0.0-ALPHA10]
version: 1.3
api: [3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9, 3.0.0-ALPHA10, 3.0.0-ALPHA11]
load: STARTUP
author: EvolSoft
description: Advanced Broadcasting plugin
Expand Down Expand Up @@ -34,6 +34,9 @@ permissions:
broadcaster.reload:
default: op
description: Let player reload Broadcaster.
broadcaster.update:
default: op
description: Let player update Broadcaster.
broadcaster.sendmessage:
default: op
description: Let player send messages to players with /sendmessage command.
Expand Down
75 changes: 50 additions & 25 deletions src/Broadcaster/Broadcaster.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?php

/*
* Broadcaster (v1.2) by EvolSoft
* Broadcaster (v1.3) by EvolSoft
* Developer: EvolSoft (Flavius12)
* Website: https://www.evolsoft.tk
* Date: 13/01/2018 04:00 PM (UTC)
* Date: 01/02/2018 01:09 PM (UTC)
* Copyright & License: (C) 2014-2018 EvolSoft
* Licensed under MIT (https://github.com/EvolSoft/Broadcaster/blob/master/LICENSE)
*/

namespace Broadcaster;

use Broadcaster\Tasks\PopupDurationTask;

use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat;
use pocketmine\scheduler\TaskHandler;
use pocketmine\utils\TextFormat;

class Broadcaster extends PluginBase {

/** @var string */
const PREFIX = "&9[&eBroadcaster&9] ";

/** @var string */
const API_VERSION = "1.0";
const API_VERSION = "2.0";

/** @var int */
const TYPE_MESSAGE = 0;
Expand All @@ -33,24 +33,25 @@ class Broadcaster extends PluginBase {

/** @var int */
const TYPE_TITLE = 2;

/** @var array */
public $cfg;

/** @var TaskHandler */
public $mtask;
private $mtask;

/** @var TaskHandler */
public $ptask;
private $ptask;

/** @var TaskHandler */
public $ttask;
private $ttask;

/** @var array */
public $cfg;

/** @var Broadcaster $instance */
/** @var Broadcaster */
private static $instance = null;

/**
* Translate Minecraft colors
*
* @param string $symbol
* @param string $message
*
Expand Down Expand Up @@ -115,8 +116,6 @@ public function replaceVars($str, array $vars){
return $str;
}

//API Functions

/**
* Get Broadcaster API
*
Expand All @@ -132,7 +131,7 @@ public static function getAPI(){
* @return string
*/
public function getVersion(){
return $this->getVersion();
return $this->getDescription()->getVersion();
}

/**
Expand All @@ -144,6 +143,18 @@ public function getAPIVersion(){
return self::API_VERSION;
}

/**
* Reload Broadcaster configuration
*/
public function reload(){
$this->reloadConfig();
$this->cfg = $this->getConfig()->getAll();
$this->mtask->remove();
$this->ptask->remove();
$this->ttask->remove();
$this->initTasks();
}

/**
* Initialize Broadcaster tasks
*/
Expand All @@ -158,7 +169,7 @@ public function initTasks(){
}
if($this->cfg["title-broadcast"]["enabled"]){
$ttime = intval($this->cfg["title-broadcast"]["time"]) * 20;
$this->ttask = $this->getServer()->getScheduler()->scheduleRepeatingTask(new Tasks\TitleTask($this), $mtime);
$this->ttask = $this->getServer()->getScheduler()->scheduleRepeatingTask(new Tasks\TitleTask($this), $ttime);
}
}

Expand All @@ -182,12 +193,12 @@ public function formatMessage($message){
/**
* Broadcast message, popup or title
*
* @param Player $recipient
* @param int $type
* @param string $sender
* @param string $message
* @param Player $recipient
*/
public function broadcast(Player $recipient, int $type, $sender, $message){
public function broadcast(int $type, $sender, $message, Player $recipient = null){
switch($type){
default:
case self::TYPE_MESSAGE:
Expand Down Expand Up @@ -216,15 +227,29 @@ public function broadcast(Player $recipient, int $type, $sender, $message){
switch($type){
default:
case self::TYPE_MESSAGE:
$recipient->sendMessage($this->translateColors("&", $msg));
break;
if($recipient){
$recipient->sendMessage($this->translateColors("&", $msg));
return;
}
foreach($this->getServer()->getOnlinePlayers() as $player){
$player->sendMessage($this->translateColors("&", str_replace("{PLAYER}", $player->getName(), $msg)));
}
return;
case self::TYPE_POPUP:
$this->getServer()->getScheduler()->scheduleTask(new PopupDurationTask($this, $msg, $recipient, $this->cfg["popup-broadcast"]["duration"]));
break;
$this->getServer()->getScheduler()->scheduleTask(new Tasks\PopupDurationTask($this, $msg, $recipient, $this->cfg["popup-broadcast"]["duration"]));
return;
case self::TYPE_TITLE:
$msg = explode("{SUBTITLE}", $msg);
$recipient->addTitle($this->translateColors("&", $msg[0]), isset($msg[1]) ? $this->translateColors("&", $msg[1]) : "");
break;
if($recipient){
$msg = explode("{SUBTITLE}", $msg);
$recipient->addTitle($this->translateColors("&", $msg[0]), isset($msg[1]) ? $this->translateColors("&", $msg[1]) : "");
return;
}
foreach($this->getServer()->getOnlinePlayers() as $player){
$out = str_replace("{PLAYER}", $player->getName(), $msg);
$out = explode("{SUBTITLE}", $out);
$player->addTitle($this->translateColors("&", $out[0]), isset($out[1]) ? $this->translateColors("&", $out[1]) : "");
}
return;
}
}

Expand Down
23 changes: 12 additions & 11 deletions src/Broadcaster/Commands/Commands.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/*
* Broadcaster (v1.2) by EvolSoft
* Broadcaster (v1.4) by EvolSoft
* Developer: EvolSoft (Flavius12)
* Website: https://www.evolsoft.tk
* Date: 13/01/2018 04:01 PM (UTC)
* Date: 13/02/2018 06:57 PM (UTC)
* Copyright & License: (C) 2014-2018 EvolSoft
* Licensed under MIT (https://github.com/EvolSoft/Broadcaster/blob/master/LICENSE)
*/
Expand All @@ -19,6 +19,12 @@
use Broadcaster\Broadcaster;

class Commands extends PluginBase implements CommandExecutor {

/** @var Broadcaster */
private $plugin;

/** @var int */
private $lstchk = 0;

public function __construct(Broadcaster $plugin){
$this->plugin = $plugin;
Expand All @@ -30,7 +36,7 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar
switch($args[0]){
case "info":
if($sender->hasPermission("broadcaster.info")){
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&2BroadCaster &9v" . $this->plugin->getDescription()->getVersion() . "&2 developed by &9EvolSoft"));
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&2Broadcaster &9v" . $this->plugin->getDescription()->getVersion() . "&2 developed by &9EvolSoft"));
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&2Website &9" . $this->plugin->getDescription()->getWebsite()));
break;
}
Expand All @@ -39,14 +45,9 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar
case "help":
goto help;
case "reload":
if($sender->hasPermission("broadcaster.reload")) {
$this->plugin->reloadConfig();
$this->plugin->cfg = $this->plugin->getConfig()->getAll();
$this->plugin->mtask->remove();
$this->plugin->ptask->remove();
$this->plugin->ttask->remove();
$this->plugin->initTasks();
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&aConfiguration Reloaded."));
if($sender->hasPermission("broadcaster.reload")){
$this->plugin->reload();
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&aConfiguration reloaded"));
break;
}
$sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
Expand Down
18 changes: 8 additions & 10 deletions src/Broadcaster/Commands/SendMessage.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

/*
* Broadcaster (v1.2) by EvolSoft
* Broadcaster (v1.3) by EvolSoft
* Developer: EvolSoft (Flavius12)
* Website: https://www.evolsoft.tk
* Date: 13/01/2018 04:01 PM (UTC)
* Date: 01/02/2018 01:06 PM (UTC)
* Copyright & License: (C) 2014-2018 EvolSoft
* Licensed under MIT (https://github.com/EvolSoft/Broadcaster/blob/master/LICENSE)
*/


namespace Broadcaster\Commands;

use pocketmine\command\Command;
Expand All @@ -20,6 +19,9 @@
use Broadcaster\Broadcaster;

class SendMessage extends PluginBase implements CommandExecutor {

/** @var Broadcaster */
private $plugin;

public function __construct(Broadcaster $plugin){
$this->plugin = $plugin;
Expand All @@ -28,14 +30,10 @@ public function __construct(Broadcaster $plugin){
public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool {
if($sender->hasPermission("broadcaster.sendmessage")){
if(isset($args[0]) && isset($args[1])){
//Send message to all players
if($args[0] == "*"){
foreach($this->plugin->getServer()->getOnlinePlayers() as $player){
$this->plugin->broadcast($player, Broadcaster::TYPE_MESSAGE, $sender->getName(), $this->plugin->getMessagefromArray($args));
}
}else if($this->plugin->getServer()->getPlayerExact($args[0])){
$player = $this->plugin->getServer()->getPlayerExact($args[0]);
$this->plugin->broadcast($player, Broadcaster::TYPE_MESSAGE, $sender->getName(), $this->plugin->getMessagefromArray($args));
$this->plugin->broadcast(Broadcaster::TYPE_MESSAGE, $sender->getName(), $this->plugin->getMessagefromArray($args));
}else if(($player = $this->plugin->getServer()->getPlayerExact($args[0]))){
$this->plugin->broadcast(Broadcaster::TYPE_MESSAGE, $sender->getName(), $this->plugin->getMessagefromArray($args), $player);
}else{
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&cPlayer not found"));
}
Expand Down
16 changes: 8 additions & 8 deletions src/Broadcaster/Commands/SendPopup.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

/*
* Broadcaster (v1.2) by EvolSoft
* Broadcaster (v1.3) by EvolSoft
* Developer: EvolSoft (Flavius12)
* Website: https://www.evolsoft.tk
* Date: 13/01/2018 04:01 PM (UTC)
* Date: 01/02/2018 01:06 PM (UTC)
* Copyright & License: (C) 2014-2018 EvolSoft
* Licensed under MIT (https://github.com/EvolSoft/Broadcaster/blob/master/LICENSE)
*/


namespace Broadcaster\Commands;

use pocketmine\command\Command;
Expand All @@ -21,6 +20,9 @@

class SendPopup extends PluginBase implements CommandExecutor {

/** @var Broadcaster */
private $plugin;

public function __construct(Broadcaster $plugin){
$this->plugin = $plugin;
}
Expand All @@ -29,12 +31,10 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar
$this->temp = $this->plugin->getConfig()->getAll();
if($sender->hasPermission("broadcaster.sendpopup")){
if(isset($args[0]) && isset($args[1])){
//Send message to all players
if($args[0] == "*"){
$this->plugin->broadcast(null, Broadcaster::TYPE_POPUP, $sender->getName(), $this->plugin->getMessagefromArray($args));
}else if($this->plugin->getServer()->getPlayerExact($args[0])){
$player = $this->plugin->getServer()->getPlayerExact($args[0]);
$this->plugin->broadcast($player, Broadcaster::TYPE_POPUP, $sender->getName(), $this->plugin->getMessagefromArray($args));
$this->plugin->broadcast(Broadcaster::TYPE_POPUP, $sender->getName(), $this->plugin->getMessagefromArray($args));
}else if(($player = $this->plugin->getServer()->getPlayerExact($args[0]))){
$this->plugin->broadcast(Broadcaster::TYPE_POPUP, $sender->getName(), $this->plugin->getMessagefromArray($args), $player);
}else{
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&cPlayer not found"));
}
Expand Down
Loading

0 comments on commit ec68eb2

Please sign in to comment.