issue?

Discussion in 'Plugin Development' started by Forword, Mar 27, 2018.

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

    Forword

    The issue shows as is shown in the picture below :D


    Code:
    package me.forword.warps;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Warps extends JavaPlugin {
      
        public String prefix = ChatColor.GOLD + "Warps> ";
      
        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
          
        public void onDisable() {
            saveConfig();
        }
    
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player))
                sender.sendMessage(ChatColor.RED + "Only players can execute this command!");
    
          
            Player p = (Player) sender;
          
            if (cmd.getName().equalsIgnoreCase("setwarp")) {
                if (p.hasPermission("warps.setwarp")) {
                      if (args.length == 0) {
                            p.sendMessage(prefix + ChatColor.RED + "Please specify the name of the warp.");
                        } else if (args.length == 1) {
                            String arg = args[0].toLowerCase();
    
                        getConfig().set("warps."+arg+".world", p.getWorld().getName());
                        getConfig().getDouble("warps."+arg+".x", p.getLocation().getX());
                        getConfig().getDouble("warps."+arg+".y", p.getLocation().getY());
                        getConfig().getDouble("warps."+arg+".z", p.getLocation().getZ());
                        getConfig().getDouble("warps."+arg+".yaw", p.getLocation().getYaw());
                        getConfig().getDouble("warps."+arg+".pitch", p.getLocation().getPitch());
                        saveConfig();
                        }
                      
                } else if (cmd.getName().equalsIgnoreCase("warp")) {
                    if (p.hasPermission("warps.warp")) {
                    String arg = args[0].toLowerCase();
                    if (getConfig().getConfigurationSection("warps." +arg) == null) {
                        p.sendMessage(prefix + ChatColor.RED + "A warp with that name does not exist!");
                        return true;
                    }
    
                    World world = Bukkit.getWorld(getConfig().getString("warps." + arg + ".world"));
                    double x = getConfig().getDouble("warps."+arg+".x");
                    double y = getConfig().getDouble("warps."+arg+".y");
                    double z = getConfig().getDouble("warps."+arg+".z");
                    float yaw = (float) getConfig().getDouble("warps."+arg+".yaw");
                    float pitch = (float) getConfig().getDouble("warps."+arg+".pitch");
    
                    p.teleport(new Location(world, x, y, z, yaw, pitch));
    
                    p.sendMessage(prefix + ChatColor.GREEN+"You successfully teleported to the warp: "+ChatColor.DARK_GREEN +arg + ChatColor.GREEN+"!");
                  
        }
            return true;
    }
            }
            return true;
        }
    }
    
    [​IMG]

    hm?
     

    Attached Files:

    Last edited by a moderator: Mar 28, 2018
  2. Offline

    CostelabrMn

    Try casting it: set(String, (Double) Object);
    I am not really sure if it will work, but that is what i imagine.

    Good luck with your code.
     
  3. Offline

    Dnyce72799

    You're trying to get x, y, z, pitch, and yaw.

    Code:
    getConfig().getDouble("warps."+arg+".x", p.getLocation().getX());
    getConfig().getDouble("warps."+arg+".y", p.getLocation().getY());
    getConfig().getDouble("warps."+arg+".z", p.getLocation().getZ());
    getConfig().getDouble("warps."+arg+".yaw", p.getLocation().getYaw());
    getConfig().getDouble("warps."+arg+".pitch", p.getLocation().getPitch());
    You have to set them, like you did with the world.

    Sent from my LGLS775 using Tapatalk
    [​IMG]
     
    Last edited: Mar 28, 2018
  4. Offline

    Tabuu_

    The problem is not in de code you send. It is in the Teleport class on line 29, something there is null.
     
  5. Offline

    Forword

    Capture.PNG
    @Dnyce72799 putting it as .set breaks the code further, not possible. The error i get when using .set is "The method set(String, Object) in the type MemorySection is not applicable for the arguments (String, double)"

    When i do it as .GetDouble it doesnt write it down in the configs. it sets the worlds because it has .set but it isnt doing the coords cuz it isnt(although eclipse is giving me an error when i do .set)


    @Tabuu_ i dont see whats wrong with line 29 though, its just blank
     
    Last edited: Mar 28, 2018
Thread Status:
Not open for further replies.

Share This Page