From 37b67af09c1cc57f8349edf1b6976d1e39ff8170 Mon Sep 17 00:00:00 2001 From: "Mr. Piggy" Date: Wed, 27 Dec 2017 13:46:12 -0800 Subject: [PATCH] Now using PMMP's Enchantment Registering function --- .../CustomEnchants/CustomEnchants.php | 161 ++----------- .../CustomEnchants/CustomEnchantsIds.php | 121 ++++++++++ src/PiggyCustomEnchants/EventListener.php | 146 ++++++------ src/PiggyCustomEnchants/Main.php | 215 ++++++++---------- src/PiggyCustomEnchants/Tasks/CactusTask.php | 4 +- src/PiggyCustomEnchants/Tasks/ChickenTask.php | 4 +- src/PiggyCustomEnchants/Tasks/EffectTask.php | 16 +- .../Tasks/ForcefieldTask.php | 4 +- .../Tasks/ImplantsTask.php | 5 +- src/PiggyCustomEnchants/Tasks/JetpackTask.php | 4 +- .../Tasks/MeditationTask.php | 4 +- .../Tasks/ParachuteTask.php | 4 +- src/PiggyCustomEnchants/Tasks/ProwlTask.php | 4 +- src/PiggyCustomEnchants/Tasks/RadarTask.php | 4 +- src/PiggyCustomEnchants/Tasks/SizeTask.php | 6 +- src/PiggyCustomEnchants/Tasks/SpiderTask.php | 5 +- .../Tasks/UseEnchantedBookTask.php | 2 +- src/PiggyCustomEnchants/Tasks/VacuumTask.php | 4 +- 18 files changed, 335 insertions(+), 378 deletions(-) create mode 100644 src/PiggyCustomEnchants/CustomEnchants/CustomEnchantsIds.php diff --git a/src/PiggyCustomEnchants/CustomEnchants/CustomEnchants.php b/src/PiggyCustomEnchants/CustomEnchants/CustomEnchants.php index d5dc1958..25109f69 100644 --- a/src/PiggyCustomEnchants/CustomEnchants/CustomEnchants.php +++ b/src/PiggyCustomEnchants/CustomEnchants/CustomEnchants.php @@ -1,161 +1,36 @@ $enchantment) { + $vanillaenchants[$id] = $enchantment; + } + parent::$enchantments = $vanillaenchants; } /** - * @param $name - * @return null|CustomEnchants + * @param string $name + * + * @return Enchantment|null */ - public static function getEnchantmentByName(string $name) - { - $const = CustomEnchants::class . "::" . strtoupper($name); - if (defined($const)) { + public static function getEnchantmentByName(string $name){ + $const = CustomEnchantsIds::class . "::" . strtoupper($name); + if(defined($const)){ return self::getEnchantment(constant($const)); } return null; } - - } \ No newline at end of file diff --git a/src/PiggyCustomEnchants/CustomEnchants/CustomEnchantsIds.php b/src/PiggyCustomEnchants/CustomEnchants/CustomEnchantsIds.php new file mode 100644 index 00000000..8ae76e14 --- /dev/null +++ b/src/PiggyCustomEnchants/CustomEnchants/CustomEnchantsIds.php @@ -0,0 +1,121 @@ +getPlayer(); - if (isset($this->plugin->flying[$player->getLowerCaseName()]) || $this->plugin->getEnchantment($player->getInventory()->getChestplate(), CustomEnchants::SPIDER) !== null) { + if (isset($this->plugin->flying[$player->getLowerCaseName()]) || $player->getInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::SPIDER) !== null) { $event->setCancelled(); } } @@ -256,7 +256,7 @@ public function onKick(PlayerKickEvent $event) $player = $event->getPlayer(); $reason = $event->getReason(); if ($reason == "Flying is not enabled on this server") { - if (isset($this->plugin->flying[$player->getLowerCaseName()]) || $this->plugin->getEnchantment($player->getInventory()->getChestplate(), CustomEnchants::SPIDER) !== null) { + if (isset($this->plugin->flying[$player->getLowerCaseName()]) || $player->getInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::SPIDER) !== null) { $event->setCancelled(); } } @@ -396,7 +396,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even { //TODO: Check to make sure you can use enchant with item if ($event instanceof EntityDamageEvent) { - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::LIFESTEAL); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::LIFESTEAL); if ($enchantment !== null) { if ($damager->getHealth() + 2 + $enchantment->getLevel() <= $damager->getMaxHealth()) { $damager->setHealth($damager->getHealth() + 2 + $enchantment->getLevel()); @@ -404,7 +404,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even $damager->setHealth($damager->getMaxHealth()); } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::BLIND); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BLIND); if ($enchantment !== null && $entity->hasEffect(Effect::BLINDNESS) !== true) { $effect = Effect::getEffect(Effect::BLINDNESS); $effect->setAmplifier(0); @@ -412,17 +412,17 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even $effect->setVisible(false); $entity->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::DEATHBRINGER); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::DEATHBRINGER); if ($enchantment !== null) { $damage = 2 + ($enchantment->getLevel() / 10); $event->setDamage($event->getDamage() + $damage); } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::GOOEY); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::GOOEY); if ($enchantment !== null) { $task = new GoeyTask($this->plugin, $entity, $enchantment->getLevel()); $this->plugin->getServer()->getScheduler()->scheduleDelayedTask($task, 1); } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::POISON); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::POISON); if ($enchantment !== null && $entity->hasEffect(Effect::POISON) !== true) { $effect = Effect::getEffect(Effect::POISON); $effect->setAmplifier($enchantment->getLevel()); @@ -430,7 +430,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even $effect->setVisible(false); $entity->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::CRIPPLINGSTRIKE); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::CRIPPLINGSTRIKE); if ($enchantment !== null) { if (!$entity->hasEffect(Effect::NAUSEA)) { $effect = Effect::getEffect(Effect::NAUSEA); @@ -447,7 +447,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even $entity->addEffect($effect); } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::VAMPIRE); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::VAMPIRE); if ($enchantment !== null) { if (!isset($this->plugin->vampirecd[$damager->getLowerCaseName()]) || time() > $this->plugin->vampirecd[$damager->getLowerCaseName()]) { $this->plugin->vampirecd[$damager->getLowerCaseName()] = time() + 5; @@ -463,19 +463,19 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even } } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::CHARGE); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::CHARGE); if ($enchantment !== null) { if ($damager->isSprinting()) { $event->setDamage($event->getDamage() * (1 + 0.10 * $enchantment->getLevel())); } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::AERIAL); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::AERIAL); if ($enchantment !== null) { if (!$damager->isOnGround()) { $event->setDamage($event->getDamage() * (1 + 0.10 * $enchantment->getLevel())); } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::WITHER); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::WITHER); if ($enchantment !== null && $entity->hasEffect(Effect::WITHER) !== true) { $effect = Effect::getEffect(Effect::WITHER); $effect->setAmplifier($enchantment->getLevel()); @@ -483,7 +483,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even $effect->setVisible(false); $entity->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::DISARMING); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::DISARMING); if ($enchantment !== null) { if ($entity instanceof Player) { $chance = 10 * $enchantment->getLevel(); @@ -496,7 +496,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even } } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::HALLUCINATION); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HALLUCINATION); if ($enchantment !== null) { $chance = 5 * $enchantment->getLevel(); $random = mt_rand(0, 100); @@ -507,7 +507,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even $task->setHandler($handler); } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::BLESSED); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BLESSED); if ($enchantment !== null) { $chance = 15 * $enchantment->getLevel(); $random = mt_rand(0, 100); @@ -519,7 +519,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even } } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::DISARMOR); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::DISARMOR); if ($enchantment !== null) { if ($entity instanceof Player) { $chance = 10 * $enchantment->getLevel(); @@ -540,13 +540,13 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even } } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::BACKSTAB); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BACKSTAB); if ($enchantment !== null) { if ($damager->getDirectionVector()->dot($entity->getDirectionVector()) > 0) { $event->setDamage($event->getDamage() * (1 + 0.10 * $enchantment->getLevel())); } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::LIGHTNING); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::LIGHTNING); if ($enchantment !== null) { $chance = 10 * $enchantment->getLevel(); $random = mt_rand(0, 100); @@ -562,7 +562,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even $soulbounded = []; $soulboundedarmor = []; foreach ($damager->getInventory()->getContents() as $k => $item) { - $enchantment = $this->plugin->getEnchantment($item, CustomEnchants::SOULBOUND); + $enchantment = $item->getEnchantment(CustomEnchantsIds::SOULBOUND); if ($enchantment !== null) { $index = array_search($item, $drops); if ($index !== false) { @@ -572,7 +572,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even } } foreach ($damager->getInventory()->getArmorContents() as $k => $item) { - $enchantment = $this->plugin->getEnchantment($item, CustomEnchants::SOULBOUND); + $enchantment = $item->getEnchantment(CustomEnchantsIds::SOULBOUND); if ($enchantment !== null) { $index = array_search($item, $drops); if ($index !== false) { @@ -591,7 +591,7 @@ public function checkGlobalEnchants(Player $damager, Entity $entity = null, Even } if ($event instanceof PlayerMoveEvent) { foreach ($damager->getInventory()->getContents() as $slot => $item) { - $enchantment = $this->plugin->getEnchantment($item, CustomEnchants::AUTOREPAIR); + $enchantment = $item->getEnchantment(CustomEnchantsIds::AUTOREPAIR); if ($enchantment !== null) { $newDir = $item->getDamage() - (1 + (1 * $enchantment->getLevel())); if ($newDir < 0) { @@ -614,7 +614,7 @@ public function checkToolEnchants(Player $player, Event $event) if ($event instanceof BlockBreakEvent) { $block = $event->getBlock(); $drops = $event->getDrops(); - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::EXPLOSIVE); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::EXPLOSIVE); if ($enchantment !== null) { if (!isset($this->plugin->using[$player->getLowerCaseName()]) || $this->plugin->using[$player->getLowerCaseName()] < time()) { $this->plugin->using[$player->getLowerCaseName()] = time() + 1; @@ -623,7 +623,7 @@ public function checkToolEnchants(Player $player, Event $event) $explosion->explodeB(); } } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::LUMBERJACK); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::LUMBERJACK); if ($enchantment !== null) { if ($player->isSneaking()) { if ($block->getId() == Block::WOOD || $block->getId() == Block::WOOD2) { @@ -635,7 +635,7 @@ public function checkToolEnchants(Player $player, Event $event) } $event->setInstaBreak(true); } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::DRILLER); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::DRILLER); if ($enchantment !== null) { if (!isset($this->plugin->using[$player->getLowerCaseName()]) || $this->plugin->using[$player->getLowerCaseName()] < time()) { if (isset($this->plugin->blockface[$player->getLowerCaseName()])) { @@ -668,7 +668,7 @@ public function checkToolEnchants(Player $player, Event $event) } $event->setInstaBreak(true); } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::JACKPOT); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::JACKPOT); if ($enchantment !== null) { $chance = 10 * $enchantment->getLevel(); $random = mt_rand(0, 100); @@ -692,7 +692,7 @@ public function checkToolEnchants(Player $player, Event $event) } } } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::SMELTING); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::SMELTING); if ($enchantment !== null) { $finaldrop = array(); $otherdrops = array(); @@ -740,7 +740,7 @@ public function checkToolEnchants(Player $player, Event $event) } $event->setDrops($drops = array_merge($finaldrop, $otherdrops)); } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::ENERGIZING); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::ENERGIZING); if ($enchantment !== null && $player->hasEffect(Effect::HASTE) !== true) { $effect = Effect::getEffect(Effect::HASTE); $effect->setAmplifier(1 + $enchantment->getLevel() - 2); @@ -748,7 +748,7 @@ public function checkToolEnchants(Player $player, Event $event) $effect->setVisible(false); $player->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::QUICKENING); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::QUICKENING); if ($enchantment !== null && $player->hasEffect(Effect::SPEED) !== true) { $effect = Effect::getEffect(Effect::SPEED); $effect->setAmplifier(3 + $enchantment->getLevel() - 2); @@ -756,14 +756,14 @@ public function checkToolEnchants(Player $player, Event $event) $effect->setVisible(false); $player->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::TELEPATHY); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::TELEPATHY); if ($enchantment !== null) { foreach ($drops as $drop) { $player->getInventory()->addItem($drop); } $event->setDrops([]); } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::FARMER); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::FARMER); if ($enchantment !== null) { $seed = null; switch ($block->getId()) { @@ -786,7 +786,7 @@ public function checkToolEnchants(Player $player, Event $event) $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new PlaceTask($this->plugin, $pos, $block->getLevel(), $seed, $player), 1); } } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::HARVEST); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HARVEST); if ($enchantment !== null) { $radius = $enchantment->getLevel(); if (!isset($this->plugin->using[$player->getLowerCaseName()]) || $this->plugin->using[$player->getLowerCaseName()] < time()) { @@ -807,7 +807,7 @@ public function checkToolEnchants(Player $player, Event $event) } if ($event instanceof PlayerInteractEvent) { $block = $event->getBlock(); - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::FERTILIZER); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::FERTILIZER); if ($enchantment !== null) { if (!isset($this->plugin->using[$player->getLowerCaseName()]) || $this->plugin->using[$player->getLowerCaseName()] < time()) { if ($this->plugin->checkBlocks($block, [Block::DIRT, Block::GRASS])) { @@ -836,7 +836,7 @@ public function checkToolEnchants(Player $player, Event $event) public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $event) { if ($event instanceof EntityDamageByChildEntityEvent) { - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::MOLOTOV); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::MOLOTOV); if ($enchantment !== null) { $boundaries = 0.1 * $enchantment->getLevel(); for ($x = $boundaries; $x >= -$boundaries; $x -= 0.1) { @@ -847,7 +847,7 @@ public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $e } } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::PARALYZE); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::PARALYZE); if ($enchantment !== null) { if (!$entity->hasEffect(Effect::SLOWNESS)) { $effect = Effect::getEffect(Effect::SLOWNESS); @@ -871,11 +871,11 @@ public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $e $entity->addEffect($effect); } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::PIERCING); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::PIERCING); if ($enchantment !== null) { $event->setDamage(0, EntityDamageEvent::MODIFIER_ARMOR); } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::SHUFFLE); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::SHUFFLE); if ($enchantment !== null) { $pos1 = clone $damager->getPosition(); $pos2 = clone $entity->getPosition(); @@ -888,7 +888,7 @@ public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $e } $damager->sendMessage(TextFormat::DARK_PURPLE . "You have switched positions with " . $name); } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::BOUNTYHUNTER); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BOUNTYHUNTER); if ($enchantment !== null) { if (!isset($this->plugin->bountyhuntercd[$damager->getLowerCaseName()]) || time() > $this->plugin->bountyhuntercd[$damager->getLowerCaseName()]) { $bountydrop = $this->getBounty(); @@ -896,7 +896,7 @@ public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $e $this->plugin->bountyhuntercd[$damager->getLowerCaseName()] = time() + 30; } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::HEALING); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HEALING); if ($enchantment !== null) { if ($entity->getHealth() + $event->getDamage() + $enchantment->getLevel() <= $entity->getMaxHealth()) { $entity->setHealth($entity->getHealth() + $event->getDamage() + $enchantment->getLevel()); @@ -905,21 +905,21 @@ public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $e } $event->setDamage(0); } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::HEADHUNTER); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HEADHUNTER); if ($enchantment !== null) { $projectile = $event->getChild(); if ($projectile->y > $entity->getPosition()->y + $entity->getEyeHeight()) { $event->setDamage($event->getDamage() * (1 + 0.10 * $enchantment->getLevel())); } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::GRAPPLING); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::GRAPPLING); if ($enchantment !== null) { $task = new GrapplingTask($this->plugin, $damager->getPosition(), $entity); $this->plugin->getServer()->getScheduler()->scheduleDelayedTask($task, 1); //Delayed due to knockback interfering } } if ($event instanceof EntityShootBowEvent) { - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::BLAZE); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BLAZE); if ($enchantment !== null && $entity instanceof Fireball !== true) { $nbt = Entity::createBaseNBT($entity, $damager->getDirectionVector(), $entity->yaw, $entity->pitch); $fireball = Entity::createEntity("Fireball", $damager->getLevel(), $nbt, $damager); @@ -928,7 +928,7 @@ public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $e $entity->close(); $entity = $fireball; } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::PORKIFIED); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::PORKIFIED); if ($enchantment !== null && $entity instanceof PigProjectile !== true) { $nbt = Entity::createBaseNBT($entity, $damager->getDirectionVector(), $entity->yaw, $entity->pitch); $pig = Entity::createEntity("PigProjectile", $damager->getLevel(), $nbt, $damager, $enchantment->getLevel()); @@ -937,7 +937,7 @@ public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $e $entity->close(); $entity = $pig; } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::VOLLEY); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::VOLLEY); if ($enchantment !== null) { $amount = 1 + 2 * $enchantment->getLevel(); $anglesbetweenarrows = (45 / ($amount - 1)) * M_PI / 180; @@ -973,7 +973,7 @@ public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $e } if ($event instanceof ProjectileHitEvent && $entity instanceof Projectile) { if ($entity->hadCollision) { - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::GRAPPLING); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::GRAPPLING); if ($enchantment !== null) { $location = $entity->getPosition(); $damagerloc = $damager->getPosition(); @@ -998,7 +998,7 @@ public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $e $this->plugin->nofall[$damager->getLowerCaseName()] = time() + 1; } } - $enchantment = $this->plugin->getEnchantment($damager->getInventory()->getItemInHand(), CustomEnchants::MISSILE); + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::MISSILE); if ($enchantment !== null) { for ($i = 0; $i <= $enchantment->getLevel(); $i++) { $tnt = Entity::createEntity("PrimedTNT", $entity->getLevel(), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $entity->x), new DoubleTag("", $entity->y), new DoubleTag("", $entity->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 40)])); @@ -1022,7 +1022,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) $cause = $event->getCause(); $antikb = 4; if ($cause == EntityDamageEvent::CAUSE_FALL) { - $enchantment = $this->plugin->getEnchantment($entity->getInventory()->getBoots(), CustomEnchants::STOMP); + $enchantment = $entity->getInventory()->getBoots()->getEnchantment(CustomEnchantsIds::STOMP); if ($enchantment !== null) { $entities = $entity->getLevel()->getNearbyEntities($entity->getBoundingBox()); foreach ($entities as $e) { @@ -1039,7 +1039,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) } } foreach ($entity->getInventory()->getArmorContents() as $slot => $armor) { - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::REVIVE); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::REVIVE); if ($enchantment !== null) { if ($event->getDamage() >= $entity->getHealth()) { $entity->getInventory()->setArmorItem($slot, $this->plugin->removeEnchantment($armor, $enchantment)); @@ -1052,7 +1052,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) //TODO: Side effect } } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::SELFDESTRUCT); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::SELFDESTRUCT); if ($enchantment !== null) { if ($event->getDamage() >= $entity->getHealth()) { //Compatibility for plugins that auto respawn players on death for ($i = $enchantment->getLevel(); $i >= 0; $i--) { @@ -1061,7 +1061,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) } } } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::ENDERSHIFT); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::ENDERSHIFT); if ($enchantment !== null) { if ($entity->getHealth() - $event->getDamage() <= 4) { if (!isset($this->plugin->endershiftcd[$entity->getLowerCaseName()]) || time() > $this->plugin->endershiftcd[$entity->getLowerCaseName()]) { @@ -1084,7 +1084,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) } } } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::BERSERKER); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::BERSERKER); if ($enchantment !== null) { if ($entity->getHealth() - $event->getDamage() <= 4) { if ((!isset($this->plugin->berserkercd[$entity->getLowerCaseName()]) || time() > $this->plugin->berserkercd[$entity->getLowerCaseName()]) && $entity->hasEffect(Effect::STRENGTH) !== true) { @@ -1102,11 +1102,11 @@ public function checkArmorEnchants(Entity $entity, Event $event) if ($event instanceof EntityDamageByEntityEvent) { $damager = $event->getDamager(); foreach ($entity->getInventory()->getArmorContents() as $slot => $armor) { - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::MOLTEN); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::MOLTEN); if ($enchantment !== null) { $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new MoltenTask($this->plugin, $damager, $enchantment->getLevel()), 1); } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::ENLIGHTED); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::ENLIGHTED); if ($enchantment !== null && $entity->hasEffect(Effect::REGENERATION) !== true) { $effect = Effect::getEffect(Effect::REGENERATION); $effect->setAmplifier($enchantment->getLevel()); @@ -1114,7 +1114,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) $effect->setVisible(false); $entity->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::HARDENED); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::HARDENED); if ($enchantment !== null && $damager->hasEffect(Effect::WEAKNESS) !== true) { $effect = Effect::getEffect(Effect::WEAKNESS); $effect->setAmplifier($enchantment->getLevel()); @@ -1122,7 +1122,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) $effect->setVisible(false); $damager->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::POISONED); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::POISONED); if ($enchantment !== null && $damager->hasEffect(Effect::POISON) !== true) { $effect = Effect::getEffect(Effect::POISON); $effect->setAmplifier($enchantment->getLevel()); @@ -1130,7 +1130,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) $effect->setVisible(false); $damager->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::FROZEN); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::FROZEN); if ($enchantment !== null && $damager->hasEffect(Effect::SLOWNESS) !== true) { $effect = Effect::getEffect(Effect::SLOWNESS); $effect->setAmplifier($enchantment->getLevel()); @@ -1138,7 +1138,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) $effect->setVisible(false); $damager->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::REVULSION); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::REVULSION); if ($enchantment !== null && $damager->hasEffect(Effect::NAUSEA) !== true) { $effect = Effect::getEffect(Effect::NAUSEA); $effect->setAmplifier(0); @@ -1146,7 +1146,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) $effect->setVisible(false); $damager->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::CURSED); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::CURSED); if ($enchantment !== null && $damager->hasEffect(Effect::WITHER) !== true) { $effect = Effect::getEffect(Effect::WITHER); $effect->setAmplifier($enchantment->getLevel()); @@ -1154,7 +1154,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) $effect->setVisible(false); $damager->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::DRUNK); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::DRUNK); if ($enchantment !== null) { if (!$damager->hasEffect(Effect::SLOWNESS)) { $effect = Effect::getEffect(Effect::SLOWNESS); @@ -1178,7 +1178,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) $damager->addEffect($effect); } } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::CLOAKING); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::CLOAKING); if ($enchantment !== null) { if ((!isset($this->plugin->cloakingcd[$entity->getLowerCaseName()]) || time() > $this->plugin->cloakingcd[$entity->getLowerCaseName()]) && $entity->hasEffect(Effect::INVISIBILITY)) { $this->plugin->cloakingcd[$entity->getLowerCaseName()] = time() + 10; @@ -1190,25 +1190,25 @@ public function checkArmorEnchants(Entity $entity, Event $event) $entity->sendMessage(TextFormat::DARK_GRAY . "You have become invisible!"); } } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::ANTIKNOCKBACK); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::ANTIKNOCKBACK); if ($enchantment !== null) { $event->setKnockBack($event->getKnockBack() - ($event->getKnockBack() / $antikb)); $antikb--; } if ($damager instanceof Player) { - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::ARMORED); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::ARMORED); if ($enchantment !== null) { if ($damager->getInventory()->getItemInHand()->isSword()) { $event->setDamage($damage - ($damage * 0.2 * $enchantment->getLevel())); } } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::TANK); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::TANK); if ($enchantment !== null) { if ($damager->getInventory()->getItemInHand()->isAxe()) { $event->setDamage($damage - ($damage * 0.2 * $enchantment->getLevel())); } } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::HEAVY); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::HEAVY); if ($enchantment !== null) { if ($damager->getInventory()->getItemInHand()->getId() == Item::BOW) { $event->setDamage($damage - ($damage * 0.2 * $enchantment->getLevel())); @@ -1220,7 +1220,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) } if ($event instanceof EntityEffectAddEvent) { $effect = $event->getEffect(); - $enchantment = $this->plugin->getEnchantment($entity->getInventory()->getHelmet(), CustomEnchants::FOCUSED); + $enchantment = $entity->getInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::FOCUSED); if ($enchantment !== null) { if (!isset($this->plugin->using[$entity->getLowerCaseName()]) || $this->plugin->using[$entity->getLowerCaseName()] < time()) { if ($effect->getId() == Effect::NAUSEA) { @@ -1234,7 +1234,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) } } } - $enchantment = $this->plugin->getEnchantment($entity->getInventory()->getHelmet(), CustomEnchants::ANTITOXIN); + $enchantment = $entity->getInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::ANTITOXIN); if ($enchantment !== null) { if ($effect->getId() == Effect::POISON) { $event->setCancelled(); @@ -1242,7 +1242,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) } } if ($event instanceof PlayerMoveEvent) { - $enchantment = $this->plugin->getEnchantment($entity->getInventory()->getBoots(), CustomEnchants::MAGMAWALKER); + $enchantment = $entity->getInventory()->getBoots()->getEnchantment(CustomEnchantsIds::MAGMAWALKER); if ($enchantment !== null) { $block = $entity->getLevel()->getBlock($entity); if (!$this->plugin->checkBlocks($block, [Block::STILL_LAVA, Block::LAVA, Block::FLOWING_LAVA])) { @@ -1262,13 +1262,13 @@ public function checkArmorEnchants(Entity $entity, Event $event) } } } - $enchantment = $this->plugin->getEnchantment($entity->getInventory()->getHelmet(), CustomEnchants::MEDITATION); + $enchantment = $entity->getInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::MEDITATION); if ($enchantment !== null) { if ($event->getFrom()->floor() !== $event->getTo()->floor()) { $this->plugin->meditationTick[$entity->getLowerCaseName()] = 0; } } - $enchantment = $this->plugin->getEnchantment($entity->getInventory()->getHelmet(), CustomEnchants::IMPLANTS); + $enchantment = $entity->getInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::IMPLANTS); if ($enchantment !== null) { if ($event->getFrom()->floor() !== $event->getTo()->floor()) { if (!isset($this->plugin->implantscd[$entity->getLowerCaseName()]) || $this->plugin->implantscd[$entity->getLowerCaseName()] < time()) { @@ -1292,12 +1292,12 @@ public function checkArmorEnchants(Entity $entity, Event $event) $shrinklevel = 0; $growlevel = 0; foreach ($entity->getInventory()->getArmorContents() as $armor) { - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::SHRINK); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::SHRINK); if ($enchantment !== null) { $shrinklevel += $enchantment->getLevel(); $shrinkpoints++; } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::GROW); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::GROW); if ($enchantment !== null) { $growlevel += $enchantment->getLevel(); $growpoints++; @@ -1343,7 +1343,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) } } } - $enchantment = $this->plugin->getEnchantment($entity->getInventory()->getBoots(), CustomEnchants::JETPACK); + $enchantment = $entity->getInventory()->getBoots()->getEnchantment(CustomEnchantsIds::JETPACK); if ($enchantment !== null) { if (isset($this->plugin->flying[$entity->getLowerCaseName()]) && $this->plugin->flying[$entity->getLowerCaseName()] > time()) { if ($entity->isOnGround()) { @@ -1376,7 +1376,7 @@ public function checkArmorEnchants(Entity $entity, Event $event) $action = $packet->action; switch ($action) { case 8: - $enchantment = $this->plugin->getEnchantment($entity->getInventory()->getBoots(), CustomEnchants::SPRINGS); + $enchantment = $entity->getInventory()->getBoots()->getEnchantment(CustomEnchantsIds::SPRINGS); if ($enchantment !== null) { $entity->setMotion(new Vector3(0, $entity->getJumpVelocity() + 0.4)); $this->plugin->nofall[$entity->getLowerCaseName()] = time() + 1; diff --git a/src/PiggyCustomEnchants/Main.php b/src/PiggyCustomEnchants/Main.php index 3e7d0d77..f6529ca6 100644 --- a/src/PiggyCustomEnchants/Main.php +++ b/src/PiggyCustomEnchants/Main.php @@ -5,6 +5,7 @@ use PiggyCustomEnchants\Blocks\PiggyObsidian; use PiggyCustomEnchants\Commands\CustomEnchantCommand; use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Entities\Fireball; use PiggyCustomEnchants\Entities\Lightning; use PiggyCustomEnchants\Entities\PigProjectile; @@ -122,90 +123,90 @@ class Main extends PluginBase public $enchants = [ //id => ["name", "slot", "trigger", "rarity", maxlevel", "description"] - CustomEnchants::ANTIKNOCKBACK => ["Anti Knockback", "Armor", "Damage", "Rare", 1, "Reduces knockback by 25% per armor piece"], - CustomEnchants::ANTITOXIN => ["Antitoxin", "Helmets", "Effect", "Mythic", 1, "Immunity to poison"], - CustomEnchants::AERIAL => ["Aerial", "Weapons", "Damage", "Common", 5, "Increases damage in air"], - CustomEnchants::ARMORED => ["Armored", "Armor", "Damage", "Rare", 5, "Decreases sword damage by 20l%"], - CustomEnchants::AUTOREPAIR => ["Autorepair", "Damageable", "Move", "Uncommon", 5, "Automatically repairs items when moving"], - CustomEnchants::BACKSTAB => ["Backstab", "Weapons", "Damage", "Uncommon", 5, "When hitting from behind, you deal more damage."], - CustomEnchants::BERSERKER => ["Berserker", "Armor", "Damaged", "Rare", 5, "Gives strength on low health"], - CustomEnchants::BLESSED => ["Blessed", "Weapons", "Damage", "Uncommon", 3, "15l% (l = level) chance to remove bad effects"], - CustomEnchants::BLAZE => ["Blaze", "Bow", "Shoot", "Rare", 1, "Shoots fireballs"], - CustomEnchants::BLIND => ["Blind", "Weapons", "Damage", "Common", 5, "Gives enemies blindness"], - CustomEnchants::BOUNTYHUNTER => ["Bounty Hunter", "Bow", "Damage", "Uncommon", 5, "Collect bounties (items) when hitting enemies."], - CustomEnchants::CACTUS => ["Cactus", "Armor", "Equip", "Rare", 1, "Poke people around you", "Poke people around you"], - CustomEnchants::CHARGE => ["Charge", "Weapons", "Damage", "Uncommon", 5, "Increases damage when sprinting"], - CustomEnchants::CHICKEN => ["Chicken", "Chestplate", "Equip", "Uncommon", 5, "Lays egg every 5 minutes, 5l% (l = level) chance of rare drop"], - CustomEnchants::CLOAKING => ["Cloaking", "Armor", "Damaged", "Uncommon", 5, "Becomes invisible when hit"], - CustomEnchants::CRIPPLINGSTRIKE => ["Cripple", "Weapons", "Damage", "Common", 5, "Gives enemies nausea and slowness"], - CustomEnchants::CRIPPLE => ["Cripple", "Weapons", "Damage", "Common", 5, "Gives enemies nausea and slowness"], - CustomEnchants::CURSED => ["Cursed", "Armor", "Damaged", "Uncommon", 5, "Gives wither to enemy when hit"], - CustomEnchants::DEATHBRINGER => ["Deathbringer", "Weapons", "Damage", "Rare", 5, "Increases damage"], - CustomEnchants::DISARMING => ["Disarming", "Weapons", "Damage", "Uncommon", 5, "10l% chance to disarm enemy"], - CustomEnchants::DISARMOR => ["Disarmor", "Weapons", "Damage", "Uncommon", 5, "10l% chance to disarmor enemy"], - CustomEnchants::DRILLER => ["Driller", "Tools", "Break", "Uncommon", 5, "Breaks a 3 by 3 by 1 + level"], - CustomEnchants::DRUNK => ["Drunk", "Armor", "Damaged", "Rare", 5, "Gives slowness, mining fatigue, and nausea to enemy when hit"], - CustomEnchants::ENDERSHIFT => ["Endershift", "Armor", "Damaged", "Rare", 5, "Gives speed and extra health when low on health"], - CustomEnchants::ENERGIZING => ["Energizing", "Tools", "Break", "Uncommon", 5, "Gives haste when block is broken"], - CustomEnchants::ENLIGHTED => ["Enlighted", "Armor", "Damaged", "Uncommon", 5, "Gives regeneration when hit"], - CustomEnchants::ENRAGED => ["Enraged", "Chestplate", "Equip", "Rare", 5, "Strength per level"], - CustomEnchants::EXPLOSIVE => ["Explosive", "Tools", "Break", "Rare", 5, "Cause an explosion when block is broken"], - CustomEnchants::FARMER => ["Farmer", "Hoe", "Break", "Uncommon", 1, "Automatically regrows crops when harvested"], - CustomEnchants::FERTILIZER => ["Fertilizer", "Hoe", "Interact", "Uncommon", 3, "Creates farmland in a level radius around the block"], - CustomEnchants::FOCUSED => ["Focused", "Helmets", "Effect", "Uncommon", 5, "Nausea will affect you less"], - CustomEnchants::FORCEFIELD => ["Forcefield", "Armor", "Equip", "Mythic", 1, "Deflects projectiles and living entities in a 0.75x (x = # of armor pieces)"], - CustomEnchants::FROZEN => ["Frozen", "Armor", "Damaged", "Rare", 5, "Gives slowness to enemy when hit"], - CustomEnchants::GEARS => ["Gears", "Boots", "Equip", "Uncommon", 5, "Gives speed"], - CustomEnchants::GLOWING => ["Glowing", "Helmets", "Equip", "Common", 1, "Gives night vision"], - CustomEnchants::GOOEY => ["Gooey", "Weapons", "Damage", "Uncommon", 5, "Flings enemy into the air"], - CustomEnchants::GRAPPLING => ["Grappling", "Bow", "Projectile_Hit", "Rare", 1, "Pulls you to location of arrow. If enemy is hit, the enemy will be pulled to you."], - CustomEnchants::GROW => ["Grow", "Armor", "Sneak", "Uncommon", 5, "Increases size on sneak (Must be wearing full set of Grow armor)"], - CustomEnchants::HALLUCINATION => ["Hallucination", "Weapons", "Damage", "Mythic", 5, "5l% (l = level) chance of trapping enemies in a fake prison"], - CustomEnchants::HARDENED => ["Hardened", "Armor", "Damaged", "Uncommon", 5, "Gives weakness to enemy when hit"], - CustomEnchants::HASTE => ["Haste", "Tools", "Held", "Uncommon", 5, "Gives haste when held"], - CustomEnchants::HARVEST => ["Harvest", "Hoe", "Break", "Uncommon", 3, "Harvest crops in a level radius around the block"], - CustomEnchants::HEADHUNTER => ["Headhunter", "Bow", "Damage", "Uncommon", 5, "Increases damage if enemy is shot in the head"], - CustomEnchants::HEALING => ["Healing", "Bow", "Damage", "Rare", 5, "Heals target when shot"], - CustomEnchants::HEAVY => ["Heavy", "Armor", "Damage", "Rare", 5, "Decreases damage from axes by 20l%"], - CustomEnchants::IMPLANTS => ["Implants", "Helmets", "Move", "Rare", 5, "Replenishes hunger and air"], - CustomEnchants::JETPACK => ["Jetpack", "Boots", "Sneak", "Rare", 3, "Enable flying (you fly where you look) when you sneak."], - CustomEnchants::JACKPOT => ["Jackpot", "Tools", "Break", "Mythic", 10, "10l% chance to increase the ore tier"], - CustomEnchants::LIFESTEAL => ["Lifesteal", "Weapons", "Damage", "Common", 5, "Heals when damaging enemies"], - CustomEnchants::LIGHTNING => ["Lightning", "Weapons", "Damage", "Rare", 5, "10l% chance to strike enemies with lightning"], - CustomEnchants::LUMBERJACK => ["Lumberjack", "Axe", "Break", "Rare", 1, "Mines all logs connected to log when broken"], - CustomEnchants::MAGMAWALKER => ["Magma Walker", "Boots", "Move", "Uncommon", 2, "Turns lava into obsidian around you"], - CustomEnchants::MEDITATION => ["Meditation", "Helmets", "Equip", "Uncommon", 5, "Replenish health and hunger every 20 seconds (half a hunger bar/heart per level)"], - CustomEnchants::MISSILE => ["Missile", "Bow", "Projectile_Hit", "Rare", 5, "Spawns tnt on hit"], - CustomEnchants::MOLOTOV => ["Molotov", "Bow", "Projectile_Hit", "Uncommon", 5, "Starts fire around target"], - CustomEnchants::MOLTEN => ["Molten", "Armor", "Damaged", "Rare", 5, "Sets enemy on fire when hit"], - CustomEnchants::OBSIDIANSHIELD => ["Obsidian Shield", "Armor", "Equip", "Common", 5, "Gives fire resistance while worn"], - CustomEnchants::OVERLOAD => ["Overload", "Armor", "Equip", "Mythic", 3, "Gives 1 extra heart per level per armor piece"], - CustomEnchants::OXYGENATE => ["Oxygenate", "Tools", "Break", "Uncommon", 1, "Breathe underwater when held"], - CustomEnchants::PARACHUTE => ["Parachute", "Chestplate", "Equip", "Uncommon", 1, "Slows your fall (above 3 blocks)s"], - CustomEnchants::PARALYZE => ["Paralyze", "Bow", "Damage", "Rare", 5, "Gives slowness, blindness, and weakness"], - CustomEnchants::PIERCING => ["Piercing", "Bow", "Damage", "Rare", 5, "Ignores armor when dealing damage"], - CustomEnchants::POISON => ["Poison", "Weapons", "Damage", "Uncommon", 5, "Poisons enemies"], - CustomEnchants::POISONED => ["Poisoned", "Armor", "Damaged", "Uncommon", 5, "Poisons enemy when hit"], - CustomEnchants::PORKIFIED => ["Porkified", "Bow", "Shoot", "Mythic", 3, "Shoot pigs"], - CustomEnchants::PROWL => ["Prowl", "Chestplate", "Equip", "Rare", 1, "Goes invisible when sneaking, gives slowness"], - CustomEnchants::QUICKENING => ["Quickening", "Tools", "Break", "Uncommon", 5, "Gives speed when block is broken"], - CustomEnchants::RADAR => ["Radar", "Compass", "Inventory", "Rare", 5, "Points to nearest player in a 50l (l = level) range."], - CustomEnchants::REVIVE => ["Revive", "Armor", "Death", "Rare", 5, "Will revive you when you die. (will remove enchantment)"], - CustomEnchants::REVULSION => ["Revulsion", "Armor", "Damaged", "Uncommon", 5, "Gives nausea to enemy when hit"], - CustomEnchants::SELFDESTRUCT => ["Self Destruct", "Armor", "Damaged", "Rare", 5, "Spawn TNT when you die."], - CustomEnchants::SHRINK => ["Shrink", "Armor", "Sneak", "Uncommon", 2, "Decreases size on sneak (Must be wearing full set of Shrink armor)"], - CustomEnchants::SHUFFLE => ["Shuffle", "Bow", "Damage", "Rare", 1, "Switches position with target"], - CustomEnchants::SMELTING => ["Smelting", "Tools", "Break", "Uncommon", 1, "Automatically smelts drops when broken"], - CustomEnchants::SOULBOUND => ["Soulbound", "Global", "Death", "Mythic", 1, "Keeps item after death (will remove enchantment)"], - CustomEnchants::SPIDER => ["Spider", "Chestplate", "Equip", "Rare", 1, "Climb walls"], - CustomEnchants::SPRINGS => ["Springs", "Boots", "Equip", "Uncommon", 5, "Gives a jump boost"], - CustomEnchants::STOMP => ["Stomp", "Boots", "Fall_Damage", "Uncommon", 5, "Deal part of fall damage to enemy when taking fall damage"], - CustomEnchants::TANK => ["Tank", "Armor", "Damage", "Uncommon", 5, "Spawn TNT when you die."], - CustomEnchants::TELEPATHY => ["Telepathy", "Tools", "Break", "Rare", 1, "Automatically puts drops in inventory."], - CustomEnchants::VACUUM => ["Vacuum", "Chestplate", "Equip", "Rare", 3, "Suck up items in a 3l radius"], - CustomEnchants::VAMPIRE => ["Vampire", "Weapons", "Damage", "Uncommon", 1, "Heals by part of damage dealt"], - CustomEnchants::VOLLEY => ["Volley", "Bow", "Shoot", "Uncommon", 5, "Shoot multiple arrows in a cone"], - CustomEnchants::WITHER => ["Wither", "Weapons", "Damage", "Uncommon", 5, "Gives enemies wither"] + CustomEnchantsIds::ANTIKNOCKBACK => ["Anti Knockback", "Armor", "Damage", "Rare", 1, "Reduces knockback by 25% per armor piece"], + CustomEnchantsIds::ANTITOXIN => ["Antitoxin", "Helmets", "Effect", "Mythic", 1, "Immunity to poison"], + CustomEnchantsIds::AERIAL => ["Aerial", "Weapons", "Damage", "Common", 5, "Increases damage in air"], + CustomEnchantsIds::ARMORED => ["Armored", "Armor", "Damage", "Rare", 5, "Decreases sword damage by 20l%"], + CustomEnchantsIds::AUTOREPAIR => ["Autorepair", "Damageable", "Move", "Uncommon", 5, "Automatically repairs items when moving"], + CustomEnchantsIds::BACKSTAB => ["Backstab", "Weapons", "Damage", "Uncommon", 5, "When hitting from behind, you deal more damage."], + CustomEnchantsIds::BERSERKER => ["Berserker", "Armor", "Damaged", "Rare", 5, "Gives strength on low health"], + CustomEnchantsIds::BLESSED => ["Blessed", "Weapons", "Damage", "Uncommon", 3, "15l% (l = level) chance to remove bad effects"], + CustomEnchantsIds::BLAZE => ["Blaze", "Bow", "Shoot", "Rare", 1, "Shoots fireballs"], + CustomEnchantsIds::BLIND => ["Blind", "Weapons", "Damage", "Common", 5, "Gives enemies blindness"], + CustomEnchantsIds::BOUNTYHUNTER => ["Bounty Hunter", "Bow", "Damage", "Uncommon", 5, "Collect bounties (items) when hitting enemies."], + CustomEnchantsIds::CACTUS => ["Cactus", "Armor", "Equip", "Rare", 1, "Poke people around you", "Poke people around you"], + CustomEnchantsIds::CHARGE => ["Charge", "Weapons", "Damage", "Uncommon", 5, "Increases damage when sprinting"], + CustomEnchantsIds::CHICKEN => ["Chicken", "Chestplate", "Equip", "Uncommon", 5, "Lays egg every 5 minutes, 5l% (l = level) chance of rare drop"], + CustomEnchantsIds::CLOAKING => ["Cloaking", "Armor", "Damaged", "Uncommon", 5, "Becomes invisible when hit"], + CustomEnchantsIds::CRIPPLINGSTRIKE => ["Cripple", "Weapons", "Damage", "Common", 5, "Gives enemies nausea and slowness"], + CustomEnchantsIds::CRIPPLE => ["Cripple", "Weapons", "Damage", "Common", 5, "Gives enemies nausea and slowness"], + CustomEnchantsIds::CURSED => ["Cursed", "Armor", "Damaged", "Uncommon", 5, "Gives wither to enemy when hit"], + CustomEnchantsIds::DEATHBRINGER => ["Deathbringer", "Weapons", "Damage", "Rare", 5, "Increases damage"], + CustomEnchantsIds::DISARMING => ["Disarming", "Weapons", "Damage", "Uncommon", 5, "10l% chance to disarm enemy"], + CustomEnchantsIds::DISARMOR => ["Disarmor", "Weapons", "Damage", "Uncommon", 5, "10l% chance to disarmor enemy"], + CustomEnchantsIds::DRILLER => ["Driller", "Tools", "Break", "Uncommon", 5, "Breaks a 3 by 3 by 1 + level"], + CustomEnchantsIds::DRUNK => ["Drunk", "Armor", "Damaged", "Rare", 5, "Gives slowness, mining fatigue, and nausea to enemy when hit"], + CustomEnchantsIds::ENDERSHIFT => ["Endershift", "Armor", "Damaged", "Rare", 5, "Gives speed and extra health when low on health"], + CustomEnchantsIds::ENERGIZING => ["Energizing", "Tools", "Break", "Uncommon", 5, "Gives haste when block is broken"], + CustomEnchantsIds::ENLIGHTED => ["Enlighted", "Armor", "Damaged", "Uncommon", 5, "Gives regeneration when hit"], + CustomEnchantsIds::ENRAGED => ["Enraged", "Chestplate", "Equip", "Rare", 5, "Strength per level"], + CustomEnchantsIds::EXPLOSIVE => ["Explosive", "Tools", "Break", "Rare", 5, "Cause an explosion when block is broken"], + CustomEnchantsIds::FARMER => ["Farmer", "Hoe", "Break", "Uncommon", 1, "Automatically regrows crops when harvested"], + CustomEnchantsIds::FERTILIZER => ["Fertilizer", "Hoe", "Interact", "Uncommon", 3, "Creates farmland in a level radius around the block"], + CustomEnchantsIds::FOCUSED => ["Focused", "Helmets", "Effect", "Uncommon", 5, "Nausea will affect you less"], + CustomEnchantsIds::FORCEFIELD => ["Forcefield", "Armor", "Equip", "Mythic", 1, "Deflects projectiles and living entities in a 0.75x (x = # of armor pieces)"], + CustomEnchantsIds::FROZEN => ["Frozen", "Armor", "Damaged", "Rare", 5, "Gives slowness to enemy when hit"], + CustomEnchantsIds::GEARS => ["Gears", "Boots", "Equip", "Uncommon", 5, "Gives speed"], + CustomEnchantsIds::GLOWING => ["Glowing", "Helmets", "Equip", "Common", 1, "Gives night vision"], + CustomEnchantsIds::GOOEY => ["Gooey", "Weapons", "Damage", "Uncommon", 5, "Flings enemy into the air"], + CustomEnchantsIds::GRAPPLING => ["Grappling", "Bow", "Projectile_Hit", "Rare", 1, "Pulls you to location of arrow. If enemy is hit, the enemy will be pulled to you."], + CustomEnchantsIds::GROW => ["Grow", "Armor", "Sneak", "Uncommon", 5, "Increases size on sneak (Must be wearing full set of Grow armor)"], + CustomEnchantsIds::HALLUCINATION => ["Hallucination", "Weapons", "Damage", "Mythic", 5, "5l% (l = level) chance of trapping enemies in a fake prison"], + CustomEnchantsIds::HARDENED => ["Hardened", "Armor", "Damaged", "Uncommon", 5, "Gives weakness to enemy when hit"], + CustomEnchantsIds::HASTE => ["Haste", "Tools", "Held", "Uncommon", 5, "Gives haste when held"], + CustomEnchantsIds::HARVEST => ["Harvest", "Hoe", "Break", "Uncommon", 3, "Harvest crops in a level radius around the block"], + CustomEnchantsIds::HEADHUNTER => ["Headhunter", "Bow", "Damage", "Uncommon", 5, "Increases damage if enemy is shot in the head"], + CustomEnchantsIds::HEALING => ["Healing", "Bow", "Damage", "Rare", 5, "Heals target when shot"], + CustomEnchantsIds::HEAVY => ["Heavy", "Armor", "Damage", "Rare", 5, "Decreases damage from axes by 20l%"], + CustomEnchantsIds::IMPLANTS => ["Implants", "Helmets", "Move", "Rare", 5, "Replenishes hunger and air"], + CustomEnchantsIds::JETPACK => ["Jetpack", "Boots", "Sneak", "Rare", 3, "Enable flying (you fly where you look) when you sneak."], + CustomEnchantsIds::JACKPOT => ["Jackpot", "Tools", "Break", "Mythic", 10, "10l% chance to increase the ore tier"], + CustomEnchantsIds::LIFESTEAL => ["Lifesteal", "Weapons", "Damage", "Common", 5, "Heals when damaging enemies"], + CustomEnchantsIds::LIGHTNING => ["Lightning", "Weapons", "Damage", "Rare", 5, "10l% chance to strike enemies with lightning"], + CustomEnchantsIds::LUMBERJACK => ["Lumberjack", "Axe", "Break", "Rare", 1, "Mines all logs connected to log when broken"], + CustomEnchantsIds::MAGMAWALKER => ["Magma Walker", "Boots", "Move", "Uncommon", 2, "Turns lava into obsidian around you"], + CustomEnchantsIds::MEDITATION => ["Meditation", "Helmets", "Equip", "Uncommon", 5, "Replenish health and hunger every 20 seconds (half a hunger bar/heart per level)"], + CustomEnchantsIds::MISSILE => ["Missile", "Bow", "Projectile_Hit", "Rare", 5, "Spawns tnt on hit"], + CustomEnchantsIds::MOLOTOV => ["Molotov", "Bow", "Projectile_Hit", "Uncommon", 5, "Starts fire around target"], + CustomEnchantsIds::MOLTEN => ["Molten", "Armor", "Damaged", "Rare", 5, "Sets enemy on fire when hit"], + CustomEnchantsIds::OBSIDIANSHIELD => ["Obsidian Shield", "Armor", "Equip", "Common", 5, "Gives fire resistance while worn"], + CustomEnchantsIds::OVERLOAD => ["Overload", "Armor", "Equip", "Mythic", 3, "Gives 1 extra heart per level per armor piece"], + CustomEnchantsIds::OXYGENATE => ["Oxygenate", "Tools", "Break", "Uncommon", 1, "Breathe underwater when held"], + CustomEnchantsIds::PARACHUTE => ["Parachute", "Chestplate", "Equip", "Uncommon", 1, "Slows your fall (above 3 blocks)s"], + CustomEnchantsIds::PARALYZE => ["Paralyze", "Bow", "Damage", "Rare", 5, "Gives slowness, blindness, and weakness"], + CustomEnchantsIds::PIERCING => ["Piercing", "Bow", "Damage", "Rare", 5, "Ignores armor when dealing damage"], + CustomEnchantsIds::POISON => ["Poison", "Weapons", "Damage", "Uncommon", 5, "Poisons enemies"], + CustomEnchantsIds::POISONED => ["Poisoned", "Armor", "Damaged", "Uncommon", 5, "Poisons enemy when hit"], + CustomEnchantsIds::PORKIFIED => ["Porkified", "Bow", "Shoot", "Mythic", 3, "Shoot pigs"], + CustomEnchantsIds::PROWL => ["Prowl", "Chestplate", "Equip", "Rare", 1, "Goes invisible when sneaking, gives slowness"], + CustomEnchantsIds::QUICKENING => ["Quickening", "Tools", "Break", "Uncommon", 5, "Gives speed when block is broken"], + CustomEnchantsIds::RADAR => ["Radar", "Compass", "Inventory", "Rare", 5, "Points to nearest player in a 50l (l = level) range."], + CustomEnchantsIds::REVIVE => ["Revive", "Armor", "Death", "Rare", 5, "Will revive you when you die. (will remove enchantment)"], + CustomEnchantsIds::REVULSION => ["Revulsion", "Armor", "Damaged", "Uncommon", 5, "Gives nausea to enemy when hit"], + CustomEnchantsIds::SELFDESTRUCT => ["Self Destruct", "Armor", "Damaged", "Rare", 5, "Spawn TNT when you die."], + CustomEnchantsIds::SHRINK => ["Shrink", "Armor", "Sneak", "Uncommon", 2, "Decreases size on sneak (Must be wearing full set of Shrink armor)"], + CustomEnchantsIds::SHUFFLE => ["Shuffle", "Bow", "Damage", "Rare", 1, "Switches position with target"], + CustomEnchantsIds::SMELTING => ["Smelting", "Tools", "Break", "Uncommon", 1, "Automatically smelts drops when broken"], + CustomEnchantsIds::SOULBOUND => ["Soulbound", "Global", "Death", "Mythic", 1, "Keeps item after death (will remove enchantment)"], + CustomEnchantsIds::SPIDER => ["Spider", "Chestplate", "Equip", "Rare", 1, "Climb walls"], + CustomEnchantsIds::SPRINGS => ["Springs", "Boots", "Equip", "Uncommon", 5, "Gives a jump boost"], + CustomEnchantsIds::STOMP => ["Stomp", "Boots", "Fall_Damage", "Uncommon", 5, "Deal part of fall damage to enemy when taking fall damage"], + CustomEnchantsIds::TANK => ["Tank", "Armor", "Damage", "Uncommon", 5, "Spawn TNT when you die."], + CustomEnchantsIds::TELEPATHY => ["Telepathy", "Tools", "Break", "Rare", 1, "Automatically puts drops in inventory."], + CustomEnchantsIds::VACUUM => ["Vacuum", "Chestplate", "Equip", "Rare", 3, "Suck up items in a 3l radius"], + CustomEnchantsIds::VAMPIRE => ["Vampire", "Weapons", "Damage", "Uncommon", 1, "Heals by part of damage dealt"], + CustomEnchantsIds::VOLLEY => ["Volley", "Bow", "Shoot", "Uncommon", 5, "Shoot multiple arrows in a cone"], + CustomEnchantsIds::WITHER => ["Wither", "Weapons", "Damage", "Uncommon", 5, "Gives enemies wither"] ]; public function onEnable() @@ -279,7 +280,7 @@ public function initCustomEnchants() CustomEnchants::init(); foreach ($this->enchants as $id => $data) { $ce = $this->translateDataToCE($id, $data); - CustomEnchants::registerEnchants($id, $ce); + CustomEnchants::registerEnchantment($ce); } } @@ -298,7 +299,7 @@ public function registerEnchantment($id, $name, $type, $trigger, $rarity, $maxle $data = [$name, $type, $trigger, $rarity, $maxlevel]; $this->enchants[$id] = $data; $ce = $this->translateDataToCE($id, $data); - CustomEnchants::registerEnchants($id, $ce); + CustomEnchants::registerEnchantment($ce); } /** @@ -352,7 +353,7 @@ public function translateDataToCE($id, $data) $slot = CustomEnchants::SLOT_FEET; break; case "Compass": - $slot = CustomEnchants::SLOT_COMPASS; + $slot = 0b10000000000000; break; } $rarity = CustomEnchants::RARITY_COMMON; @@ -374,44 +375,6 @@ public function translateDataToCE($id, $data) return $ce; } - /** - * Get enchantment on an item with specific id. Returns null if not found. - * - * @param Item $item - * @param $id - * @return null|EnchantmentInstance - */ - public function getEnchantment(Item $item, $id) - { - if (!$item->hasEnchantments()) { - return null; - } - foreach ($item->getNamedTag()->ench as $entry) { - if ($entry["id"] === $id) { - return new EnchantmentInstance(CustomEnchants::getEnchantment($entry["id"]), $entry["lvl"]); - } - } - return null; - } - - /** - * Get enchantments on an item - * - * @param Item $item - * @return array - */ - public function getEnchantments(Item $item) - { - if (!$item->hasEnchantments()) { - return []; - } - $enchants = []; - foreach ($item->getNamedTag()->ench as $entry) { - $enchants[] = new EnchantmentInstance(CustomEnchants::getEnchantment($entry["id"]), $entry["lvl"]); - } - return $enchants; - } - /** * Adds enchantment to item * @@ -706,7 +669,7 @@ public function canBeEnchanted(Item $item, $enchant, $level) if ($this->getEnchantMaxLevel($enchant) < $level) { return self::MAX_LEVEL; } - if (($enchant->getId() == CustomEnchants::PORKIFIED && $this->getEnchantment($item, CustomEnchants::BLAZE) !== null) || ($enchant->getId() == CustomEnchants::BLAZE && $this->getEnchantment($item, CustomEnchants::PORKIFIED) !== null) || ($enchant->getId() == CustomEnchants::SHRINK && $this->getEnchantment($item, CustomEnchants::GROW)) || ($enchant->getId() == CustomEnchants::GROW && $this->getEnchantment($item, CustomEnchants::SHRINK))) { + if (($enchant->getId() == CustomEnchantsIds::PORKIFIED && $item->getEnchantment(CustomEnchantsIds::BLAZE) !== null) || ($enchant->getId() == CustomEnchantsIds::BLAZE && $item->getEnchantment(CustomEnchantsIds::PORKIFIED) !== null) || ($enchant->getId() == CustomEnchantsIds::SHRINK && $item->getEnchantment(CustomEnchantsIds::GROW)) || ($enchant->getId() == CustomEnchantsIds::GROW && $item->getEnchantment(CustomEnchantsIds::SHRINK))) { return self::NOT_COMPATIBLE_WITH_OTHER_ENCHANT; } if ($item->getCount() > 1) { diff --git a/src/PiggyCustomEnchants/Tasks/CactusTask.php b/src/PiggyCustomEnchants/Tasks/CactusTask.php index b305e54d..7b354635 100644 --- a/src/PiggyCustomEnchants/Tasks/CactusTask.php +++ b/src/PiggyCustomEnchants/Tasks/CactusTask.php @@ -2,7 +2,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; @@ -33,7 +33,7 @@ public function onRun(int $currentTick) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { foreach ($player->getInventory()->getArmorContents() as $item) { - if ($this->plugin->getEnchantment($item, CustomEnchants::CACTUS) !== null) { + if ($item->getEnchantment(CustomEnchantsIds::CACTUS) !== null) { foreach ($player->getLevel()->getNearbyEntities($player->getBoundingBox()->grow(1, 0, 1), $player) as $p) { $ev = new EntityDamageByEntityEvent($player, $p, EntityDamageEvent::CAUSE_CONTACT, 1); $p->attack($ev); diff --git a/src/PiggyCustomEnchants/Tasks/ChickenTask.php b/src/PiggyCustomEnchants/Tasks/ChickenTask.php index b0311c52..8be229b5 100644 --- a/src/PiggyCustomEnchants/Tasks/ChickenTask.php +++ b/src/PiggyCustomEnchants/Tasks/ChickenTask.php @@ -3,7 +3,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\item\Item; use pocketmine\scheduler\PluginTask; @@ -33,7 +33,7 @@ public function __construct(Main $plugin) public function onRun(int $currentTick) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getChestplate(), CustomEnchants::CHICKEN); + $enchantment = $player->getInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::CHICKEN); if ($enchantment !== null) { if (!isset($this->plugin->chickenTick[$player->getLowerCaseName()])) { $this->plugin->chickenTick[$player->getLowerCaseName()] = 0; diff --git a/src/PiggyCustomEnchants/Tasks/EffectTask.php b/src/PiggyCustomEnchants/Tasks/EffectTask.php index e2bc1ba2..04604bc1 100644 --- a/src/PiggyCustomEnchants/Tasks/EffectTask.php +++ b/src/PiggyCustomEnchants/Tasks/EffectTask.php @@ -2,7 +2,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\entity\Effect; use pocketmine\scheduler\PluginTask; @@ -31,7 +31,7 @@ public function __construct(Main $plugin) public function onRun(int $currentTick) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::HASTE); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HASTE); if ($enchantment !== null) { $effect = Effect::getEffect(Effect::HASTE); $effect->setAmplifier($enchantment->getLevel() - 1); @@ -39,7 +39,7 @@ public function onRun(int $currentTick) $effect->setVisible(false); $player->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getItemInHand(), CustomEnchants::OXYGENATE); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::OXYGENATE); if ($enchantment !== null) { $effect = Effect::getEffect(Effect::WATER_BREATHING); $effect->setAmplifier(0); @@ -47,7 +47,7 @@ public function onRun(int $currentTick) $effect->setVisible(false); $player->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getHelmet(), CustomEnchants::GLOWING); + $enchantment = $player->getInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::GLOWING); if ($enchantment !== null) { $effect = Effect::getEffect(Effect::NIGHT_VISION); $effect->setAmplifier(0); @@ -61,7 +61,7 @@ public function onRun(int $currentTick) unset($this->plugin->glowing[$player->getLowerCaseName()]); } } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getChestplate(), CustomEnchants::ENRAGED); + $enchantment = $player->getInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::ENRAGED); if ($enchantment !== null) { $effect = Effect::getEffect(Effect::STRENGTH); $effect->setAmplifier($enchantment->getLevel() - 1); @@ -69,7 +69,7 @@ public function onRun(int $currentTick) $effect->setVisible(false); $player->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getBoots(), CustomEnchants::GEARS); + $enchantment = $player->getInventory()->getBoots()->getEnchantment(CustomEnchantsIds::GEARS); if ($enchantment !== null) { $effect = Effect::getEffect(Effect::SPEED); $effect->setAmplifier(0); @@ -78,7 +78,7 @@ public function onRun(int $currentTick) $player->addEffect($effect); } foreach ($player->getInventory()->getArmorContents() as $slot => $armor) { - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::OBSIDIANSHIELD); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::OBSIDIANSHIELD); if ($enchantment !== null) { $effect = Effect::getEffect(Effect::FIRE_RESISTANCE); $effect->setAmplifier(0); @@ -86,7 +86,7 @@ public function onRun(int $currentTick) $effect->setVisible(false); $player->addEffect($effect); } - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::OVERLOAD); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::OVERLOAD); if ($enchantment !== null) { if (!isset($this->plugin->overload[$player->getLowerCaseName() . "||" . $slot])) { $player->setMaxHealth($player->getMaxHealth() + (2 * $enchantment->getLevel())); diff --git a/src/PiggyCustomEnchants/Tasks/ForcefieldTask.php b/src/PiggyCustomEnchants/Tasks/ForcefieldTask.php index 50248b95..b110d4e6 100644 --- a/src/PiggyCustomEnchants/Tasks/ForcefieldTask.php +++ b/src/PiggyCustomEnchants/Tasks/ForcefieldTask.php @@ -2,7 +2,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\entity\Item; use pocketmine\entity\projectile\Projectile; @@ -36,7 +36,7 @@ public function onRun(int $currentTick) foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { $forcefields = 0; foreach ($player->getInventory()->getArmorContents() as $armor) { - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::FORCEFIELD); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::FORCEFIELD); if ($enchantment !== null) { $forcefields++; } diff --git a/src/PiggyCustomEnchants/Tasks/ImplantsTask.php b/src/PiggyCustomEnchants/Tasks/ImplantsTask.php index 47294c67..2608513f 100644 --- a/src/PiggyCustomEnchants/Tasks/ImplantsTask.php +++ b/src/PiggyCustomEnchants/Tasks/ImplantsTask.php @@ -2,8 +2,7 @@ namespace PiggyCustomEnchants\Tasks; - -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\block\Block; use pocketmine\Player; @@ -37,7 +36,7 @@ public function __construct(Main $plugin, Player $player) public function onRun(int $currentTick) { $player = $this->player; - if ($player->isOnline() && $player->isAlive() && ($enchantment = $this->plugin->getEnchantment($player->getInventory()->getHelmet(), CustomEnchants::IMPLANTS)) !== null) { + if ($player->isOnline() && $player->isAlive() && ($enchantment = $player->getInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::IMPLANTS)) !== null) { if (!$this->plugin->checkBlocks($player, [Block::WATER, Block::STILL_WATER, Block::FLOWING_WATER], -1)) { $this->cancel(); return false; diff --git a/src/PiggyCustomEnchants/Tasks/JetpackTask.php b/src/PiggyCustomEnchants/Tasks/JetpackTask.php index 07bb40a7..5389fad9 100644 --- a/src/PiggyCustomEnchants/Tasks/JetpackTask.php +++ b/src/PiggyCustomEnchants/Tasks/JetpackTask.php @@ -2,7 +2,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\level\particle\FlameParticle; use pocketmine\Player; @@ -33,7 +33,7 @@ public function __construct(Main $plugin) public function onRun(int $currentTick) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getBoots(), CustomEnchants::JETPACK); + $enchantment = $player->getInventory()->getBoots()->getEnchantment(CustomEnchantsIds::JETPACK); if ($enchantment !== null) { if (isset($this->plugin->flying[$player->getLowerCaseName()]) && $this->plugin->flying[$player->getLowerCaseName()] > time()) { if (!in_array($player->getLevel()->getName(), $this->plugin->jetpackDisabled)) { diff --git a/src/PiggyCustomEnchants/Tasks/MeditationTask.php b/src/PiggyCustomEnchants/Tasks/MeditationTask.php index 9aea4279..9659811b 100644 --- a/src/PiggyCustomEnchants/Tasks/MeditationTask.php +++ b/src/PiggyCustomEnchants/Tasks/MeditationTask.php @@ -3,7 +3,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\scheduler\PluginTask; @@ -33,7 +33,7 @@ public function __construct(Main $plugin) public function onRun(int $currentTick) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getHelmet(), CustomEnchants::MEDITATION); + $enchantment = $player->getInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::MEDITATION); if ($enchantment !== null) { if (!isset($this->plugin->meditationTick[$player->getLowerCaseName()])) { $this->plugin->meditationTick[$player->getLowerCaseName()] = 0; diff --git a/src/PiggyCustomEnchants/Tasks/ParachuteTask.php b/src/PiggyCustomEnchants/Tasks/ParachuteTask.php index e1bafd12..435a8910 100644 --- a/src/PiggyCustomEnchants/Tasks/ParachuteTask.php +++ b/src/PiggyCustomEnchants/Tasks/ParachuteTask.php @@ -3,7 +3,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\math\Vector3; use pocketmine\scheduler\PluginTask; @@ -33,7 +33,7 @@ public function onRun(int $currentTick) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { $chestplate = $player->getInventory()->getChestplate(); - $enchantment = $this->plugin->getEnchantment($chestplate, CustomEnchants::PARACHUTE); + $enchantment = $chestplate->getEnchantment(CustomEnchantsIds::PARACHUTE); if ($enchantment !== null) { $motion = $player->getMotion(); if ($this->plugin->checkBlocks($player, 0, 3)) { diff --git a/src/PiggyCustomEnchants/Tasks/ProwlTask.php b/src/PiggyCustomEnchants/Tasks/ProwlTask.php index 83d56d7d..f7f7a0f4 100644 --- a/src/PiggyCustomEnchants/Tasks/ProwlTask.php +++ b/src/PiggyCustomEnchants/Tasks/ProwlTask.php @@ -3,7 +3,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\entity\Effect; use pocketmine\entity\Entity; @@ -33,7 +33,7 @@ public function __construct(Main $plugin) public function onRun(int $currentTick) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getChestplate(), CustomEnchants::PROWL); + $enchantment = $player->getInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::PROWL); if ($enchantment !== null && $player->isSneaking()) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $p) { $p->hidePlayer($player); diff --git a/src/PiggyCustomEnchants/Tasks/RadarTask.php b/src/PiggyCustomEnchants/Tasks/RadarTask.php index b1f0c435..6f865dfb 100644 --- a/src/PiggyCustomEnchants/Tasks/RadarTask.php +++ b/src/PiggyCustomEnchants/Tasks/RadarTask.php @@ -2,7 +2,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket; use pocketmine\Player; @@ -36,7 +36,7 @@ public function onRun(int $currentTick) foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { $radar = false; foreach ($player->getInventory()->getContents() as $item) { - $enchantment = $this->plugin->getEnchantment($item, CustomEnchants::RADAR); + $enchantment = $item->getEnchantment(CustomEnchantsIds::RADAR); if ($enchantment !== null) { $distance = []; foreach ($this->plugin->getServer()->getOnlinePlayers() as $p) { diff --git a/src/PiggyCustomEnchants/Tasks/SizeTask.php b/src/PiggyCustomEnchants/Tasks/SizeTask.php index 9a680cd1..b1da2807 100644 --- a/src/PiggyCustomEnchants/Tasks/SizeTask.php +++ b/src/PiggyCustomEnchants/Tasks/SizeTask.php @@ -2,7 +2,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\scheduler\PluginTask; use pocketmine\utils\TextFormat; @@ -34,7 +34,7 @@ public function onRun(int $currentTick) $shrinkpoints = 0; $growpoints = 0; foreach ($player->getInventory()->getArmorContents() as $armor) { - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::SHRINK); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::SHRINK); if ($enchantment !== null) { $shrinkpoints++; } @@ -49,7 +49,7 @@ public function onRun(int $currentTick) $player->sendTip(TextFormat::RED . "You have grown back to normal size."); } foreach ($player->getInventory()->getArmorContents() as $armor) { - $enchantment = $this->plugin->getEnchantment($armor, CustomEnchants::GROW); + $enchantment = $armor->getEnchantment(CustomEnchantsIds::GROW); if ($enchantment !== null) { $growpoints++; } diff --git a/src/PiggyCustomEnchants/Tasks/SpiderTask.php b/src/PiggyCustomEnchants/Tasks/SpiderTask.php index ccfce279..86d93e67 100644 --- a/src/PiggyCustomEnchants/Tasks/SpiderTask.php +++ b/src/PiggyCustomEnchants/Tasks/SpiderTask.php @@ -2,8 +2,7 @@ namespace PiggyCustomEnchants\Tasks; - -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\block\Block; use pocketmine\entity\Entity; @@ -33,7 +32,7 @@ public function __construct(Main $plugin) public function onRun(int $currentTick) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getChestplate(), CustomEnchants::SPIDER); + $enchantment = $player->getInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::SPIDER); if($enchantment !== null){ $blocks = $player->getLevel()->getBlock($player)->getHorizontalSides(); //getBlocksAround() returns an empty array... $nonair = 0; diff --git a/src/PiggyCustomEnchants/Tasks/UseEnchantedBookTask.php b/src/PiggyCustomEnchants/Tasks/UseEnchantedBookTask.php index bf4d62f9..5c959d89 100644 --- a/src/PiggyCustomEnchants/Tasks/UseEnchantedBookTask.php +++ b/src/PiggyCustomEnchants/Tasks/UseEnchantedBookTask.php @@ -40,7 +40,7 @@ public function onRun(int $currentTick) { $source = $this->action->getSourceItem(); $target = $this->action->getTargetItem(); - foreach ($this->plugin->getEnchantments($source) as $enchant) { + foreach ($source->getEnchantments() as $enchant) { if ($this->plugin->canBeEnchanted($target, $enchant, $enchant->getLevel())) {//TODO: Check XP if ($this->player->getCursorInventory()->contains($target)) { //W10 UI $this->player->getCursorInventory()->removeItem($target); diff --git a/src/PiggyCustomEnchants/Tasks/VacuumTask.php b/src/PiggyCustomEnchants/Tasks/VacuumTask.php index e922b1e8..30aa2307 100644 --- a/src/PiggyCustomEnchants/Tasks/VacuumTask.php +++ b/src/PiggyCustomEnchants/Tasks/VacuumTask.php @@ -2,7 +2,7 @@ namespace PiggyCustomEnchants\Tasks; -use PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use PiggyCustomEnchants\CustomEnchants\CustomEnchantsIds; use PiggyCustomEnchants\Main; use pocketmine\entity\Item; use pocketmine\scheduler\PluginTask; @@ -31,7 +31,7 @@ public function __construct(Main $plugin) public function onRun(int $currentTick) { foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { - $enchantment = $this->plugin->getEnchantment($player->getInventory()->getChestplate(), CustomEnchants::VACUUM); + $enchantment = $player->getInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::VACUUM); if ($enchantment !== null) { foreach ($player->getLevel()->getEntities() as $entity) { if ($entity instanceof Item) {