I am trying to learn java, so I watched a few tutorials, and came up with a simple plugin for voting, but it no work O_O http://pastebin.com/3U83ehnt any problems here?
It would help if we could see the error log. What exactly is the problem that is occuring? Do you have plugin.yml file setup correctly? Have you checked out this wiki: http://wiki.bukkit.org/Plugin_Tutorial What I can tell now is the place of your return false statement in the onCommand method will make it always return false, despite if the if statement is true or not. Returning false is primarily used to check for correct arguments and if any exceptions occur to stop. But returning true means everything worked properly, the command was typed in right and the method is done. I suggest changing it like so: Code: if (commandLabel.equalsIgnoreCase("vote")) { player.sendMessage(ChatColor.GOLD + "================================="); player.sendMessage(ChatColor.AQUA + "Please Click the link below to vote!:"); player.sendMessage(ChatColor.GREEN + "link"); player.sendMessage(ChatColor.GOLD + "================================="); return true; }
Do this instead: Code:java package me.malo.votesite; import java.util.logging.Logger;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 Main extends JavaPlugin {public void onEnable() { getLogger().info("[VoteSite] has been enabled!");} public void onDisable() { getLogger().info("[VoteSite] has been disabled!");} public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player player = (Player) sender; if (cmd.getName().equalsIgnoreCase("vote")) { player.sendMessage(ChatColor.GOLD + "================================="); player.sendMessage(ChatColor.AQUA + "Please Click the link below to vote!:"); player.sendMessage(ChatColor.GREEN + "link"); player.sendMessage(ChatColor.GOLD + "================================="); return true; } return false; }} At least, that's how I would do it. Also, do you have the plugin.yml? Also, typing 'vote' in console would give you an error because you're telling it that it's a player, if you don't want that to happen, you'll have to check if the CommandSender is a player, and if it isn't, use System.out.println or java's logger to print messages to the console. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
What's the need to casting the sender to player and then sending the messages? You can just do sender.sendmessage("")... Also if you cast sender to player without checking if its a player first then this will throw errors when executed from console. Better Version Code: package me.malo.votesite; import java.util.logging.Logger; 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 Main extends JavaPlugin { public void onEnable() { getLogger().info("[VoteSite] has been enabled!"); } public void onDisable() { getLogger().info("[VoteSite] has been disabled!"); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (cmd.getName().equalsIgnoreCase("vote")) { sender.sendMessage(ChatColor.GOLD + "================================="); sender.sendMessage(ChatColor.AQUA + "Please Click the link below to vote!:"); sender.sendMessage(ChatColor.GREEN + "link"); sender.sendMessage(ChatColor.GOLD + "================================="); return true; } return false; } }
It's ok But you do have a plugin.yml, right? EDIT by Moderator: merged posts, please use the edit button instead of double posting.