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;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-12-25 07:01:10 +01:00
|
|
|
import org.bukkit.material.MaterialData;
|
2012-06-05 16:13:10 +02:00
|
|
|
import org.getspout.spoutapi.sound.SoundEffect;
|
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;
|
2012-05-17 06:24:33 +02:00
|
|
|
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
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-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillType;
|
2013-01-26 23:01:55 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillTools;
|
2012-06-05 16:13:10 +02:00
|
|
|
import com.gmail.nossr50.spout.SpoutSounds;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.ModChecks;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.Users;
|
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
|
|
|
|
* @param player The player who broke the block
|
|
|
|
*/
|
|
|
|
public static void excavationProcCheck(Block block, Player player) {
|
2013-01-10 05:03:17 +01:00
|
|
|
if (player == null)
|
2012-10-30 19:46:52 +01:00
|
|
|
return;
|
|
|
|
|
2012-03-12 22:57:44 +01:00
|
|
|
Material type = block.getType();
|
2012-07-04 21:35:14 +02:00
|
|
|
Location location = block.getLocation();
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
|
|
|
int skillLevel = profile.getSkillLevel(SkillType.EXCAVATION);
|
2012-03-12 22:57:44 +01:00
|
|
|
ArrayList<ItemStack> is = new ArrayList<ItemStack>();
|
|
|
|
|
|
|
|
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
|
2012-03-20 03:05:17 +01:00
|
|
|
|
2012-05-17 06:24:33 +02:00
|
|
|
int xp;
|
|
|
|
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
|
|
|
if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
|
2012-05-17 06:24:33 +02:00
|
|
|
xp = ModChecks.getCustomBlock(block).getXpGain();
|
|
|
|
}
|
|
|
|
else {
|
2013-01-27 07:09:20 +01:00
|
|
|
switch (type) {
|
|
|
|
case CLAY:
|
|
|
|
xp = Config.getInstance().getExcavationClayXP();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIRT:
|
|
|
|
xp = Config.getInstance().getExcavationDirtXP();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRASS:
|
|
|
|
xp = Config.getInstance().getExcavationGrassXP();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRAVEL:
|
|
|
|
xp = Config.getInstance().getExcavationGravelXP();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MYCEL:
|
|
|
|
xp = Config.getInstance().getExcavationMycelXP();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SAND:
|
|
|
|
xp = Config.getInstance().getExcavationSandXP();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOUL_SAND:
|
|
|
|
xp = Config.getInstance().getExcavationSoulSandXP();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
xp = 0;
|
|
|
|
break;
|
|
|
|
}
|
2012-05-17 06:24:33 +02:00
|
|
|
}
|
2012-03-12 22:57:44 +01:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.excavationTreasures(player)) {
|
2012-03-20 03:05:17 +01:00
|
|
|
switch (type) {
|
|
|
|
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
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
for (ExcavationTreasure treasure : treasures) {
|
|
|
|
if (skillLevel >= 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();
|
|
|
|
is.add(treasure.getDrop());
|
|
|
|
}
|
2012-03-12 22:57:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
//Drop items
|
|
|
|
for (ItemStack x : is) {
|
|
|
|
if (x != null) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, x);
|
2012-03-20 03:05:17 +01:00
|
|
|
}
|
2012-03-12 22:57:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
SkillTools.xpProcessing(player, profile, SkillType.EXCAVATION, xp);
|
2012-03-12 22:57:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle triple drops from Giga Drill Breaker.
|
|
|
|
*
|
|
|
|
* @param player The player using the ability
|
|
|
|
* @param block The block to check
|
|
|
|
*/
|
|
|
|
public static void gigaDrillBreaker(Player player, Block block) {
|
2013-01-10 05:03:17 +01:00
|
|
|
if (player == null)
|
2012-10-30 19:46:52 +01:00
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
|
|
|
Excavation.excavationProcCheck(block, player);
|
|
|
|
Excavation.excavationProcCheck(block, player);
|
|
|
|
}
|
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
if (mcMMO.spoutEnabled) {
|
2012-03-21 03:33:58 +01:00
|
|
|
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
2012-03-12 22:57:44 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-02-01 21:57:47 +01:00
|
|
|
}
|