Skip to content

Commit

Permalink
CrackShot: consider guns as ranged weapons for autoswitch
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 11, 2024
1 parent 83cb3e4 commit b0941a7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/mcmonkey/sentinel/SentinelIntegration.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mcmonkey.sentinel;

import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;

/**
* Represents an integration of an external plugin or system into Sentinel.
Expand Down Expand Up @@ -53,4 +54,12 @@ public boolean isTarget(LivingEntity ent, String text) {
public boolean tryAttack(SentinelTrait st, LivingEntity ent) {
return false;
}

/**
* For autoswitch logic, return 'true' if the item should be considered a valid ranged weapon to swap to.
* If Sentinel's core and all integrations return 'false', the item will be considered a melee weapon.
*/
public boolean itemIsRanged(SentinelTrait sentinel, ItemStack item) {
return false;
}
}
12 changes: 10 additions & 2 deletions src/main/java/org/mcmonkey/sentinel/SentinelItemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public boolean isRanged() {
* Returns whether the NPC is holding a ranged weapon.
*/
public boolean isRanged(ItemStack item) {
return usesBow(item)
if (usesBow(item)
|| usesFireball(item)
|| usesSnowball(item)
|| usesLightning(item)
Expand All @@ -300,7 +300,15 @@ public boolean isRanged(ItemStack item) {
|| usesSpectral(item)
|| usesPotion(item)
|| usesLlamaSpit(item)
|| usesShulkerBullet(item);
|| usesShulkerBullet(item)) {
return true;
}
for (SentinelIntegration integration : SentinelPlugin.integrations) {
if (integration.itemIsRanged(sentinel, item)) {
return true;
}
}
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public String[] getTargetPrefixes() {
return new String[0];
}

@Override
public boolean itemIsRanged(SentinelTrait sentinel, ItemStack item) {
if (!(sentinel.getLivingEntity() instanceof Player)) {
return false;
}
CSDirector direc = (CSDirector) Bukkit.getPluginManager().getPlugin("CrackShot");
return direc.itemParentNode(item, (Player) sentinel.getLivingEntity()) != null;
}

@Override
public boolean tryAttack(SentinelTrait st, LivingEntity ent) {
if (!(st.getLivingEntity() instanceof Player)) {
Expand Down

0 comments on commit b0941a7

Please sign in to comment.