From 0669f5eb9d5029a8b94ec552171b0837605f7747 Mon Sep 17 00:00:00 2001 From: draknyte1 Date: Fri, 4 Nov 2016 15:23:26 +1000 Subject: $ Cleaned up the entire project. > Much neat, very nices. --- .../gtPlusPlus/core/util/player/PlayerCache.java | 261 +++++++++++---------- .../gtPlusPlus/core/util/player/PlayerUtils.java | 170 ++++++++------ .../gtPlusPlus/core/util/player/UtilsMining.java | 204 ++++++++-------- 3 files changed, 335 insertions(+), 300 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/player') diff --git a/src/Java/gtPlusPlus/core/util/player/PlayerCache.java b/src/Java/gtPlusPlus/core/util/player/PlayerCache.java index a82aaa2b83..ea40993dae 100644 --- a/src/Java/gtPlusPlus/core/util/player/PlayerCache.java +++ b/src/Java/gtPlusPlus/core/util/player/PlayerCache.java @@ -13,165 +13,170 @@ public class PlayerCache { private static final File cache = new File("PlayerCache.dat"); - public static final void initCache() { - if (CORE.PlayerCache == null || CORE.PlayerCache.equals(null)){ - try { + public static void appendParamChanges(final String playerName, final String playerUUIDasString) { + final HashMap playerInfo = new HashMap(); + playerInfo.put(playerName, UUID.fromString(playerUUIDasString)); - if (cache != null){ - CORE.PlayerCache = PlayerCache.readPropertiesFileAsMap(); - Utils.LOG_INFO("Loaded PlayerCache.dat"); - } + /* + * try { Utils.LOG_INFO("Attempting to load "+cache.getName()); + * properties.load(new FileInputStream(cache)); if (properties == null + * || properties.equals(null)){ Utils.LOG_INFO("Please wait."); } else { + * Utils.LOG_INFO("Loaded PlayerCache.dat"); + * properties.setProperty(playerName+"_", playerUUIDasString); + * FileOutputStream fr=new FileOutputStream(cache); properties.store(fr, + * "Player Cache."); fr.close(); } + * + * } + */ + try { + final FileOutputStream fos = new FileOutputStream("PlayerCache.dat"); + final ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(playerInfo); + oos.close(); + fos.close(); + Utils.LOG_INFO("Serialized Player data saved in PlayerCache.dat"); + } - } catch (Exception e) { - Utils.LOG_INFO("Failed to initialise PlayerCache.dat"); - PlayerCache.createPropertiesFile("PLAYER_", "DATA"); - //e.printStackTrace(); - } + catch (final IOException e) { + Utils.LOG_INFO("No PlayerCache file found, creating one."); + PlayerCache.createPropertiesFile(playerName, playerUUIDasString); } } - public static void createPropertiesFile(String playerName, String playerUUIDasString) { + public static void createPropertiesFile(final String playerName, final String playerUUIDasString) { try { - Properties props = new Properties(); - props.setProperty(playerName+" ", playerUUIDasString); - OutputStream out = new FileOutputStream(cache); + final Properties props = new Properties(); + props.setProperty(playerName + " ", playerUUIDasString); + final OutputStream out = new FileOutputStream(PlayerCache.cache); props.store(out, "Player Cache."); Utils.LOG_INFO("PlayerCache.dat created for future use."); } - catch (Exception e ) { + catch (final Exception e) { e.printStackTrace(); } } - public static void appendParamChanges(String playerName, String playerUUIDasString) { - HashMap playerInfo = new HashMap(); - playerInfo.put(playerName, UUID.fromString(playerUUIDasString)); - - /*try { - Utils.LOG_INFO("Attempting to load "+cache.getName()); - properties.load(new FileInputStream(cache)); - if (properties == null || properties.equals(null)){ - Utils.LOG_INFO("Please wait."); + public static final void initCache() { + if (CORE.PlayerCache == null || CORE.PlayerCache.equals(null)) { + try { + + if (PlayerCache.cache != null) { + CORE.PlayerCache = PlayerCache.readPropertiesFileAsMap(); + Utils.LOG_INFO("Loaded PlayerCache.dat"); + } + } - else { - Utils.LOG_INFO("Loaded PlayerCache.dat"); - properties.setProperty(playerName+"_", playerUUIDasString); - FileOutputStream fr=new FileOutputStream(cache); - properties.store(fr, "Player Cache."); - fr.close(); + catch (final Exception e) { + Utils.LOG_INFO("Failed to initialise PlayerCache.dat"); + PlayerCache.createPropertiesFile("PLAYER_", "DATA"); + // e.printStackTrace(); } + } + } - } */ - - try - { - FileOutputStream fos = new FileOutputStream("PlayerCache.dat"); - ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(playerInfo); - oos.close(); - fos.close(); - Utils.LOG_INFO("Serialized Player data saved in PlayerCache.dat"); - } - - catch (IOException e) { - Utils.LOG_INFO("No PlayerCache file found, creating one."); - createPropertiesFile(playerName, playerUUIDasString); - } + public static String lookupPlayerByUUID(final UUID UUID) { + + try { + final World worldw = Minecraft.getMinecraft().thePlayer.worldObj; + // if (!worldw.isRemote){ + + try { + Map map = null; + try { + map = PlayerCache.readPropertiesFileAsMap(); + } + catch (final Exception e) { + Utils.LOG_INFO("With " + e.getCause() + " as cause, Caught Exception: " + e.toString()); + // e.printStackTrace(); + } + for (final Entry entry : map.entrySet()) { + if (Objects.equals(UUID, entry.getValue())) { + return entry.getKey(); + } + } + return null; + } + catch (final NullPointerException e) { + Utils.LOG_INFO("With " + e.getCause() + " as cause, Caught Exception: " + e.toString()); + // e.printStackTrace(); + } + + // } + + } + catch (final Throwable r) { + Utils.LOG_INFO("With " + r.getCause() + " as cause, Caught Exception: " + r.toString()); + } + return null; + } + + public static HashMap readPropertiesFileAsMap() { + HashMap map = null; + try { + final FileInputStream fis = new FileInputStream(PlayerCache.cache); + final ObjectInputStream ois = new ObjectInputStream(fis); + map = (HashMap) ois.readObject(); + ois.close(); + fis.close(); + } + catch (final IOException ioe) { + ioe.printStackTrace(); + return null; + } + catch (final ClassNotFoundException c) { + Utils.LOG_INFO("Class not found"); + c.printStackTrace(); + return null; + } + Utils.LOG_WARNING("Deserialized PlayerCache.."); + return map; } /** - * Reads a "properties" file, and returns it as a Map - * (a collection of key/value pairs). - * - * Credit due to Alvin Alexander - http://alvinalexander.com/java/java-properties-file-map-example?nocache=1#comment-8215 - * Changed slightly as the filename and delimiter are constant in my case. - * - * @param filename The properties filename to read. - * @param delimiter The string (or character) that separates the key - * from the value in the properties file. + * Reads a "properties" file, and returns it as a Map (a collection of + * key/value pairs). + * + * Credit due to Alvin Alexander - + * http://alvinalexander.com/java/java-properties-file-map-example?nocache=1 + * #comment-8215 Changed slightly as the filename and delimiter are constant + * in my case. + * + * @param filename + * The properties filename to read. + * @param delimiter + * The string (or character) that separates the key from the + * value in the properties file. * @return The Map that contains the key/value pairs. * @throws Exception */ @Deprecated public static Map readPropertiesFileAsMapOld() throws Exception { - String delimiter = "="; - @SuppressWarnings({ "rawtypes", "unchecked" }) - Map map = new HashMap(); - BufferedReader reader = new BufferedReader(new FileReader(cache)); + final String delimiter = "="; + @SuppressWarnings({ + "rawtypes", "unchecked" + }) + final Map map = new HashMap(); + final BufferedReader reader = new BufferedReader(new FileReader(PlayerCache.cache)); String line; - while ((line = reader.readLine()) != null) - { - if (line.trim().length()==0) continue; - if (line.charAt(0)=='#') continue; - // assumption here is that proper lines are like "String : http://xxx.yyy.zzz/foo/bar", + while ((line = reader.readLine()) != null) { + if (line.trim().length() == 0) { + continue; + } + if (line.charAt(0) == '#') { + continue; + } + // assumption here is that proper lines are like "String : http://xxx.yyy.zzz/foo/bar", // and the ":" is the delimiter - int delimPosition = line.indexOf(delimiter); - String key = line.substring(0, delimPosition-1).trim(); - String value = line.substring(delimPosition+1).trim(); + final int delimPosition = line.indexOf(delimiter); + final String key = line.substring(0, delimPosition - 1).trim(); + final String value = line.substring(delimPosition + 1).trim(); map.put(key, value); } reader.close(); CORE.PlayerCache = map; return map; } - - public static HashMap readPropertiesFileAsMap() { - HashMap map = null; - try - { - FileInputStream fis = new FileInputStream(cache); - ObjectInputStream ois = new ObjectInputStream(fis); - map = (HashMap) ois.readObject(); - ois.close(); - fis.close(); - }catch(IOException ioe) - { - ioe.printStackTrace(); - return null; - }catch(ClassNotFoundException c) - { - Utils.LOG_INFO("Class not found"); - c.printStackTrace(); - return null; - } - Utils.LOG_WARNING("Deserialized PlayerCache.."); - return map; - } - - public static String lookupPlayerByUUID(UUID UUID){ - - try { - World worldw = Minecraft.getMinecraft().thePlayer.worldObj; - //if (!worldw.isRemote){ - - - try { - Map map = null; - try { - map = readPropertiesFileAsMap(); - } catch (Exception e) { - Utils.LOG_INFO("With "+e.getCause()+" as cause, Caught Exception: "+e.toString()); - //e.printStackTrace(); - } - for (Entry entry : map.entrySet()) { - if (Objects.equals(UUID, entry.getValue())) { - return entry.getKey(); - } - } - return null; - } catch (NullPointerException e) { - Utils.LOG_INFO("With "+e.getCause()+" as cause, Caught Exception: "+e.toString()); - //e.printStackTrace(); - } - - - //} - - - } catch (Throwable r){ - Utils.LOG_INFO("With "+r.getCause()+" as cause, Caught Exception: "+r.toString()); - } - return null; - } } diff --git a/src/Java/gtPlusPlus/core/util/player/PlayerUtils.java b/src/Java/gtPlusPlus/core/util/player/PlayerUtils.java index 616ecc439e..7d6e2f42e7 100644 --- a/src/Java/gtPlusPlus/core/util/player/PlayerUtils.java +++ b/src/Java/gtPlusPlus/core/util/player/PlayerUtils.java @@ -14,113 +14,129 @@ import net.minecraft.world.World; public class PlayerUtils { - public static void messagePlayer(EntityPlayer P, String S){ - gregtech.api.util.GT_Utility.sendChatToPlayer(P, S); - } + @SideOnly(Side.CLIENT) + public static Item getItemInPlayersHand() { + final Minecraft mc = Minecraft.getMinecraft(); + Item heldItem = null; - public static EntityPlayer getPlayer(String name){ - List i = new ArrayList(); - Iterator crunchifyIterator = MinecraftServer.getServer().getConfigurationManager().playerEntityList.iterator(); - while (crunchifyIterator.hasNext()) { - i.add((crunchifyIterator.next())); - } - try{ - for (EntityPlayer temp : i) { - if (temp.getDisplayName().toLowerCase().equals(name.toLowerCase())){ - return temp; - } - } + try { + heldItem = mc.thePlayer.getHeldItem().getItem(); } - catch(NullPointerException e){} - return null; - } - - public static EntityPlayer getPlayerOnServerFromUUID(UUID parUUID){ - if (parUUID == null) - { + catch (final NullPointerException e) { return null; } - List allPlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList; - for (EntityPlayerMP player : allPlayers) - { - if (player.getUniqueID().equals(parUUID)) - { - return player; - } + + if (heldItem != null) { + return heldItem; } + return null; } - //Not Clientside - public static EntityPlayer getPlayerInWorld(World world, String Name){ - List i = world.playerEntities; - Minecraft mc = Minecraft.getMinecraft(); - try{ - for (EntityPlayer temp : i) { - if (temp.getDisplayName().toLowerCase().equals(Name.toLowerCase())){ - return temp; - } - } - } - catch(NullPointerException e){} + @SideOnly(Side.CLIENT) + public static ItemStack getItemStackInPlayersHand() { + final Minecraft mc = Minecraft.getMinecraft(); + ItemStack heldItem = null; + try { + heldItem = mc.thePlayer.getHeldItem(); + } + catch (final NullPointerException e) { return null; } - - public static boolean isPlayerOP(EntityPlayer player){ - if (player.canCommandSenderUseCommand(2, "")){ - return true; + if (heldItem != null) { + return heldItem; } - return false; + return null; } - //Not Clientside - public static ItemStack getItemStackInPlayersHand(World world, String Name){ - EntityPlayer thePlayer = getPlayer(Name); + @SideOnly(Side.SERVER) + public static ItemStack getItemStackInPlayersHand(final EntityPlayer player) { ItemStack heldItem = null; - try{heldItem = thePlayer.getHeldItem(); - }catch(NullPointerException e){return null;} - if (heldItem != null){ + try { + heldItem = player.getHeldItem(); + } + catch (final NullPointerException e) { + return null; + } + if (heldItem != null) { return heldItem; } return null; } - @SideOnly(Side.CLIENT) - public static ItemStack getItemStackInPlayersHand(){ - Minecraft mc = Minecraft.getMinecraft(); + // Not Clientside + public static ItemStack getItemStackInPlayersHand(final World world, final String Name) { + final EntityPlayer thePlayer = PlayerUtils.getPlayer(Name); ItemStack heldItem = null; - try{heldItem = mc.thePlayer.getHeldItem(); - }catch(NullPointerException e){return null;} - if (heldItem != null){ + try { + heldItem = thePlayer.getHeldItem(); + } + catch (final NullPointerException e) { + return null; + } + if (heldItem != null) { return heldItem; } return null; } - - @SideOnly(Side.SERVER) - public static ItemStack getItemStackInPlayersHand(EntityPlayer player){ - ItemStack heldItem = null; - try{heldItem = player.getHeldItem(); - }catch(NullPointerException e){return null;} - if (heldItem != null){ - return heldItem; + + public static EntityPlayer getPlayer(final String name) { + final List i = new ArrayList(); + final Iterator crunchifyIterator = MinecraftServer.getServer() + .getConfigurationManager().playerEntityList.iterator(); + while (crunchifyIterator.hasNext()) { + i.add(crunchifyIterator.next()); + } + try { + for (final EntityPlayer temp : i) { + if (temp.getDisplayName().toLowerCase().equals(name.toLowerCase())) { + return temp; + } + } + } + catch (final NullPointerException e) { } return null; } - @SideOnly(Side.CLIENT) - public static Item getItemInPlayersHand(){ - Minecraft mc = Minecraft.getMinecraft(); - Item heldItem = null; - - try{heldItem = mc.thePlayer.getHeldItem().getItem(); - }catch(NullPointerException e){return null;} - - if (heldItem != null){ - return heldItem; + // Not Clientside + public static EntityPlayer getPlayerInWorld(final World world, final String Name) { + final List i = world.playerEntities; + final Minecraft mc = Minecraft.getMinecraft(); + try { + for (final EntityPlayer temp : i) { + if (temp.getDisplayName().toLowerCase().equals(Name.toLowerCase())) { + return temp; + } + } + } + catch (final NullPointerException e) { } - return null; } + public static EntityPlayer getPlayerOnServerFromUUID(final UUID parUUID) { + if (parUUID == null) { + return null; + } + final List allPlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (final EntityPlayerMP player : allPlayers) { + if (player.getUniqueID().equals(parUUID)) { + return player; + } + } + return null; + } + + public static boolean isPlayerOP(final EntityPlayer player) { + if (player.canCommandSenderUseCommand(2, "")) { + return true; + } + return false; + } + + public static void messagePlayer(final EntityPlayer P, final String S) { + gregtech.api.util.GT_Utility.sendChatToPlayer(P, S); + } + } diff --git a/src/Java/gtPlusPlus/core/util/player/UtilsMining.java b/src/Java/gtPlusPlus/core/util/player/UtilsMining.java index 1b6b957b32..e92a5ac41a 100644 --- a/src/Java/gtPlusPlus/core/util/player/UtilsMining.java +++ b/src/Java/gtPlusPlus/core/util/player/UtilsMining.java @@ -8,139 +8,133 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class UtilsMining { - - private static boolean durabilityDamage = false; - private static ItemStack stack; - public static Boolean canPickaxeBlock(Block currentBlock, World currentWorld){ + private static boolean durabilityDamage = false; + private static ItemStack stack; + + public static Boolean canPickaxeBlock(final Block currentBlock, final World currentWorld) { String correctTool = ""; - if (!currentWorld.isRemote){ + if (!currentWorld.isRemote) { try { correctTool = currentBlock.getHarvestTool(0); - //Utils.LOG_WARNING(correctTool); - if (correctTool.equals("pickaxe")){ - return true;} - } catch (NullPointerException e){ - return false;} - } - return false; - } - - private static void removeBlockAndDropAsItem(World world, int X, int Y, int Z){ - try { - Block block = world.getBlock(X, Y, Z); - if (canPickaxeBlock(block, world)){ - if((block != Blocks.bedrock) && (block.getBlockHardness(world, X, Y, Z) != -1) && (block.getBlockHardness(world, X, Y, Z) <= 100) && (block != Blocks.water) && (block != Blocks.lava)){ - block.dropBlockAsItem(world, X, Y, Z, world.getBlockMetadata(X, Y, Z), 0); - world.setBlockToAir(X, Y, Z); - - } - else { - Utils.LOG_WARNING("Incorrect Tool for mining this block."); + // Utils.LOG_WARNING(correctTool); + if (correctTool.equals("pickaxe")) { + return true; } } - } catch (NullPointerException e){ - + catch (final NullPointerException e) { + return false; + } } + return false; } - public static void customMine(World world, String FACING, EntityPlayer aPlayer){ + public static void customMine(final World world, final String FACING, final EntityPlayer aPlayer) { float DURABILITY_LOSS = 0; - if (!world.isRemote){ + if (!world.isRemote) { int X = 0; int Y = 0; int Z = 0; - if (FACING.equals("below") || FACING.equals("above")){ + if (FACING.equals("below") || FACING.equals("above")) { - //Set Player Facing + // Set Player Facing X = (int) aPlayer.posX; - Utils.LOG_WARNING("Setting Variable X: "+X); - if (FACING.equals("above")){ + Utils.LOG_WARNING("Setting Variable X: " + X); + if (FACING.equals("above")) { Z = (int) aPlayer.posY + 1; - Utils.LOG_WARNING("Setting Variable Y: "+Y); - } - else { - Z = (int) aPlayer.posY - 1; - Utils.LOG_WARNING("Setting Variable Y: "+Y);} + Utils.LOG_WARNING("Setting Variable Y: " + Y); + } + else { + Z = (int) aPlayer.posY - 1; + Utils.LOG_WARNING("Setting Variable Y: " + Y); + } Z = (int) aPlayer.posZ; - Utils.LOG_WARNING("Setting Variable Z: "+Z); + Utils.LOG_WARNING("Setting Variable Z: " + Z); DURABILITY_LOSS = 0; - for(int i = -2; i < 3; i++) { - for(int j = -2; j < 3; j++) { - for(int k = -2; k < 3; k++) { -/*// float dur = calculateDurabilityLoss(world, X + i, Y + k, Z + j); -// DURABILITY_LOSS = (DURABILITY_LOSS + dur); -// Utils.LOG_WARNING("Added Loss: "+dur); -*/ removeBlockAndDropAsItem(world, X + i, Y + k, Z + j); + for (int i = -2; i < 3; i++) { + for (int j = -2; j < 3; j++) { + for (int k = -2; k < 3; k++) { + /* + * // float dur = calculateDurabilityLoss(world, X + + * i, Y + k, Z + j); // DURABILITY_LOSS = + * (DURABILITY_LOSS + dur); // Utils.LOG_WARNING( + * "Added Loss: "+dur); + */ UtilsMining.removeBlockAndDropAsItem(world, X + i, Y + k, Z + j); } } } } - else if (FACING.equals("facingEast") || FACING.equals("facingWest")){ + else if (FACING.equals("facingEast") || FACING.equals("facingWest")) { - //Set Player Facing + // Set Player Facing Z = (int) aPlayer.posZ; Y = (int) aPlayer.posY; - if (FACING.equals("facingEast")){ - X = (int) aPlayer.posX + 1;} - else { - X = (int) aPlayer.posX - 1;} - + if (FACING.equals("facingEast")) { + X = (int) aPlayer.posX + 1; + } + else { + X = (int) aPlayer.posX - 1; + } DURABILITY_LOSS = 0; - for(int i = -1; i < 2; i++) { - for(int j = -1; j < 2; j++) { - for(int k = -1; k < 2; k++) { - /*float dur = calculateDurabilityLoss(world, X+k, Y + i, Z + j); - DURABILITY_LOSS = (DURABILITY_LOSS + dur); - Utils.LOG_WARNING("Added Loss: "+dur);*/ - removeBlockAndDropAsItem(world, X+k, Y + i, Z + j); + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int k = -1; k < 2; k++) { + /* + * float dur = calculateDurabilityLoss(world, X+k, Y + * + i, Z + j); DURABILITY_LOSS = (DURABILITY_LOSS + + * dur); Utils.LOG_WARNING("Added Loss: "+dur); + */ + UtilsMining.removeBlockAndDropAsItem(world, X + k, Y + i, Z + j); } } } } - else if (FACING.equals("facingNorth") || FACING.equals("facingSouth")){ + else if (FACING.equals("facingNorth") || FACING.equals("facingSouth")) { - //Set Player Facing + // Set Player Facing X = (int) aPlayer.posX; Y = (int) aPlayer.posY; - - if (FACING.equals("facingNorth")){ - Z = (int) aPlayer.posZ + 1;} + + if (FACING.equals("facingNorth")) { + Z = (int) aPlayer.posZ + 1; + } else { - Z = (int) aPlayer.posZ - 1;} - + Z = (int) aPlayer.posZ - 1; + } + DURABILITY_LOSS = 0; - for(int i = -1; i < 2; i++) { - for(int j = -1; j < 2; j++) { - for(int k = -1; k < 2; k++) { - /*float dur = calculateDurabilityLoss(world, X + j, Y + i, Z+k); - DURABILITY_LOSS = (DURABILITY_LOSS + dur); - Utils.LOG_WARNING("Added Loss: "+dur);*/ - removeBlockAndDropAsItem(world, X + j, Y + i, Z+k); + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int k = -1; k < 2; k++) { + /* + * float dur = calculateDurabilityLoss(world, X + j, + * Y + i, Z+k); DURABILITY_LOSS = (DURABILITY_LOSS + + * dur); Utils.LOG_WARNING("Added Loss: "+dur); + */ + UtilsMining.removeBlockAndDropAsItem(world, X + j, Y + i, Z + k); } } } } - //Set Durability damage to the item - if (durabilityDamage == true){ - Utils.LOG_WARNING("Total Loss: "+(int)DURABILITY_LOSS); - if (stack.getItemDamage() < (stack.getMaxDamage()-DURABILITY_LOSS)){ - stack.damageItem((int) DURABILITY_LOSS, aPlayer); - } + // Set Durability damage to the item + if (UtilsMining.durabilityDamage == true) { + Utils.LOG_WARNING("Total Loss: " + (int) DURABILITY_LOSS); + if (UtilsMining.stack.getItemDamage() < UtilsMining.stack.getMaxDamage() - DURABILITY_LOSS) { + UtilsMining.stack.damageItem((int) DURABILITY_LOSS, aPlayer); + } } DURABILITY_LOSS = 0; } } - - - public static boolean getBlockType(Block block){ + + public static boolean getBlockType(final Block block) { final String LIQUID = "liquid"; final String BLOCK = "block"; final String ORE = "ore"; @@ -150,31 +144,51 @@ public class UtilsMining { try { blockClass = block.getClass().toString().toLowerCase(); Utils.LOG_WARNING(blockClass); - if (blockClass.toLowerCase().contains(LIQUID)){ - Utils.LOG_WARNING(block.toString()+" is a Liquid."); + if (blockClass.toLowerCase().contains(LIQUID)) { + Utils.LOG_WARNING(block.toString() + " is a Liquid."); return false; } - else if (blockClass.toLowerCase().contains(ORE)){ - Utils.LOG_WARNING(block.toString()+" is an Ore."); + else if (blockClass.toLowerCase().contains(ORE)) { + Utils.LOG_WARNING(block.toString() + " is an Ore."); return true; } - else if (blockClass.toLowerCase().contains(AIR)){ - Utils.LOG_WARNING(block.toString()+" is Air."); + else if (blockClass.toLowerCase().contains(AIR)) { + Utils.LOG_WARNING(block.toString() + " is Air."); return false; } - else if (blockClass.toLowerCase().contains(BLOCK)){ - Utils.LOG_WARNING(block.toString()+" is a block of some kind."); + else if (blockClass.toLowerCase().contains(BLOCK)) { + Utils.LOG_WARNING(block.toString() + " is a block of some kind."); return false; } else { - Utils.LOG_WARNING(block.toString()+" is mystery."); + Utils.LOG_WARNING(block.toString() + " is mystery."); return false; } } - catch(NullPointerException e){ + catch (final NullPointerException e) { return false; } } - - + + private static void removeBlockAndDropAsItem(final World world, final int X, final int Y, final int Z) { + try { + final Block block = world.getBlock(X, Y, Z); + if (UtilsMining.canPickaxeBlock(block, world)) { + if (block != Blocks.bedrock && block.getBlockHardness(world, X, Y, Z) != -1 + && block.getBlockHardness(world, X, Y, Z) <= 100 && block != Blocks.water + && block != Blocks.lava) { + block.dropBlockAsItem(world, X, Y, Z, world.getBlockMetadata(X, Y, Z), 0); + world.setBlockToAir(X, Y, Z); + + } + else { + Utils.LOG_WARNING("Incorrect Tool for mining this block."); + } + } + } + catch (final NullPointerException e) { + + } + } + } -- cgit