Java Code Examples for org.bukkit.entity.Player#closeInventory()

The following examples show how to use org.bukkit.entity.Player#closeInventory() . 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: CreativeModeListener.java    From ShopChest with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent e) {
    HumanEntity entity = e.getWhoClicked();
    if (!(entity instanceof Player))
        return;

    Player p = (Player) entity;

    ClickType clickType = ClickType.getPlayerClickType(p);
    if (clickType instanceof SelectClickType) {
        e.setCancelled(true);

        if (e.getCursor() == null || e.getCursor().getType() == Material.AIR)
            return;

        ClickType.removePlayerClickType(p);
        ((SelectClickType) clickType).setItem(e.getCursor());
        p.closeInventory();

        p.sendMessage(LanguageUtils.getMessage(Message.ITEM_SELECTED,
                new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(e.getCursor()))));
        plugin.getShopCommand().createShopAfterSelected(p, (SelectClickType) clickType);
    }
}
 
Example 2
Source File: UHPluginListener.java    From KTP with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent ev) {
	if (ev.getInventory().getName().equals("- Teams -")) {
		Player pl = (Player) ev.getWhoClicked();
		ev.setCancelled(true);
		if (ev.getCurrentItem().getType() == Material.DIAMOND) {
			pl.closeInventory();
			p.getConversationFactory("teamPrompt").buildConversation(pl).begin();
		} else if (ev.getCurrentItem().getType() == Material.BEACON) {
			pl.closeInventory();
			Conversation c = p.getConversationFactory("playerPrompt").buildConversation(pl);
			c.getContext().setSessionData("nomTeam", ChatColor.stripColor(ev.getCurrentItem().getItemMeta().getDisplayName()));
			c.getContext().setSessionData("color", p.getTeam(ChatColor.stripColor(ev.getCurrentItem().getItemMeta().getDisplayName())).getChatColor());
			c.begin();
		}
	}
}
 
Example 3
Source File: GizmoUtils.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void purchaseGizmo(final Player player, final Gizmo gizmo) {
    player.closeInventory();

    final PlayerId playerId = Users.playerId(player);

    syncExecutor.callback(
        userService.purchaseGizmo(playerId, new PurchaseGizmoRequest(gizmo.getIdentifier(), gizmo.getCost())),
        CommandFutureCallback.onSuccess(player, obj -> {
            if(!player.isOnline()) return;

            Bukkit.getPluginManager().callEvent(new PlayerRecieveRaindropsEvent(player, -gizmo.getCost(), 100, new Component("Purchased gizmo")));
            player.addAttachment(Lobby.get(), gizmo.getPermissionNode(), true);
            Gizmos.purchasingMap.remove(player);
            setGizmo(player, gizmo, false);

            player.sendMessage(ChatColor.GREEN + LobbyTranslations.get().t(
                "gizmo.purchased.success",
                player,
                gizmo.getColoredName(player) + ChatColor.GREEN,
                String.valueOf(gizmo.getCost()) + ChatColor.AQUA
            ));
        })
    );
}
 
Example 4
Source File: IridiumSkyblock.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onDisable() {
    try {
        super.onDisable();

        saveData();

        for (Player p : Bukkit.getOnlinePlayers()) {
            p.closeInventory();
        }

        getLogger().info("-------------------------------");
        getLogger().info("");
        getLogger().info(getDescription().getName() + " Disabled!");
        getLogger().info("");
        getLogger().info("-------------------------------");
    } catch (Exception e) {
        sendErrorMessage(e);
    }
}
 
Example 5
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
private void onClickRestartMenu(final InventoryClickEvent event, final Player p, ItemMeta meta, int slotIndex, ItemStack currentItem) {
    event.setCancelled(true);
    if (slotIndex == 0) {
        p.closeInventory();
        p.openInventory(createMainMenu(p));
    } else if (currentItem != null && meta != null && meta.getDisplayName() != null) {
        String schemeName = stripFormatting(meta.getDisplayName());
        IslandPerk islandPerk = plugin.getPerkLogic().getIslandPerk(schemeName);
        if (plugin.getPerkLogic().getSchemes(p).contains(schemeName) && p.hasPermission(islandPerk.getPermission())) {
            if (plugin.getConfirmHandler().millisLeft(p, "/is restart") > 0) {
                p.closeInventory();
                p.performCommand("island restart " + schemeName);
            } else {
                p.performCommand("island restart " + schemeName);
                updateRestartMenuTimer(p, event.getInventory());
            }
        }
    }
}
 
Example 6
Source File: ItemFlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
void onPluginDisable(PluginDisableEvent event) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "Is PluginDisableEvent event.");
    for (Player play : event.getPlugin().getServer().getOnlinePlayers()) {
        play.closeInventory();
    }
}
 
Example 7
Source File: LobbyListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
 public void onInventoryClick(final InventoryClickEvent e) {
 	Player player = (Player) e.getWhoClicked();
 	if (Util.get().isSpawnWorld(player.getWorld())) {
 		if (SkyWarsReloaded.getCfg().protectLobby()) {
         	if (!player.hasPermission("sw.alterlobby") && !SkyWarsReloaded.getIC().has(player)) {
         		e.setCancelled(true);
         	}
 		}
     	int rawSlot = e.getRawSlot();
if (e.getInventory().equals(joinMenu) && rawSlot < joinMenu.getSize() && rawSlot >= 0) {
	e.setCancelled(true);
	SWRServer server = SWRServer.getServerByDisplayName(ChatColor.stripColor(SkyWarsReloaded.getNMS().getItemName(e.getCurrentItem())));
             if (server == null) {
                 return;
             }
             
             if (server.getMatchState() != MatchState.WAITINGSTART) {
             	Util.get().playSound(player, player.getLocation(), SkyWarsReloaded.getCfg().getErrorSound(), 1, 1);
             	return;
             }
             
             if (player.hasPermission("sw.join")) {
              if (player!= null) {
              	if (server.getMatchState() == MatchState.WAITINGSTART && server.getPlayerCount() < server.getMaxPlayers()) {
               	player.closeInventory();
               	server.setPlayerCount(server.getPlayerCount() + 1);
     			    	server.updateSigns();
 			    		SkyWarsReloaded.get().sendBungeeMsg(player, "Connect", server.getServerName());
              	}
              }
             }
} 
 	}
 }
 
Example 8
Source File: FreezeHandler.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
public void removeFreeze(CommandSender sender, Player player, boolean shouldMessage)
{
	UUID uuid = player.getUniqueId();
	User user = userManager.get(uuid);
	
	if(permission.has(player, options.permissionFreezeBypass) && shouldMessage)
	{
		message.send(sender, messages.bypassed, messages.prefixGeneral);
		return;
	}
	
	if(shouldMessage)
	{
		if(options.modeFreezePrompt && user.getCurrentGui() != null)
		{
			if(user.getCurrentGui() instanceof FreezeGui)
			{
				player.closeInventory();
			}
			
			player.removePotionEffect(PotionEffectType.BLINDNESS);
		}
		
		message.send(sender, messages.staffUnfroze.replace("%target%", player.getName()), messages.prefixGeneral);
		message.sendCollectedMessage(player, messages.unfrozen, messages.prefixGeneral);;
	}else loggedOut.remove(uuid);
	
	user.setFrozen(false);
	lastFrozenLocations.remove(uuid);
	player.removePotionEffect(PotionEffectType.JUMP);
	player.removePotionEffect(PotionEffectType.SLOW);
}
 
Example 9
Source File: ConfirmationMenu.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
private boolean doesntHavePermission(Civilian civilian, Map<UUID, String> people, Player player) {
    LocaleManager localeManager = LocaleManager.getInstance();
    if ((!people.containsKey(civilian.getUuid()) ||
            !people.get(civilian.getUuid()).contains(Constants.OWNER)) &&
            (Civs.perm == null || !Civs.perm.has(player, Constants.ADMIN_PERMISSION))) {
        player.closeInventory();
        player.sendMessage(Civs.getPrefix() +
                localeManager.getTranslation(civilian.getLocale(), "no-permission"));
        return true;
    }
    return false;
}
 
Example 10
Source File: GUIManager.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void clickEvent(InventoryClickEvent e) {
    if (!(e.getWhoClicked() instanceof Player))
        return;
    Player p = (Player) e.getWhoClicked();
    if (!activeWindows.containsKey(p.getUniqueId()) || activeWindows.get(p.getUniqueId()) == null)
        return;
    if (!activeWindows.get(p.getUniqueId()).getInventory().equals(e.getClickedInventory()))
        return;
    e.setCancelled(true);
    String perm = Hawk.BASE_PERMISSION + ".gui";
    if (!p.hasPermission(perm)) {
        p.sendMessage(String.format(Hawk.NO_PERMISSION, perm));
        p.closeInventory();
        return;
    }
    Window window = activeWindows.get(p.getUniqueId());
    int clickedLoc = e.getRawSlot();
    for (int i = 0; i < window.getElements().length; i++) {
        if (i == clickedLoc) {
            Element element = window.getElements()[i];
            if(element == null)
                break;
            element.doAction(p, hawk);
            break;
        }
    }
}
 
Example 11
Source File: CrateControl.java    From Crazy-Crates with MIT License 5 votes vote down vote up
@EventHandler
public void onAdminMenuClick(InventoryClickEvent e) {
    Inventory inv = e.getInventory();
    Player player = (Player) e.getWhoClicked();
    if (inv != null && e.getView().getTitle().equals(Methods.sanitizeColor("&4&lAdmin Keys"))) {
        e.setCancelled(true);
        if (!Methods.permCheck(player, "admin")) {
            player.closeInventory();
            return;
        }
        //Added the >= due to an error about a raw slot set at -999.
        if (e.getRawSlot() < inv.getSize() && e.getRawSlot() >= 0) {//Clicked in the admin menu.
            ItemStack item = inv.getItem(e.getRawSlot());
            if (cc.isKey(item)) {
                Crate crate = cc.getCrateFromKey(item);
                if (e.getAction() == InventoryAction.PICKUP_ALL) {
                    player.getInventory().addItem(crate.getKey());
                } else if (e.getAction() == InventoryAction.PICKUP_HALF) {
                    cc.addKeys(1, player, crate, KeyType.VIRTUAL_KEY);
                    String name = null;
                    ItemStack key = crate.getKey();
                    if (key.hasItemMeta() && key.getItemMeta().hasDisplayName()) {
                        name = key.getItemMeta().getDisplayName();
                    }
                    player.sendMessage(Methods.getPrefix() + Methods.color("&a&l+1 " + (name != null ? name : crate.getName())));
                }
            }
        }
    }
}
 
Example 12
Source File: MatchPlayer.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public void reset() {
    final Player bukkit = getBukkit();
    bukkit.closeInventory();
    clearInventory();
    bukkit.setExhaustion(0);
    bukkit.setFallDistance(0);
    bukkit.setFireTicks(0);
    bukkit.setFoodLevel(20); // full
    bukkit.setMaxHealth(20);
    bukkit.setHealth(bukkit.getMaxHealth());
    bukkit.setAbsorption(0);
    bukkit.setLevel(0);
    bukkit.setExp(0); // clear xp
    bukkit.setSaturation(5); // default
    bukkit.setFastNaturalRegeneration(false);
    bukkit.setSlowNaturalRegeneration(true);
    bukkit.setAllowFlight(false);
    bukkit.setFlying(false);
    bukkit.setSneaking(false);
    bukkit.setSprinting(false);
    bukkit.setFlySpeed(0.1f);
    bukkit.setKnockbackReduction(0);
    bukkit.setWalkSpeed(WalkSpeedKit.BUKKIT_DEFAULT);
    AttributeUtils.removeAllModifiers(bukkit);
    resetPotions();

    // we only reset bed spawn here so people don't have to see annoying messages when they respawn
    bukkit.setBedSpawnLocation(null);

    match.callEvent(new PlayerResetEvent(this));
}
 
Example 13
Source File: MatchManager.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private void startMatch(final GameMap gameMap) {
  	if (debug) {
  		Util.get().logToFile(debugName + ChatColor.YELLOW + "Starting SkyWars Match");
  	}
  	for (Player player: gameMap.getAlivePlayers()) {
  		player.closeInventory();
  		player.setGameMode(GameMode.SURVIVAL);
	if (SkyWarsReloaded.getCfg().titlesEnabled()) {
		Util.get().sendTitle(player, 5, 60, 5, new Messaging.MessageFormatter().setVariable("map", gameMap.getDisplayName()).format("titles.start-title"),
				new Messaging.MessageFormatter().setVariable("map", gameMap.getDisplayName()).format("titles.start-subtitle"));
	}
  	}
      if (gameMap.getMatchState() != MatchState.ENDING) {
      	this.matchCountdown(gameMap);
      }
      gameMap.getChestOption().completeOption();
  	if (SkyWarsReloaded.getCfg().isTimeVoteEnabled()) {
	gameMap.getTimeOption().completeOption();
}
if (SkyWarsReloaded.getCfg().isWeatherVoteEnabled()) {
	gameMap.getWeatherOption().completeOption();
}
if (SkyWarsReloaded.getCfg().isModifierVoteEnabled()) {
	gameMap.getModifierOption().completeOption();
}
if (SkyWarsReloaded.getCfg().isHealthVoteEnabled()) {
	gameMap.getHealthOption().completeOption();
}
selectKit(gameMap);
  	gameMap.getCage().removeSpawnHousing(gameMap);
  }
 
Example 14
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private void onClickLogMenu(InventoryClickEvent event, Player p, int slotIndex) {
    event.setCancelled(true);
    if (slotIndex < 0 || slotIndex > 35) {
        return;
    }
    p.closeInventory();
    p.performCommand("island");
}
 
Example 15
Source File: Trade.java    From TradePlus with GNU General Public License v3.0 5 votes vote down vote up
public void open(Player player) {
  if (cancelled) {
    player.closeInventory();
  } else {
    if (player1.equals(player)) {
      player.openInventory(inv1);
    } else if (player2.equals(player)) {
      player.openInventory(inv2);
    }
  }
}
 
Example 16
Source File: Players.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static void setObserver(Player player) {
    player.setGameMode(GameMode.CREATIVE);
    player.setAllowFlight(true);
    player.setFlying(true);
    canInteract(player, false);
    resetPlayer(player, false);
    player.closeInventory();
}
 
Example 17
Source File: SpectateListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onInventoryClick(InventoryClickEvent e) {
	final Player player = (Player) e.getWhoClicked();
	final GameMap gameMap = MatchManager.get().getSpectatorMap(player);
	if (gameMap == null) {
		return;
	}
	int slot = e.getSlot();
	if (slot == 8) {
		player.closeInventory();
		gameMap.getSpectators().remove(player.getUniqueId());
		MatchManager.get().removeSpectator(player);
	} else if (slot >= 9 && slot <= 35) {
		player.closeInventory();
		ItemStack item = e.getCurrentItem();
		if (item != null && !item.getType().equals(Material.AIR)) {
			String name = ChatColor.stripColor(item.getItemMeta().getDisplayName());
			Player toSpec = SkyWarsReloaded.get().getServer().getPlayer(name);
            if (toSpec != null) {
   				if (!gameMap.mapContainsDead(toSpec.getUniqueId()) && player != null) {
   					player.teleport(toSpec.getLocation(), TeleportCause.END_PORTAL);
   				}
            }
		}
	}

}
 
Example 18
Source File: WarpPanel.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
public void onInventoryClick(InventoryClickEvent event) {
    Inventory inventory = event.getInventory(); // The inventory that was clicked in
    if (inventory.getName() == null) {
        return;
    }
    // The player that clicked the item
    final Player player = (Player) event.getWhoClicked();
    String title = inventory.getTitle();
    if (!inventory.getTitle().startsWith(plugin.myLocale().warpsTitle + " #")) {
        return;
    }
    event.setCancelled(true);
    if (event.getSlotType().equals(SlotType.OUTSIDE)) {
        player.closeInventory();
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        player.closeInventory();
        player.updateInventory();
        return;
    }
    ItemStack clicked = event.getCurrentItem(); // The item that was clicked
    if (DEBUG)
        plugin.getLogger().info("DEBUG: inventory size = " + inventory.getSize());
    if (DEBUG)
        plugin.getLogger().info("DEBUG: clicked = " + clicked);
    if (DEBUG)
        plugin.getLogger().info("DEBUG: rawslot = " + event.getRawSlot());
    if (event.getRawSlot() >= event.getInventory().getSize() || clicked.getType() == Material.AIR) {
        return;
    }
    int panelNumber = 0;
    try {
        panelNumber = Integer.valueOf(title.substring(title.indexOf('#')+ 1));
    } catch (Exception e) {
        panelNumber = 0;
    }
    if (clicked.getItemMeta().hasDisplayName()) {
        String command = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
        if (DEBUG)
            plugin.getLogger().info("DEBUG: command = " + command);
        if (command != null) {
            if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsNext))) {
                player.closeInventory();
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber+1));
            } else if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsPrevious))) {
                player.closeInventory();
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber-1));
            } else {
                player.closeInventory();
                Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).warpswarpToPlayersSign.replace("<player>", command));
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warp " + command);
            }
        }
    }
}
 
Example 19
Source File: ItemsListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
private void handleGameItemInteract(GameItem gameItem, Player player, UhcPlayer uhcPlayer, ItemStack item){
	GameManager gm = GameManager.getGameManager();

	switch (gameItem){
		case TEAM_SELECTION:
			UhcItems.openTeamMainInventory(player, uhcPlayer);
			break;
		case TEAM_SETTINGS:
			UhcItems.openTeamSettingsInventory(player);
			break;
		case KIT_SELECTION:
			KitsManager.openKitSelectionInventory(player);
			break;
		case CUSTOM_CRAFT_BOOK:
			CraftsManager.openCraftBookInventory(player);
			break;
		case TEAM_COLOR_SELECTION:
			UhcItems.openTeamColorInventory(player);
			break;
		case TEAM_RENAME:
			openTeamRenameGUI(player, uhcPlayer.getTeam());
			break;
		case SCENARIO_VIEWER:
			Inventory inv;
			if (gm.getConfiguration().getEnableScenarioVoting()){
				inv = gm.getScenarioManager().getScenarioVoteInventory(uhcPlayer);
			}else {
				inv = gm.getScenarioManager().getScenarioMainInventory(player.hasPermission("uhc-core.scenarios.edit"));
			}
			player.openInventory(inv);
			break;
		case BUNGEE_ITEM:
			GameManager.getGameManager().getPlayersManager().sendPlayerToBungeeServer(player);
			break;
		case COMPASS_ITEM:
			uhcPlayer.pointCompassToNextPlayer(gm.getConfiguration().getPlayingCompassMode(), gm.getConfiguration().getPlayingCompassCooldown());
			break;
		case TEAM_READY:
		case TEAM_NOT_READY:
			uhcPlayer.getTeam().changeReadyState();
			UhcItems.openTeamSettingsInventory(player);
			break;
		case TEAM_INVITE_PLAYER:
			UhcItems.openTeamInviteInventory(player);
			break;
		case TEAM_INVITE_PLAYER_SEARCH:
			openTeamInviteGUI(player);
			break;
		case TEAM_VIEW_INVITES:
			UhcItems.openTeamInvitesInventory(player, uhcPlayer);
			break;
		case TEAM_INVITE_ACCEPT:
			handleTeamInviteReply(uhcPlayer, item, true);
			player.closeInventory();
			break;
		case TEAM_INVITE_DENY:
			handleTeamInviteReply(uhcPlayer, item, false);
			player.closeInventory();
			break;
		case TEAM_LEAVE:
			try {
				uhcPlayer.getTeam().leave(uhcPlayer);
			}catch (UhcTeamException ex){
				uhcPlayer.sendMessage(ex.getMessage());
			}
			break;
		case TEAM_LIST:
			UhcItems.openTeamsListInventory(player);
			break;
	}
}
 
Example 20
Source File: ShopHandler.java    From EliteMobs with GNU General Public License v3.0 2 votes vote down vote up
@EventHandler
public void onClick(InventoryClickEvent event) {

    if (!SharedShopElements.inventoryNullPointerPreventer(event))
        return;

    if (!event.getInventory().getName().equals(SHOP_NAME)) return;

    //reroll loot button
    if (event.getCurrentItem().getItemMeta().getDisplayName().equals(SignatureItem.SIGNATURE_ITEMSTACK.getItemMeta().getDisplayName())) {

        populateShop(event.getInventory());
        event.setCancelled(true);
        return;

    }

    if (!ObfuscatedSignatureLoreData.obfuscatedSignatureDetector(event.getCurrentItem())) {

        event.setCancelled(true);
        return;

    }

    Player player = (Player) event.getWhoClicked();
    ItemStack itemStack = event.getCurrentItem();
    String itemDisplayName = itemStack.getItemMeta().getDisplayName();

    double itemValue = ItemWorthCalculator.determineItemWorth(itemStack);

    boolean inventoryHasFreeSlots = false;
    for (ItemStack iteratedStack : player.getInventory().getStorageContents()) {

        if (iteratedStack == null) {

            inventoryHasFreeSlots = true;
            break;

        }

    }

    //These slots are for buying items
    if (event.getClickedInventory().getName().equalsIgnoreCase(SHOP_NAME) && validSlots.contains(event.getSlot())) {

        if (!inventoryHasFreeSlots) {

            player.sendMessage("Your inventory is full! You can't buy items until you get some free space.");
            player.closeInventory();

        } else if (EconomyHandler.checkCurrency(UUIDFilter.guessUUI(player.getName())) >= itemValue) {
            //player has enough money
            EconomyHandler.subtractCurrency(UUIDFilter.guessUUI(player.getName()), itemValue);
            player.getInventory().addItem(itemStack);
            populateShop(event.getInventory());

            SharedShopElements.buyMessage(player, itemDisplayName, itemValue);

        } else {

            player.closeInventory();
            SharedShopElements.insufficientFundsMessage(player, itemValue);

        }

    }

    event.setCancelled(true);

}