Code Problems

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

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

    JujuMot

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

    Zombie_Striker

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

    DuaneTheDev_

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

    Trey2k

    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

    JujuMot

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

    A5H73Y


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

    JujuMot

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

    timtower Administrator Administrator Moderator

    And that error is?
     
  9. Offline

    A5H73Y

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

    JujuMot

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

    timtower Administrator Administrator Moderator

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

    JujuMot

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

    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

    Maxxxy93

    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

    A5H73Y


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

    Maxxxy93

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

    Xerox262

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

    Mr. Sandwich

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

    Minibros

    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