Hello, I've been coding a "Custom Join Sign" plugin, and I've tried many things, but they don't seem to work: Code:java public class Main extends JavaPlugin implements Listener { public final HashMap<Location, String> signs = new HashMap<Location, String>(); public static Main plugin; public void onEnable(){plugin = this;this.getLogger().info("{Custom Join Signs} has been enabled!");this.getConfig().options().copyDefaults(true);this.saveConfig();this.getServer().getPluginManager().registerEvents(this, this);} public void onDisable() {plugin = null;getLogger().info("{Custom Join Signs} has been disabled!");}public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){if(sender instanceof Player);Player player = (Player) sender;if(player.isOp()) {if(commandLabel.equalsIgnoreCase("cjs create")){player.sendMessage(ChatColor.BLUE + "Please type in the minigame name:");player.sendMessage(ChatColor.GOLD + " 1)" + ChatColor.RED + "Do " + ChatColor.YELLOW + "/cjs setminigame [Minigame]" + ChatColor.RED + "to create a minigame.");if(commandLabel.equalsIgnoreCase("cjs setminigame" + minvar));player.sendMessage("Test Successful");}}return false;} @EventHandlerpublic void onBlockBreak(BlockBreakEvent event){Player player = event.getPlayer();if(event.equals(Blocks.SIGN_POST)) {if(signs.containsKey(event.getBlock().getLocation()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {event.setCancelled(true);} else {signs.remove(event.getBlock().getLocation());event.getBlock().breakNaturally();}}} @EventHandlerpublic void onPlayerInteract(PlayerInteractEvent event){Player player = event.getPlayer();if(signs.containsKey(event.getClickedBlock().getLocation())) {player.teleport(player.getWorld().getSpawnLocation());} else { }} When I apply the command: /cjs create; it simply doesn't work. Any help?
There are no errors in the console, but is simply says on the server (When I type in the command): "Unknown Command. Type '/help' for help."
Im not sure if this would work but try to use this code. Tell me if it works: Code:java if (args[0].equalsIgnoreCase("cjs")) {//When typed /cjsif (args[1].equalsIgnoreCase("create")) {//when typed /cjs createreturn true;}if (args[1].equalsIgnoreCase("setminigame")){//when typed /cjs setminigame}} You probably know where to put this... I don't want to explain right now. If it doesen't work try to work your way around it. If it still doesn't work then tag me and il help!
I did exactly what you did, but it's not working. Do I need to register the commands in the plugin.yml? If so, how?
brbtus um, no, that's wrong, it goes /cmd args[0] args[1] etc, not /args[0] args[1] args[2]. SkyStatus don't copy-paste above code, register the command cjs in the plugin.yml, then check the args.
Alright, thanks Necrodoom, but now I've got another problem which I need help. I want a variable to be an input from the player (For example): Code:java if (args[0].equalsIgnoreCase("setminigame" + minvar)); //Variable minvar is the variable I want to get from the player. How would I do that? Using "String minvar;", "float minvar;", or something like that? Thanks for your help! Note: System.out.print("I'm still learning, I'm much a noob. -- SkyStatus");
What is the example command you want a player to execute? Also where you are getting minvar from? Because you don't seem to get it from the command.
I want the player to execute anything, and I'm getting minvar from the player. The point is that I want them to do this: Whenever they do /cjs setminigame <Anything>, It gets the the "Anything" (Which is the variable minvar), it gets the variable minvar and sends it back to the player using "player.sendMessage('You typed in: " + minvar')".
I already got this problem resolved. (Thanks for your help though): Look at the code below (I thought it would work and it worked): Code:java if (args[1].length() > 0) { String minvar = args[1]; player.sendMessage(ChatColor.BLUE + "Success! You have added the minigame " + ChatColor.YELLOW + minvar + ChatColor.BLUE + " to the configuration file!"); this.getConfig().createSection(minvar); this.getConfig().set(minvar, "Arena Number []:" + "Arena Name: []" + "Max Players: []" + "Arena Location: [] [] []"); this.saveConfig(); return true; } However, I have another problem: Look at this code first: Code:java if (args[1].length() > 0) { String minvard = args[1]; if (this.getConfig().getString(minvard).isEmpty()) { // I had absolutely no idea what to write, so I played around with the code for a bit. player.sendMessage(ChatColor.RED + "Error: The minigame " + ChatColor.YELLOW + minvard + ChatColor.RED + "does not exist!"); return true; } this.getConfig().set(minvard, null); this.saveConfig(); player.sendMessage(ChatColor.BLUE + "Success! You have deleted the minigame " + ChatColor.YELLOW + minvard + ChatColor.BLUE + " to the configuration file!"); return true; } I want it to send the player a message if the variable "minvar" they type in doesn't exist in the configuration file. How would I do that though?
SkyStatus your length check shows me you need to learn how to use arrays before continuing, or you will simply get errors if the command is written wrong.
Um.. How would Arrays relate to this? Arent' they when coders get frustrated with many variables they use something like "String names[] = new String[8]"?
SkyStatus you didn't look what type is args? And no, thats not the only reason for arrays. Read http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html