Solved My plugin don't upload ?

Discussion in 'Plugin Development' started by Doct_fr, May 19, 2020 at 1:41 PM.

  1. Offline

    Doct_fr

    Code:
    if (current.getType() == Material.GREEN_STAINED_GLASS_PANE) {
                            Inventory inv4 = Bukkit.createInventory(null, 27, "§8Online player");
                            player.closeInventory();
                            player.openInventory(inv4);      
                               List<String> players = new ArrayList<String>();
                                for (Player online : Bukkit.getServer().getOnlinePlayers()) {
                                players.add(online.getName()); }
                                for(int i = 0; i < players.size(); i++) {
                                    int y = 2;
                                    inv4.setItem(y, getItem(Material.PLAYER_HEAD, players.get(i)));
                                    y = y + 9;
                                    if (y > 22) {
                                        y = 7;
                                    }
                                }
                        }
                    }
      if(event.getView().getTitle().equalsIgnoreCase("§8Online player")) {
                        if (current.getType() == Material.PLAYER_HEAD) {  
                            player.closeInventory();
                            Inventory inv5 = Bukkit.createInventory(null, 27, "§8Make a price");
                            player.openInventory(inv5);
                          
                            inv5.setItem(27, getItem(Material.RED_WOOL, ChatColor.RED + "Back"));
                            if (current.getType() == Material.RED_WOOL) {
                                player.closeInventory();
                            }
                          
                            inv5.setItem(0, getItem(Material.LIME_STAINED_GLASS_PANE, ChatColor.GREEN + "add 1"));
                            if (current.getType() == Material.LIME_STAINED_GLASS_PANE) {
                                prix = prix +1;
                            }
                            inv5.setItem(1, getItem(Material.BLACK_STAINED_GLASS_PANE, ChatColor.GREEN + "add 5"));
                            if (current.getType() == Material.GREEN_STAINED_GLASS_PANE) {
                                prix = prix +5;
                            }
                            inv5.setItem(2, getItem(Material.BROWN_STAINED_GLASS_PANE, ChatColor.GREEN + "add 10"));
                            if (current.getType() == Material.BROWN_STAINED_GLASS_PANE) {
                                prix = prix +10;
                            }
                            inv5.setItem(6, getItem(Material.ORANGE_STAINED_GLASS_PANE, ChatColor.RED + "remove 1"));
                            if (current.getType() == Material.ORANGE_STAINED_GLASS_PANE) {
                                prix = prix -1;
                            }
                            inv5.setItem(7, getItem(Material.PINK_STAINED_GLASS_PANE, ChatColor.RED + "remove 5"));
                            if (current.getType() == Material.PINK_STAINED_GLASS_PANE) {
                                prix = prix -5;
                            }
                            inv5.setItem(8, getItem(Material.RED_STAINED_GLASS_PANE, ChatColor.RED + "remove 10"));
                            if (current.getType() == Material.RED_STAINED_GLASS_PANE) {
                                prix = prix -10;
                            }
                          
                          
                            inv5.setItem(13, getItem(Material.YELLOW_STAINED_GLASS_PANE, ChatColor.GOLD + "" + prix));
                            inv5.setItem(18, getItem(Material.GREEN_WOOL, ChatColor.GREEN + "Valid"));
                        }
                      
                    }
                  
                  
                    if(event.getView().getTitle().equalsIgnoreCase("§8Make a price")) {
                    if (current.getType() == Material.GREEN_WOOL) {                                                                                              
                        player.closeInventory();                                                                                                              
                        Bukkit.dispatchCommand(player, "bounty new "+current.getItemMeta().getDisplayName()+ " " + prix);  
                        listtab.add(addplayer(current.getItemMeta().getDisplayName(), prix));
                        }                                                                              
                    }
    
    When i put the plugin on my world i can go in §8Online player gui but then i click the player_head but it directly do last thing the commands Bukkit.dispatchCommand(player, "bounty new "+current.getItemMeta().getDisplayName()+ " " + prix);

    Like all inv5 don't upload. pls help
     
    Last edited by a moderator: May 19, 2020 at 2:22 PM
  2. Online

    timtower Moderator Moderator

    @Doct_fr Close the old inventory, open inv5 a tick later
     
  3. Offline

    Doct_fr

    @timtower thx for your help but how to pause to i need to use sleep ?
     
  4. Online

    timtower Moderator Moderator

    No, then you will freeze the entire server.
    You use a BukkitRunnable with runTaskLater
     
  5. Offline

    Doct_fr

    @timtower wohh you quick let me try this

    Code:
    JavaPlugin plugin = null;       
                            double timeInSeconds = 0.1;
                            double timeInTicks = 20 * timeInSeconds;
                            new BukkitRunnable() {
                                @Override
                                public void run() {player.openInventory(inv5);}
                            }.runTaskLater(plugin, (long) timeInTicks); 

    This is the code i added but it is still not working.


    Code:
    if(cmd.getName().equalsIgnoreCase("bounty")) {
                    if(args.length == 3) {
                        if (args[0].equalsIgnoreCase("new"))    {
                       
                            Player target = Bukkit.getPlayer(args[1]);
                            Integer u = Integer.parseInt (args [2]);
                            ItemStack Gold = new ItemStack(Material.GOLD_INGOT, u);
                            int i = Gold.getAmount();
                            if (player.getInventory().contains(Material.GOLD_INGOT, i)) {
                                player.getInventory().removeItem(Gold);
                                player.sendMessage(ChatColor.GREEN +"you choosed " + target.getName() + " has a target for " + u + ChatColor.GOLD + "GOLD");
                                target.sendMessage(ChatColor.RED + "Your are a target");
                            } else {
                                player.sendMessage(ChatColor.DARK_RED + "Not enough gold");
                            }                       
                        }
                    }
                    else {
                        player.sendMessage(ChatColor.DARK_RED + "Invalid command do /bounty new Player Amount");
                    }
                }
    

    this is the /bounty new player amout that i create. and when i click on the head it directly says "Not enough gold"
    probably my code isn't good ?
    @timtower

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2020 at 1:38 AM
  6. Online

    timtower Moderator Moderator

    @Doct_fr Yeah, don't use null as your plugin, needs to be an actual plugin.

    How much gold does the player have? How much are you asking for?
     
  7. Offline

    Doct_fr

    @timtower inv5 is here to make a price; so you have some item that you can click and it add or remove price. the old way was automatic; you had to pay 10G.

    JavaPlugin plugin = ; what do i put here

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2020 at 1:50 AM
  8. Online

    timtower Moderator Moderator

    Check what the value is for i, check how much gold the user actually has.
    And the instance of your main class
     
  9. Offline

    Doct_fr

    i is Gold.getamout
    and Gold is u (number) gold_ingot. u is arg 2 in /bounty new Player arg2
    Sorry I am new in plugins coding, and i am new in this forum.

    I don't have a real main class with "public static void main(String[] args) {" I have a class with on enable is that that one ?
     
  10. Online

    timtower Moderator Moderator

    Print the actual values, see why the check is failing! Debug!

    And no, that is for executables only.
    The main class is the one that extends JavaPlugin.
     
  11. Offline

    Doct_fr

    sorry but this question must be very stupid bt how can i have instance of main. my main class is named random
     
  12. Online

    timtower Moderator Moderator

    @Doct_fr If the posted code is in your main class: "this"
    If not in your main class: pass it along using a constructor.
     
  13. Offline

    Doct_fr

    Ok I extends the class to my main and then i put this. I also
    Code:
     player.sendMessage(""+i);
    
    but nothing hapends so is it bugged ?
     
  14. Online

    timtower Moderator Moderator

    Please post your full class, a single line from which I don't know where it is located tells nothing.
     
  15. Offline

    Doct_fr

    Code:
    package fr.doctfr.random.commands;
    
    import java.io.Console;
    import java.util.Arrays;
    import java.util.LinkedList;
    import java.util.List;
    
    import fr.doctfr.random.RandomListerners;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import net.md_5.bungee.api.ChatColor;
    import net.minecraft.server.v1_15_R1.DataWatcher.Item;
    
    public class CommendDiscord implements CommandExecutor {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args) {
            if(sender instanceof Player) {
                Player player = (Player)sender;
           
            if(cmd.getName().equalsIgnoreCase("bounty")) {
                if(args.length == 0) {
                Inventory inv = Bukkit.createInventory(null, 27, "§8Bouty Menu");
                player.openInventory(inv);
                inv.setItem(15, getItem(Material.DIAMOND_SWORD, ChatColor.RED + "find a target to kill"));
                inv.setItem(11, getItem(Material.GOLD_INGOT, ChatColor.GREEN + "manage your target for money."));
               
                return true;
    
                }
                if(cmd.getName().equalsIgnoreCase("bounty")) {
                    if(args.length == 3) {
                        if (args[0].equalsIgnoreCase("new"))    {
                       
                            Player target = Bukkit.getPlayer(args[1]);
                            Integer u = Integer.parseInt (args [2]);
                            ItemStack Gold = new ItemStack(Material.GOLD_INGOT, u);
                             int i = Gold.getAmount();
                             player.sendMessage(""+i);
    
                            if (player.getInventory().contains(Material.GOLD_INGOT, i)) {
                                player.getInventory().removeItem(Gold);
                                player.sendMessage(ChatColor.GREEN +"you choosed " + target.getName() + " has a target for " + u + ChatColor.GOLD + "GOLD");
    
                                target.sendMessage(ChatColor.RED + "Your are a target");
                            } else {
                                player.sendMessage(ChatColor.DARK_RED + "Not enough gold");
                            }                       
                        }
                    }
                    else {
                        player.sendMessage(ChatColor.DARK_RED + "Invalid command do /bounty new Player Amount");
                    }
                }
               
               
               
                   
                   
                }
               
           
            return true;
           
            }
           
           
            return false;
        }
        public ItemStack getItem(Material material, String customitem) {
            ItemStack it = new ItemStack(material);
            ItemMeta itm = it.getItemMeta();
            itm.setDisplayName(customitem);
            it.setItemMeta(itm);
            return it;
        }
    
    }
    


    Code:
    package fr.doctfr.random;
    
    import java.sql.Date;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.LinkedList;
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.libs.jline.console.KillRing;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.SkullMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    
    import com.google.common.base.Ticker;
    import com.google.common.io.ByteArrayDataOutput;
    import com.mojang.authlib.yggdrasil.response.HasJoinedMinecraftServerResponse;
    import com.mojang.brigadier.Command;
    import com.mysql.fabric.Server;
    
    import net.md_5.bungee.api.ChatColor;
    import net.minecraft.server.v1_15_R1.CommandBlockListenerAbstract;
    import net.minecraft.server.v1_15_R1.DataWatcher.Item;
    
    public class RandomListerners extends Random implements Listener {
        public LinkedList list = new LinkedList();
        public LinkedList<String> listtab = new LinkedList<String>();
    
       
        @EventHandler
        public void onClick(InventoryClickEvent event) {
           
            Inventory inv = event.getInventory();
            Player player = (Player) event.getWhoClicked();
            ItemStack current = event.getCurrentItem();
            int prix = 0;
            if(current == null) return;
           
            if(event.getView().getTitle().equalsIgnoreCase("§8Bouty Menu")) {
           
                if (current.getType() == Material.DIAMOND_SWORD) {
                    Inventory inv2 = Bukkit.createInventory(null, 54, "§8Lst of targets");
                    player.closeInventory();
                    player.openInventory(inv2);
                     for(int i = 0; i < listtab.size(); i++) {
                            int y = 2;
                            inv2.setItem(y, getItem(Material.PLAYER_HEAD, (String) listtab.get(i)));
                            y = y + 9;
    
                    }
                }
                if (current.getType() == Material.GOLD_INGOT) {
               
                    Inventory inv3 = Bukkit.createInventory(null, 27, "§8manage your target");
                    player.closeInventory();
                    player.openInventory(inv3);
                    inv3.setItem(0, getItem(Material.GREEN_STAINED_GLASS_PANE, ChatColor.GREEN + "add a target"));
                    inv3.setItem(9, getItem(Material.GREEN_STAINED_GLASS_PANE, ChatColor.GREEN + "add a target"));
                    inv3.setItem(18, getItem(Material.GREEN_STAINED_GLASS_PANE, ChatColor.GREEN + "add a target"));
                    inv3.setItem(8, getItem(Material.RED_STAINED_GLASS_PANE, ChatColor.RED + "remove a target"));
                    inv3.setItem(17, getItem(Material.RED_STAINED_GLASS_PANE, ChatColor.RED + "remove a target"));
                    inv3.setItem(26, getItem(Material.RED_STAINED_GLASS_PANE, ChatColor.RED + "remove a target"));
    
                }
            }
                    if(event.getView().getTitle().equalsIgnoreCase("§8manage your target")) {
    
                        if (current.getType() == Material.GREEN_STAINED_GLASS_PANE) {
                            Inventory inv4 = Bukkit.createInventory(null, 27, "§8Online player");
                            player.closeInventory();
                            player.openInventory(inv4);       
                               List<String> players = new ArrayList<String>();
                                for (Player online : Bukkit.getServer().getOnlinePlayers()) {
                                players.add(online.getName()); }
                                for(int i = 0; i < players.size(); i++) {
                                    int y = 2;
                                    inv4.setItem(y, getItem(Material.PLAYER_HEAD, players.get(i)));
                                    y = y + 9;
                                    if (y > 22) {
                                        y = 7;
                                    }
                                }
                        }
                    }
                   
                    if(event.getView().getTitle().equalsIgnoreCase("§8Online player")) {
                        if (current.getType() == Material.PLAYER_HEAD) {   
                            player.closeInventory();
                            Inventory inv5 = Bukkit.createInventory(null, 27, "§8Make a price");
                            JavaPlugin plugin = this;      
                            double timeInSeconds = 0.1;
                            double timeInTicks = 20 * timeInSeconds;
                            new BukkitRunnable() {
                                @Override
                                public void run() {player.openInventory(inv5);}
                            }.runTaskLater(plugin, (long) timeInTicks); 
                           
                            inv5.setItem(27, getItem(Material.RED_WOOL, ChatColor.RED + "Back"));
                            if (current.getType() == Material.RED_WOOL) {
                                player.closeInventory();
                            }
                           
    
    
                            inv5.setItem(0, getItem(Material.LIME_STAINED_GLASS_PANE, ChatColor.GREEN + "add 1"));
                            if (current.getType() == Material.LIME_STAINED_GLASS_PANE) {
                                prix = prix +1;
                            }
                            inv5.setItem(1, getItem(Material.BLACK_STAINED_GLASS_PANE, ChatColor.GREEN + "add 5"));
                            if (current.getType() == Material.GREEN_STAINED_GLASS_PANE) {
                                prix = prix +5;
                            }
                            inv5.setItem(2, getItem(Material.BROWN_STAINED_GLASS_PANE, ChatColor.GREEN + "add 10"));
                            if (current.getType() == Material.BROWN_STAINED_GLASS_PANE) {
                                prix = prix +10;
                            }
                            inv5.setItem(6, getItem(Material.ORANGE_STAINED_GLASS_PANE, ChatColor.RED + "remove 1"));
                            if (current.getType() == Material.ORANGE_STAINED_GLASS_PANE) {
                                prix = prix -1;
                            }
                            inv5.setItem(7, getItem(Material.PINK_STAINED_GLASS_PANE, ChatColor.RED + "remove 5"));
                            if (current.getType() == Material.PINK_STAINED_GLASS_PANE) {
                                prix = prix -5;
                            }
                            inv5.setItem(8, getItem(Material.RED_STAINED_GLASS_PANE, ChatColor.RED + "remove 10"));
                            if (current.getType() == Material.RED_STAINED_GLASS_PANE) {
                                prix = prix -10;
                            }
                           
                           
                            inv5.setItem(13, getItem(Material.YELLOW_STAINED_GLASS_PANE, ChatColor.GOLD + "" + prix));
                            inv5.setItem(18, getItem(Material.GREEN_WOOL, ChatColor.GREEN + "Valid"));
                        }
                       
                    }
                   
                   
                    if(event.getView().getTitle().equalsIgnoreCase("§8Make a price")) {
    
                    if (current.getType() == Material.GREEN_WOOL) {                                                                                               
                        player.closeInventory();                                                                                                               
                        Bukkit.dispatchCommand(player, "bounty new "+current.getItemMeta().getDisplayName()+ " " + prix);   
                        listtab.add(addplayer(current.getItemMeta().getDisplayName(), prix));
                        }                                                                               
                    }
        }
        public String addplayer(String nom, int prixx) {
            String l = "Joueur" + nom + " à " +prixx + "Gold";
            return l;
           
        }
                                   
        public ItemStack getItem(Material material, String customitem) {
            ItemStack it = new ItemStack(material);
            ItemMeta itm = it.getItemMeta();
            itm.setDisplayName(customitem);
            it.setItemMeta(itm);
            return it;
        }
    }
       
           
       
       
    
    
       
           
    
    
    
    Code:
    package fr.doctfr.random;
    
    import java.awt.Color;
    import java.util.LinkedList;
    
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import fr.doctfr.random.commands.CommendDiscord;
    import net.md_5.bungee.api.ChatColor;
    
    public class Random extends JavaPlugin {
        @Override
        public void onEnable() {
            System.out.println(ChatColor.DARK_GREEN + "Le plugin vient de s'allumer");
            getCommand("discord").setExecutor(new CommendDiscord());
            getCommand("alert").setExecutor(new CommendDiscord());
            getCommand("bounty").setExecutor(new CommendDiscord());
    
           
            getServer().getPluginManager().registerEvents(new RandomListerners(), this);
           
        }
       
        @Override
        public void onDisable() {
            System.out.println("Le plugin vient de s'eteindre");
            super.onDisable();
       
        }
        public Random() {
        }
       
    
    }
    
    
    Code:
    name: random
    version: 1.0
    author: doctfr
    main: fr.doctfr.random.Random
    api-version: 1.13
    commands:
      discord:
        description: discord
        permission: discord.use
      alert:
        description: restart du serv
        permission: mod.use
      bounty:
        description: choose ur target
        permission: discord.use
      bounty new:
        description: new target
        permission: d


    there you go. I really thank you
     
  16. Online

    timtower Moderator Moderator

    @Doct_fr You can't extend your main class.
    Pass it along using a constructor.

    And what command are you running?
     
  17. Offline

    Doct_fr

    /bounty to get to inv and /bounty new playername amout
    how to pass it using a constructor @timtower
     
  18. Online

    timtower Moderator Moderator

  19. Offline

    Doct_fr

    System.out.println(i); it doesn't work. like i see nothings in the console
    i want the player to choose his amout in a gui but the gui don't appear.


    if i don't have enought money "Not enough gold" and if i have "you choosed " + target.getName() + " has a target for " + u + ChatColor.GOLD + "GOLD"
     
  20. Online

    timtower Moderator Moderator

    @Doct_fr Then you if statements are not going through, move them up.
    First line of the method, add a print there.
     
  21. Offline

    Doct_fr

    Thx man it is working now. I really thank you.
     

Share This Page