"An internal error occurred" while testing my plugin

Discussion in 'Plugin Development' started by space1188, Jan 31, 2016.

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

    space1188

    Im making a /spawn and /setspawn and when i do /setspawn it works but when i do /spawn it get an error saying "An internal error occurred while attempting to perform this command" and i cant find the problem​


    Code:
    
    package me.space1188.spawn;
    
    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 Spawn extends JavaPlugin {
    
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    
            if (command.getName().equalsIgnoreCase("setspawn")) {
                if (sender.isOp()) {
                    if (sender instanceof Player) {
    
                        Player p = (Player) sender;
    
                        getConfig().set("spawn.world", p.getLocation().getWorld());
                        getConfig().set("spawn.x", p.getLocation().getX());
                        getConfig().set("spawn.y", p.getLocation().getY());
                        getConfig().set("spawn.z", p.getLocation().getZ());
                        saveConfig();
    
                        p.sendMessage(ChatColor.GREEN + "Spawn set");
    
                        return true;
                    } else {
                        sender.sendMessage(ChatColor.RED + "You must be a player to do this");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "You are not permmited to do this command");
                }
                return true;
            }
    
            if (label.equalsIgnoreCase("spawn")) {
                Player p = (Player) sender;
                if (getConfig().getConfigurationSection("spawn") == null) {
                    p.sendMessage(ChatColor.RED + "Spawn has not yet ben set");
                    return true;
                }
    
                World w = Bukkit.getServer().getWorld(getConfig().getString("spawn.world"));
                double x = getConfig().getDouble("spawn.x");
                double y = getConfig().getDouble("spawn.y");
                double z = getConfig().getDouble("spawn.z");
    
                p.teleport(new Location(w, x, y, z));
                p.sendMessage(ChatColor.GREEN + "Woooosh");
       
                return true;
            }
    
            return super.onCommand(sender, command, label, args);
        }
    
    }
    
    
     
    Last edited: Jan 31, 2016
  2. Offline

    teej107

    @space1188 Read the stacktrace in the console. That'll tell you where your problem is.
     
  3. Offline

    tobiyas

    @space1188 I would guess it's while using /setspawn.
    You are trying to serialize a World. Try using the worlds name. ;)

    To be exact: line 24. Replace with:
    Code:
    getConfig().set("spawn.world", p.getLocation().getWorld().getName());
     
  4. Offline

    sailorerik

    Why you use only X, Y, and Z? Why you don't use pitch and yaw?
     
  5. Offline

    Skylandz

    Because he is probably following PogoStick29's tutorial series, and in the video he removes the pitch and yaw because they dont work or something, so i guess this guy did the same @sailorerik
     
  6. Offline

    mcdorli

    Either you copied one of the command's code, or you only fixed the error in one of them. In the setspawn you use command.getNamr() and you do instace check, in the othdr one, you do not do this.
     
Thread Status:
Not open for further replies.

Share This Page