Rewrote excavation to be a tiny bit faster and overall cleaner

This commit is contained in:
nossr50 2011-08-06 16:31:34 -07:00
parent 8b3e8947c0
commit ca9e5c5349
2 changed files with 126 additions and 153 deletions

View File

@ -18,6 +18,7 @@ import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import org.getspout.spoutapi.sound.SoundEffect; import org.getspout.spoutapi.sound.SoundEffect;
@ -26,27 +27,33 @@ import com.gmail.nossr50.skills.*;
import com.gmail.nossr50.datatypes.FakeBlockBreakEvent; import com.gmail.nossr50.datatypes.FakeBlockBreakEvent;
public class mcBlockListener extends BlockListener { public class mcBlockListener extends BlockListener
{
private final mcMMO plugin; private final mcMMO plugin;
public mcBlockListener(final mcMMO plugin) { public mcBlockListener(final mcMMO plugin)
{
this.plugin = plugin; this.plugin = plugin;
} }
public void onBlockPlace(BlockPlaceEvent event) public void onBlockPlace(BlockPlaceEvent event)
{ {
//Setup some basic vars
Block block; Block block;
Player player = event.getPlayer(); Player player = event.getPlayer();
if (event.getBlock() != null && event.getBlockReplacedState() != null && event.getBlockReplacedState().getTypeId() == 78)
//When blocks are placed on snow this event reports the wrong block.
if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getTypeId() == 78)
{ {
block = event.getBlockAgainst(); block = event.getBlockAgainst();
} }
else else
{ {
block = event.getBlock(); block = event.getBlock();
} }
if(player != null && m.shouldBeWatched(block))
//Check if the blocks placed should be monitored so they do not give out XP in the future
if(m.shouldBeWatched(block))
{ {
if(block.getTypeId() != 17 && block.getTypeId() != 39 && block.getTypeId() != 40 && block.getTypeId() != 91 && block.getTypeId() != 86) if(block.getTypeId() != 17 && block.getTypeId() != 39 && block.getTypeId() != 40 && block.getTypeId() != 91 && block.getTypeId() != 86)
block.setData((byte) 5); //Change the byte block.setData((byte) 5); //Change the byte
@ -59,7 +66,7 @@ public class mcBlockListener extends BlockListener {
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
if(LoadProperties.spoutEnabled) if(LoadProperties.spoutEnabled)
{ {
SpoutPlayer sPlayer = (SpoutPlayer)player; SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
if(sPlayer.isSpoutCraftEnabled()) if(sPlayer.isSpoutCraftEnabled())
{ {
if(!PP.getPlacedAnvil()) if(!PP.getPlacedAnvil())
@ -104,10 +111,13 @@ public class mcBlockListener extends BlockListener {
/* /*
* HERBALISM * HERBALISM
*/ */
//Green Terra
if(PP.getHoePreparationMode() && mcPermissions.getInstance().herbalismAbility(player) && block.getTypeId() == 59 && block.getData() == (byte) 0x07) if(PP.getHoePreparationMode() && mcPermissions.getInstance().herbalismAbility(player) && block.getTypeId() == 59 && block.getData() == (byte) 0x07)
{ {
Herbalism.greenTerraCheck(player, block, plugin); Herbalism.greenTerraCheck(player, block, plugin);
} }
//Wheat && Triple drops //Wheat && Triple drops
if(PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block)) if(PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block))
{ {
@ -233,7 +243,7 @@ public class mcBlockListener extends BlockListener {
/* /*
* EXCAVATION * EXCAVATION
*/ */
if(mcPermissions.getInstance().excavation(player)) if(mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 5)
Excavation.excavationProcCheck(block.getData(), block.getTypeId(), block.getLocation(), player); Excavation.excavationProcCheck(block.getData(), block.getTypeId(), block.getLocation(), player);
/* /*
* HERBALISM * HERBALISM
@ -254,13 +264,10 @@ public class mcBlockListener extends BlockListener {
plugin.misc.blockWatchList.remove(block); plugin.misc.blockWatchList.remove(block);
} }
} }
} }
public void onBlockDamage(BlockDamageEvent event) public void onBlockDamage(BlockDamageEvent event)
{ {
if(event.isCancelled()) if(event.isCancelled())
return; return;
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -284,36 +291,6 @@ public class mcBlockListener extends BlockListener {
if(PP.getFistsPreparationMode() && (Excavation.canBeGigaDrillBroken(block) || block.getTypeId() == 78)) if(PP.getFistsPreparationMode() && (Excavation.canBeGigaDrillBroken(block) || block.getTypeId() == 78))
Unarmed.berserkActivationCheck(player, plugin); Unarmed.berserkActivationCheck(player, plugin);
/*
if(mcPermissions.getInstance().mining(player) && Mining.canBeSuperBroken(block) &&
m.blockBreakSimulate(block, player, plugin) && PP.getSkillLevel(SkillType.MINING) >= 250
&& block.getType() != Material.STONE && m.isMiningPick(inhand))
{
contribStuff.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation());
if(PP.getSkillLevel(SkillType.MINING) >= 500)
{
if(Math.random() * 100 > 99)
{
Mining.blockProcSmeltSimulate(block);
Mining.miningBlockCheck(true, player, block, plugin); //PROC
block.setType(Material.AIR);
contribStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
}
} else
{
if(Math.random() * 100 > 97)
{
Mining.blockProcSmeltSimulate(block);
Mining.miningBlockCheck(true, player, block, plugin); //PROC
block.setType(Material.AIR);
contribStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
}
}
}
*/
/* /*
* TREE FELLAN STUFF * TREE FELLAN STUFF
*/ */
@ -323,7 +300,8 @@ public class mcBlockListener extends BlockListener {
/* /*
* GREEN TERRA STUFF * GREEN TERRA STUFF
*/ */
if(PP.getGreenTerraMode() && mcPermissions.getInstance().herbalismAbility(player) && PP.getGreenTerraMode()){ if(PP.getGreenTerraMode() && mcPermissions.getInstance().herbalismAbility(player) && PP.getGreenTerraMode())
{
Herbalism.greenTerra(player, block); Herbalism.greenTerra(player, block);
} }
@ -333,27 +311,33 @@ public class mcBlockListener extends BlockListener {
if(PP.getGigaDrillBreakerMode() && m.blockBreakSimulate(block, player, plugin) if(PP.getGigaDrillBreakerMode() && m.blockBreakSimulate(block, player, plugin)
&& Excavation.canBeGigaDrillBroken(block) && m.isShovel(inhand)) && Excavation.canBeGigaDrillBroken(block) && m.isShovel(inhand))
{ {
int x = 0;
int x = 1; while(x < 3)
while(x < 4)
{ {
Excavation.excavationProcCheck(block.getData(), block.getTypeId(), block.getLocation(), player); if(block.getData() != (byte)5)
Excavation.excavationProcCheck(block.getData(), block.getTypeId(), block.getLocation(), player);
x++; x++;
} }
Material mat = Material.getMaterial(block.getTypeId()); Material mat = Material.getMaterial(block.getTypeId());
if(block.getTypeId() == 2) if(block.getTypeId() == 2)
mat = Material.DIRT; mat = Material.DIRT;
byte type = block.getData(); byte type = block.getData();
ItemStack item = new ItemStack(mat, 1, (byte)0, type); ItemStack item = new ItemStack(mat, 1, (byte)0, type);
block.setType(Material.AIR); block.setType(Material.AIR);
player.incrementStatistic(Statistic.MINE_BLOCK, event.getBlock().getType()); player.incrementStatistic(Statistic.MINE_BLOCK, event.getBlock().getType());
if(LoadProperties.toolsLoseDurabilityFromAbilities) if(LoadProperties.toolsLoseDurabilityFromAbilities)
m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss); m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss);
block.getLocation().getWorld().dropItemNaturally(block.getLocation(), item); block.getLocation().getWorld().dropItemNaturally(block.getLocation(), item);
//Contrib stuff //Spout stuff
if(LoadProperties.spoutEnabled) if(LoadProperties.spoutEnabled)
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation()); SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
} }

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills; package com.gmail.nossr50.skills;
import java.util.ArrayList;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -66,45 +68,84 @@ public class Excavation
public static void excavationProcCheck(byte data, int type, Location loc, Player player) public static void excavationProcCheck(byte data, int type, Location loc, Player player)
{ {
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
ItemStack is = null; ArrayList<ItemStack> is = new ArrayList<ItemStack>();
Material mat = null;
if(data == (byte) 5)
return;
if(type == 2) int xp = 0;
switch(type)
{ {
case 2:
if(PP.getSkillLevel(SkillType.EXCAVATION) >= 250) if(PP.getSkillLevel(SkillType.EXCAVATION) >= 250)
{ {
//CHANCE TO GET EGGS //CHANCE TO GET EGGS
if(LoadProperties.eggs == true && Math.random() * 100 > 99) if(LoadProperties.eggs == true && Math.random() * 100 > 99)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.meggs * LoadProperties.xpGainMultiplier); xp+= LoadProperties.meggs * LoadProperties.xpGainMultiplier;
mat = Material.getMaterial(344); is.add(new ItemStack(Material.EGG, 1, (byte)0, (byte)0));
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
} }
//CHANCE TO GET APPLES //CHANCE TO GET APPLES
if(LoadProperties.apples == true && Math.random() * 100 > 99) if(LoadProperties.apples == true && Math.random() * 100 > 99)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.mapple * LoadProperties.xpGainMultiplier); xp+= LoadProperties.mapple * LoadProperties.xpGainMultiplier;
mat = Material.getMaterial(260); is.add(new ItemStack(Material.APPLE, 1, (byte)0, (byte)0));
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
} }
} }
break;
case 3:
//CHANCE TO GET NETHERRACK
if(LoadProperties.netherrack == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 850 && Math.random() * 200 > 199)
{
xp+= LoadProperties.mnetherrack * LoadProperties.xpGainMultiplier;
is.add(new ItemStack(Material.NETHERRACK, 1, (byte)0, (byte)0));
}
//CHANCE TO GET SULPHUR
if(LoadProperties.sulphur == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 75)
{
if(Math.random() * 10 > 9)
{
xp+= LoadProperties.msulphur * LoadProperties.xpGainMultiplier;
is.add(new ItemStack(Material.SULPHUR, 1, (byte)0, (byte)0));
}
}
//CHANCE TO GET BONES
if(LoadProperties.bones == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 175)
{
if(Math.random() * 10 > 9)
{
xp+= LoadProperties.mbones * LoadProperties.xpGainMultiplier;
is.add(new ItemStack(Material.BONE, 1, (byte)0, (byte)0));
}
}
break;
case 12:
//CHANCE TO GET GLOWSTONE
if(LoadProperties.glowstone == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 50 && Math.random() * 100 > 95)
{
xp+= LoadProperties.mglowstone2 * LoadProperties.xpGainMultiplier;
is.add(new ItemStack(Material.GLOWSTONE_DUST, 1, (byte)0, (byte)0));
}
//CHANCE TO GET SOUL SAND
if(LoadProperties.slowsand == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 650 && Math.random() * 200 > 199)
{
xp+= LoadProperties.mslowsand * LoadProperties.xpGainMultiplier;
is.add(new ItemStack(Material.SOUL_SAND, 1, (byte)0, (byte)0));
}
break;
} }
//DIRT SAND OR GRAVEL //DIRT SAND OR GRAVEL
if(type == 3 || type == 13 || type == 2 || type == 12) if(type == 3 || type == 13 || type == 2 || type == 12)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.mbase * LoadProperties.xpGainMultiplier); xp+= LoadProperties.mbase * LoadProperties.xpGainMultiplier;
if(PP.getSkillLevel(SkillType.EXCAVATION) >= 750){ if(PP.getSkillLevel(SkillType.EXCAVATION) >= 750)
{
//CHANCE TO GET CAKE //CHANCE TO GET CAKE
if(LoadProperties.cake == true && Math.random() * 2000 > 1999) if(LoadProperties.cake == true && Math.random() * 2000 > 1999)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.mcake * LoadProperties.xpGainMultiplier); xp+= LoadProperties.mcake * LoadProperties.xpGainMultiplier;
mat = Material.getMaterial(354); is.add(new ItemStack(Material.CAKE, 1, (byte)0, (byte)0));
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
} }
} }
if(PP.getSkillLevel(SkillType.EXCAVATION) >= 350) if(PP.getSkillLevel(SkillType.EXCAVATION) >= 350)
@ -112,10 +153,8 @@ public class Excavation
//CHANCE TO GET DIAMOND //CHANCE TO GET DIAMOND
if(LoadProperties.diamond == true && Math.random() * 750 > 749) if(LoadProperties.diamond == true && Math.random() * 750 > 749)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.mdiamond2 * LoadProperties.xpGainMultiplier); xp+= LoadProperties.mdiamond2 * LoadProperties.xpGainMultiplier;
mat = Material.getMaterial(264); is.add(new ItemStack(Material.DIAMOND, 1, (byte)0, (byte)0));
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
} }
} }
if(PP.getSkillLevel(SkillType.EXCAVATION) >= 250) if(PP.getSkillLevel(SkillType.EXCAVATION) >= 250)
@ -123,45 +162,21 @@ public class Excavation
//CHANCE TO GET YELLOW MUSIC //CHANCE TO GET YELLOW MUSIC
if(LoadProperties.music == true && Math.random() * 2000 > 1999) if(LoadProperties.music == true && Math.random() * 2000 > 1999)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.mmusic * LoadProperties.xpGainMultiplier); xp+= LoadProperties.mmusic * LoadProperties.xpGainMultiplier;
mat = Material.getMaterial(2256); is.add(new ItemStack(Material.GOLD_RECORD, 1, (byte)0, (byte)0));
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
} }
} }
if(PP.getSkillLevel(SkillType.EXCAVATION) >= 350) if(PP.getSkillLevel(SkillType.EXCAVATION) >= 350)
{ {
//CHANCE TO GET GREEN MUSIC //CHANCE TO GET GREEN MUSIC
if(LoadProperties.music == true && Math.random() * 2000 > 1999) if(LoadProperties.music == true && Math.random() * 2000 > 1999)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.mmusic * LoadProperties.xpGainMultiplier); xp+= LoadProperties.mmusic * LoadProperties.xpGainMultiplier;
mat = Material.getMaterial(2257); is.add(new ItemStack(Material.GREEN_RECORD, 1, (byte)0, (byte)0));
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
} }
} }
} }
//SAND
if(type == 12)
{
//CHANCE TO GET GLOWSTONE
if(LoadProperties.glowstone == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 50 && Math.random() * 100 > 95)
{
PP.addXP(SkillType.EXCAVATION, LoadProperties.mglowstone2 * LoadProperties.xpGainMultiplier);
mat = Material.getMaterial(348);
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
}
//CHANCE TO GET SLOWSAND
if(LoadProperties.slowsand == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 650 && Math.random() * 200 > 199)
{
PP.addXP(SkillType.EXCAVATION, LoadProperties.mslowsand * LoadProperties.xpGainMultiplier);
mat = Material.getMaterial(88);
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
}
}
//GRASS OR DIRT //GRASS OR DIRT
if(type == 2 || type == 3) if(type == 2 || type == 3)
{ {
@ -170,68 +185,42 @@ public class Excavation
//CHANCE FOR COCOA BEANS //CHANCE FOR COCOA BEANS
if(LoadProperties.cocoabeans == true && Math.random() * 75 > 74) if(LoadProperties.cocoabeans == true && Math.random() * 75 > 74)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.mcocoa * LoadProperties.xpGainMultiplier); xp+= LoadProperties.mcocoa * LoadProperties.xpGainMultiplier;
mat = Material.getMaterial(351); is.add(new ItemStack(Material.getMaterial(351), 1, (short)3, (byte)0));
is = new ItemStack(mat, 1, (byte)0, (byte)0);
is.setDurability((byte) 3); //COCOA
loc.getWorld().dropItemNaturally(loc, is);
} }
} }
//CHANCE FOR SHROOMS //CHANCE FOR SHROOMS
if(LoadProperties.mushrooms == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 500 && Math.random() * 200 > 199) if(LoadProperties.mushrooms == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 500 && Math.random() * 200 > 199)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.mmushroom2 * LoadProperties.xpGainMultiplier); xp+= LoadProperties.mmushroom2 * LoadProperties.xpGainMultiplier;
if(Math.random() * 10 > 5){ switch((int) Math.random() * 1)
mat = Material.getMaterial(39); {
} else { case 0:
mat = Material.getMaterial(40); is.add(new ItemStack(Material.BROWN_MUSHROOM, 1, (byte)0, (byte)0));
break;
case 1:
is.add(new ItemStack(Material.RED_MUSHROOM, 1, (byte)0, (byte)0));
break;
} }
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
} }
//CHANCE TO GET GLOWSTONE //CHANCE TO GET GLOWSTONE
if(LoadProperties.glowstone == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 25 && Math.random() * 100 > 95) if(LoadProperties.glowstone == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 25 && Math.random() * 100 > 95)
{ {
PP.addXP(SkillType.EXCAVATION, LoadProperties.mglowstone2 * LoadProperties.xpGainMultiplier); xp+= LoadProperties.mglowstone2 * LoadProperties.xpGainMultiplier;
mat = Material.getMaterial(348); is.add(new ItemStack(Material.GLOWSTONE_DUST, 1, (byte)0, (byte)0));
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
} }
} }
//GRAVEL
if(type == 13) //Drop items
for(ItemStack x : is)
{ {
//CHANCE TO GET NETHERRACK if(x != null)
if(LoadProperties.netherrack == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 850 && Math.random() * 200 > 199) loc.getWorld().dropItemNaturally(loc, x);
{
PP.addXP(SkillType.EXCAVATION, LoadProperties.mnetherrack * LoadProperties.xpGainMultiplier);
mat = Material.getMaterial(87);
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
}
//CHANCE TO GET SULPHUR
if(LoadProperties.sulphur == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 75)
{
if(Math.random() * 10 > 9)
{
PP.addXP(SkillType.EXCAVATION, LoadProperties.msulphur * LoadProperties.xpGainMultiplier);
mat = Material.getMaterial(289);
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
}
}
//CHANCE TO GET BONES
if(LoadProperties.bones == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 175)
{
if(Math.random() * 10 > 9)
{
PP.addXP(SkillType.EXCAVATION, LoadProperties.mbones * LoadProperties.xpGainMultiplier);
mat = Material.getMaterial(352);
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
}
}
} }
//Handle XP related tasks
PP.addXP(SkillType.EXCAVATION, xp);
Skills.XpCheckSkill(SkillType.EXCAVATION, player); Skills.XpCheckSkill(SkillType.EXCAVATION, player);
} }
} }