What did I do wrong!??!?!?!??!?!?!?!??!?

Discussion in 'Plugin Development' started by number1_Master, Jan 9, 2012.

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

    number1_Master

    Ok, I have been working on the next update to my plugin. I wanted to add a way where you can strike lightning where you are looking at, after you type a command. Yet, nothing happens in the game when I type the command, and no matter where I am pointing...
    Also, within my code, you will see something like:
    Code:
    (null, 50)
    I have changed that number many times, and I am afraid to change it too high, and too low. At first, that number was 40.
    Here is my code:
    Code:
                    else if(player.hasPermission("thor.rage.look"))
                    {
                        if(args.length == 2 && args[1].equalsIgnoreCase("-l"))
                        {
                            Block pointedblock = player.getTargetBlock(null, 50);
                            Location pointedlocation = pointedblock.getLocation();
                            int counter = 0;
                            while(counter < 20)
                            {
                                world.strikeLightningEffect(pointedlocation);
                                world.createExplosion(pointedlocation, 0);
                                try
                                {
                                    Thread.sleep(150);
                                }
                                catch (InterruptedException e)
                                {
                                    e.printStackTrace();
                                }
                                counter++;
                            }
                            player.sendMessage(yellow + "[Thor] " + red + "Your target was successfully destroyed!");
                        }
                        else if(args.length == 3 && ((args[1].equalsIgnoreCase("-l") && args[2].equalsIgnoreCase("-d")) || (args[1].equalsIgnoreCase("-d") && args[2].equalsIgnoreCase("-l"))))
                        {
                            Block pointedblock = player.getTargetBlock(null, 50);
                            Location pointedlocation = pointedblock.getLocation();
                            int counter = 0;
                            while(counter < 20)
                            {
                                world.strikeLightning(pointedlocation);
                                world.createExplosion(pointedlocation, 0);
                                try
                                {
                                    Thread.sleep(150);
                                }
                                catch (InterruptedException e)
                                {
                                    e.printStackTrace();
                                }
                                counter++;
                            }
                            player.sendMessage(yellow + "[Thor] " + red + "Your target was successfully destroyed, painfully!");
                        }
                    }
    Please help, and thank you!!!!!!!!!
     
  2. DONT use Thread.sleep(); it will blow up your server O:! Use schedulers instead.
     
  3. Offline

    number1_Master

    Also:
    My code starts off with an if statement saying if the commandlabel is "thorr", and then another under it stating if args[0] == rage, then some other code to rage against yourself, then this code.
    :)

    hasn't blown up mine
    this might sound stupid, but how do "define"/use a scheduler ...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  4. You can read more about schedulers on the Wiki (link)
     
    nunber1_Master likes this.
  5. Offline

    number1_Master

    how would i exactly use that in "onCommand" ?
     
  6. Offline

    sayaad

    please post your plugin.yml and your entire class.
     
  7. Offline

    number1_Master

    http://pastebin.com/pbNBWEgy
    plugin.yml:
    Code:
    name: Thor
    version: 1.6.8
    main: me.nunber1_Master.Thor.ThorMain
    description: ^
                 A plugin that gives you the powers of Thor!
    commands:
        thorr:
            description: Destroy yourself, or another player!
            usage: /thorr [destroy, rage] [-d, -l] [playername]
    permissions:
         thor.*:
            description: Gives you access to all the Thor permission nodes.
            children:
                thor.login: true
                thor.logout: true
                thor.destroy.me: true
                thor.destroy.other: true
                thor.rage.me: true
                thor.rage.other: true
         thor.commands.*:
            description: Gives you access to all the /thorr commands!
            children:
                thor.destroy.me: true
                thor.destroy.other: true
                thor.rage.me: true
                thor.rage.other: true
                thor.rage.look: true
         thor.destroy.me:
             description: Lets you destroy yourself!
             default: op
         thor.destroy.other:
             description: Allows you to destroy others!
             default: op
         thor.login:
             description: Allows you to login with the Thor Message!
             default: op
         thor.logout:
             description: Allows you to log-out with the Thor Message!
             default: false
         thor.rage.me:
             description: Allows you to rage with lightning!
             default: op
         thor.rage.other:
             description: Allows you to rage against other players!
             default: op
         thor.rage.look:
             description: Allows you to rage where you are looking!
             default: op
    
     
  8. Offline

    sayaad

    add this code to your main class

    Code:
    //add under public class <main class name> extends JavaPlugin
    
    private ThorThorrCommand Executor = new ThorThorrCommand(this);
    Code:
    //add under onEnable()
    
    getCommand("thorr").setExecutor(this.Executor);
     
  9. Offline

    number1_Master

    ive had that for a long time
    edit: i just have this, and it has been working
    only the -l stuff is working in my code
    this is what i have btw:
    Code:
    getCommand("thorr").setExecutor(new ThorrThorCommand());
     
  10. Offline

    number1_Master

  11. Offline

    Chiller

    What are you using the thread for? And why are you using a while loop instead of a for loop?
     
  12. Offline

    number1_Master

    while loop over a for... idk
    thread, i already found out i should use schedulers... but im running into multiple issues with them

    Edit: I fixed the while loops and changed them to for loops. I have no clue why I didn't use for loops...
    But, thanks anyways, for , um, THANKS!

    the thread.sleep has been working fine for me so far, but since this comment, i have been struggling with schedulers :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
Thread Status:
Not open for further replies.

Share This Page