Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.brokenarrow.storage.hopperteleportitems;
- import lombok.Getter;
- import org.brokenarrow.storage.Crafting.FilterItems;
- import org.brokenarrow.storage.CustomContainersMainClass;
- import org.brokenarrow.storage.Settings.ChatMessages;
- import org.brokenarrow.storage.Settings.LogTimingsReport;
- import org.brokenarrow.storage.Settings.MainSettings;
- import org.brokenarrow.storage.api.ContainerRegistryAPI;
- import org.brokenarrow.storage.api.PreferenceSettingsRegisteryApi;
- import org.brokenarrow.storage.api.TeleportAndPickupItemsApi;
- import org.brokenarrow.storage.api.containerholders.InventoryHolders;
- import org.brokenarrow.storage.cache.ContainerRegistry;
- import org.brokenarrow.storage.util.ItemUtily;
- import org.brokenarrow.storage.util.MathCalations;
- import org.brokenarrow.storage.util.YamlSettingsContainers;
- import org.bukkit.*;
- import org.bukkit.block.*;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Item;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import java.util.*;
- import java.util.stream.Collectors;
- public class TeleportAndPickupItems implements TeleportAndPickupItemsApi {
- private final CustomContainersMainClass plugin = CustomContainersMainClass.getInstance();
- private final ContainerRegistryAPI registry = ContainerRegistryAPI.getInstance();
- @Getter
- private final static TeleportAndPickupItems instance = new TeleportAndPickupItems();
- private final PreferenceSettingsRegisteryApi preferenceRegistery = PreferenceSettingsRegisteryApi.getInstance();
- private final Map<Location, CacheHelpClass> cachedLinkSuctionInventorys = new HashMap<>();
- private Inventory containerInventory;
- public TeleportAndPickupItems() {
- }
- public void runTeleportSuctionTask(List<Location> locationsList) {
- long timess = System.nanoTime();
- locationsList = locationsList.stream().filter((location) -> ContainerRegistry.TypeOfContainer.LINKEDCONTAINER == registry.getTypeofContainer(location)).collect(Collectors.toList());
- for (ListIterator<Location> locations = locationsList.listIterator(); locations.hasNext(); ) {
- Location location = locations.next();
- if (!(ContainerRegistry.TypeOfContainer.LINKEDCONTAINER == registry.getTypeofContainer(location))) continue;
- if (!location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4)) continue;
- if (!(System.currentTimeMillis() >= getDelayItemPicupTeleport(location))) continue;
- if (getDelayItemPicupTeleport(location) == 0) {
- int secondsForPickupTeleport = YamlSettingsContainers.getSecondsForPickupTeleport(registry.getContainerFileName(location), registry.getCurrentUpdate(location));
- setDelayItemPicupTeleportInMilli(location,
- (System.currentTimeMillis() + (secondsForPickupTeleport < 0 ? 1000 * 2 : secondsForPickupTeleport * 1000L)));
- //delayItemPicupTeleport.put(location, (System.currentTimeMillis() + (secondsForPickupTeleport < 0 ? 1000 * 2 : secondsForPickupTeleport * 1000L)));
- } else if (System.currentTimeMillis() >= getDelayItemPicupTeleport(location)) {
- linkedContainer(location);
- int secondsForPickupTeleport = YamlSettingsContainers.getSecondsForPickupTeleport(registry.getContainerFileName(location), registry.getCurrentUpdate(location));
- setDelayItemPicupTeleportInMilli(location,
- (System.currentTimeMillis() + (secondsForPickupTeleport < 0 ? 1000 * 2 : secondsForPickupTeleport * 1000L)));
- //delayItemPicupTeleport.put(location, (System.currentTimeMillis() + (secondsForPickupTeleport <= 0 ? 1000 * 2 : secondsForPickupTeleport * 1000L)));
- }
- }
- if (MainSettings.getInstance().getSettings().isDebugTeleportPickupItems()) {
- LogTimingsReport.getInstance().setTimeListQueue("runTeleportSuctionTask", Math.round(((double) (System.nanoTime() - timess) / 1000000) * 1000.0) / 1000.0);
- }
- }
- private void linkedContainer(Location location) {
- Iterator<Entity> items = null;
- Inventory hopperInventory = null;
- String nextUpdate = registry.getCurrentUpdate(location);
- String sugtionRange = YamlSettingsContainers.getSuctionRange(registry.getContainerFileName(location), nextUpdate);
- String[] radieSplited;
- int locX;
- int locY;
- int locZ;
- World world = location.getChunk().getWorld();
- Block placedItem = location.getBlock();
- int radiesLengt = (radieSplited = sugtionRange.split(",")).length;
- if (radiesLengt == 3) {
- locX = Integer.parseInt(radieSplited[0]);
- locY = Integer.parseInt(radieSplited[1]);
- locZ = Integer.parseInt(radieSplited[2]);
- items = world.getNearbyEntities(location.clone().add(0.5, 0, 0.5), locX, locY, locZ).iterator();
- } else if (sugtionRange.startsWith("-1")) {
- Location locationCloned = MathCalations.getCentrumBlock(location.clone(), -0.5, false);
- int chunkSize = 0;
- if (sugtionRange.contains(",")) {
- String[] radiesplited = sugtionRange.split(",");
- if (radiesplited.length == 2) {
- String calculateChunkSize = radiesplited[1];
- chunkSize = Integer.parseInt(calculateChunkSize);
- }
- }
- items = world.getNearbyEntities(locationCloned, chunkSize > 0 ? 8 + (8 * chunkSize) : 8, location.getWorld().getMaxHeight(), chunkSize > 0 ? 8 + (8 * chunkSize) : 8).iterator();
- }
- if (getCachedContainerInventory(location) == null) {
- if (placedItem.getState() instanceof Hopper) {
- setCachedContainerInventory(location, ((Hopper) placedItem.getState()).getInventory());
- } else if (placedItem.getState() instanceof Chest) {
- setCachedContainerInventory(location, ((Chest) placedItem.getState()).getInventory());
- } else if (placedItem.getState() instanceof Barrel) {
- setCachedContainerInventory(location, ((Barrel) placedItem.getState()).getInventory());
- }
- }
- hopperInventory = getCachedContainerInventory(location);
- if (hopperInventory != null && !(YamlSettingsContainers.getLinkRange(registry.getContainerFileName(location), registry.getCurrentUpdate(location)) == -1)) {
- ItemStack[] hopperContents = hopperInventory.getContents();
- teleportItemsToContainer(location, hopperContents, hopperInventory);
- }
- if (items != null && !(sugtionRange.equals("-2") || sugtionRange.equals("")))
- findItemAndAddToContainer(items, location, world, hopperInventory);
- }
- private void findItemAndAddToContainer(Iterator<Entity> items, Location location, World world, Inventory hopperInventory) {
- while (items.hasNext()) {
- Entity itemstacks = items.next();
- if (itemstacks.isValid() && itemstacks.getTicksLived() >= 20 && itemstacks instanceof Item) {
- ItemStack itemOnGrund = ((Item) itemstacks).getItemStack().clone();
- FilterItems itemsSort = new FilterItems();
- if (itemsSort.checkIfItemMatch(location, itemOnGrund)) {
- if (hopperInventory.firstEmpty() == -1 && !hopperInventory.containsAtLeast(itemOnGrund, 1))
- break;
- List<String> effectWhenContainerRunTask = YamlSettingsContainers.getEffectWhenContainerRunTask(registry.getContainerFileName(location), registry.getCurrentUpdate(location));
- String soundWhenContainerRunTask = YamlSettingsContainers.getSoundWhenContainerRunTask(registry.getContainerFileName(location), registry.getCurrentUpdate(location));
- if (preferenceRegistery.isSoundEffectsWhenContainerPickUpItems(registry.getPlayerUUID(location)))
- if (soundWhenContainerRunTask != null && !soundWhenContainerRunTask.equals(""))
- itemstacks.getLocation().getWorld().playSound(itemstacks.getLocation(), Sound.valueOf(soundWhenContainerRunTask), 1.0F, 1.0F);
- else
- itemstacks.getLocation().getWorld().playSound(itemstacks.getLocation(), Sound.BLOCK_NOTE_BLOCK_BIT, 1.0F, 1.0F);
- itemstacks.getWorld().spawnParticle(effectWhenContainerRunTask != null && !effectWhenContainerRunTask.isEmpty() ? Particle.valueOf(effectWhenContainerRunTask.get(0)) : Particle.FIREWORKS_SPARK, itemstacks.getLocation(), 2, 0.0, 0.1, 0.0, 0.2);
- int itemAmount = plugin.getStackerProvider().getProvider() != null ? plugin.getStackerProvider().getProvider().getItemAmount((Item) itemstacks) : ((Item) itemstacks).getItemStack().getAmount();
- if (itemAmount > 64) {
- if (plugin.getStackerProvider().getProvider() != null)
- plugin.getStackerProvider().getProvider().setItemAmount((Item) itemstacks, itemAmount - 64);
- itemOnGrund = itemOnGrund.clone();
- itemOnGrund.setAmount(64);
- } else {
- itemOnGrund.setAmount(itemAmount);
- itemstacks.remove();
- }
- HashMap<Integer, ItemStack> leftOvers = hopperInventory.addItem(new ItemStack(itemOnGrund));
- if (!leftOvers.isEmpty())
- world.dropItemNaturally(location, itemOnGrund);
- else
- registry.setTotalAmountPickedUp(location, itemOnGrund.getAmount());
- }
- }
- }
- }
- private void teleportItemsToContainer(Location location, ItemStack[] hopperContents, Inventory hopperInventory) {
- Location linkedContainerLocation = getLinkLocation(location, registry);
- if (linkedContainerLocation != null) {
- if (!linkedContainerLocation.getWorld().isChunkLoaded(linkedContainerLocation.getBlockX() >> 4, linkedContainerLocation.getBlockZ() >> 4))
- return;
- InventoryHolders customInventory = plugin.getClassinstans().createObjektInventoryHolder(linkedContainerLocation, null);
- if (registry.getTypeofContainer(linkedContainerLocation) != null)
- switch (registry.getTypeofContainer(linkedContainerLocation)) {
- case PAGEDCONTAINER:
- case CRAFTINGCONTAINER:
- case SELLCHEST:
- case STORAGEUNIT: {
- ItemStack[] itemStacks = Arrays.stream(hopperContents).filter((contents) -> contents != null &&
- contents.getType() != Material.AIR).toArray(ItemStack[]::new);
- Map<Integer, ItemStack> containerLeftOvers = customInventory.addItems(itemStacks);
- hopperInventory.clear();
- if (!containerLeftOvers.isEmpty()) {
- setTeleportedItems(location, false);
- Collection<ItemStack> collectionItemStack = containerLeftOvers.values();
- hopperInventory.addItem(collectionItemStack.toArray(new ItemStack[0]));
- } else {
- registry.setTotalAmountTeleportedItems(location, ItemUtily.countItemStacks(hopperContents, customInventory.getContents(linkedContainerLocation)));
- setTeleportedItems(location, true);
- }
- break;
- }
- default:
- ItemStack[] itemStacks = Arrays.stream(hopperContents).filter((contents) -> contents != null &&
- contents.getType() != Material.AIR).toArray(ItemStack[]::new);
- System.out.println("itemstacks " + isTeleportedItems(location));
- HopperTeleportListener event = new HopperTeleportListener(linkedContainerLocation, isTeleportedItems(location), itemStacks);
- Bukkit.getPluginManager().callEvent(event);
- if (event.isCancelled()) {
- if (event.isShallRemoveFromHopper())
- hopperInventory.clear();
- break;
- } else {
- HashMap<Integer, ItemStack> containerLeftOvers = containerInventory.addItem(itemStacks);
- hopperInventory.clear();
- if (!containerLeftOvers.isEmpty()) {
- setTeleportedItems(location, false);
- Collection<ItemStack> collectionItemStack = containerLeftOvers.values();
- hopperInventory.addItem(collectionItemStack.toArray(new ItemStack[0]));
- } else {
- registry.setTotalAmountTeleportedItems(location, ItemUtily.countItemStacks(hopperContents, containerInventory));
- setTeleportedItems(location, itemStacks.length >= 1);
- }
- }
- break;
- }
- }
- }
- //todo check and fix so it change location and are not same.
- private Location getLinkLocation(Location containerLocation, ContainerRegistryAPI registry) {
- List<Location> linkedContainerLocation = registry.getLinkContainerLinkedToLocation(containerLocation);
- Location locations = null;
- boolean ifLinkedContainerIsAir = false;
- Set<Location> noVaildLocation = new HashSet<>();
- int locationNumberInList = 0;
- if (getCachedContainerInventory(containerLocation) != null) {
- locationNumberInList = getNumberInList(containerLocation);
- }
- if (linkedContainerLocation != null && linkedContainerLocation.size() > 0) {
- if (locationNumberInList >= linkedContainerLocation.size()) {
- locationNumberInList = 0;
- }
- Location loc = linkedContainerLocation.get(locationNumberInList);
- if (loc.getWorld().isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4)) {
- if (!getLinkedInventory(loc, containerLocation)) {
- switch (loc.getBlock().getType()) {
- case HOPPER:
- case DISPENSER:
- case DROPPER:
- case BARREL:
- case CHEST:
- locationNumberInList++;
- if (locationNumberInList >= linkedContainerLocation.size()) {
- locationNumberInList = 0;
- }
- loc = linkedContainerLocation.get(locationNumberInList);
- break;
- default:
- noVaildLocation.add(loc);
- ifLinkedContainerIsAir = true;
- break;
- }
- }
- locations = loc;
- }
- locationNumberInList++;
- setNumberInList(containerLocation, locationNumberInList);
- }
- if (ifLinkedContainerIsAir) {
- noVaildLocation.stream().sorted().forEach((location) -> {
- ChatMessages.THIS_BLOCK_IS_NOT_VAILD.sendMessage(registry.getPlayer(containerLocation), location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getBlock().getType().toString().toLowerCase());
- this.registry.removeLinkContainerLinkedToThisContainer(location, containerLocation);
- });
- noVaildLocation.clear();
- }
- return locations;
- }
- private boolean getLinkedInventory(Location linkedContainerLocation, Location containerLocation) {
- if (containerLocation != null && linkedContainerLocation != null) {
- if (getCachedLinkedInventory(containerLocation) != null && getCachedLinkedInventory(containerLocation).containsKey(linkedContainerLocation)) {
- Inventory inventory = getCachedLinkedInventory(containerLocation).get(linkedContainerLocation);
- for (ItemStack items : inventory.getContents())
- if (inventory.firstEmpty() == -1 && !inventory.containsAtLeast(items, 1)) {
- removeCachedLinkedContainerInventory(containerLocation, linkedContainerLocation);
- return false;
- } else if (linkedContainerLocation.getBlock().getType() == Material.HOPPER || linkedContainerLocation.getBlock().getType() == Material.CHEST ||
- linkedContainerLocation.getBlock().getType() == Material.BARREL || linkedContainerLocation.getBlock().getType() == Material.DROPPER ||
- linkedContainerLocation.getBlock().getType() == Material.DISPENSER) {
- this.containerInventory = inventory;
- return true;
- } else {
- removeCachedLinkedContainerInventory(containerLocation, linkedContainerLocation);
- }
- } else {
- Block blocktype = linkedContainerLocation.getBlock();
- if (blocktype.getState() instanceof Hopper) {
- setCachedLinkedContainer(containerLocation, (((Hopper) blocktype.getState()).getInventory()), linkedContainerLocation);
- this.containerInventory = (((Hopper) blocktype.getState()).getInventory());
- return true;
- } else if ((blocktype.getState() instanceof Chest)) {
- setCachedLinkedContainer(containerLocation, (((Chest) blocktype.getState()).getInventory()), linkedContainerLocation);
- this.containerInventory = (((Chest) blocktype.getState()).getInventory());
- return true;
- } else if ((blocktype.getState() instanceof Barrel)) {
- setCachedLinkedContainer(containerLocation, (((Barrel) blocktype.getState()).getInventory()), linkedContainerLocation);
- this.containerInventory = (((Barrel) blocktype.getState()).getInventory());
- return true;
- } else if ((blocktype.getState() instanceof Dropper)) {
- setCachedLinkedContainer(containerLocation, (((Dropper) blocktype.getState()).getInventory()), linkedContainerLocation);
- this.containerInventory = (((Dropper) blocktype.getState()).getInventory());
- return true;
- } else if ((blocktype.getState() instanceof Dispenser)) {
- setCachedLinkedContainer(containerLocation, (((Dispenser) blocktype.getState()).getInventory()), linkedContainerLocation);
- this.containerInventory = (((Dispenser) blocktype.getState()).getInventory());
- return true;
- } else {
- this.containerInventory = null;
- removeCachedLinkedContainerInventory(containerLocation, linkedContainerLocation);
- return false;
- }
- }
- }
- return false;
- }
- /**
- * Remove all linked containers inventorys and locations from cache.
- *
- * @param containerLocation location of suction/link container you have link from.
- */
- @Override
- public void removeCachedLinkedContainerInventory(Location containerLocation) {
- if (getCachedLinkedInventory(containerLocation) != null) {
- for (ListIterator<Location> locationListIterator = new ArrayList<>(getCachedLinkedInventory(containerLocation).keySet()).listIterator(); locationListIterator.hasNext(); )
- getCachedLinkedInventory(containerLocation).remove(locationListIterator.next());
- }
- setInCache(containerLocation);
- }
- /**
- * Remove one linked container inventory and location from cache.
- *
- * @param containerLocation location of suction/link container you have link from.
- * @param linkedTo location of container you link to.
- */
- @Override
- public void removeCachedLinkedContainerInventory(Location containerLocation, Location linkedTo) {
- if (this.cachedLinkSuctionInventorys.containsKey(containerLocation)) {
- this.cachedLinkSuctionInventorys.get(containerLocation).getCachedLinkedInventory().remove(linkedTo);
- }
- setInCache(containerLocation);
- }
- /**
- * Put linked containers inventorys and locations to cache.
- *
- * @param containerLocation location of suction/link container you have link from.
- * @param toInventory inventory you want to cache.
- * @param toLocation location of the inventory you link to.
- */
- @Override
- public void setCachedLinkedContainer(Location containerLocation, Inventory toInventory, Location toLocation) {
- setInCache(containerLocation, SetTypeOfdataToCache.CACHED_LINKED_CONTAINER, toInventory, toLocation);
- }
- /**
- * Put Suction/link container´s inventory to cache.
- *
- * @param containerLocation location of suction/link container.
- * @param containerInventory inventory you want to cache.
- */
- @Override
- public void setCachedContainerInventory(Location containerLocation, Inventory containerInventory) {
- setInCache(containerLocation, SetTypeOfdataToCache.CACHED_CONTAINER_INVENTORY, containerInventory);
- }
- /**
- * remove Suction/link container´s inventory from cache.
- *
- * @param containerLocation location of suction/link container.
- */
- @Override
- public void removeCachedContainerInventory(Location containerLocation) {
- setInCache(containerLocation, SetTypeOfdataToCache.CACHED_CONTAINER_INVENTORY, null);
- }
- /**
- * Remove Suction/link container´s from cache. This entity will be removed
- * from cache.
- *
- * @param containerLocation location of suction/link container.
- */
- @Override
- public void clearCachedContainer(Location containerLocation) {
- this.cachedLinkSuctionInventorys.remove(containerLocation);
- }
- /**
- * Put Suction/link container´s next run time for this task.
- *
- * @param containerLocation location of suction/link container.
- * @param delayTime set time in milliseconds.
- */
- @Override
- public void setDelayItemPicupTeleportInMilli(Location containerLocation, long delayTime) {
- setInCache(containerLocation, SetTypeOfdataToCache.DELAY_ITEM_PICKUP_TELEPORT, delayTime);
- }
- /**
- * Put Suction/link container´s next run time for this task.
- *
- * @param containerLocation location of suction/link container.
- * @param delayTime set time in seconds.
- */
- @Override
- public void setDelayItemPicupTeleportInSeconds(Location containerLocation, long delayTime) {
- setInCache(containerLocation, SetTypeOfdataToCache.DELAY_ITEM_PICKUP_TELEPORT, delayTime * 1000);
- }
- /**
- * Set the number of location it will process next.
- *
- * @param containerLocation location of suction/link container.
- * @param numberInList set the number it shall process next.
- */
- @Override
- public void setNumberInList(Location containerLocation, int numberInList) {
- setInCache(containerLocation, SetTypeOfdataToCache.LOCATIONNUMBERINLIST, numberInList);
- }
- /**
- * Set it to true if has sucessfull teleported the item to container.
- *
- * @param containerLocation location of suction/link container.
- */
- @Override
- public void setTeleportedItems(Location containerLocation, boolean teleportItems) {
- setInCache(containerLocation, SetTypeOfdataToCache.TELEPORT_ITEMS, teleportItems);
- }
- /**
- * Get the map of stored inventorys on location. Is a snapshot of inventory/inventory`s
- * on the containers you has link from your hopper/chest or barrel. Is use less resources
- * when you cache it insted of call getState() all the time.
- * <p>
- * Keep in main this is only temporary snapshot, if chunk this container are located to get unloaded
- * you has to replace with new snapshot of the inventory.
- *
- * @param containerLocation location of suction/link container you have link from.
- * @return map with all cached data of current stored location with snapshot of inventory.
- */
- @Override
- public Map<Location, Inventory> getCachedLinkedInventory(Location containerLocation) {
- if (this.cachedLinkSuctionInventorys.containsKey(containerLocation))
- return this.cachedLinkSuctionInventorys.get(containerLocation).getCachedLinkedInventory();
- return null;
- }
- /**
- * Get your Suction/link container´s inventory on location. Is use less resources
- * when you cache it insted of call getState() all the time.
- * <p>
- * Keep in main this is only temporary snapshot, if chunk this container are located to get unloaded
- * you has to replace with new snapshot of the inventory.
- *
- * @param containerLocation location of suction/link container.
- * @return a cached snapshot of container inventory.
- */
- @Override
- public Inventory getCachedContainerInventory(Location containerLocation) {
- if (this.cachedLinkSuctionInventorys.containsKey(containerLocation))
- return this.cachedLinkSuctionInventorys.get(containerLocation).getCachedContainerInventory();
- return null;
- }
- /**
- * Get the number of location it will process next, in the array for the containers some are linked
- * to Suction/link container.
- *
- * @param containerLocation location of suction/link container.
- * @return the number it will process next.
- */
- @Override
- public int getNumberInList(Location containerLocation) {
- if (this.cachedLinkSuctionInventorys.containsKey(containerLocation))
- return this.cachedLinkSuctionInventorys.get(containerLocation).getLocationNumberInList();
- return 0;
- }
- /**
- * Get time for next time it will run the task (pickup items and/or teleport item).
- *
- * @param containerLocation location of suction/link container.
- * @return next time it will run in milliseconds.
- */
- @Override
- public long getDelayItemPicupTeleport(Location containerLocation) {
- if (this.cachedLinkSuctionInventorys.get(containerLocation) != null)
- return this.cachedLinkSuctionInventorys.get(containerLocation).getDelayItemPicupTeleport();
- return 0;
- }
- /**
- * Get if items has successfully teleported items to container.
- *
- * @param containerLocation location of suction/link container.
- * @return true if the item has bee moved.
- */
- @Override
- public boolean isTeleportedItems(Location containerLocation) {
- if (this.cachedLinkSuctionInventorys.containsKey(containerLocation))
- return this.cachedLinkSuctionInventorys.get(containerLocation).isTeleportedItems();
- return false;
- }
- /**
- * Do not use this methods. Is only help, to set data in cache.
- *
- * @param containerlocation location of suction/link container.
- */
- private void setInCache(Location containerlocation) {
- setInCache(containerlocation, null, null, null);
- }
- /**
- * Do not use this methods. Is only help, to set data in cache.
- *
- * @param containerlocation location of suction/link container.
- */
- private void setInCache(Location containerlocation, SetTypeOfdataToCache dataSomeShallCache, Object object) {
- setInCache(containerlocation, dataSomeShallCache, null, object);
- }
- /**
- * Do not use this methods. Is only help, to set data in cache.
- *
- * @param containerlocation location of suction/link container.
- */
- private void setInCache(Location containerlocation, SetTypeOfdataToCache dataSomeShallCache, Inventory toinventory, Object object) {
- Map<Location, Inventory> cachedLinkedInventory = new HashMap<>();
- if (dataSomeShallCache == SetTypeOfdataToCache.CACHED_LINKED_CONTAINER) {
- Map<Location, Inventory> olddata = null;
- if (getCachedLinkedInventory(containerlocation) != null)
- olddata = getCachedLinkedInventory(containerlocation);
- if (olddata != null)
- cachedLinkedInventory.putAll(olddata);
- cachedLinkedInventory.put((Location) object, toinventory);
- }
- //cachedLinkedInventory.put(obj);
- this.cachedLinkSuctionInventorys.put(containerlocation, CacheHelpClass.of(!cachedLinkedInventory.isEmpty() || dataSomeShallCache == SetTypeOfdataToCache.CACHED_LINKED_CONTAINER ? cachedLinkedInventory : getCachedLinkedInventory(containerlocation),
- dataSomeShallCache == SetTypeOfdataToCache.CACHED_CONTAINER_INVENTORY ? (Inventory) object : getCachedContainerInventory(containerlocation),
- dataSomeShallCache == SetTypeOfdataToCache.TELEPORT_ITEMS ? (boolean) object : isTeleportedItems(containerlocation),
- dataSomeShallCache == SetTypeOfdataToCache.LOCATIONNUMBERINLIST ? (int) object : getNumberInList(containerlocation),
- dataSomeShallCache == SetTypeOfdataToCache.DELAY_ITEM_PICKUP_TELEPORT ? (Long) object : getDelayItemPicupTeleport(containerlocation)));
- }
- public static class CacheHelpClass {
- private Map<Location, Inventory> cachedLinkedInventory;
- private Inventory cachedContainerInventory;
- private int locationNumberInList;
- private long delayItemPicupTeleport;
- private boolean teleportedItems;
- public CacheHelpClass(Map<Location, Inventory> cachedLinkedInventory, Inventory cachedContainerInventory, int locationNumberInList, long delayItemPicupTeleport, boolean teleportedItems) {
- this.cachedLinkedInventory = cachedLinkedInventory;
- this.cachedContainerInventory = cachedContainerInventory;
- this.locationNumberInList = locationNumberInList;
- this.delayItemPicupTeleport = delayItemPicupTeleport;
- this.teleportedItems = teleportedItems;
- }
- private CacheHelpClass() {
- }
- public static CacheHelpClass of(Map<Location, Inventory> cachedLinkedInventory, Inventory cachedContainerInventory, boolean teleportedItems
- , int locationNumberInList, long delayItemPicupTeleport) {
- CacheHelpClass data = new CacheHelpClass();
- data.cachedLinkedInventory = cachedLinkedInventory;
- data.cachedContainerInventory = cachedContainerInventory;
- data.locationNumberInList = locationNumberInList;
- data.delayItemPicupTeleport = delayItemPicupTeleport;
- data.teleportedItems = teleportedItems;
- return data;
- }
- public Inventory getCachedContainerInventory() {
- return cachedContainerInventory;
- }
- public int getLocationNumberInList() {
- return locationNumberInList;
- }
- public long getDelayItemPicupTeleport() {
- return delayItemPicupTeleport;
- }
- public boolean isTeleportedItems() {
- return teleportedItems;
- }
- public Map<Location, Inventory> getCachedLinkedInventory() {
- return cachedLinkedInventory;
- }
- }
- private enum SetTypeOfdataToCache {
- CACHED_CONTAINER_INVENTORY,
- CACHED_LINKED_CONTAINER,
- LOCATIONNUMBERINLIST,
- DELAY_ITEM_PICKUP_TELEPORT,
- TELEPORT_ITEMS
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement