Work on ShopTransactions
This commit is contained in:
@@ -2,6 +2,7 @@ package com.alttd.playershops.utils;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -13,28 +14,6 @@ import java.util.Map;
|
||||
|
||||
public class ShopUtil {
|
||||
|
||||
/**
|
||||
* Counts the number of items in the given inventory where
|
||||
* Util.matches(inventory item, item) is true.
|
||||
*
|
||||
* @param inv
|
||||
* The inventory to search
|
||||
* @param item
|
||||
* The ItemStack to search for
|
||||
* @return The number of items that match in this inventory.
|
||||
*/
|
||||
public static int countItems(Inventory inv, ItemStack item) {
|
||||
int items = 0;
|
||||
for (ItemStack iStack : inv.getContents()) {
|
||||
if (iStack == null)
|
||||
continue;
|
||||
if (ShopUtil.matches(item, iStack)) {
|
||||
items += iStack.getAmount();
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given location is loaded or not.
|
||||
*
|
||||
@@ -43,22 +22,12 @@ public class ShopUtil {
|
||||
* @return true if the given location is loaded or not.
|
||||
*/
|
||||
public static boolean isLoaded(Location loc) {
|
||||
// System.out.println("Checking isLoaded(Location loc)");
|
||||
if (loc.getWorld() == null) {
|
||||
// System.out.println("Is not loaded. (No world)");
|
||||
if (!loc.isWorldLoaded()) {
|
||||
return false;
|
||||
}
|
||||
// Calculate the chunks coordinates. These are 1,2,3 for each chunk, NOT
|
||||
// location rounded to the nearest 16.
|
||||
int x = (int) Math.floor((loc.getBlockX()) / 16.0);
|
||||
int z = (int) Math.floor((loc.getBlockZ()) / 16.0);
|
||||
if (loc.getWorld().isChunkLoaded(x, z)) {
|
||||
// System.out.println("Chunk is loaded " + x + ", " + z);
|
||||
return true;
|
||||
} else {
|
||||
// System.out.println("Chunk is NOT loaded " + x + ", " + z);
|
||||
return false;
|
||||
}
|
||||
return (loc.getWorld().isChunkLoaded(x, z));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,4 +118,6 @@ public class ShopUtil {
|
||||
ItemStack stack = cfg.getItemStack("item");
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user