Skip to content

Commit

Permalink
Publish SimpleGameMode plugin v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ImmoDevs committed Jun 2, 2024
1 parent 7054a33 commit 1e43f14
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 27 deletions.
67 changes: 40 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
# SimpleGamemode
# SimpleGameMode

![SimpleGamemode](https://img.shields.io/badge/SimpleGamemode-v1.0.0-brightgreen.svg)
![PocketMine-MP](https://img.shields.io/badge/PocketMine--MP-5.0.0-blue.svg)
![License](https://img.shields.io/badge/License-MIT-yellow.svg)
[![SimpleGameMode](https://img.shields.io/badge/SimpleGamemode-v1.0.0-brightgreen.svg)](https://github.com/ImmoDevs/SimpleGameMode)
[![PocketMine-MP](https://img.shields.io/badge/PocketMine--MP-5.0.0-blue.svg)](https://github.com/pmmp/PocketMine-MP)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ImmoDevs/SimpleGameMode/blob/main/LICENSE)

**SimpleGamemode** is a PocketMine-MP plugin that simplifies changing gamemodes with shorter commands. Easily switch between creative, survival, adventure, and spectator modes, and target other players or use selectors for flexibility.
**SimpleGameMode** is a sleek and powerful PocketMine-MP plugin designed to streamline gamemode switching with intuitive and shortened commands. Effortlessly toggle between creative, survival, adventure, and spectator modes. Target specific players or utilize player selectors for maximum flexibility.

## Features
## Features

- **Simplified Commands**: Shortened commands for quick gamemode changes.
- **Player Targeting**: Change gamemodes for other players using direct names or selectors (`@a`, `@s`, `@p`).
- **Permission Control**: Restrict command usage based on permissions.
- **✂️ Simplified Commands**: Shortened commands for quick gamemode changes.
- **🎯 Player Targeting**: Change gamemodes for other players using direct names, partial names, or selectors (`@a`, `@s`).
- **🔐 Permission Control**: Restrict command usage based on permissions.
- **⚙️ Configurable Messages**: Customize success messages for gamemode changes via the config file.

## Commands
## 📜 Commands

| Command | Description | Permission |Usage |
| Command | Description | Permission | Usage |
|---------|------------------------------------|-----------------------|----------------------------|
| `/gmc` | Change to Creative mode | `simplegamemode.gmc` | `/gmc [player/@selector]` |
| `/gms` | Change to Survival mode | `simplegamemode.gms` | `/gms [player/@selector]` |
| `/gma` | Change to Adventure mode | `simplegamemode.gma` | `/gma [player/@selector]` |
| `/gmsp` | Change to Spectator mode | `simplegamemode.gmsp` | `/gmsp [player/@selector]` |

## Installation
## 🚀 Installation

1. Download the `SimpleGamemode.phar` file from the [releases page](#).
2. Place the `SimpleGamemode.phar` file into the `plugins` directory of your PocketMine-MP server.
1. Download the `SimpleGameMode.phar` file from the [releases page](https://github.com/ImmoDevs/SimpleGamemode/releases).
2. Place the `SimpleGameMode.phar` file into the `plugins` directory of your PocketMine-MP server.
3. Restart your server to load the plugin.

## Permissions
## 🔐 Permissions

| Permission | Description | Default |
|-----------------------|-----------------------------------|---------|
Expand All @@ -36,26 +37,38 @@
| `simplegamemode.gma` | Allows the use of `/gma` command | `op` |
| `simplegamemode.gmsp` | Allows the use of `/gmsp` command | `op` |

## Usage Examples
## 💡 Usage Examples

- Change your own gamemode to Creative:
```
```sh
/gmc | /gmc @s
```
- Change another player's gamemode to Survival:
```
```sh
/gms PlayerName
```
- Change all players' gamemode to Adventure:
```
```sh
/gma @a
```
- Change the nearest player's gamemode to Spectator:
```
/gmsp @p
```

## Building from Source
## ⚙️ Configuration

Customize the success messages in `config.yml`:
```yaml
# Configuration for SimpleGameMode Plugin

# Messages to display when a player's gamemode is changed
messages:
# Message sent to the command sender when they successfully change another player's gamemode
player-gamemode-change: "Successfully changed {player}'s gamemode to {gamemode}."

# Message sent to the player when they change their own gamemode
personal-gamemode-change: "Gamemode changed to {gamemode}."

```

## 🛠️ Building from Source

1. Clone the repository:
```bash
Expand All @@ -70,11 +83,11 @@
zip -r SimpleGamemode.phar . -x "*.git*" -x "*.md" -x "tests/*"
```

## Contributing
## 🤝 Contributing

Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/ImmoDevs/SimpleGamemode).
Contributions are welcome! Please open an [Issues](https://github.com/ImmoDevs/SimpleGameMode/issues) or submit a [Pull Request](https://github.com/ImmoDevs/SimpleGameMode/pulls).

## License
## 📄 License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Expand Down
39 changes: 39 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: SimpleGameMode
main: ImmoDevs\SimpleGameMode\Main
version: 1.0.0
api: [5.0.0]
author: ImmoDevs
website: https://github.com/SimpleGameMode
description: A simple plugin to change gamemodes with shorter commands.

commands:
gmc:
description: Change to Creative mode.
usage: /gmc [player]
permission: simplegamemode.gmc
gms:
description: Change to Survival mode.
usage: /gms [player]
permission: simplegamemode.gms
gma:
description: Change to Adventure mode.
usage: /gma [player]
permission: simplegamemode.gma
gmsp:
description: Change to Spectator mode.
usage: /gmsp [player]
permission: simplegamemode.gmsp

permissions:
simplegamemode.gmc:
description: Allows the use of /gmc command.
default: op
simplegamemode.gms:
description: Allows the use of /gms command.
default: op
simplegamemode.gma:
description: Allows the use of /gma command.
default: op
simplegamemode.gmsp:
description: Allows the use of /gmsp command.
default: op
9 changes: 9 additions & 0 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Configuration for SimpleGamemode Plugin

# Messages to display when a player's gamemode is changed
messages:
# Message sent to the command sender when they successfully change another player's gamemode
player-gamemode-change: "§f[§cSimpleGameMode§f] §6You have §aSuccessfully changed §{player}'s §6gamemode §fto §{gamemode}."

# Message sent to the player when they change their own gamemode
personal-gamemode-change: "§f[§cSimpleGameMode§f] §6Your gamemode has been changed to §c{gamemode}."
119 changes: 119 additions & 0 deletions src/ImmoDevs/SimpleGameMode/Main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

namespace ImmoDevs\SimpleGameMode;

use pocketmine\command\CommandSender;
use pocketmine\command\Command;
use pocketmine\player\GameMode;
use pocketmine\player\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat;
use pocketmine\lang\Translatable;

class Main extends PluginBase {

private array $configMessages;

public function onEnable(): void
{
$this->saveDefaultConfig();
$this->configMessages = $this->getConfig()->get("messages", []);
$this->getLogger()->info(TextFormat::GREEN . "SimpleGameMode By ImmoDevs enabled");
}

public function onDisable(): void
{
$this->getLogger()->info(TextFormat::RED . "SimpleGameMode By ImmoDevs disabled");
}

public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool
{
if (!$sender->hasPermission("simplegamemode." . $command->getName())) {
$sender->sendMessage(TextFormat::RED . "You do not have permission to use this command.");
return false;
}

if (count($args) < 1) {
$sender->sendMessage(TextFormat::RED. "Usage: /". $command->getName(). " <gamemode>");
return false;
}

if (!$sender instanceof Player && count($args) === 0) {
$sender->sendMessage(TextFormat::RED. "This command can only be used in-game or with a player/selector.");
return false;
}

$targetPlayers = [$sender];
if (count($args) > 0) {
$targetPlayers = $this->resolvePlayer($sender, $args[0]);
if(empty($targetPlayers)) {
$sender->sendMessage(TextFormat::RED . "No players matched the given selector.");
return false;
}
} elseif ($sender instanceof Player) {
$targetPlayers = [$sender];
} else {
$sender->sendMessage(TextFormat::RED . "You must specify a player or selector when using this command from console.");
return false;
}

$gamemode = match ($command->getName()) {
"gmc" => GameMode::CREATIVE(),
"gms" => GameMode::SURVIVAL(),
"gma" => GameMode::ADVENTURE(),
"gmsp" => GameMode::SPECTATOR(),
default => null,
};

if ($gamemode === null) {
return false;
}

foreach ($targetPlayers as $player) {
$player->setGamemode($gamemode);
$player->sendMessage($this->configMessages["personal-gamemode-change"]);
if ($sender !== $player) {
$senderMessage = str_replace(
["{player}", "{gamemode}"],
[$player->getName(), $this->getGamemodeName($gamemode)],
$this->configMessages["player-gamemode-change"]
);
$sender->sendMessage($senderMessage);
}
}

return true;
}

private function resolvePlayer(CommandSender $sender, string $selector): array
{
$server = $this->getServer();
switch ($selector) {
case "all":
return $server->getOnlinePlayers();
case "@a":
return $server->getOnlinePlayers();
case "@s":
return [$sender];
default:
$selector = strtolower($selector);
$matchedPlayers = [];
foreach ($server->getOnlinePlayers() as $player) {
if (strpos(strtolower($player->getName()), $selector) === 0) {
$matchedPlayers[] = $player;
}
}
return $matchedPlayers;
}
}

private function getGameModeName(GameMode $gamemode): string {
return match ($gamemode) {
GameMode::CREATIVE() => "Creative",
GameMode::SURVIVAL() => "Survival",
GameMode::ADVENTURE() => "Adventure",
GameMode::SPECTATOR() => "Spectator",
default => "Unknown",
};
}
}

0 comments on commit 1e43f14

Please sign in to comment.