2012-01-09 20:00:13 +01:00
|
|
|
/*
|
|
|
|
This file is part of mcMMO.
|
|
|
|
|
|
|
|
mcMMO is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
mcMMO is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package com.gmail.nossr50.skills;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2012-02-05 21:24:44 +01:00
|
|
|
|
|
|
|
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;
|
2012-02-04 16:45:37 +01:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2012-02-05 21:24:44 +01:00
|
|
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
|
|
|
|
2012-02-04 15:35:07 +01:00
|
|
|
import com.gmail.nossr50.spout.SpoutStuff;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.Users;
|
|
|
|
import com.gmail.nossr50.m;
|
|
|
|
import com.gmail.nossr50.config.LoadProperties;
|
2012-02-29 05:28:14 +01:00
|
|
|
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;
|
2012-02-20 23:10:37 +01:00
|
|
|
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-02-01 22:08:00 +01:00
|
|
|
public class Excavation
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
|
|
|
public static boolean canBeGigaDrillBroken(Block block)
|
|
|
|
{
|
2012-02-25 08:49:53 +01:00
|
|
|
switch(block.getType()){
|
|
|
|
case CLAY:
|
|
|
|
case DIRT:
|
|
|
|
case GRASS:
|
|
|
|
case GRAVEL:
|
|
|
|
case MYCEL:
|
|
|
|
case SAND:
|
|
|
|
case SOUL_SAND:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-02-25 08:49:53 +01:00
|
|
|
|
2012-02-24 17:21:07 +01:00
|
|
|
public static void excavationProcCheck(Block block, Player player)
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-24 17:21:07 +01:00
|
|
|
Material type = block.getType();
|
|
|
|
Location loc = block.getLocation();
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
2012-02-01 18:33:59 +01:00
|
|
|
int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
|
2012-01-09 20:00:13 +01:00
|
|
|
ArrayList<ItemStack> is = new ArrayList<ItemStack>();
|
2012-02-21 14:19:49 +01:00
|
|
|
int xp = LoadProperties.mbase;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
2012-02-20 19:58:22 +01:00
|
|
|
case DIRT:
|
2012-02-29 05:28:14 +01:00
|
|
|
for(ExcavationTreasure treasure : LoadTreasures.excavationFromDirt)
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(skillLevel >= treasure.getDropLevel())
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
xp += treasure.getXp();
|
|
|
|
is.add(treasure.getDrop());
|
2012-02-20 19:58:22 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
break;
|
2012-02-20 19:58:22 +01:00
|
|
|
case GRASS:
|
2012-02-29 05:28:14 +01:00
|
|
|
for(ExcavationTreasure treasure : LoadTreasures.excavationFromGrass)
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(skillLevel >= treasure.getDropLevel())
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
xp += treasure.getXp();
|
|
|
|
is.add(treasure.getDrop());
|
2012-02-20 19:58:22 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SAND:
|
2012-02-29 05:28:14 +01:00
|
|
|
for(ExcavationTreasure treasure : LoadTreasures.excavationFromSand)
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(skillLevel >= treasure.getDropLevel())
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
xp += treasure.getXp();
|
|
|
|
is.add(treasure.getDrop());
|
2012-02-20 19:58:22 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-02-20 19:58:22 +01:00
|
|
|
break;
|
|
|
|
case GRAVEL:
|
2012-02-29 05:28:14 +01:00
|
|
|
for(ExcavationTreasure treasure : LoadTreasures.excavationFromGravel)
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(skillLevel >= treasure.getDropLevel())
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
xp += treasure.getXp();
|
|
|
|
is.add(treasure.getDrop());
|
2012-02-20 19:58:22 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CLAY:
|
2012-02-29 05:28:14 +01:00
|
|
|
for(ExcavationTreasure treasure : LoadTreasures.excavationFromClay)
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(skillLevel >= treasure.getDropLevel())
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
xp += treasure.getXp();
|
|
|
|
is.add(treasure.getDrop());
|
2012-02-20 19:58:22 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
break;
|
2012-02-20 19:58:22 +01:00
|
|
|
case MYCEL:
|
2012-02-29 05:28:14 +01:00
|
|
|
for(ExcavationTreasure treasure : LoadTreasures.excavationFromMycel)
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(skillLevel >= treasure.getDropLevel())
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
xp += treasure.getXp();
|
|
|
|
is.add(treasure.getDrop());
|
2012-02-20 19:58:22 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-20 19:58:22 +01:00
|
|
|
break;
|
|
|
|
case SOUL_SAND:
|
2012-02-29 05:28:14 +01:00
|
|
|
for(ExcavationTreasure treasure : LoadTreasures.excavationFromSoulSand)
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(skillLevel >= treasure.getDropLevel())
|
2012-01-09 20:00:13 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
|
2012-02-20 19:58:22 +01:00
|
|
|
{
|
2012-02-20 23:10:37 +01:00
|
|
|
xp += treasure.getXp();
|
|
|
|
is.add(treasure.getDrop());
|
2012-02-20 19:58:22 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-20 19:58:22 +01:00
|
|
|
break;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Drop items
|
|
|
|
for(ItemStack x : is)
|
|
|
|
{
|
|
|
|
if(x != null)
|
2012-01-29 08:51:59 +01:00
|
|
|
m.mcDropItem(loc, x);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Handle XP related tasks
|
|
|
|
PP.addXP(SkillType.EXCAVATION, xp, player);
|
|
|
|
Skills.XpCheckSkill(SkillType.EXCAVATION, player);
|
|
|
|
}
|
2012-02-04 15:35:07 +01:00
|
|
|
|
|
|
|
public static void gigaDrillBreaker(Player player, Block block)
|
|
|
|
{
|
|
|
|
if(LoadProperties.toolsLoseDurabilityFromAbilities)
|
|
|
|
{
|
2012-02-04 16:45:37 +01:00
|
|
|
if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY))
|
2012-02-23 08:12:24 +01:00
|
|
|
{
|
|
|
|
short durability = player.getItemInHand().getDurability();
|
2012-02-23 08:26:44 +01:00
|
|
|
durability += LoadProperties.abilityDurabilityLoss;
|
2012-02-23 08:12:24 +01:00
|
|
|
player.getItemInHand().setDurability(durability);
|
|
|
|
}
|
2012-02-04 15:35:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(block.getData() != (byte)5)
|
|
|
|
{
|
2012-02-05 21:24:44 +01:00
|
|
|
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
|
|
|
|
Bukkit.getPluginManager().callEvent(armswing);
|
2012-02-24 17:21:07 +01:00
|
|
|
Excavation.excavationProcCheck(block, player);
|
|
|
|
Excavation.excavationProcCheck(block, player);
|
|
|
|
Excavation.excavationProcCheck(block, player);
|
2012-02-04 15:35:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(LoadProperties.spoutEnabled)
|
|
|
|
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
|
|
|
}
|
2012-02-01 21:57:47 +01:00
|
|
|
}
|