mcMMO/src/com/gmail/nossr50/skills/WoodCutting.java

170 lines
5.7 KiB
Java
Raw Normal View History

2011-09-12 10:47:57 +02: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/>.
*/
2011-04-20 22:56:25 +02:00
package com.gmail.nossr50.skills;
import java.util.ArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile;
2011-07-19 16:17:14 +02:00
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale;
2011-04-20 22:56:25 +02:00
import com.gmail.nossr50.config.*;
public class WoodCutting
{
2011-04-20 22:56:25 +02:00
static int w = 0;
private static boolean isdone = false;
public static void woodCuttingProcCheck(Player player, Block block)
{
2011-04-20 22:56:25 +02:00
PlayerProfile PP = Users.getProfile(player);
byte type = block.getData();
Material mat = Material.getMaterial(block.getTypeId());
if(player != null)
{
if(Math.random() * 1000 <= PP.getSkillLevel(SkillType.WOODCUTTING))
{
2011-04-20 22:56:25 +02:00
ItemStack item = new ItemStack(mat, 1, (short) 0, type);
block.getWorld().dropItemNaturally(block.getLocation(), item);
}
}
}
2011-08-08 00:44:50 +02:00
public static void treeFellerCheck(Player player, Block block)
2011-07-10 02:18:00 +02:00
{
2011-04-20 22:56:25 +02:00
PlayerProfile PP = Users.getProfile(player);
2011-07-10 02:18:00 +02:00
if(m.isAxes(player.getItemInHand()))
{
if(block != null)
{
2011-04-20 22:56:25 +02:00
if(!m.abilityBlockCheck(block))
return;
}
/*
* CHECK FOR AXE PREP MODE
*/
2011-07-10 02:18:00 +02:00
if(PP.getAxePreparationMode())
{
2011-04-20 22:56:25 +02:00
PP.setAxePreparationMode(false);
}
int ticks = 2;
2011-07-19 16:17:14 +02:00
int x = PP.getSkillLevel(SkillType.WOODCUTTING);
while(x >= 50)
{
2011-04-20 22:56:25 +02:00
x-=50;
ticks++;
}
if(!PP.getTreeFellerMode() && Skills.cooldownOver(player, (PP.getTreeFellerDeactivatedTimeStamp()*1000), LoadProperties.treeFellerCooldown))
{
player.sendMessage(mcLocale.getString("Skills.TreeFellerOn"));
2011-08-08 00:44:50 +02:00
for(Player y : player.getWorld().getPlayers())
{
2011-04-20 22:56:25 +02:00
if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10)
y.sendMessage(mcLocale.getString("Skills.TreeFellerPlayer", new Object[] {player.getName()}));
2011-04-20 22:56:25 +02:00
}
PP.setTreeFellerActivatedTimeStamp(System.currentTimeMillis());
2011-04-30 22:53:08 +02:00
PP.setTreeFellerDeactivatedTimeStamp(System.currentTimeMillis() + (ticks * 1000));
2011-04-20 22:56:25 +02:00
PP.setTreeFellerMode(true);
}
if(!PP.getTreeFellerMode() && !Skills.cooldownOver(player, (PP.getTreeFellerDeactivatedTimeStamp()*1000), LoadProperties.treeFellerCooldown)){
2011-04-20 22:56:25 +02:00
player.sendMessage(ChatColor.RED+"You are too tired to use that ability again."
+ChatColor.YELLOW+" ("+Skills.calculateTimeLeft(player, (PP.getTreeFellerDeactivatedTimeStamp()*1000), LoadProperties.treeFellerCooldown)+"s)");
2011-04-20 22:56:25 +02:00
}
}
}
2011-07-10 02:18:00 +02:00
public static void treeFeller(Block block, Player player, mcMMO plugin){
2011-04-20 22:56:25 +02:00
PlayerProfile PP = Users.getProfile(player);
int radius = 1;
2011-07-19 16:17:14 +02:00
if(PP.getSkillLevel(SkillType.WOODCUTTING) >= 500)
2011-04-20 22:56:25 +02:00
radius++;
2011-07-19 16:17:14 +02:00
if(PP.getSkillLevel(SkillType.WOODCUTTING) >= 950)
2011-04-20 22:56:25 +02:00
radius++;
ArrayList<Block> blocklist = new ArrayList<Block>();
ArrayList<Block> toAdd = new ArrayList<Block>();
if(block != null)
blocklist.add(block);
while(isdone == false){
addBlocksToTreeFelling(blocklist, toAdd, radius);
}
//This needs to be a hashmap too!
isdone = false;
/*
* Add blocks from the temporary 'toAdd' array list into the 'treeFeller' array list
* We use this temporary list to prevent concurrent modification exceptions
*/
2011-07-10 02:18:00 +02:00
for(Block x : toAdd)
{
if(!plugin.misc.treeFeller.contains(x))
plugin.misc.treeFeller.add(x);
2011-04-20 22:56:25 +02:00
}
toAdd.clear();
}
public static void addBlocksToTreeFelling(ArrayList<Block> blocklist, ArrayList<Block> toAdd, Integer radius)
{
2011-04-20 22:56:25 +02:00
int u = 0;
for (Block x : blocklist)
{
2011-04-20 22:56:25 +02:00
u++;
if(toAdd.contains(x))
continue;
w = 0;
Location loc = x.getLocation();
int vx = x.getX();
int vy = x.getY();
int vz = x.getZ();
/*
* Run through the blocks around the broken block to see if they qualify to be 'felled'
*/
for (int cx = -radius; cx <= radius; cx++) {
for (int cy = -radius; cy <= radius; cy++) {
for (int cz = -radius; cz <= radius; cz++) {
Block blocktarget = loc.getWorld().getBlockAt(vx + cx, vy + cy, vz + cz);
if (!blocklist.contains(blocktarget) && !toAdd.contains(blocktarget) && (blocktarget.getTypeId() == 17 || blocktarget.getTypeId() == 18)) {
toAdd.add(blocktarget);
w++;
}
}
}
}
}
/*
* Add more blocks to blocklist so they can be 'felled'
*/
for(Block xx : toAdd)
{
2011-04-20 22:56:25 +02:00
if(!blocklist.contains(xx))
blocklist.add(xx);
}
if(u >= blocklist.size())
{
2011-04-20 22:56:25 +02:00
isdone = true;
} else {
isdone = false;
}
}
}