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

174 lines
5.7 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.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;
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.config.mods.CustomBlocksConfig;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
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 {
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)
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>();
int xp;
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)) {
xp = ModChecks.getCustomBlock(block).getXpGain();
}
else {
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-03-12 22:57:44 +01:00
2013-01-07 02:52:31 +01:00
if (Permissions.excavationTreasures(player)) {
switch (type) {
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
for (ExcavationTreasure treasure : treasures) {
if (skillLevel >= 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();
is.add(treasure.getDrop());
}
2012-03-12 22:57:44 +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-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)
return;
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, player);
Excavation.excavationProcCheck(block, player);
}
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
}