Help com BukkitRunnable please!

Discussion in 'Spigot Plugin Development' started by yurinogueira, Jan 7, 2020.

  1. Code (Java):
    package commands.player;

    import center.vars;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.scheduler.BukkitRunnable;

    import java.util.Objects;

    public class spawn implements CommandExecutor
    {
        private Player player;
        private Integer cd = 4;
        private Location e;
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
        {
            if (sender instanceof Player)
            {
                player = (Player) sender;
                if(player.hasPermission("eternia.timing.bypass"))
                {
                    World world = Bukkit.getWorld(vars.c(center.looper.c.getString("world")));
                    double x = Double.parseDouble(vars.c(center.looper.c.getString("x")));
                    double y = Double.parseDouble(vars.c(center.looper.c.getString("y")));
                    double z = Double.parseDouble(vars.c(center.looper.c.getString("z")));
                    float yaw = Float.parseFloat(vars.c(center.looper.c.getString("yaw")));
                    float pitch = Float.parseFloat(vars.c(center.looper.c.getString("pitch")));
                    player.teleport(new Location(world, x, y, z, yaw, pitch));
                    player.sendMessage(vars.c(center.looper.c.getString("spawn")));
                }
                else
                {
                    e = player.getLocation();
                    doCountDown();
                }
                return true;
            }
            return false;
        }
        private void doCountDown()
        {
            player.sendMessage(vars.c(replaced(Objects.requireNonNull(center.looper.c.getString("teleporte-falta")), cd)));
            if(cd > 0)
            {
                if (player.getLocation().getX() == e.getX() && player.getLocation().getZ() == e.getZ())
                {
                    cd -= 1;
                    new BukkitRunnable()
                    {
                        @Override
                        public void run()
                        {
                            doCountDown();
                        }
                    }.runTaskLater((Plugin) this, 20);
                }
                else
                {
                    player.sendMessage(vars.c(center.looper.c.getString("nao-se-mova")));
                }
            }
            else
            {
                World world = Bukkit.getWorld(vars.c(center.looper.c.getString("world")));
                double x = Double.parseDouble(vars.c(center.looper.c.getString("x")));
                double y = Double.parseDouble(vars.c(center.looper.c.getString("y")));
                double z = Double.parseDouble(vars.c(center.looper.c.getString("z")));
                float yaw = Float.parseFloat(vars.c(center.looper.c.getString("yaw")));
                float pitch = Float.parseFloat(vars.c(center.looper.c.getString("pitch")));
                player.teleport(new Location(world, x, y, z, yaw, pitch));
                player.sendMessage(vars.c(center.looper.c.getString("spawn")));
            }
        }
        private String replaced(String args, double valor)
        {
            return args.replace("%s", String.valueOf(valor));
        }
    }
     
    Code (Text):
    org.bukkit.command.CommandException: Unhandled exception executing command 'spawn' in plugin EterniaServer v1.1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[patched_1.15.1.jar:git-Paper-29]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[patched_1.15.1.jar:git-Paper-29]
        at org.bukkit.craftbukkit.v1_15_R1.CraftServer.dispatchCommand(CraftServer.java:740) ~[patched_1.15.1.jar:git-Paper-29]
        at net.minecraft.server.v1_15_R1.PlayerConnection.handleCommand(PlayerConnection.java:1820) ~[patched_1.15.1.jar:git-Paper-29]
        at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1628) ~[patched_1.15.1.jar:git-Paper-29]
        at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[patched_1.15.1.jar:git-Paper-29]
        at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:5) ~[patched_1.15.1.jar:git-Paper-29]
        at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:23) ~[patched_1.15.1.jar:git-Paper-29]
        at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) ~[patched_1.15.1.jar:git-Paper-29]
        at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.15.1.jar:git-Paper-29]
        at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.15.1.jar:git-Paper-29]
        at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.15.1.jar:git-Paper-29]
        at
     
  2. Congratulations, you are one of the few people here that have managed to send us your error (seriously, no irony in that)
    Unfortunately, it is cut off at the bottom. The interesting part is where it says "Caused by", that is where the error is handled in detail. Please provide this and also kindly provide the line (since counting isn't really that fun) where the error is being thrown at :giggle:
     
  3. The stacktrace is only partly shown.
    Other than that the package name is just...
    Also, You shouldn't set the fields of the command executor object to the values from the onCommand method.
    And you do not follow the Java naming convention.
     
    • Agree Agree x 1
  4. My bid is either a NPE stemming from a missing config entry (Strings are considered Objects by specification, undefined strings yield a null value), or a NFE because you used an incorrect way of storing the number (like for example "3,48" rather then "3.48") ... Also, the Bukkit#getWorld does not return custom loaded worlds (or was it changed?) so you need to track these manually.
     
  5. THANK YOU! Hahahaha it's just the name :p!
     
  6. Nope, this works :)
     
  7. I think the main point people were saying is that, your that your error is incomplete and the whole thing needs to be shown, and if possible, the line in which the error points to. you kinda avoided that :p - if you want people to help you, you have to cooperate