Player Only Getting One Item

Discussion in 'Spigot Plugin Development' started by TheShermanTanker, Jun 6, 2017.

  1. Got one Class here which gives the Player 4 Different Colour Wool but I only get the Red Wool
    Code (Java):
    package me.TheShermanTanker.MegaWalls;

    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;

    public class JoinSigns implements Listener{
     
        @EventHandler
        public void onClick(PlayerInteractEvent event){
                                 
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
             
                Block block = event.getClickedBlock();
                if(block.getType() == Material.WALL_SIGN){
                 
                    Sign sign = (Sign) block.getState();
                    Player player = (Player) event.getPlayer();
                    if(sign.getLine(1).equals("2-0")){
                                                                                 
                        player.sendMessage(ChatColor.GREEN + "Put you in a" + ChatColor.GOLD + " Forsaken " + ChatColor.GREEN + "queue!");

                        ItemStack greenwool = new ItemStack(Material.WOOL, 1, (byte)13);
                        ItemStack yellowwool = new ItemStack(Material.WOOL, 1, (byte)4);
                        ItemStack bluewool = new ItemStack(Material.WOOL, 1, (byte)11);
                        ItemStack redwool = new ItemStack(Material.WOOL, 1, (byte)14);
                        ItemMeta greenmeta = greenwool.getItemMeta();
                        ItemMeta yellowmeta = yellowwool.getItemMeta();
                        ItemMeta bluemeta = bluewool.getItemMeta();
                        ItemMeta redmeta = redwool.getItemMeta();
                        greenmeta.setDisplayName(ChatColor.GREEN + "Green Team - " + ChatColor.BOLD + "CLICK TO JOIN!");
                        yellowmeta.setDisplayName(ChatColor.YELLOW + "Yellow Team - " + ChatColor.BOLD + "CLICK TO JOIN!");
                        bluemeta.setDisplayName(ChatColor.BLUE + "Blue Team - " + ChatColor.BOLD + "CLICK TO JOIN!");
                        redmeta.setDisplayName(ChatColor.RED + "Red Team - " + ChatColor.BOLD + "CLICK TO JOIN!");
                        greenwool.setItemMeta(greenmeta);
                        yellowwool.setItemMeta(yellowmeta);
                        bluewool.setItemMeta(bluemeta);
                        redwool.setItemMeta(redmeta);
                     
                        player.teleport(new Location(Bukkit.getWorld("2-0"),-775,104,-139));
                        player.getInventory().setItem(0, redwool);
                        player.getInventory().setItem(1, bluewool);
                        player.getInventory().setItem(2, greenwool);
                        player.getInventory().setItem(3, yellowwool);
                     
                    } else if(sign.getLine(1).equals("0-0")){
                     
                        player.sendMessage(ChatColor.GREEN + "Put you in a" + ChatColor.GOLD + " Dragonkeep " + ChatColor.GREEN + "queue!");
                        player.teleport(new Location(Bukkit.getWorld("0-0"),-775,104,-139));
                     
                    } else if(sign.getLine(1).equals("1-0")){
                     
                        player.sendMessage(ChatColor.GREEN + "Put you in a" + ChatColor.GOLD + " Dragonkeep " + ChatColor.GREEN + "queue!");
                        player.teleport(new Location(Bukkit.getWorld("1-0"),-775,104,-139));
                     
                    } else if(sign.getLine(1).equalsIgnoreCase(ChatColor.RED + "Waiting for")){
                     
                        player.sendMessage(ChatColor.RED + "This server is currently reloading!");
                     
                    } else if(sign.getLine(2).equals(100/100)){
                     
                        player.sendMessage(ChatColor.RED + "This game is already full!");
                     
                    }
                 
                }
             
            }
         
        }
         
     
    }
    For some reason they only get Red Wool and not the other colour Wools did i do something wrong
     
  2. This is really messy. You could easily create methods to make this alot cleaner. Not sure what the issue is though.
     
  3. try using updateinventory after giving the items
     
    • Agree Agree x 2