|
The great thing about this is when the conditions are met, an exception is thrown that will provide insight into the cause of the problem.Code:public static void crossbowSpecial(Client c, int i) { Player[] players = PlayerHandler.players; if (i < 0 || i > players.length - 1) { throw new IllegalStateException("Cannot perform special on index outside of player capacity."); } Client p = (Client) players[i]; // other code }
Code:[10/23/19, 3:30 PM]: java.lang.IllegalStateException: Cannot perform special on index outside of player capacity. [10/23/19, 3:30 PM]: at server.model.players.combat.range.RangeExtras.crossbowSpecial(RangeExtras.java:53) [10/23/19, 3:30 PM]: at server.model.players.CombatAssistant.crossbowSpecial(CombatAssistant.java:316) [10/23/19, 3:30 PM]: at server.model.players.combat.AttackNPC.delayedHit(AttackNPC.java:216) [10/23/19, 3:30 PM]: at server.model.players.CombatAssistant.delayedHit(CombatAssistant.java:124) [10/23/19, 3:30 PM]: at server.model.players.Client.process(Client.java:859) [10/23/19, 3:30 PM]: at server.model.players.PlayerHandler.process(PlayerHandler.java:151) [10/23/19, 3:30 PM]: at server.Server$1.execute(Server.java:239) [10/23/19, 3:30 PM]: at server.event.Task.tick(Task.java:118) [10/23/19, 3:30 PM]: at server.event.TaskScheduler.run(TaskScheduler.java:103) [10/23/19, 3:30 PM]: at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [10/23/19, 3:30 PM]: at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [10/23/19, 3:30 PM]: at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [10/23/19, 3:30 PM]: at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [10/23/19, 3:30 PM]: at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [10/23/19, 3:30 PM]: at java.base/java.lang.Thread.run(Thread.java:835)
That produces even less useful information in the stacktrace than before... previously it would have thrown an IndexOutOfBoundsException that detailed the actual length of the array and the index you were trying to lookup - now you've removed both of those pieces of information and replaced it with an IllegalStateException that always has the same message.
That is a good point, the message should have been more detailed. I initially thought the exception wasn't being thrown, preventing the user from knowing how the exception was occuring. I didn't see the stack trace initially.
@OP What is line 53 of RangeExtras? Can you provide the surrounding method as well.
Yeah, i mean i fixed the problem by boosting up the max players but i also found something else while looking through im wondering if where it says p if those should be n's to state its referring to the npcs and not another player
Code:public static void crossbowSpecial(Client c, int i) { Client p = (Client)PlayerHandler.players[i]; // error part NPC n = (NPC)NPCHandler.npcs[i]; c.crossbowDamage = 1.4; switch (c.lastArrowUsed) { case 9236: // Lucky Lightning createCombatGFX(c, i, 749, false); c.crossbowDamage = 1.25; break; case 9237: // Earth's Fury createCombatGFX(c, i, 755, false); break; case 9238: // Sea Curse createCombatGFX(c, i, 750, false); c.crossbowDamage = 1.10; break; case 9239: // Down to Earth createCombatGFX(c, i, 757, false); if(c.playerIndex > 0) { p.playerLevel[6] -= 2; p.getPA().refreshSkill(6); p.sendMessage("Your magic has been lowered!"); } break; case 9240: // Clear Mind createCombatGFX(c, i, 751, false); if(c.playerIndex > 0) { p.playerLevel[5] -= 2; p.getPA().refreshSkill(5); p.sendMessage("Your prayer has been lowered!"); c.playerLevel[5] += 2; if(c.playerLevel[5] >= c.getPA().getLevelForXP(c.playerXP[5])) { c.playerLevel[5] = c.getPA().getLevelForXP(c.playerXP[5]); } c.getPA().refreshSkill(5); } break; case 9241: // Magical Posion createCombatGFX(c, i, 752, false); if(c.playerIndex > 0) { p.getPA().appendPoison(6); } break; case 9242: // Blood Forfiet createCombatGFX(c, i, 754, false); if(c.playerLevel[3] - c.playerLevel[3]/20 < 1) { break; } c.handleHitMask(c.playerLevel[3]/20); c.dealDamage(c.playerLevel[3]/20); if(c.npcIndex > 0) { n.handleHitMask(n.HP/10); n.dealDamage(n.HP/10); } else if(c.playerIndex > 0) { p.handleHitMask(c.playerLevel[3]/10); p.dealDamage(c.playerLevel[3]/10); } break; case 9243: // Armour Piercing createCombatGFX(c, i, 758, true); c.crossbowDamage = 1.15; c.ignoreDefence = true; break; case 9244: // Dragon's Breath createCombatGFX(c, i, 756, false); if(c.playerEquipment[c.playerShield] != 1540 || c.playerEquipment[c.playerShield] != 11283 || c.playerEquipment[c.playerShield] != 11284) { c.crossbowDamage = 1.48; } break; case 9245: createCombatGFX(c, i, 753, true); c.crossbowDamage = 1.15; int heal = (int) (c.boltDamage / 3); if (c.playerLevel[3] + heal > c.getPA().getLevelForXP (c.playerXP[3])) { c.playerLevel[3] = c.getPA().getLevelForXP(c.playerXP[3]); } else { c.playerLevel[3] += heal; c.sendMessage("You heal 25% of your current hit."); } break; } }
The issue is you're not doing a check for whether the target is a NPC or a Player. At the moment, the method is accomodating for both. Grabbing a Player for the index targetted, and a NPC for index targetted. That's why when you attack a NPC with an index higher than the maximum players allowed, it's both trying to get a player for that index and a NPC for that index.
please copy + paste the code for createCombatGFX(Player c, int index, int gfx, Boolean idk)
if the index is supposed to refer to a player, find a different method for creating combat gfx that is meant for npcs
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |