mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-27 12:45:25 +01:00
Added better use of CompatibleMaterial.
This commit is contained in:
parent
1df7eb416a
commit
d813c8b780
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -38,13 +39,14 @@ public class DefaultInventory {
|
||||
String name = ChatColor.translateAlternateColorCodes('&', configLoad.getString(k + ".name"));
|
||||
List<String> lore = toColor(configLoad.getStringList(k + ".lore"));
|
||||
int redirect = configLoad.getInt(k + ".redirect");
|
||||
Material item = Material.matchMaterial(strItem);
|
||||
if (item == null || item == Material.AIR) {
|
||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(strItem);
|
||||
if (material == null || material == CompatibleMaterial.AIR) {
|
||||
Bukkit.getLogger().warning("Item " + strItem + " is not a Material");
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack is = new ItemStack(item, amount);
|
||||
ItemStack is = material.getItem();
|
||||
is.setAmount(amount);
|
||||
ItemMeta im = is.getItemMeta();
|
||||
im.setDisplayName(name);
|
||||
im.setLore(lore);
|
||||
|
@ -68,11 +68,6 @@ public final class IslandLevelManager {
|
||||
public static boolean isDoubleCheckedBlock(Block block) {
|
||||
return CHECKED_DOUBLE_TYPES.contains(parseType(block));
|
||||
}
|
||||
|
||||
private static CompatibleMaterial parseType(Block block) {
|
||||
return CompatibleMaterial.getBlockMaterial(block.getType());
|
||||
}
|
||||
|
||||
public void startScan(Player attemptScanner, Island island) {
|
||||
|
||||
if (!Bukkit.isPrimaryThread()) {
|
||||
@ -185,52 +180,44 @@ public final class IslandLevelManager {
|
||||
|
||||
if (blockType == CompatibleMaterial.AIR) return EMPTY;
|
||||
|
||||
CompatibleMaterial compMaterial = parseType(block);
|
||||
CompatibleMaterial compMaterial = CompatibleMaterial.getMaterial(block);
|
||||
|
||||
if (compMaterial == null) return EMPTY;
|
||||
|
||||
Material finalType = compMaterial.getMaterial();
|
||||
|
||||
if (finalType == null) return EMPTY;
|
||||
|
||||
final Location blockLocation = block.getLocation();
|
||||
|
||||
if (scan.getDoubleBlocks().contains(blockLocation)) return EMPTY;
|
||||
|
||||
if (CHECKED_DOUBLE_TYPES.contains(finalType)) {
|
||||
|
||||
final Block belowBlock = block.getRelative(BlockFace.DOWN);
|
||||
final CompatibleMaterial belowType = parseType(belowBlock);
|
||||
final CompatibleMaterial belowMaterial = CompatibleMaterial.getMaterial(belowBlock);
|
||||
|
||||
if (CHECKED_DOUBLE_TYPES.contains(belowType)) {
|
||||
block = belowBlock;
|
||||
blockType = belowType;
|
||||
blockType = belowMaterial;
|
||||
scan.getDoubleBlocks().add(belowBlock.getLocation());
|
||||
} else {
|
||||
scan.getDoubleBlocks().add(block.getRelative(BlockFace.UP).getLocation());
|
||||
}
|
||||
|
||||
} else if (finalType == CompatibleMaterial.SPAWNER.getBlockMaterial()) {
|
||||
finalType = CompatibleSpawners.getSpawner(((CreatureSpawner) block.getState()).getSpawnedType()).getMaterial();
|
||||
}
|
||||
|
||||
final List<Calculator> calculators = CalculatorRegistry.getCalculators(blockType);
|
||||
final StackableManager stackableManager = SkyBlock.getInstance().getStackableManager();
|
||||
|
||||
final CompatibleMaterial finalCompatMat = CompatibleMaterial.getMaterial(finalType);
|
||||
|
||||
final long stackSize = stackableManager == null ? 0 : stackableManager.getStackSizeOf(blockLocation, finalCompatMat);
|
||||
final long stackSize = stackableManager == null ? 0 : stackableManager.getStackSizeOf(blockLocation, compMaterial);
|
||||
|
||||
if (calculators == null) {
|
||||
|
||||
if (stackSize > 1) return new AmountMaterialPair(finalCompatMat, stackSize);
|
||||
if (stackSize > 1) return new AmountMaterialPair(compMaterial, stackSize);
|
||||
|
||||
AmountMaterialPair cachedPair = cachedPairs.get(finalType);
|
||||
AmountMaterialPair cachedPair = cachedPairs.get(compMaterial);
|
||||
|
||||
if (cachedPair != null) return cachedPair;
|
||||
|
||||
cachedPair = new AmountMaterialPair(finalCompatMat, 1);
|
||||
cachedPairs.put(finalCompatMat, cachedPair);
|
||||
cachedPair = new AmountMaterialPair(compMaterial, 1);
|
||||
cachedPairs.put(compMaterial, cachedPair);
|
||||
|
||||
return cachedPair;
|
||||
}
|
||||
@ -243,7 +230,7 @@ public final class IslandLevelManager {
|
||||
|
||||
if (amount == 0) amount = 1;
|
||||
|
||||
return new AmountMaterialPair(finalCompatMat, amount + stackSize);
|
||||
return new AmountMaterialPair(compMaterial, amount + stackSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user