SteamWar/MissileWars
Archiviert
13
0

Fix Bows in Chest #2

Manuell gemergt
Lixfel hat 7 Commits von chest-fix nach master 2020-09-03 19:35:39 +02:00 zusammengeführt
Nur Änderungen aus Commit 1a721b2f49 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -21,8 +21,12 @@ import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.io.File;
@ -82,11 +86,25 @@ public class ItemListener extends BasicListener {
}
}
@EventHandler(ignoreCancelled = true)
public void onInventoryClose(InventoryCloseEvent event) {
if(event.getInventory().contains(Material.BOW)) {
event.getInventory().setItem(event.getInventory().first(Material.BOW), new ItemStack(Material.AIR));
event.getPlayer().getInventory().addItem(MWTeam.getBow());
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Inventory clicked = event.getClickedInventory();
if(event.getClick().isShiftClick()){
ItemStack clickedOn = event.getCurrentItem();
if(
clickedOn != null &&
event.getView().getTopInventory().getType() != InventoryType.CRAFTING &&
event.getCurrentItem().getType() != Material.BOW &&
clicked == event.getWhoClicked().getInventory())
event.setCancelled(true);
}else if (
clicked != event.getWhoClicked().getInventory() &&
clicked != null &&
clicked.getType() != InventoryType.PLAYER &&
event.getCurrentItem().getType() != Material.BOW &&
event.getCursor() != null &&
event.getCursor().getType() != Material.AIR)
event.setCancelled(true);
}
}