diff --git a/eco-extensions/softtouch/build.gradle b/eco-extensions/softtouch/build.gradle new file mode 100644 index 00000000..8c52bc4d --- /dev/null +++ b/eco-extensions/softtouch/build.gradle @@ -0,0 +1,7 @@ +group 'com.willfp' +version '1.0.0' +description = 'Soft Touch Extension' + +shadowJar { + archiveFileName = project.getDescription() + " v" + project.version + ".jar" +} \ No newline at end of file diff --git a/eco-extensions/softtouch/src/main/java/com/willfp/ecoenchants/softtouch/SoftTouch.java b/eco-extensions/softtouch/src/main/java/com/willfp/ecoenchants/softtouch/SoftTouch.java new file mode 100644 index 00000000..551806e5 --- /dev/null +++ b/eco-extensions/softtouch/src/main/java/com/willfp/ecoenchants/softtouch/SoftTouch.java @@ -0,0 +1,51 @@ +package com.willfp.ecoenchants.softtouch; + + +import com.willfp.eco.core.drops.DropQueue; +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.CreatureSpawner; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BlockStateMeta; +import org.jetbrains.annotations.NotNull; + +public class SoftTouch extends EcoEnchant { + public SoftTouch() { + super("soft_touch", EnchantmentType.NORMAL); + } + + @Override + public void onBlockBreak(@NotNull final Player player, + @NotNull final Block block, + final int level, + @NotNull final BlockBreakEvent event) { + if (!EnchantmentUtils.passedChance(this, level)) { + return; + } + + if (!(block.getState() instanceof CreatureSpawner spawner)) { + return; + } + + EntityType type = spawner.getSpawnedType(); + + event.setDropItems(false); + event.setExpToDrop(0); + + ItemStack itemStack = new ItemStack(Material.SPAWNER); + BlockStateMeta meta = (BlockStateMeta) itemStack.getItemMeta(); + assert meta != null; + meta.setBlockState(spawner); + itemStack.setItemMeta(meta); + + new DropQueue(player) + .addItem(itemStack) + .push(); + } +} diff --git a/eco-extensions/softtouch/src/main/java/com/willfp/ecoenchants/softtouch/SoftTouchMain.java b/eco-extensions/softtouch/src/main/java/com/willfp/ecoenchants/softtouch/SoftTouchMain.java new file mode 100644 index 00000000..78ad3475 --- /dev/null +++ b/eco-extensions/softtouch/src/main/java/com/willfp/ecoenchants/softtouch/SoftTouchMain.java @@ -0,0 +1,24 @@ +package com.willfp.ecoenchants.softtouch; + +import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.core.extensions.Extension; +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import org.jetbrains.annotations.NotNull; + +public class SoftTouchMain extends Extension { + public static final EcoEnchant SOFT_TOUCH = new SoftTouch(); + + public SoftTouchMain(@NotNull final EcoPlugin plugin) { + super(plugin); + } + + @Override + public void onEnable() { + // Handled by super + } + + @Override + public void onDisable() { + // Handled by super + } +} diff --git a/eco-extensions/softtouch/src/main/resources/enchants/normal/softtouch.yml b/eco-extensions/softtouch/src/main/resources/enchants/normal/softtouch.yml new file mode 100644 index 00000000..ccf75c52 --- /dev/null +++ b/eco-extensions/softtouch/src/main/resources/enchants/normal/softtouch.yml @@ -0,0 +1,30 @@ +# +# Soft Touch EcoEnchant +# + +name: "Soft Touch" +description: '&a%value%%&r chance to drop a spawner when you mine it.' +enabled: true + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + targets: + - pickaxe + grindstoneable: true + disabled-in-worlds: [ ] + conflicts: + - silk_touch + maximum-level: 5 + +config: + chance-per-level: 10 + spawner-name: + - "&a%type%&f Spawner" + spawner-lore: + - "&a%type%&f Spawner" + - "&fCan be placed anywhere in the world" \ No newline at end of file diff --git a/eco-extensions/softtouch/src/main/resources/extension.yml b/eco-extensions/softtouch/src/main/resources/extension.yml new file mode 100644 index 00000000..12b6bec7 --- /dev/null +++ b/eco-extensions/softtouch/src/main/resources/extension.yml @@ -0,0 +1,4 @@ +name: Soft Touch +main: com.willfp.ecoenchants.softtouch.SoftTouchMain +version: ${projectVersion} +author: Auxilor \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index a41292ab..2392821c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,6 +22,7 @@ include ':eco-extensions:intimidation' include ':eco-extensions:precision' include ':eco-extensions:rainbow' include ':eco-extensions:sprint-artifacts' +include ':eco-extensions:softtouch' include ':eco-extensions:summoning' include ':eco-extensions:transmission' include ':eco-extensions:xray' \ No newline at end of file