Code: if(commandLabel.equalsIgnoreCase("tp")) { if(player.hasPermission("BC.tp.*") == true || player.hasPermission("BC.tp.p2p") == true) { if(args.length == 0) { eC.sendMultiColouredMessage(player, "You must select a player"); eC.sendColouredMessage(player, "Usage: /tp <player>"); }else if(args.length == 1) { Player targetPlayer = player.getServer().getPlayer(args[0]); if(targetPlayer.isOnline() == true) { Location loc = targetPlayer.getLocation(); player.teleport(loc); player.sendMessage(ChatColor.GOLD + "You teleported to: " + args[0]); }else if(targetPlayer.isOnline() == false){ eC.sendColouredMessage(player, "Player is not online!"); } }else if(args.length >= 2) { player.sendMessage(ChatColor.WHITE + PREFIX + ChatColor.BLUE + " Not yet supported!"); } }else if(player.hasPermission("BC.tp.*") == false || player.hasPermission("BC.tp.p2p") == true) { player.sendMessage(PERM); } } code for the command Code: 09:30:52 [SEVERE] null org.bukkit.command.CommandException: Unhandled exception executing command 'tp' in plugin BaseCommands v1.01 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166) at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:479) at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:821) at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764) at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34) at net.minecraft.server.NetworkManager.b(NetworkManager.java:229) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113) at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78) at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459) at net.minecraft.server.ThreadServerApplication.run(SourceFile:492) Caused by: java.lang.NullPointerException at com.github.catchaser.BaseCommandsCommandExecutor.onCommand(BaseCommandsCommandExecutor.java:69) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40) ... 12 more The error I have tried changing the targetPlayer.isOnline() thing like 5 times and still cant figure it out any ideas?
targetPlayer is probably null player.getServer().getPlayer(args[0]) You need to check if the player with a name args[0] is online.
Change this: Code: }else if(args.length == 1) { Player targetPlayer = player.getServer().getPlayer(args[0]); if(targetPlayer.isOnline() == true) { Location loc = targetPlayer.getLocation(); player.teleport(loc); player.sendMessage(ChatColor.GOLD + "You teleported to: " + args[0]); }else if(targetPlayer.isOnline() == false){ eC.sendColouredMessage(player, "Player is not online!"); } to this: Code: }else if(args.length == 1) { Player targetPlayer = player.getServer().getPlayer(args[0]); Location loc = targetPlayer.getLocation(); player.teleport(loc); player.sendMessage(ChatColor.GOLD + "You teleported to: " + "" + targetplayer.getName()); return true; if(!targetPlayer.isOnline()){ eC.sendColouredMessage(player, "Player is not online!"); return false; } Lacked the return statments(return true; and return false; )of the boolean; for check if a player is offline use the ! before targetplayer.isOnline(); for send the targetplayer's name in the chat you must write "" before the + targetplayer, and get the targetplayer's name with targetplayer.getName().
The Player player is the (Player) sender? If not, type this: Code: Player player = (Player) sender; And for check if player has permission use: Code: if(player.hasPermissions("permission.node.here")) { Don't use == true or == false, for check if is false, use this code(the ! before player.hasPermissions()): Code: if(!player.hasPermissions("permission.node.here")) {
if(!targetPlayer.isOnline()){ eC.sendColouredMessage(player, "Player is not online!"); return false; } I get unreachable code in eclipse with this part
What is eC, a player? For send colored message you can do this: Code: player.sendMessage(ChatColor.GREEN + "Message"); I use green at default, change it to the color you want.
no eC is for something else Extras thing http://forums.bukkit.org/threads/de...methods-for-plugin-developers-1-0-1-r1.26207/
If you want to send a coloured message to the player try this: Code: if(!targetPlayer.isOnline()){ player.sendMessage("" + targetplayer.getName() + " is not online!"); return false; }
i tried moving and got rid of that error but when i try the command it gives me an error Code: if(commandLabel.equalsIgnoreCase("tp")) { if(player.hasPermission("BC.tp.*")|| player.hasPermission("BC.tp.p2p")) { if(args.length == 0) { eC.sendMultiColouredMessage(player, "You must select a player"); eC.sendColouredMessage(player, "Usage: /tp <player>"); }else if(args.length == 1) { Player targetPlayer = player.getServer().getPlayer(args[0]); if(!targetPlayer.isOnline()){ eC.sendColouredMessage(player, "Player is not online!"); return true; } Location loc = targetPlayer.getLocation(); player.teleport(loc); player.sendMessage(ChatColor.GOLD + "You teleported to: " + "" + targetPlayer.getName()); return true; }else if(args.length >= 2) { player.sendMessage(ChatColor.WHITE + PREFIX + ChatColor.BLUE + " Not yet supported!"); } }else if(!(player.hasPermission("BC.tp.*") || player.hasPermission("BC.tp.p2p"))) { player.sendMessage(PERM); } } error: Line 69 is the if(!targetPlayer.isOnline()) thing Code: 10:39:36 [SEVERE] null org.bukkit.command.CommandException: Unhandled exception executing command 'tp' in plugin BaseCommands v1.01 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166) at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:479) at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:821) at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764) at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34) at net.minecraft.server.NetworkManager.b(NetworkManager.java:229) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113) at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78) at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459) at net.minecraft.server.ThreadServerApplication.run(SourceFile:492) Caused by: java.lang.NullPointerException at com.github.catchaser.BaseCommandsCommandExecutor.onCommand(BaseCommandsCommandExecutor.java:69) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40) ... 12 more
nvm fixed it: from: Code: if(commandLabel.equalsIgnoreCase("tp")) { if(player.hasPermission("BC.tp.*")|| player.hasPermission("BC.tp.p2p")) { if(args.length == 0) { eC.sendMultiColouredMessage(player, "You must select a player"); eC.sendColouredMessage(player, "Usage: /tp <player>"); }else if(args.length == 1) { Player targetPlayer = player.getServer().getPlayer(args[0]); if(!targetPlayer.isOnline()){ eC.sendColouredMessage(player, "Player is not online!"); return true; } Location loc = targetPlayer.getLocation(); player.teleport(loc); player.sendMessage(ChatColor.GOLD + "You teleported to: " + "" + targetPlayer.getName()); return true; }else if(args.length >= 2) { player.sendMessage(ChatColor.WHITE + PREFIX + ChatColor.BLUE + " Not yet supported!"); } }else if(!(player.hasPermission("BC.tp.*") || player.hasPermission("BC.tp.p2p"))) { player.sendMessage(PERM); } } to: Code: if(commandLabel.equalsIgnoreCase("tp")) { if(player.hasPermission("BC.tp.*")|| player.hasPermission("BC.tp.p2p")) { if(args.length == 0) { eC.sendMultiColouredMessage(player, "You must select a player"); eC.sendColouredMessage(player, "Usage: /tp <player>"); }else if(args.length == 1) { Player targetPlayer = player.getServer().getPlayer(args[0]); if(targetPlayer == null){ eC.sendMultiColouredMessage(player, "Player is not online!"); return true; }else if(targetPlayer != null){ Location loc = targetPlayer.getLocation(); player.teleport(loc); player.sendMessage(ChatColor.GOLD + "You teleported to: " + "" + targetPlayer.getName()); return true; } }else if(args.length >= 2) { player.sendMessage(ChatColor.WHITE + PREFIX + ChatColor.BLUE + " Not yet supported!"); } }else if(!(player.hasPermission("BC.tp.*") || player.hasPermission("BC.tp.p2p"))) { player.sendMessage(PERM); } } changed the if(!(targetPlayer.isOnline()) to if(targetPlayer == null)