Solved What to cast

Discussion in 'Plugin Help/Development/Requests' started by DogeDebugger, Jan 14, 2015.

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

    DogeDebugger

    I was watching a youtube tutorial on making a cooldown. I followed along fine, everything was cool until i got to having to cast.

    Code:
    ((Object) Bukkit.getServer().getScheduler()).scheduleSyncedDelayedTasks(this, new Runnable() {
                        public void run() {
                            cd.remove(player);
                            player.sendMessage(ChatColor.GREEN+"Your cooldown has worn off!");
                        }
                    }, 8*20);
    So i get that i'm supposed to change the cast (Object), but the video for some reason doesn't and i have no idea what to change the cast to :(
    halp.
     
  2. Invisible

    nverdier

    @DogeDebugger Why on earth are you trying to cast... I don't understand.
     
  3. Offline

    DogeDebugger

    eclipse is forcing me to.
     
  4. Invisible

    nverdier

  5. Offline

    DogeDebugger

    Listener:
    (Sorry if i tick you off from a stupid mistake, beek some time since i've been back to java)
    Code:
    import java.util.ArrayList;
    import java.util.HashMap;
    
    import me.Thomas.Main;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    
    public class Creeper implements Listener {
    
        public static Main plugin;
        ArrayList<Player> cd = new ArrayList<Player>();
    
        @EventHandler
        public void explode(final PlayerInteractEvent event) {
            final Player player = event.getPlayer();
    
            ItemStack item = player.getItemInHand();
            if (item != null && item.hasItemMeta()
                    && item.getItemMeta().hasDisplayName()) {
                if (item.getItemMeta().getDisplayName()
                        .equalsIgnoreCase("Blast Powder")) {
                    if(cd.contains(player)) {
                        player.sendMessage(ChatColor.RED+"You are on cooldown!");
                        return;
                    }
                    Location loc = player.getLocation();
                    int x = loc.getBlockX();
                    int y = loc.getBlockY();
                    int z = loc.getBlockZ();
                    player.getLocation().getWorld()
                            .createExplosion(x, y, z, (float) 3.0, false, false);
                    cd.add(player);
                     Bukkit.getServer().getScheduler().scheduleSyncedDelayedTasks(this, new Runnable() {
                        public void run() {
                            cd.remove(player);
                            player.sendMessage(ChatColor.GREEN+"Your cooldown has worn off!");
                        }
                    }, 8*20);
                }
            }
        }
    
    }
       
    
     
  6. Invisible

    nverdier

  7. Invisible

    nverdier

    @DogeDebugger Well I just noticed that you have 'scheduleSyncedDelayedTasks' but that doesn't exist... It should be 'scheduleSyncDelayedTask'.
     
  8. Offline

    DogeDebugger

    It has another error with 3 choices: Cast Plugin to my class (this), change to scheduleAsyncDelayedTask, or have Creeper implement Plugin. I'm really stuck :I
     
  9. Invisible

    nverdier

    @DogeDebugger You have to pass an instance of the class that extends JavaPlugin to the event...
     
  10. Offline

    DogeDebugger

    I'll try, thanks <3

    Like this, right?
    Code:
    Main main = new Main();
     
    Last edited by a moderator: Jan 15, 2015
  11. Invisible

    nverdier

    @DogeDebugger No, that would cause some major issues. You should create a constructor and when you create an instance of the class that you have the runnable it, pass an instance of Main.
     
  12. Offline

    DogeDebugger

    o, a constructor...
    alright, thanks. so instance in constructor?
     
  13. Invisible

    nverdier

    @DogeDebugger Yes, you pass an instance of the Main class in the constructor.
     
  14. Offline

    DogeDebugger

    Understand. Thanks.

    @nverdier
    Code:
     public Creeper(Main m) {
        m = new Main();
        }
    ye?

    <merged posts. Please use the edit button instead of making multiple posts in a row. ~Eya>
     
    Last edited by a moderator: Jan 15, 2015
  15. Invisible

    nverdier

    @DogeDebugger Facepalm. You create a variable in the class, then you initialize it inside the constructor with the value that is passed.
     
  16. Offline

    DogeDebugger

    Sorry...once again, coming back from some time.
    Code:
     public static Main plugin;
       
        public Creeper() {
        plugin = new Main();
        }
     
  17. Invisible

    nverdier

    @DogeDebugger No static. Do you know the concept of OOP? And you have to pass an instance of main. Why are you creating a new instance of Main? I have been telling you that you have to pass an instance, and to not create a new instance.
     
  18. Offline

    DogeDebugger

    • Please stop spamming posts and use the edit button instead
    Using magic and love, i fixed it :D\

    Thanks so much @nverdier
     
    Last edited: Jan 15, 2015
Thread Status:
Not open for further replies.

Share This Page