Skip to content

Commit 87e696e

Browse files
committed
Initial commit
0 parents  commit 87e696e

9 files changed

Lines changed: 323 additions & 0 deletions

File tree

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Wenox
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# BackToDeath Plugin
2+
3+
A powerful PocketMine-MP plugin that allows players to teleport back to their last death location with a simple command.
4+
5+
## 📋 Features
6+
7+
- **Death Location Tracking**: Automatically records player death positions
8+
- **Easy Teleportation**: Use `/back` command to return to your last death point
9+
- **Permission System**: Control who can use the back command
10+
- **Cooldown System**: 5-minute cooldown to prevent command spam
11+
- **World Management**: Automatically loads worlds if they're not already loaded
12+
- **Memory Efficient**: Uses lightweight caching system
13+
14+
## 🚀 Installation
15+
16+
1. Download the latest `BackToDeath.phar` file from releases
17+
2. Place the `.phar` file in your server's `plugins/` directory
18+
3. Restart your server
19+
4. The plugin will automatically enable and be ready to use
20+
21+
## ⚙️ Configuration
22+
23+
The plugin now supports configuration through `config.yml` file. Server owners can customize cooldown times and messages.
24+
25+
### Configuration Options:
26+
27+
```yaml
28+
# BackToDeath Plugin Configuration
29+
30+
# Cooldown settings
31+
cooldown:
32+
# Cooldown time in seconds (default: 300 seconds = 5 minutes)
33+
time: 300
34+
35+
# Message settings
36+
messages:
37+
# Message when command is used from console
38+
console_only: "§cThis command can only be used in-game."
39+
40+
# Message when player doesn't have permission
41+
no_permission: "You Dont Have Permission To Use This Command."
42+
43+
# Message when command is on cooldown
44+
on_cooldown: "You must wait some more!"
45+
46+
# Message when player hasn't died recently
47+
no_death: "You haven't died recently!"
48+
49+
# Message when teleportation is successful
50+
success: "You have been successfully teleported to your last death point."
51+
```
52+
53+
To modify these settings:
54+
1. Edit the `plugins/BackToDeath/config.yml` file
55+
2. Restart your server or reload the plugin
56+
3. Changes will take effect immediately
57+
58+
## 🔧 Commands
59+
60+
### `/back`
61+
Teleports you to your last death location.
62+
63+
**Usage:** `/back`
64+
65+
**Permission:** `back.cmd.use` (default: op)
66+
67+
**Cooldown:** Configurable (default: 5 minutes)
68+
69+
## 🔐 Permissions
70+
71+
| Permission | Description | Default |
72+
|------------|-------------|---------|
73+
| `back.cmd.use` | Allows players to use the `/back` command | op |
74+
75+
## 🎯 How It Works
76+
77+
1. When a player with permission dies, their death location is automatically recorded
78+
2. The location is stored in memory (X, Y, Z coordinates and world name)
79+
3. When the player uses `/back`, the plugin:
80+
- Checks if they have permission
81+
- Verifies they have a stored death location
82+
- Ensures the cooldown period has expired
83+
- Loads the world if necessary
84+
- Teleports the player to their death location
85+
- Sets a new 5-minute cooldown
86+
87+
## 🏎️ Performance
88+
89+
The BackToDeath plugin utilizes a **high-performance SQLite caching system** for storing player death locations and cooldowns. This ensures:
90+
- **No Lag**: Efficient data retrieval and storage minimizes server load.
91+
- **Stable Performance**: Data persists across server restarts, providing a reliable experience for players.
92+
93+
## 📝 API Compatibility
94+
95+
- **PocketMine-MP API**: 5.0.0+
96+
- **PHP Version**: 8.0+
97+
98+
## 🐛 Troubleshooting
99+
100+
**Q: I get "You haven't died recently!" message**
101+
A: This means the plugin doesn't have a recorded death location for you. Die first, then use `/back`.
102+
103+
**Q: I get "You must wait some more!" message**
104+
A: You need to wait 5 minutes between uses of the `/back` command.
105+
106+
**Q: The command doesn't work for non-op players**
107+
A: By default, only operators have permission. You can change this in your permissions configuration.
108+
109+
## 🤝 Support
110+
111+
If you encounter any issues or have suggestions:
112+
1. Check this README for common solutions
113+
2. Ensure you're using a compatible PocketMine-MP version
114+
3. Verify the plugin is properly installed
115+
116+
## 📄 License
117+
118+
This plugin is provided as-is. Feel free to modify and distribute with proper credit.
119+
120+
## 🏆 Credits
121+
122+
**Developer**: Biswajit
123+
**Plugin Name**: BackToDeath
124+
**Version**: 1.0.0
125+
126+
---
127+
128+
⭐ **Enjoy the convenience of returning to your death locations with ease!** ⭐

config.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# BackToDeath Plugin Configuration
2+
#
3+
# Cooldown settings
4+
cooldown:
5+
# Cooldown time in seconds (default: 300 seconds = 5 minutes)
6+
time: 300
7+
8+
# Message settings
9+
messages:
10+
# Message when command is used from console
11+
console_only: "§cThis command can only be used in-game."
12+
13+
# Message when player doesn't have permission
14+
no_permission: "You Dont Have Permission To Use This Command."
15+
16+
# Message when command is on cooldown
17+
on_cooldown: "You must wait some more!"
18+
19+
# Message when player hasn't died recently
20+
no_death: "You haven't died recently!"
21+
22+
# Message when teleportation is successful
23+
success: "You have been successfully teleported to your last death point."

plugin.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: BackToDeath
2+
author: Biswajit
3+
version: 1.0.0
4+
main: Biswajit\Back\Main
5+
api: [5.0.0]
6+
7+
permissions:
8+
back.cmd.use:
9+
default: op
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Biswajit\Back\Commands;
6+
7+
use Biswajit\Back\Main;
8+
use Biswajit\Back\Managers\CacheManager;
9+
use pocketmine\command\Command;
10+
use pocketmine\command\CommandSender;
11+
use pocketmine\player\Player;
12+
use pocketmine\Server;
13+
use pocketmine\world\Position;
14+
15+
class BackCommand extends Command
16+
{
17+
/** @var Main */
18+
private $plugin;
19+
20+
public function __construct(Main $plugin) {
21+
parent::__construct("back", "Teleport you to the last death position", "/back");
22+
$this->setPermission("back.cmd.use");
23+
$this->plugin = $plugin;
24+
}
25+
public function execute(CommandSender $sender, string $commandLabel, array $args): void {
26+
$config = $this->plugin->getPluginConfig();
27+
28+
if (!$sender instanceof Player) {
29+
$sender->sendMessage($config['messages']['console_only']);
30+
return;
31+
}
32+
33+
if(!$sender->hasPermission("back.cmd.use")) {
34+
$sender->sendMessage($config['messages']['no_permission']);
35+
return;
36+
}
37+
38+
if(isset(CacheManager::getInstance()->cooldown["back"][$sender->getName()]) && CacheManager::getInstance()->cooldown["back"][$sender->getName()] - time() > 0){
39+
$sender->sendMessage($config['messages']['on_cooldown']);
40+
return;
41+
}
42+
43+
if(!isset(CacheManager::getInstance()->back[$sender->getName()])){
44+
$sender->sendMessage($config['messages']['no_death']);
45+
return;
46+
}
47+
48+
$pos = explode(":", CacheManager::getInstance()->back[$sender->getName()]);
49+
$worldName = $pos[3];
50+
$worldMgr = Server::getInstance()->getWorldManager();
51+
if (!$worldMgr->isWorldLoaded($worldName)){
52+
$worldMgr->loadWorld($worldName);
53+
}
54+
$pos = new Position((int)$pos[0], (int)$pos[1], (int)$pos[2], $worldMgr->getWorldByName($worldName));
55+
$sender->teleport($pos);
56+
57+
CacheManager::getInstance()->cooldown["back"][$sender->getName()] = time() + $config['cooldown']['time'];
58+
59+
$sender->sendMessage($config['messages']['success']);
60+
}
61+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Biswajit\Back;
6+
7+
use Biswajit\Back\Managers\CacheManager;
8+
use pocketmine\event\Listener;
9+
use pocketmine\event\player\PlayerDeathEvent;
10+
11+
class EventListener implements Listener
12+
{
13+
public function onDeath(PlayerDeathEvent $event)
14+
{
15+
$player = $event->getPlayer();
16+
17+
if ($player->hasPermission("back.cmd.use")) {
18+
$pos = $player->getLocation();
19+
$x = $pos->getX();
20+
$y = $pos->getY();
21+
$z = $pos->getZ();
22+
$worldName = $pos->getWorld()->getFolderName();
23+
CacheManager::getInstance()->back[$player->getName()] = $x . ":" . $y . ":" . $z . ":" . $worldName;
24+
}
25+
}
26+
}

src/Biswajit/Back/Main.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Biswajit\Back;
4+
5+
use Biswajit\Back\Commands\BackCommand;
6+
use pocketmine\plugin\PluginBase;
7+
use Biswajit\Back\EventListener;
8+
use Biswajit\Back\Managers\CacheManager;
9+
10+
class Main extends PluginBase {
11+
12+
/** @var array */
13+
private $config;
14+
15+
public function onEnable(): void {
16+
$this->saveDefaultConfig();
17+
18+
$this->config = $this->getConfig()->getAll();
19+
20+
$this->getServer()->getPluginManager()->registerEvents(new EventListener(), $this);
21+
$this->getServer()->getCommandMap()->register("back", new BackCommand($this));
22+
new CacheManager();
23+
}
24+
25+
/**
26+
* Get the plugin configuration
27+
*
28+
* @return array
29+
*/
30+
public function getPluginConfig(): array {
31+
return $this->config;
32+
}
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Biswajit\Back\Managers;
6+
7+
use pocketmine\utils\SingletonTrait;
8+
9+
class CacheManager
10+
{
11+
use SingletonTrait;
12+
13+
public array $back = [];
14+
public array $cooldown = [];
15+
16+
public function __construct()
17+
{
18+
self::setInstance($this);
19+
}
20+
}

0 commit comments

Comments
 (0)