Plugin Help Teleport Plugin Help

Discussion in 'Plugin Help/Development/Requests' started by top2001, Nov 29, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    top2001

    Hello, I've been making a plugin for a server recently but I was wondering how I get a message to appear in the chat if the player is offline? If you could merge it into the below code, it would be more than helpful :)

    Code:java
    1. package me.top2001.OreCloudTeleport;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin{
    12.  
    13. public void onEnable() {
    14. getLogger().info("Plugin Enabled!");
    15. }
    16.  
    17. public void onDisable() {
    18. getLogger().info("Plugin Disabled!");
    19. }
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    22. if(sender instanceof Player) {
    23. final String prefix = ChatColor.GREEN + "Ore" + ChatColor.GRAY + "Cloud" + ChatColor.DARK_GREEN + " > ";
    24. Player player = (Player) sender;
    25. Location loc = player.getLocation();
    26. if(cmd.getName().equalsIgnoreCase("tp")) {
    27. if (args.length == 0) {
    28. player.sendMessage(prefix + ChatColor.GREEN + "Please specify a player. (/tp <Player> {TargetPlayer})");
    29. }else if (args.length == 1) {
    30. Player targetPlayer = player.getServer().getPlayerExact(args[0]);
    31. Location targetPlayerLocation = targetPlayer.getLocation();
    32. player.teleport(targetPlayerLocation);
    33. player.sendMessage(prefix + ChatColor.GREEN + "Now teleporting...");
    34. }else if (args.length == 2) {
    35. Player targetPlayer = player.getServer().getPlayerExact(args[0]);
    36. Player targetPlayer1 = player.getServer().getPlayerExact(args[1]);
    37. Location targetPlayer1Location = targetPlayer1.getLocation();
    38. targetPlayer.teleport(targetPlayer1Location);
    39. player.sendMessage(prefix + ChatColor.GREEN + "Now teleporting...");
    40. }
    41. Player targetPlayer = Bukkit.getServer().getPlayerExact(args[0]);
    42. if (targetPlayer == null) {
    43. player.sendMessage(prefix + ChatColor.GREEN + "The player, " + ChatColor.DARK_GREEN + args[0] + ChatColor.GREEN + ", is currently not online.");
    44. }
    45. Player targetPlayer1 = Bukkit.getServer().getPlayerExact(args[1]);
    46. if (targetPlayer1 == null) {
    47. player.sendMessage(prefix + ChatColor.GREEN + "The player, " + ChatColor.DARK_GREEN + args[1] + ChatColor.GREEN + ", is currently not online.");
    48. }
    49. }
    50. // Sets Spawn.
    51. if(cmd.getName().equalsIgnoreCase("setspawn")) {
    52. if(sender.hasPermission("orecloudteleport.setspawn")){
    53. player.getWorld().setSpawnLocation(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
    54. player.sendMessage(prefix + ChatColor.GREEN + "Spawn location created.");
    55. }else{
    56. player.sendMessage(prefix + ChatColor.RED + "Sorry, you don't have permission to perform this command.");
    57. }
    58. }
    59. // Teleport Player To Spawn.
    60. if (cmd.getName().equalsIgnoreCase("spawn")) {
    61. if(sender.hasPermission("orecloudteleport.spawn")){
    62. player.teleport(player.getWorld().getSpawnLocation());
    63. player.sendMessage(prefix + ChatColor.GREEN + "Now sending you to spawn...");
    64. }else{
    65. player.sendMessage(prefix + ChatColor.RED + "Sorry, you don't have permission to perform this command.");
    66. return true;
    67. }
    68. }
    69. }
    70. return false;
    71. }
    72. }
    73.  
     
Thread Status:
Not open for further replies.

Share This Page