Java Code Examples for org.bukkit.event.inventory.InventoryOpenEvent#getPlayer()

The following examples show how to use org.bukkit.event.inventory.InventoryOpenEvent#getPlayer() . 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: PlayerEventListener.java    From Hawk with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryOpenServerSide(InventoryOpenEvent e) {
    HumanEntity hE = e.getPlayer();
    if(!(hE instanceof Player))
        return;

    //Fixes issues regarding the client not releasing item usage when a server inventory is opened.
    //Consumables may not have this issue.
    HawkPlayer pp = hawk.getHawkPlayer((Player) hE);
    pp.sendSimulatedAction(new Runnable() {
        @Override
        public void run() {
            pp.setBlocking(false);
            pp.setPullingBow(false);
            pp.setInventoryOpen((byte)2);
        }
    });
}
 
Example 2
Source File: LWCPlayerListener.java    From Modern-LWC with MIT License 6 votes vote down vote up
@EventHandler
public void storageMinecraftInventoryOpen(InventoryOpenEvent event) {
    InventoryHolder holder = event.getInventory().getHolder();
    Player player = (Player) event.getPlayer();
    if ((!(holder instanceof StorageMinecart)) && (!(holder instanceof HopperMinecart))) {
        return;
    }
    Entity entity = (Entity) holder;
    if (plugin.getLWC().isProtectable(entity.getType())) {
        if (!plugin.getLWC().hasPermission(player, "lwc.protect")
                && plugin.getLWC().hasPermission(player, "lwc.deny") && !plugin.getLWC().isAdmin(player)
                && !plugin.getLWC().isMod(player)) {
            plugin.getLWC().sendLocale(player, "protection.interact.error.blocked");
            event.setCancelled(true);
            return;
        }
        if (onPlayerEntityInteract((Player) event.getPlayer(), entity, event.isCancelled())) {
            event.setCancelled(true);
        }
    }
}
 
Example 3
Source File: WorthListener.java    From factions-top with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void checkWorth(InventoryOpenEvent event) {
    // Do nothing if a player did not open the inventory or if chest events
    // are disabled.
    if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) {
        return;
    }

    Inventory inventory = event.getInventory();

    // Set all default worth values for this chest.
    if (inventory.getHolder() instanceof DoubleChest) {
        DoubleChest chest = (DoubleChest) inventory.getHolder();
        checkWorth((Chest) chest.getLeftSide());
        checkWorth((Chest) chest.getRightSide());
    }

    if (inventory.getHolder() instanceof Chest) {
        checkWorth((Chest) inventory.getHolder());
    }
}
 
Example 4
Source File: ListenerInventories.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onOpenInventory(InventoryOpenEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("inventories.close-on-tag")) return;

    HumanEntity human = e.getPlayer();
    if(!(human instanceof Player)) return;

    Player player = (Player) human;
    ICombatManager manager = this.plugin.getCombatManager();
    if(!manager.isInCombat(player)) return;

    e.setCancelled(true);
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.inventory.no-opening");
    this.plugin.sendMessage(player, message);
}
 
Example 5
Source File: ExploitEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onVillagerTrade(InventoryOpenEvent event) {
    if (!plugin.getWorldManager().isSkyAssociatedWorld(event.getPlayer().getWorld())) {
        return;
    }
    if (!(event.getPlayer() instanceof Player)) {
        return;
    }
    if (!anyVillagerTradingAllowed && event.getInventory().getType() == InventoryType.MERCHANT) {
        event.setCancelled(true);
        event.getPlayer().sendMessage(tr("\u00a7eVillager-trading isn't allowed."));
        return;
    }
    if (visitorVillagerTradingProtected
            && event.getPlayer() instanceof Player
            && !(event.getPlayer().hasPermission("usb.mod.bypassprotection"))
            && event.getInventory().getType() == InventoryType.MERCHANT
            && !plugin.playerIsOnIsland((Player)event.getPlayer())) {
        event.setCancelled(true);
        event.getPlayer().sendMessage(tr("\u00a7eTrading isn't allowed on other islands. Do it in spawn."));
    }
}
 
Example 6
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryOpenEvent(InventoryOpenEvent event) {
	if (event.getInventory() instanceof DoubleChestInventory) {
		DoubleChestInventory doubleInv = (DoubleChestInventory)event.getInventory();
					
		Chest leftChest = (Chest)doubleInv.getHolder().getLeftSide();			
		/*Generate a new player 'switch' event for the left and right chests. */
		PlayerInteractEvent interactLeft = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, leftChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactLeft);
		
		if (interactLeft.isCancelled()) {
			event.setCancelled(true);
			return;
		}
		
		Chest rightChest = (Chest)doubleInv.getHolder().getRightSide();
		PlayerInteractEvent interactRight = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, rightChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactRight);
		
		if (interactRight.isCancelled()) {
			event.setCancelled(true);
			return;
		}			
	}
}
 
Example 7
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 8
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 9
Source File: RewardListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInventoryOpen(InventoryOpenEvent event) {
    if (!(event.getPlayer() instanceof Player)) {
        return;
    }

    InventoryView inventory = event.getView();

    DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(event.getPlayer().getWorld());

    if (gameWorld == null) {
        return;
    }

    if (!(ContainerAdapter.isValidContainer(inventory.getTopInventory()))) {
        return;
    }

    for (RewardChest rewardChest : gameWorld.getRewardChests()) {
        if (!rewardChest.getBlock().equals(ContainerAdapter.getHolderBlock(inventory.getTopInventory().getHolder()))) {
            continue;
        }

        rewardChest.onOpen((Player) event.getPlayer());
        event.setCancelled(true);
        break;
    }

    if (!plugin.getMainConfig().getOpenInventories() && !DPermission.hasPermission(event.getPlayer(), DPermission.INSECURE)) {
        World world = event.getPlayer().getWorld();
        if (event.getInventory().getType() != InventoryType.CREATIVE && plugin.getEditWorld(world) != null) {
            event.setCancelled(true);
        }
    }
}
 
Example 10
Source File: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInventoryOpen(InventoryOpenEvent event) {
    final HumanEntity player = event.getPlayer();

    if (listenerService.shouldCancelEvent(player)
        && !isInventoryWhitelisted(event.getView())) {
        event.setCancelled(true);

        /*
         * @note little hack cause InventoryOpenEvent cannot be cancelled for
         * real, cause no packet is sent to server by client for the main inv
         */
        bukkitService.scheduleSyncDelayedTask(player::closeInventory, 1);
    }
}
 
Example 11
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());
}