Solved Spawn Plugin

Discussion in 'Plugin Development' started by zioGiok, Aug 12, 2016.

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

    zioGiok

    I know Spawn Plugin are really easy to do but when i do the command /setcustomspawn it doesn't work. There aren't errors or things made...NOTHING.
    This is the code of the set spawn:
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("setcustomspawn") && args.length == 0) {
                plugin.getConfig().set("x", player.getLocation().getBlockX());
                plugin.getConfig().set("y", player.getLocation().getBlockY());
                plugin.getConfig().set("z", player.getLocation().getBlockZ());
                player.sendMessage("§cCustomSpawn has been setted!");       
            }
            return false;
    This is the code for the spawn:
    Code:
    player.teleport(new Location(player.getWorld(), x, y, z));
    In the config file I have create something like this:
    x:
    y:
    z:
    I can't understand why it doesn't work...withour errors too.
    Please help me and sorry for my bad English
     
  2. Offline

    DuaneTheDev_

    @zioGiok

    getX(), getY(), getZ() would be the correct usage.

    For precise spawn setting. You could add getYaw() and getPitch(), just make sure you float the values when getting it from the config.
     
  3. Offline

    Zombie_Striker

    @zioGiok
    You are forgetting to save the config. After setting anything in the config, you must use saveConfig().

    Also, don't blindly cast the sender to a player. What if a plugin sends any command? What if its the console? Consoles and plugins are not players, so that cast would break your command. Do an instanceof Player check before creating the player variable.
     
    MCMastery likes this.
  4. Offline

    zioGiok

    I have changed something, creating a new class and now it gives me an error:
    Code:
    [09:53:18 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'setc
    ustomjail' in plugin CustomJail v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServe
    r.java:641) ~[craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:1162) [craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :997) [craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :45) [craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :1) [craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
    3) [craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_101]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_101]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukki
    t.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
    14) [craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
    74) [craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
    53) [craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :556) [craftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
    Caused by: java.lang.NullPointerException
            at com.set.ziogiok.commands.SetJail.onCommand(SetJail.java:16) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Spigot-fdc1440-53fac9f]
            ... 15 more
    And this is the code I have used:
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("setcustomjail")) {
                plugin.getConfig().set("customj_x", player.getLocation().getBlockX());
                plugin.getConfig().set("customj_y", player.getLocation().getBlockY());
                plugin.getConfig().set("customj_z", player.getLocation().getBlockZ());
                plugin.saveConfig();
                player.sendMessage("CustomJail has been set!");
            }
            return false;
        }
    }
    Help me it's really easy but I'm not good so it's hard for me.
     
  5. Offline

    Mokum

    I believe your plugin variable is null.
     
  6. Offline

    Zombie_Striker

    Something is null on line 16. Null check all the values on that line, and figure out which value is null.
     
Thread Status:
Not open for further replies.

Share This Page