2011-12-03 00:00:29 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2011-12-10 01:29:23 +00:00
|
|
|
//TODO: Switch to use util class
|
2011-12-03 00:00:29 +00:00
|
|
|
@Override
|
2011-12-03 20:41:24 +00:00
|
|
|
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
|
|
|
{
|
2011-12-03 20:41:24 +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"))
|
|
|
|
{
|
2011-12-04 21:06:03 +00:00
|
|
|
throw new Exception("You are not allowed to destroy bedrock."); //TODO: Translation
|
2011-12-03 00:00:29 +00:00
|
|
|
}
|
2011-12-03 20:41:24 +00:00
|
|
|
final BlockBreakEvent event = new BlockBreakEvent(block, user);
|
2011-12-03 00:00:29 +00:00
|
|
|
server.getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled())
|
|
|
|
{
|
|
|
|
throw new NoChargeException();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
block.setType(Material.AIR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|