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

222 lines
6.9 KiB
Java
Raw Normal View History

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;
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;
import org.bukkit.event.player.PlayerAnimationEvent;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.locale.mcLocale;
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;
import com.gmail.nossr50.datatypes.AbilityType;
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-02-01 22:08:00 +01:00
public class Excavation
2012-01-09 20:00:13 +01:00
{
public static void gigaDrillBreakerActivationCheck(Player player, Block block)
{
PlayerProfile PP = Users.getProfile(player);
if(m.isShovel(player.getItemInHand()))
{
if(block != null)
{
if(!m.abilityBlockCheck(block))
return;
}
if(PP.getShovelPreparationMode())
{
PP.setShovelPreparationMode(false);
}
int ticks = 2;
int x = PP.getSkillLevel(SkillType.EXCAVATION);
while(x >= 50)
{
x-=50;
ticks++;
}
if(!PP.getGigaDrillBreakerMode() && PP.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER) < System.currentTimeMillis())
2012-01-09 20:00:13 +01:00
{
player.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerOn"));
for(Player y : player.getWorld().getPlayers())
{
if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10)
y.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerPlayer", new Object[] {player.getName()}));
}
PP.setSkillDATS(AbilityType.GIGA_DRILL_BREAKER, System.currentTimeMillis()+(ticks*1000));
2012-01-09 20:00:13 +01:00
PP.setGigaDrillBreakerMode(true);
}
}
}
public static boolean canBeGigaDrillBroken(Block block)
{
2012-02-01 22:08:00 +01:00
Material t = block.getType();
return t == Material.DIRT || t == Material.GRASS || t == Material.SAND || t == Material.GRAVEL || t == Material.CLAY || t == Material.MYCEL || t == Material.SOUL_SAND;
2012-01-09 20:00:13 +01:00
}
public static void excavationProcCheck(Material type, Location loc, Player player)
2012-01-09 20:00:13 +01:00
{
if(LoadProperties.excavationRequiresShovel && !m.isShovel(player.getItemInHand()))
return;
PlayerProfile PP = Users.getProfile(player);
int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
2012-01-09 20:00:13 +01:00
ArrayList<ItemStack> is = new ArrayList<ItemStack>();
int xp = 0;
switch(type)
{
case DIRT:
for(ExcavationTreasure treasure : LoadProperties.excavationFromDirt)
2012-01-09 20:00:13 +01:00
{
if(skillLevel >= treasure.getDropLevel())
{
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
2012-01-09 20:00:13 +01:00
}
break;
case GRASS:
for(ExcavationTreasure treasure : LoadProperties.excavationFromGrass)
2012-01-09 20:00:13 +01:00
{
if(skillLevel >= treasure.getDropLevel())
{
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
2012-01-09 20:00:13 +01:00
}
break;
case SAND:
for(ExcavationTreasure treasure : LoadProperties.excavationFromSand)
2012-01-09 20:00:13 +01:00
{
if(skillLevel >= treasure.getDropLevel())
{
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
2012-01-09 20:00:13 +01:00
}
break;
case GRAVEL:
for(ExcavationTreasure treasure : LoadProperties.excavationFromGravel)
2012-01-09 20:00:13 +01:00
{
if(skillLevel >= treasure.getDropLevel())
{
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
2012-01-09 20:00:13 +01:00
}
break;
case CLAY:
for(ExcavationTreasure treasure : LoadProperties.excavationFromClay)
2012-01-09 20:00:13 +01:00
{
if(skillLevel >= treasure.getDropLevel())
{
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
2012-01-09 20:00:13 +01:00
}
break;
case MYCEL:
for(ExcavationTreasure treasure : LoadProperties.excavationFromMycel)
2012-01-09 20:00:13 +01:00
{
if(skillLevel >= treasure.getDropLevel())
2012-01-09 20:00:13 +01:00
{
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
xp += treasure.getXp();
is.add(treasure.getDrop());
}
2012-01-09 20:00:13 +01:00
}
}
break;
case SOUL_SAND:
for(ExcavationTreasure treasure : LoadProperties.excavationFromSoulSand)
2012-01-09 20:00:13 +01:00
{
if(skillLevel >= treasure.getDropLevel())
2012-01-09 20:00:13 +01:00
{
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
xp += treasure.getXp();
is.add(treasure.getDrop());
}
2012-01-09 20:00:13 +01:00
}
}
break;
2012-01-09 20:00:13 +01:00
}
//Drop items
for(ItemStack x : is)
{
if(x != null)
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);
}
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))
m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss);
}
if(block.getData() != (byte)5)
{
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing);
Excavation.excavationProcCheck(block.getType(), block.getLocation(), player);
Excavation.excavationProcCheck(block.getType(), block.getLocation(), player);
Excavation.excavationProcCheck(block.getType(), block.getLocation(), player);
}
if(LoadProperties.spoutEnabled)
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
}
2012-02-01 21:57:47 +01:00
}