-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9bd9dce
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# MagicWand Plugin | ||
|
||
## Overview | ||
The **MagicWand** plugin for PocketMine adds a feature to your Minecraft Bedrock which allows the player to splash a potion using a stick. | ||
|
||
## Features | ||
- Randomized potions upon right clicking | ||
- 8 different effects, including: | ||
- Speed | ||
- Jump Boost | ||
- Strength | ||
- Regeneration | ||
- Poison | ||
- Weakness | ||
- Invisibility | ||
- Night Vision | ||
- A command (`/magicwand`) that informs players how to use the wand. | ||
- Permissions system to control who can use the command. | ||
|
||
## Requirements | ||
- PocketMine 5.0.0 or higher. | ||
- Minecraft Bedrock Edition server. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: MagicWand | ||
main: MagicWand\MagicWand | ||
version: 1.0.0 | ||
api: 5.0.0 | ||
permissions: | ||
magicwand.use: | ||
description: "Allows use of the magic wand command" | ||
default: true | ||
commands: | ||
magicwand: | ||
description: "Use the magic wand by right-clicking with a stick" | ||
usage: "/magicwand" | ||
permission: magicwand.use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace MagicWand; | ||
|
||
use pocketmine\plugin\PluginBase; | ||
use pocketmine\event\Listener; | ||
use pocketmine\event\player\PlayerInteractEvent; | ||
use pocketmine\item\Item; | ||
use pocketmine\entity\effect\Effect; | ||
use pocketmine\entity\effect\EffectInstance; | ||
use pocketmine\command\Command; | ||
use pocketmine\command\CommandSender; | ||
|
||
class MagicWand extends PluginBase implements Listener { | ||
|
||
private $potionEffects = [ | ||
"minecraft:speed" => "Speed", | ||
"minecraft:jump_boost" => "Jump Boost", | ||
"minecraft:strength" => "Strength", | ||
"minecraft:regeneration" => "Regeneration", | ||
"minecraft:poison" => "Poison", | ||
"minecraft:weakness" => "Weakness", | ||
"minecraft:invisibility" => "Invisibility", | ||
"minecraft:night_vision" => "Night Vision" | ||
]; | ||
|
||
public function onEnable(): void { | ||
$this->getServer()->getPluginManager()->registerEvents($this, $this); | ||
$this->getLogger()->info("MagicWand plugin enabled!"); | ||
} | ||
|
||
public function onPlayerUseStick(PlayerInteractEvent $event): void { | ||
$player = $event->getPlayer(); | ||
$item = $event->getItem(); | ||
|
||
// Check if right-click with stick | ||
if ($item->getId() === Item::STICK) { | ||
$event->setCancelled(true); | ||
$randomEffect = $this->getRandomPotionEffect(); | ||
$duration = 20 * 5; // 5 seconds duration | ||
$amplifier = mt_rand(0, 1); | ||
|
||
$this->splashPotion($player, $randomEffect, $duration, $amplifier); | ||
$player->sendMessage("A random splash potion has been triggered with the Magic Wand!"); | ||
} | ||
} | ||
|
||
private function getRandomPotionEffect(): string { | ||
$effectKeys = array_keys($this->potionEffects); | ||
return $effectKeys[array_rand($effectKeys)]; | ||
} | ||
|
||
private function splashPotion($player, string $effectId, int $duration, int $amplifier): void { | ||
$effect = Effect::getEffectByName($effectId); | ||
if ($effect === null) { | ||
$player->sendMessage("Error: Invalid potion effect."); | ||
return; | ||
} | ||
|
||
$effectInstance = new EffectInstance($effect, $duration, $amplifier); | ||
$player->addEffect($effectInstance); | ||
} | ||
|
||
// Command handling | ||
public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool { | ||
if ($command->getName() === "magicwand") { | ||
// Check if the sender has permission to use the magicwand command | ||
if (!$sender->hasPermission("magicwand.use")) { | ||
$sender->sendMessage("You do not have permission to use this command."); | ||
return false; | ||
} | ||
|
||
$sender->sendMessage("Use the magic wand by right-clicking with a stick."); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |