Results 1 to 4 of 4
- 07-17-2012, 06:43 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 2
- Rep Power
- 0
Java if else statement not working
Most relevant code:
The else statement is not outputting a "1" or sending the player the message as stated.Java Code:if (cmd.getName().equalsIgnoreCase("silkon")) { if (args.length == 0) { if (player.hasPermission("MachiSilk.silktoggle") || player.isOp()) { if (this.activePlayers.contains(playerName)) { player.sendMessage(ChatColor.RED + "Silk Touch mode is already activated."); return true; } this.activePlayers.add(playerName); player.sendMessage(ChatColor.GREEN + "Silk Touch mode enabled. " + ChatColor.DARK_AQUA + "\nType " + ChatColor.YELLOW + "/silkoff" + ChatColor.DARK_AQUA + " to disable silk touch mode."); return true; } else { System.out.println("1"); player.sendMessage(ChatColor.RED + "You do not have permission for this command."); return true; } }
- 07-17-2012, 07:10 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Java if else statement not working
To see what is happening when you run the code use some lines to output useful debugging information:
If you can't understand the output, post it and the code you are using. Note that for code to be readable here it is preferable to use use spaces to indent rather than tab characters and to avoid excessive line length.Java Code:if (cmd.getName().equalsIgnoreCase("silkon")) { System.out.println("silkon: args.length =" + args.length); if (args.length == 0) { System.out.println("has permission = " + player.hasPermission("MachiSilk.silktoggle")); System.out.println("is op = " + player.isOp()); if (player.hasPermission("MachiSilk.silktoggle") || player.isOp()) { System.out.println( "active players contains name = " + this.activePlayers.contains(playerName)); if (this.activePlayers.contains(playerName)) { player.sendMessage( ChatColor.RED + "Silk Touch mode is already activated."); return true; } this.activePlayers.add(playerName); player.sendMessage( ChatColor.GREEN + "Silk Touch mode enabled. " + ChatColor.DARK_AQUA + "\nType " + ChatColor.YELLOW + "/silkoff" + ChatColor.DARK_AQUA + " to disable silk touch mode."); return true; } else { System.out.println("1"); player.sendMessage( ChatColor.RED + "You do not have permission for this command."); return true; } }
- 07-17-2012, 07:13 AM #3
Member
- Join Date
- Jul 2012
- Posts
- 2
- Rep Power
- 0
Re: Java if else statement not working
I've tried placing debugging output lines in other locations and they all work, except within the else statement.
Full .java:
#4269919 - Pastie
- 07-17-2012, 10:28 PM #4
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Similar Threads
-
Why isn't this if statement working?
By ocomobock in forum New To JavaReplies: 3Last Post: 03-27-2012, 02:13 AM -
'if' statement not working?
By Etimer in forum New To JavaReplies: 4Last Post: 03-10-2012, 05:18 AM -
If statement is not working properly
By Alpa in forum New To JavaReplies: 3Last Post: 02-04-2012, 08:40 PM -
SQL statement working in one class but not another
By Dcalladi in forum New To JavaReplies: 4Last Post: 11-11-2011, 01:35 AM -
if statement with strings not working... again
By hardcorebadger in forum New To JavaReplies: 4Last Post: 01-11-2011, 06:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks