Java Code Examples for org.bukkit.Material#ARROW

The following examples show how to use org.bukkit.Material#ARROW . 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: ScenarioManager.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
public Inventory getScenarioEditInventory(){

        Inventory inv = Bukkit.createInventory(null,6*ROW, Lang.SCENARIO_GLOBAL_INVENTORY_EDIT);

        // add edit item
        ItemStack back = new ItemStack(Material.ARROW);
        ItemMeta itemMeta = back.getItemMeta();
        itemMeta.setDisplayName(Lang.SCENARIO_GLOBAL_ITEM_BACK);
        back.setItemMeta(itemMeta);
        inv.setItem(5*ROW+8,back);

        for (Scenario scenario : Scenario.values()){
            if (!scenario.isCompatibleWithVersion()){
                continue;
            }

            ItemStack scenarioItem = scenario.getScenarioItem();
            if (isActivated(scenario)){
                scenarioItem.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
                scenarioItem.setAmount(2);
            }
            inv.addItem(scenarioItem);
        }

        return inv;
    }
 
Example 2
Source File: SentinelItemHelper.java    From Sentinel with MIT License 6 votes vote down vote up
/**
 * Gets the correct ArrowItem type for the NPC based on inventory items (can be null if the NPC needs ammo but has none).
 */
public ItemStack getArrow() {
    if (!getNPC().hasTrait(Inventory.class)) {
        return sentinel.needsAmmo ? null : new ItemStack(Material.ARROW, 1);
    }
    Inventory inv = getNPC().getTrait(Inventory.class);
    ItemStack[] items = inv.getContents();
    for (ItemStack item : items) {
        if (item != null) {
            Material mat = item.getType();
            if (mat == Material.ARROW
                    || (SentinelVersionCompat.v1_9 && (mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW))
                    || (SentinelVersionCompat.v1_14 && mat == Material.FIREWORK_ROCKET)) {
                return item.clone();
            }
        }
    }
    return sentinel.needsAmmo ? null : new ItemStack(Material.ARROW, 1);
}
 
Example 3
Source File: SentinelItemHelper.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Takes an arrow from the NPC's inventory.
 */
public void takeArrow() {
    if (!getNPC().hasTrait(Inventory.class)) {
        return;
    }
    Inventory inv = getNPC().getTrait(Inventory.class);
    ItemStack[] items = inv.getContents();
    for (int i = 0; i < items.length; i++) {
        ItemStack item = items[i];
        if (item != null) {
            Material mat = item.getType();
            if (mat == Material.ARROW
                    || (SentinelVersionCompat.v1_9 && (mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW))
                    || (SentinelVersionCompat.v1_14 && mat == Material.FIREWORK_ROCKET)) {
                if (item.getAmount() > 1) {
                    item.setAmount(item.getAmount() - 1);
                    items[i] = item;
                    inv.setContents(items);
                    return;
                }
                else {
                    items[i] = null;
                    inv.setContents(items);
                    return;
                }
            }
        }
    }
}
 
Example 4
Source File: Archer.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void arrowCraftingStopper(CraftItemEvent event)
{
	if(event.getRecipe().getResult().getType() == Material.ARROW && event.getRecipe().getResult().getAmount() == 3)
	{
		AnniPlayer player = AnniPlayer.getPlayer(event.getWhoClicked().getUniqueId());
		if(player != null && (player.getKit() == null || !player.getKit().equals(this)))
			event.setCancelled(true);
	}
}
 
Example 5
Source File: ArrowRainEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public ArrowRainEvent(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 = "ArrowRainEvent";
    	slot = 2;
    	material = new ItemStack(Material.ARROW, 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.per2Tick = fc.getInt("events." + eventName + ".spawnPer2Tick");
       }
}
 
Example 6
Source File: FlagBowspleef.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
public void onGameStart(GameStartEvent event) {
	Game game = event.getGame();
	
	ItemStack arrow = new ItemStack(Material.ARROW);
	
	for (SpleefPlayer player : game.getPlayers()) {
		Inventory inventory = player.getBukkitPlayer().getInventory();
		inventory.addItem(getBowItemstack());
		inventory.addItem(arrow);
		
		player.getBukkitPlayer().updateInventory();
	}
}
 
Example 7
Source File: MultiShot.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onShoot(ProjectileLaunchEvent event) {
	if (!this.isAllowed()) {
		return;
	}

	Projectile arrow = event.getEntity();

	if (!(arrow instanceof Arrow)) {
		return;
	}

	if (!(arrow.getShooter() instanceof Player)) {
		return;
	}

	Player player = (Player) arrow.getShooter();

	if (!player.hasPermission("minetinker.modifiers.multishot.use")) {
		return;
	}

	ItemStack tool = player.getInventory().getItemInMainHand();

	if (ToolType.CROSSBOW.contains(tool.getType()) && getConfig().getBoolean("UseEnchantOnCrossbow")) {
		return;
	}

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

	int modLevel = modManager.getModLevel(tool, this);

	if (modLevel <= 0) {
		return;
	}

	Vector vel = arrow.getVelocity().clone();
	Location loc = arrow.getLocation().clone();

	boolean hasInfinity = modManager.hasMod(tool, Infinity.instance());

	boolean hasFiery = modManager.hasMod(tool, Fiery.instance()) && player.hasPermission("minetinker.modifiers.fiery.use");
	ChatWriter.logModifier(player, event, this, tool,
			Fiery.instance().getKey() + "(" + hasFiery + ")",
			Infinity.instance().getKey() + "(" + hasInfinity + ")");

	for (int i = 1; i <= modLevel; i++) {
		if (!player.getGameMode().equals(GameMode.CREATIVE)) {
			if (!hasInfinity && needsArrows) {
				if (!player.getInventory().contains(Material.ARROW)) {
					break;
				}

				for (ItemStack item : player.getInventory().getContents()) {
					if (item == null) {
						continue;
					}

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

		Bukkit.getScheduler().runTaskLater(MineTinker.getPlugin(), () -> {
			Arrow arr = loc.getWorld().spawnArrow(loc, vel, (float) vel.length(), (float) spread);
			if(hasFiery) arr.setFireTicks(2000);
			arr.setShooter(player);

			if (hasInfinity || player.getGameMode().equals(GameMode.CREATIVE)) {
				arr.setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY);
			}

			arr.setCritical(((Arrow) arrow).isCritical());
			arr.setDamage(((Arrow) arrow).getDamage());
		}, i);
	}
}
 
Example 8
Source File: QuestItem.java    From BetonQuest with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return the material
 */
public Material getMaterial() {
    Material material = selector.getMaterial();
    return material != null ? material : Material.ARROW;
}