Player Command Blocks. (First Plugin) Please help.

Discussion in 'Plugin Development' started by MrbCrafts, Mar 9, 2014.

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

    MrbCrafts

    I need a little help here. I have a little bit of the plugin completed. What I want to happen in the end is that a player does /pcb and it gives the player a command block, but with a economy price. (iConomy) Then, a player can place it down, set/use a command they only have the permission for.

    EDIT: I know that only ops can set commands. Maybe have it use data like Button Commands and have the user say the command in the chat. (User places down block, plugin asks;"What do you want this PCB to have as a command? Please say it in chat without the /"

    This is what I have so far.
    Code:java
    1. package me.MrbCrafts.PCB;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class PCB extends JavaPlugin{
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15. public static PCB plugin;
    16.  
    17. @Override
    18. public void onDisable() {
    19. PluginDescriptionFile pdfFile = this.getDescription();
    20. this.logger.info(pdfFile.getName() + " Has Been Disabled ");
    21. }
    22.  
    23. @Override
    24. public void onEnable() {
    25. PluginDescriptionFile pdfFile = this.getDescription();
    26. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled ");
    27. }
    28.  
    29. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[]args){
    30. Player player = (Player) sender;
    31. if(commandLabel.equalsIgnoreCase("pcb")){
    32. }
     
  2. Offline

    MrbCrafts

    Can someone please help me? I may be new at plugin development, but I would like to learn from someone experienced.
     
  3. Offline

    Tomasko

    For giving an item to player(etc. commanblock)
    Code:java
    1. player.getInventory().addItem(new ItemStack(Material.COMMAND, 1));


    There is thread for hooking to iConomy
    https://forums.bukkit.org/threads/hooking-into-iconomy-api.178273/
    For "chat command without /" you can use hashmaps
    Code:java
    1. [FONT=Consolas] HashMap<String, Integer> map = new HashMap<String, Integer>();[/FONT]

    like if player placed block(BlockPlaceEvent) put player into hashmap and use ASyncPlayerChatEvent to log/cancel message and then remove player from hashmap. For executing command you can use for console
    Code:java
    1. getSever().dispatchCommand(getServer().getConsoleSender, "cmd");
    or from player
    Code:java
    1. player.performCommand("command").


    //EDIT
    You can use Arraylist instead hashmaps, it's quite easier :)
    Code:java
    1. ArrayList<String> alist = new ArrayList<>;
     
  4. Offline

    MrbCrafts

    Thank you. I will use this to the best of my knowlage. If your advice helped a lot, I will put your name in the credits. Thanks a lot.
     
Thread Status:
Not open for further replies.

Share This Page