How can I access this thread?! Please help!!!

Discussion in 'Plugin Development' started by Plazmotech, May 25, 2012.

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

    Plazmotech

    Hello: I have this code:



    Code:
        package com.webs.playsoulcraft.plazmotech.java.MineRegen;
       
        import java.util.logging.Logger;
        import org.bukkit.Location;
        import org.bukkit.World;
        import org.bukkit.block.Block;
        import org.bukkit.command.Command;
        import org.bukkit.command.CommandSender;
        import org.bukkit.event.block.Action;
        import org.bukkit.event.player.PlayerInteractEvent;
        import org.bukkit.plugin.java.JavaPlugin;
       
        public class Main extends JavaPlugin{
            String pmrgenable = "no";
            public final Logger log = Logger.getLogger("Minecraft");
           
           
            @Override
            public void onEnable() {
                this.log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                this.log.info("Plaz's Mine Regen is now enabled!");
                this.log.info("Copyright 2012 Plazmotech Co. All rights reserved.");
                this.log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            }
           
            @Override
            public void onDisable() {
                this.log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                this.log.info("Plaz's Mine Regen is now disabled!");
                this.log.info("Copyright 2012 Plazmotech Co. All rights reserved.");
                this.log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            }
           
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
                if(cmd.getName().equalsIgnoreCase("pmrgdefenable")){ // If the player typed /basic then do the following...
                    pmrgenable = "yes";
                    sender.sendMessage("Select mode enabled!");
                    return true;
                } //If this has happened the function will break and return true. if this hasn't happened the a value of false will be returned.
                return false;
            }
       
            public boolean onCommand1(CommandSender sender, Command cmd, String commandLabel, String[] args){
                if(cmd.getName().equalsIgnoreCase("pmrgdefdisable")){ // If the player typed /basic then do the following...
                    pmrgenable = "no";
                    sender.sendMessage("Select mode disabled!");
                    return true;
                } //If this has happened the function will break and return true. if this hasn't happened the a value of false will be returned.
                return false;
            }
           
            public void onPlayerInteract(PlayerInteractEvent event) {
                final Action action = event.getAction();
                final Location blockLocation = event.getClickedBlock().getLocation();
                final Location l1 = (action == Action.LEFT_CLICK_BLOCK) ? blockLocation : null;
                final Location l2 = (action == Action.RIGHT_CLICK_BLOCK) ? blockLocation : null;
               
            }
           
            Thread t = new Thread() {
                @SuppressWarnings("null")
                @Override
                public void run() {
                    log.info("Thread t is working...");
                    while(true) {
                        try {
                            Thread.sleep(1000*60);
                            Location bloc = null;
                            log.info("Mine regenerated!");
                            for(double i=l1.getX(); i == l2.getX(); i++){
                                for(double j=l1.getY(); j == l2.getX(); j++){
                                    for(double k=l1.getZ(); k == l2.getX(); k++){
                                        int r = (int) (Math.random()*100);
                                        bloc.setX(i);
                                        bloc.setY(j);
                                        bloc.setZ(k);
                                        World w = bloc.getWorld();
                                        Block b = w.getBlockAt(bloc);
                                        if(r <= 5){
                                            b.setTypeId(56);
                                        }
                                        if(r <= 10 && r > 5){
                                            b.setTypeId(14);
                                        }
                                        if(r <= 25 && r > 10){
                                            b.setTypeId(15);
                                        }
                                        if(r <= 45 && r > 25){
                                            b.setTypeId(16);
                                        }
                                        if(r > 45){
                                            b.setTypeId(1);
                                        }
                                    }
                                }
                            }
                           
                           
                        } catch (InterruptedException ie) {
                            log.info("Error!");
                        }
                    }
                }
            };
            t.start();
        }
    
    The important bit is the Thread t. Why can't I start it using t.start();? It gives me the error: Syntax error on token "start", Identifier expected after this token Please help!
     
  2. Offline

    nisovin

    You can't put statements like that inside a class, they need to be in a method.

    Edit: Also, you should really be using the scheduler for this, not a thread.
     
Thread Status:
Not open for further replies.

Share This Page