Skip to content
This repository was archived by the owner on Jul 11, 2018. It is now read-only.

Commit 7d6f692

Browse files
committed
FloatChat-0.1.0
1 parent 2e53ba5 commit 7d6f692

File tree

4 files changed

+261
-0
lines changed

4 files changed

+261
-0
lines changed

FloatChat/README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<img src="https://raw.githubusercontent.com/alejandroliu/bad-plugins/master/Media/floatchat.jpg" style="width:64px;height:64px" width="64" height="64"/>
2+
3+
# FloatChat
4+
5+
* Summary: Float chat messages
6+
* PocketMine-MP version: 1.5 - API 1.12.0
7+
* DependencyPlugins: -
8+
* OptionalPlugins: -
9+
* Categories: Chat, Fun, Mechanics
10+
* Plugin Access: Entities
11+
* WebSite: [github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/LocalChat)
12+
13+
Overview
14+
--------
15+
16+
Make chats to appear in text above the player.
17+
If you want to broadcast a message to all players in the Level use:
18+
19+
.text
20+
21+
While if you want to broacast a message to all players in the Server
22+
use:
23+
24+
:text
25+
26+
27+
Documentation
28+
-------------
29+
30+
By prefixing your text with a "." to a message you can *shout* your
31+
message to everybody in the same level.
32+
33+
By prefixing your text with a ":" to a message you can *broadcast*
34+
your message to everybody in the same server.
35+
36+
37+
### Permission Nodes:
38+
39+
* floatchat.brodcast: Allow access to `.` and `:` to broadcast messages.
40+
* floatchat.brodcast.level: Allow access to `.` messages
41+
* floatchat.brodcast.server: Allow access to `:` messages
42+
* floatchat.spy: Users with this permission are always able to hear
43+
all messages.
44+
45+
### TODO
46+
47+
48+
Changes
49+
-------
50+
51+
* 1.0.0 : First public release
52+
53+
Copyright
54+
---------
55+
56+
FloatChat
57+
Copyright (C) 2015 Alejandro Liu
58+
All Rights Reserved.
59+
60+
This program is free software: you can redistribute it and/or modify
61+
it under the terms of the GNU General Public License as published by
62+
the Free Software Foundation, either version 2 of the License, or
63+
(at your option) any later version.
64+
65+
This program is distributed in the hope that it will be useful,
66+
but WITHOUT ANY WARRANTY; without even the implied warranty of
67+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68+
GNU General Public License for more details.
69+
70+
You should have received a copy of the GNU General Public License
71+
along with this program. If not, see <http://www.gnu.org/licenses/>.

FloatChat/plugin.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: FloatChat
2+
version: 0.1.0
3+
main: aliuly\floatchat\Main
4+
api: 1.12.0
5+
load: POSTWORLD
6+
7+
description: Float chat messages
8+
author: aliuly
9+
10+
permissions:
11+
floatchat.broadcast:
12+
default: true
13+
description: "Give players the ability to broadcast messages"
14+
floatchat.broadcast.server:
15+
default: op
16+
description: "Broadcast to the server"
17+
floatchat.broadcast.level:
18+
default: true
19+
description: "Broadcast to the level"
20+
floatchat.spy:
21+
default: true
22+
description: "Grant players the ability to spy on players"
+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?php
2+
namespace aliuly\floatchat;
3+
4+
use pocketmine\plugin\PluginBase;
5+
use pocketmine\Player;
6+
use pocketmine\event\Listener;
7+
use pocketmine\event\player\PlayerChatEvent;
8+
use pocketmine\event\player\PlayerQuitEvent;
9+
use pocketmine\event\player\PlayerMoveEvent;
10+
use pocketmine\event\entity\EntityTeleportEvent;
11+
use pocketmine\utils\Config;
12+
use pocketmine\utils\TextFormat;
13+
use pocketmine\command\CommandSender;
14+
15+
use pocketmine\level\particle\FloatingTextParticle;
16+
use pocketmine\math\Vector3;
17+
18+
use pocketmine\scheduler\PluginTask;
19+
20+
class cleanUpTask extends PluginTask {
21+
public function onRun($currentTick){
22+
if ($this->owner->isDisabled()) return;
23+
$this->owner->timerTick();
24+
}
25+
}
26+
27+
28+
class Main extends PluginBase implements Listener {
29+
protected $particles;
30+
protected $timeout = 5;
31+
32+
protected static function iName($player) {
33+
return strtolower($player->getName());
34+
}
35+
36+
// Access and other permission related checks
37+
private function access(CommandSender $sender, $permission) {
38+
if($sender->hasPermission($permission)) return true;
39+
$sender->sendMessage("You do not have permission to do that.");
40+
return false;
41+
}
42+
//////////////////////////////////////////////////////////////////////
43+
//
44+
// Standard call-backs
45+
//
46+
//////////////////////////////////////////////////////////////////////
47+
public function onEnable(){
48+
//if (!is_dir($this->getDataFolder())) mkdir($this->getDataFolder());
49+
$this->getServer()->getPluginManager()->registerEvents($this, $this);
50+
$this->particles = [];
51+
$this->getServer()->getScheduler()->scheduleRepeatingTask(new cleanUpTask($this),20);
52+
53+
}
54+
55+
protected function deSpawn($particle,$level) {
56+
if ($level === null) return;
57+
$particle->setInvisible();
58+
$level->addParticle($particle);
59+
}
60+
61+
//////////////////////////////////////////////////////////////////////
62+
//
63+
// Event handlers
64+
//
65+
//////////////////////////////////////////////////////////////////////
66+
public function timerTick() {
67+
$now = time();
68+
foreach (array_keys($this->particles) as $n) {
69+
list($particle,$level,$expby,) = $this->particles[$n];
70+
if ($level !== null && $now > $expby) {
71+
$this->deSpawn($particle,$level);
72+
$this->particles[$n][1] = null;
73+
}
74+
}
75+
}
76+
77+
public function onQuit(PlayerQuitEvent $e){
78+
$n = self::iName($e->getPlayer());
79+
if (isset($this->particles[$n])) {
80+
list($p,$level,,) = $this->particles[$n];
81+
unset($this->particles[$n]);
82+
$this->deSpawn($p,$level);
83+
}
84+
}
85+
86+
public function onMove(PlayerMoveEvent $e) {
87+
$n = self::iName($e->getPlayer());
88+
if (!isset($this->particles[$n])) return;
89+
list($p,$level,,) = $this->particles[$n];
90+
if ($level === null) return;
91+
$pw = $e->getPlayer();
92+
$p->x = $pw->getX();
93+
$p->y = $pw->getY()+2+count($this->particles[$n][3])*0.5;
94+
$p->z = $pw->getZ();
95+
$pw->getLevel()->addParticle($p);
96+
}
97+
98+
public function onChat(PlayerChatEvent $e){
99+
if ($e->isCancelled()) return;
100+
$pw = $e->getPlayer();
101+
// Non players are handled normally
102+
if (!($pw instanceof Player)) return;
103+
104+
$msg = $e->getMessage();
105+
if (substr($msg,0,1) == ":") {
106+
// This messages goes to everybody on the server...
107+
// no need to do much...
108+
if (!$this->access($pw,"floatchat.broadcast.server")) {
109+
$e->setCancelled();
110+
return;
111+
}
112+
$e->setMessage(substr($msg,1));
113+
return;
114+
}
115+
if (substr($msg,0,1) == ".") {
116+
$target = [];
117+
if (!$this->access($pw,"floatchat.broadcast.level")) {
118+
$e->setCancelled();
119+
return;
120+
}
121+
// Send this message to everybody on this level
122+
$e->setMessage(substr($msg,1));
123+
foreach ($e->getRecipients() as $pr) {
124+
if ($pr instanceof Player) {
125+
if (!$pr->hasPermission("floatchat.spy") &&
126+
$pr->getLevel() != $pw->getLevel()) continue;
127+
}
128+
$target[] = $pr;
129+
}
130+
$e->setRecipients($target);
131+
return;
132+
}
133+
$target = [];
134+
foreach ($e->getRecipients() as $pr) {
135+
if ($pr instanceof Player) {
136+
if (!$pr->hasPermission("floatchat.spy") && $pr != $pw) continue;
137+
}
138+
$target[] = $pr;
139+
}
140+
$e->setRecipients($target);
141+
echo __METHOD__.",".__LINE__."\n";//##DEBUG
142+
143+
$n = self::iName($pw);
144+
if (!isset($this->particles[$n]))
145+
$this->particles[$n] = [new FloatingTextParticle($pw,""), null, 0, ""];
146+
147+
$p = $this->particles[$n][0];
148+
$msg = $e->getMessage();
149+
if ($p->isInvisible()) {
150+
$this->particles[$n][3] = [ $msg ];
151+
$p->setText(TextFormat::YELLOW.$msg);
152+
$p->setInvisible(false);
153+
} else {
154+
$this->particles[$n][3][] = $msg;
155+
while (count($this->particles[$n][3]) > 3) {
156+
array_shift($this->particles[$n][3]);
157+
}
158+
$p->setText(TextFormat::YELLOW.implode("\n",$this->particles[$n][3]));
159+
}
160+
$p->x = $pw->getX();
161+
$p->y = $pw->getY()+2+count($this->particles[$n][3])*0.5;
162+
$p->z = $pw->getZ();
163+
$this->particles[$n][1] = $pw->getLevel();
164+
$this->particles[$n][2] = time()+$this->timeout;
165+
166+
$pw->getLevel()->addParticle($p);
167+
}
168+
}

Media/floatchat-icon.jpg

5.94 KB
Loading

0 commit comments

Comments
 (0)