2018-02-04 15:29:07 +00:00
|
|
|
/*
|
2020-02-01 13:03:15 +00:00
|
|
|
* Copyright (C) 2011-2020 lishid. All rights reserved.
|
2018-02-04 15:29:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-12-01 02:26:56 +00:00
|
|
|
package com.lishid.openinv.listeners;
|
|
|
|
|
2020-09-15 15:43:43 +00:00
|
|
|
import com.lishid.openinv.IOpenInv;
|
2019-05-06 02:20:43 +00:00
|
|
|
import com.lishid.openinv.util.InventoryAccess;
|
2016-12-01 02:26:56 +00:00
|
|
|
import com.lishid.openinv.util.Permissions;
|
|
|
|
import org.bukkit.entity.HumanEntity;
|
2020-09-15 15:43:43 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2016-12-01 02:26:56 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
2020-09-15 15:43:43 +00:00
|
|
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
|
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
2016-12-01 02:26:56 +00:00
|
|
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
2020-09-15 15:43:43 +00:00
|
|
|
import org.bukkit.event.inventory.InventoryInteractEvent;
|
2016-12-01 02:26:56 +00:00
|
|
|
import org.bukkit.inventory.Inventory;
|
|
|
|
|
|
|
|
/**
|
2020-09-15 15:43:43 +00:00
|
|
|
* Listener for inventory-related events to prevent modification of inventories where not allowed.
|
2018-02-04 15:29:07 +00:00
|
|
|
*
|
2016-12-01 02:26:56 +00:00
|
|
|
* @author Jikoo
|
|
|
|
*/
|
2020-09-15 15:43:43 +00:00
|
|
|
public class InventoryListener implements Listener {
|
|
|
|
|
|
|
|
private final IOpenInv plugin;
|
|
|
|
|
|
|
|
public InventoryListener(final IOpenInv plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onInventoryClose(final InventoryCloseEvent event) {
|
|
|
|
if (!(event.getPlayer() instanceof Player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = (Player) event.getPlayer();
|
|
|
|
|
|
|
|
if (this.plugin.getPlayerSilentChestStatus(player)) {
|
|
|
|
this.plugin.getAnySilentContainer().deactivateContainer(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
|
|
|
public void onInventoryClick(InventoryClickEvent event) {
|
|
|
|
onInventoryInteract(event);
|
|
|
|
}
|
2016-12-01 02:26:56 +00:00
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
|
|
|
public void onInventoryDrag(InventoryDragEvent event) {
|
2020-09-15 15:43:43 +00:00
|
|
|
onInventoryInteract(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onInventoryInteract(InventoryInteractEvent event) {
|
2016-12-01 02:26:56 +00:00
|
|
|
HumanEntity entity = event.getWhoClicked();
|
|
|
|
Inventory inventory = event.getInventory();
|
2019-05-06 02:20:43 +00:00
|
|
|
if (InventoryAccess.isPlayerInventory(inventory) && !Permissions.EDITINV.hasPermission(entity)
|
|
|
|
|| InventoryAccess.isEnderChest(inventory) && !Permissions.EDITENDER.hasPermission(entity)) {
|
2016-12-01 02:26:56 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|