Start of Inventory Sort Implementation.

This commit is contained in:
jameslfc19 2020-04-20 14:13:51 +01:00
parent cba7fd7b5f
commit c4fa121c7e
3 changed files with 21 additions and 3 deletions

View File

@ -45,6 +45,7 @@ public class HopperListener implements Listener {
public void run() {
Utils.moveToOtherInventory(event.getSource(), 1, storage.getInventory());
event.getDestination().getHolder().getInventory().clear();
storage.sort();
}
}.runTaskLater(ChestsPlusPlus.PLUGIN, 1);
}

View File

@ -1,24 +1,26 @@
package com.jamesdpeters.minecraft.chests.listeners;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.misc.Config;
import com.jamesdpeters.minecraft.chests.misc.Messages;
import com.jamesdpeters.minecraft.chests.misc.Permissions;
import com.jamesdpeters.minecraft.chests.misc.Utils;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualInventoryHolder;
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.scheduler.BukkitScheduler;
public class InventoryListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryPlayerUpdate(InventoryClickEvent event){
if(event.getInventory().getHolder() instanceof VirtualInventoryHolder){
inventoryUpdate(event);
Config.save();
}
}
@ -55,4 +57,18 @@ public class InventoryListener implements Listener {
} catch (NullPointerException ignore){} //Essentials does something weird with enderchests - shit fix but works :)
}
public void inventoryUpdate(InventoryInteractEvent event){
if(event.getInventory().getHolder() instanceof VirtualInventoryHolder){
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestsPlusPlus.PLUGIN, () -> ((VirtualInventoryHolder) event.getInventory().getHolder()).getStorage().sort(),1);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryPlayerUpdate(InventoryDragEvent event){
if(event.getInventory().getHolder() instanceof VirtualInventoryHolder){
inventoryUpdate(event);
}
}
}

View File

@ -36,6 +36,7 @@ public class VirtualChestToHopper extends BukkitRunnable {
continue;
}
Utils.moveToOtherInventory(storage.getInventory(), 1, hopper.getInventory(), Utils.getHopperFilters(below.getBlock()));
storage.sort();
}
}
}