-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VeinMinerSkill 1.8 compatibility patches in LumberSkill
- Loading branch information
1 parent
6bfebdb
commit cf4cd0c
Showing
5 changed files
with
244 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/me/itzjustsamu/playerskills/skill/MagicResistanceSkill.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfigPath<?>> getAdditionalConfigPaths() { | ||
return Collections.singletonList(getUpgrade()); | ||
} | ||
|
||
@Override | ||
public ItemBuilder<ItemStack> 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); | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
160
src/main/java/me/itzjustsamu/playerskills/skill/VeinMinerSkill.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Block> 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<Block> getVeinBlocks(Block originBlock, Material material) { | ||
List<Block> veinBlocks = new ArrayList<>(); | ||
List<Block> queue = new ArrayList<>(); | ||
List<Block> 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<Block> getAdjacentBlocks(Block block) { | ||
List<Block> 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<ConfigPath<?>> getAdditionalConfigPaths() { | ||
return Collections.singletonList(getUpgrade()); | ||
} | ||
|
||
@Override | ||
public ItemBuilder<ItemStack> 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); | ||
} | ||
} |