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

148 lines
4.4 KiB
Java
Raw Normal View History

2012-01-09 20:00:13 +01:00
package com.gmail.nossr50.skills;
import java.util.ArrayList;
2012-03-12 22:57:44 +01:00
import java.util.List;
2012-03-26 17:04:17 +02:00
import java.util.Random;
import org.bukkit.Bukkit;
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;
import org.bukkit.event.player.PlayerAnimationEvent;
2012-03-21 03:33:58 +01:00
import com.gmail.nossr50.spout.SpoutSounds;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcPermissions;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.LoadTreasures;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
2012-02-04 16:45:37 +01:00
import org.getspout.spoutapi.sound.SoundEffect;
2012-01-09 20:00:13 +01:00
2012-03-12 22:57:44 +01:00
public class Excavation {
2012-03-26 17:04:17 +02:00
private static Random random = new Random();
2012-03-12 22:57:44 +01:00
/**
* Check to see if a block can be broken by Giga Drill Breaker.
*
* @param material The type of block to check
* @return
*/
public static boolean canBeGigaDrillBroken(Material type) {
switch (type) {
case CLAY:
case DIRT:
case GRASS:
case GRAVEL:
case MYCEL:
case SAND:
case SOUL_SAND:
return true;
2012-03-19 02:12:29 +01:00
2012-03-12 22:57:44 +01:00
default:
return false;
}
}
/**
* 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) {
Material type = block.getType();
Location loc = block.getLocation();
PlayerProfile PP = Users.getProfile(player);
int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
ArrayList<ItemStack> is = new ArrayList<ItemStack>();
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
2012-03-12 22:57:44 +01:00
int xp = LoadProperties.mbase;
if (mcPermissions.getInstance().excavationTreasures(player)) {
switch (type) {
case DIRT:
treasures = LoadTreasures.excavationFromDirt;
break;
2012-03-12 22:57:44 +01:00
case GRASS:
treasures = LoadTreasures.excavationFromGrass;
break;
2012-03-12 22:57:44 +01:00
case SAND:
treasures = LoadTreasures.excavationFromSand;
break;
2012-03-12 22:57:44 +01:00
case GRAVEL:
treasures = LoadTreasures.excavationFromGravel;
break;
2012-03-12 22:57:44 +01:00
case CLAY:
treasures = LoadTreasures.excavationFromClay;
break;
2012-03-12 22:57:44 +01:00
case MYCEL:
treasures = LoadTreasures.excavationFromMycel;
break;
2012-03-12 22:57:44 +01:00
case SOUL_SAND:
treasures = LoadTreasures.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()) {
2012-03-26 17:04:17 +02:00
if (random.nextInt(100) <= 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) {
m.mcDropItem(loc, x);
}
2012-03-12 22:57:44 +01:00
}
}
//Handle XP related tasks
PP.addXP(SkillType.EXCAVATION, xp, player);
Skills.XpCheckSkill(SkillType.EXCAVATION, player);
}
/**
* 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) {
Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss);
if (!block.hasMetadata("mcmmoPlacedBlock")) {
2012-03-12 22:57:44 +01:00
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing);
Excavation.excavationProcCheck(block, player);
Excavation.excavationProcCheck(block, player);
}
if (LoadProperties.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
}