2013-01-22 18:43:25 +01:00
|
|
|
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-02-05 21:24:44 +01:00
|
|
|
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2013-01-30 00:36:16 +01:00
|
|
|
import org.bukkit.Sound;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
2012-02-05 21:24:44 +01:00
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
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;
|
2013-02-01 06:38:25 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2012-02-20 23:10:37 +01:00
|
|
|
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
2012-03-27 05:01:51 +02:00
|
|
|
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
2013-01-30 17:35:33 +01:00
|
|
|
import com.gmail.nossr50.mods.ModChecks;
|
2013-01-30 17:53:51 +01:00
|
|
|
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 {
|
2013-01-25 18:33:48 +01:00
|
|
|
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
|
2013-02-01 06:38:25 +01:00
|
|
|
* @param mcMMOPlayer The player who broke the block
|
2012-03-12 22:57:44 +01:00
|
|
|
*/
|
2013-02-01 06:38:25 +01:00
|
|
|
public static void excavationProcCheck(Block block, McMMOPlayer mcMMOPlayer) {
|
|
|
|
Material material = block.getType();
|
2012-05-17 06:24:33 +02:00
|
|
|
int xp;
|
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
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-27 07:09:20 +01:00
|
|
|
|
2013-01-29 18:02:32 +01:00
|
|
|
case GRASS:
|
|
|
|
xp = Config.getInstance().getExcavationGrassXP();
|
|
|
|
break;
|
2013-01-27 07:09:20 +01:00
|
|
|
|
2013-01-29 18:02:32 +01:00
|
|
|
case GRAVEL:
|
|
|
|
xp = Config.getInstance().getExcavationGravelXP();
|
|
|
|
break;
|
2013-01-27 07:09:20 +01:00
|
|
|
|
2013-01-29 18:02:32 +01:00
|
|
|
case MYCEL:
|
|
|
|
xp = Config.getInstance().getExcavationMycelXP();
|
|
|
|
break;
|
2013-01-27 07:09:20 +01:00
|
|
|
|
2013-01-29 18:02:32 +01:00
|
|
|
case SAND:
|
|
|
|
xp = Config.getInstance().getExcavationSandXP();
|
|
|
|
break;
|
2013-01-27 07:09:20 +01:00
|
|
|
|
2013-01-29 18:02:32 +01:00
|
|
|
case SOUL_SAND:
|
|
|
|
xp = Config.getInstance().getExcavationSoulSandXP();
|
|
|
|
break;
|
2013-01-27 07:09:20 +01:00
|
|
|
|
2013-01-29 18:02:32 +01:00
|
|
|
default:
|
|
|
|
xp = ModChecks.getCustomBlock(block).getXpGain();;
|
|
|
|
break;
|
2012-05-17 06:24:33 +02:00
|
|
|
}
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
|
|
|
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
|
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.excavationTreasures(player)) {
|
2013-02-01 06:38:25 +01:00
|
|
|
switch (material) {
|
2012-03-20 03:05:17 +01:00
|
|
|
case DIRT:
|
2012-05-17 16:26:21 +02:00
|
|
|
treasures = TreasuresConfig.getInstance().excavationFromDirt;
|
2012-03-20 03:05:17 +01:00
|
|
|
break;
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
case GRASS:
|
2012-05-17 16:26:21 +02:00
|
|
|
treasures = TreasuresConfig.getInstance().excavationFromGrass;
|
2012-03-20 03:05:17 +01:00
|
|
|
break;
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
case SAND:
|
2012-05-17 16:26:21 +02:00
|
|
|
treasures = TreasuresConfig.getInstance().excavationFromSand;
|
2012-03-20 03:05:17 +01:00
|
|
|
break;
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
case GRAVEL:
|
2012-05-17 16:26:21 +02:00
|
|
|
treasures = TreasuresConfig.getInstance().excavationFromGravel;
|
2012-03-20 03:05:17 +01:00
|
|
|
break;
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
case CLAY:
|
2012-05-17 16:26:21 +02:00
|
|
|
treasures = TreasuresConfig.getInstance().excavationFromClay;
|
2012-03-20 03:05:17 +01:00
|
|
|
break;
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
case MYCEL:
|
2012-05-17 16:26:21 +02:00
|
|
|
treasures = TreasuresConfig.getInstance().excavationFromMycel;
|
2012-03-20 03:05:17 +01:00
|
|
|
break;
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
case SOUL_SAND:
|
2012-05-17 16:26:21 +02:00
|
|
|
treasures = TreasuresConfig.getInstance().excavationFromSoulSand;
|
2012-03-20 03:05:17 +01:00
|
|
|
break;
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
Location location = block.getLocation();
|
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
for (ExcavationTreasure treasure : treasures) {
|
2013-02-01 06:38:25 +01:00
|
|
|
if (mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION) >= treasure.getDropLevel()) {
|
2013-01-22 02:01:33 +01:00
|
|
|
int activationChance = Misc.calculateActivationChance(Permissions.luckyExcavation(player));
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
if (Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
|
2012-03-20 03:05:17 +01:00
|
|
|
xp += treasure.getXp();
|
2013-02-01 06:38:25 +01:00
|
|
|
Misc.dropItem(location, treasure.getDrop());
|
2012-03-20 03:05:17 +01:00
|
|
|
}
|
2012-03-12 22:57:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
mcMMOPlayer.addXp(SkillType.EXCAVATION, xp);
|
2012-03-12 22:57:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle triple drops from Giga Drill Breaker.
|
|
|
|
*
|
2013-02-01 06:38:25 +01:00
|
|
|
* @param mcMMOPlayer The player using the ability
|
2012-03-12 22:57:44 +01:00
|
|
|
* @param block The block to check
|
|
|
|
*/
|
2013-02-01 06:38:25 +01:00
|
|
|
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
|
|
|
|
2013-01-08 20:56:31 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(block) && Misc.blockBreakSimulate(block, player, true)) {
|
2012-03-27 05:01:51 +02:00
|
|
|
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
|
2012-06-07 00:02:22 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
Excavation.excavationProcCheck(block, mcMMOplayer);
|
|
|
|
Excavation.excavationProcCheck(block, mcMMOplayer);
|
2012-03-12 22:57:44 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 00:36:16 +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
|
|
|
}
|