Solved [1.8.8] How to send a command as console not working

Discussion in 'Spigot Plugin Development' started by Moose1031, Mar 22, 2019.

Thread Status:
Not open for further replies.
  1. I'm trying to make it so console sudoes the player that clicks a item in a GUI (That is working) but the sudoing a player is not working
    Code (Java):
    package me.moose.TESHOP.PickaxeUI;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;

    import me.moose.TESHOP.Utils;
    public class CreateUI {

        public static Inventory inv;
        public static String inventory_name;
        public static int inv_rows = 2 * 9;
     
        public static void initializes() {
            inventory_name = Utils.chat("&c&lEnchant Your Pickaxe");
         
            inv = Bukkit.createInventory(null, inv_rows);
        }
     
        public static Inventory PickGUI (Player p) {
            Inventory toReturn = Bukkit.createInventory(null, inv_rows, inventory_name);
            Utils.createItem(inv, 399, 1, 14, "&c&lClose");
            Utils.createItem(inv, 46, 1, 1,  "&c&lExplosion","&a&bMust be holding Pickaxe!");
            Utils.createItem(inv, 278, 1, 2, "&6&lJackHammer","&a&bMust be holding Pickaxe!");
            Utils.createItem(inv, 285, 1, 3, "&e&lHaste","&a&bMust be holding Pickaxe!");
            Utils.createItem(inv, 278, 1, 4, "&2&lEfficiency","&7Efficiency 10","&a&bMust be holding Pickaxe!");
            Utils.createItem(inv, 278, 1, 5, "&b&lFortune","&7Fortune 10","&a&bMust be holding Pickaxe!");
            Utils.createItem(inv, 288, 1, 6, "&o&lSpeed", "&a&bMust be holding Pickaxe!");
            toReturn.setContents(inv.getContents());
            return toReturn;
    }

    public static void clicked(Player p, int slot, ItemStack clicked, Inventory inv) {
    if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&cClose"))) {
        p.closeInventory();
    if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&c&lExplosion"))) {
        Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "sudo " + p.getName() + " te enchant " + p.getName() + " Explosion +1");
    }
    if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&6&lJackHammer"))) {
        Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "sudo " + p.getName() + " te enchant " + p.getName() + " JackHammer +1");
    }
    if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&e&lHaste"))) {
        Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "sudo " + p.getName() + " te enchant " + p.getName() + " Haste +1");
    }
    if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&2&lEfficiency"))) {
        Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "sudo " + p.getName() + " te enchant " + p.getName() + " Efficiency +1");
    }
    if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&b&lFortune"))) {
        Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "sudo " + p.getName() + " te enchant " + p.getName() + " Fortune +1");
    }
    if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&o&lSpeed"))) {
        Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "sudo " + p.getName() + " te enchant " + p.getName() + " Speed +1");
    }
    }
    }
    }
     
     
  2. Instead of comparing names, why dont you compare slots?
     
  3. I never thought about compare slots
    How would i compare the slots?
    I have used it before but it was complicated for me
     
    #3 Moose1031, Mar 22, 2019
    Last edited: Mar 22, 2019
  4. Do you have a 'sudo' command on the server?
     
  5. Are you ever calling your clicked method? Speaking of the 'clicked' method, it would be simpler to use a switch statement.
     
  6. I way i'm using i know because i have used it before in the same plugin.
    It worked when i only had one item
     
  7. You should be using an API instead of running console commands.

    Are you sure clicked is being fired? Try debugging our the item name.
     
  8. How would i check if the click is being fired?
    because i think it isn't being fired
     
  9. I fixed it thanks for the help.
     
Thread Status:
Not open for further replies.