Code Problems

Discussion in 'Plugin Development' started by JujuMot, Jun 1, 2016.

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


    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):
    if(cmd.equalsIgnoreCase("/flyspeed 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):
    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?

    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.
    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");
            ShapedRecipe recipe = new ShapedRecipe(tnt);
            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);
    if(cmd.equalsIgnoreCase("/gm 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!
    Last edited by a moderator: Jun 2, 2016
  2. Offline


    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).
  3. Offline



    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.
  4. Offline


    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();
  5. Offline


    Ok, but then how would I get the target variable enabled? New to coding so don't know much :3
  6. Offline


    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:

    if (arguments equal 1)
    targetPlayer = Bukkit.getPlayer(args[1])
    } else {
    //open your inventory
  7. Offline


    I just get a massive error....
  8. Offline

    timtower Administrator Administrator Moderator

    And that error is?
  9. Offline


    I'm going to take a wild guess and assume my code has been copied and pasted.
  10. Offline


    I get a red line under,

    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.
    Last edited by a moderator: Jun 2, 2016
  11. Offline

    timtower Administrator Administrator Moderator

    @JujuMot That is why your never blindly copy paste.
  12. Offline


    Sorry..But can anyone help me...
  13. Offline

    timtower Administrator Administrator Moderator

    @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.
  14. Offline


    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
  15. Offline


    Correct, although what they should be doing is using an argument, rather than a hardcoded '7'.
  16. Offline


    Wasnt aware of that, thanks :D, I started not long ago
  17. Offline


    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

    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.
  18. Offline

    Mr. Sandwich

    Here's a pro tip: Watch bukkit coding tutorials on youtube and then continue coding plugins
  19. Offline


    Delete the /
  20. 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.
Thread Status:
Not open for further replies.

Share This Page