下面列出了org.bukkit.Material#isBlock ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public <T extends ControllableEntityHandle<? extends LivingEntity>> T createEntityHandle(ControllableEntity entity, Location location) {
SafeConstructor<ControllableEntityHandle> entityConstructor = getConstructorFor(entity.getEntityType());
EntityRegistrationEntry oldEntry = GameRegistry.get(IEntityRegistry.class).getDefaultEntryFor(entity.getEntityType());
GameRegistry.get(IEntityRegistry.class).register(new EntityRegistrationEntry(
entity.getEntityType().getName(),
entity.getEntityType().getId(),
entity.getEntityType().getHandleClass()
));
WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
T handle = (T) entityConstructor.getAccessor().invoke(worldServer, entity);
handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
worldServer.addEntity((net.minecraft.server.v1_7_R1.Entity) handle, CreatureSpawnEvent.SpawnReason.CUSTOM);
GameRegistry.get(IEntityRegistry.class).register(oldEntry);
Material beneath = location.getBlock().getRelative(BlockFace.DOWN).getType();
if (beneath.isBlock()) { // What lies beneath
((Entity) handle).onGround = true;
}
return handle;
}
private void importBlocksBroken(PlayerInfo playerInfo, String worldName) {
Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);
if (!object.isPresent()) {
return;
}
Optional<JSONObject> minedSection = getMinedSection(playerInfo.getUUID(), worldName);
if (!minedSection.isPresent()) return;
for (Material material : Material.values()) {
if (material.isBlock()) {
long broken = (Long) getStatistic(minedSection.get(), material.getKey().toString()).orElse(0L);
if (broken <= 0) continue;
playerInfo.addRow(PlayerStat.BLOCKS_BROKEN,
StatzUtil.makeQuery(playerInfo.getUUID(), "value", broken, "world",
worldName, "block", material));
}
}
}
@Override
public <T extends ControllableEntityHandle<? extends LivingEntity>> T createEntityHandle(ControllableEntity entity, Location location) {
SafeConstructor<ControllableEntityHandle> entityConstructor = getConstructorFor(entity.getEntityType());
EntityRegistrationEntry oldEntry = GameRegistry.get(IEntityRegistry.class).getDefaultEntryFor(entity.getEntityType());
GameRegistry.get(IEntityRegistry.class).register(new EntityRegistrationEntry(
entity.getEntityType().getName(),
entity.getEntityType().getId(),
entity.getEntityType().getHandleClass()
));
WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
T handle = (T) entityConstructor.getAccessor().invoke(worldServer, entity);
handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
worldServer.addEntity((net.minecraft.server.v1_8_R1.Entity) handle, CreatureSpawnEvent.SpawnReason.CUSTOM);
GameRegistry.get(IEntityRegistry.class).register(oldEntry);
Material beneath = location.getBlock().getRelative(BlockFace.DOWN).getType();
if (beneath.isBlock()) { // What lies beneath
((Entity) handle).onGround = true;
}
return handle;
}
@Override
public <T extends ControllableEntityHandle<? extends LivingEntity>> T createHandle(ControllableEntity entity, Location location) {
SafeConstructor<ControllableEntityHandle> entityConstructor = new Reflection().reflect(entity.getEntityType().getHandleClass()).getSafeConstructor(World.class, entity.getEntityType().getControllableInterface());
EntityRegistrationEntry oldEntry = GameRegistry.get(IEntityRegistry.class).getDefaultEntryFor(entity.getEntityType());
GameRegistry.get(IEntityRegistry.class).register(new EntityRegistrationEntry(
entity.getEntityType().getName(),
entity.getEntityType().getId(),
entity.getEntityType().getHandleClass()
));
WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
T handle = (T) entityConstructor.getAccessor().invoke(worldServer, entity);
handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
worldServer.addEntity((net.minecraft.server.v1_7_R1.Entity) handle, CreatureSpawnEvent.SpawnReason.CUSTOM);
GameRegistry.get(IEntityRegistry.class).register(oldEntry);
Material beneath = location.getBlock().getRelative(BlockFace.DOWN).getType();
if (beneath.isBlock()) { // What lies beneath
((Entity) handle).onGround = true;
}
return handle;
}
public static Material parseBlockMaterial(Node node, String text) throws InvalidXMLException {
Material material = parseMaterial(node, text);
if(!material.isBlock()) {
throw new InvalidXMLException("Material " + material.name() + " is not a block", node);
}
return material;
}
/**
* Does the given {@link Material} support falling blocks placed on top of it?
*
* This only counts when the gravity block is placed directly on top of the given material,
* not when it is already falling and lands on the material.
*/
public static boolean canSupportBlocks(Material material) {
if(material == null || !material.isBlock() || isLiquid(material)) return false;
switch(material) {
case AIR:
case FIRE:
return false;
}
return true;
}
/**
* Gets a block material corresponding to given item material, which might
* be the given material. If no block material is found, null is returned.
* @param type Material.
* @return Block version of material or null.
*/
@Nullable
public static Material asBlock(Material type) {
if (!damageMeta) { // Apply some hacks on 1.12 and older
if (type == bedItem) { // BED and BED_BLOCK mess, issue #1856
return bedBlock;
}
}
if (type.isBlock()) {
return type;
} else {
return null;
}
}
@Override
@Nullable
public BlockValues getBlockValues(ItemStack stack) {
Material type = stack.getType();
if (type.isBlock()) { // Block has data
// Create default block data for the type
return new NewBlockValues(type, Bukkit.createBlockData(type), true);
}
return null;
}
@NotNull
private Material getMaterial(String type, boolean needBlock) {
Material material = Material.matchMaterial(type);
if (material == null) {
plugin.getLogger().warning("Invalid material for particle in the config: " + type);
return Material.STONE;
}
if (needBlock && !material.isBlock()) {
plugin.getLogger().warning("The material for particle in the config must be a block: " + type);
return Material.STONE;
}
return material;
}
@Override
public boolean set(String value, Player player) {
Material material = MaterialMap.getByName(value);
if (material == null) {
material = MaterialMap.getByName("minecraft:" + value);
}
if (material != null && material.isBlock()) {
NBTTagCompound data = new NBTTagCompound();
data.setString("Name", MaterialMap.getName(material));
data().setCompound(_key, data);
return true;
}
return false;
}
/**
* Returns all possible block data states for this material
* @param material block material
* @return all possible block data states
*/
@SuppressWarnings("deprecation")
public static List<BlockData> getBlockDataList(Material material) {
if (material.isLegacy()) {
throw new IllegalArgumentException(MessageFormat.format("Material {0} is legacy", material));
}
if (!material.isBlock()) {
throw new IllegalArgumentException(MessageFormat.format("Material {0} is not a block", material));
}
return ServerPlatform.get().getMiscUtils().getBlockDataList(material);
}
/**
* Returns block material network id
* @param material block material
* @return network id
*/
@SuppressWarnings("deprecation")
public static int getBlockNetworkId(Material material) {
if (material.isLegacy()) {
throw new IllegalArgumentException(MessageFormat.format("Material {0} is legacy", material));
}
if (!material.isBlock()) {
throw new IllegalArgumentException(MessageFormat.format("Material {0} is not a block", material));
}
return ServerPlatform.get().getMiscUtils().getBlockNetworkId(material);
}
/** Block world that a player can stand on */
static boolean isSupportive(Material type) {
if (type.isOccluding()) {
return true;
}
// blocks that aren't listed as occluding but can support a player
if (type.isBlock()) {
if (type.name().endsWith("STAIRS")) return true;
if (type.name().endsWith("STEP")) return true;
switch (type) {
case CHEST:
case ENDER_CHEST:
case TRAPPED_CHEST:
case HOPPER:
case ANVIL:
case BEACON:
case ENCHANTMENT_TABLE:
case CAULDRON:
case DAYLIGHT_DETECTOR:
case DAYLIGHT_DETECTOR_INVERTED:
case GLASS:
case STAINED_GLASS:
case GLOWSTONE:
case ICE:
case LEAVES:
case LEAVES_2:
case PISTON_BASE:
case PISTON_STICKY_BASE:
case REDSTONE_BLOCK:
case SOIL:
case TNT:
case BARRIER:
case CARPET:
case WATER_LILY:
case CAKE_BLOCK:
case SLIME_BLOCK:
return true;
}
}
return false;
}
@Override
public boolean apply(Material input) {
return input.isBlock();
}
@Override
public boolean matches(Material material) {
return material.isBlock();
}
@Override
public boolean apply(Material input) {
return input.isBlock();
}
@Override
public boolean matches(Material material) {
return material.isBlock();
}
@Override
public void validate(Material material, @Nullable Node node) throws InvalidXMLException {
if(!material.isBlock()) {
throw new InvalidXMLException("Material " + material.name() + " is not a block", node);
}
}
/**
* Construct a new block data
*
* @param material Material of the block
* @param data Data value of the block
* @throws IllegalArgumentException If the material is not a block
* @see ParticleData#ParticleData(Material, byte)
*/
@SuppressWarnings("deprecation")
public BlockData(Material material, byte data) throws IllegalArgumentException {
super(material, data);
if (!material.isBlock()) {
throw new IllegalArgumentException("The material is not a block");
}
}
/**
* Construct a new block data
*
* @param material Material of the block
* @param data Data value of the block
* @throws IllegalArgumentException If the material is not a block
* @see ParticleData#ParticleData(Material, byte)
*/
public BlockData(Material material, byte data) throws IllegalArgumentException {
super(material, data);
if (!material.isBlock()) {
throw new IllegalArgumentException("The material is not a block");
}
}