下面列出了org.bukkit.Material#EMERALD 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Material getDropType(){
if (type == UniversalMaterial.NETHER_QUARTZ_ORE.getType()){
return Material.QUARTZ;
}
switch (type){
case DIAMOND_ORE:
return Material.DIAMOND;
case GOLD_ORE:
return Material.GOLD_INGOT;
case IRON_ORE:
return Material.IRON_INGOT;
case COAL_ORE:
return Material.COAL;
case LAPIS_ORE:
return UniversalMaterial.LAPIS_LAZULI.getType();
case EMERALD_ORE:
return Material.EMERALD;
case REDSTONE_ORE:
return Material.REDSTONE;
case GRAVEL:
return Material.FLINT;
}
return null;
}
/**
* This method returns the outcome that mining certain ores yields.
*
* @param ore
* The {@link Material} of the ore that was mined
*
* @return The outcome when mining this ore
*/
public ItemStack getOutcome(Material ore) {
if (hasSilkTouch()) {
return new ItemStack(ore);
}
Random random = ThreadLocalRandom.current();
switch (ore) {
case COAL_ORE:
return new ItemStack(Material.COAL);
case DIAMOND_ORE:
return new ItemStack(Material.DIAMOND);
case EMERALD_ORE:
return new ItemStack(Material.EMERALD);
case NETHER_QUARTZ_ORE:
return new ItemStack(Material.QUARTZ);
case REDSTONE_ORE:
return new ItemStack(Material.REDSTONE, 4 + random.nextInt(2));
case LAPIS_ORE:
return new ItemStack(Material.LAPIS_LAZULI, 4 + random.nextInt(4));
default:
// This includes Iron and Gold ore
return new ItemStack(ore);
}
}
@Test
public void testSetDataItemMeta() {
CustomItemDataService service = new CustomItemDataService(plugin, "test");
ItemStack item = new ItemStack(Material.EMERALD);
ItemMeta meta = item.getItemMeta();
service.setItemData(meta, "Hello World");
Optional<String> data = service.getItemData(meta);
Assertions.assertTrue(data.isPresent());
Assertions.assertEquals("Hello World", data.get());
item.setItemMeta(meta);
Optional<String> data2 = service.getItemData(item);
Assertions.assertTrue(data2.isPresent());
Assertions.assertEquals("Hello World", data2.get());
}
private PrepareItemCraftEvent mockPreCraftingEvent(ItemStack item) {
Player player = server.addPlayer();
CraftingInventory inv = Mockito.mock(CraftingInventory.class);
MutableObject result = new MutableObject(new ItemStack(Material.EMERALD));
Mockito.doAnswer(invocation -> {
ItemStack argument = invocation.getArgument(0);
result.setValue(argument);
return null;
}).when(inv).setResult(Mockito.any());
Mockito.when(inv.getResult()).thenAnswer(invocation -> result.getValue());
Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { null, null, item, null, null, null, null, null, null });
InventoryView view = player.openInventory(inv);
PrepareItemCraftEvent event = new PrepareItemCraftEvent(inv, view, false);
listener.onPrepareCraft(event);
return event;
}
@Test
public void testLockedCategoriesParents() {
Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null));
Category category = new Category(new NamespacedKey(plugin, "unlocked"), new CustomItem(Material.EMERALD, "&5I am SHERlocked"));
category.register();
Category unregistered = new Category(new NamespacedKey(plugin, "unregistered"), new CustomItem(Material.EMERALD, "&5I am unregistered"));
LockedCategory locked = new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), category.getKey(), unregistered.getKey());
locked.register();
Assertions.assertTrue(locked.getParents().contains(category));
Assertions.assertFalse(locked.getParents().contains(unregistered));
locked.removeParent(category);
Assertions.assertFalse(locked.getParents().contains(category));
Assertions.assertThrows(IllegalArgumentException.class, () -> locked.addParent(locked));
Assertions.assertThrows(IllegalArgumentException.class, () -> locked.addParent(null));
locked.addParent(category);
Assertions.assertTrue(locked.getParents().contains(category));
}
private Material getBounty() {
double rand = Tools.random.nextDouble() *100;
double currentChance = ChanceEmerald;
if(rand < currentChance)
return Material.EMERALD;
currentChance += ChanceDiamond;
if(rand < currentChance)
return Material.DIAMOND;
currentChance += ChanceGold;
if(rand < currentChance)
return Material.GOLD_INGOT;
currentChance += ChanceIron;
if(rand < currentChance)
return Material.IRON_INGOT;
return Material.COAL;
}
public void addReduceCountdownItem() {
ItemStack reduceCountdownItem = new ItemStack(Material.EMERALD, 1);
ItemMeta im = reduceCountdownItem.getItemMeta();
im.setDisplayName(BedwarsRel._l(player, "lobby.reduce_countdown"));
reduceCountdownItem.setItemMeta(im);
this.player.getInventory().addItem(reduceCountdownItem);
}
@Test
public void testSetDataItem() {
CustomItemDataService service = new CustomItemDataService(plugin, "test");
ItemStack item = new ItemStack(Material.EMERALD);
service.setItemData(item, "Hello World");
Optional<String> data = service.getItemData(item);
Assertions.assertTrue(data.isPresent());
Assertions.assertEquals("Hello World", data.get());
}
private CraftItemEvent mockCraftingEvent(ItemStack item) {
Recipe recipe = new ShapedRecipe(new NamespacedKey(plugin, "test_recipe"), new ItemStack(Material.EMERALD));
Player player = server.addPlayer();
CraftingInventory inv = Mockito.mock(CraftingInventory.class);
Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { item, null, null, null, null, null, null, null, null });
InventoryView view = player.openInventory(inv);
CraftItemEvent event = new CraftItemEvent(recipe, view, SlotType.RESULT, 9, ClickType.LEFT, InventoryAction.PICKUP_ALL);
listener.onCraft(event);
return event;
}
@Test
public void testRecipeOutput() {
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "RECIPE_OUTPUT_TEST", new CustomItem(Material.DIAMOND, "&cTest"));
item.register(plugin);
Assertions.assertEquals(item.getItem(), item.getRecipeOutput());
ItemStack output = new ItemStack(Material.EMERALD, 64);
item.setRecipeOutput(output);
Assertions.assertEquals(output, item.getRecipeOutput());
item.setRecipeOutput(item.getItem());
Assertions.assertEquals(item.getItem(), item.getRecipeOutput());
}
@Test
public void testLockedCategoriesUnlocking() throws InterruptedException {
Player player = server.addPlayer();
PlayerProfile profile = TestUtilities.awaitProfile(player);
Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null));
Category category = new Category(new NamespacedKey(plugin, "parent"), new CustomItem(Material.EMERALD, "&5I am SHERlocked"));
category.register();
LockedCategory locked = new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), category.getKey());
locked.register();
// No Items, so it should be unlocked
Assertions.assertTrue(locked.hasUnlocked(player, profile));
SlimefunItem item = new SlimefunItem(category, new SlimefunItemStack("LOCKED_CATEGORY_TEST", new CustomItem(Material.LANTERN, "&6Test Item for locked categories")), RecipeType.NULL, new ItemStack[9]);
item.register(plugin);
item.load();
SlimefunPlugin.getRegistry().setResearchingEnabled(true);
Research research = new Research(new NamespacedKey(plugin, "cant_touch_this"), 432432, "MC Hammer", 90);
research.addItems(item);
research.register();
Assertions.assertFalse(profile.hasUnlocked(research));
Assertions.assertFalse(locked.hasUnlocked(player, profile));
profile.setResearched(research, true);
Assertions.assertTrue(locked.hasUnlocked(player, profile));
}
public static ItemStack getEmerald(Player player) {
if (GameHandler.getGameHandler().getMatch().getModules().getModules(Tutorial.class).size() > 0) {
ItemStack emerald = new ItemStack(Material.EMERALD);
ItemMeta meta = emerald.getItemMeta();
meta.setDisplayName(ChatColor.GOLD + new LocalizedChatMessage(ChatConstant.UI_TUTORIAL_VIEW).getMessage(ChatUtil.getLocale(player)));
emerald.setItemMeta(meta);
return emerald;
}
return new ItemStack(Material.AIR);
}
public static SlimefunItem mockSlimefunItem(Plugin plugin, String id, ItemStack item) {
Category category = new Category(new NamespacedKey(plugin, "test"), new CustomItem(Material.EMERALD, "&4Test Category"));
return new MockSlimefunItem(category, item, id);
}
public static VanillaItem mockVanillaItem(Plugin plugin, Material type, boolean enabled) {
Category category = new Category(new NamespacedKey(plugin, "test"), new CustomItem(Material.EMERALD, "&4Test Category"));
VanillaItem item = new VanillaItem(category, new ItemStack(type), type.name(), RecipeType.NULL, new ItemStack[9]);
SlimefunPlugin.getItemCfg().setValue(type.name() + ".enabled", enabled);
return item;
}