Plugin Help Config File Help

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

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

    top2001

    Hello, I am creating a plugin which allows you to teleport and set the spawn of the server and I;ve nearly got it working. The only thing which isn't working in the plugin is that /spawn isn't working. If you could look at the code I've done below and help me, it would be greatly appreciated.

    Code:java
    1. package me.top2001.OreCloudTeleport;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Instrument;
    6. import org.bukkit.Location;
    7. import org.bukkit.Note;
    8. import org.bukkit.World;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin{
    15.  
    16. public void onEnable() {
    17. getLogger().info("Plugin Enabled!");
    18. }
    19.  
    20. public void onDisable() {
    21. getLogger().info("Plugin Disabled!");
    22. }
    23.  
    24. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    25. if(sender instanceof Player) {
    26. final String prefix = ChatColor.GREEN + "Ore" + ChatColor.GRAY + "Cloud" + ChatColor.DARK_GREEN + " > ";
    27. Player player = (Player) sender;
    28. Location loc = player.getLocation();
    29. if(cmd.getName().equalsIgnoreCase("tp")) {
    30. if (args.length == 0) {
    31. player.sendMessage(prefix + ChatColor.GREEN + "You haven't specified a player to teleport to!");
    32. player.playNote(loc, Instrument.PIANO, new Note(1));
    33. return true;
    34. }
    35. Player target = Bukkit.getServer().getPlayerExact(args[0]);
    36. if (target == null) {
    37. player.sendMessage(prefix + ChatColor.GREEN + "The player, " + ChatColor.GREEN + args[0] + ChatColor.GREEN + " is currently not online.");
    38. return true;
    39. }
    40. player.teleport(target.getLocation());
    41. return true;
    42. }
    43. if (cmd.getName().equalsIgnoreCase("setspawn")) {
    44. getConfig().set("spawn.world", player.getLocation().getWorld());
    45. getConfig().set("spawn.x", player.getLocation().getX());
    46. getConfig().set("spawn.y", player.getLocation().getY());
    47. getConfig().set("spawn.z", player.getLocation().getZ());
    48. saveConfig();
    49. player.sendMessage(prefix + ChatColor.GREEN + "Spawn location set!");
    50. return true;
    51. }
    52. if(cmd.getName().equalsIgnoreCase("spawn")) {
    53. if (getConfig().getConfigurationSection("spawn") == null) {
    54. player.sendMessage(prefix + ChatColor.GREEN + "Sorry, you cannot go to the spawn as it has not yet been set.");
    55. return true;
    56. }
    57. World w = Bukkit.getServer().getWorld(getConfig().getString("spawn.world"));
    58. double x = getConfig().getDouble("spawn.x");
    59. double y = getConfig().getDouble("spawn.y");
    60. double z = getConfig().getDouble("spawn.z");
    61. player.teleport(new Location(w, x, y, z));
    62. player.sendMessage(prefix + ChatColor.GREEN + "Sent you to the spawn.");
    63. }
    64. }
    65. return false;
    66. }
    67. }
    68.  
     
Thread Status:
Not open for further replies.

Share This Page