Skip to content

Commit b0941a7

Browse files
committed
CrackShot: consider guns as ranged weapons for autoswitch
1 parent 83cb3e4 commit b0941a7

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/main/java/org/mcmonkey/sentinel/SentinelIntegration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.mcmonkey.sentinel;
22

33
import org.bukkit.entity.LivingEntity;
4+
import org.bukkit.inventory.ItemStack;
45

56
/**
67
* Represents an integration of an external plugin or system into Sentinel.
@@ -53,4 +54,12 @@ public boolean isTarget(LivingEntity ent, String text) {
5354
public boolean tryAttack(SentinelTrait st, LivingEntity ent) {
5455
return false;
5556
}
57+
58+
/**
59+
* For autoswitch logic, return 'true' if the item should be considered a valid ranged weapon to swap to.
60+
* If Sentinel's core and all integrations return 'false', the item will be considered a melee weapon.
61+
*/
62+
public boolean itemIsRanged(SentinelTrait sentinel, ItemStack item) {
63+
return false;
64+
}
5665
}

src/main/java/org/mcmonkey/sentinel/SentinelItemHelper.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public boolean isRanged() {
289289
* Returns whether the NPC is holding a ranged weapon.
290290
*/
291291
public boolean isRanged(ItemStack item) {
292-
return usesBow(item)
292+
if (usesBow(item)
293293
|| usesFireball(item)
294294
|| usesSnowball(item)
295295
|| usesLightning(item)
@@ -300,7 +300,15 @@ public boolean isRanged(ItemStack item) {
300300
|| usesSpectral(item)
301301
|| usesPotion(item)
302302
|| usesLlamaSpit(item)
303-
|| usesShulkerBullet(item);
303+
|| usesShulkerBullet(item)) {
304+
return true;
305+
}
306+
for (SentinelIntegration integration : SentinelPlugin.integrations) {
307+
if (integration.itemIsRanged(sentinel, item)) {
308+
return true;
309+
}
310+
}
311+
return false;
304312
}
305313

306314
/**

src/main/java/org/mcmonkey/sentinel/integration/SentinelCrackShot.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ public String[] getTargetPrefixes() {
2222
return new String[0];
2323
}
2424

25+
@Override
26+
public boolean itemIsRanged(SentinelTrait sentinel, ItemStack item) {
27+
if (!(sentinel.getLivingEntity() instanceof Player)) {
28+
return false;
29+
}
30+
CSDirector direc = (CSDirector) Bukkit.getPluginManager().getPlugin("CrackShot");
31+
return direc.itemParentNode(item, (Player) sentinel.getLivingEntity()) != null;
32+
}
33+
2534
@Override
2635
public boolean tryAttack(SentinelTrait st, LivingEntity ent) {
2736
if (!(st.getLivingEntity() instanceof Player)) {

0 commit comments

Comments
 (0)