Setting and teleporting to a spawn for each world.

Discussion in 'Bukkit Help' started by jts3304, Jul 27, 2014.

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

    jts3304

    So I've been working on a plugin that creates per world spawns.

    I've made two commands:
    * /setspawn [x] [y] [z] [world] - this sets the spawn for that world at the specified coordinates otherwise at the player's location.
    * /spawn [player] [world] - Teleports the specified player to the spawn of the specified world, otherwise it teleports the player who sent the command.

    Here is my code for /setspawn
    Code:java
    1. package me.jts3304.masterplugin.commands;
    2.  
    3. import me.jts3304.masterplugin.utils.CommandSource;
    4. import me.jts3304.masterplugin.utils.Person;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Server;
    9. import org.bukkit.World;
    10. import org.bukkit.command.Command;
    11.  
    12. public class Commandsetspawn extends MasterPluginCommand
    13. {
    14. public Commandsetspawn()
    15. {
    16. super("setspawn");
    17. }
    18.  
    19. @Override
    20. public void run(Server server, CommandSource source, Command command, String label, String[] args) throws Exception
    21. {
    22. if(args.length == 4)
    23. {
    24. if(Integer.valueOf(args[0]) == null)
    25. {
    26. source.sendMessage(ChatColor.RED + "The first argument should be a number.");
    27. }
    28. if(Integer.valueOf(args[1]) == null)
    29. {
    30. source.sendMessage(ChatColor.RED + "The second argument should be a number.");
    31. }
    32. if(Integer.valueOf(args[2]) == null)
    33. {
    34. source.sendMessage(ChatColor.RED + "The third argument should be a number.");
    35. } else
    36. {
    37. World world = Bukkit.getWorld(args[3]);
    38. int x = Integer.valueOf(args[0]);
    39. int y = Integer.valueOf(args[1]);
    40. int z = Integer.valueOf(args[2]);
    41. world.setSpawnLocation(x, y, z);
    42. source.sendMessage("The spawn of " + world.getName() + " has been set to (" + x + " " + y + " " + z + " " + ").");
    43. }
    44. } else
    45. {
    46. throw new NotEnoughArgumentsException();
    47. }
    48. }
    49.  
    50. @Override
    51. public void run(Server server, Person person, Command command, String label, String[] args) throws Exception
    52. {
    53. if(args.length == 3)
    54. {
    55. if(Integer.valueOf(args[0]) != null && Integer.valueOf(args[1]) != null && Integer.valueOf(args[2]) != null)
    56. {
    57. World world = person.getWorld();
    58. int x = Integer.valueOf(args[0]);
    59. int y = Integer.valueOf(args[1]);
    60. int z = Integer.valueOf(args[2]);
    61. world.setSpawnLocation(x, y, z);
    62. person.sendMessage("The spawn of " + world.getName() + " has been set to (" + x + " " + y + " " + z + " " + ").");
    63. } else
    64. {
    65. person.getWorld().setSpawnLocation(person.getBlockX(), person.getBlockY(), person.getBlockZ());
    66. person.sendMessage("The spawn of " + person.getWorld().getName() + " has been set to (" + person.getBlockX() + person.getBlockY() + person.getBlockZ() + ").");
    67. }
    68. }
    69. if(args.length == 4)
    70. {
    71. if(Integer.valueOf(args[0]) != null && Integer.valueOf(args[1]) != null && Integer.valueOf(args[2]) != null)
    72. {
    73. World world = Bukkit.getWorld(args[3]);
    74. int x = Integer.valueOf(args[0]);
    75. int y = Integer.valueOf(args[1]);
    76. int z = Integer.valueOf(args[2]);
    77. world.setSpawnLocation(x, y, z);
    78. person.sendMessage("The spawn of " + world.getName() + " has been set to (" + x + " " + y + " " + z + " " + ").");
    79. } else
    80. {
    81. person.getWorld().setSpawnLocation(person.getBlockX(), person.getBlockY(), person.getBlockZ());
    82. person.sendMessage("The spawn of " + person.getWorld().getName() + " has been set to (" + person.getBlockX() + person.getBlockY() + person.getBlockZ() + ").");
    83. }
    84. } else
    85. {
    86. person.getWorld().setSpawnLocation(person.getBlockX(), person.getBlockY(), person.getBlockZ());
    87. person.sendMessage("The spawn of " + person.getWorld().getName() + " has been set to (" + person.getBlockX() + " " + person.getBlockY() + " " + person.getBlockZ()
    88. + ").");
    89. }
    90. }
    91. }


    And here is the code for /spawn
    Code:java
    1. package me.jts3304.masterplugin.commands;
    2.  
    3. import me.jts3304.masterplugin.utils.CommandSource;
    4. import me.jts3304.masterplugin.utils.Person;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Server;
    9. import org.bukkit.World;
    10. import org.bukkit.command.Command;
    11.  
    12. public class Commandspawn extends MasterPluginCommand
    13. {
    14. public Commandspawn()
    15. {
    16. super("spawn");
    17. }
    18.  
    19. @Override
    20. public void run(Server server, CommandSource source, Command command, String label, String[] args) throws Exception
    21. {
    22. if(args.length == 2)
    23. {
    24. if(args[1] == "~")
    25. {
    26. Person person = Person.getPerson(args[0]);
    27. World world = person.getWorld();
    28. person.teleport(world.getSpawnLocation());
    29. source.sendMessage("Teleporting " + person.getName() + " to the spawn of the world they are in...");
    30. } else
    31. {
    32. // World
    33. World world = Bukkit.getWorld(args[1]);
    34. //
    35. // Person
    36. Person person = Person.getPerson(args[0]);
    37. person.teleport(world.getSpawnLocation());
    38. source.sendMessage("Teleporting " + person.getName() + " to " + world.getName() + "'s spawn...");
    39. }
    40. } else
    41. {
    42. throw new NotEnoughArgumentsException();
    43. }
    44. }
    45.  
    46. @Override
    47. public void run(Server server, Person person, Command command, String label, String[] args)
    48. {
    49. if(person.hasPermission("masterplugin.spawn.others"))
    50. {
    51. if(args.length == 1)
    52. {
    53. Person target = Person.getPerson(args[0]);
    54. World world = person.getWorld();
    55. target.teleport(world.getSpawnLocation());
    56. person.sendMessage(ChatColor.GREEN + "Teleporting " + target.getName() + " to this world's spawn...");
    57. }
    58. if(args.length == 2)
    59. {
    60. if(args[1] == "~")
    61. {
    62. Person target = Person.getPerson(args[0]);
    63. World world = person.getWorld();
    64. target.teleport(world.getSpawnLocation());
    65. person.sendMessage("Teleporting " + person.getName() + " to the spawn of the world they are in...");
    66. } else
    67. {
    68. // World
    69. World world = Bukkit.getWorld(args[1]);
    70. //
    71. // Person
    72. Person target = Person.getPerson(args[0]);
    73. target.teleport(world.getSpawnLocation());
    74. person.sendMessage("Teleporting " + person.getName() + " to " + world.getName() + "'s spawn...");
    75. }
    76. }
    77. } else
    78. {
    79. person.denyAccess();
    80. }
    81. if(args.length != 1 && args.length != 2)
    82. {
    83. person.teleport(person.getWorld().getSpawnLocation());
    84. person.sendMessage(ChatColor.GREEN + "Teleportig to this world's spawn...");
    85. }
    86.  
    87. }
    88. }


    Here is my plugin.yml
    name: MasterPlugin
    version: 0.2.05
    main: me.jts3304.masterplugin.MasterPlugin
    description: |
    Basic plugin for the Brotherhood public server.
    author: jts3304
    commands:
    spawn:
    description: Teleport to the world's spawn.
    usage: /<command>
    setspawn:
    description: Set the spawn of the world.
    usage: /<command> [x] [y] [z] [world]
    permissions:
    masterplugin.*:
    description: Gives access to all MasterPlugin commands.

    default: false

    /setspawn works fine, but when I type /spawn nothing happens. I checked my code but I didn't see anything that would affect the command. Could someone tell me what I'm doing wrong. It registers the command and everything. I checked the log, it said I typed the command but it didn't say anything in the chat or the log.
     
Thread Status:
Not open for further replies.

Share This Page