本文整理汇总了Java中org.bukkit.inventory.AnvilInventory类的典型用法代码示例。如果您正苦于以下问题:Java AnvilInventory类的具体用法?Java AnvilInventory怎么用?Java AnvilInventory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnvilInventory类属于org.bukkit.inventory包,在下文中一共展示了AnvilInventory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRepair
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@EventHandler
public void onRepair(InventoryClickEvent event) {
if(event.isCancelled() || !(event.getWhoClicked() instanceof Player) || !(event.getInventory() instanceof AnvilInventory))
return;
InventoryView view = event.getView();
int rawSlot = event.getRawSlot();
if(rawSlot != view.convertSlot(rawSlot) || rawSlot != 2)
return;
ItemStack item = event.getInventory().getItem(0);
if(!plugin.getAbilityManager().hasAbility(item) || !plugin.getAbilityManager().isTemporaryItem(item))
return;
Ability ability = plugin.getAbilityManager().getAbility(item);
event.getInventory().setItem(0, plugin.getAbilityManager().removeItemLore(item, ability));
event.setCancelled(true);
}
示例2: onInventoryClick
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e) {
// Only looking for anvils
if (!(e.getInventory() instanceof AnvilInventory)) {
return;
}
ItemStack item = e.getCurrentItem();
// Only looking for kits
if (!item.hasItemMeta()) {
return;
}
ItemMeta meta = item.getItemMeta();
if (meta.hasDisplayName() && meta.hasLore() && meta.getDisplayName().startsWith("Kit ")) {
if (meta.getLore().contains(ChestKitsPlugin.LORE_KEY)) {
e.setCancelled(true);
}
}
}
示例3: onItemRename
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void onItemRename(InventoryClickEvent e) {
if (e.isCancelled()) {
return;
}
if (!mythicDrops.getConfigSettings().isRepairingEnabled()) {
return;
}
HumanEntity ent = e.getWhoClicked();
if (!(ent instanceof Player)) {
return;
}
Inventory inv = e.getInventory();
if (!(inv instanceof AnvilInventory)) {
return;
}
ItemStack fis = inv.getItem(0);
ItemStack sis = inv.getItem(1);
if (mythicDrops.getConfigSettings().isAllowRepairingUsingAnvil()) {
preventGems(fis, sis, e);
} else {
preventTiersAndGems(fis, sis, e);
}
}
示例4: get
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@Override
@Nullable
protected Number[] get(Event e) {
try {
AnvilInventory a = ((PrepareAnvilEvent) e).getInventory();
return new Number[] { a.getRepairCost() };
} catch (NullPointerException ex) {
return new Number[] { 0 };
}
}
示例5: canEnchant
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@EventHandler(priority= EventPriority.LOW, ignoreCancelled=true)
public void canEnchant(InventoryClickEvent event) {
if (!(event.getInventory() instanceof AnvilInventory)) {
return;
}
if (event.getSlotType() != InventoryType.SlotType.RESULT) {
return;
}
ItemStack item = event.getInventory().getItem(0);
ItemStack item2 = event.getInventory().getItem(1);
if (!PowerUtils.isPowerTool(item)) {
return;
}
if (item2 == null) {
return;
}
if (item2.getType() != Material.ENCHANTED_BOOK) {
switch (item2.getType()) {
case LEATHER_HELMET:
case LEATHER_LEGGINGS:
case LEAVES:
return;
}
if (PowerUtils.isPowerTool(item2)) {
if (!item.getEnchantments().isEmpty()) {}
} else {
event.setCancelled(true);
return;
}
}
if (!PowerUtils.checkEnchantPermission((Player) event.getWhoClicked(), item.getType())) {
event.setCancelled(true);
}
}
示例6: onInventoryChange
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@EventHandler(priority = EventPriority.NORMAL)
public void onInventoryChange(InventoryClickEvent e){
Inventory inven = e.getInventory();
if(inven instanceof AnvilInventory){
if(e.getRawSlot() == 2){
ItemStack item = e.getCurrentItem();
if(item != null){
if(item.getType().equals(Material.ENDER_PORTAL_FRAME)){
ItemMeta meta = item.getItemMeta();
if(meta != null){
if(meta.hasDisplayName()){
String displayName = meta.getDisplayName();
PortalFile pf = new PortalFile();
if(pf.contains(displayName)){
e.setCancelled(true);
((Player) e.getWhoClicked()).sendMessage(messageData.get("portalblock.alreadyexist")
.replace("%name%", displayName));
}
}
}
}
}
}
}
}
示例7: onInventoryClick
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
/**
* - Workaround to fix the crafting grid being not updated when the item is
* taken from the grid.
* <p>
* - Used to prevent our blocks to be renamed using an anvil.
* <p>
* - Used to allow our tools to be enchanted (ensure the name is kept).
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent ev)
{
if (ev.getInventory() instanceof CraftingInventory && ev.getSlot() == 0)
{
InventoryUtils.updateInventoryLater(ev.getInventory());
}
// Disable Anvil overrides if not using item names.
else if (ev.getInventory() instanceof AnvilInventory && BBConfig.USE_ITEM_NAMES_FALLBACK.get())
{
ItemStack item = ev.getInventory().getItem(0);
ItemStack result = ev.getInventory().getItem(2);
if (item == null) return;
BelovedBlock block = BelovedBlocks.getBelovedBlocksManager().getFromItem(item);
// Items cannot be renamed
if(block != null)
{
ev.getInventory().setItem(2, new ItemStack(Material.AIR, 0));
return;
}
BelovedTool tool = BelovedBlocks.getToolsManager().getFromItem(item);
// Players can add enchantments to the tools.
if(tool != null)
{
ItemUtils.setDisplayName(result, tool.getDisplayName());
ev.getInventory().setItem(2, result);
}
}
}
示例8: getMerger
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
private EnchantmentMerger getMerger(final AnvilInventory anvil) {
final ItemStack result = select(anvil.getItem(0), anvil.getItem(1), true).clone();
final ItemStack supplement = select(anvil.getItem(0), anvil.getItem(1), false);
return new EnchantmentMerger()
.merge(result, false)
.merge(supplement, true);
}
示例9: onClick
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@EventHandler
public void onClick(InventoryClickEvent event) {
if (event.getInventory().getType() == InventoryType.ANVIL && event.getRawSlot() == 2) {
final AnvilInventory anvil = (AnvilInventory) event.getInventory();
if (anvil.getRepairCost() == 0
&& isPresent(anvil.getItem(2))
&& !isPresent(event.getWhoClicked().getItemOnCursor()) || !event.getAction().name().startsWith("PICKUP")) {
final Player player = (Player)event.getWhoClicked();
if (player.getGameMode() == GameMode.CREATIVE || checkLevels(player, anvil)) {
player.setItemOnCursor(anvil.getItem(2));
anvil.clear();
}
}
}
}
示例10: checkLevels
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
private boolean checkLevels(final Player player, final AnvilInventory anvil) {
final EnchantmentMerger merger = getMerger(anvil);
if (player.getLevel() >= merger.getCost()) {
player.setLevel(player.getLevel() - merger.getCost());
return true;
}
return false;
}
示例11: AnvilRenameItemEvent
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
/**
* Constructor.
*
* @param player The player.
* @param anvilInventory The anvil inventory.
* @param item The item being renamed.
* @param newName The new name.
* @param oldName The old name.
*/
public AnvilRenameItemEvent(Player player, AnvilInventory anvilInventory,
ItemStack item, String newName, @Nullable String oldName) {
_player = player;
_anvilInventory = anvilInventory;
_item = item;
_newName = newName;
_oldName = oldName;
}
示例12: onPlayerInventoryClick
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@EventHandler
public void onPlayerInventoryClick(InventoryClickEvent event)
{
if(plugin.isXpBar())
{
/**
* This part of code, is not by me.(como89)
* Credit : Zelnehlun
*/
if(!event.isCancelled())
{
HumanEntity human = event.getWhoClicked();
if(human instanceof Player)
{
Inventory inv = event.getInventory();
if(inv instanceof AnvilInventory)
{
InventoryView view = event.getView();
int rawSlot = event.getRawSlot();
if(rawSlot == view.convertSlot(rawSlot))
{
if(rawSlot == 2)
{
ItemStack item = event.getCurrentItem();
if(item != null)
{
event.setCancelled(true);
}
}
}
}
}
}
/**
* END part of code
*/
}
}
示例13: onInventoryClick
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@EventHandler
public void onInventoryClick(InventoryClickEvent e)
{
Inventory inv = e.getInventory();
if(inv instanceof AnvilInventory)
{
AnvilInventory anvil = (AnvilInventory)inv;
InventoryView view = e.getView();
int rawSlot = e.getRawSlot();
// compare raw slot to the inventory view to make sure we are in the upper inventory
if(rawSlot == view.convertSlot(rawSlot))
{
// 2 = result slot
if(rawSlot == 2)
{
// item in the left slot
ItemStack item = anvil.getContents()[0];
if(item != null)
{
if
(
item.getType() == Material.GOLD_AXE
|| item.getType() == Material.GOLD_PICKAXE
|| item.getType() == Material.GOLD_SPADE
|| item.getType() == Material.GOLD_HOE
|| item.getType() == Material.GOLD_SWORD
|| item.getType() == Material.WOOD_AXE
|| item.getType() == Material.WOOD_PICKAXE
|| item.getType() == Material.WOOD_SPADE
|| item.getType() == Material.WOOD_HOE
|| item.getType() == Material.WOOD_SWORD
)
{
e.setCancelled(true);
e.getWhoClicked().closeInventory();
e.getWhoClicked().sendMessage(ChatColor.RED + Survival.Words.get("You cannot rename or repair ") + item.getItemMeta().getDisplayName() + ChatColor.RED + Survival.Words.get("period"));
}
}
}
}
}
}
示例14: onInventoryClick
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryClick(InventoryClickEvent e){
if (e.isCancelled() || !(e.getWhoClicked() instanceof Player)) {
return;
}
if (!(e.getInventory() instanceof AnvilInventory)) {
return;
}
Player p = (Player) e.getWhoClicked();
if (!QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getWorlds().contains(
p.getWorld().getName())) {
return;
}
AnvilInventory inv = (AnvilInventory) e.getInventory();
int rawSlot = e.getSlot();
if(rawSlot != 2){
return;
}
if (inv.getItem(2) == null) {
return;
}
//trying to finish it. Just compare name from slot 0 to slot 2 and make sure the same
ItemStack left = inv.getItem(0);
ItemStack right = inv.getItem(2);
//first check: left has nothing, right should have nothing
if ( (!left.hasItemMeta() && right.hasItemMeta() && right.getItemMeta().hasDisplayName())) {
e.setCancelled(true);
return;
}
//second check: the name has changed
if (left.hasItemMeta() && left.getItemMeta().hasDisplayName()) { //we odn't need to make sure the right does cause it always will
if (!left.getItemMeta().getDisplayName().equals(right.getItemMeta().getDisplayName())) {
e.setCancelled(true);
return;
}
}
//last check: left has meta, no name but right does
if (left.hasItemMeta() && !left.getItemMeta().hasDisplayName() && right.getItemMeta().hasDisplayName()) {
e.setCancelled(true);
return;
}
}
示例15: init
import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] e, int arg1, Kleenean arg2, ParseResult arg3) {
inventory = (Expression<AnvilInventory>) e[0];
return true;
}