Help with warp command

Discussion in 'Plugin Development' started by MinecraftZach443, Nov 21, 2013.

Thread Status:
Not open for further replies.
  1. I am trying to make a "/warp" "/setwarp" command. Its usage would be like "/warp <warp-name>" for the first and then obviously the second one would set a warp to the location of the sender.
    I was asking around on the BukkitDev IRC and one guy tried to help me but he only gave me some very rushed and faulty code. I have not been able to get back with him since then as our time zones are 13 hours apart.
    I am totally clueless about how to make that kind of command. Here is what he gave me:

    Code:java
    1.  
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.plugin.PluginManager;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener {
    16.  
    17. PluginManager pm = Bukkit.getServer().getPluginManager();
    18.  
    19. HashMap<String, Object> warpNames = new HashMap<String, Object>();
    20.  
    21. @Override
    22. public void onEnable() {
    23. this.getServer().getLogger().info("TestCode Enabled!");
    24. pm.registerEvents(this, this);
    25. this.getConfig().options().copyDefaults();
    26. this.saveConfig();
    27. warpNames = (HashMap<String, Object>) this.getConfig().getConfigurationSection("Warps").getValues(false);
    28. }
    29.  
    30. @Override
    31. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    32. Player p = (Player) sender;
    33. if(cmd.getName().equalsIgnoreCase("setwarp")) {
    34. if(!warpNames.containsKey(args[0])) {
    35. Location loc = p.getLocation();
    36. warpNames.put(args[0], loc);
    37. this.getConfig().set("Warps", warpNames);
    38. this.getConfig().set("Warps." + args[1] + ".Location", loc);
    39. this.saveConfig();
    40. p.sendMessage(ChatColor.GREEN + "Warp Successfully Created!");
    41. }else{
    42. p.sendMessage(ChatColor.RED + "Sorry, this Warp already Exists!");
    43. }
    44. }else if(cmd.getName().equalsIgnoreCase("delwarp")) {
    45. if(warpNames.containsKey(args[0])) {
    46. warpNames.remove(args[0]);
    47. this.getConfig().set("Warps", warpNames);
    48. this.saveConfig();
    49. p.sendMessage(ChatColor.GREEN + "Warp Successfully Deleted!");
    50. }else{
    51. p.sendMessage(ChatColor.RED + "Sorry, this Warp does not Exist!");
    52. }
    53. }else if(cmd.getName().equalsIgnoreCase("warp")) {
    54. if(warpNames.containsKey(args[0])) {
    55. Location loc = (Location) this.getConfig().get("Warps." + args[0] + ".Location");
    56. p.teleport(loc);
    57. p.sendMessage(ChatColor.GREEN + "You have successfully Warpes to " + ChatColor.GOLD + args[0]);
    58. }else{
    59. p.sendMessage(ChatColor.RED + "Sorry, this Warp does not Exist!");
    60. }
    61. }
    62. return false;
    63. }
    64.  
    65. @Override
    66. public void onDisable() {
    67. this.getServer().getLogger().info("TestCode Disabled!");
    68. }
    69.  
    70. }


    When I run the command in-game it just tells me there was an internal error while trying to run the command. Could you please tell what/why needs to be fixed in this? Thanks!
     
  2. Offline

    JRL1004

    MinecraftZach443 warpNames should be <String, Location> so that you can just call up the name of the warp and it will have to location ready
     
  3. Offline

    JRL1004

    MinecraftZach443 Line 19. Also make sure you are saving the warps to a file so that when the server reloads or restarts your warps are saved. Then all you need to do is load them into the HashMap again inside your onEnable().
     
Thread Status:
Not open for further replies.

Share This Page