Java Code Examples for org.bukkit.Material#STONE

The following examples show how to use org.bukkit.Material#STONE . 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: ItemConvertionTest.java    From Item-NBT-API with MIT License 6 votes vote down vote up
@Override
public void test() throws Exception {
	ItemStack item = new ItemStack(Material.STONE, 1);
	ItemMeta meta = item.getItemMeta();
	meta.setLore(Lists.newArrayList("Firest Line", "Second Line"));
	item.setItemMeta(meta);
	String nbt = NBTItem.convertItemtoNBT(item).toString();
	if (!nbt.contains("Firest Line") || !nbt.contains("Second Line"))
		throw new NbtApiException("The Item nbt '" + nbt + "' didn't contain the lore");
	ItemStack rebuild = NBTItem.convertNBTtoItem(new NBTContainer(nbt));
	if (!item.isSimilar(rebuild))
		throw new NbtApiException("Rebuilt item did not match the original!");
	
	NBTContainer cont = new NBTContainer();
	cont.setItemStack("testItem", item);
	if(!cont.getItemStack("testItem").isSimilar(item))
		throw new NbtApiException("Rebuilt item did not match the original!");
}
 
Example 2
Source File: Items.java    From TabooLib with MIT License 6 votes vote down vote up
public static ItemStack fromJson(String item) {
    JsonElement json = new JsonParser().parse(item);
    if (json instanceof JsonObject) {
        ItemBuilder itemBuilder = new ItemBuilder(Material.STONE);
        JsonElement type = ((JsonObject) json).get("type");
        if (type != null) {
            itemBuilder.material(Items.asMaterial(type.getAsString()));
        }
        JsonElement data = ((JsonObject) json).get("data");
        if (data != null) {
            itemBuilder.damage(data.getAsInt());
        }
        JsonElement amount = ((JsonObject) json).get("amount");
        if (amount != null) {
            itemBuilder.amount(amount.getAsInt());
        }
        ItemStack itemBuild = itemBuilder.build();
        JsonElement meta = ((JsonObject) json).get("meta");
        if (meta != null) {
            return NMS.handle().saveNBT(itemBuild, NBTCompound.fromJson(meta.toString()));
        }
        return itemBuild;
    }
    return null;
}
 
Example 3
Source File: TestWindow.java    From Hawk with GNU General Public License v3.0 6 votes vote down vote up
public TestWindow(Hawk hawk, Player p) {
    super(hawk, p, 1, "Test");
    elements[4] = new Element(Material.STONE, "Click on me to update inventory") {
        @Override
        public void doAction(Player p, Hawk hawk) {
            Element element = elements[4];
            if(element.getItemStack().getType() == Material.STONE) {
                element.getItemStack().setType(Material.WOOD);
            }
            else {
                element.getItemStack().setType(Material.STONE);
            }
            updateWindow();
        }
    };

    prepareInventory();
}
 
Example 4
Source File: JsonItem.java    From TrMenu with MIT License 6 votes vote down vote up
public static ItemStack fromJson(String item) {
    JsonElement json = new JsonParser().parse(TLocale.Translate.setColored(item));
    if (json instanceof JsonObject) {
        ItemBuilder itemBuilder = new ItemBuilder(Material.STONE);
        JsonElement type = ((JsonObject) json).get("type");
        if (type != null) {
            itemBuilder.material(Items.asMaterial(type.getAsString()));
        }
        JsonElement data = ((JsonObject) json).get("data");
        if (data != null) {
            itemBuilder.damage(data.getAsInt());
        }
        JsonElement amount = ((JsonObject) json).get("amount");
        if (amount != null) {
            itemBuilder.amount(amount.getAsInt());
        }
        ItemStack itemBuild = itemBuilder.build();
        JsonElement meta = ((JsonObject) json).get("meta");
        if (meta != null) {
            return NMS.handle().saveNBT(itemBuild, NBTCompound.fromJson(meta.toString()));
        }
        return itemBuild;
    }
    return null;
}
 
Example 5
Source File: ChestReplaceEvent.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
private Material getWool() {
Material wool = Material.STONE;
try {
	if(SurvivalGames.PRE1_13) {
		wool = Material.class.cast(Material.class.getDeclaredField("WOOL").get(Material.class));
	}else {				
		wool = Material.class.cast(Material.class.getDeclaredField("LEGACY_WOOL").get(Material.class));
	}
} catch (Exception e1) {
		e1.printStackTrace();
}
return wool;
  }
 
Example 6
Source File: TestMultiBlocks.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEqualWithMovingPistons() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PISTON_MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));

    // Some Pistons are moving but that should not interefere with the Multiblock
    MultiBlock multiblock = new MultiBlock(item, new Material[] { Material.PISTON, Material.MOVING_PISTON, Material.PISTON, null, Material.CRAFTING_TABLE, null, Material.PISTON, Material.STONE, Material.PISTON }, BlockFace.DOWN);
    MultiBlock multiblock2 = new MultiBlock(item, new Material[] { Material.MOVING_PISTON, Material.PISTON, Material.MOVING_PISTON, null, Material.CRAFTING_TABLE, null, Material.PISTON, Material.STONE, Material.PISTON }, BlockFace.DOWN);
    MultiBlock multiblock3 = new MultiBlock(item, new Material[] { Material.PISTON, Material.PISTON, Material.STICKY_PISTON, null, Material.CRAFTING_TABLE, null, Material.PISTON, Material.STONE, Material.PISTON }, BlockFace.DOWN);

    Assertions.assertTrue(multiblock.equals(multiblock2));
    Assertions.assertFalse(multiblock.equals(multiblock3));
}
 
Example 7
Source File: GsonTest.java    From Item-NBT-API with MIT License 5 votes vote down vote up
@Override
public void test() throws Exception {
	if (!MinecraftVersion.hasGsonSupport()) {
		return;
	}
	try {
		ItemStack item = new ItemStack(Material.STONE, 1);
		NBTItem nbtItem = new NBTItem(item);

		nbtItem.setObject(JSON_TEST_KEY, new SimpleJsonTestObject());

		if (!nbtItem.hasKey(JSON_TEST_KEY)) {
			throw new NbtApiException(
					"Wasn't able to find JSON key! The Item-NBT-API may not work with Json serialization/deserialization!");
		} else {
			SimpleJsonTestObject simpleObject = nbtItem.getObject(JSON_TEST_KEY, SimpleJsonTestObject.class);
			if (simpleObject == null) {
				throw new NbtApiException(
						"Wasn't able to check JSON key! The Item-NBT-API may not work with Json serialization/deserialization!");
			} else if (!(STRING_TEST_VALUE).equals(simpleObject.getTestString())
					|| simpleObject.getTestInteger() != INT_TEST_VALUE
					|| simpleObject.getTestDouble() != DOUBLE_TEST_VALUE
					|| !simpleObject.isTestBoolean() == BOOLEAN_TEST_VALUE) {
				throw new NbtApiException(
						"One key does not equal the original value in JSON! The Item-NBT-API may not work with Json serialization/deserialization!");
			}
		}
	} catch (Exception ex) {
		throw new NbtApiException("Exception during Gson check!", ex);
	}
}
 
Example 8
Source File: RepairConfig.java    From NyaaUtils with MIT License 5 votes vote down vote up
public RepairConfigItem normalize() {
    if (material == null) material = Material.STONE;
    if (fullRepairCost <= 0) fullRepairCost = 1;
    if (expCost < 0) expCost = 0;
    if (enchantCostPerLv < 0) enchantCostPerLv = 0;
    if (repairLimit <= 0) repairLimit = 0;
    return this;
}
 
Example 9
Source File: ConfigurationHelper.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
@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;
}
 
Example 10
Source File: ItemBuilder.java    From Crazy-Crates with MIT License 5 votes vote down vote up
/**
 * The initial starting point for making an item.
 */
public ItemBuilder() {
    this.nbtItem = null;
    this.material = Material.STONE;
    this.damage = 0;
    this.name = "";
    this.crateName = "";
    this.lore = new ArrayList<>();
    this.amount = 1;
    this.player = "";
    this.isHash = false;
    this.isURL = false;
    this.isHead = false;
    this.enchantments = new HashMap<>();
    this.unbreakable = false;
    this.hideItemFlags = false;
    this.glowing = false;
    this.referenceItem = null;
    this.entityType = EntityType.BAT;
    this.potionType = null;
    this.potionColor = null;
    this.isPotion = false;
    this.armorColor = null;
    this.isLeatherArmor = false;
    this.patterns = new ArrayList<>();
    this.isBanner = false;
    this.isShield = false;
    this.customModelData = 0;
    this.useCustomModelData = false;
    this.isMobEgg = false;
    this.namePlaceholders = new HashMap<>();
    this.lorePlaceholders = new HashMap<>();
    this.itemFlags = new ArrayList<>();
}
 
Example 11
Source File: Options.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
private Material stringToMaterial(String string)
{
	Material sound = Material.STONE;
	boolean isValid = JavaUtils.isValidEnum(Material.class, string);
	
	if(!isValid)
	{
		message.sendConsoleMessage("Invalid material type '" + string + "'!", true);
	}else sound = Material.valueOf(string);
	
	return sound;
}
 
Example 12
Source File: ItemGetterLatest.java    From Quests with MIT License 5 votes vote down vote up
@Override
public ItemStack getItemStack(String material, Quests plugin) {
    Material type;
    try {
        type = Material.valueOf(material);
    } catch (Exception e) {
        plugin.getQuestsLogger().debug("Unrecognised material: " + material);
        type = Material.STONE;
    }
    return new ItemStack(type, 1);
}
 
Example 13
Source File: ItemGetter_1_13.java    From Quests with MIT License 5 votes vote down vote up
@Override
public ItemStack getItemStack(String material, Quests plugin) {
    Material type;
    try {
        type = Material.valueOf(material);
    } catch (Exception e) {
        plugin.getQuestsLogger().debug("Unrecognised material: " + material);
        type = Material.STONE;
    }
    return new ItemStack(type, 1);
}
 
Example 14
Source File: CVItem.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
public static CVItem createCVItemFromString(String locale, String materialString)  {
    boolean isMMOItem = materialString.contains("mi:");
    if (isMMOItem) {
        materialString = materialString.replace("mi:", "");
    }

    String quantityString = "1";
    String chanceString = "100";
    String nameString = null;
    String mmoType = "";
    Material mat;

    String[] splitString;


    for (;;) {
        int asteriskIndex = materialString.indexOf("*");
        int percentIndex = materialString.indexOf("%");
        int nameIndex = materialString.indexOf(".");
        if (asteriskIndex != -1 && asteriskIndex > percentIndex && asteriskIndex > nameIndex) {
            splitString = materialString.split("\\*");
            quantityString = splitString[splitString.length - 1];
            materialString = splitString[0];
        } else if (percentIndex != -1 && percentIndex > asteriskIndex && percentIndex > nameIndex) {
            splitString = materialString.split("%");
            chanceString = splitString[splitString.length - 1];
            materialString = splitString[0];
        } else if (nameIndex != -1 && nameIndex > percentIndex && nameIndex > asteriskIndex) {
            splitString = materialString.split("\\.");
            nameString = splitString[splitString.length -1];
            materialString = splitString[0];
        } else {
            if (isMMOItem) {
                mmoType = materialString;
                mat = Material.STONE;
            } else {
                mat = getMaterialFromString(materialString);
            }
            break;
        }
    }


    if (mat == null) {
        mat = Material.STONE;
        Civs.logger.severe(Civs.getPrefix() + "Unable to parse material " + materialString);
    }
    int quantity = Integer.parseInt(quantityString);
    int chance = Integer.parseInt(chanceString);

    if (isMMOItem) {
        if (Civs.mmoItems == null) {
            Civs.logger.severe(Civs.getPrefix() + "Unable to create MMOItem because MMOItems is disabled");
            return new CVItem(mat, quantity, chance);
        }
        Type mmoItemType = Civs.mmoItems.getTypes().get(mmoType);
        if (mmoItemType == null) {
            Civs.logger.severe(Civs.getPrefix() + "MMOItem type " + mmoType + " not found");
            return new CVItem(mat, quantity, chance);
        }
        if (nameString == null) {
            Civs.logger.severe(Civs.getPrefix() + "Invalid MMOItem " + mmoType + " did not provide item name");
            return new CVItem(mat, quantity, chance);
        }
        MMOItem mmoItem = Civs.mmoItems.getItems().getMMOItem(mmoItemType, nameString);
        ItemStack item = mmoItem.newBuilder().build();
        CVItem cvItem = new CVItem(item.getType(), quantity, chance, item.getItemMeta().getDisplayName(),
                item.getItemMeta().getLore());
        cvItem.mmoItemName = nameString;
        cvItem.mmoItemType = mmoType;
        return cvItem;
    }
    if (nameString == null) {
        return new CVItem(mat, quantity, chance);
    } else {
        String displayName = LocaleManager.getInstance().getTranslation(locale, "item-" + nameString + "-name");
        List<String> lore = new ArrayList<>();
        lore.add(ChatColor.BLACK + nameString);
        lore.addAll(Util.textWrap(ConfigManager.getInstance().getCivsItemPrefix() +
                LocaleManager.getInstance().getTranslation(locale, "item-" + nameString + "-desc")));
        return new CVItem(mat, quantity, chance, displayName, lore);
    }
}
 
Example 15
Source File: StoneVariantPopulator.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void createVein(World world, int size, int x, int y, int z) {
       Random random = new Random(world.getSeed());
       float f = random.nextFloat() * 3.141593F;
       double d1 = x + 8 + Math.sin(f) * size / 8.0F;
       double d2 = x + 8 - Math.sin(f) * size / 8.0F;
       double d3 = z + 8 + Math.cos(f) * size / 8.0F;
       double d4 = z + 8 - Math.cos(f) * size / 8.0F;
       double d5 = y + random.nextInt(3) - 2;
       double d6 = y + random.nextInt(3) - 2;
       for (int i = 0; i <= size; i++) {
           double d7 = d1 + (d2 - d1) * i / size;
           double d8 = d5 + (d6 - d5) * i / size;
           double d9 = d3 + (d4 - d3) * i / size;
           double d10 = random.nextDouble() * size / 16.0D;
           double d11 = (Math.sin(i * 3.141593F / size) + 1.0F) * d10 + 1.0D;
           double d12 = (Math.sin(i * 3.141593F / size) + 1.0F) * d10 + 1.0D;
           int j = (int) Math.floor(d7 - d11 / 2.0D);
           int k = (int) Math.floor(d8 - d12 / 2.0D);
           int m = (int) Math.floor(d9 - d11 / 2.0D);
           int n = (int) Math.floor(d7 + d11 / 2.0D);
           int i1 = (int) Math.floor(d8 + d12 / 2.0D);
           int i2 = (int) Math.floor(d9 + d11 / 2.0D);
           for (int i3 = j; i3 <= n; i3++) {
               double d13 = (i3 + 0.5D - d7) / (d11 / 2.0D);
               if (d13 * d13 < 1.0D) {
                   for (int i4 = k; i4 <= i1; i4++) {
                       double d14 = (i4 + 0.5D - d8) / (d12 / 2.0D);
                       if (d13 * d13 + d14 * d14 < 1.0D) {
                           for (int i5 = m; i5 <= i2; i5++) {
                               double d15 = (i5 + 0.5D - d9) / (d11 / 2.0D);
                               if ((d13 * d13 + d14 * d14 + d15 * d15 >= 1.0D) || (world.getBlockAt(i3, i4, i5).getType() != Material.STONE)) {
                                   continue;
                               }
                               world.getBlockAt(i3, i4, i5).setTypeIdAndData(blockType.getId(), data, true);
                           }
                       }
                   }
               }
           }
       }
   }
 
Example 16
Source File: ItemEntryTest.java    From LanguageUtils with MIT License 4 votes vote down vote up
@Test
public void testEquals() throws Exception {
    //Same Material
    ItemEntry equalEntry1 = new ItemEntry(Material.STONE);
    ItemEntry equalEntry2 = new ItemEntry(Material.STONE);

    assertThat(equalEntry1, is(equalEntry2));
    assertThat(equalEntry1.hashCode(), is(equalEntry2.hashCode()));

    //Same Material + metadata
    ItemEntry equalEntry3 = new ItemEntry(Material.STONE, 2);
    ItemEntry equalEntry4 = new ItemEntry(Material.STONE, 2);

    assertThat(equalEntry3, is(equalEntry4));
    assertThat(equalEntry3.hashCode(), is(equalEntry4.hashCode()));

    //Different Material
    ItemEntry diffEntry1 = new ItemEntry(Material.STONE);
    ItemEntry diffEntry2 = new ItemEntry(Material.ANVIL);

    assertThat(diffEntry1, not(diffEntry2));
    assertThat(diffEntry1.hashCode(), not(diffEntry2.hashCode()));

    //Different metadata
    ItemEntry diffEntry3 = new ItemEntry(Material.STONE, 4);
    ItemEntry diffEntry4 = new ItemEntry(Material.STONE, 7);

    assertThat(diffEntry3, not(diffEntry4));
    assertThat(diffEntry3.hashCode(), not(diffEntry4.hashCode()));

    //Different Material + metadata
    ItemEntry diffEntry5 = new ItemEntry(Material.STONE, 4);
    ItemEntry diffEntry6 = new ItemEntry(Material.SAND, 2);

    assertThat(diffEntry5, not(diffEntry6));
    assertThat(diffEntry5.hashCode(), not(diffEntry6.hashCode()));


    //HashMap Test
    Map<ItemEntry, EnumItem> testMap = new HashMap<ItemEntry, EnumItem>();

    testMap.put(equalEntry1, EnumItem.STONE);
    assertTrue(testMap.containsKey(equalEntry1));

    testMap.put(equalEntry3, EnumItem.POLISHED_GRANITE);
    assertTrue(testMap.containsKey(equalEntry4));

    assertFalse(testMap.containsKey(diffEntry2));
    assertFalse(testMap.containsKey(diffEntry3));
    assertFalse(testMap.containsKey(diffEntry6));
}
 
Example 17
Source File: ClassModuleBuilder.java    From CardinalPGM with MIT License 4 votes vote down vote up
@Override
public ModuleCollection<ClassModule> load(Match match) {
    ModuleCollection<ClassModule> results = new ModuleCollection<>();
    for (Element classes : match.getDocument().getRootElement().getChildren("classes")) {
        for (Element classElement : classes.getChildren("class")) {
            String name = null;
            if (classElement.getAttributeValue("name") != null) {
                name = classElement.getAttributeValue("name");
            } else if (classes.getAttributeValue("name") != null) {
                name = classes.getAttributeValue("name");
            }
            String description = null;
            if (classElement.getAttributeValue("description") != null) {
                description = classElement.getAttributeValue("description");
            } else if (classes.getAttributeValue("description") != null) {
                description = classes.getAttributeValue("description");
            }
            String longDescription = description;
            if (classElement.getAttributeValue("longdescription") != null) {
                longDescription = classElement.getAttributeValue("longdescription");
            } else if (classes.getAttributeValue("longdescription") != null) {
                longDescription = classes.getAttributeValue("longdescription");
            }
            Material icon = Material.STONE;
            if (classElement.getAttributeValue("icon") != null) {
                icon = Material.matchMaterial(classElement.getAttributeValue("icon"));
            } else if (classes.getAttributeValue("icon") != null) {
                icon = Material.matchMaterial(classes.getAttributeValue("icon"));
            }
            boolean sticky = false;
            if (classElement.getAttributeValue("sticky") != null) {
                sticky = classElement.getAttributeValue("sticky").equalsIgnoreCase("true");
            } else if (classes.getAttributeValue("sticky") != null) {
                sticky = classes.getAttributeValue("sticky").equalsIgnoreCase("true");
            }
            boolean defaultClass = false;
            if (classElement.getAttributeValue("default") != null) {
                defaultClass = classElement.getAttributeValue("default").equalsIgnoreCase("true");
            } else if (classes.getAttributeValue("default") != null) {
                defaultClass = classes.getAttributeValue("default").equalsIgnoreCase("true");
            }
            boolean restrict = false;
            if (classElement.getAttributeValue("restrict") != null) {
                restrict = !classElement.getAttributeValue("restrict").equalsIgnoreCase("false");
            } else if (classes.getAttributeValue("restrict") != null) {
                restrict = !classes.getAttributeValue("restrict").equalsIgnoreCase("false");
            }
            KitNode kit = classElement.getChildren().size() > 0 ? KitBuilder.getKit(classElement.getChildren().get(0)) : null;
            results.add(new ClassModule(name, description, longDescription, icon, sticky, defaultClass, restrict, kit));
        }
    }
    return results;
}
 
Example 18
Source File: ItemDisguise.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 2 votes vote down vote up
/**
 * Creates an instance.<br>
 * The default item stack is one stone.
 * 
 * @since 5.1.1
 */
public ItemDisguise() {
	this(new ItemStack(Material.STONE, 1));
}
 
Example 19
Source File: FallingBlockDisguise.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 2 votes vote down vote up
/**
 * Creates an instance.<br>
 * The default material is {@linkplain Material#STONE}.
 * 
 * @since 5.1.1
 */
public FallingBlockDisguise() {
	this(Material.STONE);
}
 
Example 20
Source File: TrUtils.java    From TrMenu with MIT License 2 votes vote down vote up
/**
 * 取得一个 ItemStack 构造器 (from TabooLib5)
 *
 * @return
 */
public ItemBuilder getItemBuildr() {
    return new ItemBuilder(Material.STONE);
}