[solved]Command always returning false?

Discussion in 'Plugin Development' started by herghost, Dec 18, 2011.

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

    herghost

    Hi all

    I am trying to a simple command to set the time in the world, however the command is always returning false and the time is not changing.

    I think the issue is with my args[], but I am not sure what?

    Code:
    package me.herghost.Fiery.commands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class timeCommand implements CommandExecutor {
    
    	@Override
    	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if(cmd.getName().equalsIgnoreCase("settime")&& sender instanceof Player)
            {
            	if(args[0] == "day")
    			{
    				for (World world : Bukkit.getWorlds())
    					{
    						world.setTime(0);
    					}
    				Command.broadcastCommandMessage(sender, "Its is now day time!");
    				return true;
    			}
    			if(args[0] == "night")
    			{
    				for(World world : Bukkit.getWorlds())
    				{
    					world.setTime(14);
    				}
    				Command.broadcastCommandMessage(sender, "Its is now night time!");
    				return true;
    			}
    		}
    		return false;
        }
    }
    
    Thanks for any help.

    Got it!

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if(cmd.getName().equalsIgnoreCase("settime")&& sender instanceof Player)
            {
            	if(args[0].equalsIgnoreCase("day"))
    			{
    				for (World world : Bukkit.getWorlds())
    					{
    						world.setTime(0);
    					}
    				Command.broadcastCommandMessage(sender, "Its is now day time!");
    				return true;
    			}
    			if(args[0].equalsIgnoreCase("night"))
    			{
    				for(World world : Bukkit.getWorlds())
    				{
    					world.setTime(14);
    				}
    				Command.broadcastCommandMessage(sender, "Its is now night time!");
    				return true;
    			}
    			else
    			{
    				Command.broadcastCommandMessage(sender, "Somethings wrong");
    			}
    		}
    		return false;
        }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
Thread Status:
Not open for further replies.

Share This Page