From 42331bc0091a604ffe6bd7f69eadd3202d6f60bd Mon Sep 17 00:00:00 2001 From: Brianna Date: Tue, 6 Aug 2019 14:30:02 -0400 Subject: [PATCH] DropHeld --- .gitlab-ci.yml | 2 +- .../epicenchants/effect/effects/DropHeld.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/songoda/epicenchants/effect/effects/DropHeld.java diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a7ddb5b..8a54693 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "EpicEnchants" path: "/builds/$CI_PROJECT_PATH" - version: "1.0.1" + version: "1.0.2" build: stage: build diff --git a/src/main/java/com/songoda/epicenchants/effect/effects/DropHeld.java b/src/main/java/com/songoda/epicenchants/effect/effects/DropHeld.java new file mode 100644 index 0000000..8144ca3 --- /dev/null +++ b/src/main/java/com/songoda/epicenchants/effect/effects/DropHeld.java @@ -0,0 +1,29 @@ +package com.songoda.epicenchants.effect.effects; + +import com.songoda.epicenchants.effect.EffectExecutor; +import com.songoda.epicenchants.enums.EventType; +import com.songoda.epicenchants.utils.objects.ItemBuilder; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class DropHeld extends EffectExecutor { + public DropHeld(ConfigurationSection section) { + super(section); + } + + @Override + public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) { + consume(entity -> { + Player player = ((Player) entity); + if (player.getItemInHand().getType() != Material.AIR) { + entity.getLocation().getWorld().dropItemNaturally(entity.getLocation(), new ItemBuilder(player + .getItemInHand()).build()); + player.setItemInHand(null); + } + }, user, opponent); + } +}