Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Commit

Permalink
Implement Particles (#8)
Browse files Browse the repository at this point in the history
Wasn't expecting myself to be that successful as it is my first time using particles.
  • Loading branch information
AGTHARN committed Dec 9, 2020
1 parent 7bc8cac commit eb471ff
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 2 deletions.
22 changes: 22 additions & 0 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ flyuiexit: "§cExit"
##################


##### PARTICLES #####

# If set to true, particles will appear on player's feet if they are flying.
# If set to false, no particles will appear.
enableflyparticles: false

# Type of particle to spawn.
# SUPPORTED: (case insensitive)
#
# BubbleParticle, CriticalParticle, EnchantParticle, InstantEnchantParticle, ExplodeParticle, HugeExplodeParticle
# EntityFlameParticle, FlameParticle, HeartParticle, InkParticle, LavaDripParticle, LavaParticle, PortalParticle
# RedstoneParticle, SmokeParticle, SplashParticle, SporeParticle, MobSpawnParticle, WaterDripParticle
# WaterParticle, EnchantmentTableParticle, HappyVillagerParticle, AngryVillagerParticle, RainSplashParticle
flyparticletype: "FlameParticle"

# Rate of fly particle.
# 20 (ticks) = 1 second
flyparticlerate: 5

#####################


##### TEMPORAL FLY (COMING SOON) #####

# Would you like to time how long a player could use /fly?
Expand Down
16 changes: 14 additions & 2 deletions src/AGTHARN/FlyPE/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use pocketmine\Player;

use AGTHARN\FlyPE\commands\FlyCommand;
use AGTHARN\FlyPE\tasks\ParticleTask;
use AGTHARN\FlyPE\lists\ParticleList;

use jojoe77777\FormAPI\SimpleForm;
use JackMD\UpdateNotifier\UpdateNotifier;
Expand All @@ -56,10 +58,11 @@ public function onEnable(): void {

$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
$this->getServer()->getCommandMap()->register("fly", new FlyCommand("fly", $this));
$this->getScheduler()->scheduleRepeatingTask(new ParticleTask($this), $this->getConfig()->get("flyparticlerate"));

if ($this->getConfig()->get("config-version") < "3") {
$this->getLogger()->warning("Your config is outdated! Please consider deleting your old config to get the latest features!");
//$this->getServer()->getPluginManager()->disablePlugin($this);
$this->getLogger()->warning("Your config is outdated! Please delete your old config to get the latest features!");
$this->getServer()->getPluginManager()->disablePlugin($this);
}
UpdateNotifier::checkUpdate($this->getDescription()->getName(), $this->getDescription()->getVersion());
}
Expand Down Expand Up @@ -179,5 +182,14 @@ public function toggleFlight(Player $player): void {
*/
public static function getInstance(): Main {
return self::$instance;
}

/**
* getParticles
*
* @return mixed|object|resource
*/
public function getParticleList() {
return new ParticleList($this);
}
}
199 changes: 199 additions & 0 deletions src/AGTHARN/FlyPE/lists/ParticleList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?php

/*
* ______ _ __ _______ ______
* | ____| | \ \ / / __ \| ____|
* | |__ | | \ \_/ /| |__) | |__
* | __| | | \ / | ___/| __|
* | | | |____| | | | | |____
* |_| |______|_| |_| |______|
*
* FlyPE, is an advanced fly plugin for PMMP.
* Copyright(C) 2020 AGTHARN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace AGTHARN\FlyPE\lists;

use pocketmine\utils\TextFormat as C;
use pocketmine\math\Vector3;

use pocketmine\level\particle\BubbleParticle;
use pocketmine\level\particle\CriticalParticle;
use pocketmine\level\particle\EnchantParticle;
use pocketmine\level\particle\InstantEnchantParticle;
use pocketmine\level\particle\ExplodeParticle;
use pocketmine\level\particle\HugeExplodeParticle;
use pocketmine\level\particle\EntityFlameParticle;
use pocketmine\level\particle\FlameParticle;
use pocketmine\level\particle\HeartParticle;
use pocketmine\level\particle\InkParticle;
use pocketmine\level\particle\LavaDripParticle;
use pocketmine\level\particle\LavaParticle;
use pocketmine\level\particle\PortalParticle;
use pocketmine\level\particle\RedstoneParticle;
use pocketmine\level\particle\SmokeParticle;
use pocketmine\level\particle\SplashParticle;
use pocketmine\level\particle\SporeParticle;
use pocketmine\level\particle\MobSpawnParticle;
use pocketmine\level\particle\WaterDripParticle;
use pocketmine\level\particle\WaterParticle;
use pocketmine\level\particle\EnchantmentTableParticle;
use pocketmine\level\particle\HappyVillagerParticle;
use pocketmine\level\particle\AngryVillagerParticle;
use pocketmine\level\particle\RainSplashParticle;

use AGTHARN\FlyPE\Main;

class ParticleList {

/**
* plugin
*
* @var Main
*/
private $plugin;

/**
* __construct
*
* @param Main $plugin
* @return void
*/
public function __construct(Main $plugin) {
$this->plugin = $plugin;
}

/**
* getParticle
*
* @param string $particleName
* @param Vector3 $playerPos
* @return void|object|mixed
*/
public function getParticle(string $particleName, Vector3 $playerPos) {
switch(strtolower($particleName)):
// a
case "angryvillagerparticle":
case "angryvillager":
case "angry":
return new AngryVillagerParticle($playerPos);
// b
case "bubbleparticle":
case "bubble":
return new BubbleParticle($playerPos);
// c
case "criticalparticle":
case "critical":
case "crit":
return new CriticalParticle($playerPos);
// d
case "waterdripparticle":
case "waterdrip":
case "dripwater":
return new WaterDripParticle($playerPos);
case "lavadripparticle":
case "lavadrip":
case "driplava":
return new LavaDripParticle($playerPos);
// e
case "explodeparticle":
case "explode":
return new ExplodeParticle($playerPos);
case "entityflameparticle":
case "entityflame":
case "flameentity":
return new EntityFlameParticle($playerPos);
case "enchantmenttableparticle":
case "enchantmenttable":
case "enchantment":
return new EnchantmentTableParticle($playerPos);
// f
case "flameparticle":
case "flame":
case "fire":
return new FlameParticle($playerPos);
// g
// h
case "hugeexplodeparticle":
case "hugeexplode":
return new HugeExplodeParticle($playerPos);
case "heartparticle":
case "heart":
return new HeartParticle($playerPos);
case "happyvillagerparticle":
case "happyvillager":
case "happy":
return new HappyVillagerParticle($playerPos);
// i
case "inkparticle":
case "ink":
return new InkParticle($playerPos);
case "instantenchantparticle":
case "instantenchant":
case "instant":
return new InstantEnchantParticle($playerPos);
// j
// k
// l
case "lavaparticle":
case "lava":
return new LavaParticle($playerPos);
// m
case "mobspawnparticle":
case "mobspawn":
case "spawnmob":
return new MobSpawnParticle($playerPos);
// n
// o
// p
case "portalparticle":
case "portal":
return new PortalParticle($playerPos);
// q
// r
case "redstoneparticle":
case "redstone":
return new RedstoneParticle($playerPos);
case "rainsplashparticle":
case "rainsplash":
case "rain":
return new RainSplashParticle($playerPos);
// s
case "smokeparticle":
case "smoke":
return new SmokeParticle($playerPos);
case "splashparticle":
case "splash":
return new SplashParticle($playerPos);
case "enchantparticle":
case "enchant":
return new EnchantParticle($playerPos);
case "sporeparticle":
case "spore":
return new SporeParticle($playerPos);
// t
// u
// v
// w
case "waterparticle":
case "water":
return new WaterParticle($playerPos);
// x
// y
// z
endswitch;
}
}
69 changes: 69 additions & 0 deletions src/AGTHARN/FlyPE/tasks/ParticleTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* ______ _ __ _______ ______
* | ____| | \ \ / / __ \| ____|
* | |__ | | \ \_/ /| |__) | |__
* | __| | | \ / | ___/| __|
* | | | |____| | | | | |____
* |_| |______|_| |_| |______|
*
* FlyPE, is an advanced fly plugin for PMMP.
* Copyright (C) 2020 AGTHARN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace AGTHARN\FlyPE\tasks;

use pocketmine\scheduler\Task;
use pocketmine\utils\TextFormat as C;
use pocketmine\math\Vector3;

use AGTHARN\FlyPE\tasks\ParticleTask;
use AGTHARN\FlyPE\Main;

class ParticleTask extends Task {

/**
* plugin
*
* @var Main
*/
private $plugin;

/**
* __construct
*
* @param Main $plugin
* @return void
*/
public function __construct(Main $plugin) {
$this->plugin = $plugin;
}

/**
* onRun
*
* @param int $tick
* @return void
*/
public function onRun(int $tick): void {
foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) {
if ($player->getAllowFlight() === true && $this->plugin->getConfig()->get("enableflyparticles") === true) {
$player->getLevel()->addParticle($this->plugin->getParticleList()->getParticle($this->plugin->getConfig()->get("flyparticletype"), new Vector3($player->x, $player->y, $player->z)));
}
}
}
}

0 comments on commit eb471ff

Please sign in to comment.