mcMMO/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java

146 lines
4.8 KiB
Java
Raw Normal View History

package com.gmail.nossr50.skills.excavation;
2012-01-09 20:00:13 +01:00
import java.util.ArrayList;
2012-03-12 22:57:44 +01:00
import java.util.List;
2012-01-09 20:00:13 +01:00
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
2012-01-09 20:00:13 +01:00
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
2012-04-26 16:27:57 +02:00
import com.gmail.nossr50.config.Config;
2012-05-17 16:26:21 +02:00
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
2013-01-30 17:35:33 +01:00
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
2012-06-05 16:13:10 +02:00
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
2012-01-09 20:00:13 +01:00
2012-03-12 22:57:44 +01:00
public class Excavation {
public static boolean requiresTool = Config.getInstance().getExcavationRequiresTool();
2012-03-12 22:57:44 +01:00
/**
* Check to see if treasures were found.
*
* @param block The block to check
* @param mcMMOPlayer The player who broke the block
2012-03-12 22:57:44 +01:00
*/
public static void excavationProcCheck(Block block, McMMOPlayer mcMMOPlayer) {
Material material = block.getType();
int xp;
switch (material) {
2013-01-29 18:02:32 +01:00
case CLAY:
xp = Config.getInstance().getExcavationClayXP();
break;
2012-12-25 07:01:10 +01:00
2013-01-29 18:02:32 +01:00
case DIRT:
xp = Config.getInstance().getExcavationDirtXP();
break;
2013-01-29 18:02:32 +01:00
case GRASS:
xp = Config.getInstance().getExcavationGrassXP();
break;
2013-01-29 18:02:32 +01:00
case GRAVEL:
xp = Config.getInstance().getExcavationGravelXP();
break;
2013-01-29 18:02:32 +01:00
case MYCEL:
xp = Config.getInstance().getExcavationMycelXP();
break;
2013-01-29 18:02:32 +01:00
case SAND:
xp = Config.getInstance().getExcavationSandXP();
break;
2013-01-29 18:02:32 +01:00
case SOUL_SAND:
xp = Config.getInstance().getExcavationSoulSandXP();
break;
2013-01-29 18:02:32 +01:00
default:
xp = ModChecks.getCustomBlock(block).getXpGain();;
break;
}
2012-03-12 22:57:44 +01:00
Player player = mcMMOPlayer.getPlayer();
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
2013-01-07 02:52:31 +01:00
if (Permissions.excavationTreasures(player)) {
switch (material) {
case DIRT:
2012-05-17 16:26:21 +02:00
treasures = TreasuresConfig.getInstance().excavationFromDirt;
break;
2012-03-12 22:57:44 +01:00
case GRASS:
2012-05-17 16:26:21 +02:00
treasures = TreasuresConfig.getInstance().excavationFromGrass;
break;
2012-03-12 22:57:44 +01:00
case SAND:
2012-05-17 16:26:21 +02:00
treasures = TreasuresConfig.getInstance().excavationFromSand;
break;
2012-03-12 22:57:44 +01:00
case GRAVEL:
2012-05-17 16:26:21 +02:00
treasures = TreasuresConfig.getInstance().excavationFromGravel;
break;
2012-03-12 22:57:44 +01:00
case CLAY:
2012-05-17 16:26:21 +02:00
treasures = TreasuresConfig.getInstance().excavationFromClay;
break;
2012-03-12 22:57:44 +01:00
case MYCEL:
2012-05-17 16:26:21 +02:00
treasures = TreasuresConfig.getInstance().excavationFromMycel;
break;
2012-03-12 22:57:44 +01:00
case SOUL_SAND:
2012-05-17 16:26:21 +02:00
treasures = TreasuresConfig.getInstance().excavationFromSoulSand;
break;
2012-03-12 22:57:44 +01:00
default:
break;
}
2012-03-12 22:57:44 +01:00
Location location = block.getLocation();
for (ExcavationTreasure treasure : treasures) {
if (mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION) >= treasure.getDropLevel()) {
2013-01-22 02:01:33 +01:00
int activationChance = Misc.calculateActivationChance(Permissions.luckyExcavation(player));
2013-01-22 02:01:33 +01:00
if (Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
xp += treasure.getXp();
Misc.dropItem(location, treasure.getDrop());
}
2012-03-12 22:57:44 +01:00
}
}
}
mcMMOPlayer.addXp(SkillType.EXCAVATION, xp);
2012-03-12 22:57:44 +01:00
}
/**
* Handle triple drops from Giga Drill Breaker.
*
* @param mcMMOPlayer The player using the ability
2012-03-12 22:57:44 +01:00
* @param block The block to check
*/
public static void gigaDrillBreaker(McMMOPlayer mcMMOplayer, Block block) {
Player player = mcMMOplayer.getPlayer();
2013-01-26 23:01:55 +01:00
SkillTools.abilityDurabilityLoss(player.getItemInHand(), Misc.toolDurabilityLoss);
2012-03-12 22:57:44 +01:00
if (!mcMMO.placeStore.isTrue(block) && Misc.blockBreakSimulate(block, player, true)) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
2012-03-12 22:57:44 +01:00
Excavation.excavationProcCheck(block, mcMMOplayer);
Excavation.excavationProcCheck(block, mcMMOplayer);
2012-03-12 22:57:44 +01:00
}
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
2012-01-09 20:00:13 +01:00
}
2012-02-01 21:57:47 +01:00
}