Give Bedrock Command

Discussion in 'Plugin Development' started by DaAdamBombYT, Feb 24, 2017.

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

    DaAdamBombYT

    Hi, I have been making a plugin, but it won't work. I want it to be so that you type /bedrockcore and it gives you 64 bedrock, no matter what rank you are. Mine isn't working. I was wondering if someone can help me. Can someone either make the plugin, or fix my coding. ERRORS: http://imgur.com/a/fPSCa Heres the coding:

    Code:
    package me.DaAdamBombYT.Bedrock;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    import net.minecraft.server.v1_8_R3.ItemStack;
    import net.minecraft.server.v1_8_R3.Material;
    
    public class Enable extends JavaPlugin implements Listener {
    
        public void onEnable() {
         
            Bukkit.getServer().getPluginManager().registerEvents(this,  this);
         
        }
         
     
        public void onDisable() {
         
         
         
         
        }
        @EventHandler
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
         
            Player.player = (Player) sender;
         
            if(cmd.getName().equalsIgnoreCase("bedrockcore")) {
                if(player.hasPermission("bedrockcore.use")) {
                 
                    player.sendMessage(chatColor.GREEN + "You Have obtained Bedrock!")
                    player.getInventory().addItem(new ItemStack(Material.BEDROCK, 64));
                 
                }else{
                 
                    player.sendMessage(ChatColor.RED + "You do not have access to this command!");
             
                    return false;
                 
                }
     
           
                 
             
            }
         
            return false;
         
        }
     
    }
     
    Last edited by a moderator: Feb 24, 2017
  2. Online

    timtower Administrator Administrator Moderator

    Moved to plugin development.
    @DaAdamBombYT onCommand is not an event, remove the @EventHandler and Listener stuff.
    Did you register the command in your plugin.yml?
    Do not cast to Player before checking if it is a player.
    Your imports are wrong for ChatColor, ItemStack and Material, please build on the Bukkit.jar, not on Spigot.jar
     
  3. Offline

    DaAdamBombYT


    I changed to bukkit

    Heres Plugin.yml:

    Code:
    name: BedrockCore
    description: Duplication Patches
    main: me.plisov.tutorial.Enable
    version: 2.0
    author: DaAdamBombYT
    commands:
        bedrockcore:
         description: Gives Bedrock
     
  4. Online

    timtower Administrator Administrator Moderator

    @DaAdamBombYT Indentation in the plugin.yml is wrong, at least on here it is.
    And about those errors: Add Bukkit.jar to your build path and remove the NMS imports.
     
  5. Offline

    DaAdamBombYT

    Getting better, i think there are 3 errors ledt. Can you help? It says where the errors are on the left. Heres the coding: http://imgur.com/a/KIDhp
    EDIT: I fixed the chatcolor and "player" problems.
    ANy ideas on fixing?

    FInally, one error left. Its on this line, how can i fix?
    sender.getInventory().addItem(new ItemBlock(Material.BEDROCK, 64));

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.

    Okay, i have made multiple threads on this, so ill combine them into one.
    I have been having trouble with my give bedrock command. It makes it so that if you run /bedrockcore it adds 64 bedrock to your inventory. I am having errors on line 35.

    *Before i keep going, if u reply, please remember, i am REALLY NEW to coding plugins.*

    Here is a screenshot of eclipse with the coding: http://imgur.com/a/Ldx66
    Here is a pastebin of the code: http://pastebin.com/R6pPVmmC
    Here is a screenshot of the error on line 35: http://imgur.com/a/xDx9h
    Here is a screenshot of the Plugin.yml: http://imgur.com/a/eASDr

    Also, i want it so that as soon as i add the plugin, all the players can have access to /bedrockcore WITHOUT changing up the permissions manually on the server.

    Please explain how to do the permission thing and help me debug line 35
     
    Last edited by a moderator: Feb 25, 2017
  6. Offline

    MrGeneralQ

    We all replied to your thread.

    First of all don't use sender , use player instead, Therefore cast the sender to the player.

    if(!(sender instanceof Player)) return ;
    Player player = (Player) sender;


    Then you typed ItemBlock instead of ItemStack

    ItemStack item = new ItemStack(Material.BEDROCK, 64);
    player.getInventory.addItem(item);
     
    Zombie_Striker and mine-care like this.
  7. Offline

    DaAdamBombYT

    getInventory and ItemStack cannot be resolved
     
  8. Offline

    Zombie_Striker

    @DaAdamBombYT
    Are you using the player instance, and have you imported itemstack yet?
     
    MrGeneralQ likes this.
  9. Online

    timtower Administrator Administrator Moderator

    @DaAdamBombYT It is ItemStack, not ItemBlock

    EDIT: Merged threads
     
    Last edited: Feb 25, 2017
  10. Offline

    Zombie_Striker

    Just noticed this: Why are you still on 1.8? Please read this and update your server to 1.11.
     
Thread Status:
Not open for further replies.

Share This Page