TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java

50 lines
1.2 KiB
Java
Raw Normal View History

2011-12-03 00:00:29 +00:00
package com.earth2me.essentials.commands;
2012-03-12 15:35:20 +00:00
import static com.earth2me.essentials.I18n._;
2011-12-03 00:00:29 +00:00
import com.earth2me.essentials.User;
2012-03-22 17:26:05 +00:00
import java.util.ArrayList;
import java.util.List;
2011-12-03 00:00:29 +00:00
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent;
2012-03-22 17:26:05 +00:00
import org.bukkit.inventory.ItemStack;
2011-12-03 00:00:29 +00:00
public class Commandbreak extends EssentialsCommand
{
public Commandbreak()
{
super("break");
}
//TODO: Switch to use util class
2011-12-03 00:00:29 +00:00
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
2011-12-03 00:00:29 +00:00
{
final Block block = user.getTargetBlock(null, 20);
2011-12-04 21:06:03 +00:00
if (block == null)
{
throw new NoChargeException();
}
2011-12-03 00:00:29 +00:00
if (block.getType() == Material.AIR)
{
throw new NoChargeException();
}
if (block.getType() == Material.BEDROCK && !user.isAuthorized("essentials.break.bedrock"))
{
2012-03-12 15:35:20 +00:00
throw new Exception(_("noBreakBedrock"));
2011-12-03 00:00:29 +00:00
}
2012-03-22 17:26:05 +00:00
final List<ItemStack> list = (List<ItemStack>)block.getDrops();
final BlockBreakEvent event = new BlockBreakEvent(block, user.getBase(), list);
2011-12-03 00:00:29 +00:00
server.getPluginManager().callEvent(event);
if (event.isCancelled())
{
throw new NoChargeException();
}
else
{
block.setType(Material.AIR);
}
}
}