@Override public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding) { GlowBanner banner = (GlowBanner) block.getState(); banner.setBase(DyeColor.getByDyeData((byte) holding.getDurability())); BannerMeta meta = (BannerMeta) holding.getItemMeta(); banner.setPattern(meta.getPattern()); banner.update(); }
@Override public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) { GlowBanner state = (GlowBanner) block.getState(); ItemStack drop = new ItemStack(Material.BANNER, 1); BannerMeta meta = (BannerMeta) drop.getItemMeta(); meta.setPattern(state.getPattern()); drop.setItemMeta(meta); drop.setDurability(state.getBase().getDyeData()); return Arrays.asList(drop); }
@EventHandler public void playerInteract(PlayerInteractEvent event) { if (event.isCancelled()) { return; } Player player = event.getPlayer(); if (player.hasPermission(BannerEditorCommand.PERMISSION) && player.getItemInHand().getType().equals(Material.STICK)) { BlockState state = event.getClickedBlock().getState(); if (state instanceof Banner) { Banner banner = (Banner) state; BannerEditorConfig config = BannerEditorCommand.getPlayerConfig(event.getPlayer()); BannerEditorMode mode = config.getEditorMode(); int patternId = config.getPatternId(); switch (mode) { case LIST: sendBannerInfoMessage(player, banner); break; case TEXTURE: if (patternId > 0 && patternId <= banner.numberOfPatterns()) { banner.setPattern( patternId - 1, new Pattern( banner.getPattern(patternId - 1).getColor(), (PatternType) cycle(banner.getPattern(patternId - 1).getPattern(), event.getAction()))); banner.update(true, false); } else if (patternId == 0) { sendNoPattern(player); } else { sendInvalidPatternId(player, patternId); } break; case COLOR: if (patternId > 0 && patternId <= banner.numberOfPatterns()) { banner.setPattern( patternId - 1, new Pattern( (DyeColor) cycle(banner.getPattern(patternId - 1).getColor(), event.getAction()), banner.getPattern(patternId - 1).getPattern())); banner.update(true, false); } else if (patternId == 0) { banner.setBaseColor((DyeColor) cycle(banner.getBaseColor(), event.getAction())); banner.update(true, false); } else { sendInvalidPatternId(player, patternId); } break; case ADD: banner.addPattern(new Pattern(DyeColor.WHITE, PatternType.CIRCLE_MIDDLE)); banner.update(true, false); break; case REMOVE: if (patternId > 0 && patternId <= banner.numberOfPatterns()) { Pattern pat = banner.removePattern(patternId - 1); banner.update(true, false); } else if (patternId == 0) { sendBaseNoPattern(player); } else { sendInvalidPatternId(player, patternId); } break; case GET: ItemStack item = new ItemStack(Material.BANNER); BannerMeta meta = (BannerMeta) item.getItemMeta(); meta.setBaseColor(banner.getBaseColor()); for (Pattern pattern : banner.getPatterns()) { meta.addPattern(pattern); } item.setItemMeta(meta); int amount = item.getMaxStackSize(); item.setAmount(amount); player.getInventory().addItem(item); sendGotBanner(player, amount); } event.setCancelled(true); } } }