Java Code Examples for org.bukkit.Material#SHEARS

The following examples show how to use org.bukkit.Material#SHEARS . 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: WindStaff.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();

        if (p.getFoodLevel() >= 2) {
            if (p.getInventory().getItemInMainHand().getType() != Material.SHEARS && p.getGameMode() != GameMode.CREATIVE) {
                FoodLevelChangeEvent event = new FoodLevelChangeEvent(p, p.getFoodLevel() - 2);
                Bukkit.getPluginManager().callEvent(event);
                p.setFoodLevel(event.getFoodLevel());
            }

            p.setVelocity(p.getEyeLocation().getDirection().multiply(4));
            p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1);
            p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1);
            p.setFallDistance(0F);
        }
        else {
            SlimefunPlugin.getLocalization().sendMessage(p, "messages.hungry", true);
        }
    };
}
 
Example 2
Source File: BlockListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
private void handleShearedLeaves(BlockBreakEvent e){
	MainConfiguration cfg = GameManager.getGameManager().getConfiguration();
	if (!cfg.getAppleDropsFromShearing()){
		return;
	}

	if (!UniversalMaterial.isLeaves(e.getBlock().getType())){
		return;
	}

	if (e.getPlayer().getItemInHand().getType() == Material.SHEARS){
		Bukkit.getPluginManager().callEvent(new LeavesDecayEvent(e.getBlock()));
	}
}
 
Example 3
Source File: RegionInteractListener.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerClickEntityEvent(PlayerInteractEntityEvent event) {
	Player player = event.getPlayer();
	NovaPlayer nPlayer = PlayerManager.getPlayer(player);
	Entity entity = event.getEntity();
	List<String> denyDamage = Config.REGION_DENYMOBDAMAGE.getStringList();

	if(entity instanceof Player ) {
		return;
	}

	if(RegionManager.get(entity) != null) {
		if(event.getAction() == EntityUseAction.ATTACK) {
			if(!plugin.getRegionManager().canInteract(player, entity) || (!nPlayer.getPreferences().getBypass() && !nPlayer.hasPermission(GuildPermission.MOB_ATTACK))
					&& denyDamage.contains(entity.getType().name())) {
				event.setCancelled(true);
				Message.CHAT_REGION_DENY_ATTACKMOB.send(player);
			}
		}
		else if(!plugin.getRegionManager().canInteract(player, entity) || (!nPlayer.getPreferences().getBypass() && !nPlayer.hasPermission(GuildPermission.MOB_RIDE))
				&& entity.getType() == EntityType.SHEEP
				&& CompatibilityUtils.getItemInMainHand(player).getType() == Material.SHEARS) {
			event.setCancelled(true);
			Message.CHAT_REGION_DENY_RIDEMOB.send(player);
		}
	}
}
 
Example 4
Source File: StormStaff.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private void useItem(Player p, ItemStack item, Location loc) {
    loc.getWorld().strikeLightning(loc);

    if (p.getInventory().getItemInMainHand().getType() == Material.SHEARS) {
        return;
    }

    if (p.getGameMode() != GameMode.CREATIVE) {
        FoodLevelChangeEvent event = new FoodLevelChangeEvent(p, p.getFoodLevel() - 4);
        Bukkit.getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            p.setFoodLevel(event.getFoodLevel());
        }
    }

    ItemMeta meta = item.getItemMeta();
    int usesLeft = meta.getPersistentDataContainer().getOrDefault(usageKey, PersistentDataType.INTEGER, MAX_USES);

    if (usesLeft == 1) {
        p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
        item.setAmount(0);
    }
    else {
        usesLeft--;
        meta.getPersistentDataContainer().set(usageKey, PersistentDataType.INTEGER, usesLeft);

        List<String> lore = meta.getLore();
        lore.set(4, ChatColors.color("&e" + usesLeft + ' ' + (usesLeft > 1 ? "Uses" : "Use") + " &7left"));
        meta.setLore(lore);

        item.setItemMeta(meta);
    }
}
 
Example 5
Source File: GrapplingHook.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();
        UUID uuid = p.getUniqueId();

        if (!e.getClickedBlock().isPresent() && !SlimefunPlugin.getGrapplingHookListener().isGrappling(uuid)) {
            e.cancel();

            if (p.getInventory().getItemInOffHand().getType() == Material.BOW) {
                // Cancel, to fix dupe #740
                return;
            }

            ItemStack item = e.getItem();

            if (item.getType() == Material.LEAD) {
                item.setAmount(item.getAmount() - 1);
            }

            Vector direction = p.getEyeLocation().getDirection().multiply(2.0);
            Arrow arrow = p.getWorld().spawn(p.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Arrow.class);
            arrow.setShooter(p);
            arrow.setVelocity(direction);

            Bat bat = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT);
            bat.setCanPickupItems(false);
            bat.setAI(false);
            bat.setSilent(true);
            bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000));
            bat.setLeashHolder(arrow);

            boolean state = item.getType() != Material.SHEARS;
            SlimefunPlugin.getGrapplingHookListener().addGrapplingHook(p, arrow, bat, state, despawnTicks.getValue());
        }
    };
}
 
Example 6
Source File: FlagShears.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
private ItemStack createShears() {
	ItemStack shearsStack = new ItemStack(Material.SHEARS);
	
	ItemMeta meta = shearsStack.getItemMeta();
	meta.setDisplayName(getI18N().getString(Messages.Player.SHEARS));
	String lore = getI18N().getString(Messages.Player.SHEARS_LORE);
	if (!lore.isEmpty()) {
		meta.setLore(Lists.newArrayList(lore.split("\n")));
	}
	
	shearsStack.setItemMeta(meta);
	return shearsStack;
}
 
Example 7
Source File: FlagShears.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
public void onPlayerBreakBlock(PlayerBlockBreakEvent event) {
	for (SpleefPlayer player : event.getGame().getPlayers()) {
		ItemStack stack = player.getBukkitPlayer().getItemInHand();
		if (stack.getType() != Material.SHEARS) {
			continue;
		}
		
		stack.setDurability((short)0);
		player.getBukkitPlayer().setItemInHand(stack);
	}
}
 
Example 8
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
	Player player = event.getPlayer();
	ItemStack tool = player.getInventory().getItemInMainHand();

	if (Lists.WORLDS.contains(player.getWorld().getName())) {
		return;
	}

	if (event.getBlock().getType().getHardness() == 0 && !(tool.getType() == Material.SHEARS
			|| ToolType.HOE.contains(tool.getType()))) {
		return;
	}

	if (!modManager.isToolViable(tool)) {
		return;
	}

	FileConfiguration config = MineTinker.getPlugin().getConfig();

	//--------------------------------------EXP-CALCULATIONS--------------------------------------------
	if (player.getGameMode() != GameMode.CREATIVE) {
		long cooldown = MineTinker.getPlugin().getConfig().getLong("BlockExpCooldownInSeconds", 60) * 1000;
		boolean eligible = true;
		if (cooldown > 0) {
			List<MetadataValue> blockPlaced = event.getBlock().getMetadata("blockPlaced");
			for(MetadataValue val : blockPlaced) {
				if (val == null) continue;
				if (!MineTinker.getPlugin().equals(val.getOwningPlugin())) continue; //Not MTs value

				Object value = val.value();
				if (value instanceof Long) {
					long time = (long) value;
					eligible = System.currentTimeMillis() - cooldown > time;
					break;
				}
			}
		}

		if (eligible) {
			int expAmount = config.getInt("ExpPerBlockBreak");
			if (!(!config.getBoolean("ExtraExpPerBlock.ApplicableToSilkTouch")
					&& modManager.hasMod(tool, SilkTouch.instance()))) {
				expAmount += config.getInt("ExtraExpPerBlock." + event.getBlock().getType().toString());
				//adds 0 if not in found in config (negative values are also fine)
			}

			modManager.addExp(player, tool, expAmount);
		}
	}

	//-------------------------------------------POWERCHECK---------------------------------------------
	if (Power.HAS_POWER.get(player).get() && !ToolType.PICKAXE.contains(tool.getType())
			&& event.getBlock().getDrops(tool).isEmpty()
			&& event.getBlock().getType() != Material.NETHER_WART) { //Necessary for EasyHarvest NetherWard-Break

		event.setCancelled(true);
		return;
	}

	MTBlockBreakEvent breakEvent = new MTBlockBreakEvent(tool, event);
	Bukkit.getPluginManager().callEvent(breakEvent); //Event-Trigger for Modifiers
}