diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index 706aafb9..b51b286d 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -224,6 +224,7 @@ public class EcoEnchants { public static final EcoEnchant GRACEFUL = new Graceful(); public static final EcoEnchant BLOCK_BREATHER = new BlockBreather(); public static final EcoEnchant VOLTAGE = new Voltage(); + public static final EcoEnchant TRANSFUSE = new Transfuse(); /** * Get all registered {@link EcoEnchant}s diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java index 4b2875da..75f86297 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java @@ -19,7 +19,7 @@ import org.bukkit.inventory.ItemStack; public class StoneSwitcher extends EcoEnchant { public StoneSwitcher() { super( - new EcoEnchantBuilder("stone_switcher", EnchantmentType.NORMAL, Target.Applicable.PICKAXE, 4.0) + new EcoEnchantBuilder("stone_switcher", EnchantmentType.NORMAL, Target.Applicable.PICKAXE, 4.01) ); } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java new file mode 100644 index 00000000..7f7a4327 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java @@ -0,0 +1,70 @@ +package com.willfp.ecoenchants.enchantments.ecoenchants.normal; + +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; +import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.checks.EnchantChecks; +import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager; +import com.willfp.ecoenchants.nms.Target; +import com.willfp.ecoenchants.queue.DropQueue; +import com.willfp.ecoenchants.util.EqualIfOver; +import com.willfp.ecoenchants.util.Rand; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; + +public class Transfuse extends EcoEnchant { + public Transfuse() { + super( + new EcoEnchantBuilder("transfuse", EnchantmentType.NORMAL, Target.Applicable.PICKAXE, 4.0) + ); + } + + // START OF LISTENERS + + @EventHandler + public void onBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); + + if (!EnchantChecks.mainhand(player, this)) return; + + if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) + return; + + if(!block.getType().equals(Material.STONE)) return; + + if (event.isCancelled()) + return; + + if (!AntigriefManager.canBreakBlock(player, block)) return; + + int level = EnchantChecks.getMainhandLevel(player, this); + double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); + + if(Rand.randFloat(0, 1) > level * chance * 0.01) + return; + + event.setDropItems(false); + + Material material; + double random = Rand.randFloat(0, 1); + double band = 1/(double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size(); + int selectedIndex = (int) Math.floor(random/band); + selectedIndex = EqualIfOver.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size() - 1); + String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").get(selectedIndex); + material = Material.getMaterial(materialName.toUpperCase()); + if(material == null) material = Material.COBBLESTONE; + + ItemStack item = new ItemStack(material, 1); + + new DropQueue(player) + .setLocation(block.getLocation()) + .addItem(item) + .push(); + } +} diff --git a/Plugin/src/main/resources/enchants/normal/stoneswitcher.yml b/Plugin/src/main/resources/enchants/normal/stoneswitcher.yml index d66818eb..5f9854f0 100644 --- a/Plugin/src/main/resources/enchants/normal/stoneswitcher.yml +++ b/Plugin/src/main/resources/enchants/normal/stoneswitcher.yml @@ -2,7 +2,7 @@ # Stone Switcher EcoEnchant # -config-version: 4.0 # Don't edit this. +config-version: 4.01 # Don't edit this. name: "Stone Switcher" @@ -16,7 +16,9 @@ obtaining: general-config: grindstoneable: true - conflicts: [] + conflicts: + - transfuse + - silk_touch maximum-level: 3 config: diff --git a/Plugin/src/main/resources/enchants/normal/transfuse.yml b/Plugin/src/main/resources/enchants/normal/transfuse.yml new file mode 100644 index 00000000..f09f59c8 --- /dev/null +++ b/Plugin/src/main/resources/enchants/normal/transfuse.yml @@ -0,0 +1,31 @@ +# +# Transfuse EcoEnchant +# + +config-version: 4.0 # Don't edit this. + +name: "Transfuse" + +description: Breaking stone can drop as random ore. + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + grindstoneable: true + conflicts: + - stone_switcher + - silk_touch + maximum-level: 4 + +config: + blocks: + - diamond_ore + - gold_ore + - lapis_ore + - redstone_ore + - iron_ore + chance-per-level: 0.05 # Chance for drop to be switched diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index 629d3a02..65d986bd 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -243,6 +243,7 @@ permissions: ecoenchants.fromtable.graceful: true ecoenchants.fromtable.blockbreather: true ecoenchants.fromtable.voltage: true + ecoenchants.fromtable.transfuse: true ecoenchants.updateannounce: description: Informs admins of a new update @@ -844,4 +845,7 @@ permissions: default: true ecoenchants.fromtable.voltage: description: Allows getting voltage from an enchanting table + default: true + ecoenchants.fromtable.transfuse: + description: Allows getting transfuse from an enchanting table default: true \ No newline at end of file