Skip to content

Commit

Permalink
3.0.0 API Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavius12 committed Jul 6, 2018
1 parent 4af7af7 commit 0c7b53f
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 138 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PocketMine-MP plugins

## Requirements

PocketMine-MP 1.7dev API 3.0.0-ALPHA7 -> 3.0.0-ALPHA12
PocketMine-MP API 3.0.0

## Overview

Expand Down
4 changes: 2 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.4
api: [3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9, 3.0.0-ALPHA10, 3.0.0-ALPHA11, 3.0.0-ALPHA12]
version: 1.5
api: [3.0.0]
load: STARTUP
author: EvolSoft
description: Advanced Broadcasting plugin
Expand Down
57 changes: 10 additions & 47 deletions src/Broadcaster/Broadcaster.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php

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

namespace Broadcaster;


use pocketmine\Player;
use pocketmine\plugin\PluginBase;
Expand Down Expand Up @@ -48,41 +46,6 @@ class Broadcaster extends PluginBase {

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

/**
* Translate Minecraft colors
*
* @param string $symbol
* @param string $message
*
* @return string
*/
public function translateColors($symbol, $message){
$message = str_replace($symbol . "0", TextFormat::BLACK, $message);
$message = str_replace($symbol . "1", TextFormat::DARK_BLUE, $message);
$message = str_replace($symbol . "2", TextFormat::DARK_GREEN, $message);
$message = str_replace($symbol . "3", TextFormat::DARK_AQUA, $message);
$message = str_replace($symbol . "4", TextFormat::DARK_RED, $message);
$message = str_replace($symbol . "5", TextFormat::DARK_PURPLE, $message);
$message = str_replace($symbol . "6", TextFormat::GOLD, $message);
$message = str_replace($symbol . "7", TextFormat::GRAY, $message);
$message = str_replace($symbol . "8", TextFormat::DARK_GRAY, $message);
$message = str_replace($symbol . "9", TextFormat::BLUE, $message);
$message = str_replace($symbol . "a", TextFormat::GREEN, $message);
$message = str_replace($symbol . "b", TextFormat::AQUA, $message);
$message = str_replace($symbol . "c", TextFormat::RED, $message);
$message = str_replace($symbol . "d", TextFormat::LIGHT_PURPLE, $message);
$message = str_replace($symbol . "e", TextFormat::YELLOW, $message);
$message = str_replace($symbol . "f", TextFormat::WHITE, $message);

$message = str_replace($symbol . "k", TextFormat::OBFUSCATED, $message);
$message = str_replace($symbol . "l", TextFormat::BOLD, $message);
$message = str_replace($symbol . "m", TextFormat::STRIKETHROUGH, $message);
$message = str_replace($symbol . "n", TextFormat::UNDERLINE, $message);
$message = str_replace($symbol . "o", TextFormat::ITALIC, $message);
$message = str_replace($symbol . "r", TextFormat::RESET, $message);
return $message;
}

public function onLoad(){
if(!self::$instance instanceof Broadcaster){
Expand Down Expand Up @@ -161,15 +124,15 @@ public function reload(){
public function initTasks(){
if($this->cfg["message-broadcast"]["enabled"]){
$mtime = intval($this->cfg["message-broadcast"]["time"]) * 20;
$this->mtask = $this->getServer()->getScheduler()->scheduleRepeatingTask(new Tasks\MessageTask($this), $mtime);
$this->mtask = $this->getScheduler()->scheduleRepeatingTask(new Tasks\MessageTask($this), $mtime);
}
if($this->cfg["popup-broadcast"]["enabled"]){
$ptime = intval($this->cfg["popup-broadcast"]["time"]) * 20;
$this->ptask = $this->getServer()->getScheduler()->scheduleRepeatingTask(new Tasks\PopupTask($this), $ptime);
$this->ptask = $this->getScheduler()->scheduleRepeatingTask(new Tasks\PopupTask($this), $ptime);
}
if($this->cfg["title-broadcast"]["enabled"]){
$ttime = intval($this->cfg["title-broadcast"]["time"]) * 20;
$this->ttask = $this->getServer()->getScheduler()->scheduleRepeatingTask(new Tasks\TitleTask($this), $ttime);
$this->ttask = $this->getScheduler()->scheduleRepeatingTask(new Tasks\TitleTask($this), $ttime);
}
}

Expand Down Expand Up @@ -228,11 +191,11 @@ public function broadcast(int $type, $sender, $message, Player $recipient = null
default:
case self::TYPE_MESSAGE:
if($recipient){
$recipient->sendMessage($this->translateColors("&", $msg));
$recipient->sendMessage(TextFormat::colorize($msg));
return;
}
foreach($this->getServer()->getOnlinePlayers() as $player){
$player->sendMessage($this->translateColors("&", str_replace("{PLAYER}", $player->getName(), $msg)));
$player->sendMessage(TextFormat::colorize(str_replace("{PLAYER}", $player->getName(), $msg)));
}
return;
case self::TYPE_POPUP:
Expand All @@ -241,13 +204,13 @@ public function broadcast(int $type, $sender, $message, Player $recipient = null
case self::TYPE_TITLE:
if($recipient){
$msg = explode("{SUBTITLE}", $msg);
$recipient->addTitle($this->translateColors("&", $msg[0]), isset($msg[1]) ? $this->translateColors("&", $msg[1]) : "");
$recipient->addTitle(TextFormat::colorize($msg[0]), isset($msg[1]) ? TextFormat::colorize($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]) : "");
$player->addTitle(TextFormat::colorize($out[0]), isset($out[1]) ? TextFormat::colorize($out[1]) : "");
}
return;
}
Expand Down
40 changes: 20 additions & 20 deletions src/Broadcaster/Commands/Commands.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

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

Expand All @@ -14,11 +13,12 @@
use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\plugin\PluginBase;
use pocketmine\command\PluginCommand;
use pocketmine\utils\TextFormat;

use Broadcaster\Broadcaster;

class Commands extends PluginBase implements CommandExecutor {
class Commands extends PluginCommand implements CommandExecutor {

/** @var Broadcaster */
private $plugin;
Expand All @@ -36,42 +36,42 @@ 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 . "&2Website &9" . $this->plugin->getDescription()->getWebsite()));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&2Broadcaster &9v" . $this->plugin->getDescription()->getVersion() . "&2 developed by &9EvolSoft"));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&2Website &9" . $this->plugin->getDescription()->getWebsite()));
break;
}
$sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
break;
case "help":
goto help;
case "reload":
if($sender->hasPermission("broadcaster.reload")){
$this->plugin->reload();
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&aConfiguration reloaded"));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&aConfiguration reloaded"));
break;
}
$sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
break;
default:
if($sender->hasPermission("broadcaster")){
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&cSubcommand &9" . $args[0] . "&c not found. Use &9/bc &cto show available commands"));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&cSubcommand &9" . $args[0] . "&c not found. Use &9/bc &cto show available commands"));
break;
}
$sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
break;
}
return true;
}
help:
if($sender->hasPermission("broadcaster")){
$sender->sendMessage($this->plugin->translateColors("&", "&2- &9Available Commands &2-"));
$sender->sendMessage($this->plugin->translateColors("&", "&9/bc info &2- &9Show info about this plugin"));
$sender->sendMessage($this->plugin->translateColors("&", "&9/bc reload &2- &9Reload the config"));
$sender->sendMessage($this->plugin->translateColors("&", "&9/sendmessage &2- &9Send message to the specified player (* for all players)"));
$sender->sendMessage($this->plugin->translateColors("&", "&9/sendpopup &2- &9Send popup to the specified player (* for all players)"));
$sender->sendMessage($this->plugin->translateColors("&", "&9/sendtitle &2- &9Send title to the specified player (* for all players)"));
$sender->sendMessage(TextFormat::colorize("&2- &9Available Commands &2-"));
$sender->sendMessage(TextFormat::colorize("&9/bc info &2- &9Show info about this plugin"));
$sender->sendMessage(TextFormat::colorize("&9/bc reload &2- &9Reload the config"));
$sender->sendMessage(TextFormat::colorize("&9/sendmessage &2- &9Send message to the specified player (* for all players)"));
$sender->sendMessage(TextFormat::colorize("&9/sendpopup &2- &9Send popup to the specified player (* for all players)"));
$sender->sendMessage(TextFormat::colorize("&9/sendtitle &2- &9Send title to the specified player (* for all players)"));
}else{
$sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
}
return true;
}
Expand Down
18 changes: 9 additions & 9 deletions src/Broadcaster/Commands/SendMessage.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

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

Expand All @@ -14,11 +13,12 @@
use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\plugin\PluginBase;
use pocketmine\command\PluginCommand;
use pocketmine\utils\TextFormat;

use Broadcaster\Broadcaster;

class SendMessage extends PluginBase implements CommandExecutor {
class SendMessage extends PluginCommand implements CommandExecutor {

/** @var Broadcaster */
private $plugin;
Expand All @@ -35,13 +35,13 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar
}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"));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&cPlayer not found"));
}
}else{
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&cUsage: /sm <player> <message>"));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&cUsage: /sm <player> <message>"));
}
}else{
$sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
}
return true;
}
Expand Down
18 changes: 9 additions & 9 deletions src/Broadcaster/Commands/SendPopup.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

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

Expand All @@ -14,11 +13,12 @@
use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\plugin\PluginBase;
use pocketmine\command\PluginCommand;
use pocketmine\utils\TextFormat;

use Broadcaster\Broadcaster;

class SendPopup extends PluginBase implements CommandExecutor {
class SendPopup extends PluginCommand implements CommandExecutor {

/** @var Broadcaster */
private $plugin;
Expand All @@ -36,13 +36,13 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar
}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"));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&cPlayer not found"));
}
}else{
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&cUsage: /sp <player> <message>"));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&cUsage: /sp <player> <message>"));
}
}else{
$sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
}
return true;
}
Expand Down
18 changes: 9 additions & 9 deletions src/Broadcaster/Commands/SendTitle.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

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

Expand All @@ -14,11 +13,12 @@
use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\plugin\PluginBase;
use pocketmine\command\PluginCommand;
use pocketmine\utils\TextFormat;

use Broadcaster\Broadcaster;

class SendTitle extends PluginBase implements CommandExecutor {
class SendTitle extends PluginCommand implements CommandExecutor {

/** @var Broadcaster */
private $plugin;
Expand All @@ -35,13 +35,13 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar
}else if(($player = $this->plugin->getServer()->getPlayerExact($args[0]))){
$this->plugin->broadcast(Broadcaster::TYPE_TITLE, $sender->getName(), $this->plugin->getMessagefromArray($args), $player);
}else{
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&cPlayer not found"));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&cPlayer not found"));
}
}else{
$sender->sendMessage($this->plugin->translateColors("&", Broadcaster::PREFIX . "&cUsage: /st <player> <message>"));
$sender->sendMessage(TextFormat::colorize(Broadcaster::PREFIX . "&cUsage: /st <player> <message>"));
}
}else{
$sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
}
return true;
}
Expand Down
Loading

0 comments on commit 0c7b53f

Please sign in to comment.