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.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import org.getspout.spoutapi.sound.SoundEffect;
@ -26,19 +27,23 @@ import com.gmail.nossr50.skills.*;
import com.gmail.nossr50.datatypes.FakeBlockBreakEvent;
public class mcBlockListener extends BlockListener {
public class mcBlockListener extends BlockListener
{
private final mcMMO plugin;
public mcBlockListener(final mcMMO plugin) {
public mcBlockListener(final mcMMO plugin)
{
this.plugin = plugin;
}
public void onBlockPlace(BlockPlaceEvent event)
{
//Setup some basic vars
Block block;
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();
}
@ -46,7 +51,9 @@ public class mcBlockListener extends BlockListener {
{
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)
block.setData((byte) 5); //Change the byte
@ -59,7 +66,7 @@ public class mcBlockListener extends BlockListener {
PlayerProfile PP = Users.getProfile(player);
if(LoadProperties.spoutEnabled)
{
SpoutPlayer sPlayer = (SpoutPlayer)player;
SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
if(sPlayer.isSpoutCraftEnabled())
{
if(!PP.getPlacedAnvil())
@ -104,10 +111,13 @@ public class mcBlockListener extends BlockListener {
/*
* HERBALISM
*/
//Green Terra
if(PP.getHoePreparationMode() && mcPermissions.getInstance().herbalismAbility(player) && block.getTypeId() == 59 && block.getData() == (byte) 0x07)
{
Herbalism.greenTerraCheck(player, block, plugin);
}
//Wheat && Triple drops
if(PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block))
{
@ -233,7 +243,7 @@ public class mcBlockListener extends BlockListener {
/*
* EXCAVATION
*/
if(mcPermissions.getInstance().excavation(player))
if(mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 5)
Excavation.excavationProcCheck(block.getData(), block.getTypeId(), block.getLocation(), player);
/*
* HERBALISM
@ -254,13 +264,10 @@ public class mcBlockListener extends BlockListener {
plugin.misc.blockWatchList.remove(block);
}
}
}
public void onBlockDamage(BlockDamageEvent event)
{
if(event.isCancelled())
return;
Player player = event.getPlayer();
@ -284,36 +291,6 @@ public class mcBlockListener extends BlockListener {
if(PP.getFistsPreparationMode() && (Excavation.canBeGigaDrillBroken(block) || block.getTypeId() == 78))
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
*/
@ -323,7 +300,8 @@ public class mcBlockListener extends BlockListener {
/*
* 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);
}
@ -333,27 +311,33 @@ public class mcBlockListener extends BlockListener {
if(PP.getGigaDrillBreakerMode() && m.blockBreakSimulate(block, player, plugin)
&& Excavation.canBeGigaDrillBroken(block) && m.isShovel(inhand))
{
int x = 0;
int x = 1;
while(x < 4)
while(x < 3)
{
if(block.getData() != (byte)5)
Excavation.excavationProcCheck(block.getData(), block.getTypeId(), block.getLocation(), player);
x++;
}
Material mat = Material.getMaterial(block.getTypeId());
if(block.getTypeId() == 2)
mat = Material.DIRT;
byte type = block.getData();
ItemStack item = new ItemStack(mat, 1, (byte)0, type);
block.setType(Material.AIR);
player.incrementStatistic(Statistic.MINE_BLOCK, event.getBlock().getType());
if(LoadProperties.toolsLoseDurabilityFromAbilities)
m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss);
block.getLocation().getWorld().dropItemNaturally(block.getLocation(), item);
//Contrib stuff
//Spout stuff
if(LoadProperties.spoutEnabled)
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
}

View File

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