mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-12-17 06:18:46 +01:00
add Spears interactions to CombatUtils
This commit is contained in:
@@ -166,20 +166,6 @@ public final class ItemUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Unit tests
|
|
||||||
public static boolean isCrossbow(@NotNull ItemStack item) {
|
|
||||||
return mcMMO.getMaterialMapStore().isCrossbow(item.getType().getKey().getKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Unit tests
|
|
||||||
public static boolean isTrident(@NotNull ItemStack item) {
|
|
||||||
return mcMMO.getMaterialMapStore().isTrident(item.getType().getKey().getKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isMace(@NotNull ItemStack item) {
|
|
||||||
return mcMMO.getMaterialMapStore().isMace(item.getType().getKey().getKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasItemInEitherHand(@NotNull Player player, Material material) {
|
public static boolean hasItemInEitherHand(@NotNull Player player, Material material) {
|
||||||
return player.getInventory().getItemInMainHand().getType() == material
|
return player.getInventory().getItemInMainHand().getType() == material
|
||||||
|| player.getInventory().getItemInOffHand().getType() == material;
|
|| player.getInventory().getItemInOffHand().getType() == material;
|
||||||
@@ -276,6 +262,46 @@ public final class ItemUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the item is a crossbow.
|
||||||
|
*
|
||||||
|
* @param item Item to check
|
||||||
|
* @return true if the item is a crossbow, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isCrossbow(@NotNull ItemStack item) {
|
||||||
|
return mcMMO.getMaterialMapStore().isCrossbow(item.getType().getKey().getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the item is a trident.
|
||||||
|
*
|
||||||
|
* @param item Item to check
|
||||||
|
* @return true if the item is a trident, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isTrident(@NotNull ItemStack item) {
|
||||||
|
return mcMMO.getMaterialMapStore().isTrident(item.getType().getKey().getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the item is a mace.
|
||||||
|
*
|
||||||
|
* @param item Item to check
|
||||||
|
* @return true if the item is a mace, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isMace(@NotNull ItemStack item) {
|
||||||
|
return mcMMO.getMaterialMapStore().isMace(item.getType().getKey().getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the item is a spear.
|
||||||
|
* @param item Item to check
|
||||||
|
*
|
||||||
|
* @return true if the item is a spear, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isSpear(@NotNull ItemStack item) {
|
||||||
|
return mcMMO.getMaterialMapStore().isSpear(item.getType().getKey().getKey());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the item is a sword.
|
* Checks if the item is a sword.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -51,9 +51,10 @@ public class MaterialMapStore {
|
|||||||
private final @NotNull HashSet<String> tridents;
|
private final @NotNull HashSet<String> tridents;
|
||||||
private final @NotNull HashSet<String> bows;
|
private final @NotNull HashSet<String> bows;
|
||||||
private final @NotNull HashSet<String> crossbows;
|
private final @NotNull HashSet<String> crossbows;
|
||||||
private final @NotNull HashSet<String> tools;
|
|
||||||
private final @NotNull HashSet<String> enchantables;
|
|
||||||
private final @NotNull HashSet<String> maces;
|
private final @NotNull HashSet<String> maces;
|
||||||
|
private final @NotNull HashSet<String> spears;
|
||||||
|
private final @NotNull HashSet<String> enchantables;
|
||||||
|
private final @NotNull HashSet<String> tools;
|
||||||
|
|
||||||
private final @NotNull HashSet<String> ores;
|
private final @NotNull HashSet<String> ores;
|
||||||
private final @NotNull HashSet<String> intendedToolPickAxe;
|
private final @NotNull HashSet<String> intendedToolPickAxe;
|
||||||
@@ -95,15 +96,15 @@ public class MaterialMapStore {
|
|||||||
crossbows = new HashSet<>();
|
crossbows = new HashSet<>();
|
||||||
stringTools = new HashSet<>();
|
stringTools = new HashSet<>();
|
||||||
prismarineTools = new HashSet<>();
|
prismarineTools = new HashSet<>();
|
||||||
tools = new HashSet<>();
|
|
||||||
|
|
||||||
swords = new HashSet<>();
|
swords = new HashSet<>();
|
||||||
axes = new HashSet<>();
|
axes = new HashSet<>();
|
||||||
pickAxes = new HashSet<>();
|
pickAxes = new HashSet<>();
|
||||||
shovels = new HashSet<>();
|
shovels = new HashSet<>();
|
||||||
hoes = new HashSet<>();
|
hoes = new HashSet<>();
|
||||||
tridents = new HashSet<>();
|
tridents = new HashSet<>();
|
||||||
|
spears = new HashSet<>();
|
||||||
maces = new HashSet<>();
|
maces = new HashSet<>();
|
||||||
|
tools = new HashSet<>();
|
||||||
|
|
||||||
enchantables = new HashSet<>();
|
enchantables = new HashSet<>();
|
||||||
|
|
||||||
@@ -459,6 +460,7 @@ public class MaterialMapStore {
|
|||||||
enchantables.addAll(bows);
|
enchantables.addAll(bows);
|
||||||
enchantables.addAll(crossbows);
|
enchantables.addAll(crossbows);
|
||||||
enchantables.addAll(maces);
|
enchantables.addAll(maces);
|
||||||
|
enchantables.addAll(spears);
|
||||||
|
|
||||||
enchantables.add("shears");
|
enchantables.add("shears");
|
||||||
enchantables.add("fishing_rod");
|
enchantables.add("fishing_rod");
|
||||||
@@ -484,6 +486,7 @@ public class MaterialMapStore {
|
|||||||
fillShovels();
|
fillShovels();
|
||||||
fillTridents();
|
fillTridents();
|
||||||
fillMaces();
|
fillMaces();
|
||||||
|
fillSpears();
|
||||||
fillStringTools();
|
fillStringTools();
|
||||||
fillPrismarineTools();
|
fillPrismarineTools();
|
||||||
fillBows();
|
fillBows();
|
||||||
@@ -502,6 +505,7 @@ public class MaterialMapStore {
|
|||||||
tools.addAll(bows);
|
tools.addAll(bows);
|
||||||
tools.addAll(crossbows);
|
tools.addAll(crossbows);
|
||||||
tools.addAll(maces);
|
tools.addAll(maces);
|
||||||
|
tools.addAll(spears);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillBows() {
|
private void fillBows() {
|
||||||
@@ -527,6 +531,16 @@ public class MaterialMapStore {
|
|||||||
maces.add("mace");
|
maces.add("mace");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillSpears() {
|
||||||
|
spears.add("wooden_spear");
|
||||||
|
spears.add("stone_spear");
|
||||||
|
spears.add("copper_spear");
|
||||||
|
spears.add("iron_spear");
|
||||||
|
spears.add("golden_spear");
|
||||||
|
spears.add("diamond_spear");
|
||||||
|
spears.add("netherite_spear");
|
||||||
|
}
|
||||||
|
|
||||||
private void fillTridents() {
|
private void fillTridents() {
|
||||||
tridents.add("trident");
|
tridents.add("trident");
|
||||||
}
|
}
|
||||||
@@ -874,6 +888,14 @@ public class MaterialMapStore {
|
|||||||
return maces.contains(id);
|
return maces.contains(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSpear(@NotNull Material material) {
|
||||||
|
return isSpear(material.getKey().getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSpear(@NotNull String id) {
|
||||||
|
return spears.contains(id);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isLeatherArmor(@NotNull Material material) {
|
public boolean isLeatherArmor(@NotNull Material material) {
|
||||||
return isLeatherArmor(material.getKey().getKey());
|
return isLeatherArmor(material.getKey().getKey());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
|||||||
import com.gmail.nossr50.skills.archery.ArcheryManager;
|
import com.gmail.nossr50.skills.archery.ArcheryManager;
|
||||||
import com.gmail.nossr50.skills.axes.AxesManager;
|
import com.gmail.nossr50.skills.axes.AxesManager;
|
||||||
import com.gmail.nossr50.skills.maces.MacesManager;
|
import com.gmail.nossr50.skills.maces.MacesManager;
|
||||||
|
import com.gmail.nossr50.skills.spears.SpearsManager;
|
||||||
import com.gmail.nossr50.skills.swords.SwordsManager;
|
import com.gmail.nossr50.skills.swords.SwordsManager;
|
||||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||||
import com.gmail.nossr50.skills.tridents.TridentsManager;
|
import com.gmail.nossr50.skills.tridents.TridentsManager;
|
||||||
@@ -331,6 +332,41 @@ public final class CombatUtils {
|
|||||||
printFinalDamageDebug(player, event, mmoPlayer);
|
printFinalDamageDebug(player, event, mmoPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void processSpearsCombat(@NotNull LivingEntity target,
|
||||||
|
@NotNull Player player,
|
||||||
|
@NotNull EntityDamageByEntityEvent event) {
|
||||||
|
if (event.getCause() == DamageCause.THORNS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double boostedDamage = event.getDamage();
|
||||||
|
|
||||||
|
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
|
//Make sure the profiles been loaded
|
||||||
|
if (mmoPlayer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final SpearsManager spearsManager = mmoPlayer.getSpearsManager();
|
||||||
|
|
||||||
|
// Apply Limit Break DMG
|
||||||
|
if (canUseLimitBreak(player, target, SubSkillType.SPEARS_SPEARS_LIMIT_BREAK)) {
|
||||||
|
boostedDamage += (getLimitBreakDamage(
|
||||||
|
player, target, SubSkillType.SPEARS_SPEARS_LIMIT_BREAK)
|
||||||
|
* mmoPlayer.getAttackStrength());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Apply any other damage boosts for spears here
|
||||||
|
|
||||||
|
event.setDamage(boostedDamage);
|
||||||
|
|
||||||
|
// TODO: Apply any non-damage effects here
|
||||||
|
|
||||||
|
processCombatXP(mmoPlayer, target, PrimarySkillType.SPEARS);
|
||||||
|
printFinalDamageDebug(player, event, mmoPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
private static void processAxeCombat(@NotNull LivingEntity target, @NotNull Player player,
|
private static void processAxeCombat(@NotNull LivingEntity target, @NotNull Player player,
|
||||||
@NotNull EntityDamageByEntityEvent event) {
|
@NotNull EntityDamageByEntityEvent event) {
|
||||||
if (event.getCause() == DamageCause.THORNS) {
|
if (event.getCause() == DamageCause.THORNS) {
|
||||||
@@ -642,6 +678,15 @@ public final class CombatUtils {
|
|||||||
.doesPlayerHaveSkillPermission(player, PrimarySkillType.MACES)) {
|
.doesPlayerHaveSkillPermission(player, PrimarySkillType.MACES)) {
|
||||||
processMacesCombat(target, player, event);
|
processMacesCombat(target, player, event);
|
||||||
}
|
}
|
||||||
|
} else if (ItemUtils.isSpear(heldItem)) {
|
||||||
|
if (!mcMMO.p.getSkillTools()
|
||||||
|
.canCombatSkillsTrigger(PrimarySkillType.SPEARS, target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mcMMO.p.getSkillTools()
|
||||||
|
.doesPlayerHaveSkillPermission(player, PrimarySkillType.SPEARS)) {
|
||||||
|
processSpearsCombat(target, player, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (entityType == EntityType.WOLF) {
|
} else if (entityType == EntityType.WOLF) {
|
||||||
Wolf wolf = (Wolf) painSource;
|
Wolf wolf = (Wolf) painSource;
|
||||||
|
|||||||
Reference in New Issue
Block a user