Files
armor
bow
fishing
DistributionConfig.java
EnchantCatalog.java
EnchantCatalog$Weight.java
EnchantContext.java
EnchantedItem.java
EnchantFactory.java
EnchantHolder.java
EnchantRegistry.java
EnchantSettings.java
Code
48 2,851
armor/FlameWalkerEnchant.java
/* */ package su.nightexpress.excellentenchants.enchantment.armor;
/* */
/* */ import java.nio.file.Path;
/* */ import java.util.ArrayList;
/* */ import java.util.HashSet;
/* */ import java.util.List;
/* */ import java.util.Set;
/* */ import java.util.stream.Stream;
/* */ import org.bukkit.Bukkit;
/* */ import org.bukkit.Location;
/* */ import org.bukkit.Material;
/* */ import org.bukkit.World;
/* */ import org.bukkit.block.Block;
/* */ import org.bukkit.block.BlockFace;
/* */ import org.bukkit.block.BlockState;
/* */ import org.bukkit.block.data.BlockData;
/* */ import org.bukkit.block.data.Levelled;
/* */ import org.bukkit.damage.DamageSource;
/* */ import org.bukkit.damage.DamageType;
/* */ import org.bukkit.entity.Entity;
/* */ import org.bukkit.entity.LivingEntity;
/* */ import org.bukkit.entity.Player;
/* */ import org.bukkit.event.Event;
/* */ import org.bukkit.event.block.EntityBlockFormEvent;
/* */ import org.bukkit.event.entity.EntityDamageEvent;
/* */ import org.bukkit.event.player.PlayerMoveEvent;
/* */ import org.bukkit.inventory.ItemStack;
/* */ import org.jetbrains.annotations.NotNull;
/* */ import su.nightexpress.excellentenchants.EnchantsPlugin;
/* */ import su.nightexpress.excellentenchants.api.EnchantPriority;
/* */ import su.nightexpress.excellentenchants.api.Modifier;
/* */ import su.nightexpress.excellentenchants.api.damage.DamageBonus;
/* */ import su.nightexpress.excellentenchants.api.damage.DamageBonusType;
/* */ import su.nightexpress.excellentenchants.api.enchantment.type.MoveEnchant;
/* */ import su.nightexpress.excellentenchants.api.enchantment.type.ProtectionEnchant;
/* */ import su.nightexpress.excellentenchants.enchantment.EnchantContext;
/* */ import su.nightexpress.excellentenchants.enchantment.GameEnchantment;
/* */ import su.nightexpress.excellentenchants.manager.EnchantManager;
/* */ import su.nightexpress.nightcore.config.FileConfig;
/* */ import su.nightexpress.nightcore.util.Randomizer;
/* */
/* */ public class FlameWalkerEnchant extends GameEnchantment implements MoveEnchant, ProtectionEnchant {
/* 43 */ private static final BlockFace[] FACES = new BlockFace[] { BlockFace.SOUTH, BlockFace.NORTH, BlockFace.EAST, BlockFace.WEST };
/* */
/* */ private Modifier radius;
/* */ private Modifier decayTime;
/* */
/* */ public FlameWalkerEnchant(@NotNull EnchantsPlugin plugin, @NotNull EnchantManager manager, @NotNull Path file, @NotNull EnchantContext context) {
/* 49 */ super(plugin, manager, file, context);
/* */ }
/* */
/* */
/* */ protected void loadAdditional(@NotNull FileConfig config) {
/* 54 */ this.radius = Modifier.load(config, "FlameWalker.Radius",
/* 55 */ Modifier.addictive(1.0D).perLevel(1.0D).capacity(16.0D), new String[] { "Square radius around the block to transform into magma block." });
/* */
/* */
/* */
/* 59 */ this.decayTime = Modifier.load(config, "FlameWalker.Block_Decay",
/* 60 */ Modifier.addictive(8.0D).perLevel(1.0D).capacity(15.0D), new String[] { "Sets life time for magma blocks before turning back into lava." });
/* */ }
/* */
/* */
/* */
/* */ @NotNull
/* */ public Modifier getRadius() {
/* 67 */ return this.radius;
/* */ }
/* */
/* */ public int getBlockDecayTime(int level) {
/* 71 */ return (int)this.decayTime.getValue(level);
/* */ }
/* */
/* */
/* */ @NotNull
/* */ public EnchantPriority getMovePriority() {
/* 77 */ return EnchantPriority.LOWEST;
/* */ }
/* */
/* */
/* */ @NotNull
/* */ public EnchantPriority getProtectionPriority() {
/* 83 */ return EnchantPriority.NORMAL;
/* */ }
/* */
/* */
/* */ @NotNull
/* */ public DamageBonus getDamageBonus() {
/* 89 */ return new DamageBonus(DamageBonusType.NORMAL);
/* */ }
/* */
/* */
/* */ public boolean onMove(@NotNull PlayerMoveEvent event, @NotNull Player player, @NotNull ItemStack itemStack, int level) {
/* 94 */ Location to = event.getTo();
/* */
/* 96 */ Block nextBlock = to.getBlock().getRelative(BlockFace.DOWN);
/* 97 */ boolean hasLava = Stream.<BlockFace>of(FACES).anyMatch(face -> (nextBlock.getRelative(face).getType() == Material.LAVA));
/* 98 */ if (!hasLava) return false;
/* */
/* 100 */ int radius = (int)this.radius.getValue(level);
/* 101 */ Set<Block> blocks = handleFlameWalker((LivingEntity)player, level, radius);
/* 102 */ if (blocks.isEmpty()) return false;
/* */
/* 104 */ blocks.forEach(block -> {
/* */ int lifeTime = (int)(Randomizer.nextDouble(getBlockDecayTime(level)) + 1.0D);
/* */ this.plugin.getEnchantManager().addTickedBlock(block, Material.LAVA, Material.MAGMA_BLOCK, lifeTime);
/* */ });
/* 108 */ return true;
/* */ }
/* */
/* */
/* */ public boolean onProtection(@NotNull EntityDamageEvent event, @NotNull DamageBonus damageBonus, @NotNull LivingEntity entity, @NotNull ItemStack itemStack, int level) {
/* 113 */ DamageSource source = event.getDamageSource();
/* 114 */ DamageType type = source.getDamageType();
/* 115 */ if (type != DamageType.HOT_FLOOR) return false;
/* */
/* 117 */ event.setCancelled(true);
/* 118 */ return true;
/* */ }
/* */
/* */ @NotNull
/* */ public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, int level, int radius) {
/* 123 */ Set<Block> blocks = new HashSet<>();
/* */
/* 125 */ for (Block block : getCircleBlocks(bukkitEntity, radius)) {
/* 126 */ if (block.getType() != Material.LAVA)
/* 127 */ continue; BlockData blockData = block.getBlockData(); if (blockData instanceof Levelled) { Levelled levelled = (Levelled)blockData;
/* 128 */ if (levelled.getLevel() != 0)
/* */ continue;
/* 130 */ Block above = block.getRelative(BlockFace.UP);
/* 131 */ if (!above.isEmpty())
/* */ continue;
/* 133 */ BlockState state = Material.MAGMA_BLOCK.createBlockData().createBlockState();
/* */
/* 135 */ EntityBlockFormEvent entityBlockFormEvent = new EntityBlockFormEvent((Entity)bukkitEntity, block, state);
/* 136 */ Bukkit.getPluginManager().callEvent((Event)entityBlockFormEvent);
/* 137 */ if (entityBlockFormEvent.isCancelled())
/* */ continue;
/* 139 */ block.setBlockData(state.getBlockData());
/* 140 */ blocks.add(block); }
/* */
/* */ }
/* 143 */ return blocks;
/* */ }
/* */
/* */ @NotNull
/* */ protected List<Block> getCircleBlocks(@NotNull LivingEntity entity, int radius) {
/* 148 */ World world = entity.getWorld();
/* 149 */ int fixedY = entity.getLocation().getBlockY() - 1;
/* */
/* 151 */ List<Block> blocks = new ArrayList<>();
/* */
/* 153 */ int centerX = entity.getLocation().getBlockX();
/* 154 */ int centerZ = entity.getLocation().getBlockZ();
/* */
/* 156 */ for (int x = centerX - radius; x <= centerX + radius; x++) {
/* 157 */ for (int z = centerZ - radius; z <= centerZ + radius; z++) {
/* */
/* 159 */ int dx = centerX - x;
/* 160 */ int dz = centerZ - z;
/* 161 */ if (dx * dx + dz * dz <= radius * radius) {
/* 162 */ Block block = world.getBlockAt(x, fixedY, z);
/* 163 */ blocks.add(block);
/* */ }
/* */ }
/* */ }
/* 167 */ return blocks;
/* */ }
/* */ }
/* Location: C:\Users\Administrator\Downloads\ExcellentEnchants-5.4.1.zip!\su\nightexpress\excellentenchants\enchantment\armor\FlameWalkerEnchant.class
* Java compiler version: 21 (65.0)
* JD-Core Version: 1.1.3
*/