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

The following examples show how to use org.bukkit.event.inventory.InventoryType#ENCHANTING . 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 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 2
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 3
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 4
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 5
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 6
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void openInventory(InventoryOpenEvent ioe) {
  if (!(ioe.getPlayer() instanceof Player)) {
    return;
  }

  Player player = (Player) ioe.getPlayer();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

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

  if (ioe.getInventory().getType() == InventoryType.ENCHANTING
      || ioe.getInventory().getType() == InventoryType.BREWING
      || (ioe.getInventory().getType() == InventoryType.CRAFTING
      && !BedwarsRel.getInstance().getBooleanConfig("allow-crafting", false))) {
    ioe.setCancelled(true);
    return;
  } else if (ioe.getInventory().getType() == InventoryType.CRAFTING
      && BedwarsRel.getInstance().getBooleanConfig("allow-crafting", false)) {
    return;
  }

  if (game.isSpectator(player)) {
    if (ioe.getInventory().getName().equals(BedwarsRel._l(player, "ingame.spectator"))) {
      return;
    }

    ioe.setCancelled(true);
  }

  if (ioe.getInventory().getHolder() == null) {
    return;
  }

  if (game.getRegion().getInventories().contains(ioe.getInventory())) {
    return;
  }

  game.getRegion().addInventory(ioe.getInventory());
}