Java Code Examples for org.bukkit.event.inventory.InventoryType#ANVIL

The following examples show how to use org.bukkit.event.inventory.InventoryType#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: AnvilRenameListener.java    From MineableSpawners with MIT License 6 votes vote down vote up
@EventHandler (ignoreCancelled = true)
public void onAnvilRename(InventoryClickEvent e) {
  if (e.getInventory() == null || e.getInventory().getType() == null) {
    return;
  }

  if (e.getCurrentItem() == null || e.getCurrentItem().getType() == null) {
    return;
  }

  if (e.getInventory().getType() != InventoryType.ANVIL || e.getCurrentItem().getType() != XMaterial.SPAWNER.parseMaterial()) {
    return;
  }

  if (!plugin.getConfigurationHandler().getBoolean("anvil", "prevent-anvil")) {
    return;
  }

  Player player = (Player) e.getWhoClicked();
  e.setCancelled(true);
  player.sendMessage(plugin.getConfigurationHandler().getMessage("anvil", "prevented"));
}
 
Example 2
Source File: RepairListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onAnvilGUIClick(final InventoryClickEvent event) {
    if (event.getInventory().getType() == InventoryType.ANVIL && event.getWhoClicked() instanceof Player) {
        if (!(event.getInventory() instanceof AnvilInventory)) {
            return;
        }
        final Player player = (Player) event.getWhoClicked();
        final AnvilInventory inv = (AnvilInventory) event.getInventory();
        AnvilTask task = AnvilTask.getTask(inv);
        if (task == null) {
            task = new AnvilTask(inv, player);
        }
        if (event.getRawSlot() == 2) {
            final ItemStack translatedItem = ColorHandler.getTranslatedItem(player, inv, task);
            event.setCurrentItem(translatedItem);
        }
    }
}
 
Example 3
Source File: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInventoryOpen(InventoryOpenEvent event) {
    if (event.isCancelled() || !(event.getPlayer() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getPlayer();
    if (Main.isPlayerInGame(player)) {
        GamePlayer gProfile = Main.getPlayerGameProfile(player);
        if (gProfile.getGame().getStatus() == GameStatus.RUNNING) {
            if (gProfile.isSpectator) {
                // TODO spectator compass exclude
                event.setCancelled(true);
                return;
            }
            if (event.getInventory().getType() == InventoryType.ENCHANTING
                    || event.getInventory().getType() == InventoryType.CRAFTING
                    || event.getInventory().getType() == InventoryType.ANVIL
                    || event.getInventory().getType() == InventoryType.BREWING
                    || event.getInventory().getType() == InventoryType.FURNACE
                    || event.getInventory().getType() == InventoryType.WORKBENCH) {
                if (!gProfile.getGame().getOriginalOrInheritedCrafting()) {
                    event.setCancelled(true);
                }
            }
        }
    }
}
 
Example 4
Source File: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInventoryOpen(InventoryOpenEvent event) {
    if (event.isCancelled() || !(event.getPlayer() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getPlayer();
    if (Main.isPlayerInGame(player)) {
        GamePlayer gProfile = Main.getPlayerGameProfile(player);
        if (gProfile.getGame().getStatus() == GameStatus.RUNNING) {
            if (gProfile.isSpectator) {
                // TODO spectator compass exclude
                event.setCancelled(true);
                return;
            }
            if (event.getInventory().getType() == InventoryType.ENCHANTING
                    || event.getInventory().getType() == InventoryType.CRAFTING
                    || event.getInventory().getType() == InventoryType.ANVIL
                    || event.getInventory().getType() == InventoryType.BREWING
                    || event.getInventory().getType() == InventoryType.FURNACE
                    || event.getInventory().getType() == InventoryType.WORKBENCH) {
                if (!gProfile.getGame().getOriginalOrInheritedCrafting()) {
                    event.setCancelled(true);
                }
            }
        }
    }
}
 
Example 5
Source File: CraftInventory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public InventoryType getType() {
    // Thanks to Droppers extending Dispensers, order is important.
    if (inventory instanceof InventoryCrafting) {
        return inventory.getSizeInventory() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING;
    } else if (inventory instanceof InventoryPlayer) {
        return InventoryType.PLAYER;
    } else if (inventory instanceof TileEntityDropper) {
        return InventoryType.DROPPER;
    } else if (inventory instanceof TileEntityDispenser) {
        return InventoryType.DISPENSER;
    } else if (inventory instanceof TileEntityFurnace) {
        return InventoryType.FURNACE;
    } else if (this instanceof CraftInventoryEnchanting) {
        return InventoryType.ENCHANTING;
    } else if (inventory instanceof TileEntityBrewingStand) {
        return InventoryType.BREWING;
    } else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) {
        return ((CraftInventoryCustom.MinecraftInventory) inventory).getType();
    } else if (inventory instanceof InventoryEnderChest) {
        return InventoryType.ENDER_CHEST;
    } else if (inventory instanceof InventoryMerchant) {
        return InventoryType.MERCHANT;
    } else if (inventory instanceof TileEntityBeacon) {
        return InventoryType.BEACON;
    } else if (this instanceof CraftInventoryAnvil) {
        return InventoryType.ANVIL;
    } else if (inventory instanceof IHopper) {
        return InventoryType.HOPPER;
    } else if (inventory instanceof TileEntityShulkerBox) {
        return InventoryType.SHULKER_BOX;
    } else {
        return InventoryType.CHEST;
    }
}
 
Example 6
Source File: CraftInventory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public InventoryType getType() {
    // Thanks to Droppers extending Dispensers, order is important.
    if (inventory instanceof net.minecraft.inventory.InventoryCrafting) {
        return inventory.getSizeInventory() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING;
    } else if (inventory instanceof net.minecraft.entity.player.InventoryPlayer) {
        return InventoryType.PLAYER;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityDropper) {
        return InventoryType.DROPPER;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityDispenser) {
        return InventoryType.DISPENSER;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityFurnace) {
        return InventoryType.FURNACE;
    } else if (inventory instanceof net.minecraft.inventory.ContainerEnchantTableInventory) {
        return InventoryType.ENCHANTING;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityBrewingStand) {
        return InventoryType.BREWING;
    } else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) {
        return ((CraftInventoryCustom.MinecraftInventory) inventory).getType();
    } else if (inventory instanceof net.minecraft.inventory.InventoryEnderChest) {
        return InventoryType.ENDER_CHEST;
    } else if (inventory instanceof net.minecraft.inventory.InventoryMerchant) {
        return InventoryType.MERCHANT;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityBeacon) {
        return InventoryType.BEACON;
    } else if (inventory instanceof net.minecraft.inventory.ContainerRepairInventory) {
        return InventoryType.ANVIL;
    } else if (inventory instanceof net.minecraft.tileentity.IHopper) {
        return InventoryType.HOPPER;
    } else {
        return InventoryType.CHEST;
    }
}
 
Example 7
Source File: VanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onAnvil(InventoryClickEvent e) {
    if (e.getRawSlot() == 2 && e.getInventory().getType() == InventoryType.ANVIL && e.getWhoClicked() instanceof Player) {
        ItemStack item1 = e.getInventory().getContents()[0];
        ItemStack item2 = e.getInventory().getContents()[1];

        if (checkForUnallowedItems(item1, item2)) {
            e.setResult(Result.DENY);
            SlimefunPlugin.getLocalization().sendMessage((Player) e.getWhoClicked(), "anvil.not-working", true);
        }
    }
}
 
Example 8
Source File: ItemCraftListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onClick(InventoryClickEvent event) {
    if (event.getInventory().getType() == InventoryType.ANVIL && Utils.getCrystals(event.getCurrentItem()) != 0) {
        event.setCancelled(true);
    }
}
 
Example 9
Source File: TrMenuNmsModern.java    From TrMenu with MIT License 4 votes vote down vote up
private Containers<?> getByInventory(Inventory inventory) {
    InventoryType type = inventory.getType();
    int size = inventory.getSize();
    if (type == InventoryType.CHEST) {
        if (size == 9) {
            return Containers.GENERIC_9X1;
        } else if (size == 18) {
            return Containers.GENERIC_9X2;
        } else if (size == 27) {
            return Containers.GENERIC_9X3;
        } else if (size == 36) {
            return Containers.GENERIC_9X4;
        } else if (size == 45) {
            return Containers.GENERIC_9X5;
        } else {
            return Containers.GENERIC_9X6;
        }
    } else if (type == InventoryType.DROPPER || type == InventoryType.DISPENSER) {
        return Containers.GENERIC_3X3;
    } else if (type == InventoryType.BARREL || type == InventoryType.ENDER_CHEST) {
        return Containers.GENERIC_9X3;
    } else if (type == InventoryType.CRAFTING || type == InventoryType.WORKBENCH) {
        return Containers.CRAFTING;
    } else if (type == InventoryType.HOPPER) {
        return Containers.HOPPER;
    } else if (type == InventoryType.LOOM) {
        return Containers.LOOM;
    } else if (type == InventoryType.ANVIL) {
        return Containers.ANVIL;
    } else if (type == InventoryType.BEACON) {
        return Containers.BEACON;
    } else if (type == InventoryType.SMOKER) {
        return Containers.SMOKER;
    } else if (type == InventoryType.BREWING) {
        return Containers.BREWING_STAND;
    } else if (type == InventoryType.FURNACE) {
        return Containers.FURNACE;
    } else if (type == InventoryType.LECTERN) {
        return Containers.LECTERN;
    } else if (type == InventoryType.MERCHANT) {
        return Containers.MERCHANT;
    } else if (type == InventoryType.ENCHANTING) {
        return Containers.ENCHANTMENT;
    } else if (type == InventoryType.GRINDSTONE) {
        return Containers.GRINDSTONE;
    } else if (type == InventoryType.CARTOGRAPHY) {
        return Containers.CARTOGRAPHY_TABLE;
    } else if (type == InventoryType.SHULKER_BOX) {
        return Containers.SHULKER_BOX;
    } else if (type == InventoryType.STONECUTTER) {
        return Containers.STONECUTTER;
    } else if (type == InventoryType.BLAST_FURNACE) {
        return Containers.BLAST_FURNACE;
    } else {
        return Containers.GENERIC_3X3;
    }
}
 
Example 10
Source File: CustomItemManager.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
public static void initialize() {
	// Find NBTEditor plugin...
	if (_plugin != null || (_plugin = Bukkit.getPluginManager().getPlugin("NBTEditor")) == null) {
		return;
	}

	Permission mainPermission = new Permission("nbteditor.customitems.*");
	mainPermission.addParent(UtilsMc.getRootPermission(_plugin), true);

	_usePermission = new Permission("nbteditor.customitems.use.*");
	_usePermission.addParent(mainPermission, true);
	Bukkit.getPluginManager().addPermission(_usePermission);

	_worldOverridePermission = new Permission("nbteditor.customitems.world-override.*");
	_worldOverridePermission.addParent(mainPermission, true);
	Bukkit.getPluginManager().addPermission(_worldOverridePermission);

	_mainListener = new Listener() {
		@EventHandler
		private void onInventoryClick(InventoryClickEvent event) {
			if (event.getInventory().getType() == InventoryType.ANVIL && getCustomItem(event.getCurrentItem()) != null) {
				event.setCancelled(true);
			}
		}
		@EventHandler
		private void onPluginDisable(PluginDisableEvent event) {
			Plugin plugin = event.getPlugin();
			if (plugin == _plugin) {
				HandlerList.unregisterAll(_mainListener);
				HandlerList.unregisterAll(_listener);
				_plugin = null;
				_mainListener = null;
				_container.clear();
				_configsByGroup.clear();
			} else {
				_container.remove(plugin);
			}
		}
	};

	Bukkit.getPluginManager().registerEvents(_mainListener, _plugin);
	Bukkit.getPluginManager().registerEvents(_listener, _plugin);
}