Remove Internal Error Message! [HELP]

Discussion in 'Plugin Development' started by Hank, Jul 21, 2012.

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

    Hank

    Hello. I am learning how to make bukkit plugins. I am trying to make a set time command.

    Code:
            if(commandLabel.equalsIgnoreCase("time"))
            {   
                if(args[0].equalsIgnoreCase("day"))
                {
                    world.setTime(6000);
                    Bukkit.broadcastMessage(ChatColor.GRAY + "Time set to day!");
                }
                else if(args[0].equalsIgnoreCase("night"))
                {
                    world.setTime(18000);
                    Bukkit.broadcastMessage(ChatColor.GRAY + "Time set to night!");
                }
                else if(args[0].equalsIgnoreCase("dawn"))
                {
                    world.setTime(0);
                    Bukkit.broadcastMessage(ChatColor.GRAY + "Time set to dawn!");
                }
                else if(args[0].equalsIgnoreCase("dusk"))
                {
                    world.setTime(12000);
                    Bukkit.broadcastMessage(ChatColor.MAGIC + "Time set to dusk!");
                }
                else
                {
                    player.sendMessage(ChatColor.DARK_RED + "Usage: /time <day|night|dusk|dawn>");
                }
            }
    The setting time works but when I do /time it gives me the internal error message. Is there anyway I can change that to [player.sendMessage(ChatColor.DARK_RED + "Usage: /time <day|night|dusk|dawn>");] So it displays the error message I made? That error message only shows if I do /time somethingwronghere. Can someone please help me with this!
     
  2. First off "Internal Error" means have a look in your server.log to see the stacktrace. If you would do that you would see that it crashes cause args[0] does not exist.
    So simply check the size of args:
    Code:java
    1. if(args.length < 1)
    2. {
    3. //No arguments given!
    4. }
    5. else if(args[0].equalsIgnoreCase("day"))
    6. {
    7. ...
     
    Hank and ZeusAllMighty11 like this.
  3. Offline

    Hank

    Thanks alot! I added player.sendMessage(ChatColor.DARK_RED + "Usage: /time <day|night|dusk|dawn>"); return true; to where you said //No arguments given! It works now the error is gone but there is one thing...... now when I do /time dusk it makes all the letters just switch constantly like the matrix!?!
     
  4. Which is exactly what ChatColor.MAGIC is for. So it's not a bug, it's a feature. :D
     
    ferrybig and Hank like this.
  5. Offline

    Hank

    Oh ????? I didn't put Magic there........ Hmm maybe I did lol. Thanks for all your help! Also can you help me make a fly toggle? I know you use a boolean but I just cant get it.
     
  6. Yes you did:
    ;)
    Depends on what exactly you want to do, a simple toggle could look like this:
    Code:java
    1.  
    2. if(commandLabel.equalsIgnoreCase("fly"))
    3. {
    4. if(!(sender instanceof Player))
    5. {
    6. sender.sendMessage("Your console can't fly. Use this command in-game!");
    7. return true;
    8. }
    9. Player player = (Player)sender;
    10. if(player.getAllowFlight())
    11. {
    12. player.setFlying(false);
    13. player.setAllowFlight(false);
    14. player.sendMessage("You are no longer allowed to fly");
    15. }
    16. else
    17. {
    18. player.setAllowFlight(true);
    19. player.sendMessage("Double-jump to fly!");
    20. }
    21. return true;
    22. }
     
    Hank likes this.
  7. Offline

    Hank

    Thanks so much! Your help has been awesome! I remember now adding magic cause I was going through seeing which color looked the best and I guess when I went back to change it I forgot that one. Can I basically use this to also make a gamemode switcher but change it to gamemode and an alias gm. And also do player.setGamemode instead of flying.
     
  8. Sure...
    Code:java
    1.  
    2. if(commandLabel.equalsIgnoreCase("gm"))
    3. {
    4. if(!(sender instanceof Player))
    5. {
    6. sender.sendMessage("Use this command in-game!");
    7. return true;
    8. }
    9. Player player = (Player)sender;
    10. if(player.getGameMode() == GameMode.SURVIVAL)
    11. {
    12. player.setGameMode(GameMode.CREATIVE);
    13. player.setDisplayName("[CREATIVE] "+player.getName());
    14. }
    15. else
    16. {
    17. player.setGameMode(GameMode.SURVIVAL);
    18. player.setDisplayName("[SURVIVAL] "+player.getName());
    19. }
    20. return true;
    21. }

    but keep in mind that my examples are simple and may not be 100% what you want.
     
    Hank likes this.
  9. Offline

    Hank

    They are pretty spot on! I just changed a few of the messages and display name stuff. Ok so I also attempted to make a /spawn command but everytime I did it I would teleport into the ground a few blocks below spawn.

    Also how do I remove when it says your gamemode has been changed?

    You there?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  10. you cant remove the part where it says your gamemode has chanced

    actually you can, kick player, set gammode to creative/survival ssave data
    when he joins he sees it, but this is verry unfrendly
     
  11. Offline

    Hank

    haha yea i don't think i would wanna kick them! do you know anything about the spawn?
     
Thread Status:
Not open for further replies.

Share This Page