Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sulubsquared authored Nov 23, 2024
0 parents commit 9bd9dce
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
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.



13 changes: 13 additions & 0 deletions plugin.yml
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
78 changes: 78 additions & 0 deletions src/MagicWand/MagicWand.php
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;
}
}

0 comments on commit 9bd9dce

Please sign in to comment.