Added Transfuse

This commit is contained in:
Auxilor
2020-08-30 11:35:04 +01:00
parent 8ac7b1a383
commit 0a6084703f
6 changed files with 111 additions and 3 deletions

View File

@@ -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

View File

@@ -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)
);
}

View File

@@ -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();
}
}