mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-27 20:56:05 +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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -38,13 +39,14 @@ public class DefaultInventory {
|
|||||||
String name = ChatColor.translateAlternateColorCodes('&', configLoad.getString(k + ".name"));
|
String name = ChatColor.translateAlternateColorCodes('&', configLoad.getString(k + ".name"));
|
||||||
List<String> lore = toColor(configLoad.getStringList(k + ".lore"));
|
List<String> lore = toColor(configLoad.getStringList(k + ".lore"));
|
||||||
int redirect = configLoad.getInt(k + ".redirect");
|
int redirect = configLoad.getInt(k + ".redirect");
|
||||||
Material item = Material.matchMaterial(strItem);
|
CompatibleMaterial material = CompatibleMaterial.getMaterial(strItem);
|
||||||
if (item == null || item == Material.AIR) {
|
if (material == null || material == CompatibleMaterial.AIR) {
|
||||||
Bukkit.getLogger().warning("Item " + strItem + " is not a Material");
|
Bukkit.getLogger().warning("Item " + strItem + " is not a Material");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack is = new ItemStack(item, amount);
|
ItemStack is = material.getItem();
|
||||||
|
is.setAmount(amount);
|
||||||
ItemMeta im = is.getItemMeta();
|
ItemMeta im = is.getItemMeta();
|
||||||
im.setDisplayName(name);
|
im.setDisplayName(name);
|
||||||
im.setLore(lore);
|
im.setLore(lore);
|
||||||
|
@ -68,11 +68,6 @@ public final class IslandLevelManager {
|
|||||||
public static boolean isDoubleCheckedBlock(Block block) {
|
public static boolean isDoubleCheckedBlock(Block block) {
|
||||||
return CHECKED_DOUBLE_TYPES.contains(parseType(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) {
|
public void startScan(Player attemptScanner, Island island) {
|
||||||
|
|
||||||
if (!Bukkit.isPrimaryThread()) {
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
@ -185,52 +180,44 @@ public final class IslandLevelManager {
|
|||||||
|
|
||||||
if (blockType == CompatibleMaterial.AIR) return EMPTY;
|
if (blockType == CompatibleMaterial.AIR) return EMPTY;
|
||||||
|
|
||||||
CompatibleMaterial compMaterial = parseType(block);
|
CompatibleMaterial compMaterial = CompatibleMaterial.getMaterial(block);
|
||||||
|
|
||||||
if (compMaterial == null) return EMPTY;
|
if (compMaterial == null) return EMPTY;
|
||||||
|
|
||||||
Material finalType = compMaterial.getMaterial();
|
|
||||||
|
|
||||||
if (finalType == null) return EMPTY;
|
|
||||||
|
|
||||||
final Location blockLocation = block.getLocation();
|
final Location blockLocation = block.getLocation();
|
||||||
|
|
||||||
if (scan.getDoubleBlocks().contains(blockLocation)) return EMPTY;
|
if (scan.getDoubleBlocks().contains(blockLocation)) return EMPTY;
|
||||||
|
|
||||||
if (CHECKED_DOUBLE_TYPES.contains(finalType)) {
|
if (CHECKED_DOUBLE_TYPES.contains(finalType)) {
|
||||||
|
|
||||||
final Block belowBlock = block.getRelative(BlockFace.DOWN);
|
final Block belowBlock = block.getRelative(BlockFace.DOWN);
|
||||||
final CompatibleMaterial belowType = parseType(belowBlock);
|
final CompatibleMaterial belowMaterial = CompatibleMaterial.getMaterial(belowBlock);
|
||||||
|
|
||||||
if (CHECKED_DOUBLE_TYPES.contains(belowType)) {
|
if (CHECKED_DOUBLE_TYPES.contains(belowType)) {
|
||||||
block = belowBlock;
|
block = belowBlock;
|
||||||
blockType = belowType;
|
blockType = belowMaterial;
|
||||||
scan.getDoubleBlocks().add(belowBlock.getLocation());
|
scan.getDoubleBlocks().add(belowBlock.getLocation());
|
||||||
} else {
|
} else {
|
||||||
scan.getDoubleBlocks().add(block.getRelative(BlockFace.UP).getLocation());
|
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 List<Calculator> calculators = CalculatorRegistry.getCalculators(blockType);
|
||||||
final StackableManager stackableManager = SkyBlock.getInstance().getStackableManager();
|
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 (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;
|
if (cachedPair != null) return cachedPair;
|
||||||
|
|
||||||
cachedPair = new AmountMaterialPair(finalCompatMat, 1);
|
cachedPair = new AmountMaterialPair(compMaterial, 1);
|
||||||
cachedPairs.put(finalCompatMat, cachedPair);
|
cachedPairs.put(compMaterial, cachedPair);
|
||||||
|
|
||||||
return cachedPair;
|
return cachedPair;
|
||||||
}
|
}
|
||||||
@ -243,7 +230,7 @@ public final class IslandLevelManager {
|
|||||||
|
|
||||||
if (amount == 0) amount = 1;
|
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