diff --git a/pom.xml b/pom.xml index 99d5e9e..e05853d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.itzjustsamu PlayerSkills - 2.5.4 + 2.5.5 PlayerSkills diff --git a/src/main/java/me/itzjustsamu/playerskills/PlayerSkills.java b/src/main/java/me/itzjustsamu/playerskills/PlayerSkills.java index 5b6afe9..45ac09b 100644 --- a/src/main/java/me/itzjustsamu/playerskills/PlayerSkills.java +++ b/src/main/java/me/itzjustsamu/playerskills/PlayerSkills.java @@ -73,12 +73,14 @@ public void enable() { registerSkill(new LacerateSkill(this)); registerSkill(new LootingSkill(this)); registerSkill(new LumberSkill(this)); + registerSkill(new MagicResistanceSkill(this)); registerSkill(new MultiBlockBreakSkill(this)); registerSkill(new HasteSkill(this)); registerSkill(new ResistanceSkill(this)); registerSkill(new ShadowStepSkill(this)); registerSkill(new SpeedSkill(this)); registerSkill(new StrengthSkill(this)); + registerSkill(new VeinMinerSkill(this)); registerSkill(new WitherRewardSkill(this)); registerSkill(new XPSkill(this)); diff --git a/src/main/java/me/itzjustsamu/playerskills/skill/LumberSkill.java b/src/main/java/me/itzjustsamu/playerskills/skill/LumberSkill.java index c025daf..19e3cd6 100644 --- a/src/main/java/me/itzjustsamu/playerskills/skill/LumberSkill.java +++ b/src/main/java/me/itzjustsamu/playerskills/skill/LumberSkill.java @@ -83,11 +83,15 @@ private boolean isLog(Material material) { private boolean isAxe(Player player) { Material mainHand = player.getInventory().getItemInMainHand().getType(); + if (mainHand == null || mainHand == Material.AIR) { + mainHand = player.getInventory().getItemInHand().getType(); + } Material offHand = player.getInventory().getItemInOffHand().getType(); return mainHand.toString().endsWith("_AXE") || offHand.toString().endsWith("_AXE"); } + @Override public List> getAdditionalConfigPaths() { return Collections.singletonList(getUpgrade()); diff --git a/src/main/java/me/itzjustsamu/playerskills/skill/MagicResistanceSkill.java b/src/main/java/me/itzjustsamu/playerskills/skill/MagicResistanceSkill.java new file mode 100644 index 0000000..44d83ee --- /dev/null +++ b/src/main/java/me/itzjustsamu/playerskills/skill/MagicResistanceSkill.java @@ -0,0 +1,77 @@ +package me.itzjustsamu.playerskills.skill; + +import com.cryptomorin.xseries.XMaterial; +import me.hsgamer.hscore.bukkit.item.BukkitItemBuilder; +import me.hsgamer.hscore.bukkit.item.modifier.LoreModifier; +import me.hsgamer.hscore.bukkit.item.modifier.NameModifier; +import me.hsgamer.hscore.config.path.ConfigPath; +import me.hsgamer.hscore.minecraft.item.ItemBuilder; +import me.itzjustsamu.playerskills.PlayerSkills; +import me.itzjustsamu.playerskills.player.SPlayer; +import me.itzjustsamu.playerskills.util.modifier.XMaterialModifier; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Collections; +import java.util.List; + +public class MagicResistanceSkill extends Skill implements Listener { + + public MagicResistanceSkill(PlayerSkills plugin) { + super(plugin, "MagicResistance", "magicresistance", 10, 26); + } + + @EventHandler + public void onEntityDamage(EntityDamageEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + SPlayer sPlayer = SPlayer.get(player.getUniqueId()); + + if (sPlayer != null && getLevel(sPlayer) > 0) { + if (event.getCause() == EntityDamageEvent.DamageCause.MAGIC || + event.getCause() == EntityDamageEvent.DamageCause.MAGIC) { + double resistanceLevel = getLevel(sPlayer) * getUpgrade().getValue(); + double reduction = resistanceLevel / 100.0; // Convert resistance level to percentage + + // Reduce the damage by the calculated percentage + event.setDamage(event.getDamage() * (1 - reduction)); + } + } + } + } + + @Override + public List> getAdditionalConfigPaths() { + return Collections.singletonList(getUpgrade()); + } + + @Override + public ItemBuilder getDefaultItem() { + return new BukkitItemBuilder() + .addItemModifier(new NameModifier().setName("&cMagic Resistance Overview")) + .addItemModifier(new XMaterialModifier(XMaterial.ENCHANTED_BOOK)) + .addItemModifier(new LoreModifier().setLore( + "&eLeft-Click &7to upgrade this skill using &e{price} &7point(s).", + "&7This skill provides resistance against magical damage.", + "&7Level: &e{level}&7/&e{limit}&7", + " ", + "&cResistance Increase: ", + " &e{prev}% &7 >>> &e{next}%" + )); + } + + @Override + public String getPreviousString(SPlayer player) { + double resistanceLevel = getLevel(player) * getUpgrade().getValue(); + return String.valueOf(resistanceLevel); + } + + @Override + public String getNextString(SPlayer player) { + double resistanceLevel = (getLevel(player) + 1) * getUpgrade().getValue(); + return String.valueOf(resistanceLevel); + } +} diff --git a/src/main/java/me/itzjustsamu/playerskills/skill/VeinMinerSkill.java b/src/main/java/me/itzjustsamu/playerskills/skill/VeinMinerSkill.java new file mode 100644 index 0000000..22547c0 --- /dev/null +++ b/src/main/java/me/itzjustsamu/playerskills/skill/VeinMinerSkill.java @@ -0,0 +1,160 @@ +package me.itzjustsamu.playerskills.skill; + +import com.cryptomorin.xseries.XMaterial; +import me.hsgamer.hscore.bukkit.item.BukkitItemBuilder; +import me.hsgamer.hscore.bukkit.item.modifier.LoreModifier; +import me.hsgamer.hscore.bukkit.item.modifier.NameModifier; +import me.hsgamer.hscore.config.path.ConfigPath; +import me.hsgamer.hscore.minecraft.item.ItemBuilder; +import me.itzjustsamu.playerskills.PlayerSkills; +import me.itzjustsamu.playerskills.player.SPlayer; +import me.itzjustsamu.playerskills.util.modifier.XMaterialModifier; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.*; + +public class VeinMinerSkill extends Skill implements Listener { + + public VeinMinerSkill(PlayerSkills plugin) { + super(plugin, "VeinMiner", "veinminer", 1, 25); + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + UUID uniqueId = player.getUniqueId(); + SPlayer sPlayer = SPlayer.get(uniqueId); + + if (sPlayer == null) { + return; + } + + if (getLevel(sPlayer) > 0) { + ItemStack itemInHand = getItemInMainHand(player); + + if (itemInHand.getType() == Material.DIAMOND_PICKAXE) { + Block block = event.getBlock(); + Material material = block.getType(); + + if (isOre(material)) { + List veinBlocks = getVeinBlocks(block, material); + + for (Block veinBlock : veinBlocks) { + veinBlock.breakNaturally(); // Break the block + } + } + } + } + } + + private ItemStack getItemInMainHand(Player player) { + ItemStack itemInMainHand = null; + try { + itemInMainHand = player.getInventory().getItemInMainHand(); + } catch (NoSuchMethodError ignored) { + // Version is likely pre-1.9, handle it accordingly + } + if (itemInMainHand == null || itemInMainHand.getType() == Material.AIR) { + // If main hand is null or air (empty hand), try getting from the whole inventory + itemInMainHand = player.getInventory().getItemInHand(); + } + return itemInMainHand; + } + + private boolean isOre(Material material) { + switch (material) { + case COAL_ORE: + case IRON_ORE: + case GOLD_ORE: + case LAPIS_ORE: + case DIAMOND_ORE: + case EMERALD_ORE: + case REDSTONE_ORE: + return true; + default: + return false; + } + } + + private List getVeinBlocks(Block originBlock, Material material) { + List veinBlocks = new ArrayList<>(); + List queue = new ArrayList<>(); + List visited = new ArrayList<>(); + queue.add(originBlock); + + while (!queue.isEmpty()) { + Block currentBlock = queue.remove(0); + + if (!visited.contains(currentBlock) && currentBlock.getType() == material) { + visited.add(currentBlock); + veinBlocks.add(currentBlock); + + for (Block relativeBlock : getAdjacentBlocks(currentBlock)) { + if (!visited.contains(relativeBlock) && !queue.contains(relativeBlock)) { + queue.add(relativeBlock); + } + } + } + } + + return veinBlocks; + } + + private List getAdjacentBlocks(Block block) { + List adjacentBlocks = new ArrayList<>(); + + for (int xOffset = -1; xOffset <= 1; xOffset++) { + for (int yOffset = -1; yOffset <= 1; yOffset++) { + for (int zOffset = -1; zOffset <= 1; zOffset++) { + if (xOffset != 0 || yOffset != 0 || zOffset != 0) { + Block relativeBlock = block.getWorld().getBlockAt( + block.getX() + xOffset, + block.getY() + yOffset, + block.getZ() + zOffset + ); + adjacentBlocks.add(relativeBlock); + } + } + } + } + + return adjacentBlocks; + } + + @Override + public List> getAdditionalConfigPaths() { + return Collections.singletonList(getUpgrade()); + } + + @Override + public ItemBuilder getDefaultItem() { + return new BukkitItemBuilder() + .addItemModifier(new NameModifier().setName("&cVeinMiner Overview")) + .addItemModifier(new XMaterialModifier(XMaterial.DIAMOND_PICKAXE)) + .addItemModifier(new LoreModifier().setLore( + "&eLeft-Click &7to upgrade this skill using &e{price} &7point(s).", + "&7Break entire veins of ores with a single hit.", + "&7Level: &e{level}&7/&e{limit}&7", + " ", + "&cVein Upgrade: ", + " &e{prev} &7 >>> &e{next}+" + )); + } + @Override + public String getPreviousString(SPlayer player) { + double value = getLevel(player) * getUpgrade().getValue(); + return String.valueOf(value); + } + + @Override + public String getNextString(SPlayer player) { + double value = (getLevel(player) + 1) * getUpgrade().getValue(); + return String.valueOf(value); + } +}