org.bukkit.block.Banner Java Examples

The following examples show how to use org.bukkit.block.Banner. 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: Banners.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public static boolean placeStanding(Location location, BannerMeta meta) {
    Block block = location.getBlock();
    block.setType(Material.STANDING_BANNER, false);

    final BlockState state = block.getState();
    if(state instanceof Banner) {
        Banner banner = (Banner) block.getState();
        applyToBlock(banner, meta);

        org.bukkit.material.Banner material = (org.bukkit.material.Banner) banner.getData();
        material.setFacingDirection(BlockFaces.yawToFace(location.getYaw()));
        banner.setData(material);
        banner.update(true);
        return true;
    }
    return false;
}
 
Example #2
Source File: Materials.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
static void placeStanding(Location location, BannerMeta meta) {
  Block block = location.getBlock();
  block.setType(Material.STANDING_BANNER);

  Banner banner = (Banner) block.getState();
  applyToBlock(banner, meta);

  org.bukkit.material.Banner material = (org.bukkit.material.Banner) banner.getData();
  material.setFacingDirection(BlockFaces.yawToFace(location.getYaw()));
  banner.setData(material);
  banner.update(true);
}
 
Example #3
Source File: BannerBlock.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
public boolean set(Block block) {
    Banner banner = (Banner) block.getState();
    banner.setBaseColor(bannerBaseColor);
    banner.setPatterns(bannerPattern);
    banner.update(true, false);
    return true;
}
 
Example #4
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Turns a banner into banner meta
 *
 * @param banner banner block
 * @return banner meta
 */
public static BannerMeta getBannerMeta(Banner banner) {
	if(ConfigManager.getServerVersion().isOlderThan(ConfigManager.ServerVersion.MINECRAFT_1_8_R2)) {
		return null;
	}

	BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(CompatibilityUtils.Mat.WHITE_BANNER.get());

	meta.setBaseColor(banner.getBaseColor());
	for(Pattern pattern : banner.getPatterns()) {
		meta.addPattern(pattern);
	}

	return meta;
}
 
Example #5
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies meta to a shield
 *
 * @param itemStack  shield item
 * @param bannerMeta banner meta
 * @return shield item
 */
public static ItemStack applyMeta(ItemStack itemStack, BannerMeta bannerMeta) {
	if(itemStack.getType() != Material.SHIELD && itemStack.getType() != CompatibilityUtils.Mat.WHITE_BANNER.get()) {
		throw new IllegalArgumentException("Passed ItemStack is not a shield nor a banner");
	}

	ItemMeta meta = itemStack.getItemMeta();
	BlockStateMeta blockStateMeta = (BlockStateMeta) meta;
	Banner banner = (Banner) blockStateMeta.getBlockState();
	applyMeta(banner, bannerMeta);
	banner.update();
	blockStateMeta.setBlockState(banner);
	itemStack.setItemMeta(blockStateMeta);
	return itemStack;
}
 
Example #6
Source File: Flags.java    From CardinalPGM with MIT License 4 votes vote down vote up
public static void setBannerFacing(BlockFace face, Banner banner) {
    org.bukkit.material.Banner data = (org.bukkit.material.Banner) banner.getMaterialData();
    data.setFacingDirection(face);
    banner.setMaterialData(data);
    banner.update();
}
 
Example #7
Source File: Materials.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static BannerMeta getItemMeta(Banner block) {
  BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(Material.BANNER);
  meta.setBaseColor(block.getBaseColor());
  meta.setPatterns(block.getPatterns());
  return meta;
}
 
Example #8
Source File: FlagObjective.java    From CardinalPGM with MIT License 4 votes vote down vote up
private void spawnFlag() {
    if (!isOnPost()) {
        setLastValidBlock();
        if (currentFlagBlock == null) {
            armorStand.remove();
            currentFlagBlock = nextSpawn();
            state = FlagState.WAITING_TO_RESPAWN;
            respawnTime = getPost().getRespawnTime(picker.getLocation(), currentFlagBlock.getLocation());
            resetPlayer();
            updateFlags();
            return;
        }
    }
    currentFlagBlock.setType(banner.getMaterial());
    currentFlagBlock = currentFlagBlock.getLocation().getBlock();
    Banner newBanner = (Banner)currentFlagBlock.getState();
    newBanner.setPatterns(banner.getPatterns());
    newBanner.setBaseColor(banner.getBaseColor());
    armorStand = createArmorStand();
    if (!isOnPost()) {
        if (currentFlagBlock.getRelative(BlockFace.DOWN).getType().equals(Material.STATIONARY_WATER)) {
            currentFlagBlock.getRelative(BlockFace.DOWN).setType(Material.ICE);
            state = FlagState.DROPPED_ON_WATER;
        } else {
            state = FlagState.DROPPED;
        }
        Flags.setBannerFacing(Flags.yawToFace(picker.getLocation().getYaw()), newBanner);
        FlagDropEvent event = new FlagDropEvent(getPicker(), this);
        Bukkit.getPluginManager().callEvent(event);
    } else {
        Flags.setBannerFacing(getPost().getYaw(), newBanner);
    }
    Player oldPicker = picker;
    this.lastNet = null;
    resetPlayer();
    for (Player player : Bukkit.getOnlinePlayers()) {
        if (oldPicker != null && player.equals(oldPicker)) continue;
        getPost().tryPickupFlag(player, player.getLocation(), null, this);
        if (picker != null) break;
    }
}
 
Example #9
Source File: FlagBuilder.java    From CardinalPGM with MIT License 4 votes vote down vote up
private ModuleCollection<? extends Module> getFlag(Element... elements) {
    ModuleCollection<Module> result =  new ModuleCollection<>();
    String id = elements[0].getAttributeValue("id");
    boolean required = Numbers.parseBoolean(Parser.getOrderedAttribute("required", elements), true);
    String name = elements[0].getAttributeValue("name");
    boolean show = Numbers.parseBoolean(Parser.getOrderedAttribute("show", elements), true);
    Post post = Flags.getPostById(Parser.getOrderedAttribute("post", elements));
    if (post == null) post = PostBuilder.parsePostElement(elements[0].getChild("post"));
    result.add(post);
    Set<Net> nets = new HashSet<>();
    if (elements[0].getChildren("net").size() > 0) {
        for (Element netEl : elements[0].getChildren("net")) {
            Net net = NetBuilder.parseNet(Parser.addElement(netEl, elements));
            nets.add(net);
            result.add(net);
        }
    }
    TeamModule owner = Parser.getOrderedAttribute("owner", elements) == null ? null : Teams.getTeamById(Parser.getOrderedAttribute("owner", elements)).orNull();
    boolean shared = Numbers.parseBoolean(Parser.getOrderedAttribute("shared", elements), false);
    DyeColor color = Parser.getOrderedAttribute("color", elements) == null ? ((Banner)post.getInitialBlock().getState()).getBaseColor() : Parser.parseDyeColor(Parser.getOrderedAttribute("color", elements));
    ChatColor chatColor = MiscUtil.convertBannerColorToChatColor(color);
    String carryMessage = ChatColor.AQUA + "" + ChatColor.BOLD + "You are carrying " + chatColor + ChatColor.BOLD + name;
    if (Parser.getOrderedAttributeOrChild("carry-message", elements) != null) carryMessage = ChatColor.translateAlternateColorCodes('`', Parser.getOrderedAttributeOrChild("carry-message", elements));
    int points = Numbers.parseInt(Parser.getOrderedAttribute("points", elements), 0);
    int pointsRate = Numbers.parseInt(Parser.getOrderedAttribute("points-rate", elements), 0);
    FilterModule pickupFilter = FilterModuleBuilder.getAttributeOrChild("pickup-filter", post.getPickupFilter(), elements);
    FilterModule dropFilter = FilterModuleBuilder.getAttributeOrChild("drop-filter", "always", elements);
    FilterModule captureFilter = FilterModuleBuilder.getAttributeOrChild("capture-filter", nets.size() > 0 ? nets.iterator().next().getCaptureFilter() : FilterModuleBuilder.getFilter("always"), elements);
    KitNode pickupKit = getKitOrChild("pickup-kit", result, elements);
    KitNode dropKit = getKitOrChild("drop-kit", result, elements);
    KitNode carryKit = getKitOrChild("carry-kit", result, elements);
    boolean dropOnWater = Numbers.parseBoolean(Parser.getOrderedAttribute("drop-on-water", elements), true);
    boolean beam = Numbers.parseBoolean(Parser.getOrderedAttribute("beam", elements), true);

    String flagProximityMetric = Parser.getOrderedAttribute("flagproximity-metric", elements);
    Boolean flagProximityHorizontal = Numbers.parseBoolean(Parser.getOrderedAttribute("flagproximity-horizontal", elements), false);
    ProximityInfo flagProximityInfo = new ProximityInfo(post.getInitialBlock().getLocation().toVector(), flagProximityHorizontal, false,
        flagProximityMetric == null ? GameObjectiveProximityHandler.ProximityMetric.CLOSEST_KILL : GameObjectiveProximityHandler.ProximityMetric.getByName(flagProximityMetric));

    String netProximityMetric = Parser.getOrderedAttribute("netproximity-metric", elements);
    Boolean netProximityHorizontal = Numbers.parseBoolean(Parser.getOrderedAttribute("netproximity-horizontal", elements), false);
    ProximityInfo netProximityInfo = new ProximityInfo(null, netProximityHorizontal, true,
            netProximityMetric == null ? GameObjectiveProximityHandler.ProximityMetric.CLOSEST_PLAYER : GameObjectiveProximityHandler.ProximityMetric.getByName(netProximityMetric));

    Map<String, GameObjectiveProximityHandler> flagProximityHandlers = new HashMap<>();
    Map<String, GameObjectiveProximityHandler> netProximityHandlers = new HashMap<>();
    for (TeamModule offender : Teams.getTeams()) {
        if (offender.isObserver() || offender == owner || !pickupFilter.evaluate(offender).equals(FilterState.ALLOW)) continue;
        GameObjectiveProximityHandler flagProximityHandler = new GameObjectiveProximityHandler(offender, flagProximityInfo);
        GameObjectiveProximityHandler netProximityHandler = new GameObjectiveProximityHandler(offender, netProximityInfo);
        flagProximityHandlers.put(offender.getId(), flagProximityHandler);
        netProximityHandlers.put(offender.getId(), netProximityHandler);
        result.add(flagProximityHandler);
        result.add(netProximityHandler);
    }
    result.add(new FlagObjective(id, required, name, color, chatColor, show, post, owner, shared, carryMessage, points, pointsRate, pickupFilter, dropFilter, captureFilter, pickupKit, dropKit, carryKit, dropOnWater, beam, nets, flagProximityHandlers, netProximityHandlers));

    return result;
}
 
Example #10
Source File: ItemBuilder.java    From Crazy-Crates with MIT License 4 votes vote down vote up
/**
 * Builder the item from all the information that was given to the builder.
 * @return The result of all the info that was given to the builder as an ItemStack.
 */
public ItemStack build() {
    if (nbtItem != null) {
        referenceItem = nbtItem.getItem();
    }
    ItemStack item = referenceItem != null ? referenceItem : new ItemStack(material);
    if (item.getType() != Material.AIR) {
        if (isHead) {//Has to go 1st due to it removing all data when finished.
            if (isHash) {//Sauce: https://github.com/deanveloper/SkullCreator
                if (isURL) {
                    SkullCreator.itemWithUrl(item, player);
                } else {
                    SkullCreator.itemWithBase64(item, player);
                }
            }
        }
        item.setAmount(amount);
        ItemMeta itemMeta = item.getItemMeta();
        itemMeta.setDisplayName(getUpdatedName());
        itemMeta.setLore(getUpdatedLore());
        if (version.isSame(Version.v1_8_R3)) {
            if (isHead && !isHash && player != null && !player.equals("")) {
                SkullMeta skullMeta = (SkullMeta) itemMeta;
                skullMeta.setOwner(player);
            }
        }
        if (version.isNewer(Version.v1_10_R1)) {
            itemMeta.setUnbreakable(unbreakable);
        }
        if (version.isNewer(Version.v1_12_R1)) {
            if (itemMeta instanceof org.bukkit.inventory.meta.Damageable) {
                ((org.bukkit.inventory.meta.Damageable) itemMeta).setDamage(damage);
            }
        } else {
            item.setDurability((short) damage);
        }
        if (isPotion && (potionType != null || potionColor != null)) {
            PotionMeta potionMeta = (PotionMeta) itemMeta;
            if (potionType != null) {
                potionMeta.setBasePotionData(new PotionData(potionType));
            }
            if (potionColor != null) {
                potionMeta.setColor(potionColor);
            }
        }
        if (isLeatherArmor && armorColor != null) {
            LeatherArmorMeta leatherMeta = (LeatherArmorMeta) itemMeta;
            leatherMeta.setColor(armorColor);
        }
        if (isBanner && !patterns.isEmpty()) {
            BannerMeta bannerMeta = (BannerMeta) itemMeta;
            bannerMeta.setPatterns(patterns);
        }
        if (isShield && !patterns.isEmpty()) {
            BlockStateMeta shieldMeta = (BlockStateMeta) itemMeta;
            Banner banner = (Banner) shieldMeta.getBlockState();
            banner.setPatterns(patterns);
            banner.update();
            shieldMeta.setBlockState(banner);
        }
        if (useCustomModelData) {
            itemMeta.setCustomModelData(customModelData);
        }
        itemFlags.forEach(itemMeta :: addItemFlags);
        item.setItemMeta(itemMeta);
        hideFlags(item);
        item.addUnsafeEnchantments(enchantments);
        addGlow(item);
        NBTItem nbt = new NBTItem(item);
        if (isHead) {
            if (!isHash && player != null && !player.equals("") && version.isNewer(Version.v1_8_R3)) {
                nbt.setString("SkullOwner", player);
            }
        }
        if (isMobEgg) {
            if (entityType != null) {
                nbt.addCompound("EntityTag").setString("id", "minecraft:" + entityType.name());
            }
        }
        if (version.isOlder(Version.v1_11_R1)) {
            if (unbreakable) {
                nbt.setBoolean("Unbreakable", true);
                nbt.setInteger("HideFlags", 4);
            }
        }
        if (!crateName.isEmpty()) {
            nbt.setString("CrazyCrates-Crate", crateName);
        }
        return nbt.getItem();
    } else {
        return item;
    }
}
 
Example #11
Source File: Banners.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Location getLocationWithYaw(Banner block) {
    Location location = block.getLocation();
    location.setYaw(BlockFaces.faceToYaw(((org.bukkit.material.Banner) block.getData()).getFacing()));
    return location;
}
 
Example #12
Source File: Banners.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void applyToBlock(Banner block, BannerMeta meta) {
    block.setBaseColor(meta.getBaseColor());
    block.setPatterns(meta.getPatterns());
}
 
Example #13
Source File: Banners.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static BannerMeta getItemMeta(Banner block) {
    BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(Material.BANNER);
    meta.setBaseColor(block.getBaseColor());
    meta.setPatterns(block.getPatterns());
    return meta;
}
 
Example #14
Source File: Flag.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
private static Banner toBanner(Block block) {
    if(block == null) return null;
    BlockState state = block.getState();
    return state instanceof Banner ? (Banner) state : null;
}
 
Example #15
Source File: Flag.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Flag(Match match, FlagDefinition definition, ImmutableSet<Net> nets) throws ModuleLoadException {
    super(definition, match);
    this.nets = nets;

    final TeamMatchModule tmm = match.getMatchModule(TeamMatchModule.class);

    this.owner = definition.owner()
                           .map(def -> tmm.team(def)) // Do not use a method ref here, it will NPE if tmm is null
                           .orElse(null);

    this.capturers = Lazy.from(
        () -> Optionals.stream(match.module(TeamMatchModule.class))
                       .flatMap(TeamMatchModule::teams)
                       .filter(team -> getDefinition().canPickup(team) && canCapture(team))
                       .collect(Collectors.toSet())
    );

    this.controllers = Lazy.from(
        () -> nets.stream()
                  .flatMap(net -> Optionals.stream(net.returnPost()
                                                      .flatMap(Post::owner)))
                  .map(def -> tmm.team(def))
                  .collect(Collectors.toSet())
    );

    this.completers = Lazy.from(
        () -> nets.stream()
                  .flatMap(net -> Optionals.stream(net.returnPost()))
                  .filter(Post::isPermanent)
                  .flatMap(post -> Optionals.stream(post.owner()))
                  .map(def -> tmm.team(def))
                  .collect(Collectors.toSet())
    );

    Banner banner = null;
    pointLoop: for(PointProvider returnPoint : definition.getDefaultPost().getReturnPoints()) {
        Region region = returnPoint.getRegion();
        if(region instanceof PointRegion) {
            // Do not require PointRegions to be at the exact center of the block.
            // It might make sense to just override PointRegion.getBlockVectors() to
            // always do this, but it does technically violate the contract of that method.
            banner = toBanner(((PointRegion) region).getPosition().toLocation(match.getWorld()).getBlock());
            if(banner != null) break pointLoop;
        } else {
            for(BlockVector pos : returnPoint.getRegion().getBlockVectors()) {
                banner = toBanner(pos.toLocation(match.getWorld()).getBlock());
                if(banner != null) break pointLoop;
            }
        }
    }

    if(banner == null) {
        throw new ModuleLoadException("Flag '" + getName() + "' must have a banner at its default post");
    }

    final Location location = Banners.getLocationWithYaw(banner);
    bannerInfo = new BannerInfo(location,
                                Banners.getItemMeta(banner),
                                new ItemStack(Material.BANNER),
                                new StaticAngleProvider(location.getYaw()));
    bannerInfo.item.setItemMeta(bannerInfo.meta);

    match.registerEvents(this);

    this.state = new Returned(this, this.getDefinition().getDefaultPost(), bannerInfo.location);
    this.state.enterState();
}
 
Example #16
Source File: Flag.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
private static Banner toBanner(Block block) {
  if (block == null) return null;
  BlockState state = block.getState();
  return state instanceof Banner ? (Banner) state : null;
}
 
Example #17
Source File: Flag.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Flag(Match match, FlagDefinition definition, ImmutableSet<Net> nets)
    throws ModuleLoadException {
  super(definition, match);
  this.nets = nets;

  TeamMatchModule tmm = match.getModule(TeamMatchModule.class);

  if (definition.getOwner() != null) {
    this.owner = tmm.getTeam(definition.getOwner());
  } else {
    this.owner = null;
  }

  ImmutableSet.Builder<Team> capturersBuilder = ImmutableSet.builder();
  if (tmm != null) {
    for (Team team : tmm.getTeams()) {
      Query query = team.getQuery();
      if (getDefinition().canPickup(query) && canCapture(query)) {
        capturersBuilder.add(team);
      }
    }
  }
  this.capturers = capturersBuilder.build();

  ImmutableSet.Builder<Team> controllersBuilder = ImmutableSet.builder();
  ImmutableSet.Builder<Team> completersBuilder = ImmutableSet.builder();
  for (Net net : nets) {
    if (net.getReturnPost() != null && net.getReturnPost().getOwner() != null) {
      Team controller = tmm.getTeam(net.getReturnPost().getOwner());
      controllersBuilder.add(controller);

      if (net.getReturnPost().isPermanent()) {
        completersBuilder.add(controller);
      }
    }
  }
  this.controllers = controllersBuilder.build();
  this.completers = completersBuilder.build();

  Banner banner = null;
  pointLoop:
  for (PointProvider returnPoint : definition.getDefaultPost().getReturnPoints()) {
    Region region = returnPoint.getRegion();
    if (region instanceof PointRegion) {
      // Do not require PointRegions to be at the exact center of the block.
      // It might make sense to just override PointRegion.getBlockVectors() to
      // always do this, but it does technically violate the contract of that method.
      banner =
          toBanner(((PointRegion) region).getPosition().toLocation(match.getWorld()).getBlock());
      if (banner != null) break pointLoop;
    } else {
      for (BlockVector pos : returnPoint.getRegion().getBlockVectors()) {
        banner = toBanner(pos.toLocation(match.getWorld()).getBlock());
        if (banner != null) break pointLoop;
      }
    }
  }

  if (banner == null) {
    throw new ModuleLoadException(
        "Flag '" + getName() + "' must have a banner at its default post");
  }

  this.bannerLocation = Materials.getLocationWithYaw(banner);
  this.bannerMeta = Materials.getItemMeta(banner);
  this.bannerYawProvider = new StaticAngleProvider(this.bannerLocation.getYaw());
  this.bannerItem = new ItemStack(Material.BANNER);
  this.bannerItem.setItemMeta(this.getBannerMeta());
}
 
Example #18
Source File: Materials.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static Location getLocationWithYaw(Banner block) {
  Location location = block.getLocation();
  location.setYaw(
      BlockFaces.faceToYaw(((org.bukkit.material.Banner) block.getData()).getFacing()));
  return location;
}
 
Example #19
Source File: Materials.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static void applyToBlock(Banner block, BannerMeta meta) {
  block.setBaseColor(meta.getBaseColor());
  block.setPatterns(meta.getPatterns());
}
 
Example #20
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Serializes banner into a string
 *
 * @param banner banner meta
 * @return serialized meta
 */
public static String serialize(Banner banner) {
	return getSerializer().serialize(getBannerMeta(banner));
}
 
Example #21
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Applies meta to a banner
 *
 * @param banner banner block
 * @param meta   banner meta
 * @return banner block
 */
public static Banner applyMeta(Banner banner, BannerMeta meta) {
	banner.setBaseColor(meta.getBaseColor());
	banner.setPatterns(meta.getPatterns());
	return banner;
}