org.bukkit.material.MaterialData Java Examples
The following examples show how to use
org.bukkit.material.MaterialData.
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: Renewable.java From ProjectAres with GNU Affero General Public License v3.0 | 7 votes |
boolean renew(BlockVector pos, MaterialData material) { // We need to do the entity check here rather than canRenew, because we are not // notified when entities move in our out of the way. if(!isClearOfEntities(pos)) return false; Location location = pos.toLocation(match.getWorld()); Block block = location.getBlock(); BlockState newState = location.getBlock().getState(); newState.setMaterialData(material); BlockRenewEvent event = new BlockRenewEvent(block, newState, this); match.callEvent(event); // Our own handler will get this and remove the block from the pool if(event.isCancelled()) return false; newState.update(true, true); if(definition.particles) { NMSHacks.playBlockBreakEffect(match.getWorld(), pos, material.getItemType()); } if(definition.sound) { NMSHacks.playBlockPlaceSound(match.getWorld(), pos, material.getItemType(), 1f); } return true; }
Example #2
Source File: CoreFactory.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
public CoreFactoryImpl(String name, @Nullable Boolean required, boolean visible, TeamFactory owner, ProximityMetric proximityMetric, Region region, MaterialData material, int leakLevel, boolean modeChanges) { super(name, required, visible, Optional.of(owner), proximityMetric); this.region = region; this.material = material; this.leakLevel = leakLevel; this.modeChanges = modeChanges; }
Example #3
Source File: Renewable.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
boolean renew(BlockVector pos) { MaterialData material; if(isOriginalShuffleable(pos)) { // If position is shuffled, first try to find a nearby shuffleable block to swap with. // This helps to make shuffling less predictable when the material deficit is small or // out of proportion to the original distribution of materials. material = sampleShuffledMaterial(pos); // If that fails, choose a random material, weighted by the current material deficits. if(material == null) material = chooseShuffledMaterial(); } else { material = snapshot().getOriginalMaterial(pos); } if(material != null) { return renew(pos, material); } return false; }
Example #4
Source File: Renewable.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
MaterialData sampleShuffledMaterial(BlockVector pos) { Random random = match.getRandom(); int range = SHUFFLE_SAMPLE_RANGE; int diameter = range * 2 + 1; for (int i = 0; i < SHUFFLE_SAMPLE_ITERATIONS; i++) { BlockState block = snapshot() .getOriginalBlock( pos.getBlockX() + random.nextInt(diameter) - range, pos.getBlockY() + random.nextInt(diameter) - range, pos.getBlockZ() + random.nextInt(diameter) - range); if (definition.shuffleableBlocks.query(new BlockQuery(block)).isAllowed()) return block.getMaterialData(); } return null; }
Example #5
Source File: LevelCalcByChunk.java From askyblock with GNU General Public License v2.0 | 6 votes |
private Collection<String> sortedReport(int total, Multiset<MaterialData> materialDataCount) { Collection<String> result = new ArrayList<>(); Iterable<Multiset.Entry<MaterialData>> entriesSortedByCount = Multisets.copyHighestCountFirst(materialDataCount).entrySet(); for (Entry<MaterialData> en : entriesSortedByCount) { MaterialData type = en.getElement(); int value = 0; if (Settings.blockValues.containsKey(type)) { // Specific value = Settings.blockValues.get(type); } else if (Settings.blockValues.containsKey(new MaterialData(type.getItemType()))) { // Generic value = Settings.blockValues.get(new MaterialData(type.getItemType())); } if (value > 0) { result.add(type.toString() + ":" + String.format("%,d", en.getCount()) + " blocks x " + value + " = " + (value * en.getCount())); total += (value * en.getCount()); } } result.add("Subtotal = " + total); result.add("=================================="); return result; }
Example #6
Source File: ExprColorOf.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecated") @Nullable private Colorable getColorable(Object colorable) { if (colorable instanceof Item || colorable instanceof ItemType) { ItemStack item = colorable instanceof Item ? ((Item) colorable).getItemStack() : ((ItemType) colorable).getRandom(); if (item == null) return null; MaterialData data = item.getData(); if (data instanceof Colorable) return (Colorable) data; } else if (colorable instanceof Block) { BlockState state = ((Block) colorable).getState(); if (state instanceof Colorable) return (Colorable) state; } else if (colorable instanceof Colorable) { return (Colorable) colorable; } return null; }
Example #7
Source File: Renewable.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
boolean renew(BlockVector pos, MaterialData material) { // We need to do the entity check here rather than canRenew, because we are not // notified when entities move in our out of the way. if (!isClearOfEntities(pos)) return false; Location location = pos.toLocation(match.getWorld()); Block block = location.getBlock(); BlockState newState = location.getBlock().getState(); newState.setMaterialData(material); BlockRenewEvent event = new BlockRenewEvent(block, newState, this); match.callEvent(event); // Our own handler will get this and remove the block from the pool if (event.isCancelled()) return false; newState.update(true, true); if (definition.particles || definition.sound) { Materials.playBreakEffect(location, material); } return true; }
Example #8
Source File: Destroyable.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
protected boolean isAffectedByBlockReplacementRules() { if (this.blockDropsRuleSet == null || this.blockDropsRuleSet.getRules().isEmpty()) { return false; } for (Block block : this.blockRegion.getBlocks()) { for (MaterialData material : this.materials) { BlockDrops drops = this.blockDropsRuleSet.getDrops(block.getState(), material); if (drops != null && drops.replacement != null && this.hasMaterial(drops.replacement)) { return true; } } } return false; }
Example #9
Source File: CraftingModuleBuilder.java From CardinalPGM with MIT License | 6 votes |
@Override public ModuleCollection<CraftingModule> load(Match match) { Set<AbstractRecipe> recipes = new HashSet<>(); Set<Material> disabledMaterials = new HashSet<>(); Set<MaterialData> disabledMaterialData = new HashSet<>(); for (Element crafting : match.getDocument().getRootElement().getChildren("crafting")) { for (Element shaped : crafting.getChildren("shaped")) recipes.add(addOverrides(getShapedRecipe(shaped), shaped)); for (Element shapeless : crafting.getChildren("shapeless")) recipes.add(addOverrides(getShapelessRecipe(shapeless), shapeless)); for (Element smelt : crafting.getChildren("smelt")) recipes.add(addOverrides(getSmeltRecipe(smelt), smelt)); for (Element disable : crafting.getChildren("disable")) { MaterialData data = Parser.parseMaterialData(disable.getText()); if ((data.getData() == -1)) disabledMaterials.add(data.getItemType()); else disabledMaterialData.add(data); } } for (AbstractRecipe recipe : recipes) { if (recipe.getOverride()) disabledMaterialData.add(recipe.getRecipe().getResult().getData()); if (recipe.getOverrideAll()) disabledMaterials.add(recipe.getRecipe().getResult().getType()); } return new ModuleCollection<>(new CraftingModule(recipes, disabledMaterials, disabledMaterialData)); }
Example #10
Source File: Destroyable.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
protected boolean isAffectedByBlockReplacementRules() { if (this.blockDropsRuleSet.getRules().isEmpty()) { return false; } for(Block block : this.blockRegion.getBlocks(match.getWorld())) { for(MaterialData material : this.materials) { BlockDrops drops = this.blockDropsRuleSet.getDrops(block.getState(), material); if(drops != null && drops.replacement != null && this.hasMaterial(drops.replacement)) { return true; } } } return false; }
Example #11
Source File: Parser.java From CardinalPGM with MIT License | 5 votes |
public static MaterialData parseMaterialData(String material) { String type = material.split(":")[0].trim(); byte damageValue = (byte) (material.contains(":") ? Numbers.parseInt(material.split(":")[1].trim()) : -1); return NumberUtils.isNumber(type) ? new MaterialData(Material.getMaterial(Integer.parseInt(type)), damageValue): new MaterialData(Material.matchMaterial(type), damageValue); }
Example #12
Source File: XMLUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static MaterialData parseMaterialData(Node node, String text) throws InvalidXMLException { String[] pieces = text.split(":"); Material material = parseMaterial(node, pieces[0]); byte data; if(pieces.length > 1) { data = parseNumber(node, pieces[1], Byte.class); } else { data = 0; } return material.getNewData(data); }
Example #13
Source File: Destroyable.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public void replaceBlocks(MaterialData newMaterial) { // Calling this method causes all non-destroyed blocks to be replaced, and the world // list to be replaced with one containing only the new block. If called on a multi-stage // destroyable, i.e. one which is affected by block replacement rules, it effectively ceases // to be multi-stage. Even if there are block replacement rules for the new block, the // replacements will not be in the world list, and so those blocks will be considered // destroyed the first time they are mined. This can have some strange effects on the health // of the destroyable: individual block health can only decrease, while the total health // percentage can only increase. for (Block block : this.getBlockRegion().getBlocks()) { BlockState oldState = block.getState(); int oldHealth = this.getBlockHealth(oldState); if (oldHealth > 0) { block.setTypeIdAndData(newMaterial.getItemTypeId(), newMaterial.getData(), true); } } // Update the world list on switch this.materialPatterns.clear(); this.materials.clear(); addMaterials(new SingleMaterialMatcher(newMaterial)); // If there is a block health map, get rid of it, since there is now only one world in the list this.blockMaterialHealth = null; this.recalculateHealth(); }
Example #14
Source File: FlagQueueLobby.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@Subscribe(priority = Subscribe.Priority.MONITOR) public void onQueueEnter(PlayerEnterQueueEvent event) { if (event.isCancelled()) { return; } Location teleportPoint = getValue(); SpleefPlayer player = event.getPlayer(); Player bukkitPlayer = player.getBukkitPlayer(); PlayerStateHolder holder = new PlayerStateHolder(); holder.setLocation(bukkitPlayer.getLocation()); holder.setGamemode(bukkitPlayer.getGameMode()); bukkitPlayer.setGameMode(GameMode.SURVIVAL); player.teleport(teleportPoint); holder.updateState(bukkitPlayer, false, holder.getGamemode()); player.savePlayerState(this, holder); boolean adventureMode = config.getGeneralSection().isAdventureMode(); PlayerStateHolder.applyDefaultState(bukkitPlayer, adventureMode); MaterialData data = config.getFlagSection().getLeaveItem(); if (data != null) { MetadatableItemStack stack = new MetadatableItemStack(data.toItemStack(1)); ItemMeta meta = stack.getItemMeta(); meta.setDisplayName(getI18N().getString(Messages.Player.LEAVE_QUEUE_DISPLAYNAME)); meta.setLore(Lists.newArrayList(getI18N().getString(Messages.Player.LEAVE_QUEUE_LORE))); stack.setItemMeta(meta); stack.setMetadata(LEAVE_ITEM_KEY, null); bukkitPlayer.getInventory().setItem(RIGHT_HOTBAR_SLOT, stack); bukkitPlayer.updateInventory(); } }
Example #15
Source File: XMLUtils.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public static MaterialData parseBlockMaterialData(Node node, String text) throws InvalidXMLException { if (node == null) return null; MaterialData material = parseMaterialData(node, text); if (!material.getItemType().isBlock()) { throw new InvalidXMLException( "Material " + material.getItemType().name() + " is not a block", node); } return material; }
Example #16
Source File: MaterialUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static MaterialData decodeMaterial(int encoded) { if(encoded == ENCODED_NULL_MATERIAL) return null; Material material = decodeType(encoded); if(material.getData() == MaterialData.class) { return new MaterialData(material, decodeMetadata(encoded)); } else { return material.getNewData(decodeMetadata(encoded)); } }
Example #17
Source File: BlockTransformListener.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private void callEvent(final BlockTransformEvent event, boolean checked) { if (!checked) { MaterialData oldData = event.getOldState().getMaterialData(); MaterialData newData = event.getNewState().getMaterialData(); if (oldData instanceof Door) { handleDoor(event, (Door) oldData); } if (newData instanceof Door) { handleDoor(event, (Door) newData); } } logger.fine("Generated event " + event); currentEvents.put(event.getCause(), event); }
Example #18
Source File: CustomItem.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
@Deprecated public CustomItem(MaterialData data, String name, String... lore) { super(data.toItemStack(1)); ItemMeta im = getItemMeta(); im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); List<String> lines = new ArrayList<String>(); for (String line: lore) { lines.add(ChatColor.translateAlternateColorCodes('&', line)); } im.setLore(lines); setItemMeta(im); }
Example #19
Source File: Destroyable.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
protected void buildMaterialHealthMap() { this.maxHealth = 0; this.health = 0; Set<MaterialData> visited = new HashSet<>(); try { for (Block block : blockRegion.getBlocks()) { Map<MaterialData, Integer> materialHealthMap = new HashMap<>(); int blockMaxHealth = 0; for (MaterialData material : this.materials) { visited.clear(); int blockHealth = this.buildBlockMaterialHealthMap(block, material, materialHealthMap, visited); if (blockHealth > blockMaxHealth) { blockMaxHealth = blockHealth; } } this.blockMaterialHealth.put( block.getLocation().toVector().toBlockVector(), materialHealthMap); this.maxHealth += blockMaxHealth; this.health += this.getBlockHealth(block.getState()); } } catch (Indestructible ex) { this.health = this.maxHealth = Integer.MAX_VALUE; PGM.get() .getLogger() .warning( "Destroyable " + this.getName() + " is indestructible due to block replacement cycle"); } }
Example #20
Source File: MaterialDataMatcher.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
public MaterialData result() { if (result == null) { throw new IllegalStateException("Must call match() first before calling result()"); } return result; }
Example #21
Source File: FlagLeaveItem.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
private void addLeaveItem(SpleefPlayer player) { MaterialData leaveItemData = config.getFlagSection().getLeaveItem(); MetadatableItemStack stack = new MetadatableItemStack(leaveItemData.toItemStack(1)); ItemMeta meta = stack.getItemMeta(); meta.setDisplayName(getI18N().getString(Messages.Player.LEAVE_GAME_DISPLAYNAME)); meta.setLore(Lists.newArrayList(getI18N().getString(Messages.Player.LEAVE_GAME_LORE))); stack.setItemMeta(meta); stack.setMetadata(LEAVE_ITEM_KEY, null); Player bukkitPlayer = player.getBukkitPlayer(); bukkitPlayer.getInventory().setItem(RIGHT_HOTBAR_SLOT, stack); bukkitPlayer.updateInventory(); }
Example #22
Source File: Destroyable.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
protected void buildMaterialHealthMap() { this.maxHealth = 0; this.health = 0; Set<MaterialData> visited = new HashSet<>(); try { for(Block block : blockRegion.getBlocks(match.getWorld())) { Map<MaterialData, Integer> materialHealthMap = new HashMap<>(); int blockMaxHealth = 0; for(MaterialData material : this.materials) { visited.clear(); int blockHealth = this.buildBlockMaterialHealthMap(block, material, materialHealthMap, visited); if(blockHealth > blockMaxHealth) { blockMaxHealth = blockHealth; } } this.blockMaterialHealth.put(block.getLocation().toVector().toBlockVector(), materialHealthMap); this.maxHealth += blockMaxHealth; this.health += this.getBlockHealth(block.getState()); } } catch(Indestructible ex) { this.health = this.maxHealth = Integer.MAX_VALUE; PGM.get().getLogger().warning("Destroyable " + this.getName() + " is indestructible due to block replacement cycle"); } }
Example #23
Source File: BlockAdapterMagicValues.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public void setFacing(Block block, BlockFace facing) { BlockState state = block.getState(); MaterialData data = state.getData(); if (!(data instanceof Directional)) { throw new IllegalArgumentException("Block is not Directional"); } ((Directional) data).setFacingDirection(facing); state.setData(data); state.update(); }
Example #24
Source File: ClassModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private static PlayerClass parseClass(Element classEl, KitParser kitParser, String family) throws InvalidXMLException { String name = classEl.getAttributeValue("name"); if (name == null) { throw new InvalidXMLException("class must have a name", classEl); } String description = classEl.getAttributeValue("description"); if (description != null) { description = BukkitUtils.colorize(description); } String longdescription = classEl.getAttributeValue("longdescription"); if (longdescription != null) { longdescription = BukkitUtils.colorize(longdescription); } boolean sticky = XMLUtils.parseBoolean(classEl.getAttribute("sticky"), false); ImmutableSet.Builder<Kit> kits = ImmutableSet.builder(); for (Element kitEl : classEl.getChildren("kit")) { Kit kit = kitParser.parse(kitEl); kits.add(kit); } MaterialData icon = XMLUtils.parseMaterialData(Node.fromAttr(classEl, "icon")); boolean restrict = XMLUtils.parseBoolean(classEl.getAttribute("restrict"), false); return new PlayerClass( name, family, description, longdescription, sticky, kits.build(), icon, restrict); }
Example #25
Source File: BlockAdapterMagicValues.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public BlockFace getFacing(Block block) { MaterialData data = block.getState().getData(); if (!(data instanceof Directional)) { throw new IllegalArgumentException("Block is not Directional"); } return ((Directional) data).getFacing(); }
Example #26
Source File: BlockQuery.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public MaterialData getMaterial() { if(material == null) { material = getBlock().getMaterialData(); } return material; }
Example #27
Source File: MaterialPattern.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static List<MaterialPattern> fromMaterialDatas(Collection<MaterialData> materials) { List<MaterialPattern> patterns = new ArrayList<>(materials.size()); for(MaterialData material : materials) { patterns.add(new MaterialPattern(material)); } return patterns; }
Example #28
Source File: CompoundMaterialMatcher.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean matches(MaterialData materialData) { for(MaterialMatcher child : children) { if(child.matches(materialData)) return true; } return false; }
Example #29
Source File: ItemStackImpl.java From Civs with GNU General Public License v3.0 | 5 votes |
public void setData(MaterialData data) { Material mat = Bukkit.getUnsafe().toLegacy(this.getType()); if (data != null && mat != null && mat.getData() != null) { if (data.getClass() != mat.getData() && data.getClass() != MaterialData.class) { throw new IllegalArgumentException("Provided data is not of type " + mat.getData().getName() + ", found " + data.getClass().getName()); } this.data = data; } else { this.data = data; } }
Example #30
Source File: Renewable.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
boolean isNew(BlockState currentState) { // If original block does not match renewable rule, block is new BlockVector pos = BlockUtils.position(currentState); if(!isOriginalRenewable(pos)) return true; // If original and current material are both shuffleable, block is new MaterialData currentMaterial = currentState.getMaterialData(); if(isOriginalShuffleable(pos) && definition.shuffleableBlocks.query(new BlockQuery(currentState)).isAllowed()) return true; // If current material matches original, block is new if(currentMaterial.equals(snapshot().getOriginalMaterial(pos))) return true; // Otherwise, block is not new (can be renewed) return false; }