org.bukkit.material.Wool Java Examples

The following examples show how to use org.bukkit.material.Wool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RaindropListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void handleItemDespawn(final EntityDespawnInVoidEvent event) {
    Entity entity = event.getEntity();
    if (!(entity instanceof Item)) return;
    ItemStack stack = ((Item) entity).getItemStack();

    PlayerId playerId = this.droppedWools.remove(entity);
    if (playerId == null) return;

    ParticipantState player = PGM.getMatchManager().getParticipantState(playerId);
    if (player == null) return;

    if(isDestroyableWool(stack, player.getParty())) {
        giveWoolDestroyRaindrops(player, ((Wool) stack.getData()).getColor());
    }
}
 
Example #2
Source File: RaindropListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Test if the given ItemStack is strictly an enemy wool i.e. not also
 * a wool that the given team can capture.
 */
private boolean isDestroyableWool(ItemStack stack, Competitor team) {
    if(stack == null || stack.getType() != Material.WOOL) {
        return false;
    }

    DyeColor color = ((Wool) stack.getData()).getColor();
    boolean enemyOwned = false;

    for(Goal goal : team.getMatch().needMatchModule(GoalMatchModule.class).getGoals()) {
        if(goal instanceof MonumentWool) {
            MonumentWool wool = (MonumentWool) goal;
            if(wool.isVisible() && !wool.isPlaced() && wool.getDyeColor() == color) {
                if(wool.getOwner() == team) {
                    return false;
                } else {
                    enemyOwned = true;
                }
            }
        }
    }

    return enemyOwned;
}
 
Example #3
Source File: GameObjectiveProximityHandler.java    From CardinalPGM with MIT License 6 votes vote down vote up
private void tryUpdate(Player player, Block block) {
    if (!teamAllowsUpdate(Teams.getTeamByPlayer(player))) return;
    boolean update = true;
    if (objective instanceof WoolObjective) {
        update = !info.needsTouch;
        if (info.needsTouch) {
            if (info.metric.equals(ProximityMetric.CLOSEST_BLOCK)) {
                if (block.getType().equals(Material.WOOL) && ((Wool) block.getState().getData()).getColor().equals(((WoolObjective) objective).getColor()))
                    update = true;
            } else {
                ItemStack item = new ItemStack(Material.WOOL, 1, ((WoolObjective) objective).getColor().getWoolData());
                if (player.getInventory().containsAtLeast(item, 1)) update = true;
            }
        }
    } else if (objective instanceof FlagObjective) {
        if (info.needsTouch) {
            update = Flags.getFlag(player) == objective;
        }
    }
    if (update) setProximity(player.getLocation(), player);
}
 
Example #4
Source File: RaindropListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void handleCraft(final CraftItemEvent event) {
    ParticipantState player = PGM.getMatchManager().getParticipantState(event.getWhoClicked());
    if (player == null) return;

    for (ItemStack ingredient : event.getInventory().getMatrix()) {
        if(this.isDestroyableWool(ingredient, player.getParty())) {
            giveWoolDestroyRaindrops(player, ((Wool) ingredient.getData()).getColor());
        }
    }
}
 
Example #5
Source File: Util.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a GUI button made of a wool.
 *
 * @param dc
 * @param name
 * @return
 */
public static ItemStack createButton(DyeColor dc, String name) {
    ItemStack i = new Wool(dc).toItemStack(1);
    ItemMeta im = i.getItemMeta();
    im.setDisplayName(name);
    i.setItemMeta(im);
    return i;
}
 
Example #6
Source File: StackLogic.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean doSheepShearAll(Sheep sheared, ItemStack tool) {
    int stackSize = StackTools.getSize(sheared);
    if(sm.getCustomConfig().getBoolean("multiply.sheep-wool") && ItemTools.hasEnoughDurability(tool, stackSize)){
        LootContext lootContext = new LootContext.Builder(sheared.getLocation()).lootedEntity(sheared).build();
        Collection<ItemStack> loot = sheared.getLootTable().populateLoot(ThreadLocalRandom.current(), lootContext);
        for(ItemStack itemStack : loot){
            if(itemStack.getData() instanceof Wool) {
                sm.getDropTools().dropDrops(itemStack, sm.getDropTools().calculateAmount(stackSize), sheared.getLocation());
            }
        }
        return true;
    }
    return false;
}
 
Example #7
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
private void onLobbyInventoryClick(InventoryClickEvent ice, Player player, Game game) {
  Inventory inv = ice.getInventory();
  ItemStack clickedStack = ice.getCurrentItem();

  if (!inv.getTitle().equals(BedwarsRel._l(player, "lobby.chooseteam"))) {
    ice.setCancelled(true);
    return;
  }

  if (clickedStack == null) {
    ice.setCancelled(true);
    return;
  }

  if (clickedStack.getType() != Material.WOOL) {
    ice.setCancelled(true);
    return;
  }

  ice.setCancelled(true);
  Wool wool = (Wool) clickedStack.getData();
  Team team = game.getTeamByDyeColor(wool.getColor());
  if (team == null) {
    return;
  }

  game.playerJoinTeam(player, team);
  player.closeInventory();
}
 
Example #8
Source File: WoolObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onWoolPickup(InventoryClickEvent event) {
    Player player = (Player) event.getWhoClicked();
    if (!this.complete && GameHandler.getGameHandler().getMatch().isRunning()) {
        try {
            if (event.getCurrentItem().getType().equals(Material.WOOL) && ((Wool) event.getCurrentItem().getData()).getColor().equals(color)) {
                if (Teams.getTeamByPlayer(player).orNull() == team) {
                    boolean touchMessage = false;
                    if (!this.playersTouched.contains(player.getUniqueId())) {
                        this.playersTouched.add(player.getUniqueId());
                        if (this.show && !this.complete) {
                            Teams.getTeamChannel(Optional.of(team)).sendLocalizedMessage(new UnlocalizedChatMessage(ChatColor.WHITE + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_PICKED_FOR, team.getColor() + player.getName() + ChatColor.WHITE, MiscUtil.convertDyeColorToChatColor(color) + name.toUpperCase().replaceAll("_", " ") + ChatColor.WHITE, team.getCompleteName() + ChatColor.WHITE)));
                            for (Player player1 : Bukkit.getOnlinePlayers()) {
                                if (Teams.getTeamByPlayer(player1).isPresent() && Teams.getTeamByPlayer(player1).get().isObserver()) {
                                    player1.sendMessage(new UnlocalizedChatMessage(ChatColor.GRAY + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_PICKED_FOR, team.getColor() + player.getName() + ChatColor.GRAY, MiscUtil.convertDyeColorToChatColor(color) + name.toUpperCase().replaceAll("_", " ") + ChatColor.GRAY, team.getCompleteName() + ChatColor.GRAY)).getMessage(player1.getLocale()));
                                }
                            }
                            touchMessage = true;
                        }
                    }
                    if (!touched) touched = true;
                    ObjectiveTouchEvent touchEvent = new ObjectiveTouchEvent(this, player, touchMessage);
                    Bukkit.getServer().getPluginManager().callEvent(touchEvent);
                }
            }
        } catch (NullPointerException e) {
        }
    }
}
 
Example #9
Source File: WoolObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onWoolPickup(PlayerPickupItemEvent event) {
    Player player = event.getPlayer();
    if (!this.complete && GameHandler.getGameHandler().getMatch().isRunning()) {
        try {
            if (event.getItem().getItemStack().getType() == Material.WOOL && ((Wool) event.getItem().getItemStack().getData()).getColor().equals(color)) {
                if (Teams.getTeamByPlayer(player).orNull() == team) {
                    boolean touchMessage = false;
                    if (!this.playersTouched.contains(player.getUniqueId())) {
                        this.playersTouched.add(player.getUniqueId());
                        if (this.show && !this.complete) {
                            Teams.getTeamChannel(Optional.of(team)).sendLocalizedMessage(new UnlocalizedChatMessage(ChatColor.WHITE + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_PICKED, team.getColor() + player.getName() + ChatColor.WHITE, MiscUtil.convertDyeColorToChatColor(color) + name.toUpperCase().replaceAll("_", " ") + ChatColor.WHITE, team.getCompleteName() + ChatColor.WHITE)));
                            for (Player player1 : Bukkit.getOnlinePlayers()) {
                                if (Teams.getTeamByPlayer(player1).isPresent() && Teams.getTeamByPlayer(player1).get().isObserver()) {
                                    player1.sendMessage(new UnlocalizedChatMessage(ChatColor.GRAY + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_PICKED_FOR, team.getColor() + player.getName() + ChatColor.GRAY, MiscUtil.convertDyeColorToChatColor(color) + name.toUpperCase().replaceAll("_", " ") + ChatColor.GRAY, team.getCompleteName() + ChatColor.GRAY)).getMessage(player1.getLocale()));
                                }
                            }
                            touchMessage = true;
                        }
                    }
                    if (!touched) touched = true;
                    ObjectiveTouchEvent touchEvent = new ObjectiveTouchEvent(this, player, touchMessage);
                    Bukkit.getServer().getPluginManager().callEvent(touchEvent);
                }
            }
        } catch (NullPointerException e) {
        }
    }
}
 
Example #10
Source File: WoolObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
    if (event.getBlock().equals(place.getBlock())) {
        if (event.getBlock().getType().equals(Material.WOOL)) {
            if (((Wool) event.getBlock().getState().getData()).getColor().equals(color)) {
                if (Teams.getTeamByPlayer(event.getPlayer()).orNull() == team) {
                    this.complete = true;
                    if (this.show)
                        ChatUtil.getGlobalChannel().sendLocalizedMessage(new UnlocalizedChatMessage(ChatColor.WHITE + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_PLACED, team.getColor() + event.getPlayer().getName() + ChatColor.WHITE, team.getCompleteName() + ChatColor.WHITE, MiscUtil.convertDyeColorToChatColor(color) + name.toUpperCase().replaceAll("_", " ") + ChatColor.WHITE)));
                    Fireworks.spawnFireworks(place.getCenterBlock().getAlignedVector(), 3, 6, MiscUtil.convertChatColorToColor(MiscUtil.convertDyeColorToChatColor(color)), 1);
                    ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, event.getPlayer());
                    Bukkit.getServer().getPluginManager().callEvent(compEvent);
                    event.setCancelled(false);
                } else {
                    event.setCancelled(true);
                    if (this.show)
                        ChatUtil.sendWarningMessage(event.getPlayer(), "You may not complete the other team's objective.");
                }
            } else {
                event.setCancelled(true);
                if (this.show)
                    ChatUtil.sendWarningMessage(event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_BLOCK_PLACE, MiscUtil.convertDyeColorToChatColor(color) + color.name().toUpperCase().replaceAll("_", " ") + " WOOL" + ChatColor.RED));
            }
        } else {
            event.setCancelled(true);
            if (this.show)
                ChatUtil.sendWarningMessage(event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_BLOCK_PLACE, MiscUtil.convertDyeColorToChatColor(color) + color.name().toUpperCase().replaceAll("_", " ") + " WOOL" + ChatColor.RED));
        }
    }
}
 
Example #11
Source File: WoolObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onCraftWool(CraftItemEvent event) {
    if (!this.craftable && event.getRecipe().getResult().getType().equals(Material.WOOL)
            && ((Wool) event.getRecipe().getResult().getData()).getColor().equals(color)) {
        event.setCancelled(true);
    }
}
 
Example #12
Source File: Snowflakes.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onItemDespawnInVoid(EntityDespawnInVoidEvent event) {
    if (!(event.getEntity() instanceof Item) || !event.getEntity().hasMetadata(ITEM_THROWER_META)) return;
    Player player = Bukkit.getPlayer((UUID) event.getEntity().getMetadata(ITEM_THROWER_META).get(0).value());
    Item item = (Item) event.getEntity();
    if (testDestroy(player, item.getItemStack())) {
        addDestroyed(player, ((Wool) item.getItemStack().getData()).getColor());
    }
}
 
Example #13
Source File: VillagerShop.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack getSubTypeItem() {
	return new Wool(this.getProfessionWoolColor()).toItemStack(1);
}
 
Example #14
Source File: MonumentWoolFactory.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean isObjectiveWool(MaterialData material) {
  return material instanceof Wool && ((Wool) material).getColor() == this.color;
}
 
Example #15
Source File: Snowflakes.java    From CardinalPGM with MIT License 4 votes vote down vote up
private List<DyeColor> getColors(Collection<ItemStack> items) {
    return items.stream().filter(item -> item != null && item.getType().equals(Material.WOOL))
            .map(item -> ((Wool) item.getData()).getColor()).distinct().collect(Collectors.toList());
}
 
Example #16
Source File: Snowflakes.java    From CardinalPGM with MIT License 4 votes vote down vote up
private boolean testDestroy(Player player, ItemStack item) {
    return item.getType().equals(Material.WOOL) && testDestroy(player, ((Wool) item.getData()).getColor());
}
 
Example #17
Source File: PlayerStorage.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
public void openTeamSelection(Game game) {
  BedwarsOpenTeamSelectionEvent openEvent = new BedwarsOpenTeamSelectionEvent(game, this.player);
  BedwarsRel.getInstance().getServer().getPluginManager().callEvent(openEvent);

  if (openEvent.isCancelled()) {
    return;
  }

  HashMap<String, Team> teams = game.getTeams();

  int nom = (teams.size() % 9 == 0) ? 9 : (teams.size() % 9);
  Inventory inv =
      Bukkit.createInventory(this.player, teams.size() + (9 - nom),
          BedwarsRel._l(this.player, "lobby.chooseteam"));
  for (Team team : teams.values()) {
    List<Player> players = team.getPlayers();
    if (players.size() >= team.getMaxPlayers()) {
      continue;
    }
    Wool wool = new Wool(team.getColor().getDyeColor());
    ItemStack is = wool.toItemStack(1);
    ItemMeta im = is.getItemMeta();

    im.setDisplayName(team.getChatColor() + team.getName());
    ArrayList<String> teamplayers = new ArrayList<>();

    int teamPlayerSize = team.getPlayers().size();
    int maxPlayers = team.getMaxPlayers();

    String current = "0";
    if (teamPlayerSize >= maxPlayers) {
      current = ChatColor.RED + String.valueOf(teamPlayerSize);
    } else {
      current = ChatColor.YELLOW + String.valueOf(teamPlayerSize);
    }

    teamplayers.add(ChatColor.GRAY + "(" + current + ChatColor.GRAY + "/" + ChatColor.YELLOW
        + String.valueOf(maxPlayers) + ChatColor.GRAY + ")");
    teamplayers.add(ChatColor.WHITE + "---------");

    for (Player teamPlayer : players) {
      teamplayers.add(team.getChatColor() + ChatColor.stripColor(teamPlayer.getDisplayName()));
    }

    im.setLore(teamplayers);
    is.setItemMeta(im);
    inv.addItem(is);
  }

  this.player.openInventory(inv);
}
 
Example #18
Source File: MonumentWoolFactory.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean isObjectiveWool(MaterialData material) {
    return material instanceof Wool && ((Wool) material).getColor() == this.color;
}