Java Code Examples for org.bukkit.Material#ANVIL

The following examples show how to use org.bukkit.Material#ANVIL . 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: InfiniteEnchantsListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onGameStarted(UhcStartedEvent e){
    ItemStack enchantingTables = UniversalMaterial.ENCHANTING_TABLE.getStack(64);
    ItemStack anvils = new ItemStack(Material.ANVIL, 64);
    ItemStack lapisBlocks = new ItemStack(Material.LAPIS_BLOCK, 64);

    for (UhcPlayer uhcPlayer : e.getPlayersManager().getOnlinePlayingPlayers()){
        try {
            Player player = uhcPlayer.getPlayer();
            player.getInventory().addItem(enchantingTables, anvils, lapisBlocks);
            player.setLevel(Integer.MAX_VALUE);
        }catch (UhcPlayerNotOnlineException ex){
            // No rod for offline players
        }
    }
}
 
Example 2
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCivilianUseExp(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null || event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    Civilian civilian = CivilianManager.getInstance().getCivilian(event.getPlayer().getUniqueId());
    if (civilian.getMana() < 1 || civilian.getMana() > 99) {
        return;
    }
    Material mat = event.getClickedBlock().getType();
    if (mat == Material.ANVIL ||
            mat == Material.ENCHANTING_TABLE) {
        event.setCancelled(true);
        event.getPlayer().sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(
                event.getPlayer(), "mana-use-exp"));
    }
}
 
Example 3
Source File: GoneFishingListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onGameStarted(UhcStartedEvent e){
    ItemStack rod = new ItemStack(Material.FISHING_ROD);
    rod.addUnsafeEnchantment(Enchantment.LURE, lureLevel);
    rod.addUnsafeEnchantment(Enchantment.LUCK, luckLevel);

    ItemMeta meta = rod.getItemMeta();
    VersionUtils.getVersionUtils().setItemUnbreakable(meta, true);
    rod.setItemMeta(meta);

    ItemStack anvils = new ItemStack(Material.ANVIL, 64);

    for (UhcPlayer uhcPlayer : e.getPlayersManager().getOnlinePlayingPlayers()){
        try {
            // Give the rod
            uhcPlayer.getPlayer().getInventory().addItem(rod);

            // Give player 10000 xl levels
            uhcPlayer.getPlayer().setLevel(10000);

            // Give player 64 anvils
            uhcPlayer.getPlayer().getInventory().addItem(anvils);
        }catch (UhcPlayerNotOnlineException ex){
            // No rod for offline players
        }
    }
}
 
Example 4
Source File: AnvilRainEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public AnvilRainEvent(GameMap map, boolean b) {
	this.gMap = map;
	this.enabled = b;
	File dataDirectory = SkyWarsReloaded.get().getDataFolder();
       File mapDataDirectory = new File(dataDirectory, "mapsData");

       if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
       	return;
       }
       
       File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
    if (mapFile.exists()) {
    	eventName = "AnvilRainEvent";
    	slot = 0;
    	material = new ItemStack(Material.ANVIL, 1);
        FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
        this.min = fc.getInt("events." + eventName + ".minStart");
        this.max = fc.getInt("events." + eventName + ".maxStart");
        this.length = fc.getInt("events." + eventName + ".length");
        this.chance = fc.getInt("events." + eventName + ".chance");
        this.title = fc.getString("events." + eventName + ".title");
        this.subtitle = fc.getString("events." + eventName + ".subtitle");
        this.startMessage = fc.getString("events." + eventName + ".startMessage");
        this.endMessage = fc.getString("events." + eventName + ".endMessage");
        this.announceEvent = fc.getBoolean("events." + eventName + ".announceTimer");
        this.repeatable = fc.getBoolean("events." + eventName + ".repeatable");
        this.per5Tick = fc.getInt("events." + eventName + ".spawnPer5Tick");
       }
}
 
Example 5
Source File: ArmorForge.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public ArmorForge(Category category, SlimefunItemStack item) {
    super(category, item, new ItemStack[] { 
          null, null, null, 
          null, new ItemStack(Material.ANVIL), null, 
          null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null 
    }, new ItemStack[0], BlockFace.SELF);
}
 
Example 6
Source File: AnvilTracker.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlace(ParticipantBlockTransformEvent event) {
  if (event.getNewState().getMaterial() == Material.ANVIL) {
    blocks().trackBlockState(event.getNewState(), new AnvilInfo(event.getPlayerState()));
  }
}
 
Example 7
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onClick(PlayerInteractEvent event) {
	Player player = event.getPlayer();

	ItemStack norm = null;
	if (event.getHand() == EquipmentSlot.HAND) {
		norm = player.getInventory().getItemInMainHand();
	} else if (event.getHand() == EquipmentSlot.OFF_HAND) {
		norm = player.getInventory().getItemInOffHand();
	}

	if (norm == null) return;

	if (event.getAction() == Action.RIGHT_CLICK_AIR) {
		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
		}
	} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
		Block block = event.getClickedBlock();

		if (block == null) {
			return;
		}
		if (!player.isSneaking()) {
			Material type = block.getType();

			if (type == Material.ANVIL || type == Material.CRAFTING_TABLE
					|| type == Material.CHEST || type == Material.ENDER_CHEST
					|| type == Material.DROPPER || type == Material.HOPPER
					|| type == Material.DISPENSER || type == Material.TRAPPED_CHEST
					|| type == Material.FURNACE || type == Material.ENCHANTING_TABLE) {

				return;
			}
		}

		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
			return;
		}

		if (block.getType() == Material.getMaterial(MineTinker.getPlugin().getConfig().getString("BlockToEnchantModifiers", Material.BOOKSHELF.name()))) {
			ItemStack item = player.getInventory().getItemInMainHand();

			for (Modifier m : modManager.getAllMods()) {
				if (m.getModItem().getType().equals(item.getType())) {
					if (!m.isEnchantable()) continue;
					m.enchantItem(player);
					event.setCancelled(true);
					break;
				}
			}
		}
	}
}
 
Example 8
Source File: AnvilTracker.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlace(ParticipantBlockTransformEvent event) {
    if(event.getNewState().getMaterial() == Material.ANVIL) {
        blocks().trackBlockState(event.getNewState(), new AnvilInfo(event.getPlayerState()));
    }
}
 
Example 9
Source File: Recipes.java    From ProRecipes with GNU General Public License v2.0 4 votes vote down vote up
public boolean handleDoubles(ItemStack[] items, ItemStack result, Player p, Inventory inv){
	//long mil = System.currentTimeMillis();
	RecipeShapeless r = new RecipeShapeless(new ItemStack(Material.ANVIL));
	
	for(ItemStack i : items){
		if(i != null && i.getType() != Material.AIR){
			r.addIngredient(i);
		}
	}
	
	r.removeIngredient(result);
	int ing = 0;
	
	RecipeShapeless fina = null;
	for(RecipeShapeless recipe : shapeless){
		if(recipe.matchLowest(r)){
			if(recipe.ingredientCount() >= ing){
				ing = recipe.ingredientCount();
			}else{
				continue;
			}
	
			if(recipe.hasPermission()){
				if(!p.hasPermission(recipe.getPermission())){
					continue;
				}
			}
			
			fina = recipe;
			
		}
	
	}
	
	if(fina != null){
		
		ItemStack old = result;
		
		WorkbenchCraftEvent workbenchEvent = new WorkbenchCraftEvent(ProRecipes.getAPI().getRecipe(RecipeType.SHAPELESS, shapeless.indexOf(fina)), p, inv, fina.getResult());
		ProRecipes.getPlugin().getServer().getPluginManager().callEvent(workbenchEvent);
				
		if(old != null){
			if(!old.isSimilar(fina.getResult())){
				p.updateInventory();
			}
		}
		//System.out.println("Milliseconds spent (handleDoubles): " + (mil - System.currentTimeMillis()));
		return true;
	}
	//System.out.println("Milliseconds spent (handleDoubles): " + (mil - System.currentTimeMillis()));
	return false;
	
}
 
Example 10
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));
}