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

46 lines
1.1 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;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent;
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
}
final BlockBreakEvent event = new BlockBreakEvent(block, user.getBase());
2011-12-03 00:00:29 +00:00
server.getPluginManager().callEvent(event);
if (event.isCancelled())
{
throw new NoChargeException();
}
else
{
block.setType(Material.AIR);
}
}
}