This commit is contained in:
nossr50 2024-01-03 01:51:59 -08:00
parent 04c9db88ab
commit 4ba0f76eb9
2 changed files with 12 additions and 8 deletions

View File

@ -17,11 +17,6 @@ public class Crossbows {
public static void processCrossbows(ProjectileHitEvent event, Plugin pluginRef) { public static void processCrossbows(ProjectileHitEvent event, Plugin pluginRef) {
if(event.getEntity() instanceof Arrow originalArrow && event.getHitBlock() != null && event.getHitBlockFace() != null) { if(event.getEntity() instanceof Arrow originalArrow && event.getHitBlock() != null && event.getHitBlockFace() != null) {
if (originalArrow.getShooter() instanceof Player) { if (originalArrow.getShooter() instanceof Player) {
// Avoid infinite spawning of arrows
if (originalArrow.hasMetadata(MetadataConstants.METADATA_KEY_SPAWNED_ARROW)) {
return;
}
McMMOPlayer mmoPlayer = UserManager.getPlayer((Player) originalArrow.getShooter()); McMMOPlayer mmoPlayer = UserManager.getPlayer((Player) originalArrow.getShooter());
if (mmoPlayer != null) { if (mmoPlayer != null) {
mmoPlayer.getCrossbowsManager().handleRicochet( mmoPlayer.getCrossbowsManager().handleRicochet(

View File

@ -4,10 +4,12 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.BowType;
import com.gmail.nossr50.util.MetadataConstants; import com.gmail.nossr50.util.MetadataConstants;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.random.ProbabilityUtil; import com.gmail.nossr50.util.random.ProbabilityUtil;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
@ -39,9 +41,13 @@ public class CrossbowsManager extends SkillManager {
if (originalArrow.hasMetadata(MetadataConstants.METADATA_KEY_BOUNCE_COUNT)) { if (originalArrow.hasMetadata(MetadataConstants.METADATA_KEY_BOUNCE_COUNT)) {
bounceCount = originalArrow.getMetadata(MetadataConstants.METADATA_KEY_BOUNCE_COUNT).get(0).asInt(); bounceCount = originalArrow.getMetadata(MetadataConstants.METADATA_KEY_BOUNCE_COUNT).get(0).asInt();
Bukkit.broadcastMessage("Bounce count: " + bounceCount);
if (bounceCount >= getTrickShotMaxBounceCount()) { if (bounceCount >= getTrickShotMaxBounceCount()) {
Bukkit.broadcastMessage("No more bounces.");
return; return;
} }
} else {
Bukkit.broadcastMessage("No bounce count metadata");
} }
final ProjectileSource originalArrowShooter = originalArrow.getShooter(); final ProjectileSource originalArrowShooter = originalArrow.getShooter();
@ -51,8 +57,12 @@ public class CrossbowsManager extends SkillManager {
// check the angle of the arrow against the inverse normal to see if the angle was too shallow // check the angle of the arrow against the inverse normal to see if the angle was too shallow
if (arrowInBlockVector.angle(inverseNormal) < Math.PI / 4) { // only checks angle on the first bounce
if (bounceCount == 0 && arrowInBlockVector.angle(inverseNormal) < Math.PI / 4) {
Bukkit.broadcastMessage("No bouncing.");
return; return;
} else {
Bukkit.broadcastMessage("Bouncing.");
} }
// Spawn new arrow with the reflected direction // Spawn new arrow with the reflected direction
@ -64,8 +74,7 @@ public class CrossbowsManager extends SkillManager {
arrow.setMetadata(MetadataConstants.METADATA_KEY_SPAWNED_ARROW, arrow.setMetadata(MetadataConstants.METADATA_KEY_SPAWNED_ARROW,
new FixedMetadataValue(pluginRef, originalArrowShooter)); new FixedMetadataValue(pluginRef, originalArrowShooter));
arrow.setMetadata(MetadataConstants.METADATA_KEY_BOW_TYPE, arrow.setMetadata(MetadataConstants.METADATA_KEY_BOW_TYPE,
new FixedMetadataValue(pluginRef, originalArrow.getMetadata( new FixedMetadataValue(pluginRef, BowType.CROSSBOW));
MetadataConstants.METADATA_KEY_BOW_TYPE).get(0)));
originalArrow.remove(); originalArrow.remove();
} }