How to have a command do /toggledownfall

Discussion in 'Plugin Development' started by JordanPlayz158, Feb 4, 2017.

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

    JordanPlayz158

    So I have this problem i'm extremely new to java coding like I started 3 hours ago and i'm trying to figure out how to have my plugin initiate the command "/toggledownfall" once you see the code you will understand:

    Class Name: "MainToggleDownfall"
    Code:
    package jordanplayz158.quicktoggledownfall.toggledownfall;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    @SuppressWarnings("unused")
    public class MainToggleDownfall {
       
        public void onEnable() {
           
        }
       
        public void onDisable() {
           
        }
    
        public boolean onCommand(CommandSender sender,
                Command command,
                String label,
                String[] args) {
            if (command.getName().equalsIgnoreCase("td")) {
                sender.sendMessage("You Used Quick Toggle Downfall Command Successfully!");
                return true;
            }
            return false;
        }
    }
    
    plugin.yml:
    Code:
    main: jordanplayz158.quicktoggledownfall.toggledownfall.MainToggleDownfall
    name: QuickToggleDownfall
    version: 1.0
    author: JordanPlayz158
    description: A Quick ToggleDownfall Command!
    commands:
      td:
        description: A Shortcut to the command /toggledownfall
        usage: /td
        permission: toggledownfall.td
        permission-message: You Don't Have The toggledownfall.td permission!
    build.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="Quick-ToggleDownfall" default="makejar" basedir=".">
        <target name="makejar" description="Create a jar for the project">
            <mkdir dir="target"></mkdir>
            <jar destfile="target/${ant.project.name}.jar">
                <fileset dir="bin"></fileset>
                <fileset file="plugin.yml"></fileset>
            </jar>
        </target>
    </project>
    or... if you prefer pastebin:
    MainToggleDownfall: http://pastebin.com/2FTbXJuq
    plugin.yml: http://pastebin.com/24bKeBEp
    build.xml: http://pastebin.com/WT5mD5rV
     
  2. Offline

    mehboss

    @JordanPlayz158
    1. get rid of the unused warning at the top and get rid of the onEnable and onDisable if you aren't executing anything with them.
    2. in the onCommand, get the players world they are in and set storm to false.

    UPDATE: Oh yeah, and extend your class to JavaPlugin
     
    Last edited: Feb 4, 2017
    Rayzr522 and mine-care like this.
  3. Offline

    Zombie_Striker

    Packagenames should follow the format "me.<your name>.<your project>".

    I highly recommend you learn Java first before working on bukkit. Knowing how to write stand-alone Java programs first will prevent a lot of confusion when working on other plugins. You can find tutorials at the following link. Find one, take a few weeks to learn Java, and then come back to bukkit.
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/

    Also, in case you do not already have this link bookmarked, bookmark this link:
    https://hub.spigotmc.org/javadocs/bukkit/

    This contains all the methods and classes that bukkit has to offer.

    Main problem: Do as mehboss posted. To make your command actiavte another command, either use Bukkit.dispatchCommand(), or better yet, get the world the player is in and call World#setStorm(true)
     
    mehboss and mine-care like this.
  4. Offline

    JordanPlayz158

    Okay Zombie_Striker And mehboss Thanks For Your Help If It Works I Will Be So Grateful. But If It Doesn't Work It Probably Means I'm Incredibly Stupid So One Sec When I Try It Out

    BTW I Tried To Use This Tutorial To Make The Plugin Work: https://www.justdave.net/dave/2015/05/04/how-to-write-a-minecraftbukkit-plugin-for-spigot-1-8/

    Ok It Didn't Work But I Probably Butchered The Coding You Said For Me To Use

    MainToggleDownfall: http://pastebin.com/x4uGC6TS
    Server Log: http://pastebin.com/ZrSFLa3U

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 5, 2017
  5. Offline

    mine-care

    I think @mehboss would agree that this tutorial has a mistake:
    If they don't do anything there is no reason why you want to overwrite them. In OOP you overwrite things if you intend to use/change them. Here you just take over them without doing anything.

    The error states:
    That means that the code was compiled with errors that where not corrected.
    Taking a look at your code one can clearly spot them, in this instance you have opened and closed the class body and wrote your code outside of it.: (extends JavaPlugin {})
     
    mehboss and Zombie_Striker like this.
  6. Offline

    JordanPlayz158

    Sorry For Bugging You But I Don't Understand How To Correct The Code?
     
  7. Offline

    Drkmaster83

    He said it quite clearly, but let me put it this way:
    • {} after the "extends JavaPlugin" needs to just be "{", move the "}" to the bottom.
    • I don't know what you're doing in the onCommand method, but you can't use Bukkit.dispatchCommand() as a parameter (between parentheses of the onCommand)... you mean to put that inside the if statement... :(
    • You're trying to use a variable called "command", but no such variable exists. You've renamed the object that you're trying to refer to as "toggledownfall".
    You're clearly missing fundamentals of Java, so you could spend some of your time looking up variables, method declarations, overriding superclass methods, control structures, and program structure.
     
    mehboss likes this.
  8. Offline

    JordanPlayz158

    Ok Then! I Will Start Researching Java Fundamentals.
     
Thread Status:
Not open for further replies.

Share This Page