Try not to ignore exceptions for oneCode:}catch (Exception e) { }
|
I'm trying to move my commands to a different file from what it originally was to make it easier for me any my brother to find them.
When originally called from the Player.java they worked,
Now loading from a Commands.java calling it as commands.handleCommand none of them work?Code:player.handleCommand(keyword, Arrays.copyOfRange(split, 1, split.length), command.substring(command.indexOf(" ") + 1));
Here's my method that calls them.
Code:private void handleCommand(Player player, Packet packet) { try { String command = packet.getIn().readString(); String[] split = command.split(" "); String keyword = split[0].toLowerCase(); commands.handleCommand(keyword, Arrays.copyOfRange(split, 1, split.length), command.substring(command.indexOf(" ") + 1)); }catch (Exception e) { } }
Here's the method in the commands file.
So what could stop it from working but it worked when it was in Player.java?Code:public void handleCommand(String keyword, String[] args, String fullString) { keyword = keyword.toLowerCase(); if (player.getUsername().equalsIgnoreCase("James")||player.getUsername().equalsIgnoreCase("Vince")) { // Administrators if (keyword.equals("potions") && player.getStaffRights() == 2) { if (player.inWild()) { actionSender.sendMessage("You can't use this command in the wilderness."); return; } inventory.addItem(new Item(2437, 100)); inventory.addItem(new Item(2441, 100)); inventory.addItem(new Item(2443, 100)); inventory.addItem(new Item(2435, 100)); } }}
Try not to ignore exceptions for oneCode:}catch (Exception e) { }
It will only print the stacktrace if something within the method is incorrectly used (E.G misused command format). I'm almost positive your commands method is not being triggered. I feel like you didn't change the packet to read commands from this new method so it's still trying to read them from the old one and that contains none. You can always use System.out.println(""); to try and test if the method even gets triggered. If not, the mistake isn't in the method lol.
This prints Lolcopta2 and not lolcopta which I put in the method of commands.java, if I make it print after commands.Handle command it doesn't print any of the lolcopta's. The method is exactly the same as the one in Player.java, so I don't see how it doesn't work?Code:private void handleCommand(Player player, Packet packet) { try { String command = packet.getIn().readString(); String[] split = command.split(" "); String keyword = split[0].toLowerCase(); System.out.println("Lolcopta2"); commands.handleCommand(keyword, Arrays.copyOfRange(split, 1, split.length), command.substring(command.indexOf(" ") + 1)); //player.handleCommand(keyword, Arrays.copyOfRange(split, 1, split.length), command.substring(command.indexOf(" ") + 1)); } catch (Exception e) { } }
Here's the code that calls the handleCommand(player, packet) rather than the keyword, argument and substring
Code:@Override public void handlePacket(Player player, Packet packet) { switch (packet.getOpcode()) { case COMMAND : handleCommand(player, packet); break; } }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |