Hey guys, Im new to coding and I learned a lot in my 1 week of coding and I have a couple of bugs/questions I need help with. Here they are: FlySpeed (My Code for it): Code: if(cmd.equalsIgnoreCase("/flyspeed 7")){ p.setFlySpeed(-7); p.sendMessage(ChatColor.GOLD.toString() + ChatColor.BOLD + "You have set your flying speed to" + ChatColor.BOLD.toString() + ChatColor.WHITE + "7" + ChatColor.GOLD.toString() + ChatColor.BOLD + "!"); } The code I use for this doesn't seem to work, I need to know the exact code for it. The code I used for it doesn't work. InventorySeeing (My code for it): Code: if(cmd.equalsIgnoreCase("/invsee")){ p.openInventory(p.getInventory()); I can only see my inventory when I do /invsee , it will show my inventory twice and I need to see players inventories too. Any help with this? WizardWands: Making a WizardWand plugin and I don't know how to add kinda like a particle when they right click the wand. Its a Custom Recipe too. Code: package MainPackage; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.meta.ItemMeta; public class Commands { private void makeTNT(){ ItemStack tnt = new ItemStack(Material.BLAZE_ROD); ItemMeta meta = tnt.getItemMeta(); meta.setDisplayName(ChatColor.GOLD + "Wizard Wand"); tnt.setItemMeta(meta); ShapedRecipe recipe = new ShapedRecipe(tnt); recipe.shape("123", "456", "789"); recipe.setIngredient('1', Material.BLAZE_ROD); recipe.setIngredient('3', Material.BLAZE_ROD); recipe.setIngredient('9', Material.BLAZE_ROD); recipe.setIngredient('7', Material.BLAZE_ROD); recipe.setIngredient('5', Material.NETHER_STAR); recipe.setIngredient('1', Material.BLAZE_ROD); recipe.setIngredient('2', Material.BOOK); recipe.setIngredient('4', Material.BOOK); recipe.setIngredient('6', Material.BOOK); recipe.setIngredient('8', Material.BOOK); getServer().addRecipe(recipe); } } Gamemode: Code: if(cmd.equalsIgnoreCase("/gm 1")){ p.setGameMode(1); (When I do that I also get a red underlined error.) Also I'm trying to make a gamemode alias in my plugin code. I want it to be /gm 1 or something like that instead of /gamemode 1. Any help for that too? Also my getServer() won't work for some reason with my plugins. Do I have to add anything to make it work? Thanks a lot!
@JujuMot What is your problem? You never clearly stated what you need help with. Please read this link (How to make a Plugin Dev thread) and provide the missing information (there is a list at the bottom of the thread).
@JujuMot You do realize that the slash inside equalsignorecase would return // Also you wouldn't put "gm 1", you would just use "gm" then check if args[0] equals 1.
This is because in this instance p refers to who ever runs the command. Therefore p.getInventory() would be getting your invatory. You would need to make a argument to get the 3rd partys username and than set it to Player target = (Player) <There Username> than run target.getInventory();
Think of it this way "/invsee [player]", this means the player parameter is optional. You must handle both scenarios by taking the amount of arguments and handling it appropriately. "/invsee" - open my inventory (the arguments will be 0) "/invsee A5H73Y" - open their inventory (the arguments will be 1) The code will look something like this: Code: if (arguments equal 1) targetPlayer = Bukkit.getPlayer(args[1]) player.openInventory(targetPlayer.getInventory) } else { //open your inventory }
I get a red line under, Player TargetPlayer Arguments Args Bukkit Equals Can you guys help me with this last? This is the last thing I need help with. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
@JujuMot Read what you blindly copied, modify it to suit your variables and make it work. It was psuedo code, even if everything was defined: it wouldn't compile.
You should remove the / at if(cmd.equalsIgnoreCase("/flyspeed 7")){ and make it if(cmd.equalsIgnoreCase("flyspeed 7")){ never put a /, it automatically registers it
@JujuMot After you've fixed the arguments you need to change the amount of fly speed you're setting, you can't set it to greater than 1 or lower than -1, trying to do so would throw an IAE https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/Player.html#getFlySpeed() As for your invsee, you need to check if the player typed whose inventory they want to view, after ensuring that they typed a name you can get the player using Bukkit.getPlayer(String), then call get inventory on that object.
That's not a pro tip. That's just how you form bad habits that could lead to errors and confusion. Please learn Java before Bukkit. Sorry, but it's a bit obvious you don't have the slightest clue about it. Anyway. On to your problems. First of all, your package name needs to follow this: me.<yourname>.<pluginname>. Of course there are others that you could do, but this is the most common one. Second, using ChatColor.COLOR.toString() is unnecessary. Why are you setting the fly speed to negative seven instead of just seven? For you InventorySeeing class, you're opening up your own inventory since you're using the variable 'p'. You'd need to check the amount of arguments, check if getting a player with that name returns null, if not, create a Player variable, and open up their inventory. Also, you aren't checking if the sender is an instanceof player. All of the commands you provided cannot be done by console, so you need to check if the person performing the command is a player. For your WizardWands class, you don't need to make different character types the same variable. That's just unnecessary. Lastly, for your Gamemode class, you don't need to check for the forward-slash. Again, check if argument length is greater than 0, get the 1st argument, check if it equals 1, and then continue with your code. The method setGameMode requires a GameMode parameter, not an int. Have you ever checked why there are red lines? Because your code is incorrect and it won't compile. Also, you can get the server by getting the instance through the Bukkit class.