SteamWar/FightSystem
Archiviert
13
1

Preventing item movement in inventory

Dieser Commit ist enthalten in:
Travis CI 2019-06-14 21:51:06 +02:00
Ursprung 990bddf300
Commit 3ca7c7049d
2 geänderte Dateien mit 57 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -80,6 +80,7 @@ public class FightSystem extends JavaPlugin {
pm.registerEvents(new PlayerTeleportListener(), plugin);
pm.registerEvents(new ProjectileLaunchListener(), plugin);
pm.registerEvents(new PistonListener(), plugin);
pm.registerEvents(new InventoryListener(), plugin);
//WinConditions
if(Config.AllDead) pm.registerEvents(new WinconditionAllDead(), plugin);

Datei anzeigen

@ -0,0 +1,56 @@
package me.yaruma.fightsystem.listener;
import me.yaruma.fightsystem.FightSystem;
import me.yaruma.fightsystem.fight.FightState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class InventoryListener implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if(FightSystem.getFightState() == FightState.SETUP){
event.setCancelled(true);
return;
}
Inventory clicked = event.getClickedInventory();
if (event.getClick().isShiftClick()) {
ItemStack clickedOn = event.getCurrentItem();
if (clickedOn != null && event.getView().getTopInventory().getType() != InventoryType.CRAFTING && clicked == event.getWhoClicked().getInventory()) {
event.setCancelled(true);
}
}else if (clicked != event.getWhoClicked().getInventory()) {
ItemStack onCursor = event.getCurrentItem();
if (onCursor != null && event.getClickedInventory().getType() != InventoryType.PLAYER){
event.setCancelled(true);
}
}
}
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if(FightSystem.getFightState() == FightState.SETUP){
event.setCancelled(true);
return;
}
if (event.getInventory().getType() != InventoryType.PLAYER) {
int inventorySize = event.getInventory().getSize();
for (int i : event.getRawSlots()) {
if (i < inventorySize) {
event.setCancelled(true);
break;
}
}
}
}
}