Commands

Discussion in 'Plugin Development' started by ItsBlockFighter, Apr 18, 2017.

Thread Status:
Not open for further replies.
  1. Hi!
    Please help me to solve a problem.How i can manage that a /duty command would work only on a block i want?
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    timtower Administrator Administrator Moderator

    @ItsBlockFighter Get the position of the player, get the block x,y,z. Compare them to what you want.
     
  4. My code how to add?
    Code:
    package me.risegaming.RG_Factions.Commands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    
    import me.risegaming.RG_Factions.Main.Errors;
    import me.risegaming.RG_Factions.Main.Permissions;
    
    public class FBI implements CommandExecutor{
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            String command = cmd.getName();
           
            if (command.equalsIgnoreCase("fbi")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    PlayerInventory inventory = player.getInventory();
    
                    if (player.hasPermission(Permissions.getPermission(Permissions.COMMAND_GUARD))) {
                        if (args.length == 0) {
                            player.sendMessage(ChatColor.RED + "[]==========[" + ChatColor.GREEN + "RiseGaming Segítség" + ChatColor.RED + "]==========[]");
                            player.sendMessage(ChatColor.WHITE + "/fbi be" + ChatColor.GRAY + " Guard Bekapcsolás");
                            player.sendMessage(ChatColor.WHITE + "/fbi ki" + ChatColor.GRAY + " Guard Kikapcsolás");
                            player.sendMessage(ChatColor.RED + "[]==========[" + ChatColor.GREEN + "Factions System" + ChatColor.RED + "]==========[]");
                        } else if(args.length == 1) {
                            if(args[0].equalsIgnoreCase("be")) {
                                player.sendMessage(ChatColor.GREEN + "Szolgálatba léptél!");
                                inventory.addItem(new ItemStack(Material.DIAMOND_SWORD, 1));
                                inventory.addItem(new ItemStack(Material.GOLDEN_APPLE, 12));
                                inventory.addItem(new ItemStack(Material.DIAMOND_CHESTPLATE, 1));
                                player.setDisplayName(ChatColor.BLUE + player.getName() + ChatColor.GREEN +  " [FBI]" + ChatColor.RED);
                            } else if(args.length == 1) {
                                if(args[0].equalsIgnoreCase("ki")) {
                                    player.sendMessage(ChatColor.GREEN + "Kiléptél a szolgálatból!");
                                    inventory.removeItem(new ItemStack(Material.DIAMOND_SWORD, 1));
                                    inventory.removeItem(new ItemStack(Material.GOLDEN_APPLE, 12));
                                    inventory.removeItem(new ItemStack(Material.DIAMOND_CHESTPLATE, 1));
                                    player.setDisplayName(player.getName());
                                }
                            }
                        }
                    } else {
                        player.sendMessage(ChatColor.RED + Errors.getErrorMessage(Errors.NO_PERMISSIONS));
                    }
    
                } else if (sender instanceof ConsoleCommandSender) {
                    Bukkit.getConsoleSender()
                            .sendMessage(ChatColor.RED + Errors.getErrorMessage(Errors.PLAYER_ONLY_COMMAND));
                }
            }
            return false;
    
        }
    
    }
    
     
  5. Offline

    timtower Administrator Administrator Moderator

    @ItsBlockFighter Lets start with: Where?
    Start by making a method that checks the location of the player.
    A Player variable in, a boolean out.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @ItsBlockFighter Not gonna spoonfeed that.
    I already told you how.
     
  7. How to get position of the player,get the block x,y,z ?
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. Oke?
    Code:
    package me.risegaming.RG_Factions.Commands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    import me.risegaming.RG_Factions.Main.Errors;
    import me.risegaming.RG_Factions.Main.Permissions;
    
    public class Mento implements CommandExecutor {
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            String command = cmd.getName();
           
            if (command.equalsIgnoreCase("mento")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    PlayerInventory inventory = player.getInventory();
                   
                    Location loc = player.getLocation();
                    loc.setX(loc.getX());
                    loc.setY(loc.getY());
                    loc.setZ(loc.getX());
                    loc.getWorld();
    
                    if (player.hasPermission(Permissions.getPermission(Permissions.COMMAND_GUARD))) {
                        if (args.length == 0) {
                            player.sendMessage(ChatColor.RED + "[]==========[" + ChatColor.GREEN + "RiseGaming Segítség" + ChatColor.RED + "]==========[]");
                            player.sendMessage(ChatColor.WHITE + "/mentő be" + ChatColor.GRAY + " Guard Bekapcsolás");
                            player.sendMessage(ChatColor.WHITE + "/mentő ki" + ChatColor.GRAY + " Guard Kikapcsolás");
                            player.sendMessage(ChatColor.RED + "[]==========[" + ChatColor.GREEN + "Factions System" + ChatColor.RED + "]==========[]");
                        } else if(args.length == 1) {
                            if(args[0].equalsIgnoreCase("be")) {
                                player.sendMessage(ChatColor.GREEN + "Szolgálatba léptél!");
                                inventory.addItem(new ItemStack(Material.GOLDEN_APPLE, 12));
                                player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 100, 0));
                                player.setDisplayName(ChatColor.BLUE + player.getName() + ChatColor.RED +  " [Mentő]" + ChatColor.GREEN);
                            } else if(args.length == 1) {
                                if(args[0].equalsIgnoreCase("ki")) {
                                    player.sendMessage(ChatColor.GREEN + "Kiléptél a szolgálatból!");
                                    inventory.removeItem(new ItemStack(Material.DIAMOND_SWORD, 1));
                                    inventory.removeItem(new ItemStack(Material.GOLDEN_APPLE, 12));
                                    inventory.removeItem(new ItemStack(Material.DIAMOND_CHESTPLATE, 1));
                                    player.setDisplayName(player.getName());
                                }
                            }
                        }
                    } else {
                        player.sendMessage(ChatColor.RED + Errors.getErrorMessage(Errors.NO_PERMISSIONS));
                    }
    
                } else if (sender instanceof ConsoleCommandSender) {
                    Bukkit.getConsoleSender()
                            .sendMessage(ChatColor.RED + Errors.getErrorMessage(Errors.PLAYER_ONLY_COMMAND));
                }
            }
            return false;
    
        }
    
    }
    
    I don't understand.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 18, 2017
  10. Offline

    timtower Administrator Administrator Moderator

  11. Sorry im beginner developer.
    You do not know if you can send the code? :( Or an example
    Because I do not really understand
     
  12. Offline

    timtower Administrator Administrator Moderator

    @ItsBlockFighter Do you know the basics for Java?
    We do not appreciate spoonfeeding as you just copy and paste code generally without knowing what it does.
     
  13. But so I usually learn things
     
  14. Offline

    timtower Administrator Administrator Moderator

    Ragnarok_ likes this.
  15. At least this is a tutorial video?
     
  16. Offline

    timtower Administrator Administrator Moderator

  17. Offline

    timtower Administrator Administrator Moderator

    @ItsBlockFighter Then you should know how to compare numbers.
    Get the player.
    Push the player into a method.
    Compare the location.
    Return true or false.
     
  18. So this is why I do not understand anything I need a code to understand
     
  19. Offline

    timtower Administrator Administrator Moderator

  20. Sorry i am not speak english (google translator)
     
  21. Er what?
    Player#getLocation is enough
     
Thread Status:
Not open for further replies.

Share This Page