Hi, I made a plugin for my network and I tried to put it on a server but when I reload the server I get this error here This is the code Code:java package com.ledscraft.ledscraft; import java.util.logging.Logger; 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.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin{ public static Main plugin; public final Logger logger = Logger.getLogger("Minecraft"); int counter = 0; @Override public void onDisable() { PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " Has Been Disabled!"); } @Override public void onEnable() { PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + "Version " + pdfFile.getVersion() + " Has Been Enabled!"); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("time")){ if(player.isOp()){ player.sendMessage(ChatColor.RED + "Usage: /time day"); }else{ player.sendMessage(ChatColor.RED + "You do not have permission to do this!"); }if(player.isOp()){ if(args[0].equalsIgnoreCase("day")){ player.sendMessage(ChatColor.GREEN + "Time set to day"); Bukkit.dispatchCommand(sender, "time set day"); } }if(player.isOp()){ if(args[0].equalsIgnoreCase("night")){ player.sendMessage(ChatColor.GREEN + "Time set to night."); Bukkit.dispatchCommand(sender, "time set night"); } } } return false;}} Help me please.
I dont know what a stacktrace is or how to tell if there are any in the console, But heres my plugin.yml http://pastebin.com/91iSpv6f
ledship seems to be a problem with your plugin.yml try running it on a local server so you can get the whole error message
a stack trace is an error in console. Here's an example: If there's a stacktrace error, it really helps with finding an error
I would say make the pdffile private and put it before everything as a class declaration. Then, when the plugin is disabling, grab that variable and use it for its information.
Heres the log: http://pastebin.com/P2Zh8FFn I dont understand, Sorry Im a noob at this. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
ledship the issue is that you have an invalid plugin description file try redoing it or exporting your jar again
On second thought, maybe try removing the ">" from your description. I know that this shouldn't be the main issue, but there may be an issue with its YAML condition. Edit: ledship What I mean by make it a class-declared variable is this: Code: public class Main extends JavaPlugin{ private PluginDescriptionFile pdfFile; public static Main plugin; public final Logger logger = Logger.getLogger("Minecraft"); @Override public void onEnable(){ pdfFile = this.getDescription(); //Initializing the variable upon startup, can now be used throughout the whole class logger.info("Main v" + pdfFile.getVersion() + " has been enabled!"); } }
Removed it, And I found out what the error was I didnt put the right thing in my plugin.yml for where the main class is, But when I do /time it says what I want it to say but it always says An internal error occurred while attempting to perform this command And also, When I do /time day it says Usage: /time day (Next line) Time set to day even when it isnt and then Usage: /time day again on the next line?
ledship looking at the structure of your if statements, I think you probably have not very much basic knowledge of java.
When the internal error occurs, post the error that's in the console as well as your plugin.yml and onCommand() method. Edit: Techy4198... Ahem...
I only have what a tutorial told me, But Its been enough to make 5 plugins which actually work and have permissions and that Console error: http://pastebin.com/mz1RiUsv Plugin.yml: http://pastebin.com/sPXYE7Ex and I didnt use any onCommand() method, I did Code:java Bukkit.dispatchCommand(sender, "time set night"); because I wanted it to run the normal minecraft time set command, if thats what your talking about because I dont know really lol. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Knowing how to make a plugin is easy. Knowing how to make a plugin work and understand why it works is the hard part. I'd recommend looking up some more advanced concepts alongside your Bukkit coding and thinking about how you can use those in plugins. But knowing how to debug stack traces and solve problems is an absolute must, so I'd recommend looking at this thread. A few pre-requisites for coding plugins is basic knowledge of YAML, obviously moderate Java knowledge, and a touch of work-ethic for the debugging portion of things.
Sorry about the post above, the Bukkit infrastructure is periodically going down for me, so my responses are delayed. Anyways, the structure of your onCommand(), as expected with a new Java programmer, is structured inefficiently and confusingly. You use the "else" statement at the end of "if" or "else-if" statements, never in the middle of them. Secondly, you're checking multiple times if the sender is an OP on separate occasions instead of putting everything in one area. I'll organize this, and show it to you in a before and after fashion. Afterwards, I will link you to a thread in which I helped someone with the onCommand() method. Before: Code: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("time")){ if(player.isOp()){ player.sendMessage(ChatColor.RED + "Usage: /time day"); }else{ player.sendMessage(ChatColor.RED + "You do not have permission to do this!"); }if(player.isOp()){ if(args[0].equalsIgnoreCase("day")){ player.sendMessage(ChatColor.GREEN + "Time set to day"); Bukkit.dispatchCommand(sender, "time set day"); } }if(player.isOp()){ if(args[0].equalsIgnoreCase("night")){ player.sendMessage(ChatColor.GREEN + "Time set to night."); Bukkit.dispatchCommand(sender, "time set night"); } } } return false; } After: Code: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ if(!(sender instanceof Player)) return false; //Checking if the sender is a player, not a console. Player player = (Player) sender; //This line, without the above if-statement, would throw an error if you typed "time" as console. if(commandLabel.equalsIgnoreCase("time")) { if(args.length == 0) //If there's nothing after the word after the "/", so just "/time" { if(player.isOp()) { player.sendMessage(ChatColor.RED + "Usage: /time day"); } else { player.sendMessage(ChatColor.RED + "You do not have permission to do this!"); } } else if(args.length == 1) //If there's one word after the word after the "/", so just "/time day" or "/time night" { if(player.isOp()) { if(args[0].equalsIgnoreCase("day")) { player.sendMessage(ChatColor.GREEN + "Time set to day!"); Bukkit.dispatchCommand(sender, "time set 1000"); } else if(args[0].equalsIgnoreCase("night")) { player.sendMessage(ChatColor.GREEN + "Time set to night!"); Bukkit.dispatchCommand(sender, "time set 18000"); } else { player.sendMessage(ChatColor.RED + "Time not applicable!"); return false; } } else { player.sendMessage(ChatColor.RED + "You do not have permission to do this!"); } } else if(args.length > 1) { if(player.isOp()) player.sendMessage(ChatColor.RED + "Too many arguments!"); else player.sendMessage(ChatColor.RED + "You do not have permission to do this!"); } } return false; } Edited the first time to apply correct spacing in code areas. Edited the second time: Here's the thread explaining the onCommand() method.