mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-03 05:32:18 -07:00
#919: Add internal ItemType and BlockType, delegate Material methods to them
By: Jishuna <joshl5324@gmail.com> Also-by: Bjarne Koll <lynxplay101@gmail.com> Also-by: DerFrZocker <derrieple@gmail.com> Also-by: md_5 <git@md-5.net>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -12,6 +12,7 @@ import java.util.stream.StreamSupport;
|
|||||||
import org.bukkit.advancement.Advancement;
|
import org.bukkit.advancement.Advancement;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
|
import org.bukkit.block.BlockType;
|
||||||
import org.bukkit.block.banner.PatternType;
|
import org.bukkit.block.banner.PatternType;
|
||||||
import org.bukkit.boss.KeyedBossBar;
|
import org.bukkit.boss.KeyedBossBar;
|
||||||
import org.bukkit.damage.DamageType;
|
import org.bukkit.damage.DamageType;
|
||||||
@@ -24,6 +25,7 @@ import org.bukkit.entity.Wolf;
|
|||||||
import org.bukkit.entity.memory.MemoryKey;
|
import org.bukkit.entity.memory.MemoryKey;
|
||||||
import org.bukkit.generator.structure.Structure;
|
import org.bukkit.generator.structure.Structure;
|
||||||
import org.bukkit.generator.structure.StructureType;
|
import org.bukkit.generator.structure.StructureType;
|
||||||
|
import org.bukkit.inventory.ItemType;
|
||||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||||
import org.bukkit.loot.LootTables;
|
import org.bukkit.loot.LootTables;
|
||||||
@@ -92,6 +94,14 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||||||
* @see Biome
|
* @see Biome
|
||||||
*/
|
*/
|
||||||
Registry<Biome> BIOME = new SimpleRegistry<>(Biome.class);
|
Registry<Biome> BIOME = new SimpleRegistry<>(Biome.class);
|
||||||
|
/**
|
||||||
|
* Server block types.
|
||||||
|
*
|
||||||
|
* @see BlockType
|
||||||
|
* @apiNote BlockType is not ready for public usage yet
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
Registry<BlockType> BLOCK = Objects.requireNonNull(Bukkit.getRegistry(BlockType.class), "No registry present for BlockType. This is a bug.");
|
||||||
/**
|
/**
|
||||||
* Custom boss bars.
|
* Custom boss bars.
|
||||||
*
|
*
|
||||||
@@ -142,6 +152,14 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||||||
* @see MusicInstrument
|
* @see MusicInstrument
|
||||||
*/
|
*/
|
||||||
Registry<MusicInstrument> INSTRUMENT = Objects.requireNonNull(Bukkit.getRegistry(MusicInstrument.class), "No registry present for MusicInstrument. This is a bug.");
|
Registry<MusicInstrument> INSTRUMENT = Objects.requireNonNull(Bukkit.getRegistry(MusicInstrument.class), "No registry present for MusicInstrument. This is a bug.");
|
||||||
|
/**
|
||||||
|
* Server item types.
|
||||||
|
*
|
||||||
|
* @see ItemType
|
||||||
|
* @apiNote ItemType is not ready for public usage yet
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
Registry<ItemType> ITEM = Objects.requireNonNull(Bukkit.getRegistry(ItemType.class), "No registry present for ItemType. This is a bug.");
|
||||||
/**
|
/**
|
||||||
* Default server loot tables.
|
* Default server loot tables.
|
||||||
*
|
*
|
||||||
|
3604
paper-api/src/main/java/org/bukkit/block/BlockType.java
Normal file
3604
paper-api/src/main/java/org/bukkit/block/BlockType.java
Normal file
File diff suppressed because it is too large
Load Diff
2422
paper-api/src/main/java/org/bukkit/inventory/ItemType.java
Normal file
2422
paper-api/src/main/java/org/bukkit/inventory/ItemType.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,9 @@ import java.util.Collection;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.BlockType;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.inventory.ItemType;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -59,6 +61,28 @@ public interface DataPackManager {
|
|||||||
*/
|
*/
|
||||||
public boolean isEnabledByFeature(@NotNull Material material, @NotNull World world);
|
public boolean isEnabledByFeature(@NotNull Material material, @NotNull World world);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if the ItemType is enabled for use by the features in World.
|
||||||
|
*
|
||||||
|
* @param itemType ItemType to check
|
||||||
|
* @param world World to check
|
||||||
|
* @return {@code True} if the ItemType is enabled
|
||||||
|
* @apiNote this method is not ready for public usage yet
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public boolean isEnabledByFeature(@NotNull ItemType itemType, @NotNull World world);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if the BlockType is enabled for use by the features in World.
|
||||||
|
*
|
||||||
|
* @param blockType BlockType to check
|
||||||
|
* @param world World to check
|
||||||
|
* @return {@code True} if the BlockType is enabled
|
||||||
|
* @apiNote this method is not ready for public usage yet
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public boolean isEnabledByFeature(@NotNull BlockType blockType, @NotNull World world);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets if the EntityType is enabled for use by the Features in World.
|
* Gets if the EntityType is enabled for use by the Features in World.
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package org.bukkit.scoreboard;
|
package org.bukkit.scoreboard;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@@ -11,12 +12,20 @@ public class CriteriaTest extends AbstractTestingBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStatistic() {
|
public void testStatistic() {
|
||||||
|
Material item = mock();
|
||||||
|
when(item.isItem()).thenReturn(true);
|
||||||
|
when(item.isBlock()).thenReturn(false);
|
||||||
|
|
||||||
|
Material block = mock();
|
||||||
|
when(block.isItem()).thenReturn(false);
|
||||||
|
when(block.isBlock()).thenReturn(true);
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, Material.STONE)); // Generic statistic with block
|
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, Material.STONE)); // Generic statistic with block
|
||||||
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type
|
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, Material.AMETHYST_SHARD)); // Entity statistic with material
|
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, Material.AMETHYST_SHARD)); // Entity statistic with material
|
||||||
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.MINE_BLOCK, Material.DIAMOND_PICKAXE)); // Block statistic with item
|
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.MINE_BLOCK, item)); // Block statistic with item
|
||||||
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.BREAK_ITEM, Material.WATER)); // Item statistic with block
|
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.BREAK_ITEM, block)); // Item statistic with block
|
||||||
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.KILL_ENTITY, Material.STONE)); // Entity statistic with Material
|
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.KILL_ENTITY, Material.STONE)); // Entity statistic with Material
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user