}
@EventHandler
public void toolUsage(PlayerInteractEvent event)
{
AutoRefMatch match = plugin.getMatch(event.getPlayer().getWorld());
if (match == null) return;
Block block;
// this event is not an "item" event
if (!event.hasItem()) return;
// get type id of the event and check if its one of our tools
ToolAction action = ToolAction.fromMaterial(event.getMaterial());
if (action == null) return;
// get which action to perform
switch (action)
{
// this is the tool built for setting win conditions
case TOOL_WINCOND:
if (match.getCurrentState().inProgress()) return;
// if there is no block involved in this event, nothing
if (!event.hasBlock()) return;
block = event.getClickedBlock();
// if the player doesn't have configure permissions, nothing
if (!event.getPlayer().hasPermission("autoreferee.configure")) return;
for (AutoRefTeam team : match.getTeams())
{
boolean canBuild = !team.hasFlag(block.getLocation(), AutoRefRegion.Flag.NO_BUILD);
boolean canEnter = !team.hasFlag(block.getLocation(), AutoRefRegion.Flag.NO_ENTRY);
if (canBuild && canEnter) team.addGoal(new BlockGoal(team, block));
}
break;
// this is the tool built for setting start mechanisms
case TOOL_STARTMECH:
if (match.getCurrentState().inProgress()) return;
// if there is no block involved in this event, nothing
if (!event.hasBlock()) return;
// if the player doesn't have configure permissions, nothing
if (!event.getPlayer().hasPermission("autoreferee.configure")) return;
// determine who owns the region that the clicked block is in
block = event.getClickedBlock();
// get the start mechanism
AutoRefMatch.StartMechanism sm = match.toggleStartMech(block);
if (sm != null) event.getPlayer().sendMessage(ChatColor.RED +
"" + sm + ChatColor.RESET + " is a start mechanism.");
else
{
String coords = LocationUtil.toBlockCoords(block.getLocation());
event.getPlayer().sendMessage(ChatColor.RED + "" +
coords + ChatColor.RESET + " is NOT a start mechanism.");
}
break;
case SPECTATOR_CYCLE:
// this tool only valid for spectators
if (!match.isSpectator(event.getPlayer())) return;
switch (event.getAction())
{
case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK:
match.getSpectator(event.getPlayer()).cyclePrevPlayer();
break;
case RIGHT_CLICK_AIR:
case RIGHT_CLICK_BLOCK:
match.getSpectator(event.getPlayer()).cycleNextPlayer();
break;
default: break;
}
break;