Optimizations for Mining & Blast Mining

This commit is contained in:
GJ 2012-03-06 01:48:45 -05:00
parent e1644d3c08
commit 798cc3bbb3
2 changed files with 145 additions and 240 deletions

View File

@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
@ -30,13 +29,23 @@ import org.bukkit.event.entity.ExplosionPrimeEvent;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
public class BlastMining{
public static List<Block> explosionYields(List<Block> ores, List<Block> debris, float yield, float oreBonus, float debrisReduction, Location location, int extraDrops)
/**
* Handler for what blocks drop from the explosion.
*
* @param ores List of ore blocks destroyed by the explosion
* @param debris List of non-ore blocks destroyed by the explosion
* @param yield Percentage of blocks to drop
* @param oreBonus Percentage bonus for ore drops
* @param debrisReduction Percentage reduction for non-ore drops
* @param extraDrops Number of times to drop each block
* @param plugin mcMMO plugin instance
* @return A list of blocks dropped from the explosion
*/
private static List<Block> explosionYields(List<Block> ores, List<Block> debris, float yield, float oreBonus, float debrisReduction, int extraDrops, mcMMO plugin)
{
Iterator<Block> iterator2 = ores.iterator();
List<Block> blocksDropped = new ArrayList<Block>();
@ -47,15 +56,18 @@ public class BlastMining{
{
blocksDropped.add(temp);
Mining.miningDrops(temp);
if(extraDrops == 2)
if(temp.getData() != (byte)5 && !plugin.misc.blockWatchList.contains(temp))
{
blocksDropped.add(temp);
Mining.miningDrops(temp);
}
if(extraDrops == 3)
{
blocksDropped.add(temp);
Mining.miningDrops(temp);
if(extraDrops == 2)
{
blocksDropped.add(temp);
Mining.miningDrops(temp);
}
if(extraDrops == 3)
{
blocksDropped.add(temp);
Mining.miningDrops(temp);
}
}
}
}
@ -73,32 +85,30 @@ public class BlastMining{
return blocksDropped;
}
/*
* Process the drops from the explosion
/**
* Handler for explosion drops and XP gain.
* @param player Player triggering the explosion
* @param event Event whose explosion is being processed
* @param plugin mcMMO plugin instance
*/
public static void dropProcessing(Player player, EntityExplodeEvent event, mcMMO plugin)
{
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
float yield = event.getYield();
Location location = event.getLocation();
List<Block> blocks = event.blockList();
Iterator<Block> iterator = blocks.iterator();
List<Block> ores = new ArrayList<Block>();
List<Block> debris = new ArrayList<Block>();
List<Block> xp = new ArrayList<Block>();
while(iterator.hasNext())
{
Block temp = iterator.next();
if(temp.getData() != 5 && !plugin.misc.blockWatchList.contains(temp))
{
if(m.isOre(temp))
ores.add(temp);
else
debris.add(temp);
}
if(m.isOre(temp))
ores.add(temp);
else
debris.add(temp);
}
//Normal explosion
@ -106,51 +116,52 @@ public class BlastMining{
return;
event.setYield(0);
//+35% ores, -10% debris
if(skillLevel >= 125 && skillLevel < 250)
xp = explosionYields(ores, debris, yield, .35f, .10f, location, 1);
xp = explosionYields(ores, debris, yield, .35f, .10f, 1, plugin);
//+40% ores, -20% debris
if(skillLevel >= 250 && skillLevel < 375)
xp = explosionYields(ores, debris, yield, .40f, .20f, location, 1);
xp = explosionYields(ores, debris, yield, .40f, .20f, 1, plugin);
//No debris, +45% ores
if(skillLevel >= 375 && skillLevel < 500)
xp = explosionYields(ores, debris, yield, .45f, .30f, location, 1);
xp = explosionYields(ores, debris, yield, .45f, .30f, 1, plugin);
//No debris, +50% ores
if(skillLevel >= 500 && skillLevel < 625)
xp = explosionYields(ores, debris, yield, .50f, .30f, location, 1);
xp = explosionYields(ores, debris, yield, .50f, .30f, 1, plugin);
//Double Drops, No Debris, +55% ores
if(skillLevel >= 625 && skillLevel < 750)
xp = explosionYields(ores, debris, yield, .55f, .30f, location, 2);
xp = explosionYields(ores, debris, yield, .55f, .30f, 2, plugin);
//Double Drops, No Debris, +60% ores
if(skillLevel >= 750 && skillLevel < 875)
xp = explosionYields(ores, debris, yield, .60f, .30f, location, 2);
xp = explosionYields(ores, debris, yield, .60f, .30f, 2, plugin);
//Triple Drops, No debris, +65% ores
if(skillLevel >= 875 && skillLevel < 1000)
xp = explosionYields(ores, debris, yield, .65f, .30f, location, 3);
xp = explosionYields(ores, debris, yield, .65f, .30f, 3, plugin);
//Triple Drops, No debris, +70% ores
if(skillLevel >= 1000)
xp = explosionYields(ores, debris, yield, .70f, .30f, location, 3);
xp = explosionYields(ores, debris, yield, .70f, .30f, 3, plugin);
for(Block block : xp)
{
blastMiningXP(player, block, plugin);
if(block.getData() != (byte)5 && !plugin.misc.blockWatchList.contains(block))
Mining.miningXP(player, block);
}
}
/*
* Bigger Bombs (Unlocked at Mining 250)
/**
* Increases the blast radius of the explosion.
*
* Increases radius of explosion by 1 at 250.
* Increases radius of explosion by 2 at 500.
* Increases radius of explosion by 3 at 750.
* Increases radius of explosion by 4 at 1000.
* @param player Player triggering the explosion
* @param event Event whose explosion radius is being changed
*/
public static void biggerBombs(Player player, ExplosionPrimeEvent event)
{
@ -169,12 +180,11 @@ public class BlastMining{
event.setRadius(radius);
}
/*
* Demolitions Expertise (Unlocked at Mining 500)
/**
* Decreases damage dealt by the explosion.
*
* Reduces explosion damage to 1/4 of normal at 500.
* Reduces explosion damage to 1/2 of normal at 750.
* Reduces explosion damage to 0 at 1000.
* @param player Player triggering the explosion
* @param event Event whose explosion damage is being reduced
*/
public static void demolitionsExpertise(Player player, EntityDamageEvent event)
{
@ -188,46 +198,8 @@ public class BlastMining{
damage = damage/2;
if(skill >= 1000)
damage = 0;
event.setDamage(damage);
}
public static void blastMiningXP(Player player, Block block, mcMMO plugin)
{
PlayerProfile PP = Users.getProfile(player);
if(plugin.misc.blockWatchList.contains(block) || block.getData() == (byte) 5)
return;
int xp = 0;
switch (block.getType()) {
//COAL
case COAL_ORE:
xp += LoadProperties.mcoal;
break;
//GOLD
case GOLD_ORE:
xp += LoadProperties.mgold;
break;
//DIAMOND
case DIAMOND_ORE:
xp += LoadProperties.mdiamond;
break;
//IRON
case IRON_ORE:
xp += LoadProperties.miron;
break;
//REDSTONE
case REDSTONE_ORE:
xp += LoadProperties.mredstone;
break;
//LAPIS
case LAPIS_ORE:
xp += LoadProperties.mlapis;
break;
}
PP.addXP(SkillType.MINING, xp, player);
Skills.XpCheckSkill(SkillType.MINING, player);
}
}

View File

@ -16,7 +16,6 @@
*/
package com.gmail.nossr50.skills;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -24,7 +23,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.sound.SoundEffect;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.player.PlayerAnimationEvent;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
@ -80,6 +78,60 @@ public class Mining
}
}
public static void miningXP(Player player, Block block)
{
PlayerProfile PP = Users.getProfile(player);
Material type = block.getType();
int xp = 0;
switch (type)
{
case COAL_ORE:
xp += LoadProperties.mcoal;
break;
case DIAMOND_ORE:
xp += LoadProperties.mdiamond;
break;
case ENDER_STONE:
xp += LoadProperties.mendstone;
break;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
xp += LoadProperties.mredstone;
break;
case GLOWSTONE:
xp += LoadProperties.mglowstone;
break;
case GOLD_ORE:
xp += LoadProperties.mgold;
break;
case IRON_ORE:
xp += LoadProperties.miron;
break;
case LAPIS_ORE:
xp += LoadProperties.mlapis;
break;
case MOSSY_COBBLESTONE:
xp += LoadProperties.mmossstone;
break;
case NETHERRACK:
xp += LoadProperties.mnetherrack;
break;
case OBSIDIAN:
xp += LoadProperties.mobsidian;
break;
case SANDSTONE:
xp += LoadProperties.msandstone;
break;
case STONE:
xp += LoadProperties.mstone;
break;
}
PP.addXP(SkillType.MINING, xp, player);
Skills.XpCheckSkill(SkillType.MINING, player);
}
public static void blockProcSimulate(Block block, Player player)
{
//Drop natural block with Silk Touch
@ -99,58 +151,11 @@ public class Mining
public static void miningBlockCheck(Player player, Block block, mcMMO plugin)
{
PlayerProfile PP = Users.getProfile(player);
if(plugin.misc.blockWatchList.contains(block) || block.getData() == (byte) 5)
return;
int xp = 0;
Material type = block.getType();
switch (type) {
case STONE:
xp += LoadProperties.mstone;
break;
case SANDSTONE:
xp += LoadProperties.msandstone;
break;
case OBSIDIAN:
xp += LoadProperties.mobsidian;
break;
case NETHERRACK:
xp += LoadProperties.mnetherrack;
break;
case GLOWSTONE:
xp += LoadProperties.mglowstone;
break;
case COAL_ORE:
xp += LoadProperties.mcoal;
break;
case GOLD_ORE:
xp += LoadProperties.mgold;
break;
case DIAMOND_ORE:
xp += LoadProperties.mdiamond;
break;
case IRON_ORE:
xp += LoadProperties.miron;
break;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
xp += LoadProperties.mredstone;
break;
case LAPIS_ORE:
xp += LoadProperties.mlapis;
break;
case ENDER_STONE:
xp += LoadProperties.mendstone;
break;
case MOSSY_COBBLESTONE:
xp += LoadProperties.mmossstone;
break;
}
miningXP(player, block);
if(canBeSuperBroken(block))
blockProcCheck(block, player);
PP.addXP(SkillType.MINING, xp, player);
Skills.XpCheckSkill(SkillType.MINING, player);
}
/*
@ -180,114 +185,42 @@ public class Mining
public static void SuperBreakerBlockCheck(Player player, Block block, mcMMO plugin)
{
PlayerProfile PP = Users.getProfile(player);
Material type = block.getType();
int tier = m.getTier(player);
int durabilityLoss = LoadProperties.abilityDurabilityLoss;
//Obsidian needs to do more damage than normal
if(type != Material.OBSIDIAN)
Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss);
else
Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss*5);
//Pre-processing
int xp = 0;
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
if(type.equals(Material.STONE) && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mstone;
switch(type)
{
case OBSIDIAN:
if(tier < 4)
return;
durabilityLoss = durabilityLoss * 5; //Obsidian needs to do more damage than normal
case DIAMOND_ORE:
case GLOWING_REDSTONE_ORE:
case GOLD_ORE:
case LAPIS_ORE:
case REDSTONE_ORE:
if(tier < 3)
return;
case IRON_ORE:
if(tier < 2)
return;
case COAL_ORE:
case ENDER_STONE:
case GLOWSTONE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case SANDSTONE:
case STONE:
if((block.getData() == (byte) 5) || plugin.misc.blockWatchList.contains(block))
return;
Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss);
blockProcCheck(block, player);
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.SANDSTONE) && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.msandstone;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.NETHERRACK) && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mnetherrack;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.GLOWSTONE) && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mglowstone;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.COAL_ORE) && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mcoal;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.GOLD_ORE) && m.getTier(player) >= 3 && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mgold;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.OBSIDIAN) && m.getTier(player) >= 4 && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mobsidian;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.DIAMOND_ORE) && m.getTier(player) >= 3 && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mdiamond;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.IRON_ORE) && m.getTier(player) >= 2 && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.miron;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if((type.equals(Material.GLOWING_REDSTONE_ORE) || type.equals(Material.REDSTONE_ORE)) && m.getTier(player) >= 3 && !plugin.misc.blockWatchList.contains(block))
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mredstone;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.LAPIS_ORE) && m.getTier(player) >= 3 && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mlapis;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.ENDER_STONE) && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mendstone;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
else if(type.equals(Material.MOSSY_COBBLESTONE) && block.getData() != (byte) 5)
{
Bukkit.getPluginManager().callEvent(armswing);
xp += LoadProperties.mmossstone;
blockProcCheck(block, player);
blockProcCheck(block, player);
}
if(!plugin.misc.blockWatchList.contains(block) && block.getData() != (byte) 5)
PP.addXP(SkillType.MINING, xp, player);
if(LoadProperties.spoutEnabled)
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
Skills.XpCheckSkill(SkillType.MINING, player);
if(!plugin.misc.blockWatchList.contains(block) && block.getData() != (byte) 5)
miningXP(player, block);
if(LoadProperties.spoutEnabled)
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
}
}
}