Solved Help! Strange error...

Discussion in 'Plugin Help/Development/Requests' started by redtsch, May 2, 2016.

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

    redtsch

    Hello everyone! I need some help.

    In one of my classes, 'Utils' I create my general methods. I created a method called tpTimer(), its supposed to start a BukkitRunnable that counts to 3. What I'm trying to do is when a player sends the command "/spawn", the plugin executes the method tpTimer() and counts to 3, then teleports the player to the specified spawn location. Here is my code:

    Utils.class:
    Code:
    package com.redtsch.RedHub.ServerCore;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;
    
    import net.minecraft.server.v1_9_R1.IChatBaseComponent;
    import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
    import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
    import net.minecraft.server.v1_9_R1.PacketPlayOutTitle;
    import net.minecraft.server.v1_9_R1.PacketPlayOutTitle.EnumTitleAction;
    
    public class Utils {
    
        Core core = Core.getInstance();
    
        private static Utils utils;
    
        public static Utils getInstance() {
            return utils;
        }
    
        public static void broadcastMessage(String message) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                player.sendMessage(message);
            }
        }
    
        public static void sendBar(Player player, String message) {
            IChatBaseComponent icbc = ChatSerializer.a("{\"text\": \"" + message + "\"}");
            PacketPlayOutChat ppoc = new PacketPlayOutChat(icbc, (byte) 2);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(ppoc);
        }
    
        public static void sendTitle(Player player, String titleMessage, String subtitleMessage) {
            PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE,
                    ChatSerializer.a("{\"text\": \"" + titleMessage + "\"}"), 20, 40, 30);
            PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE,
                    ChatSerializer.a("{\"text\": \"" + subtitleMessage + "\"}"), 20, 40, 30);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
        }
    
        @SuppressWarnings("deprecation")
        public static void tpTimer(Player player) {
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Core.getInstance(), new BukkitRunnable() {
                int time;
    
                public void run() {
                    player.sendMessage("Teleporting you to spawn, please wait 3 seconds.");
                    time = 0;
                    time++;
                    if (time == 3) {
                        player.teleport(new Location(player.getWorld(), -131.5, 66, 218.5));
                        time = 0;
                    }
                }
            }, 0, 20);
        }
    }
    CmdSpawn.class:
    Code:
    package com.redtsch.RedHub.ServerCore.Listeners.Commands;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import com.redtsch.RedHub.ServerCore.Core;
    import com.redtsch.RedHub.ServerCore.Utils;
    
    public class CmdSpawn implements CommandExecutor {
    
        Core core = Core.getInstance();
        Utils utils = Utils.getInstance();
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (label.equalsIgnoreCase("spawn")) {
                if (!(sender instanceof Player)) {
                    sender.sendMessage("You must be a player to use this command.");
                    return false;
                }
                Player player = (Player) sender;
                Utils.tpTimer(player);
            }
            return false;
        }
    }
    Please help if you can! =P

    Oops! Forgot my stacktrace..

    Here it is:
    Code:
    [16:25:08 INFO]: redtsch issued server command: /spawn
    [16:25:08 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'spawn' in plugin RedHub v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[bukkit.jar:git-Bukkit-f326992]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[bukkit.jar:git-Bukkit-f326992]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand(CraftServer.java:624) ~[bukkit.jar:git-Bukkit-f326992]
        at net.minecraft.server.v1_9_R1.PlayerConnection.handleCommand(PlayerConnection.java:1298) [bukkit.jar:git-Bukkit-f326992]
        at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1158) [bukkit.jar:git-Bukkit-f326992]
        at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(SourceFile:37) [bukkit.jar:git-Bukkit-f326992]
        at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(SourceFile:9) [bukkit.jar:git-Bukkit-f326992]
        at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [bukkit.jar:git-Bukkit-f326992]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_60]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_60]
        at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [bukkit.jar:git-Bukkit-f326992]
        at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:679) [bukkit.jar:git-Bukkit-f326992]
        at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:361) [bukkit.jar:git-Bukkit-f326992]
        at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:635) [bukkit.jar:git-Bukkit-f326992]
        at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:539) [bukkit.jar:git-Bukkit-f326992]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_60]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[bukkit.jar:git-Bukkit-f326992]
        at org.bukkit.craftbukkit.v1_9_R1.scheduler.CraftScheduler.validate(CraftScheduler.java:395) ~[bukkit.jar:git-Bukkit-f326992]
        at org.bukkit.craftbukkit.v1_9_R1.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:123) ~[bukkit.jar:git-Bukkit-f326992]
        at org.bukkit.craftbukkit.v1_9_R1.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:119) ~[bukkit.jar:git-Bukkit-f326992]
        at org.bukkit.craftbukkit.v1_9_R1.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:454) ~[bukkit.jar:git-Bukkit-f326992]
        at com.redtsch.RedHub.ServerCore.Utils.tpTimer(Utils.java:48) ~[?:?]
        at com.redtsch.RedHub.ServerCore.Listeners.Commands.CmdSpawn.onCommand(CmdSpawn.java:25) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[bukkit.jar:git-Bukkit-f326992]
        ... 15 more
    


    {{Merged by moderator: Please use the Edit button next time}}
     
    Last edited by a moderator: May 2, 2016
  2. Offline

    redtsch

    Bump?
    :oops:
     
  3. Offline

    timtower Moderator Moderator

    @redtsch Core.getInstance returns null
     
  4. Offline

    redtsch

    @timtower
    Thanks for the response :)
    And how can I change that?
    EDIT: would using just "core" instead of "core.getInstance()" work?
     
    Last edited: May 5, 2016
  5. Offline

    redtsch

    Bump?
     
  6. Offline

    _Nish_

    Does it teleport you once it reaches 3 seconds?
     
  7. Offline

    redtsch

    @_Nish_ no, it doesn't. But i'm not working on this anymore, thanks for the help =)
     
Thread Status:
Not open for further replies.

Share This Page