Java Code Examples for org.bukkit.event.inventory.CraftItemEvent#setCancelled()

The following examples show how to use org.bukkit.event.inventory.CraftItemEvent#setCancelled() . 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: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 7 votes vote down vote up
@EventHandler
public void onCraft(CraftItemEvent event) {
    if (event.isCancelled() || !(event.getWhoClicked() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getWhoClicked();
    if (Main.isPlayerInGame(player)) {
        GamePlayer gPlayer = Main.getPlayerGameProfile(player);
        if (gPlayer.getGame().getStatus() != GameStatus.RUNNING) {
            event.setCancelled(true);
        } else if (!gPlayer.getGame().getOriginalOrInheritedCrafting()) {
            event.setCancelled(true);
        }
    }
}
 
Example 2
Source File: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onCraft(CraftItemEvent event) {
    if (event.isCancelled() || !(event.getWhoClicked() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getWhoClicked();
    if (Main.isPlayerInGame(player)) {
        GamePlayer gPlayer = Main.getPlayerGameProfile(player);
        if (gPlayer.getGame().getStatus() != GameStatus.RUNNING) {
            event.setCancelled(true);
        } else if (!gPlayer.getGame().getOriginalOrInheritedCrafting()) {
            event.setCancelled(true);
        }
    }
}
 
Example 3
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onCraft(CraftItemEvent cie) {
  Player player = (Player) cie.getWhoClicked();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() == GameState.STOPPED) {
    return;
  }

  if (BedwarsRel.getInstance().getBooleanConfig("allow-crafting", false)) {
    return;
  }

  cie.setCancelled(true);
}
 
Example 4
Source File: BonusGoodieManager.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void OnCraftItemEvent(CraftItemEvent event) {
	Player player;
	try {
		player = CivGlobal.getPlayer(event.getWhoClicked().getName());
	} catch (CivException e) {
		e.printStackTrace();
		return;
	}
	
	for (ItemStack stack : event.getInventory().getMatrix()) {
		BonusGoodie goodie = CivGlobal.getBonusGoodie(stack);
		if (goodie != null) {
			CivMessage.sendError(player, "Cannot use bonus goodies in a crafting recipe.");
			event.setCancelled(true);
		}
	}
}
 
Example 5
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents crafting of EnderChest unless the player has permission
 *
 * @param event
 */
@EventHandler(priority = EventPriority.LOW)
public void onCraft(CraftItemEvent event) {
    if (DEBUG) {
        plugin.getLogger().info(event.getEventName());
    }
    Player player = (Player) event.getWhoClicked();
    if (inWorld(player) || player.getWorld().equals(ASkyBlock.getNetherWorld())) {
        if (event.getRecipe().getResult().getType() == Material.ENDER_CHEST) {
            if (!(player.hasPermission(Settings.PERMPREFIX + "craft.enderchest"))) {
                Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
                event.setCancelled(true);
            }
        }
    }
}
 
Example 6
Source File: RodlessListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onCraftItem(CraftItemEvent e) {
    ItemStack item = e.getCurrentItem();

    if (item.getType().equals(Material.FISHING_ROD)) {
        e.getWhoClicked().sendMessage(Lang.SCENARIO_RODLESS_ERROR);
        e.setCancelled(true);
    }
}
 
Example 7
Source File: BowlessListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onCraftItem(CraftItemEvent e) {
    ItemStack item = e.getCurrentItem();

    if (item.getType().equals(Material.BOW) || item.getType().equals(Material.ARROW)) {
        e.getWhoClicked().sendMessage(Lang.SCENARIO_BOWLESS_ERROR);
        e.setCancelled(true);
    }
}
 
Example 8
Source File: ShieldlessListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onCraftItem(CraftItemEvent e) {
    ItemStack item = e.getCurrentItem();

    if (item.getType() != Material.AIR && item.getType() == UniversalMaterial.SHIELD.getType()){
        e.getWhoClicked().sendMessage(Lang.SCENARIO_SHIELDLESS_ERROR);
        e.setCancelled(true);
    }
}
 
Example 9
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 10
Source File: MainListener.java    From ArmorStandTools with MIT License 5 votes vote down vote up
@EventHandler
public void onCraftItem(CraftItemEvent event) {
    if (event.isCancelled()) return;
    final Player p = (Player) event.getWhoClicked();
    CraftingInventory inventory = event.getInventory();
    for(ItemStack is : inventory.getContents()) {
        if(ArmorStandTool.isTool(is)) {
            event.setCancelled(true);
            //noinspection deprecation
            p.updateInventory();
            return;
        }
    }
}
 
Example 11
Source File: UnitItemMaterial.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onItemCraft(CraftItemEvent event) {
	try {
		CivMessage.sendError(CivGlobal.getPlayer(event.getWhoClicked().getName()), "Cannot craft with a unit item.");
	} catch (CivException e) {
		//player offline?
	}
	event.setCancelled(true);		
}
 
Example 12
Source File: UnitMaterial.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onItemCraft(CraftItemEvent event) {
	try {
		CivMessage.sendError(CivGlobal.getPlayer(event.getWhoClicked().getName()), "Cannot craft with a unit item.");
	} catch (CivException e) {
		//player offline?
	}
	event.setCancelled(true);
}
 
Example 13
Source File: WoolObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onCraftWool(CraftItemEvent event) {
    if (!this.craftable && event.getRecipe().getResult().getType().equals(Material.WOOL)
            && ((Wool) event.getRecipe().getResult().getData()).getColor().equals(color)) {
        event.setCancelled(true);
    }
}
 
Example 14
Source File: FlagSnowballs.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onCraftItem(CraftItemEvent event) {
    SpleefPlayer player = getHeavySpleef().getSpleefPlayer(event.getWhoClicked());
    if (!game.isIngame(player)) {
        return;
    }

    Recipe recipe = event.getRecipe();
    Material result = recipe.getResult().getType();

    if (result == Material.SNOW_BLOCK) {
        event.setCancelled(true);
    }
}
 
Example 15
Source File: CraftListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onCrafting(CraftItemEvent event){
	ItemStack item = event.getRecipe().getResult();
	if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()){
		return;
	}

	if (!(event.getWhoClicked() instanceof Player)){
		return;
	}

	Craft craft = CraftsManager.getCraft(item);
	if (craft == null){
		return;
	}

	Player player = (Player) event.getWhoClicked();
	GameManager gm = GameManager.getGameManager();
	UhcPlayer uhcPlayer = gm.getPlayersManager().getUhcPlayer(player);

	if(gm.getConfiguration().getEnableCraftsPermissions() && !player.hasPermission("uhc-core.craft."+craft.getName())){
		uhcPlayer.sendMessage(Lang.ITEMS_CRAFT_NO_PERMISSION.replace("%craft%", ChatColor.translateAlternateColorCodes('&', craft.getName())));
		event.setCancelled(true);
		return;
	}

	if(craft.getLimit() != -1 && (event.isShiftClick() || event.isRightClick())){
		uhcPlayer.sendMessage(Lang.ITEMS_CRAFT_LEFT_CLICK.replace("%craft%", ChatColor.translateAlternateColorCodes('&', craft.getName())));
		event.setCancelled(true);
		return;
	}

	if (craft.isReviveItem()){
		List<UhcPlayer> deadMembers = uhcPlayer.getTeam().getDeadMembers();

		if (deadMembers.isEmpty()){
			event.setCancelled(true);
			uhcPlayer.sendMessage(Lang.ITEMS_REVIVE_ERROR);
			return;
		}

		UhcPlayer revivePlayer = deadMembers.get(0);
		gm.getPlayersManager().revivePlayer(revivePlayer, craft.reviveWithInventory());

		uhcPlayer.sendMessage(Lang.ITEMS_REVIVE_SUCCESS.replace("%player%", revivePlayer.getName()));

		Bukkit.getScheduler().runTask(UhcCore.getPlugin(), () -> {
			player.setItemOnCursor(null);
			player.closeInventory();
		});
		return;
	}

	if(!uhcPlayer.addCraftedItem(craft.getName())){
		uhcPlayer.sendMessage(Lang.ITEMS_CRAFT_LIMIT.replace("%craft%", craft.getName()).replace("%limit%",""+craft.getLimit()));
		event.setCancelled(true);
	}else{
		uhcPlayer.sendMessage(Lang.ITEMS_CRAFT_CRAFTED.replace("%craft%", craft.getName()));
	}
}