Search in sources :

Example 1 with PlayerInventoryClearEvent

use of com.eintosti.buildsystem.event.player.PlayerInventoryClearEvent in project BuildSystem by Trichtern.

the class PlayerCommandPreprocessListener method onPlayerCommandPreprocess.

@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    if (event.isCancelled()) {
        return;
    }
    String command = event.getMessage().split(" ")[0];
    Player player = event.getPlayer();
    if (command.equalsIgnoreCase("/clear")) {
        ItemStack navigatorItem = inventoryManager.getItemStack(configValues.getNavigatorItem(), plugin.getString("navigator_item"));
        if (!player.getInventory().contains(navigatorItem)) {
            return;
        }
        if (settingsManager.getSettings(player).isKeepNavigator()) {
            List<Integer> navigatorSlots = inventoryManager.getNavigatorSlots(player);
            Bukkit.getScheduler().runTaskLater(plugin, () -> {
                PlayerInventoryClearEvent playerInventoryClearEvent = new PlayerInventoryClearEvent(player, navigatorSlots);
                Bukkit.getServer().getPluginManager().callEvent(playerInventoryClearEvent);
            }, 2L);
        }
        return;
    }
    if (configValues.isBlockWorldEditNonBuilder()) {
        if (!DISABLED_COMMANDS.contains(command)) {
            return;
        }
        BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
        if (buildWorld == null) {
            return;
        }
        if (disableArchivedWorlds(buildWorld, player, event)) {
            return;
        }
        checkBuilders(buildWorld, player, event);
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) PlayerInventoryClearEvent(com.eintosti.buildsystem.event.player.PlayerInventoryClearEvent) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 2 with PlayerInventoryClearEvent

use of com.eintosti.buildsystem.event.player.PlayerInventoryClearEvent in project BuildSystem by Trichtern.

the class InventoryCreativeListener method onClearInventory.

@EventHandler
public void onClearInventory(InventoryCreativeEvent event) {
    if (event.getClick() != ClickType.CREATIVE || event.getSlotType() != InventoryType.SlotType.QUICKBAR || event.getAction() != InventoryAction.PLACE_ALL) {
        return;
    }
    Player player = (Player) event.getWhoClicked();
    List<Integer> navigatorSlots = inventoryManager.getNavigatorSlots(player);
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        PlayerInventoryClearEvent playerInventoryClearEvent = new PlayerInventoryClearEvent(player, navigatorSlots);
        Bukkit.getServer().getPluginManager().callEvent(playerInventoryClearEvent);
    }, 2L);
}
Also used : Player(org.bukkit.entity.Player) PlayerInventoryClearEvent(com.eintosti.buildsystem.event.player.PlayerInventoryClearEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PlayerInventoryClearEvent (com.eintosti.buildsystem.event.player.PlayerInventoryClearEvent)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 BuildWorld (com.eintosti.buildsystem.object.world.BuildWorld)1 ItemStack (org.bukkit.inventory.ItemStack)1