Need Help: Little Duel Plugin

Discussion in 'Plugin Development' started by JeykoExample, Jun 20, 2014.

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

    JeykoExample

    Need Help with my Plugin. Can someone fix it? Because if I type in /duel Someone123, it says Usage: /duel <player>

    Code:
    package com.jeyko;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Duelplugin extends JavaPlugin {

    @Override
    public boolean onCommand(CommandSender sender, Command cmd,String label, String[] args) {

    Player p = null;
    if(sender instanceof Player);
    p = (Player) sender;

    if(cmd.getName().equalsIgnoreCase("duel")){
    if(p != null);
    if(p.hasPermission("Duelplugin.Duel"));

    if(args.length != 1);
    return false;
    }

    Player Gegner = this.getServer().getPlayer(args [0]);
    if(Gegner.isOnline());
    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " You send " + Gegner.getDisplayName() + " a Duel-Invitation.");
    Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " " + p.getName() + " wants to duel with you.");
    Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " Type in /accept to accept the Invitation.");

    if (Gegner instanceof Player);
    Gegner = (Player) Gegner;
    if(cmd.getName().equalsIgnoreCase("accept")){
    if(p != null);
    if(p.hasPermission("Duelplugin.Accept"));

    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 3...");
    Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 3...");
    try {
    wait(1);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 2...");
    Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 2...");
    try {
    wait(1);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 1...");
    Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 1...");
    try {
    wait(1);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " Teleporting to Arena...");
    Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " Teleporting to Arena...");




    }












    return false;
    }



    }
    Thanks for Help :)
     
  2. Offline

    viper_monster

  3. Offline

    TechNotes

    viper_monster

    I was just about to say that.
    JeykoExample
    Why do you have semicolons at the end of your if statements? Also, if you don't want bukkit to tell you the usage of the command, return true when all the right conditions are met in your onCommand() method
     
  4. Offline

    JeykoExample

    viper_monster TechNotes

    I need Help again. I made this. And I know there is a error in the syntax. "Insert } to complete Class Body" and I dont know how to fix it. Im a newbie in doing this. SO please help me!

    Code:
    package com.jeyko;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Duelplugin extends JavaPlugin {       
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd,String label, String[] args) {
     
            Player p = null;
            if(sender instanceof Player);
                p = (Player) sender;
               
                if(cmd.getName().equalsIgnoreCase("duel")){
                    if(p != null);
                        if(p.hasPermission("Duelplugin.Duel"));
                       
                            if(args.length != 1);
                }
               
                Player Gegner = this.getServer().getPlayer(args [0]);
                if(Gegner.isOnline());
                    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " You send " + ChatColor.RED + Gegner.getDisplayName() + ChatColor.WHITE + " a Duel-Invitation.");
                    Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " " +  ChatColor.RED + p.getName() + ChatColor.WHITE + " wants to duel with you.");
                    Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " Sneak to accept the Invtitation.");
                   
                   
     
                if(Gegner.hasPermission("Duelplugin.Accept")){
                        if(Gegner.isSneaking());
                   
                        p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 3...");
                        Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 3...");
                        int seconds = 5;
                       
                        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                        }                       
                        }, (seconds * 20));
                        p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 2...");
                        Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 2...");
                           
                        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                        }
                        }, (seconds * 20));
                        p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 1...");
                        Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " 1...");
                           
                        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                        }
                        }, (seconds * 20));
                        p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " Teleporting to Arena...");
                        Gegner.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Duel" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " Teleporting to Arena...");
            }
           
            return false;
               
        }   
           
    }
    
    Thanks alot.
     
  5. Offline

    Gater12

    JeykoExample
    Insert a closing bracket to close class body. Also why are you scheduling empty tasks?
     
  6. Offline

    Protophite

    There's a solution to all of this. You should probably learn java before getting in to bukkit API.

    JeykoExample

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
    ZodiacTheories and TheWolfBadger like this.
  7. Offline

    TechNotes

    JeykoExample

    Based on the indentations that you are using, I can see that you meant to something different than what you have written.

    This is a portion of your code:
    Code:java
    1. Player p = null;
    2. if(sender instanceof Player);
    3. p = (Player) sender;


    Player 'p' will never be checked because you put a semicolon at the end of your if statement. Instead do:
    Code:java
    1.  
    2. Player p = null;
    3. if(sender instanceof Player) {
    4. p = (Player) sender;
    5. }



    Use brackets!

    Here's a quick tutorial on if-statements
     
  8. Offline

    _Filip

    TechNotes
    You don't have to use brackets there.
     
  9. Offline

    TechNotes

    Of course you do... if you want it to actually do something based on what you checked, you need brackets. As it is (with semi-colon) it checks if sender is an instance of Player, but it goes to the next line regardless of if the sender is a player or not
     
  10. Offline

    _Filip

    TechNotes
    Incorrect.
    Code:java
    1. if(sender instanceof Player)
    2. p = (Player) sender;

    Works perfectly fine. I'd recommend you learn java.
     
  11. Offline

    TechNotes

    TheSpherret

    It may work fine for a single line, but as soon as you do anything that's even slightly complicated, it breaks. It's much better to use brackets to avoid confusion and code-breaking.
     
  12. Offline

    _Filip

    TechNotes
    Which is why I specified in which case it can be used, by saying "there".
     
  13. Offline

    TechNotes

    TheSpherret

    Ok, that makes sense :) I just advocate using brackets because it makes the easier to read, and avoids confusion
     
Thread Status:
Not open for further replies.

Share This Page